MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / elf_load_phdr

Function elf_load_phdr

components/lwp/lwp_elf.c:392–431  ·  view source on GitHub ↗

* @brief Load the program header table from an ELF file. * * This function reads and validates the program header table from the ELF file. * It ensures the program header table is properly aligned and within the file bounds. * * @param elf_info Pointer to the ELF file information structure. * @return RT_EOK on success, -RT_ERROR on failure. */

Source from the content-addressed store, hash-verified

390 * @return RT_EOK on success, -RT_ERROR on failure.
391 */
392static int elf_load_phdr(elf_info_t *elf_info)
393{
394 Elf_Ehdr *ehdr = &elf_info->ehdr;
395 uint32_t size;
396 int ret;
397
398 if (ehdr->e_phnum < 1)
399 {
400 return -RT_ERROR;
401 }
402
403 if (ehdr->e_phentsize != sizeof(Elf_Phdr))
404 {
405 return -RT_ERROR;
406 }
407
408 size = sizeof(Elf_Phdr) * ehdr->e_phnum;
409 if ((ehdr->e_phoff + size) > elf_info->file_len)
410 {
411 return -RT_ERROR;
412 }
413
414 elf_info->phdr = rt_malloc(size);
415 if (elf_info->phdr == RT_NULL)
416 {
417 LOG_E("%s : alloc phdr failed", __func__);
418 return -RT_ENOMEM;
419 }
420
421 ret = elf_file_read(elf_info->fd, (rt_uint8_t *)elf_info->phdr, size, ehdr->e_phoff);
422 if (ret != RT_EOK)
423 {
424 rt_free(elf_info->phdr);
425 elf_info->phdr = RT_NULL;
426 LOG_E("%s : elf_file_read failed, ret = %d", __func__, ret);
427 return -RT_ERROR;
428 }
429
430 return RT_EOK;
431}
432
433/**
434 * @brief Load the ELF interpreter specified in the program header.

Callers 2

elf_load_interpFunction · 0.85
elf_load_appFunction · 0.85

Calls 3

rt_mallocFunction · 0.85
elf_file_readFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected