MCPcopy Create free account
hub / github.com/F-Stack/f-stack / link_elf_link_preload

Function link_elf_link_preload

freebsd/kern/link_elf_obj.c:323–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321}
322
323static int
324link_elf_link_preload(linker_class_t cls, const char *filename,
325 linker_file_t *result)
326{
327 Elf_Ehdr *hdr;
328 Elf_Shdr *shdr;
329 Elf_Sym *es;
330 void *modptr, *baseptr, *sizeptr;
331 char *type;
332 elf_file_t ef;
333 linker_file_t lf;
334 Elf_Addr off;
335 int error, i, j, pb, ra, rl, shstrindex, symstrindex, symtabindex;
336
337 /* Look to see if we have the file preloaded */
338 modptr = preload_search_by_name(filename);
339 if (modptr == NULL)
340 return ENOENT;
341
342 type = (char *)preload_search_info(modptr, MODINFO_TYPE);
343 baseptr = preload_search_info(modptr, MODINFO_ADDR);
344 sizeptr = preload_search_info(modptr, MODINFO_SIZE);
345 hdr = (Elf_Ehdr *)preload_search_info(modptr, MODINFO_METADATA |
346 MODINFOMD_ELFHDR);
347 shdr = (Elf_Shdr *)preload_search_info(modptr, MODINFO_METADATA |
348 MODINFOMD_SHDR);
349 if (type == NULL || (strcmp(type, "elf" __XSTRING(__ELF_WORD_SIZE)
350 " obj module") != 0 &&
351 strcmp(type, "elf obj module") != 0)) {
352 return (EFTYPE);
353 }
354 if (baseptr == NULL || sizeptr == NULL || hdr == NULL ||
355 shdr == NULL)
356 return (EINVAL);
357
358 lf = linker_make_file(filename, &link_elf_class);
359 if (lf == NULL)
360 return (ENOMEM);
361
362 ef = (elf_file_t)lf;
363 ef->preloaded = 1;
364 ef->address = *(caddr_t *)baseptr;
365 lf->address = *(caddr_t *)baseptr;
366 lf->size = *(size_t *)sizeptr;
367
368 if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS ||
369 hdr->e_ident[EI_DATA] != ELF_TARG_DATA ||
370 hdr->e_ident[EI_VERSION] != EV_CURRENT ||
371 hdr->e_version != EV_CURRENT ||
372 hdr->e_type != ET_REL ||
373 hdr->e_machine != ELF_TARG_MACH) {
374 error = EFTYPE;
375 goto out;
376 }
377 ef->e_shdr = shdr;
378
379 /* Scan the section header for information and table sizing. */
380 symtabindex = -1;

Callers

nothing calls this directly

Calls 14

preload_search_by_nameFunction · 0.85
preload_search_infoFunction · 0.85
strcmpFunction · 0.85
linker_make_fileFunction · 0.85
mallocFunction · 0.85
dpcpu_allocFunction · 0.85
dpcpu_copyFunction · 0.85
vnet_data_allocFunction · 0.85
vnet_data_copyFunction · 0.85
link_elf_protect_rangeFunction · 0.85
linker_file_unloadFunction · 0.85
printfFunction · 0.70

Tested by

no test coverage detected