mirror of
git://source.winehq.org/git/wine.git
synced 2024-11-05 18:01:34 +00:00
nsiproxy: Use an unsigned integer for the ICMP handles.
Signed-off-by: Huw Davies <huw@codeweavers.com>
This commit is contained in:
parent
1c83efac77
commit
7bd58ba131
3 changed files with 41 additions and 27 deletions
|
@ -180,19 +180,20 @@ static NTSTATUS nsiproxy_get_parameter( IRP *irp )
|
||||||
return status;
|
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 )
|
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 );
|
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
|
cancel it, or the irp has already finished. If the handle
|
||||||
does exist then notify the listen thread. In all cases the irp
|
does exist then notify the listen thread. In all cases the irp
|
||||||
will be completed elsewhere. */
|
will be completed elsewhere. */
|
||||||
handle = irp_get_icmp_handle( irp );
|
params.handle = irp_get_icmp_handle( irp );
|
||||||
if (handle) nsiproxy_call( icmp_cancel_listen, handle );
|
if (params.handle) nsiproxy_call( icmp_cancel_listen, ¶ms );
|
||||||
|
|
||||||
LeaveCriticalSection( &nsiproxy_cs );
|
LeaveCriticalSection( &nsiproxy_cs );
|
||||||
}
|
}
|
||||||
|
@ -328,6 +329,7 @@ static DWORD WINAPI listen_thread_proc( void *arg )
|
||||||
IRP *irp = arg;
|
IRP *irp = arg;
|
||||||
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
||||||
struct nsiproxy_icmp_echo *in = irp->AssociatedIrp.SystemBuffer;
|
struct nsiproxy_icmp_echo *in = irp->AssociatedIrp.SystemBuffer;
|
||||||
|
struct icmp_close_params close_params;
|
||||||
struct icmp_listen_params params;
|
struct icmp_listen_params params;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
|
@ -345,7 +347,8 @@ static DWORD WINAPI listen_thread_proc( void *arg )
|
||||||
|
|
||||||
EnterCriticalSection( &nsiproxy_cs );
|
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;
|
irp->IoStatus.Status = status;
|
||||||
if (status == STATUS_SUCCESS)
|
if (status == STATUS_SUCCESS)
|
||||||
|
|
|
@ -120,10 +120,10 @@ static struct icmp_data *handle_table[MAX_HANDLES];
|
||||||
static pthread_mutex_t handle_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t handle_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static struct icmp_data **next_free, **next_unused = handle_table;
|
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;
|
struct icmp_data **entry;
|
||||||
HANDLE h;
|
icmp_handle h;
|
||||||
|
|
||||||
pthread_mutex_lock( &handle_lock );
|
pthread_mutex_lock( &handle_lock );
|
||||||
entry = next_free;
|
entry = next_free;
|
||||||
|
@ -136,25 +136,23 @@ static HANDLE handle_alloc( struct icmp_data *data )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*entry = data;
|
*entry = data;
|
||||||
h = LongToHandle( entry - handle_table + 1 );
|
h = entry - handle_table + 1;
|
||||||
pthread_mutex_unlock( &handle_lock );
|
pthread_mutex_unlock( &handle_lock );
|
||||||
TRACE( "returning handle %p\n", h );
|
TRACE( "returning handle %x\n", h );
|
||||||
return 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 (!h || h > MAX_HANDLES)
|
||||||
|
|
||||||
if (!idx || idx > MAX_HANDLES)
|
|
||||||
{
|
{
|
||||||
ERR( "Invalid icmp handle\n" );
|
ERR( "Invalid icmp handle\n" );
|
||||||
return NULL;
|
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 );
|
struct icmp_data **entry = handle_entry( h );
|
||||||
|
|
||||||
|
@ -162,11 +160,11 @@ static struct icmp_data *handle_data( HANDLE h )
|
||||||
return *entry;
|
return *entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_free( HANDLE h )
|
static void handle_free( icmp_handle h )
|
||||||
{
|
{
|
||||||
struct icmp_data **entry;
|
struct icmp_data **entry;
|
||||||
|
|
||||||
TRACE( "%p\n", h );
|
TRACE( "%x\n", h );
|
||||||
pthread_mutex_lock( &handle_lock );
|
pthread_mutex_lock( &handle_lock );
|
||||||
entry = handle_entry( h );
|
entry = handle_entry( h );
|
||||||
if (entry)
|
if (entry)
|
||||||
|
@ -778,8 +776,8 @@ NTSTATUS icmp_listen( void *args )
|
||||||
|
|
||||||
NTSTATUS icmp_cancel_listen( void *args )
|
NTSTATUS icmp_cancel_listen( void *args )
|
||||||
{
|
{
|
||||||
HANDLE handle = args;
|
struct icmp_cancel_listen_params *params = args;
|
||||||
struct icmp_data *data = handle_data( handle );
|
struct icmp_data *data = handle_data( params->handle );
|
||||||
|
|
||||||
if (!data) return STATUS_INVALID_PARAMETER;
|
if (!data) return STATUS_INVALID_PARAMETER;
|
||||||
write( data->cancel_pipe[1], "x", 1 );
|
write( data->cancel_pipe[1], "x", 1 );
|
||||||
|
@ -788,11 +786,11 @@ NTSTATUS icmp_cancel_listen( void *args )
|
||||||
|
|
||||||
NTSTATUS icmp_close( void *args )
|
NTSTATUS icmp_close( void *args )
|
||||||
{
|
{
|
||||||
HANDLE handle = args;
|
struct icmp_close_params *params = args;
|
||||||
struct icmp_data *data = handle_data( handle );
|
struct icmp_data *data = handle_data( params->handle );
|
||||||
|
|
||||||
if (!data) return STATUS_INVALID_PARAMETER;
|
if (!data) return STATUS_INVALID_PARAMETER;
|
||||||
icmp_data_free( data );
|
icmp_data_free( data );
|
||||||
handle_free( handle );
|
handle_free( params->handle );
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,22 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
* 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
|
struct icmp_listen_params
|
||||||
{
|
{
|
||||||
HANDLE handle;
|
icmp_handle handle;
|
||||||
void *reply;
|
void *reply;
|
||||||
ULONGLONG user_reply_ptr;
|
ULONGLONG user_reply_ptr;
|
||||||
unsigned int bits, reply_len;
|
unsigned int bits, reply_len;
|
||||||
|
@ -32,7 +45,7 @@ struct icmp_send_echo_params
|
||||||
void *request, *reply;
|
void *request, *reply;
|
||||||
UINT request_size, reply_len;
|
UINT request_size, reply_len;
|
||||||
BYTE bits, ttl, tos;
|
BYTE bits, ttl, tos;
|
||||||
HANDLE handle;
|
icmp_handle handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* output for IOCTL_NSIPROXY_WINE_ICMP_ECHO - cf. ICMP_ECHO_REPLY */
|
/* output for IOCTL_NSIPROXY_WINE_ICMP_ECHO - cf. ICMP_ECHO_REPLY */
|
||||||
|
|
Loading…
Reference in a new issue