* @brief Load an ELF executable file into memory and prepare it for execution. * * This function is responsible for loading an ELF format executable file into memory, * setting up the necessary process structures, and preparing it for execution. * * @param filename The path to the ELF file to be loaded. * @param lwp Pointer to the Light Weight Process (LWP) structure that will execute the pr
| 1015 | * @see dfs_normalize_path, elf_file_load |
| 1016 | */ |
| 1017 | int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr, size_t addr_size, |
| 1018 | struct process_aux *aux_ua) |
| 1019 | { |
| 1020 | elf_load_info_t load_info = { 0 }; |
| 1021 | int len; |
| 1022 | int ret; |
| 1023 | |
| 1024 | /* Validate input filename */ |
| 1025 | if (filename == RT_NULL) |
| 1026 | { |
| 1027 | LOG_E("%s : file is NULL", __func__); |
| 1028 | return -RT_ERROR; |
| 1029 | } |
| 1030 | |
| 1031 | /* Check filename length constraints */ |
| 1032 | len = rt_strlen(filename); |
| 1033 | if (len < FLF_PATH_MIN || len > ELF_PATH_MAX) |
| 1034 | { |
| 1035 | LOG_E("%s : file length (%d) invalid", __func__, len); |
| 1036 | return -RT_ERROR; |
| 1037 | } |
| 1038 | |
| 1039 | /* Allocate memory for filename and copy it */ |
| 1040 | load_info.exec_info.filename = rt_malloc(len + 1); |
| 1041 | if (!load_info.exec_info.filename) |
| 1042 | { |
| 1043 | LOG_E("%s : alloc filename failed", __func__, len); |
| 1044 | return -RT_ERROR; |
| 1045 | } |
| 1046 | else |
| 1047 | { |
| 1048 | rt_memset(load_info.exec_info.filename, 0, len + 1); |
| 1049 | rt_strncpy(load_info.exec_info.filename, filename, len); |
| 1050 | } |
| 1051 | |
| 1052 | /* Initialize load information structure */ |
| 1053 | load_info.lwp = lwp; |
| 1054 | load_info.aux = aux_ua; |
| 1055 | |
| 1056 | load_info.exec_info.fd = ELF_INVALID_FD; |
| 1057 | load_info.interp_info.fd = ELF_INVALID_FD; |
| 1058 | load_info.load_addr = (rt_ubase_t)load_addr; |
| 1059 | |
| 1060 | /* copy file name to process name */ |
| 1061 | rt_strncpy(lwp->cmd, filename, RT_NAME_MAX); |
| 1062 | lwp->exe_file = dfs_normalize_path(NULL, filename); /* malloc */ |
| 1063 | |
| 1064 | /* Load and process the ELF file */ |
| 1065 | ret = elf_file_load(&load_info); |
| 1066 | if (ret != RT_EOK) |
| 1067 | { |
| 1068 | LOG_E("%s : elf_file_load error, ret : %d", __func__, ret); |
| 1069 | return ret; |
| 1070 | } |
| 1071 | |
| 1072 | return RT_EOK; |
| 1073 | } |
| 1074 |
no test coverage detected