thread_id load_image(int32 argCount, const char **args, const char **environ) { char invoker[B_FILE_NAME_LENGTH]; char **newArgs = NULL; int32 envCount = 0; thread_id thread; if (argCount < 1 || environ == NULL) return B_BAD_VALUE; // test validity of executable + support for scripts { status_t status = __test_executable(args[0], invoker); if (status < B_OK) return status; if (invoker[0]) { status = __parse_invoke_line(invoker, &newArgs, (char * const **)&args, &argCount, args[0]); if (status < B_OK) return status; } } // count environment variables while (environ[envCount] != NULL) envCount++; char** flatArgs = NULL; size_t flatArgsSize; status_t status = __flatten_process_args(args, argCount, environ, envCount, &flatArgs, &flatArgsSize); if (status == B_OK) { thread = _kern_load_image(flatArgs, flatArgsSize, argCount, envCount, B_NORMAL_PRIORITY, B_WAIT_TILL_LOADED, -1, 0); free(flatArgs); } else thread = status; free(newArgs); return thread; }
/*static*/ thread_id BTeamDebugger::_LoadProgram(const char* const* args, int32 argCount, bool traceLoading) { // clone the argument vector so that we can change it const char** mutableArgs = new const char*[argCount]; for (int i = 0; i < argCount; i++) mutableArgs[i] = args[i]; // resolve the program path BPath programPath; status_t error = _FindProgram(args[0], programPath); if (error != B_OK) { delete[] mutableArgs; return error; } mutableArgs[0] = programPath.Path(); // count environment variables int32 envCount = 0; while (environ[envCount] != NULL) envCount++; // flatten the program args and environment char** flatArgs = NULL; size_t flatArgsSize; error = __flatten_process_args(mutableArgs, argCount, environ, &envCount, mutableArgs[0], &flatArgs, &flatArgsSize); // load the program thread_id thread; if (error == B_OK) { thread = _kern_load_image(flatArgs, flatArgsSize, argCount, envCount, B_NORMAL_PRIORITY, (traceLoading ? 0 : B_WAIT_TILL_LOADED), -1, 0); free(flatArgs); } else thread = error; delete[] mutableArgs; return thread; }