* @brief Populate the auxiliary vector for an ELF-loaded process. * * This function sets up the auxiliary vector that provides essential information * to the ELF executable about the runtime environment. It includes information * about page size, program headers, entry point, and other system-specific details. * * @param load_info Pointer to the structure containing ELF loading information.
| 741 | * executable and its interaction with the runtime environment. |
| 742 | */ |
| 743 | static int elf_aux_fill(elf_load_info_t *load_info) |
| 744 | { |
| 745 | uint8_t *random; |
| 746 | struct process_aux *aux = load_info->aux; |
| 747 | elf_addr_t *aux_info; |
| 748 | uint32_t random_value = rt_tick_get(); |
| 749 | size_t prot = PROT_READ | PROT_WRITE; |
| 750 | size_t flags = MAP_FIXED | MAP_PRIVATE; |
| 751 | rt_lwp_t lwp = load_info->lwp; |
| 752 | void *va; |
| 753 | |
| 754 | if (!aux) |
| 755 | { |
| 756 | LOG_E("%s : aux is null", __func__); |
| 757 | return -1; |
| 758 | } |
| 759 | aux_info = (elf_addr_t *)aux->item; |
| 760 | ELF_AUX_ENT(aux_info, AT_PAGESZ, ARCH_PAGE_SIZE); |
| 761 | |
| 762 | va = lwp_mmap2(lwp, (void *)(USER_VADDR_TOP - ARCH_PAGE_SIZE * 2), ARCH_PAGE_SIZE, prot, flags, -1, 0); |
| 763 | if (!va) |
| 764 | { |
| 765 | LOG_E("lwp map user failed!"); |
| 766 | return -RT_ERROR; |
| 767 | } |
| 768 | random = (uint8_t *)(USER_VADDR_TOP - ARCH_PAGE_SIZE - sizeof(char[16])); |
| 769 | lwp_data_put(load_info->lwp, random, &random_value, sizeof(random_value)); |
| 770 | ELF_AUX_ENT(aux_info, AT_RANDOM, (size_t)random); |
| 771 | ELF_AUX_ENT(aux_info, AT_PHDR, (size_t)load_info->load_addr + load_info->exec_info.ehdr.e_phoff); |
| 772 | ELF_AUX_ENT(aux_info, AT_PHNUM, (size_t)load_info->exec_info.ehdr.e_phnum); |
| 773 | ELF_AUX_ENT(aux_info, AT_PHENT, sizeof(Elf_Phdr)); |
| 774 | ELF_AUX_ENT(aux_info, AT_BASE, load_info->interp_base); |
| 775 | ELF_AUX_ENT(aux_info, AT_FLAGS, 0); |
| 776 | ELF_AUX_ENT(aux_info, AT_ENTRY, load_info->exec_info.ehdr.e_entry); |
| 777 | ELF_AUX_ENT(aux_info, AT_UID, 0); |
| 778 | ELF_AUX_ENT(aux_info, AT_EUID, 0); |
| 779 | ELF_AUX_ENT(aux_info, AT_GID, 0); |
| 780 | ELF_AUX_ENT(aux_info, AT_EGID, 0); |
| 781 | ELF_AUX_ENT(aux_info, AT_HWCAP, 0); |
| 782 | ELF_AUX_ENT(aux_info, AT_CLKTCK, 0); |
| 783 | ELF_AUX_ENT(aux_info, AT_SECURE, 0); |
| 784 | |
| 785 | #ifdef RT_USING_VDSO |
| 786 | if(RT_EOK == arch_setup_additional_pages(load_info->lwp)) |
| 787 | { |
| 788 | ELF_AUX_ENT(aux_info, AT_SYSINFO_EHDR, (size_t)load_info->lwp->vdso_vbase); |
| 789 | } |
| 790 | else |
| 791 | { |
| 792 | LOG_W("vdso map error,VDSO currently only supports aarch64 architecture!"); |
| 793 | } |
| 794 | #endif |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * @brief Load the segments of an ELF file into memory. |
no test coverage detected