| 132 | } |
| 133 | |
| 134 | long SysExec(regs64_t* r){ |
| 135 | process_t* currentProcess = Scheduler::GetCurrentProcess(); |
| 136 | |
| 137 | size_t filePathLength; |
| 138 | long filePathInvalid = strlenSafe(reinterpret_cast<char*>(SC_ARG0(r)), filePathLength, currentProcess->addressSpace); |
| 139 | if(filePathInvalid){ |
| 140 | Log::Warning("SysExec: Reached unallocated memory reading file path"); |
| 141 | return -EFAULT; |
| 142 | } |
| 143 | |
| 144 | char filepath[filePathLength + 1]; |
| 145 | |
| 146 | strncpy(filepath, (char*)SC_ARG0(r), filePathLength); |
| 147 | int argc = SC_ARG1(r); |
| 148 | char** argv = (char**)SC_ARG2(r); |
| 149 | uint64_t flags = SC_ARG3(r); |
| 150 | char** envp = (char**)SC_ARG4(r); |
| 151 | |
| 152 | FsNode* node = fs::ResolvePath(filepath, currentProcess->workingDir, true /* Follow Symlinks */); |
| 153 | if(!node){ |
| 154 | return -ENOENT; |
| 155 | } |
| 156 | |
| 157 | int envCount = 0; |
| 158 | if(envp){ |
| 159 | int i = 0; |
| 160 | while(envp[i]) i++; |
| 161 | envCount = i; |
| 162 | } |
| 163 | |
| 164 | char* kernelEnvp[envCount]; |
| 165 | if(envCount > 0){ |
| 166 | for(int i = 0; i < envCount; i++){ |
| 167 | size_t len; |
| 168 | if(strlenSafe(envp[i], len, currentProcess->addressSpace)){ |
| 169 | Log::Warning("SysExec: Reached unallocated memory reading environment"); |
| 170 | return -EFAULT; |
| 171 | } |
| 172 | kernelEnvp[i] = (char*)kmalloc(len + 1); |
| 173 | strcpy(kernelEnvp[i], envp[i]); |
| 174 | kernelEnvp[i][len] = 0; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | Log::Info("Loading: %s", (char*)SC_ARG0(r)); |
| 179 | timeval_t tv = Timer::GetSystemUptimeStruct(); |
| 180 | uint8_t* buffer = (uint8_t*)kmalloc(node->size); |
| 181 | size_t read = fs::Read(node, 0, node->size, buffer); |
| 182 | if(!read){ |
| 183 | Log::Warning("Could not read file: %s", filepath); |
| 184 | return 0; |
| 185 | } |
| 186 | timeval_t tvnew = Timer::GetSystemUptimeStruct(); |
| 187 | Log::Info("Done (took %d ms)", Timer::TimeDifference(tvnew, tv)); |
| 188 | |
| 189 | char* kernelArgv[argc]; |
| 190 | for(int i = 0; i < argc; i++){ |
| 191 | kernelArgv[i] = (char*)kmalloc(strlen(argv[i]) + 1); |
nothing calls this directly
no test coverage detected