From: Huw Davies huw@codeweavers.com
Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/nsiproxy.sys/device.c | 19 ++++++++++------- dlls/nsiproxy.sys/icmp_echo.c | 32 +++++++++++++--------------- dlls/nsiproxy.sys/nsiproxy_private.h | 17 +++++++++++++-- 3 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/dlls/nsiproxy.sys/device.c b/dlls/nsiproxy.sys/device.c index d3845829a85..aa030fa459c 100644 --- a/dlls/nsiproxy.sys/device.c +++ b/dlls/nsiproxy.sys/device.c @@ -180,19 +180,20 @@ static NTSTATUS nsiproxy_get_parameter( IRP *irp ) return status; }
-static inline HANDLE irp_get_icmp_handle( IRP *irp ) +static inline icmp_handle irp_get_icmp_handle( IRP *irp ) { - return irp->Tail.Overlay.DriverContext[0]; + return PtrToUlong( irp->Tail.Overlay.DriverContext[0] ); }
-static inline HANDLE irp_set_icmp_handle( IRP *irp, HANDLE handle ) +static inline icmp_handle irp_set_icmp_handle( IRP *irp, icmp_handle handle ) { - return InterlockedExchangePointer( irp->Tail.Overlay.DriverContext, handle ); + return PtrToUlong( InterlockedExchangePointer( irp->Tail.Overlay.DriverContext, + ULongToPtr( handle ) ) ); }
static void WINAPI icmp_echo_cancel( DEVICE_OBJECT *device, IRP *irp ) { - HANDLE handle; + struct icmp_cancel_listen_params params;
TRACE( "device %p, irp %p.\n", device, irp );
@@ -205,8 +206,8 @@ static void WINAPI icmp_echo_cancel( DEVICE_OBJECT *device, IRP *irp ) cancel it, or the irp has already finished. If the handle does exist then notify the listen thread. In all cases the irp will be completed elsewhere. */ - handle = irp_get_icmp_handle( irp ); - if (handle) nsiproxy_call( icmp_cancel_listen, handle ); + params.handle = irp_get_icmp_handle( irp ); + if (params.handle) nsiproxy_call( icmp_cancel_listen, ¶ms );
LeaveCriticalSection( &nsiproxy_cs ); } @@ -328,6 +329,7 @@ static DWORD WINAPI listen_thread_proc( void *arg ) IRP *irp = arg; IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp ); struct nsiproxy_icmp_echo *in = irp->AssociatedIrp.SystemBuffer; + struct icmp_close_params close_params; struct icmp_listen_params params; NTSTATUS status;
@@ -345,7 +347,8 @@ static DWORD WINAPI listen_thread_proc( void *arg )
EnterCriticalSection( &nsiproxy_cs );
- nsiproxy_call( icmp_close, irp_set_icmp_handle( irp, NULL ) ); + close_params.handle = irp_set_icmp_handle( irp, 0 ); + nsiproxy_call( icmp_close, &close_params );
irp->IoStatus.Status = status; if (status == STATUS_SUCCESS) diff --git a/dlls/nsiproxy.sys/icmp_echo.c b/dlls/nsiproxy.sys/icmp_echo.c index c3ce841c003..dda19915fe7 100644 --- a/dlls/nsiproxy.sys/icmp_echo.c +++ b/dlls/nsiproxy.sys/icmp_echo.c @@ -120,10 +120,10 @@ static struct icmp_data *handle_table[MAX_HANDLES]; static pthread_mutex_t handle_lock = PTHREAD_MUTEX_INITIALIZER; static struct icmp_data **next_free, **next_unused = handle_table;
-static HANDLE handle_alloc( struct icmp_data *data ) +static icmp_handle handle_alloc( struct icmp_data *data ) { struct icmp_data **entry; - HANDLE h; + icmp_handle h;
pthread_mutex_lock( &handle_lock ); entry = next_free; @@ -136,25 +136,23 @@ static HANDLE handle_alloc( struct icmp_data *data ) return 0; } *entry = data; - h = LongToHandle( entry - handle_table + 1 ); + h = entry - handle_table + 1; pthread_mutex_unlock( &handle_lock ); - TRACE( "returning handle %p\n", h ); + TRACE( "returning handle %x\n", h ); return h; }
-static struct icmp_data **handle_entry( HANDLE h ) +static struct icmp_data **handle_entry( icmp_handle h ) { - unsigned int idx = HandleToLong( h ); - - if (!idx || idx > MAX_HANDLES) + if (!h || h > MAX_HANDLES) { ERR( "Invalid icmp handle\n" ); return NULL; } - return handle_table + idx - 1; + return handle_table + h - 1; }
-static struct icmp_data *handle_data( HANDLE h ) +static struct icmp_data *handle_data( icmp_handle h ) { struct icmp_data **entry = handle_entry( h );
@@ -162,11 +160,11 @@ static struct icmp_data *handle_data( HANDLE h ) return *entry; }
-static void handle_free( HANDLE h ) +static void handle_free( icmp_handle h ) { struct icmp_data **entry;
- TRACE( "%p\n", h ); + TRACE( "%x\n", h ); pthread_mutex_lock( &handle_lock ); entry = handle_entry( h ); if (entry) @@ -778,8 +776,8 @@ NTSTATUS icmp_listen( void *args )
NTSTATUS icmp_cancel_listen( void *args ) { - HANDLE handle = args; - struct icmp_data *data = handle_data( handle ); + struct icmp_cancel_listen_params *params = args; + struct icmp_data *data = handle_data( params->handle );
if (!data) return STATUS_INVALID_PARAMETER; write( data->cancel_pipe[1], "x", 1 ); @@ -788,11 +786,11 @@ NTSTATUS icmp_cancel_listen( void *args )
NTSTATUS icmp_close( void *args ) { - HANDLE handle = args; - struct icmp_data *data = handle_data( handle ); + struct icmp_close_params *params = args; + struct icmp_data *data = handle_data( params->handle );
if (!data) return STATUS_INVALID_PARAMETER; icmp_data_free( data ); - handle_free( handle ); + handle_free( params->handle ); return STATUS_SUCCESS; } diff --git a/dlls/nsiproxy.sys/nsiproxy_private.h b/dlls/nsiproxy.sys/nsiproxy_private.h index 4bd269a0691..a62a0eebda8 100644 --- a/dlls/nsiproxy.sys/nsiproxy_private.h +++ b/dlls/nsiproxy.sys/nsiproxy_private.h @@ -17,9 +17,22 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ + +typedef UINT icmp_handle; + +struct icmp_cancel_listen_params +{ + icmp_handle handle; +}; + +struct icmp_close_params +{ + icmp_handle handle; +}; + struct icmp_listen_params { - HANDLE handle; + icmp_handle handle; void *reply; ULONGLONG user_reply_ptr; unsigned int bits, reply_len; @@ -32,7 +45,7 @@ struct icmp_send_echo_params void *request, *reply; UINT request_size, reply_len; BYTE bits, ttl, tos; - HANDLE handle; + icmp_handle handle; };
/* output for IOCTL_NSIPROXY_WINE_ICMP_ECHO - cf. ICMP_ECHO_REPLY */
From: Huw Davies huw@codeweavers.com
Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/nsiproxy.sys/device.c | 4 +++- dlls/nsiproxy.sys/icmp_echo.c | 6 +++--- dlls/nsiproxy.sys/nsiproxy_private.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/dlls/nsiproxy.sys/device.c b/dlls/nsiproxy.sys/device.c index aa030fa459c..7aba1f0c36f 100644 --- a/dlls/nsiproxy.sys/device.c +++ b/dlls/nsiproxy.sys/device.c @@ -366,6 +366,7 @@ static void handle_queued_send_echo( IRP *irp ) { struct nsiproxy_icmp_echo *in = (struct nsiproxy_icmp_echo *)irp->AssociatedIrp.SystemBuffer; struct icmp_send_echo_params params; + icmp_handle handle; NTSTATUS status;
TRACE( "\n" ); @@ -376,6 +377,7 @@ static void handle_queued_send_echo( IRP *irp ) params.ttl = in->ttl; params.tos = in->tos; params.dst = &in->dst; + params.handle = &handle;
status = nsiproxy_call( icmp_send_echo, ¶ms ); TRACE( "icmp_send_echo rets %08lx\n", status ); @@ -389,7 +391,7 @@ static void handle_queued_send_echo( IRP *irp ) } else { - irp_set_icmp_handle( irp, params.handle ); + irp_set_icmp_handle( irp, handle ); RtlQueueWorkItem( listen_thread_proc, irp, WT_EXECUTELONGFUNCTION ); } } diff --git a/dlls/nsiproxy.sys/icmp_echo.c b/dlls/nsiproxy.sys/icmp_echo.c index dda19915fe7..e92fa4394c1 100644 --- a/dlls/nsiproxy.sys/icmp_echo.c +++ b/dlls/nsiproxy.sys/icmp_echo.c @@ -659,9 +659,9 @@ NTSTATUS icmp_send_echo( void *args ) return STATUS_SUCCESS; }
- params->handle = handle_alloc( data ); - if (!params->handle) icmp_data_free( data ); - return params->handle ? STATUS_PENDING : STATUS_NO_MEMORY; + *params->handle = handle_alloc( data ); + if (!*params->handle) icmp_data_free( data ); + return *params->handle ? STATUS_PENDING : STATUS_NO_MEMORY; }
static int get_timeout( LARGE_INTEGER start, UINT timeout ) diff --git a/dlls/nsiproxy.sys/nsiproxy_private.h b/dlls/nsiproxy.sys/nsiproxy_private.h index a62a0eebda8..241106fe228 100644 --- a/dlls/nsiproxy.sys/nsiproxy_private.h +++ b/dlls/nsiproxy.sys/nsiproxy_private.h @@ -45,7 +45,7 @@ struct icmp_send_echo_params void *request, *reply; UINT request_size, reply_len; BYTE bits, ttl, tos; - icmp_handle handle; + icmp_handle *handle; };
/* output for IOCTL_NSIPROXY_WINE_ICMP_ECHO - cf. ICMP_ECHO_REPLY */
From: Huw Davies huw@codeweavers.com
Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/nsiproxy.sys/nsi.c | 131 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+)
diff --git a/dlls/nsiproxy.sys/nsi.c b/dlls/nsiproxy.sys/nsi.c index b9b04e63545..84fbf268254 100644 --- a/dlls/nsiproxy.sys/nsi.c +++ b/dlls/nsiproxy.sys/nsi.c @@ -155,3 +155,134 @@ const unixlib_entry_t __wine_unix_call_funcs[] = unix_nsi_get_all_parameters_ex, unix_nsi_get_parameter_ex }; + +#ifdef _WIN64 + +typedef UINT PTR32; + +static NTSTATUS wow64_nsi_enumerate_all_ex( void *args ) +{ + struct + { + PTR32 unknown[2]; + PTR32 module; + UINT table; + UINT first_arg; + UINT second_arg; + PTR32 key_data; + UINT key_size; + PTR32 rw_data; + UINT rw_size; + PTR32 dynamic_data; + UINT dynamic_size; + PTR32 static_data; + UINT static_size; + UINT count; + } *params32 = args; + struct nsi_enumerate_all_ex params = + { + .unknown[0] = ULongToPtr( params32->unknown[0] ), + .unknown[1] = ULongToPtr( params32->unknown[1] ), + .module = ULongToPtr( params32->module ), + .table = params32->table, + .first_arg = params32->first_arg, + .second_arg = params32->second_arg, + .key_data = ULongToPtr( params32->key_data ), + .key_size = params32->key_size, + .rw_data = ULongToPtr( params32->rw_data ), + .rw_size = params32->rw_size, + .dynamic_data = ULongToPtr( params32->dynamic_data ), + .dynamic_size = params32->dynamic_size, + .static_data = ULongToPtr( params32->static_data ), + .static_size = params32->static_size, + .count = params32->count + }; + NTSTATUS status = nsi_enumerate_all_ex( ¶ms ); + params32->count = params.count; + return status; +} + +static NTSTATUS wow64_nsi_get_all_parameters_ex( void *args ) +{ + struct + { + PTR32 unknown[2]; + PTR32 module; + UINT table; + UINT first_arg; + UINT unknown2; + PTR32 key; + UINT key_size; + PTR32 rw_data; + UINT rw_size; + PTR32 dynamic_data; + UINT dynamic_size; + PTR32 static_data; + UINT static_size; + } const *params32 = args; + struct nsi_get_all_parameters_ex params = + { + .unknown[0] = ULongToPtr( params32->unknown[0] ), + .unknown[1] = ULongToPtr( params32->unknown[1] ), + .module = ULongToPtr( params32->module ), + .table = params32->table, + .first_arg = params32->first_arg, + .unknown2 = params32->unknown2, + .key = ULongToPtr( params32->key ), + .key_size = params32->key_size, + .rw_data = ULongToPtr( params32->rw_data ), + .rw_size = params32->rw_size, + .dynamic_data = ULongToPtr( params32->dynamic_data ), + .dynamic_size = params32->dynamic_size, + .static_data = ULongToPtr( params32->static_data ), + .static_size = params32->static_size + }; + return nsi_get_all_parameters_ex( ¶ms ); +} + +static NTSTATUS wow64_nsi_get_parameter_ex( void *args ) +{ + struct + { + PTR32 unknown[2]; + PTR32 module; + UINT table; + UINT first_arg; + UINT unknown2; + PTR32 key; + UINT key_size; + UINT param_type; + PTR32 data; + UINT data_size; + UINT data_offset; + } const *params32 = args; + struct nsi_get_parameter_ex params = + { + .unknown[0] = ULongToPtr( params32->unknown[0] ), + .unknown[1] = ULongToPtr( params32->unknown[1] ), + .module = ULongToPtr( params32->module ), + .table = params32->table, + .first_arg = params32->first_arg, + .unknown2 = params32->unknown2, + .key = ULongToPtr( params32->key ), + .key_size = params32->key_size, + .param_type = params32->param_type, + .data = ULongToPtr( params32->data ), + .data_size = params32->data_size, + .data_offset = params32->data_offset + }; + return nsi_get_parameter_ex( ¶ms ); +} + +const unixlib_entry_t __wine_unix_call_wow64_funcs[] = +{ + icmp_cancel_listen, + icmp_close, + icmp_listen, + icmp_send_echo, + wow64_nsi_enumerate_all_ex, + wow64_nsi_get_all_parameters_ex, + wow64_nsi_get_parameter_ex +}; + +#endif /* _WIN64 */
From: Huw Davies huw@codeweavers.com
Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/nsiproxy.sys/icmp_echo.c | 53 ++++++++++++++++++++++++++++++++ dlls/nsiproxy.sys/nsi.c | 4 +-- dlls/nsiproxy.sys/unix_private.h | 5 +++ 3 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/dlls/nsiproxy.sys/icmp_echo.c b/dlls/nsiproxy.sys/icmp_echo.c index e92fa4394c1..8686abd70ea 100644 --- a/dlls/nsiproxy.sys/icmp_echo.c +++ b/dlls/nsiproxy.sys/icmp_echo.c @@ -794,3 +794,56 @@ NTSTATUS icmp_close( void *args ) handle_free( params->handle ); return STATUS_SUCCESS; } + +#ifdef _WIN64 + +typedef UINT PTR32; + +NTSTATUS wow64_icmp_listen( void *args ) +{ + struct + { + icmp_handle handle; + PTR32 reply; + ULONGLONG user_reply_ptr; + unsigned int bits, reply_len; + int timeout; + } const *params32 = args; + struct icmp_listen_params params = + { + .handle = params32->handle, + .reply = ULongToPtr( params32->reply ), + .user_reply_ptr = params32->user_reply_ptr, + .bits = params32->bits, + .reply_len = params32->reply_len, + .timeout = params32->timeout + }; + return icmp_listen( ¶ms ); +} + +NTSTATUS wow64_icmp_send_echo( void *args ) +{ + struct + { + PTR32 dst; + PTR32 request, reply; + UINT request_size, reply_len; + BYTE bits, ttl, tos; + PTR32 handle; + } const *params32 = args; + struct icmp_send_echo_params params = + { + .dst = ULongToPtr( params32->dst ), + .request = ULongToPtr( params32->request ), + .reply = ULongToPtr( params32->reply ), + .request_size = params32->request_size, + .reply_len = params32->reply_len, + .bits = params32->bits, + .ttl = params32->ttl, + .tos = params32->tos, + .handle = ULongToPtr( params32->handle ) + }; + return icmp_send_echo( ¶ms ); +} + +#endif /* _WIN64 */ diff --git a/dlls/nsiproxy.sys/nsi.c b/dlls/nsiproxy.sys/nsi.c index 84fbf268254..b36d5b607e3 100644 --- a/dlls/nsiproxy.sys/nsi.c +++ b/dlls/nsiproxy.sys/nsi.c @@ -278,8 +278,8 @@ const unixlib_entry_t __wine_unix_call_wow64_funcs[] = { icmp_cancel_listen, icmp_close, - icmp_listen, - icmp_send_echo, + wow64_icmp_listen, + wow64_icmp_send_echo, wow64_nsi_enumerate_all_ex, wow64_nsi_get_all_parameters_ex, wow64_nsi_get_parameter_ex diff --git a/dlls/nsiproxy.sys/unix_private.h b/dlls/nsiproxy.sys/unix_private.h index 8ab56f6d9a3..8595dbf1622 100644 --- a/dlls/nsiproxy.sys/unix_private.h +++ b/dlls/nsiproxy.sys/unix_private.h @@ -161,3 +161,8 @@ NTSTATUS icmp_cancel_listen( void *args ) DECLSPEC_HIDDEN; NTSTATUS icmp_close( void *args ) DECLSPEC_HIDDEN; NTSTATUS icmp_listen( void *args ) DECLSPEC_HIDDEN; NTSTATUS icmp_send_echo( void *args ) DECLSPEC_HIDDEN; + +#ifdef _WIN64 +NTSTATUS wow64_icmp_listen( void *args ) DECLSPEC_HIDDEN; +NTSTATUS wow64_icmp_send_echo( void *args ) DECLSPEC_HIDDEN; +#endif /* _WIN64 */
Note that this is dead code, kernel drivers are always 64-bit in a wow64 setup.
Yeah, I'll push just the first two, which I think are an improvement.