[PATCH 3/3] ntdll: Return success for magic handles.

Daniel Lehman dlehman25 at gmail.com
Sun Apr 3 02:13:36 CDT 2022


https://bugs.winehq.org/show_bug.cgi?id=51529

Signed-off-by: Daniel Lehman <dlehman25 at gmail.com>

---
the CloseHandle docs say Windows will return error and throw exception for bogus or pseudo handle:
https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle

but the docs for GetCurrentProcess/Thread say closing a pseudo handle has no effect
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthread

looks like behavior changed at Windows 10

---
 dlls/ntdll/tests/exception.c | 8 --------
 dlls/ntdll/unix/server.c     | 3 +++
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index 8af8d6b70da..42722e7b952 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -1223,7 +1223,6 @@ static void test_debugger(DWORD cont_status)
                 }
                 else if (stage == 13)
                 {
-                    todo_wine
                     ok(FALSE || broken(TRUE) /* < Win10 */, "should not throw exception\n");
                     continuestatus = DBG_EXCEPTION_NOT_HANDLED;
                 }
@@ -3923,7 +3922,6 @@ static void test_debugger(DWORD cont_status)
                 }
                 else if (stage == 13)
                 {
-                    todo_wine
                     ok(FALSE || broken(TRUE) /* < Win10 */, "should not throw exception\n");
                     continuestatus = DBG_EXCEPTION_NOT_HANDLED;
                 }
@@ -6627,7 +6625,6 @@ static void test_debugger(DWORD cont_status)
                 }
                 else if (stage == 13)
                 {
-                    todo_wine
                     ok(FALSE || broken(TRUE) /* < Win10 */, "should not throw exception\n");
                     continuestatus = DBG_EXCEPTION_NOT_HANDLED;
                 }
@@ -7881,7 +7878,6 @@ static void test_debugger(DWORD cont_status)
                 }
                 else if (stage == 13)
                 {
-                    todo_wine
                     ok(FALSE || broken(TRUE) /* < Win10 */, "should not throw exception\n");
                     continuestatus = DBG_EXCEPTION_NOT_HANDLED;
                 }
@@ -8624,24 +8620,20 @@ static void test_closehandle(DWORD numexc, HANDLE handle)
     ret = CloseHandle(handle);
     ok(expectret || (GetLastError() == ERROR_INVALID_HANDLE),
         "CloseHandle had wrong GetLastError(), got %lu for %p\n", GetLastError(), handle);
-    todo_wine_if(is_magic_handle(handle)) {
     ok(ret == expectret || broken(HandleToLong(handle) < 0) /* < Win10 */,
         "CloseHandle expected %d, got %d for %p\n", expectret, ret, handle);
     ok(invalid_handle_exceptions == numexc || broken(!numexc && is_magic_handle(handle)), /* < Win10 */
         "CloseHandle generated %ld exceptions, expected %ld for %p\n",
        invalid_handle_exceptions, numexc, handle);
-    }
 
     invalid_handle_exceptions = 0;
     expect = expectret ? STATUS_SUCCESS : STATUS_INVALID_HANDLE;
     status = pNtClose(handle);
-    todo_wine_if(is_magic_handle(handle)) {
     ok(status == expect || broken(HandleToLong(handle) < 0), /* < Win10 */
         "NtClose returned unexpected status %#lx, expected %#lx for %p\n", status, expect, handle);
     ok(invalid_handle_exceptions == numexc || broken(!numexc && is_magic_handle(handle)), /* < Win10 */
         "CloseHandle generated %ld exceptions, expected %ld for %p\n",
        invalid_handle_exceptions, numexc, handle);
-    }
 
     pRtlRemoveVectoredExceptionHandler(vectored_handler);
 }
diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c
index ab9d99c4f47..77e8d5c7566 100644
--- a/dlls/ntdll/unix/server.c
+++ b/dlls/ntdll/unix/server.c
@@ -1704,6 +1704,9 @@ NTSTATUS WINAPI NtClose( HANDLE handle )
     NTSTATUS ret;
     int fd;
 
+    if (HandleToLong( handle ) >= ~5 && HandleToLong( handle ) <= ~0)
+        return STATUS_SUCCESS;
+
     server_enter_uninterrupted_section( &fd_cache_mutex, &sigset );
 
     /* always remove the cached fd; if the server request fails we'll just
-- 
2.25.1




More information about the wine-devel mailing list