Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/link_elf_obj.c
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static void | static void | ||||
link_elf_init(void *arg) | link_elf_init(void *arg) | ||||
{ | { | ||||
linker_add_class(&link_elf_class); | linker_add_class(&link_elf_class); | ||||
} | } | ||||
SYSINIT(link_elf_obj, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, NULL); | SYSINIT(link_elf_obj, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, NULL); | ||||
static void | static void | ||||
link_elf_protect_range(elf_file_t ef, vm_offset_t start, vm_offset_t end, | link_elf_protect_range(elf_file_t ef, vm_offset_t start, vm_offset_t end, | ||||
vm_prot_t prot) | vm_prot_t prot) | ||||
{ | { | ||||
int error __unused; | int error __unused; | ||||
KASSERT(start <= end && start >= (vm_offset_t)ef->address && | KASSERT(start <= end && start >= (vm_offset_t)ef->address && | ||||
end <= round_page((vm_offset_t)ef->address + ef->lf.size), | end <= round_page((vm_offset_t)ef->address + ef->lf.size), | ||||
("link_elf_protect_range: invalid range %#jx-%#jx", | ("link_elf_protect_range: invalid range %#jx-%#jx", | ||||
(uintmax_t)start, (uintmax_t)end)); | (uintmax_t)start, (uintmax_t)end)); | ||||
if (start == end) | if (start == end) | ||||
return; | return; | ||||
if (ef->preloaded) { | |||||
#ifdef __amd64__ | |||||
error = pmap_change_prot(start, end - start, prot); | |||||
KASSERT(error == 0, | |||||
("link_elf_protect_range: pmap_change_prot() returned %d", | |||||
error)); | |||||
#endif | |||||
return; | |||||
} | |||||
error = vm_map_protect(kernel_map, start, end, prot, FALSE); | error = vm_map_protect(kernel_map, start, end, prot, FALSE); | ||||
KASSERT(error == KERN_SUCCESS, | KASSERT(error == KERN_SUCCESS, | ||||
("link_elf_protect_range: vm_map_protect() returned %d", error)); | ("link_elf_protect_range: vm_map_protect() returned %d", error)); | ||||
} | } | ||||
/* | /* | ||||
* Restrict permissions on linker file memory based on section flags. | * Restrict permissions on linker file memory based on section flags. | ||||
* Sections need not be page-aligned, so overlap within a page is possible. | * Sections need not be page-aligned, so overlap within a page is possible. | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | if (rl != ef->nreltab) { | ||||
goto out; | goto out; | ||||
} | } | ||||
if (ra != ef->nrelatab) { | if (ra != ef->nrelatab) { | ||||
printf("%s: lost relatab\n", filename); | printf("%s: lost relatab\n", filename); | ||||
error = ENOEXEC; | error = ENOEXEC; | ||||
goto out; | goto out; | ||||
} | } | ||||
/* | |||||
* The file needs to be writeable and executable while applying | |||||
* relocations. Mapping protections are applied once relocation | |||||
* processing is complete. | |||||
*/ | |||||
link_elf_protect_range(ef, (vm_offset_t)ef->address, | |||||
round_page((vm_offset_t)ef->address + ef->lf.size), VM_PROT_ALL); | |||||
/* Local intra-module relocations */ | /* Local intra-module relocations */ | ||||
error = link_elf_reloc_local(lf, false); | error = link_elf_reloc_local(lf, false); | ||||
if (error != 0) | if (error != 0) | ||||
goto out; | goto out; | ||||
*result = lf; | *result = lf; | ||||
return (0); | return (0); | ||||
out: | out: | ||||
Show All 36 Lines | |||||
#if defined(__i386__) || defined(__amd64__) | #if defined(__i386__) || defined(__amd64__) | ||||
/* Now ifuncs. */ | /* Now ifuncs. */ | ||||
error = link_elf_reloc_local(lf, true); | error = link_elf_reloc_local(lf, true); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
#endif | #endif | ||||
/* Invoke .ctors */ | /* Apply protections now that relocation processing is complete. */ | ||||
link_elf_protect(ef); | |||||
link_elf_invoke_ctors(lf->ctors_addr, lf->ctors_size); | link_elf_invoke_ctors(lf->ctors_addr, lf->ctors_size); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
link_elf_load_file(linker_class_t cls, const char *filename, | link_elf_load_file(linker_class_t cls, const char *filename, | ||||
linker_file_t *result) | linker_file_t *result) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,092 Lines • Show Last 20 Lines |