Commit 04f41e87 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Move NtClose() and NtDuplicateObject() to the Unix library.

parent 09fcfe27
...@@ -351,28 +351,8 @@ NTSTATUS WINAPI NtDuplicateObject( HANDLE source_process, HANDLE source, ...@@ -351,28 +351,8 @@ NTSTATUS WINAPI NtDuplicateObject( HANDLE source_process, HANDLE source,
HANDLE dest_process, PHANDLE dest, HANDLE dest_process, PHANDLE dest,
ACCESS_MASK access, ULONG attributes, ULONG options ) ACCESS_MASK access, ULONG attributes, ULONG options )
{ {
NTSTATUS ret; return unix_funcs->NtDuplicateObject( source_process, source, dest_process,
SERVER_START_REQ( dup_handle ) dest, access, attributes, options );
{
req->src_process = wine_server_obj_handle( source_process );
req->src_handle = wine_server_obj_handle( source );
req->dst_process = wine_server_obj_handle( dest_process );
req->access = access;
req->attributes = attributes;
req->options = options;
if (!(ret = wine_server_call( req )))
{
if (dest) *dest = wine_server_ptr_handle( reply->handle );
if (reply->closed && reply->self)
{
int fd = unix_funcs->server_remove_fd_from_cache( source );
if (fd != -1) close( fd );
}
}
}
SERVER_END_REQ;
return ret;
} }
static LONG WINAPI invalid_handle_exception_handler( EXCEPTION_POINTERS *eptr ) static LONG WINAPI invalid_handle_exception_handler( EXCEPTION_POINTERS *eptr )
...@@ -384,16 +364,7 @@ static LONG WINAPI invalid_handle_exception_handler( EXCEPTION_POINTERS *eptr ) ...@@ -384,16 +364,7 @@ static LONG WINAPI invalid_handle_exception_handler( EXCEPTION_POINTERS *eptr )
/* Everquest 2 / Pirates of the Burning Sea hooks NtClose, so we need a wrapper */ /* Everquest 2 / Pirates of the Burning Sea hooks NtClose, so we need a wrapper */
NTSTATUS close_handle( HANDLE handle ) NTSTATUS close_handle( HANDLE handle )
{ {
NTSTATUS ret; NTSTATUS ret = unix_funcs->NtClose( handle );
int fd = unix_funcs->server_remove_fd_from_cache( handle );
SERVER_START_REQ( close_handle )
{
req->handle = wine_server_obj_handle( handle );
ret = wine_server_call( req );
}
SERVER_END_REQ;
if (fd != -1) close( fd );
if (ret == STATUS_INVALID_HANDLE && handle && NtCurrentTeb()->Peb->BeingDebugged) if (ret == STATUS_INVALID_HANDLE && handle && NtCurrentTeb()->Peb->BeingDebugged)
{ {
......
...@@ -983,6 +983,8 @@ static HMODULE load_ntdll(void) ...@@ -983,6 +983,8 @@ static HMODULE load_ntdll(void)
*/ */
static struct unix_funcs unix_funcs = static struct unix_funcs unix_funcs =
{ {
NtClose,
NtDuplicateObject,
get_main_args, get_main_args,
get_paths, get_paths,
get_dll_path, get_dll_path,
...@@ -999,7 +1001,6 @@ static struct unix_funcs unix_funcs = ...@@ -999,7 +1001,6 @@ static struct unix_funcs unix_funcs =
server_call_unlocked, server_call_unlocked,
wine_server_call, wine_server_call,
server_send_fd, server_send_fd,
server_remove_fd_from_cache,
server_get_unix_fd, server_get_unix_fd,
server_fd_to_handle, server_fd_to_handle,
server_handle_to_fd, server_handle_to_fd,
......
...@@ -542,9 +542,9 @@ static inline NTSTATUS get_cached_fd( HANDLE handle, int *fd, enum server_fd_typ ...@@ -542,9 +542,9 @@ static inline NTSTATUS get_cached_fd( HANDLE handle, int *fd, enum server_fd_typ
/*********************************************************************** /***********************************************************************
* server_remove_fd_from_cache * remove_fd_from_cache
*/ */
int CDECL server_remove_fd_from_cache( HANDLE handle ) static int remove_fd_from_cache( HANDLE handle )
{ {
unsigned int entry, idx = handle_to_index( handle, &entry ); unsigned int entry, idx = handle_to_index( handle, &entry );
int fd = -1; int fd = -1;
...@@ -1122,3 +1122,53 @@ size_t CDECL server_init_thread( void *entry_point, BOOL *suspend, unsigned int ...@@ -1122,3 +1122,53 @@ size_t CDECL server_init_thread( void *entry_point, BOOL *suspend, unsigned int
server_protocol_error( "init_thread failed with status %x\n", ret ); server_protocol_error( "init_thread failed with status %x\n", ret );
} }
} }
/******************************************************************************
* NtDuplicateObject
*/
NTSTATUS WINAPI NtDuplicateObject( HANDLE source_process, HANDLE source, HANDLE dest_process, HANDLE *dest,
ACCESS_MASK access, ULONG attributes, ULONG options )
{
NTSTATUS ret;
SERVER_START_REQ( dup_handle )
{
req->src_process = wine_server_obj_handle( source_process );
req->src_handle = wine_server_obj_handle( source );
req->dst_process = wine_server_obj_handle( dest_process );
req->access = access;
req->attributes = attributes;
req->options = options;
if (!(ret = wine_server_call( req )))
{
if (dest) *dest = wine_server_ptr_handle( reply->handle );
if (reply->closed && reply->self)
{
int fd = remove_fd_from_cache( source );
if (fd != -1) close( fd );
}
}
}
SERVER_END_REQ;
return ret;
}
/**************************************************************************
* NtClose
*/
NTSTATUS WINAPI NtClose( HANDLE handle )
{
NTSTATUS ret;
int fd = remove_fd_from_cache( handle );
SERVER_START_REQ( close_handle )
{
req->handle = wine_server_obj_handle( handle );
ret = wine_server_call( req );
}
SERVER_END_REQ;
if (fd != -1) close( fd );
return ret;
}
...@@ -62,7 +62,6 @@ extern void CDECL dbg_init(void) DECLSPEC_HIDDEN; ...@@ -62,7 +62,6 @@ extern void CDECL dbg_init(void) DECLSPEC_HIDDEN;
extern unsigned int CDECL server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN; extern unsigned int CDECL server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
extern void CDECL server_send_fd( int fd ) DECLSPEC_HIDDEN; extern void CDECL server_send_fd( int fd ) DECLSPEC_HIDDEN;
extern int CDECL server_remove_fd_from_cache( HANDLE handle ) DECLSPEC_HIDDEN;
extern int CDECL server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd, extern int CDECL server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd,
int *needs_close, enum server_fd_type *type, int *needs_close, enum server_fd_type *type,
unsigned int *options ) DECLSPEC_HIDDEN; unsigned int *options ) DECLSPEC_HIDDEN;
......
...@@ -25,10 +25,16 @@ ...@@ -25,10 +25,16 @@
#include "wine/debug.h" #include "wine/debug.h"
/* increment this when you change the function table */ /* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 10 #define NTDLL_UNIXLIB_VERSION 11
struct unix_funcs struct unix_funcs
{ {
/* Nt* functions */
NTSTATUS (WINAPI *NtClose)( HANDLE handle );
NTSTATUS (WINAPI *NtDuplicateObject)( HANDLE source_process, HANDLE source,
HANDLE dest_process, HANDLE *dest,
ACCESS_MASK access, ULONG attributes, ULONG options );
/* environment functions */ /* environment functions */
void (CDECL *get_main_args)( int *argc, char **argv[], char **envp[] ); void (CDECL *get_main_args)( int *argc, char **argv[], char **envp[] );
void (CDECL *get_paths)( const char **builddir, const char **datadir, const char **configdir ); void (CDECL *get_paths)( const char **builddir, const char **datadir, const char **configdir );
...@@ -54,7 +60,6 @@ struct unix_funcs ...@@ -54,7 +60,6 @@ struct unix_funcs
unsigned int (CDECL *server_call_unlocked)( void *req_ptr ); unsigned int (CDECL *server_call_unlocked)( void *req_ptr );
unsigned int (CDECL *server_call)( void *req_ptr ); unsigned int (CDECL *server_call)( void *req_ptr );
void (CDECL *server_send_fd)( int fd ); void (CDECL *server_send_fd)( int fd );
int (CDECL *server_remove_fd_from_cache)( HANDLE handle );
int (CDECL *server_get_unix_fd)( HANDLE handle, unsigned int wanted_access, int *unix_fd, int (CDECL *server_get_unix_fd)( HANDLE handle, unsigned int wanted_access, int *unix_fd,
int *needs_close, enum server_fd_type *type, unsigned int *options ); int *needs_close, enum server_fd_type *type, unsigned int *options );
NTSTATUS (CDECL *server_fd_to_handle)( int fd, unsigned int access, unsigned int attributes, NTSTATUS (CDECL *server_fd_to_handle)( int fd, unsigned int access, unsigned int attributes,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment