Huw Davies : nsiproxy: Use an unsigned integer for the ICMP handles.

Alexandre Julliard julliard at winehq.org
Tue Jun 21 15:45:24 CDT 2022


Module: wine
Branch: master
Commit: 7bd58ba1317e4d8f37818283b770e316d201e839
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=7bd58ba1317e4d8f37818283b770e316d201e839

Author: Huw Davies <huw at codeweavers.com>
Date:   Fri Jun 17 10:22:18 2022 +0100

nsiproxy: Use an unsigned integer for the ICMP handles.

Signed-off-by: Huw Davies <huw at 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, &params );
 
     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 */




More information about the wine-cvs mailing list