Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/link_elf_obj.c
Show First 20 Lines • Show All 475 Lines • ▼ Show 20 Lines | |||||
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) | ||||
{ | { | ||||
struct nameidata nd; | struct nameidata nd; | ||||
struct thread *td = curthread; /* XXX */ | struct thread *td = curthread; /* XXX */ | ||||
Elf_Ehdr *hdr; | Elf_Ehdr *hdr; | ||||
Elf_Shdr *shdr; | Elf_Shdr *shdr; | ||||
Elf_Sym *es; | Elf_Sym *es; | ||||
char *fullpath, *freepath; | |||||
int nbytes, i, j; | int nbytes, i, j; | ||||
vm_offset_t mapbase; | vm_offset_t mapbase; | ||||
size_t mapsize; | size_t mapsize; | ||||
int error = 0; | int error = 0; | ||||
ssize_t resid; | ssize_t resid; | ||||
int flags; | int flags; | ||||
elf_file_t ef; | elf_file_t ef; | ||||
linker_file_t lf; | linker_file_t lf; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (hdr->e_type != ET_REL) { | ||||
goto out; | goto out; | ||||
} | } | ||||
if (hdr->e_machine != ELF_TARG_MACH) { | if (hdr->e_machine != ELF_TARG_MACH) { | ||||
link_elf_error(filename, "Unsupported machine"); | link_elf_error(filename, "Unsupported machine"); | ||||
error = ENOEXEC; | error = ENOEXEC; | ||||
goto out; | goto out; | ||||
} | } | ||||
lf = linker_make_file(filename, &link_elf_class); | /* Try to get the full path, hwpmc(4) will use it. */ | ||||
jhb: This probably belongs in the caller (note that non-amd64 use link_elf.c to load
modules) | |||||
fabientAuthorUnsubmitted Not Done Inline ActionsDo you mean it is better to resolve filename at upper level even if we need to open file again ? fabient: Do you mean it is better to resolve filename at upper level even if we need to open file again ? | |||||
jhbUnsubmitted Not Done Inline ActionsSo do you have a use case where the filename isn't already the full path? linker_load_module() in kern_linker.c already passes the pathname (not the basename) to this function. jhb: So do you have a use case where the filename isn't already the full path? linker_load_module()… | |||||
fullpath = __DECONST(char *, filename); | |||||
freepath = NULL; | |||||
vn_fullpath(td, nd.ni_vp, &fullpath, &freepath); | |||||
lf = linker_make_file(fullpath, &link_elf_class); | |||||
free(freepath, M_TEMP); | |||||
if (!lf) { | if (!lf) { | ||||
error = ENOMEM; | error = ENOMEM; | ||||
goto out; | goto out; | ||||
} | } | ||||
ef = (elf_file_t) lf; | ef = (elf_file_t) lf; | ||||
ef->nprogtab = 0; | ef->nprogtab = 0; | ||||
ef->e_shdr = 0; | ef->e_shdr = 0; | ||||
ef->nreltab = 0; | ef->nreltab = 0; | ||||
▲ Show 20 Lines • Show All 945 Lines • Show Last 20 Lines |
This probably belongs in the caller (note that non-amd64 use link_elf.c to load
modules)