diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 61ec0e97312..0fbefe1d451 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1023,6 +1023,7 @@ name ntdll # Server interface @ cdecl -norelay wine_server_call(ptr) wine_server_call +@ cdecl wine_server_fd_to_handle(long long long ptr) wine_server_fd_to_handle @ cdecl wine_server_handle_to_fd(long long ptr ptr ptr) wine_server_handle_to_fd # Codepages diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c index 4034dc28803..0f26b83c294 100644 --- a/dlls/x11drv/x11drv_main.c +++ b/dlls/x11drv/x11drv_main.c @@ -36,15 +36,15 @@ #include "wine/winbase16.h" #include "winreg.h" -#include "wine/debug.h" #include "gdi.h" -#include "file.h" #include "user.h" #include "win.h" #include "wine_gl.h" #include "x11drv.h" #include "xvidmode.h" #include "dga2.h" +#include "wine/server.h" +#include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(x11drv); @@ -449,8 +449,12 @@ struct x11drv_thread_data *x11drv_init_thread_data(void) fcntl( ConnectionNumber(data->display), F_SETFD, 1 ); /* set close on exec flag */ if (synchronous) XSynchronize( data->display, True ); wine_tsx11_unlock(); - data->display_fd = FILE_DupUnixHandle( ConnectionNumber(data->display), - GENERIC_READ | SYNCHRONIZE, FALSE ); + if (wine_server_fd_to_handle( ConnectionNumber(data->display), GENERIC_READ | SYNCHRONIZE, + FALSE, &data->display_fd )) + { + MESSAGE( "x11drv: Can't allocate handle for display fd\n" ); + ExitProcess(1); + } data->process_event_count = 0; NtCurrentTeb()->driver_data = data; return data; diff --git a/files/file.c b/files/file.c index 7f7cca7de70..06bdf0f11cd 100644 --- a/files/file.c +++ b/files/file.c @@ -306,31 +306,6 @@ void FILE_SetDosError(void) } -/*********************************************************************** - * FILE_DupUnixHandle - * - * Duplicate a Unix handle into a task handle. - * Returns 0 on failure. - */ -HANDLE FILE_DupUnixHandle( int fd, DWORD access, BOOL inherit ) -{ - HANDLE ret; - - wine_server_send_fd( fd ); - - SERVER_START_REQ( alloc_file_handle ) - { - req->access = access; - req->inherit = inherit; - req->fd = fd; - wine_server_call( req ); - ret = reply->handle; - } - SERVER_END_REQ; - return ret; -} - - /*********************************************************************** * FILE_GetUnixHandleType * diff --git a/include/file.h b/include/file.h index 2d7dbd396b7..09e1f59b9c7 100644 --- a/include/file.h +++ b/include/file.h @@ -69,7 +69,6 @@ extern mode_t FILE_umask; extern int FILE_strcasecmp( const char *str1, const char *str2 ); extern int FILE_strncasecmp( const char *str1, const char *str2, int len ); extern void FILE_SetDosError(void); -extern HANDLE FILE_DupUnixHandle( int fd, DWORD access, BOOL inherit ); extern int FILE_GetUnixHandle( HANDLE handle, DWORD access ); extern BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info ); extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ); diff --git a/include/wine/server.h b/include/wine/server.h index 16a9767e8ed..7cecb409363 100644 --- a/include/wine/server.h +++ b/include/wine/server.h @@ -51,6 +51,7 @@ struct __server_request_info extern unsigned int wine_server_call( void *req_ptr ); extern void wine_server_send_fd( int fd ); +extern int wine_server_fd_to_handle( int fd, unsigned int access, int inherit, obj_handle_t *handle ); extern int wine_server_handle_to_fd( obj_handle_t handle, unsigned int access, int *unix_fd, enum fd_type *type, int *flags ); diff --git a/scheduler/client.c b/scheduler/client.c index 2c6ca68f396..de1da8ced17 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -364,6 +364,30 @@ inline static int store_cached_fd( int fd, obj_handle_t handle ) } +/*********************************************************************** + * wine_server_fd_to_handle (NTDLL.@) + * + * Allocate a file handle for a Unix fd. + */ +int wine_server_fd_to_handle( int fd, unsigned int access, int inherit, obj_handle_t *handle ) +{ + int ret; + + *handle = 0; + wine_server_send_fd( fd ); + + SERVER_START_REQ( alloc_file_handle ) + { + req->access = access; + req->inherit = inherit; + req->fd = fd; + if (!(ret = wine_server_call( req ))) *handle = reply->handle; + } + SERVER_END_REQ; + return ret; +} + + /*********************************************************************** * wine_server_handle_to_fd (NTDLL.@) * diff --git a/scheduler/process.c b/scheduler/process.c index 2d83fbc7b70..e91bd883342 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -403,9 +403,13 @@ static BOOL process_init( char *argv[] ) /* no parent, and no new console requested, create a simple console with bare handles to * unix stdio input & output streams (aka simple console) */ - SetStdHandle( STD_INPUT_HANDLE, FILE_DupUnixHandle( 0, GENERIC_READ|SYNCHRONIZE, TRUE )); - SetStdHandle( STD_OUTPUT_HANDLE, FILE_DupUnixHandle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE )); - SetStdHandle( STD_ERROR_HANDLE, FILE_DupUnixHandle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE )); + HANDLE handle; + wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, TRUE, &handle ); + SetStdHandle( STD_INPUT_HANDLE, handle ); + wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, &handle ); + SetStdHandle( STD_OUTPUT_HANDLE, handle ); + wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, &handle ); + SetStdHandle( STD_ERROR_HANDLE, handle ); } else if (!(main_create_flags & (DETACHED_PROCESS|CREATE_NEW_CONSOLE))) {