* @brief Calculate the total size required to map all loadable ELF segments. * * @param elf_info Pointer to the ELF file information structure. * @return 0 on success, -1 if no loadable segments are found. */
| 524 | * @return 0 on success, -1 if no loadable segments are found. |
| 525 | */ |
| 526 | static int total_mapping_size(elf_info_t *elf_info) |
| 527 | { |
| 528 | int i; |
| 529 | int first_idx = -1; |
| 530 | int last_idx = -1; |
| 531 | |
| 532 | for (i = 0; i < elf_info->ehdr.e_phnum; i++) |
| 533 | { |
| 534 | if (elf_info->phdr[i].p_type == PT_LOAD) |
| 535 | { |
| 536 | last_idx = i; |
| 537 | if (first_idx == -1) |
| 538 | first_idx = i; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | if (first_idx == -1) |
| 543 | return -1; |
| 544 | |
| 545 | elf_info->map_size = elf_info->phdr[last_idx].p_vaddr + elf_info->phdr[last_idx].p_memsz - |
| 546 | ELF_PAGESTART(elf_info->phdr[first_idx].p_vaddr); |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * @brief Map an ELF segment into the process's address space. |
no outgoing calls
no test coverage detected