Changeset 70486 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Jan 8, 2018 2:16:16 PM (7 years ago)
- Location:
- trunk/src/VBox/Runtime/r3/win
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r70361 r70486 2260 2260 } 2261 2261 2262 PCRTHANDLE paHandles[3] = { phStdIn, phStdOut, phStdErr }; 2263 HANDLE *aphStds[3] = { &StartupInfo.hStdInput, &StartupInfo.hStdOutput, &StartupInfo.hStdError }; 2264 DWORD afInhStds[3] = { 0xffffffff, 0xffffffff, 0xffffffff }; 2262 PCRTHANDLE paHandles[3] = { phStdIn, phStdOut, phStdErr }; 2263 HANDLE *aphStds[3] = { &StartupInfo.hStdInput, &StartupInfo.hStdOutput, &StartupInfo.hStdError }; 2264 DWORD afInhStds[3] = { 0xffffffff, 0xffffffff, 0xffffffff }; 2265 HANDLE ahStdDups[3] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 2265 2266 for (int i = 0; i < 3; i++) 2266 2267 { … … 2271 2272 { 2272 2273 case RTHANDLETYPE_FILE: 2273 *aphStds[i] = paHandles[i]->u.hFile != NIL_RTFILE 2274 ? (HANDLE)RTFileToNative(paHandles[i]->u.hFile) 2275 : INVALID_HANDLE_VALUE; 2274 { 2275 HANDLE hNativeFile = paHandles[i]->u.hFile != NIL_RTFILE 2276 ? (HANDLE)RTFileToNative(paHandles[i]->u.hFile) 2277 : INVALID_HANDLE_VALUE; 2278 if ( hNativeFile == *aphStds[i] 2279 && g_enmWinVer == kRTWinOSType_NT310) 2280 continue; 2281 *aphStds[i] = hNativeFile; 2276 2282 break; 2283 } 2277 2284 2278 2285 case RTHANDLETYPE_PIPE: … … 2280 2287 ? (HANDLE)RTPipeToNative(paHandles[i]->u.hPipe) 2281 2288 : INVALID_HANDLE_VALUE; 2289 if ( g_enmWinVer == kRTWinOSType_NT310 2290 && *aphStds[i] == INVALID_HANDLE_VALUE) 2291 { 2292 AssertMsgReturn(RTPipeGetCreationInheritability(paHandles[i]->u.hPipe), ("%Rrc %p\n", rc, *aphStds[i]), 2293 VERR_INVALID_STATE); 2294 continue; 2295 } 2282 2296 break; 2283 2297 … … 2295 2309 if (*aphStds[i] != INVALID_HANDLE_VALUE) 2296 2310 { 2297 if (!GetHandleInformation(*aphStds[i], &afInhStds[i])) 2311 if (g_enmWinVer == kRTWinOSType_NT310) 2312 afInhStds[i] = 0; /* No handle info on NT 3.1, so ASSUME it is not inheritable. */ 2313 else if (!GetHandleInformation(*aphStds[i], &afInhStds[i])) 2298 2314 { 2299 2315 rc = RTErrConvertFromWin32(GetLastError()); 2300 if (rc != VERR_INVALID_FUNCTION || g_enmWinVer != kRTWinOSType_NT310) 2301 AssertMsgFailedReturn(("%Rrc %p\n", rc, *aphStds[i]), rc); 2316 AssertMsgFailedReturn(("%Rrc aphStds[%d] => %p paHandles[%d]={%d,%p}\n", 2317 rc, i, *aphStds[i], i, paHandles[i]->enmType, paHandles[i]->u.uInt), 2318 rc); 2302 2319 } 2303 2320 } … … 2307 2324 /* 2308 2325 * Set the inheritability any handles we're handing the child. 2326 * 2327 * Note! On NT 3.1 there is no SetHandleInformation, so we have to duplicate 2328 * the handles to make sure they are inherited by the child. 2309 2329 */ 2310 2330 rc = VINF_SUCCESS; 2311 2331 for (int i = 0; i < 3; i++) 2312 if ( (afInhStds[i] != 0xffffffff) 2313 && !(afInhStds[i] & HANDLE_FLAG_INHERIT)) 2314 { 2315 if (!SetHandleInformation(*aphStds[i], HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) 2332 if ( (afInhStds[i] != 0xffffffff) 2333 && !(afInhStds[i] & HANDLE_FLAG_INHERIT)) 2334 { 2335 if (g_enmWinVer == kRTWinOSType_NT310) 2336 { 2337 if (DuplicateHandle(GetCurrentProcess(), *aphStds[i], GetCurrentProcess(), &ahStdDups[i], 2338 i == 0 ? GENERIC_READ : GENERIC_WRITE, TRUE /*fInheritHandle*/, DUPLICATE_SAME_ACCESS)) 2339 *aphStds[i] = ahStdDups[i]; 2340 else 2341 { 2342 rc = RTErrConvertFromWin32(GetLastError()); 2343 AssertMsgFailedBreak(("%Rrc aphStds[%u] => %p\n", rc, i, *aphStds[i])); 2344 } 2345 } 2346 else if (!SetHandleInformation(*aphStds[i], HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) 2316 2347 { 2317 2348 rc = RTErrConvertFromWin32(GetLastError()); … … 2319 2350 rc = VINF_SUCCESS; 2320 2351 else 2321 AssertMsgFailedBreak(("%Rrc %p\n", rc,*aphStds[i]));2352 AssertMsgFailedBreak(("%Rrc aphStds[%u] => %p\n", rc, i, *aphStds[i])); 2322 2353 } 2323 2354 } … … 2423 2454 } 2424 2455 2425 /* Undo any handle inherit changes. */ 2426 for (int i = 0; i < 3; i++) 2427 if ( (afInhStds[i] != 0xffffffff) 2428 && !(afInhStds[i] & HANDLE_FLAG_INHERIT)) 2429 { 2430 if ( !SetHandleInformation(*aphStds[i], HANDLE_FLAG_INHERIT, 0) 2431 && ( GetLastError() != ERROR_INVALID_FUNCTION 2432 || g_enmWinVer != kRTWinOSType_NT310) ) 2433 AssertMsgFailed(("%Rrc %p\n", RTErrConvertFromWin32(GetLastError()), *aphStds[i])); 2434 } 2456 if (g_enmWinVer != kRTWinOSType_NT310) 2457 { 2458 /* Undo any handle inherit changes. */ 2459 for (int i = 0; i < 3; i++) 2460 if ( (afInhStds[i] != 0xffffffff) 2461 && !(afInhStds[i] & HANDLE_FLAG_INHERIT)) 2462 { 2463 if ( !SetHandleInformation(*aphStds[i], HANDLE_FLAG_INHERIT, 0) 2464 && ( GetLastError() != ERROR_INVALID_FUNCTION 2465 || g_enmWinVer != kRTWinOSType_NT310) ) 2466 AssertMsgFailed(("%Rrc %p\n", RTErrConvertFromWin32(GetLastError()), *aphStds[i])); 2467 } 2468 } 2469 else 2470 { 2471 /* Close handles duplicated for correct inheritance. */ 2472 for (int i = 0; i < 3; i++) 2473 if (ahStdDups[i] != INVALID_HANDLE_VALUE) 2474 CloseHandle(ahStdDups[i]); 2475 } 2435 2476 2436 2477 return rc; -
trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakes.cpp
r70480 r70486 579 579 *pfFlags = 0; 580 580 //MY_ASSERT(rcNt == STATUS_INVALID_HANDLE, "rcNt=%#x", rcNt); 581 MY_ASSERT(rcNt == STATUS_INVALID_HANDLE , "GetHandleInformation");581 MY_ASSERT(rcNt == STATUS_INVALID_HANDLE || rcNt == STATUS_INVALID_INFO_CLASS, "GetHandleInformation"); 582 582 SetLastError(rcNt == STATUS_INVALID_HANDLE ? ERROR_INVALID_HANDLE : ERROR_INVALID_FUNCTION); /* see also process-win.cpp */ 583 583 return FALSE;
Note:
See TracChangeset
for help on using the changeset viewer.