From ab399468c2adfd8e1fef68cc907a9b25e8ac24ae Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Mon, 18 Nov 2024 21:34:40 +0100
Subject: [PATCH] server: Use an explicit union instead of a typedef for IRP
 params.

---
 dlls/ntoskrnl.exe/ntoskrnl.c   |  2 +-
 include/wine/server_protocol.h |  6 +++---
 server/device.c                | 27 ++++++++++++++-------------
 server/protocol.def            |  6 +++---
 server/request_handlers.h      |  2 +-
 server/request_trace.h         |  2 +-
 server/trace.c                 |  2 +-
 tools/make_requests            |  2 +-
 8 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index ec67781d9d1..ac2bc42dbb6 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -506,7 +506,7 @@ static NTSTATUS WINAPI dispatch_irp_completion( DEVICE_OBJECT *device, IRP *irp,
 
 struct dispatch_context
 {
-    irp_params_t params;
+    union irp_params params;
     HANDLE handle;
     struct irp_data *irp_data;
     ULONG  in_size;
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 51188a9c126..374c3dac6e1 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -748,7 +748,7 @@ enum irp_type
     IRP_CALL_CANCEL
 };
 
-typedef union
+union irp_params
 {
     enum irp_type        type;
     struct
@@ -816,7 +816,7 @@ typedef union
         int              __pad;
         client_ptr_t     irp;
     } cancel;
-} irp_params_t;
+};
 
 
 typedef struct
@@ -5239,7 +5239,7 @@ struct get_next_device_request_request
 struct get_next_device_request_reply
 {
     struct reply_header __header;
-    irp_params_t params;
+    union irp_params params;
     obj_handle_t next;
     thread_id_t  client_tid;
     client_ptr_t client_thread;
diff --git a/server/device.c b/server/device.c
index 436dac6bfe9..cab09700d8c 100644
--- a/server/device.c
+++ b/server/device.c
@@ -49,7 +49,7 @@ struct irp_call
     struct device_file    *file;          /* file containing this irp */
     struct thread         *thread;        /* thread that queued the irp */
     struct async          *async;         /* pending async op */
-    irp_params_t           params;        /* irp parameters */
+    union irp_params       params;        /* irp parameters */
     struct iosb           *iosb;          /* I/O status block */
     int                    canceled;      /* the call was canceled */
     client_ptr_t           user_ptr;      /* client side pointer */
@@ -348,7 +348,8 @@ static void irp_call_destroy( struct object *obj )
     if (irp->thread) release_object( irp->thread );
 }
 
-static struct irp_call *create_irp( struct device_file *file, const irp_params_t *params, struct async *async )
+static struct irp_call *create_irp( struct device_file *file, const union irp_params *params,
+                                    struct async *async )
 {
     struct irp_call *irp;
 
@@ -455,7 +456,7 @@ static struct object *device_open_file( struct object *obj, unsigned int access,
     if (device->manager)
     {
         struct irp_call *irp;
-        irp_params_t params;
+        union irp_params params;
 
         memset( &params, 0, sizeof(params) );
         params.create.type    = IRP_CALL_CREATE;
@@ -512,7 +513,7 @@ static int device_file_close_handle( struct object *obj, struct process *process
     if (!file->closed && file->device->manager && obj->handle_count == 1)  /* last handle */
     {
         struct irp_call *irp;
-        irp_params_t params;
+        union irp_params params;
 
         file->closed = 1;
         memset( &params, 0, sizeof(params) );
@@ -542,7 +543,7 @@ static void device_file_destroy( struct object *obj )
     release_object( file->device );
 }
 
-static int fill_irp_params( struct device_manager *manager, struct irp_call *irp, irp_params_t *params )
+static int fill_irp_params( struct device_manager *manager, struct irp_call *irp, union irp_params *params )
 {
     switch (irp->params.type)
     {
@@ -595,7 +596,7 @@ static void free_irp_params( struct irp_call *irp )
 }
 
 /* queue an irp to the device */
-static void queue_irp( struct device_file *file, const irp_params_t *params, struct async *async )
+static void queue_irp( struct device_file *file, const union irp_params *params, struct async *async )
 {
     struct irp_call *irp = create_irp( file, params, async );
     if (!irp) return;
@@ -615,7 +616,7 @@ static enum server_fd_type device_file_get_fd_type( struct fd *fd )
 static void device_file_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class )
 {
     struct device_file *file = get_fd_user( fd );
-    irp_params_t params;
+    union irp_params params;
 
     memset( &params, 0, sizeof(params) );
     params.volume.type = IRP_CALL_VOLUME;
@@ -626,7 +627,7 @@ static void device_file_get_volume_info( struct fd *fd, struct async *async, uns
 static void device_file_read( struct fd *fd, struct async *async, file_pos_t pos )
 {
     struct device_file *file = get_fd_user( fd );
-    irp_params_t params;
+    union irp_params params;
 
     memset( &params, 0, sizeof(params) );
     params.read.type = IRP_CALL_READ;
@@ -638,7 +639,7 @@ static void device_file_read( struct fd *fd, struct async *async, file_pos_t pos
 static void device_file_write( struct fd *fd, struct async *async, file_pos_t pos )
 {
     struct device_file *file = get_fd_user( fd );
-    irp_params_t params;
+    union irp_params params;
 
     memset( &params, 0, sizeof(params) );
     params.write.type = IRP_CALL_WRITE;
@@ -650,7 +651,7 @@ static void device_file_write( struct fd *fd, struct async *async, file_pos_t po
 static void device_file_flush( struct fd *fd, struct async *async )
 {
     struct device_file *file = get_fd_user( fd );
-    irp_params_t params;
+    union irp_params params;
 
     memset( &params, 0, sizeof(params) );
     params.flush.type = IRP_CALL_FLUSH;
@@ -660,7 +661,7 @@ static void device_file_flush( struct fd *fd, struct async *async )
 static void device_file_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
 {
     struct device_file *file = get_fd_user( fd );
-    irp_params_t params;
+    union irp_params params;
 
     memset( &params, 0, sizeof(params) );
     params.ioctl.type = IRP_CALL_IOCTL;
@@ -671,7 +672,7 @@ static void device_file_ioctl( struct fd *fd, ioctl_code_t code, struct async *a
 static void cancel_irp_call( struct irp_call *irp )
 {
     struct irp_call *cancel_irp;
-    irp_params_t params;
+    union irp_params params;
 
     irp->canceled = 1;
     if (!irp->user_ptr || !irp->file || !irp->file->device->manager) return;
@@ -842,7 +843,7 @@ void free_kernel_objects( struct object *obj )
     {
         struct kernel_object *kernel_object = LIST_ENTRY( ptr, struct kernel_object, list_entry );
         struct irp_call *irp;
-        irp_params_t params;
+        union irp_params params;
 
         assert( !kernel_object->owned );
 
diff --git a/server/protocol.def b/server/protocol.def
index 7b14b5e92eb..ec9ef1eb746 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -764,7 +764,7 @@ enum irp_type
     IRP_CALL_CANCEL
 };
 
-typedef union
+union irp_params
 {
     enum irp_type        type;      /* irp call type */
     struct
@@ -832,7 +832,7 @@ typedef union
         int              __pad;
         client_ptr_t     irp;       /* opaque ptr for canceled irp */
     } cancel;
-} irp_params_t;
+};
 
 /* information about a PE image mapping, roughly equivalent to SECTION_IMAGE_INFORMATION */
 typedef struct
@@ -3695,7 +3695,7 @@ typedef union
     data_size_t  result;          /* IOSB result of the previous irp */
     VARARG(data,bytes);           /* output data of the previous irp */
 @REPLY
-    irp_params_t params;          /* irp parameters */
+    union irp_params params;      /* irp parameters */
     obj_handle_t next;            /* handle to the next irp */
     thread_id_t  client_tid;      /* tid of thread calling irp */
     client_ptr_t client_thread;   /* pointer to thread object of calling irp */
diff --git a/server/request_handlers.h b/server/request_handlers.h
index 6611cb57153..9577bd0d947 100644
--- a/server/request_handlers.h
+++ b/server/request_handlers.h
@@ -608,7 +608,6 @@ C_ASSERT( sizeof(file_pos_t) == 8 );
 C_ASSERT( sizeof(generic_map_t) == 16 );
 C_ASSERT( sizeof(int) == 4 );
 C_ASSERT( sizeof(ioctl_code_t) == 4 );
-C_ASSERT( sizeof(irp_params_t) == 32 );
 C_ASSERT( sizeof(lparam_t) == 8 );
 C_ASSERT( sizeof(mem_size_t) == 8 );
 C_ASSERT( sizeof(mod_handle_t) == 8 );
@@ -641,6 +640,7 @@ C_ASSERT( sizeof(union apc_call) == 64 );
 C_ASSERT( sizeof(union apc_result) == 40 );
 C_ASSERT( sizeof(union debug_event_data) == 160 );
 C_ASSERT( sizeof(union hw_input) == 40 );
+C_ASSERT( sizeof(union irp_params) == 32 );
 C_ASSERT( sizeof(union message_data) == 48 );
 C_ASSERT( sizeof(unsigned __int64) == 8 );
 C_ASSERT( sizeof(unsigned char) == 1 );
diff --git a/server/request_trace.h b/server/request_trace.h
index 06976f33f1b..33fa57db10b 100644
--- a/server/request_trace.h
+++ b/server/request_trace.h
@@ -11,7 +11,7 @@ static void dump_async_data( const char *prefix, const struct async_data *val );
 static void dump_generic_map( const char *prefix, const generic_map_t *val );
 static void dump_hw_input( const char *prefix, const union hw_input *val );
 static void dump_ioctl_code( const char *prefix, const ioctl_code_t *val );
-static void dump_irp_params( const char *prefix, const irp_params_t *val );
+static void dump_irp_params( const char *prefix, const union irp_params *val );
 static void dump_luid( const char *prefix, const struct luid *val );
 static void dump_obj_locator( const char *prefix, const obj_locator_t *val );
 static void dump_rectangle( const char *prefix, const rectangle_t *val );
diff --git a/server/trace.c b/server/trace.c
index c3d4763c055..4c14df83c55 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -387,7 +387,7 @@ static void dump_async_data( const char *prefix, const struct async_data *data )
     fputc( '}', stderr );
 }
 
-static void dump_irp_params( const char *prefix, const irp_params_t *data )
+static void dump_irp_params( const char *prefix, const union irp_params *data )
 {
     switch (data->type)
     {
diff --git a/tools/make_requests b/tools/make_requests
index f028bd42dde..8354afb2b55 100755
--- a/tools/make_requests
+++ b/tools/make_requests
@@ -38,7 +38,6 @@ my %formats =
     "timeout_t"     => [  8,   8 ],
     "abstime_t"     => [  8,   8 ],
     "rectangle_t"   => [  16,  4 ],
-    "irp_params_t"  => [  32,  8 ],
     "generic_map_t" => [  16,  4 ],
     "ioctl_code_t"  => [  4,   4 ],
     "obj_locator_t" => [  16,  8 ],
@@ -58,6 +57,7 @@ my %formats =
     "struct filesystem_event"  => [ 12, 4 ],
     "struct handle_info"       => [ 20, 4 ],
     "union hw_input"           => [ 40, 8 ],
+    "union irp_params"         => [ 32, 8 ],
     "struct luid"              => [  8, 4 ],
     "struct luid_attr"         => [ 12, 4 ],
     "union message_data"       => [ 48, 8 ],
-- 
GitLab