summaryrefslogtreecommitdiff
path: root/sys/kern/link_elf.c
Commit message (Collapse)AuthorAgeFilesLines
* Implement a facility for dynamic per-cpu variables.Jeff Roberson2009-06-231-0/+52
| | | | | | | | | | | | | | | | | | - Modules and kernel code alike may use DPCPU_DEFINE(), DPCPU_GET(), DPCPU_SET(), etc. akin to the statically defined PCPU_*. Requires only one extra instruction more than PCPU_* and is virtually the same as __thread for builtin and much faster for shared objects. DPCPU variables can be initialized when defined. - Modules are supported by relocating the module's per-cpu linker set over space reserved in the kernel. Modules may fail to load if there is insufficient space available. - Track space available for modules with a one-off extent allocator. Free may block for memory to allocate space for an extent. Reviewed by: jhb, rwatson, kan, sam, grehan, marius, marcel, stas Notes: svn path=/head/; revision=194784
* Move "options MAC" from opt_mac.h to opt_global.h, as it's now in GENERICRobert Watson2009-06-051-1/+0
| | | | | | | | | | | and used in a large number of files, but also because an increasing number of incorrect uses of MAC calls were sneaking in due to copy-and-paste of MAC-aware code without the associated opt_mac.h include. Discussed with: pjd Notes: svn path=/head/; revision=193511
* Add the ksyms(4) pseudo driver. The ksyms driver allows a process toStacey Son2009-05-261-0/+30
| | | | | | | | | | | | | | | | | get a quick snapshot of the kernel's symbol table including the symbols from any loaded modules (the symbols are all merged into one symbol table). Unlike like other implementations, this ksyms driver maps memory in the process memory space to store the snapshot at the time /dev/ksyms is opened. It also checks to see if the process has already a snapshot open and won't allow it to open /dev/ksyms it again until it closes first. This prevents kernel and process memory from being exhausted. Note that /dev/ksyms is used by the lockstat(1) command. Reviewed by: gallatin kib (freebsd-arch) Approved by: gnn (mentor) Notes: svn path=/head/; revision=192859
* Scanning all the formats for binary translation of modules loading canAttilio Rao2009-02-101-4/+2
| | | | | | | | | | | | | | | | | | | | | | result in errors for a format loading but subsequent correct recognizing for another format. File format loading functions should avoid printing any additional informations but just returning appropriate (and different between each other) error condition, characterizing different informations. Additively, the linker should handle appropriately different format loading errors. While a general mechanism is desired, fix a simple and common case on amd64: file type is not recognized for link elf and confuses the linker. Printout an error if all the registered linker classes can't recognize and load the module. Reviewed by: jhb Sponsored by: Sandvine Incorporated Notes: svn path=/head/; revision=188440
* Calling linker_load_dependencies() while holding the module'Konstantin Belousov2008-08-031-0/+2
| | | | | | | | | | | | vnode lock may cause a LOR between kld_sx lock and vnode lock. linker_load_dependencies() drops kld_sx, and another thread may attempt to load the same kld. Reported and tested by: pjd MFC after: 1 week Notes: svn path=/head/; revision=181235
* Revert r180431.David E. O'Brien2008-07-111-0/+47
| | | | | | | r180431 broke the AMD64 build (the only arch using kern/link_elf_obj.c) Notes: svn path=/head/; revision=180438
* Allow 'elf_file_t' to be used in a wider scope.David E. O'Brien2008-07-101-47/+0
| | | | Notes: svn path=/head/; revision=180431
* Improve the output of kldload(8) to show which module can't be loaded.Edwin Groothuis2008-07-081-11/+14
| | | | | | | | | | | | | Was: kldload: Unsupported file type Is now: kldload: /boot/modules/test.ko: Unsupported file type PR: kern/121276 Submitted by: Edwin Groothuis <edwin@mavetju.org> Approved by: bde (mentor) MFC after: 1 week Notes: svn path=/head/; revision=180374
* Add hooks for the Compact C Type Format (CTF) data to be attached toJohn Birrell2008-05-231-0/+47
| | | | | | | | | the elf files. This is complicated by the fact that the actual CTF parsing has to be done in CDDL'd code, so the BSD licensed code only knows about the opaque data which it must be able to free. Notes: svn path=/head/; revision=179223
* Fix panic on e.g. "kldload /dev/null".Ruslan Ermilov2008-03-151-0/+5
| | | | | | | | | PR: kern/121427 Reviewed by: sem MFC after: 3 days Notes: svn path=/head/; revision=177228
* VOP_LOCK1() (and so VOP_LOCK()) and VOP_UNLOCK() are only used inAttilio Rao2008-01-131-1/+1
| | | | | | | | | | | | | | conjuction with 'thread' argument passing which is always curthread. Remove the unuseful extra-argument and pass explicitly curthread to lower layer functions, when necessary. KPI results broken by this change, which should affect several ports, so version bumping and manpage update will be further committed. Tested by: kris, pho, Diego Sardina <siarodx at gmail dot com> Notes: svn path=/head/; revision=175294
* Merge first in a series of TrustedBSD MAC Framework KPI changesRobert Watson2007-10-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | from Mac OS X Leopard--rationalize naming for entry points to the following general forms: mac_<object>_<method/action> mac_<object>_check_<method/action> The previous naming scheme was inconsistent and mostly reversed from the new scheme. Also, make object types more consistent and remove spaces from object types that contain multiple parts ("posix_sem" -> "posixsem") to make mechanical parsing easier. Introduce a new "netinet" object type for certain IPv4/IPv6-related methods. Also simplify, slightly, some entry point names. All MAC policy modules will need to be recompiled, and modules not updates as part of this commit will need to be modified to conform to the new KPI. Sponsored by: SPARTA (original patches against Mac OS X) Obtained from: TrustedBSD Project, Apple Computer Notes: svn path=/head/; revision=172930
* Revert UF_OPENING workaround for CURRENT.Konstantin Belousov2007-05-311-1/+1
| | | | | | | | | | | | Change the VOP_OPEN(), vn_open() vnode operation and d_fdopen() cdev operation argument from being file descriptor index into the pointer to struct file. Proposed and reviewed by: jhb Reviewed by: daichi (unionfs) Approved by: re (kensmith) Notes: svn path=/head/; revision=170152
* Mark the kernel linker file as linked so that it is visible to the variousJohn Baldwin2007-02-261-0/+1
| | | | | | | | | kld*() syscalls. Tested by: piso Notes: svn path=/head/; revision=167020
* Complete break-out of sys/sys/mac.h into sys/security/mac/mac_framework.hRobert Watson2006-10-221-1/+2
| | | | | | | | | | | | | | | | begun with a repo-copy of mac.h to mac_framework.h. sys/mac.h now contains the userspace and user<->kernel API and definitions, with all in-kernel interfaces moved to mac_framework.h, which is now included across most of the kernel instead. This change is the first step in a larger cleanup and sweep of MAC Framework interfaces in the kernel, and will not be MFC'd. Obtained from: TrustedBSD Project Sponsored by: SPARTA Notes: svn path=/head/; revision=163606
* Let native elf class be registered earlier.Jung-uk Kim2006-07-141-1/+1
| | | | Notes: svn path=/head/; revision=160367
* Replace the kld_mtx mutex with a kld_sx sx lock and expand it's scope toJohn Baldwin2006-06-211-2/+2
| | | | | | | | | | | | | | | protect all linker-related data structures including the contents of linker file objects and the any linker class data as well. Considering how rarely the linker is used I just went with the simple solution of single-threading the whole thing rather than expending a lot of effor on something more fine-grained and complex. Giant is still explicitly acquired while registering and deregistering sysctl's as well as in the elf linker class while calling kmupetext(). The rest of the linker runs without Giant unless it has to acquire Giant while loading files from a non-MPSAFE filesystem. Notes: svn path=/head/; revision=159845
* Conditionally acquire Giant around VFS operations.John Baldwin2006-06-201-1/+5
| | | | Notes: svn path=/head/; revision=159808
* Make our ELF64 type definitions match standards. In particular thisMarcel Moolenaar2005-12-181-5/+5
| | | | | | | | | | | | | | | | means: o Remove Elf64_Quarter, o Redefine Elf64_Half to be 16-bit, o Redefine Elf64_Word to be 32-bit, o Add Elf64_Xword and Elf64_Sxword for 64-bit entities, o Use Elf_Size in MI code to abstract the difference between Elf32_Word and Elf64_Word. o Add Elf_Ssize as the signed counterpart of Elf_Size. MFC after: 2 weeks Notes: svn path=/head/; revision=153504
* Check to see if the hash table is present in link_elf_lookup_symbol()John Baldwin2005-10-311-0/+6
| | | | | | | | | | | | | before dereferencing it. Certain corrupt kernel modules might not have a valid hash table, and would cause a kernel panic when they were loaded. Instead of panic'ing, the kernel now prints out a warning that it is missing the symbol hash table. Tested by: Benjamin Close Benjamin dot Close at clearchain dot com MFC after: 1 week Notes: svn path=/head/; revision=151902
* Add support for kernel modules with a single PT_LOAD section.Peter Wemm2005-10-171-6/+9
| | | | | | | | | | | | | | | | | While here, support up to four sections because it was trivial to do and cheap. (One pointer per section). For amd64 with "-fpic -shared" format .ko files, using a single PT_LOAD section is important to avoid wasting about 1MB of KVM and physical ram for the 'gap' between the two PT_LOAD sections. amd64 normally uses .o format kld files and isn't affected normally. But -fpic -shared modules are actually possible to produce and load... (And with a bugfix to binutils, we can build and use plain -shared .ko files without -fpic) i386 only wastes 4K per .ko file, so that isn't such a big deal there. Notes: svn path=/head/; revision=151430
* Correctly handle vm_map_wire()'s failure. (See also revisions 1.81 andAlan Cox2005-08-281-1/+5
| | | | | | | | | 1.82.) Reviewed by: tegge Notes: svn path=/head/; revision=149544
* Eliminate an unneeded reference on a vm object. If, in fact, the nearbyAlan Cox2005-08-281-2/+0
| | | | | | | | | | vm_map_find() fails, then the excess reference causes the vm object to be leaked. Reviewed by: tegge Notes: svn path=/head/; revision=149540
* Revert the previous change for two reasons: (1) If vm_map_find() succeedsAlan Cox2005-08-281-17/+10
| | | | | | | | | | | but vm_map_wire() fails, then a vm object, vm map entries, and kernel_map free space is leaked and (2) unwiring is handled automatically by vm_map_remove(). Suggested by: tegge Notes: svn path=/head/; revision=149539
* Normalize the VM wiring done with SPARSE_MAPPING: check for errors, andBrian Feldman2004-08-091-10/+17
| | | | | | | | unmap when done. For whatever reason, SPARSE_MAPPING is not even a config option, so this is dead code. Notes: svn path=/head/; revision=133397
* Give kldunload a -f(orce) argument.Poul-Henning Kamp2004-07-131-2/+2
| | | | | | | | | | | | | | | | | | | | Add a MOD_QUIESCE event for modules. This should return error (EBUSY) of the module is in use. MOD_UNLOAD should now only fail if it is impossible (as opposed to inconvenient) to unload the module. Valid reasons are memory references into the module which cannot be tracked down and eliminated. When kldunloading, we abandon if MOD_UNLOAD fails, and if -force is not given, MOD_QUIESCE failing will also prevent the unload. For backwards compatibility, we treat EOPNOTSUPP from MOD_QUIESCE as success. Document that modules should return EOPNOTSUPP for unknown events. Notes: svn path=/head/; revision=132117
* Make the GDB dynamic linker hooks (r_debug_state) conditional uponMarcel Moolenaar2004-07-101-9/+9
| | | | | | | GDB instead of DDB. Notes: svn path=/head/; revision=131928
* Include <sys/gmon.h> instead of <machine/profile.h> for the declarationBruce Evans2004-05-191-3/+3
| | | | | | | | | of kmupetext(). The declaration is misplaced in <machine/profile.h> since it is not MD and not related to the lowest level of profiling. It will be moved, but getting it via <sys/gmon.h> already works. Notes: svn path=/head/; revision=129443
* Make a small revision to the api between the elf linker core and thePeter Wemm2004-05-161-7/+14
| | | | | | | | | elf_reloc() backends for two reasons. First, to support the possibility of there being two elf linkers in the kernel (eg: amd64), and second, to pass the relocbase explicitly (for relocating .o format kld files). Notes: svn path=/head/; revision=129282
* Add the mlockall() and munlockall() system calls.Bruce M Simpson2003-08-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | - All those diffs to syscalls.master for each architecture *are* necessary. This needed clarification; the stub code generation for mlockall() was disabled, which would prevent applications from linking to this API (suggested by mux) - Giant has been quoshed. It is no longer held by the code, as the required locking has been pushed down within vm_map.c. - Callers must specify VM_MAP_WIRE_HOLESOK or VM_MAP_WIRE_NOHOLES to express their intention explicitly. - Inspected at the vmstat, top and vm pager sysctl stats level. Paging-in activity is occurring correctly, using a test harness. - The RES size for a process may appear to be greater than its SIZE. This is believed to be due to mappings of the same shared library page being wired twice. Further exploration is needed. - Believed to back out of allocations and locks correctly (tested with WITNESS, MUTEX_PROFILING, INVARIANTS and DIAGNOSTIC). PR: kern/43426, standards/54223 Reviewed by: jake, alc Approved by: jake (mentor) MFC after: 2 weeks Notes: svn path=/head/; revision=118771
* Add fdidx argument to vn_open() and vn_open_cred() and pass -1 throughout.Poul-Henning Kamp2003-07-271-1/+1
| | | | Notes: svn path=/head/; revision=118094
* Use __FBSDID().David E. O'Brien2003-06-111-2/+3
| | | | Notes: svn path=/head/; revision=116182
* Bail out if there were not two loadable sections. Add XXX comment aboutPoul-Henning Kamp2003-05-121-0/+8
| | | | | | | | | one other issue. Approved by: re/rwatson. Notes: svn path=/head/; revision=114946
* Search for "elf32 kernel" (and elf64) and "elf32 module" (and elf64)Peter Wemm2003-04-061-2/+6
| | | | | | | | as well as "elf kernel" and "elf module". This is a precursor to x86-64 support in the i386 loader so it can load an elf64 x86-64 kernel. Notes: svn path=/head/; revision=113158
* Back out M_* changes, per decision of the TRB.Warner Losh2003-02-191-7/+7
| | | | | | | Approved by: trb Notes: svn path=/head/; revision=111119
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.Alfred Perlstein2003-01-211-7/+7
| | | | | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT. Notes: svn path=/head/; revision=109623
* Resolve relative relocations in klds before trying to parse the module'sJake Burkholder2003-01-211-0/+32
| | | | | | | | | | | | | | | metadata. This fixes module dependency resolution by the kernel linker on sparc64, where the relocations for the metadata are different than on other architectures; the relative offset is in the addend of an Elf_Rela record instead of the original value of the location being patched. Also fix printf formats in debug code. Submitted by: Hartmut Brandt <brandt@fokus.gmd.de> PR: 46732 Tested on: alpha (obrien), i386, sparc64 Notes: svn path=/head/; revision=109605
* Merge kld access control checks from the MAC tree: these access controlRobert Watson2002-11-191-0/+9
| | | | | | | | | | | | | | checks permit policy modules to augment the system policy for permitting kld operations. This permits policies to limit access to kld operations based on credential (and other) properties, as well as to perform checks on the kld being loaded (integrity, etc). Approved by: re Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=107089
* Add two hooks to signal module load and module unload to MD code.Marcel Moolenaar2002-10-191-0/+9
| | | | | | | | | | | | | | | The primary reason for this is to allow MD code to process machine specific attributes, segments or sections in the ELF file and update machine specific state accordingly. An immediate use of this is in the ia64 port where unwind information is updated to allow debugging and tracing in/across modules. Note that this commit does not add the functionality to the ia64 port. See revision 1.9 of ia64/ia64/elf_machdep.c. Validated on: alpha, i386, ia64 Notes: svn path=/head/; revision=105469
* Reduce code duplication by moving the common actions inMarcel Moolenaar2002-10-191-58/+56
| | | | | | | | | | | | link_elf_init(), link_elf_link_preload_finish() and link_elf_load_file() to link_elf_link_common_finish(). Since link_elf_init() did initializations as a side-effect of doing the common actions, keep the initialization in that function. Consequently, link_elf_add_gdb() is now also called to insert the very first link_map() (ie the kernel). Notes: svn path=/head/; revision=105468
* Non-functional change in preparation of the next commit:Marcel Moolenaar2002-10-191-41/+36
| | | | | | | | | Move link_elf_add_gdb(), link_elf_delete_gdb() and link_elf_error() near the top of the file. The *_gdb() functions are moved inside the #ifdef DDB already present there. Notes: svn path=/head/; revision=105467
* In link_elf_load_file(), when SPARSE_MAPPING is defined and weMarcel Moolenaar2002-10-191-1/+0
| | | | | | | | | | cannot allocate ef->object, we freed ef before bailing out with an error. This is wrong because ef=lf and when we have an error and lf is non-NULL (which holds if we try to alloc ef->object), we free lf and thus ef as part of the bailing-out. Notes: svn path=/head/; revision=105434
* Fix kernel module loading on ia64. Cross-module function callsMarcel Moolenaar2002-10-151-0/+12
| | | | | | | | | | | | | | | were improperly relocated due to faulty logic in lookup_fdesc() in elf_machdep.c. The symbol index (symidx) was bogusly used for load modules other than the one the relocation applied to. This resulted in bogus bindings and consequently runtime failures. The fix is to use the symbol index only for the module being relocated and to use the symbol name for look-ups in the modules in the dependent list. As such, we need a function to return the symbol name given the linker file and symbol index. Notes: svn path=/head/; revision=105147
* Be consistent about "static" functions: if the function is markedPoul-Henning Kamp2002-09-281-2/+2
| | | | | | | | | static in its prototype, mark it static at the definition too. Inspired by: FlexeLint warning #512 Notes: svn path=/head/; revision=104094
* Add a workaround for what seems to be confusion between binutils and theJake Burkholder2002-09-271-0/+10
| | | | | | | | | | | | | | sparc v9 ABI. The Elf_Rela records for local symbols appear to already have the symbol's value added in to the addend field, even though the ABI specifies we need to lookup the symbol and add its value too. This breaks text relocations in klds because the symbol's value is added twice, and the resulting address points off into nowhere land, so for now just use the addend. Tested by: rwatson Notes: svn path=/head/; revision=104072
* Initiate deorbit burn for the i386-only a.out related support. Moves arePeter Wemm2002-09-171-8/+0
| | | | | | | | | | | | | | | | | | under way to move the remnants of the a.out toolchain to ports. As the comment in src/Makefile said, this stuff is deprecated and one should not expect this to remain beyond 4.0-REL. It has already lasted WAY beyond that. Notable exceptions: gcc - I have not touched the a.out generation stuff there. ldd/ldconfig - still have some code to interface with a.out rtld. old as/ld/etc - I have not removed these yet, pending their move to ports. some includes - necessary for ldd/ldconfig for now. Tested on: i386 (extensively), alpha Notes: svn path=/head/; revision=103436
* Unrot SPARSE_MAPPING code (vm_map_pageable -> vm_map_wire).Jake Burkholder2002-08-291-4/+4
| | | | Notes: svn path=/head/; revision=102547
* Work around a GCC optimization bug on ia64: In link_elf_symbol_values(),Marcel Moolenaar2002-08-241-2/+2
| | | | | | | | | | | | | | | | | | a pointer to a symbol is given and we have to find the containing symbol table. We do this by bounds checking. For some strange reason (ie I haven't found the root cause) the first test succeeded for said symbol, implying that the symbol came from the .dynsym table. In reality however the symbol actually resided in the .symtab table. Needless to say that all that was returned was junk. The upper bounds check was: (symptr - baseptr) < symtab_size This has been rewritten to: symptr < (baseptr + symtab_size) As a side-effect, slightly more optimal (and still correct :-) code can be generated on ia64. Notes: svn path=/head/; revision=102348
* s/sus/sys/ in the a.out kernel case.Peter Wemm2002-08-221-1/+1
| | | | | | | Submitted by: julian Notes: svn path=/head/; revision=102293
* Instead of nlist.h and link.h, use sys/nlist_aout.h and sys/link_elf.hPeter Wemm2002-08-221-2/+2
| | | | | | | | This avoids reaching out into userland sources (or worse: /usr/include!) for building the kernel. Notes: svn path=/head/; revision=102288