Changeset 27348 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Mar 14, 2010 6:36:53 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r27017 r27348 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Process, Win 32.3 * IPRT - Process, Windows. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Sun Microsystems, Inc.7 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 51 51 * calling convention. 52 52 */ 53 typedef struct _PEB { 53 typedef struct _PEB 54 { 54 55 BYTE Reserved1[2]; 55 56 BYTE BeingDebugged; … … 59 60 } PEB, *PPEB; 60 61 61 typedef struct _PROCESS_BASIC_INFORMATION { 62 typedef struct _PROCESS_BASIC_INFORMATION 63 { 62 64 PVOID Reserved1; 63 65 PPEB PebBaseAddress; … … 67 69 } PROCESS_BASIC_INFORMATION; 68 70 69 typedef enum _PROCESSINFOCLASS { 71 typedef enum _PROCESSINFOCLASS 72 { 70 73 ProcessBasicInformation = 0, 71 74 ProcessWow64Information = 26 … … 73 76 74 77 extern "C" LONG WINAPI 75 NtQueryInformationProcess 78 NtQueryInformationProcess( 76 79 IN HANDLE ProcessHandle, 77 80 IN PROCESSINFOCLASS ProcessInformationClass, 78 81 OUT PVOID ProcessInformation, 79 82 IN ULONG ProcessInformationLength, 80 OUT PULONG ReturnLength OPTIONAL 81 ); 83 OUT PULONG ReturnLength OPTIONAL); 82 84 83 85 /** @todo r=michael This function currently does not work correctly if the arguments … … 163 165 PRTPROCESS phProcess) 164 166 { 167 #if 0 /* needs more work... dinner time. */ 168 int rc; 169 170 /* 171 * Input validation 172 */ 173 AssertPtrReturn(pszExec, VERR_INVALID_POINTER); 174 AssertReturn(*pszExec, VERR_INVALID_PARAMETER); 175 AssertReturn(!(fFlags & ~RTPROC_FLAGS_DAEMONIZE), VERR_INVALID_PARAMETER); 176 AssertReturn(hEnv != NIL_RTENV, VERR_INVALID_PARAMETER); 177 AssertPtrReturn(papszArgs, VERR_INVALID_PARAMETER); 178 /** @todo search the PATH (add flag for this). */ 179 AssertPtrNullReturn(pszAsUser, VERR_INVALID_POINTER); 180 181 /* 182 * Get the file descriptors for the handles we've been passed. 183 * 184 * It seems there is no point in trying to convince a child process's CRT 185 * that any of the standard file handles is non-TEXT. So, we don't... 186 */ 187 STARTUPINFOW StartupInfo; 188 RT_ZERO(StartupInfo); 189 StartupInfo.cb = sizeof(StartupInfo); 190 StartupInfo.dwFlags = STARTF_USESTDHANDLES; 191 #if 1 /* The CRT should keep the standard handles up to date. */ 192 StartupInfo.hStdIn = GetStdHandle(STD_INPUT_HANDLE); 193 StartupInfo.hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); 194 StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); 195 #else 196 StartupInfo.hStdIn = _get_osfhandle(0); 197 StartupInfo.hStdOut = _get_osfhandle(1); 198 StartupInfo.hStdError = _get_osfhandle(2); 199 #endif 200 PCRTHANDLE paHandles[3] = { phStdIn, phStdOut, phStdErr }; 201 HANDLE *aphStds[3] = { &StartupInfo.hStdIn, &StartupInfo.hStdOut, &StartupInfo.hStdError }; 202 for (int i = 0; i < 3; i++) 203 { 204 if (paHandles[i]) 205 { 206 AssertPtrReturn(paHandles[i], VERR_INVALID_POINTER); 207 switch (paHandles[i]->enmType) 208 { 209 case RTHANDLETYPE_FILE: 210 aphStds[i] = paHandles[i]->u.hFile != NIL_RTFILE 211 ? (HANDLE)RTFileToNative(paHandles[i]->u.hFile) 212 : INVALID_HANDLE_VALUE; 213 break; 214 215 case RTHANDLETYPE_PIPE: 216 aphStds[i] = paHandles[i]->u.hPipe != NIL_RTPIPE 217 ? (HANDLE)RTPipeToNative(paHandles[i]->u.hPipe) 218 : INVALID_HANDLE_VALUE; 219 break; 220 221 //case RTHANDLETYPE_SOCKET: 222 // aphStds[i] = paHandles[i]->u.hSocket != NIL_RTSOCKET 223 // ? (HANDLE)RTTcpToNative(paHandles[i]->u.hSocket) 224 // : INVALID_HANDLE_VALUE; 225 // break; 226 227 default: 228 AssertMsgFailedReturn(("%d: %d\n", i, paHandles[i]->enmType), VERR_INVALID_PARAMETER); 229 } 230 } 231 } 232 233 /* 234 * Create the environment block, command line and convert the executable 235 * name. 236 */ 237 PRTUTF16 pwszzBlock; 238 rc = RTEnvQueryUtf16Block(hEnv); 239 if (RT_SUCCESS(rc)) 240 { 241 PRTUTF16 pwszCmdLine; 242 rc = RTGetOptArgvToUtf16String(&pwszCmdLine, papszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 243 if (RT_SUCCESS(rc)) 244 { 245 PRTUTF16 pwszExec; 246 rc = RTStrToUtf16(pszExec, &pwszExec); 247 if (RT_SUCCESS(rc)) 248 { 249 HANDLE hToken = INVALID_HANDLE_VALUE; 250 if (pszAsUser) 251 { 252 /** @todo - Maybe use CreateProcessWithLoginW? */ 253 rc = VERR_NOT_IMPLEMENTED; 254 } 255 if (RT_SUCCESS(rc)) 256 { 257 /* 258 * Get going... 259 */ 260 PROCESS_INFORMATION ProcInfo; 261 RT_ZERO(ProcInfo); 262 BOOL fRc; 263 if (!pwszAsUser) 264 fRc = CreateProcessW(pwszExec, 265 pwszCmdLine, 266 NULL, /* pProcessAttributes */ 267 NULL, /* pThreadAttributes */ 268 TRUE, /* bInheritHandles */ 269 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 270 pwszzBlock, 271 cwd, 272 &StartupInfo, 273 &ProcInfo); 274 else 275 fRc = CreateProcessAsUserW(hToken, 276 pwszExec, 277 pwszCmdLine, 278 NULL, /* pProcessAttributes */ 279 NULL, /* pThreadAttributes */ 280 TRUE, /* bInheritHandles */ 281 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 282 pwszzBlock, 283 cwd, 284 &StartupInfo, 285 &ProcInfo); 286 287 if (fRc) 288 { 289 //DWORD dwErr; 290 //DWORD dwExitCode; 291 // 292 //CloseHandle(ProcInfo.hThread); 293 //dwErr = WaitForSingleObject(ProcInfo.hProcess, INFINITE); 294 //assert(dwErr == WAIT_OBJECT_0); 295 // 296 //if (GetExitCodeProcess(ProcInfo.hProcess, &dwExitCode)) 297 //{ 298 // CloseHandle(ProcInfo.hProcess); 299 // _exit(dwExitCode); 300 //} 301 //errno = EINVAL; 302 } 303 304 if (hToken == INVALID_HANDLE_VALUE) 305 CloseHandle(hToken); 306 } 307 RTUtf16Free(pwszExec); 308 } 309 RTUtf16Free(pwszCmdLine); 310 } 311 RTEnvFreeUtf16Block(pwszzBlock); 312 } 313 314 return rc; 315 #else 165 316 return VERR_NOT_IMPLEMENTED; 317 #endif 166 318 } 167 319 … … 195 347 if (GetExitCodeProcess(hProcess, &dwExitCode)) 196 348 { 349 /** @todo the exit code can be special statuses. */ 197 350 if (pProcStatus) 198 351 {
Note:
See TracChangeset
for help on using the changeset viewer.