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

Function elf_load_ehdr

components/lwp/lwp_elf.c:347–381  ·  view source on GitHub ↗

* @brief Load and validate the ELF header from a file. * * This function opens the ELF file, reads its elf header, and performs basic validation * to ensure it's a valid ELF file. It also retrieves the file size and stores the * file descriptor for subsequent operations. * * @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

345 * @return RT_EOK on success, -RT_ERROR on failure.
346 */
347static int elf_load_ehdr(elf_info_t *elf_info)
348{
349 int ret;
350
351 ret = elf_file_open(elf_info->filename);
352 if (ret < 0)
353 {
354 LOG_E("%s : elf_file_open %s failed", __func__, elf_info->filename);
355 return ret;
356 }
357
358 elf_info->fd = ret;
359
360 ret = elf_file_length(elf_info->filename, &elf_info->file_len);
361 if (ret != RT_EOK)
362 {
363 return -RT_ERROR;
364 }
365
366 ret = elf_file_read(elf_info->fd, (rt_uint8_t *)&elf_info->ehdr, sizeof(Elf_Ehdr), 0);
367 if (ret != RT_EOK)
368 {
369 LOG_E("%s : elf_file_read failed, ret : %d", __func__, ret);
370 return -RT_ERROR;
371 }
372
373 ret = elf_check_ehdr(&elf_info->ehdr, elf_info->file_len);
374 if (ret != RT_EOK)
375 {
376 LOG_E("%s : elf_check_ehdr failed, ret : %d", __func__, ret);
377 return -RT_ERROR;
378 }
379
380 return RT_EOK;
381}
382
383/**
384 * @brief Load the program header table from an ELF file.

Callers 2

elf_load_interpFunction · 0.85
elf_load_appFunction · 0.85

Calls 4

elf_file_openFunction · 0.85
elf_file_lengthFunction · 0.85
elf_file_readFunction · 0.85
elf_check_ehdrFunction · 0.85

Tested by

no test coverage detected