Module: wine Branch: master Commit: 4752e252ea6ee084b679a9b9551a1c55f8744451 URL: https://source.winehq.org/git/wine.git/?a=commit;h=4752e252ea6ee084b679a9b95...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Jul 21 15:50:36 2020 +0200
ntdll: Use a syscall thunk for NtClose().
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/Makefile.in | 1 - dlls/ntdll/ntdll.spec | 4 +-- dlls/ntdll/ntdll_misc.h | 2 -- dlls/ntdll/om.c | 90 ------------------------------------------------ dlls/ntdll/unix/loader.c | 1 - dlls/ntdll/unix/server.c | 9 +++++ dlls/ntdll/unixlib.h | 3 +- 7 files changed, 12 insertions(+), 98 deletions(-)
diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index eed8d10f0b..bc8215b6bf 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -24,7 +24,6 @@ C_SRCS = \ locale.c \ misc.c \ nt.c \ - om.c \ path.c \ printf.c \ process.c \ diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 0bfe3d3545..ff1433be40 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -150,7 +150,7 @@ @ stdcall -syscall NtCancelTimer(long ptr) @ stdcall -syscall NtClearEvent(long) @ stdcall -syscall NtClearPowerRequest(long long) -@ stdcall NtClose(long) +@ stdcall -syscall NtClose(long) @ stub NtCloseObjectAuditAlarm # @ stub NtCompactKeys # @ stub NtCompareTokens @@ -1139,7 +1139,7 @@ @ stdcall -private -syscall ZwCancelTimer(long ptr) NtCancelTimer @ stdcall -private -syscall ZwClearEvent(long) NtClearEvent @ stdcall -private -syscall ZwClearPowerRequest(long long) NtClearPowerRequest -@ stdcall -private ZwClose(long) NtClose +@ stdcall -private -syscall ZwClose(long) NtClose @ stub ZwCloseObjectAuditAlarm # @ stub ZwCompactKeys # @ stub ZwCompareTokens diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 1f27cd100a..d845416e95 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -44,8 +44,6 @@ static const UINT_PTR page_size = 0x1000; extern UINT_PTR page_size DECLSPEC_HIDDEN; #endif
-extern NTSTATUS close_handle( HANDLE ) DECLSPEC_HIDDEN; - /* exceptions */ extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN raise_status( NTSTATUS status, EXCEPTION_RECORD *rec ) DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/om.c b/dlls/ntdll/om.c deleted file mode 100644 index 8c8f2a4297..0000000000 --- a/dlls/ntdll/om.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Object management functions - * - * Copyright 1999, 2000 Juergen Schmied - * Copyright 2005 Vitaliy Margolen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> - -#include "ntstatus.h" -#define WIN32_NO_STATUS -#include "wine/debug.h" -#include "windef.h" -#include "winternl.h" -#include "ntdll_misc.h" -#include "wine/server.h" -#include "wine/exception.h" - - -/* - * Generic object functions - */ - -static LONG WINAPI invalid_handle_exception_handler( EXCEPTION_POINTERS *eptr ) -{ - EXCEPTION_RECORD *rec = eptr->ExceptionRecord; - return (rec->ExceptionCode == EXCEPTION_INVALID_HANDLE) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; -} - -/* Everquest 2 / Pirates of the Burning Sea hooks NtClose, so we need a wrapper */ -NTSTATUS close_handle( HANDLE handle ) -{ - DWORD_PTR debug_port; - NTSTATUS ret = unix_funcs->NtClose( handle ); - - if (ret == STATUS_INVALID_HANDLE && handle && NtCurrentTeb()->Peb->BeingDebugged && - !NtQueryInformationProcess( NtCurrentProcess(), ProcessDebugPort, &debug_port, - sizeof(debug_port), NULL) && debug_port) - { - __TRY - { - EXCEPTION_RECORD record; - record.ExceptionCode = EXCEPTION_INVALID_HANDLE; - record.ExceptionFlags = 0; - record.ExceptionRecord = NULL; - record.ExceptionAddress = NULL; - record.NumberParameters = 0; - RtlRaiseException( &record ); - } - __EXCEPT(invalid_handle_exception_handler) - { - } - __ENDTRY - } - - return ret; -} - -/************************************************************************** - * NtClose [NTDLL.@] - * - * Close a handle reference to an object. - * - * PARAMS - * Handle [I] handle to close - * - * RETURNS - * Success: ERROR_SUCCESS. - * Failure: An NTSTATUS error code. - */ -NTSTATUS WINAPI NtClose( HANDLE Handle ) -{ - return close_handle( Handle ); -} diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index fba785c2b6..99c70b400a 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1360,7 +1360,6 @@ static double CDECL ntdll_tan( double d ) { return tan( d ); } */ static struct unix_funcs unix_funcs = { - NtClose, NtCurrentTeb, NtGetContextThread, NtQueryPerformanceCounter, diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c index 452094ff5d..21817ad159 100644 --- a/dlls/ntdll/unix/server.c +++ b/dlls/ntdll/unix/server.c @@ -1629,6 +1629,7 @@ NTSTATUS WINAPI NtDuplicateObject( HANDLE source_process, HANDLE source, HANDLE */ NTSTATUS WINAPI NtClose( HANDLE handle ) { + HANDLE port; NTSTATUS ret; int fd = remove_fd_from_cache( handle );
@@ -1639,5 +1640,13 @@ NTSTATUS WINAPI NtClose( HANDLE handle ) } SERVER_END_REQ; if (fd != -1) close( fd ); + + if (ret != STATUS_INVALID_HANDLE || !handle) return ret; + if (!NtCurrentTeb()->Peb->BeingDebugged) return ret; + if (!NtQueryInformationProcess( NtCurrentProcess(), ProcessDebugPort, &port, sizeof(port), NULL) && port) + { + NtCurrentTeb()->ExceptionCode = ret; + pKiRaiseUserExceptionDispatcher(); + } return ret; } diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h index e4206762b1..d7487feafc 100644 --- a/dlls/ntdll/unixlib.h +++ b/dlls/ntdll/unixlib.h @@ -28,12 +28,11 @@ struct msghdr; struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */ -#define NTDLL_UNIXLIB_VERSION 88 +#define NTDLL_UNIXLIB_VERSION 89
struct unix_funcs { /* Nt* functions */ - NTSTATUS (WINAPI *NtClose)( HANDLE handle ); TEB * (WINAPI *NtCurrentTeb)(void); NTSTATUS (WINAPI *NtGetContextThread)( HANDLE handle, CONTEXT *context ); NTSTATUS (WINAPI *NtQueryPerformanceCounter)( LARGE_INTEGER *counter, LARGE_INTEGER *frequency );