From 339ed576430fa0b7096563c5b19608ba87cba320 Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Tue, 27 Apr 2021 10:42:04 +0200
Subject: [PATCH] server: Get rid of the CPU type and functions.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 dlls/ntdll/unix/process.c      | 22 ++--------------------
 dlls/ntdll/unix/server.c       |  1 -
 dlls/ntdll/unix/unix_private.h |  4 ----
 include/wine/server_protocol.h | 14 +++-----------
 server/debugger.c              |  2 +-
 server/mach.c                  |  2 +-
 server/object.h                |  1 -
 server/process.c               |  5 -----
 server/process.h               |  4 ----
 server/protocol.def            | 10 +---------
 server/registry.c              | 30 +-----------------------------
 server/request.h               |  6 ++----
 server/thread.c                | 28 ----------------------------
 server/thread.h                |  1 -
 server/trace.c                 | 17 +----------------
 tools/make_requests            |  1 -
 16 files changed, 12 insertions(+), 136 deletions(-)

diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c
index 6347d9d7c27..3f71d70e60f 100644
--- a/dlls/ntdll/unix/process.c
+++ b/dlls/ntdll/unix/process.c
@@ -70,25 +70,8 @@ static ULONG execute_flags = MEM_EXECUTE_OPTION_DISABLE | (sizeof(void *) > size
                                                            MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION |
                                                            MEM_EXECUTE_OPTION_PERMANENT : 0);
 
-static const char * const cpu_names[] = { "x86", "x86_64", "ARM", "ARM64" };
-
 static UINT process_error_mode;
 
-static client_cpu_t get_machine_cpu( pe_image_info_t *pe_info )
-{
-    switch (pe_info->machine)
-    {
-    case IMAGE_FILE_MACHINE_I386:
-        if ((is_win64 || is_wow64) && (pe_info->image_flags & IMAGE_FLAGS_ComPlusNativeReady))
-            return CPU_x86_64;
-        return CPU_x86;
-    case IMAGE_FILE_MACHINE_AMD64: return CPU_x86_64;
-    case IMAGE_FILE_MACHINE_ARMNT: return CPU_ARM;
-    case IMAGE_FILE_MACHINE_ARM64: return CPU_ARM64;
-    default: return 0;
-    }
-}
-
 static char **build_argv( const UNICODE_STRING *cmdline, int reserved )
 {
     char **argv, *arg, *src, *dst;
@@ -714,7 +697,6 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_
         req->flags          = process_flags;
         req->socket_fd      = socketfd[1];
         req->access         = process_access;
-        req->cpu            = get_machine_cpu( &pe_info );
         req->info_size      = startup_info_size;
         req->handles_size   = handles_size;
         wine_server_add_data( req, objattr, attr_len );
@@ -740,8 +722,8 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_
             ERR( "64-bit application %s not supported in 32-bit prefix\n", debugstr_us(&path) );
             break;
         case STATUS_INVALID_IMAGE_FORMAT:
-            ERR( "%s not supported on this installation (%s binary)\n",
-                 debugstr_us(&path), cpu_names[get_machine_cpu(&pe_info)] );
+            ERR( "%s not supported on this installation (machine %04x)\n",
+                 debugstr_us(&path), pe_info.machine );
             break;
         }
         goto done;
diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c
index 7849fe927f5..1ee903e1bf4 100644
--- a/dlls/ntdll/unix/server.c
+++ b/dlls/ntdll/unix/server.c
@@ -1561,7 +1561,6 @@ size_t server_init_process(void)
         req->reply_fd    = reply_pipe;
         req->wait_fd     = ntdll_get_thread_data()->wait_fd[1];
         req->debug_level = (TRACE_ON(server) != 0);
-        req->cpu         = client_cpu;
         wine_server_set_reply( req, supported_machines, sizeof(supported_machines) );
         ret = wine_server_call( req );
         NtCurrentTeb()->ClientId.UniqueProcess = ULongToHandle(reply->pid);
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index c75d5b6e701..9a7e9ca01d6 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -28,16 +28,12 @@
 #include "wine/list.h"
 
 #ifdef __i386__
-static const enum cpu_type client_cpu = CPU_x86;
 static const WORD current_machine = IMAGE_FILE_MACHINE_I386;
 #elif defined(__x86_64__)
-static const enum cpu_type client_cpu = CPU_x86_64;
 static const WORD current_machine = IMAGE_FILE_MACHINE_AMD64;
 #elif defined(__arm__)
-static const enum cpu_type client_cpu = CPU_ARM;
 static const WORD current_machine = IMAGE_FILE_MACHINE_ARMNT;
 #elif defined(__aarch64__)
-static const enum cpu_type client_cpu = CPU_ARM64;
 static const WORD current_machine = IMAGE_FILE_MACHINE_ARM64;
 #endif
 
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 31338700e9c..563799b6bdc 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -110,13 +110,6 @@ typedef union
 } debug_event_t;
 
 
-enum cpu_type
-{
-    CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64
-};
-typedef int client_cpu_t;
-
-
 typedef struct
 {
     unsigned int     machine;
@@ -832,7 +825,8 @@ struct new_process_request
     unsigned int flags;
     int          socket_fd;
     unsigned int access;
-    client_cpu_t cpu;
+    unsigned short machine;
+    char __pad_38[2];
     data_size_t  info_size;
     data_size_t  handles_size;
     /* VARARG(objattr,object_attributes); */
@@ -926,8 +920,6 @@ struct init_first_thread_request
     client_ptr_t ldt_copy;
     int          reply_fd;
     int          wait_fd;
-    client_cpu_t cpu;
-    char __pad_60[4];
 };
 struct init_first_thread_reply
 {
@@ -6219,7 +6211,7 @@ union generic_reply
 
 /* ### protocol_version begin ### */
 
-#define SERVER_PROTOCOL_VERSION 695
+#define SERVER_PROTOCOL_VERSION 696
 
 /* ### protocol_version end ### */
 
diff --git a/server/debugger.c b/server/debugger.c
index 2a2839f42ee..56c699302d4 100644
--- a/server/debugger.c
+++ b/server/debugger.c
@@ -134,7 +134,7 @@ static const struct object_ops debug_obj_ops =
 /* get a pointer to TEB->ArbitraryUserPointer in the client address space */
 static client_ptr_t get_teb_user_ptr( struct thread *thread )
 {
-    unsigned int ptr_size = (CPU_FLAG( thread->process->cpu ) & CPU_64BIT_MASK) ? 8 : 4;
+    unsigned int ptr_size = is_machine_64bit( thread->process->machine ) ? 8 : 4;
     return thread->teb + 5 * ptr_size;
 }
 
diff --git a/server/mach.c b/server/mach.c
index 69f3ee22a91..20bc3878560 100644
--- a/server/mach.c
+++ b/server/mach.c
@@ -240,7 +240,7 @@ void set_thread_context( struct thread *thread, const context_t *context, unsign
 
 
 #ifdef __x86_64__
-    if (thread->process->cpu == CPU_x86_64)
+    if (thread->process->machine == IMAGE_FILE_MACHINE_AMD64)
     {
         /* Mac OS doesn't allow setting the global breakpoint flags */
         dr7 = (context->debug.x86_64_regs.dr7 & ~0xaa) | ((context->debug.x86_64_regs.dr7 & 0xaa) >> 1);
diff --git a/server/object.h b/server/object.h
index 89e39a7fa00..e9d9a87875e 100644
--- a/server/object.h
+++ b/server/object.h
@@ -238,7 +238,6 @@ extern void generate_startup_debug_events( struct process *process );
 
 /* registry functions */
 
-extern unsigned int get_prefix_cpu_mask(void);
 extern unsigned int supported_machines_count;
 extern unsigned short supported_machines[8];
 extern void init_registry(void);
diff --git a/server/process.c b/server/process.c
index 780a2076a71..17abd9800d2 100644
--- a/server/process.c
+++ b/server/process.c
@@ -1045,11 +1045,6 @@ DECL_HANDLER(new_process)
         close( socket_fd );
         return;
     }
-    if (!is_cpu_supported( req->cpu ))
-    {
-        close( socket_fd );
-        return;
-    }
 
     if (req->parent_process)
     {
diff --git a/server/process.h b/server/process.h
index b49b8c9b919..0e1a83859d9 100644
--- a/server/process.h
+++ b/server/process.h
@@ -52,7 +52,6 @@ struct process
     process_id_t         id;              /* id of the process */
     process_id_t         group_id;        /* group id of the process */
     struct timeout_user *sigkill_timeout; /* timeout for final SIGKILL */
-    enum cpu_type        cpu;             /* client CPU type */
     unsigned short       machine;         /* client machine type */
     int                  unix_pid;        /* Unix pid for final SIGKILL */
     int                  exit_code;       /* process exit code */
@@ -90,9 +89,6 @@ struct process
     struct list          kernel_object;   /* list of kernel object pointers */
 };
 
-#define CPU_FLAG(cpu) (1 << (cpu))
-#define CPU_64BIT_MASK (CPU_FLAG(CPU_x86_64) | CPU_FLAG(CPU_ARM64))
-
 /* process functions */
 
 extern unsigned int alloc_ptid( void *ptr );
diff --git a/server/protocol.def b/server/protocol.def
index bd8d6335355..d061fca7073 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -125,13 +125,6 @@ typedef union
     } unload_dll;
 } debug_event_t;
 
-/* supported CPU types */
-enum cpu_type
-{
-    CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64
-};
-typedef int client_cpu_t;
-
 /* context data */
 typedef struct
 {
@@ -846,7 +839,7 @@ typedef struct
     unsigned int flags;          /* process creation flags */
     int          socket_fd;      /* file descriptor for process socket */
     unsigned int access;         /* access rights for process object */
-    client_cpu_t cpu;            /* CPU that the new process will use */
+    unsigned short machine;      /* architecture that the new process will use */
     data_size_t  info_size;      /* size of startup info */
     data_size_t  handles_size;   /* length of explicit handles list */
     VARARG(objattr,object_attributes);   /* object attributes */
@@ -909,7 +902,6 @@ typedef struct
     client_ptr_t ldt_copy;     /* address of LDT copy (in process address space) */
     int          reply_fd;     /* fd for reply pipe */
     int          wait_fd;      /* fd for blocking calls pipe */
-    client_cpu_t cpu;          /* CPU that this thread is running on */
 @REPLY
     process_id_t pid;          /* process id of the new thread's process */
     thread_id_t  tid;          /* thread id of the new thread */
diff --git a/server/registry.c b/server/registry.c
index 086297379e4..17281f24634 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -1769,34 +1769,6 @@ static WCHAR *format_user_registry_path( const SID *sid, struct unicode_str *pat
     return ascii_to_unicode_str( buffer, path );
 }
 
-/* get the cpu architectures that can be supported in the current prefix */
-unsigned int get_prefix_cpu_mask(void)
-{
-    /* Allowed server/client/prefix combinations:
-     *
-     *              prefix
-     *            32     64
-     *  server +------+------+ client
-     *         |  ok  | fail | 32
-     *      32 +------+------+---
-     *         | fail | fail | 64
-     *      ---+------+------+---
-     *         |  ok  |  ok  | 32
-     *      64 +------+------+---
-     *         | fail |  ok  | 64
-     *      ---+------+------+---
-     */
-    switch (prefix_type)
-    {
-    case PREFIX_64BIT:
-        /* 64-bit prefix requires 64-bit server */
-        return sizeof(void *) > sizeof(int) ? ~0 : 0;
-    case PREFIX_32BIT:
-    default:
-        return ~CPU_64BIT_MASK;  /* only 32-bit cpus supported on 32-bit prefix */
-    }
-}
-
 static void init_supported_machines(void)
 {
     unsigned int count = 0;
@@ -2072,7 +2044,7 @@ void flush_registry(void)
 /* determine if the thread is wow64 (32-bit client running on 64-bit prefix) */
 static int is_wow64_thread( struct thread *thread )
 {
-    return (prefix_type == PREFIX_64BIT && !(CPU_FLAG(thread->process->cpu) & CPU_64BIT_MASK));
+    return (is_machine_64bit( supported_machines[0] ) && !is_machine_64bit( thread->process->machine ));
 }
 
 
diff --git a/server/request.h b/server/request.h
index b8424b675c7..0512d536ad5 100644
--- a/server/request.h
+++ b/server/request.h
@@ -681,7 +681,6 @@ C_ASSERT( sizeof(apc_result_t) == 40 );
 C_ASSERT( sizeof(async_data_t) == 40 );
 C_ASSERT( sizeof(atom_t) == 4 );
 C_ASSERT( sizeof(char) == 1 );
-C_ASSERT( sizeof(client_cpu_t) == 4 );
 C_ASSERT( sizeof(client_ptr_t) == 8 );
 C_ASSERT( sizeof(data_size_t) == 4 );
 C_ASSERT( sizeof(file_pos_t) == 8 );
@@ -710,7 +709,7 @@ C_ASSERT( FIELD_OFFSET(struct new_process_request, parent_process) == 20 );
 C_ASSERT( FIELD_OFFSET(struct new_process_request, flags) == 24 );
 C_ASSERT( FIELD_OFFSET(struct new_process_request, socket_fd) == 28 );
 C_ASSERT( FIELD_OFFSET(struct new_process_request, access) == 32 );
-C_ASSERT( FIELD_OFFSET(struct new_process_request, cpu) == 36 );
+C_ASSERT( FIELD_OFFSET(struct new_process_request, machine) == 36 );
 C_ASSERT( FIELD_OFFSET(struct new_process_request, info_size) == 40 );
 C_ASSERT( FIELD_OFFSET(struct new_process_request, handles_size) == 44 );
 C_ASSERT( sizeof(struct new_process_request) == 48 );
@@ -746,8 +745,7 @@ C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, peb) == 32 );
 C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, ldt_copy) == 40 );
 C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, reply_fd) == 48 );
 C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, wait_fd) == 52 );
-C_ASSERT( FIELD_OFFSET(struct init_first_thread_request, cpu) == 56 );
-C_ASSERT( sizeof(struct init_first_thread_request) == 64 );
+C_ASSERT( sizeof(struct init_first_thread_request) == 56 );
 C_ASSERT( FIELD_OFFSET(struct init_first_thread_reply, pid) == 8 );
 C_ASSERT( FIELD_OFFSET(struct init_first_thread_reply, tid) == 12 );
 C_ASSERT( FIELD_OFFSET(struct init_first_thread_reply, server_start) == 16 );
diff --git a/server/thread.c b/server/thread.c
index e84d803f1bf..48f793b6a74 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -53,18 +53,6 @@
 #include "security.h"
 
 
-#ifdef __i386__
-static const unsigned int supported_cpus = CPU_FLAG(CPU_x86);
-#elif defined(__x86_64__)
-static const unsigned int supported_cpus = CPU_FLAG(CPU_x86_64) | CPU_FLAG(CPU_x86);
-#elif defined(__arm__)
-static const unsigned int supported_cpus = CPU_FLAG(CPU_ARM);
-#elif defined(__aarch64__)
-static const unsigned int supported_cpus = CPU_FLAG(CPU_ARM64) | CPU_FLAG(CPU_ARM);
-#else
-#error Unsupported CPU
-#endif
-
 /* thread queues */
 
 struct thread_wait
@@ -1326,21 +1314,6 @@ struct token *thread_get_impersonation_token( struct thread *thread )
         return thread->process->token;
 }
 
-/* check if a cpu type can be supported on this server */
-int is_cpu_supported( enum cpu_type cpu )
-{
-    unsigned int prefix_cpu_mask = get_prefix_cpu_mask();
-
-    if (supported_cpus & prefix_cpu_mask & CPU_FLAG(cpu)) return 1;
-    if (!(supported_cpus & prefix_cpu_mask))
-        set_error( STATUS_NOT_SUPPORTED );
-    else if (supported_cpus & CPU_FLAG(cpu))
-        set_error( STATUS_INVALID_IMAGE_WIN_64 );  /* server supports it but not the prefix */
-    else
-        set_error( STATUS_INVALID_IMAGE_FORMAT );
-    return 0;
-}
-
 /* create a new thread */
 DECL_HANDLER(new_thread)
 {
@@ -1444,7 +1417,6 @@ DECL_HANDLER(init_first_thread)
     current->teb      = req->teb;
     process->peb      = req->peb;
     process->ldt_copy = req->ldt_copy;
-    process->cpu      = req->cpu;
 
     if (!process->parent_id)
         process->affinity = current->affinity = get_thread_affinity( current );
diff --git a/server/thread.h b/server/thread.h
index 0ae0a354695..74b828f768b 100644
--- a/server/thread.h
+++ b/server/thread.h
@@ -119,7 +119,6 @@ extern int thread_add_inflight_fd( struct thread *thread, int client, int server
 extern int thread_get_inflight_fd( struct thread *thread, int client );
 extern struct token *thread_get_impersonation_token( struct thread *thread );
 extern int set_thread_affinity( struct thread *thread, affinity_t affinity );
-extern int is_cpu_supported( enum cpu_type cpu );
 extern int suspend_thread( struct thread *thread );
 extern int resume_thread( struct thread *thread );
 
diff --git a/server/trace.c b/server/trace.c
index c54e765f17f..0803108dc41 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -147,20 +147,6 @@ static void dump_ioctl_code( const char *prefix, const ioctl_code_t *code )
     }
 }
 
-static void dump_client_cpu( const char *prefix, const client_cpu_t *code )
-{
-    switch (*code)
-    {
-#define CASE(c) case CPU_##c: fprintf( stderr, "%s%s", prefix, #c ); break
-        CASE(x86);
-        CASE(x86_64);
-        CASE(ARM);
-        CASE(ARM64);
-        default: fprintf( stderr, "%s%u", prefix, *code ); break;
-#undef CASE
-    }
-}
-
 static void dump_apc_call( const char *prefix, const apc_call_t *call )
 {
     fprintf( stderr, "%s{", prefix );
@@ -1370,7 +1356,7 @@ static void dump_new_process_request( const struct new_process_request *req )
     fprintf( stderr, ", flags=%08x", req->flags );
     fprintf( stderr, ", socket_fd=%d", req->socket_fd );
     fprintf( stderr, ", access=%08x", req->access );
-    dump_client_cpu( ", cpu=", &req->cpu );
+    fprintf( stderr, ", machine=%04x", req->machine );
     fprintf( stderr, ", info_size=%u", req->info_size );
     fprintf( stderr, ", handles_size=%u", req->handles_size );
     dump_varargs_object_attributes( ", objattr=", cur_size );
@@ -1443,7 +1429,6 @@ static void dump_init_first_thread_request( const struct init_first_thread_reque
     dump_uint64( ", ldt_copy=", &req->ldt_copy );
     fprintf( stderr, ", reply_fd=%d", req->reply_fd );
     fprintf( stderr, ", wait_fd=%d", req->wait_fd );
-    dump_client_cpu( ", cpu=", &req->cpu );
 }
 
 static void dump_init_first_thread_reply( const struct init_first_thread_reply *req )
diff --git a/tools/make_requests b/tools/make_requests
index acee35cb2c4..a70b29df3d2 100755
--- a/tools/make_requests
+++ b/tools/make_requests
@@ -52,7 +52,6 @@ my %formats =
     "luid_t"        => [  8,   4,  "&dump_luid" ],
     "generic_map_t" => [  16,  4,  "&dump_generic_map" ],
     "ioctl_code_t"  => [  4,   4,  "&dump_ioctl_code" ],
-    "client_cpu_t"  => [  4,   4,  "&dump_client_cpu" ],
     "hw_input_t"    => [  32,  8,  "&dump_hw_input" ],
 );