From 86947587d206a0a95b4ac2c5458f8465ee4c371d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 17 Mar 2021 10:38:43 +0100 Subject: [PATCH] server: Remove the redundant cpu field in the PE image information. Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/loader.c | 13 +++++------ dlls/ntdll/unix/process.c | 40 ++++++++++++++++++++++------------ dlls/ntdll/unix/unix_private.h | 4 ++++ include/wine/server_protocol.h | 4 +--- server/mapping.c | 12 ++-------- server/protocol.def | 2 -- server/trace.c | 4 +--- 7 files changed, 40 insertions(+), 39 deletions(-) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 20f614f59f1..87a81343737 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -411,13 +411,13 @@ static void preloader_exec( char **argv ) execv( argv[1], argv + 1 ); } -static NTSTATUS loader_exec( const char *loader, char **argv, client_cpu_t cpu ) +static NTSTATUS loader_exec( const char *loader, char **argv, WORD machine ) { char *p, *path; if (build_dir) { - argv[1] = build_path( build_dir, (cpu == CPU_x86_64) ? "loader/wine64" : "loader/wine" ); + argv[1] = build_path( build_dir, (machine == IMAGE_FILE_MACHINE_AMD64) ? "loader/wine64" : "loader/wine" ); preloader_exec( argv ); return STATUS_INVALID_IMAGE_FORMAT; } @@ -452,7 +452,8 @@ static NTSTATUS loader_exec( const char *loader, char **argv, client_cpu_t cpu ) */ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_info ) { - int is_child_64bit = (pe_info->cpu == CPU_x86_64 || pe_info->cpu == CPU_ARM64); + int is_child_64bit = (pe_info->machine == IMAGE_FILE_MACHINE_AMD64 || + pe_info->machine == IMAGE_FILE_MACHINE_ARM64); ULONGLONG res_start = pe_info->base; ULONGLONG res_end = pe_info->base + pe_info->map_size; const char *loader = argv0; @@ -494,7 +495,7 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i putenv( preloader_reserve ); putenv( socket_env ); - return loader_exec( loader, argv, pe_info->cpu ); + return loader_exec( loader, argv, pe_info->machine ); } @@ -1037,8 +1038,6 @@ static void fill_builtin_image_info( void *module, pe_image_info_t *info ) info->checksum = nt->OptionalHeader.CheckSum; info->dbg_offset = 0; info->dbg_size = 0; - info->cpu = client_cpu; - info->__pad = 0; } @@ -1923,7 +1922,7 @@ void __wine_main( int argc, char *argv[], char *envp[] ) memcpy( new_argv + 1, argv, (argc + 1) * sizeof(*argv) ); putenv( noexec ); - loader_exec( argv0, new_argv, client_cpu ); + loader_exec( argv0, new_argv, current_machine ); fatal_error( "could not exec the wine loader\n" ); } } diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c index ca9951dfa03..441b34ee9c4 100644 --- a/dlls/ntdll/unix/process.c +++ b/dlls/ntdll/unix/process.c @@ -80,6 +80,18 @@ static const char * const cpu_names[] = { "x86", "x86_64", "PowerPC", "ARM", "AR static UINT process_error_mode; +static client_cpu_t get_machine_cpu( WORD machine ) +{ + switch (machine) + { + case IMAGE_FILE_MACHINE_I386: 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; @@ -356,10 +368,10 @@ static BOOL get_so_file_info( HANDLE handle, pe_image_info_t *info ) #endif switch (header.elf.machine) { - case 3: info->cpu = CPU_x86; break; - case 40: info->cpu = CPU_ARM; break; - case 62: info->cpu = CPU_x86_64; break; - case 183: info->cpu = CPU_ARM64; break; + case 3: info->machine = IMAGE_FILE_MACHINE_I386; break; + case 40: info->machine = IMAGE_FILE_MACHINE_ARMNT; break; + case 62: info->machine = IMAGE_FILE_MACHINE_AMD64; break; + case 183: info->machine = IMAGE_FILE_MACHINE_ARM64; break; } if (header.elf.type != 3 /* ET_DYN */) return FALSE; if (header.elf.class == 2 /* ELFCLASS64 */) @@ -385,10 +397,10 @@ static BOOL get_so_file_info( HANDLE handle, pe_image_info_t *info ) { switch (header.macho.cputype) { - case 0x00000007: info->cpu = CPU_x86; break; - case 0x01000007: info->cpu = CPU_x86_64; break; - case 0x0000000c: info->cpu = CPU_ARM; break; - case 0x0100000c: info->cpu = CPU_ARM64; break; + case 0x00000007: info->machine = IMAGE_FILE_MACHINE_I386; break; + case 0x01000007: info->machine = IMAGE_FILE_MACHINE_AMD64; break; + case 0x0000000c: info->machine = IMAGE_FILE_MACHINE_ARMNT; break; + case 0x0100000c: info->machine = IMAGE_FILE_MACHINE_ARM64; break; } if (header.macho.filetype == 8) return TRUE; } @@ -419,9 +431,9 @@ static NTSTATUS get_pe_file_info( UNICODE_STRING *path, HANDLE *handle, pe_image TRACE( "assuming %u-bit builtin for %s\n", is_64bit ? 64 : 32, debugstr_us(path)); /* assume current arch */ #if defined(__i386__) || defined(__x86_64__) - info->cpu = is_64bit ? CPU_x86_64 : CPU_x86; + info->machine = is_64bit ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386; #else - info->cpu = client_cpu; + info->machine = current_machine; #endif return STATUS_SUCCESS; } @@ -642,7 +654,7 @@ void DECLSPEC_NORETURN exec_process( NTSTATUS status ) case STATUS_INVALID_IMAGE_PROTECT: /* we'll start winevdm */ memset( &pe_info, 0, sizeof(pe_info) ); - pe_info.cpu = CPU_x86; + pe_info.machine = IMAGE_FILE_MACHINE_I386; break; default: goto done; @@ -668,7 +680,7 @@ void DECLSPEC_NORETURN exec_process( NTSTATUS status ) SERVER_START_REQ( exec_process ) { req->socket_fd = socketfd[1]; - req->cpu = pe_info.cpu; + req->cpu = get_machine_cpu( pe_info.machine ); status = wine_server_call( req ); } SERVER_END_REQ; @@ -952,7 +964,7 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_ req->create_flags = params->DebugFlags; /* hack: creation flags stored in DebugFlags for now */ req->socket_fd = socketfd[1]; req->access = process_access; - req->cpu = pe_info.cpu; + req->cpu = get_machine_cpu( pe_info.machine ); req->info_size = startup_info_size; req->handles_size = handles_size; wine_server_add_data( req, objattr, attr_len ); @@ -979,7 +991,7 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_ break; case STATUS_INVALID_IMAGE_FORMAT: ERR( "%s not supported on this installation (%s binary)\n", - debugstr_us(&path), cpu_names[pe_info.cpu] ); + debugstr_us(&path), cpu_names[get_machine_cpu(pe_info.machine)] ); break; } goto done; diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 3c961ce2ca5..7e31710af70 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -29,12 +29,16 @@ #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 struct debug_info diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index 0a1a5d80b1d..238d0d6045d 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -780,8 +780,6 @@ typedef struct unsigned int checksum; unsigned int dbg_offset; unsigned int dbg_size; - client_cpu_t cpu; - int __pad; } pe_image_info_t; #define IMAGE_FLAGS_ComPlusNativeReady 0x01 #define IMAGE_FLAGS_ComPlusILOnly 0x02 @@ -6231,7 +6229,7 @@ union generic_reply /* ### protocol_version begin ### */ -#define SERVER_PROTOCOL_VERSION 685 +#define SERVER_PROTOCOL_VERSION 686 /* ### protocol_version end ### */ diff --git a/server/mapping.c b/server/mapping.c index 6413594b94b..3a162eae76b 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -673,17 +673,12 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s switch (nt.FileHeader.Machine) { case IMAGE_FILE_MACHINE_I386: - mapping->image.cpu = CPU_x86; if (cpu_mask & (CPU_FLAG(CPU_x86) | CPU_FLAG(CPU_x86_64))) break; return STATUS_INVALID_IMAGE_FORMAT; - case IMAGE_FILE_MACHINE_ARM: - case IMAGE_FILE_MACHINE_THUMB: case IMAGE_FILE_MACHINE_ARMNT: - mapping->image.cpu = CPU_ARM; if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break; return STATUS_INVALID_IMAGE_FORMAT; case IMAGE_FILE_MACHINE_POWERPC: - mapping->image.cpu = CPU_POWERPC; if (cpu_mask & CPU_FLAG(CPU_POWERPC)) break; return STATUS_INVALID_IMAGE_FORMAT; default: @@ -721,11 +716,9 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s switch (nt.FileHeader.Machine) { case IMAGE_FILE_MACHINE_AMD64: - mapping->image.cpu = CPU_x86_64; if (cpu_mask & (CPU_FLAG(CPU_x86) | CPU_FLAG(CPU_x86_64))) break; return STATUS_INVALID_IMAGE_FORMAT; case IMAGE_FILE_MACHINE_ARM64: - mapping->image.cpu = CPU_ARM64; if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break; return STATUS_INVALID_IMAGE_FORMAT; default: @@ -769,7 +762,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s mapping->image.zerobits = 0; /* FIXME */ mapping->image.file_size = file_size; mapping->image.loader_flags = clr_va && clr_size; - mapping->image.__pad = 0; if (mz_size == sizeof(mz) && !memcmp( mz.buffer, builtin_signature, sizeof(builtin_signature) )) mapping->image.image_flags |= IMAGE_FLAGS_WineBuiltin; else if (mz_size == sizeof(mz) && !memcmp( mz.buffer, fakedll_signature, sizeof(fakedll_signature) )) @@ -798,8 +790,8 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s if (!(clr.Flags & COMIMAGE_FLAGS_32BITREQUIRED)) { mapping->image.image_flags |= IMAGE_FLAGS_ComPlusNativeReady; - if (cpu_mask & CPU_FLAG(CPU_x86_64)) mapping->image.cpu = CPU_x86_64; - else if (cpu_mask & CPU_FLAG(CPU_ARM64)) mapping->image.cpu = CPU_ARM64; + if (cpu_mask & CPU_FLAG(CPU_x86_64)) mapping->image.machine = IMAGE_FILE_MACHINE_AMD64; + else if (cpu_mask & CPU_FLAG(CPU_ARM64)) mapping->image.machine = IMAGE_FILE_MACHINE_ARM64; } if (clr.Flags & COMIMAGE_FLAGS_32BITPREFERRED) mapping->image.image_flags |= IMAGE_FLAGS_ComPlusPrefer32bit; diff --git a/server/protocol.def b/server/protocol.def index fa40a15c21a..a5790cda939 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -796,8 +796,6 @@ typedef struct unsigned int checksum; unsigned int dbg_offset; unsigned int dbg_size; - client_cpu_t cpu; - int __pad; } pe_image_info_t; #define IMAGE_FLAGS_ComPlusNativeReady 0x01 #define IMAGE_FLAGS_ComPlusILOnly 0x02 diff --git a/server/trace.c b/server/trace.c index b640236b816..5f906a5abfa 100644 --- a/server/trace.c +++ b/server/trace.c @@ -1307,13 +1307,11 @@ static void dump_varargs_pe_image_info( const char *prefix, data_size_t size ) fprintf( stderr, ",zerobits=%08x,subsystem=%08x,subsystem_minor=%04x,subsystem_major=%04x" ",osversion_major=%04x,osversion_minor=%04x,image_charact=%04x,dll_charact=%04x,machine=%04x" ",contains_code=%u,image_flags=%02x" - ",loader_flags=%08x,header_size=%08x,file_size=%08x,checksum=%08x", + ",loader_flags=%08x,header_size=%08x,file_size=%08x,checksum=%08x}", info.zerobits, info.subsystem, info.subsystem_minor, info.subsystem_major, info.osversion_major, info.osversion_minor, info.image_charact, info.dll_charact, info.machine, info.contains_code, info.image_flags, info.loader_flags, info.header_size, info.file_size, info.checksum ); - dump_client_cpu( ",cpu=", &info.cpu ); - fputc( '}', stderr ); remove_data( min( size, sizeof(info) )); }