FreeBSD kernel kern code
|
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_gdb.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/mount.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/namei.h>
#include <sys/fcntl.h>
#include <sys/vnode.h>
#include <sys/linker.h>
#include <sys/sysctl.h>
#include <machine/elf.h>
#include <net/vnet.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <sys/link_elf.h>
#include "linker_if.h"
#include <kern/kern_ctf.c>
Go to the source code of this file.
Data Structures | |
struct | elf_file |
struct | elf_set |
Macros | |
#define | MAXSEGS 4 |
#define | LS_PADDING 0x90909090 |
#define | APPLY_RELOCS(iter, tbl, tblsize, type) |
Typedefs | |
typedef struct elf_file * | elf_file_t |
typedef int(* | elf_reloc_fn) (linker_file_t lf, Elf_Addr relocbase, const void *data, int type, elf_lookup_fn lookup) |
Functions | |
__FBSDID ("$FreeBSD$") | |
TAILQ_HEAD (elf_set_head, elf_set) | |
static int | link_elf_link_common_finish (linker_file_t) |
static int | link_elf_link_preload (linker_class_t cls, const char *, linker_file_t *) |
static int | link_elf_link_preload_finish (linker_file_t) |
static int | link_elf_load_file (linker_class_t, const char *, linker_file_t *) |
static int | link_elf_lookup_symbol (linker_file_t, const char *, c_linker_sym_t *) |
static int | link_elf_lookup_debug_symbol (linker_file_t, const char *, c_linker_sym_t *) |
static int | link_elf_symbol_values (linker_file_t, c_linker_sym_t, linker_symval_t *) |
static int | link_elf_debug_symbol_values (linker_file_t, c_linker_sym_t, linker_symval_t *) |
static int | link_elf_search_symbol (linker_file_t, caddr_t, c_linker_sym_t *, long *) |
static void | link_elf_unload_file (linker_file_t) |
static void | link_elf_unload_preload (linker_file_t) |
static int | link_elf_lookup_set (linker_file_t, const char *, void ***, void ***, int *) |
static int | link_elf_each_function_name (linker_file_t, int(*)(const char *, void *), void *) |
static int | link_elf_each_function_nameval (linker_file_t, linker_function_nameval_callback_t, void *) |
static void | link_elf_reloc_local (linker_file_t) |
static long | link_elf_symtab_get (linker_file_t, const Elf_Sym **) |
static long | link_elf_strtab_get (linker_file_t, caddr_t *) |
static int | elf_lookup (linker_file_t, Elf_Size, int, Elf_Addr *) |
SYSCTL_BOOL (_debug, OID_AUTO, link_elf_leak_locals, CTLFLAG_RWTUN, &link_elf_leak_locals, 0, "Allow local symbols to participate in global module symbol resolution") | |
static int | parse_dynamic (elf_file_t) |
static int | relocate_file (elf_file_t) |
static int | relocate_file1 (elf_file_t ef, elf_lookup_fn lookup, elf_reloc_fn reloc, bool ifuncs) |
static int | link_elf_preload_parse_symbols (elf_file_t) |
static void | elf_set_add (struct elf_set_head *list, Elf_Addr start, Elf_Addr stop, Elf_Addr base) |
static int | elf_set_find (struct elf_set_head *list, Elf_Addr addr, Elf_Addr *start, Elf_Addr *base) |
static void | elf_set_delete (struct elf_set_head *list, Elf_Addr start) |
static void | link_elf_error (const char *filename, const char *s) |
static void | link_elf_invoke_ctors (caddr_t addr, size_t size) |
SYSCTL_ULONG (_kern, OID_AUTO, base_address, CTLFLAG_RD, SYSCTL_NULL_ULONG_PTR, KERNBASE, "Kernel base address") | |
SYSCTL_ULONG (_kern, OID_AUTO, relbase_address, CTLFLAG_RD, &kern_relbase, 0, "Kernel relocated base address") | |
static void | link_elf_init (void *arg) |
SYSINIT (link_elf, SI_SUB_KLD, SI_ORDER_THIRD, link_elf_init, NULL) | |
static int | parse_dpcpu (elf_file_t ef) |
static int | preload_protect (elf_file_t ef, vm_prot_t prot) |
Elf_Addr | elf_relocaddr (linker_file_t lf, Elf_Addr x) |
static const char * | symbol_name (elf_file_t ef, Elf_Size r_info) |
static int | symbol_type (elf_file_t ef, Elf_Size r_info) |
static unsigned long | elf_hash (const char *name) |
static int | link_elf_lookup_symbol1 (linker_file_t lf, const char *name, c_linker_sym_t *sym, bool see_local) |
static int | link_elf_symbol_values1 (linker_file_t lf, c_linker_sym_t sym, linker_symval_t *symval, bool see_local) |
const Elf_Sym * | elf_get_sym (linker_file_t lf, Elf_Size symidx) |
const char * | elf_get_symname (linker_file_t lf, Elf_Size symidx) |
Variables | |
static kobj_method_t | link_elf_methods [] |
static struct linker_class | link_elf_class |
static bool | link_elf_leak_locals = true |
static struct elf_set_head | set_pcpu_list |
struct _dynamic | _DYNAMIC |
static unsigned long | kern_relbase = KERNBASE |
#define APPLY_RELOCS | ( | iter, | |
tbl, | |||
tblsize, | |||
type | |||
) |
#define LS_PADDING 0x90909090 |
Definition at line 654 of file link_elf.c.
#define MAXSEGS 4 |
Definition at line 76 of file link_elf.c.
typedef struct elf_file * elf_file_t |
typedef int(* elf_reloc_fn) (linker_file_t lf, Elf_Addr relocbase, const void *data, int type, elf_lookup_fn lookup) |
Definition at line 202 of file link_elf.c.
__FBSDID | ( | "$FreeBSD$" | ) |
const Elf_Sym * elf_get_sym | ( | linker_file_t | lf, |
Elf_Size | symidx | ||
) |
Definition at line 1791 of file link_elf.c.
References elf_file::nchains, and elf_file::symtab.
const char * elf_get_symname | ( | linker_file_t | lf, |
Elf_Size | symidx | ||
) |
Definition at line 1801 of file link_elf.c.
References elf_file::nchains, elf_file::strtab, sym, and elf_file::symtab.
|
static |
Definition at line 1488 of file link_elf.c.
References name.
Referenced by link_elf_lookup_symbol1().
|
static |
Definition at line 1820 of file link_elf.c.
References addr, elf_file::address, elf_set_find(), linker_file_lookup_symbol(), elf_file::nchains, res, set_pcpu_list, start, elf_file::strtab, sym, and elf_file::symtab.
Referenced by link_elf_reloc_local(), and relocate_file().
Elf_Addr elf_relocaddr | ( | linker_file_t | lf, |
Elf_Addr | x | ||
) |
Definition at line 1338 of file link_elf.c.
References link_elf_class, elf_file::pcpu_base, and elf_file::pcpu_start.
|
static |
Definition at line 217 of file link_elf.c.
References elf_set::es_start, elf_set::es_stop, malloc(), set, start, and stop.
Referenced by parse_dpcpu().
|
static |
Definition at line 262 of file link_elf.c.
References elf_set::es_start, free(), set, and start.
Referenced by link_elf_unload_file().
|
static |
Definition at line 244 of file link_elf.c.
References elf_set::es_start, elf_set::es_stop, set, and start.
Referenced by elf_lookup().
|
static |
Definition at line 1628 of file link_elf.c.
References elf_file::address, elf_file::ddbstrtab, elf_file::ddbsymcnt, elf_file::ddbsymtab, link_elf_symbol_values1(), sym, and elf_file::symtab.
Referenced by link_elf_each_function_nameval(), and link_elf_symbol_values().
|
static |
Definition at line 1745 of file link_elf.c.
References callback, elf_file::ddbstrtab, elf_file::ddbsymtab, opaque, and symp.
|
static |
Definition at line 1766 of file link_elf.c.
References callback, elf_file::ddbsymtab, link_elf_debug_symbol_values(), opaque, and symp.
|
static |
Definition at line 343 of file link_elf.c.
References filename, and printf().
Referenced by link_elf_load_file().
|
static |
Definition at line 428 of file link_elf.c.
References __ELF_WORD_SIZE, _DYNAMIC, elf_file::address, elf_file::dynamic, kern_relbase, link_elf_class, link_elf_link_common_finish(), link_elf_preload_parse_symbols(), linker_add_class(), linker_kernel_file, linker_make_file(), elf_file::modptr, elf_file::object, panic(), parse_dynamic(), preload_search_by_type(), preload_search_info(), elf_file::preloaded, and set_pcpu_list.
|
static |
Definition at line 352 of file link_elf.c.
References addr.
Referenced by link_elf_link_common_finish().
|
static |
Definition at line 372 of file link_elf.c.
References elf_file::address, elf_file::dynamic, link_elf_invoke_ctors(), and malloc().
Referenced by link_elf_init(), link_elf_link_preload_finish(), and link_elf_load_file().
|
static |
Definition at line 858 of file link_elf.c.
References __ELF_WORD_SIZE, elf_file::address, elf_file::dynamic, filename, link_elf_class, link_elf_reloc_local(), linker_file_unload(), linker_make_file(), elf_file::modptr, elf_file::object, parse_dpcpu(), parse_dynamic(), preload_protect(), preload_search_by_name(), preload_search_info(), elf_file::preloaded, result, and type.
|
static |
Definition at line 935 of file link_elf.c.
References link_elf_link_common_finish(), link_elf_preload_parse_symbols(), preload_protect(), and relocate_file().
|
static |
Definition at line 952 of file link_elf.c.
References elf_file::address, elf_file::ddbstrcnt, elf_file::ddbstrtab, elf_file::ddbsymcnt, elf_file::ddbsymtab, elf_file::dynamic, filename, flags, free(), Giant, link_elf_class, link_elf_error(), link_elf_link_common_finish(), link_elf_reloc_local(), linker_file_unload(), linker_load_dependencies(), linker_make_file(), malloc(), malloc_exec(), MAXSEGS, nbytes, NDFREE(), elf_file::object, parse_dpcpu(), parse_dynamic(), relocate_file(), result, elf_file::strbase, elf_file::symbase, vn_close(), vn_open(), and vn_rdwr().
|
static |
Definition at line 1566 of file link_elf.c.
References elf_file::ddbstrtab, elf_file::ddbsymtab, link_elf_lookup_symbol1(), name, sym, and symp.
Referenced by link_elf_lookup_symbol().
|
static |
Definition at line 1692 of file link_elf.c.
References count, free(), link_elf_lookup_symbol(), link_elf_symbol_values(), malloc(), name, snprintf(), start, stop, and sym.
Referenced by parse_dpcpu().
|
static |
Definition at line 1558 of file link_elf.c.
References link_elf_leak_locals, link_elf_lookup_debug_symbol(), link_elf_lookup_symbol1(), name, and sym.
Referenced by link_elf_lookup_set().
|
static |
Definition at line 1504 of file link_elf.c.
References elf_file::buckets, elf_file::chains, elf_hash(), name, elf_file::nbuckets, elf_file::nchains, printf(), elf_file::strtab, sym, symp, and elf_file::symtab.
Referenced by link_elf_lookup_debug_symbol(), and link_elf_lookup_symbol().
|
static |
Definition at line 513 of file link_elf.c.
References elf_file::ddbstrcnt, elf_file::ddbstrtab, elf_file::ddbsymcnt, elf_file::ddbsymtab, elf_file::modptr, preload_search_info(), printf(), strtab, and symtab.
Referenced by link_elf_init(), and link_elf_link_preload_finish().
|
static |
Definition at line 1881 of file link_elf.c.
References elf_file::address, elf_lookup(), elf_file::rel, elf_file::rela, elf_file::relasize, and elf_file::relsize.
Referenced by link_elf_link_preload(), and link_elf_load_file().
|
static |
Definition at line 1653 of file link_elf.c.
References elf_file::address, elf_file::ddbsymtab, diffp, sym, and value.
|
static |
Definition at line 1925 of file link_elf.c.
References elf_file::ddbstrcnt, elf_file::ddbstrtab, and strtab.
|
static |
Definition at line 1619 of file link_elf.c.
References link_elf_debug_symbol_values(), link_elf_leak_locals, link_elf_symbol_values1(), and sym.
Referenced by link_elf_lookup_set().
|
static |
Definition at line 1595 of file link_elf.c.
References elf_file::address, elf_file::nchains, elf_file::strtab, sym, elf_file::symtab, and symtab.
Referenced by link_elf_debug_symbol_values(), and link_elf_symbol_values().
|
static |
Definition at line 1912 of file link_elf.c.
References elf_file::ddbsymcnt, elf_file::ddbsymtab, and symtab.
|
static |
Definition at line 1356 of file link_elf.c.
References elf_file::address, elf_file::ctfoff, elf_file::ctftab, dpcpu_free(), elf_set_delete(), free(), link_elf_unload_preload(), elf_file::object, elf_file::pcpu_base, elf_file::pcpu_start, elf_file::pcpu_stop, elf_file::preloaded, set_pcpu_list, elf_file::strbase, elf_file::symbase, and elf_file::typoff.
|
static |
Definition at line 1406 of file link_elf.c.
References preload_delete_name().
Referenced by link_elf_unload_file().
|
static |
Definition at line 656 of file link_elf.c.
References dpcpu_alloc(), dpcpu_copy(), elf_set_add(), elf_file::lf, link_elf_lookup_set(), LS_PADDING, elf_file::pcpu_base, elf_file::pcpu_start, elf_file::pcpu_stop, printf(), set_pcpu_list, and uprintf().
Referenced by link_elf_link_preload(), and link_elf_load_file().
|
static |
Definition at line 566 of file link_elf.c.
References elf_file::address, elf_file::buckets, elf_file::chains, elf_file::ddbstrcnt, elf_file::ddbstrtab, elf_file::ddbsymcnt, elf_file::ddbsymtab, elf_file::dynamic, elf_file::got, elf_file::nbuckets, elf_file::nchains, elf_file::pltrel, elf_file::pltrela, elf_file::pltrelasize, elf_file::pltrelsize, elf_file::rel, elf_file::rela, elf_file::relasize, elf_file::relsize, elf_file::strsz, elf_file::strtab, and elf_file::symtab.
Referenced by link_elf_init(), link_elf_link_preload(), and link_elf_load_file().
|
static |
Definition at line 781 of file link_elf.c.
References elf_file::address.
Referenced by link_elf_link_preload(), and link_elf_link_preload_finish().
|
static |
Definition at line 1473 of file link_elf.c.
References elf_lookup(), and relocate_file1().
Referenced by link_elf_link_preload_finish(), and link_elf_load_file().
|
static |
Definition at line 1438 of file link_elf.c.
References APPLY_RELOCS, elf_file::pltrel, elf_file::pltrela, elf_file::pltrelasize, elf_file::pltrelsize, elf_file::rel, elf_file::rela, elf_file::relasize, and elf_file::relsize.
Referenced by relocate_file().
|
static |
Definition at line 1414 of file link_elf.c.
References elf_file::strtab, and elf_file::symtab.
Referenced by mi_startup().
|
static |
Definition at line 1426 of file link_elf.c.
References elf_file::symtab.
SYSCTL_BOOL | ( | _debug | , |
OID_AUTO | , | ||
link_elf_leak_locals | , | ||
CTLFLAG_RWTUN | , | ||
& | link_elf_leak_locals, | ||
0 | , | ||
"Allow local symbols to participate in global module symbol resolution" | |||
) |
SYSCTL_ULONG | ( | _kern | , |
OID_AUTO | , | ||
base_address | , | ||
CTLFLAG_RD | , | ||
SYSCTL_NULL_ULONG_PTR | , | ||
KERNBASE | , | ||
"Kernel base address" | |||
) |
SYSCTL_ULONG | ( | _kern | , |
OID_AUTO | , | ||
relbase_address | , | ||
CTLFLAG_RD | , | ||
& | kern_relbase, | ||
0 | , | ||
"Kernel relocated base address" | |||
) |
SYSINIT | ( | link_elf | , |
SI_SUB_KLD | , | ||
SI_ORDER_THIRD | , | ||
link_elf_init | , | ||
NULL | |||
) |
TAILQ_HEAD | ( | elf_set_head | , |
elf_set | |||
) |
|
extern |
Referenced by link_elf_init().
|
static |
Definition at line 420 of file link_elf.c.
Referenced by link_elf_init().
|
static |
Definition at line 188 of file link_elf.c.
Referenced by elf_relocaddr(), link_elf_init(), link_elf_link_preload(), and link_elf_load_file().
|
static |
Definition at line 197 of file link_elf.c.
Referenced by link_elf_lookup_symbol(), and link_elf_symbol_values().
|
static |
Definition at line 169 of file link_elf.c.
|
static |
Definition at line 211 of file link_elf.c.
Referenced by elf_lookup(), link_elf_init(), link_elf_unload_file(), and parse_dpcpu().