* @brief Map a file into the process's address space. * * This function maps a file into the process's virtual memory using the specified * address, size, protection flags, and offset. It ensures the mapping is properly * aligned and verifies the mapping operation. * * @param lwp Pointer to the Light Weight Process (LWP) structure. * @param fd File descriptor of the file to map. * @param l
| 169 | * @return Virtual address where the file is mapped on success, NULL on failure. |
| 170 | */ |
| 171 | static void *file_mmap(struct rt_lwp *lwp, int fd, rt_ubase_t load_addr, |
| 172 | rt_ubase_t map_size, size_t prot, size_t flags, rt_ubase_t offset) |
| 173 | { |
| 174 | uint8_t *map_va; |
| 175 | |
| 176 | map_va = (uint8_t *)lwp_mmap2(lwp, (void *)load_addr, map_size, prot, flags, fd, offset >> ARCH_PAGE_SHIFT); |
| 177 | if (!map_va || (map_va != (uint8_t *)load_addr)) |
| 178 | { |
| 179 | LOG_E("%s : lwp map user failed!", __func__); |
| 180 | return RT_NULL; |
| 181 | } |
| 182 | LOG_D(" %s : map va = %p load_addr : %p size : 0x%x", __func__, map_va, load_addr, map_size); |
| 183 | |
| 184 | return map_va; |
| 185 | } |
| 186 | |
| 187 | static int elf_file_open(const char *filename) |
| 188 | { |