ntdll: Use a syscall thunk for NtClose().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-07-21 15:50:36 +02:00
parent 5eefbc6db9
commit 4752e252ea
7 changed files with 12 additions and 98 deletions

View File

@ -24,7 +24,6 @@ C_SRCS = \
locale.c \
misc.c \
nt.c \
om.c \
path.c \
printf.c \
process.c \

View File

@ -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

View File

@ -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;

View File

@ -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 );
}

View File

@ -1360,7 +1360,6 @@ static double CDECL ntdll_tan( double d ) { return tan( d ); }
*/
static struct unix_funcs unix_funcs =
{
NtClose,
NtCurrentTeb,
NtGetContextThread,
NtQueryPerformanceCounter,

View File

@ -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;
}

View File

@ -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 );