Module: wine Branch: master Commit: 8d50c3465579eeda92580f3c2153b6a07b0bd1f1 URL: https://source.winehq.org/git/wine.git/?a=commit;h=8d50c3465579eeda92580f3c2...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Apr 27 10:35:16 2021 +0200
server: Check the supported machines list to validate an image mapping.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
server/mapping.c | 32 ++++++++------------------------ server/object.h | 15 +++++++++++++++ server/thread.c | 6 ------ server/thread.h | 1 - 4 files changed, 23 insertions(+), 31 deletions(-)
diff --git a/server/mapping.c b/server/mapping.c index 3c4b707f282..a8de45482c9 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -642,7 +642,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s off_t pos; int size, opt_size; size_t mz_size, clr_va, clr_size; - unsigned int i, cpu_mask = get_supported_cpu_mask(); + unsigned int i;
/* load the headers */
@@ -671,17 +671,9 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s switch (nt.opt.hdr32.Magic) { case IMAGE_NT_OPTIONAL_HDR32_MAGIC: - switch (nt.FileHeader.Machine) - { - case IMAGE_FILE_MACHINE_I386: - if (cpu_mask & (CPU_FLAG(CPU_x86) | CPU_FLAG(CPU_x86_64))) break; - return STATUS_INVALID_IMAGE_FORMAT; - case IMAGE_FILE_MACHINE_ARMNT: - if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break; - return STATUS_INVALID_IMAGE_FORMAT; - default: - return STATUS_INVALID_IMAGE_FORMAT; - } + if (!is_machine_32bit( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; + if (!is_machine_supported( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; + clr_va = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; clr_size = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
@@ -710,18 +702,10 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s break;
case IMAGE_NT_OPTIONAL_HDR64_MAGIC: - if (!(cpu_mask & CPU_64BIT_MASK)) return STATUS_INVALID_IMAGE_WIN_64; - switch (nt.FileHeader.Machine) - { - case IMAGE_FILE_MACHINE_AMD64: - if (cpu_mask & (CPU_FLAG(CPU_x86) | CPU_FLAG(CPU_x86_64))) break; - return STATUS_INVALID_IMAGE_FORMAT; - case IMAGE_FILE_MACHINE_ARM64: - if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break; - return STATUS_INVALID_IMAGE_FORMAT; - default: - return STATUS_INVALID_IMAGE_FORMAT; - } + if (!is_machine_64bit( supported_machines[0] )) return STATUS_INVALID_IMAGE_WIN_64; + if (!is_machine_64bit( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; + if (!is_machine_supported( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; + clr_va = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; clr_size = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
diff --git a/server/object.h b/server/object.h index 604362d6e2c..89e39a7fa00 100644 --- a/server/object.h +++ b/server/object.h @@ -244,6 +244,21 @@ extern unsigned short supported_machines[8]; extern void init_registry(void); extern void flush_registry(void);
+static inline int is_machine_32bit( unsigned short machine ) +{ + return machine == IMAGE_FILE_MACHINE_I386 || machine == IMAGE_FILE_MACHINE_ARMNT; +} +static inline int is_machine_64bit( unsigned short machine ) +{ + return machine == IMAGE_FILE_MACHINE_AMD64 || machine == IMAGE_FILE_MACHINE_ARM64; +} +static inline int is_machine_supported( unsigned short machine ) +{ + unsigned int i; + for (i = 0; i < supported_machines_count; i++) if (supported_machines[i] == machine) return 1; + return 0; +} + /* signal functions */
extern void start_watchdog(void); diff --git a/server/thread.c b/server/thread.c index a649dc432f6..3c438a2002a 100644 --- a/server/thread.c +++ b/server/thread.c @@ -1341,12 +1341,6 @@ int is_cpu_supported( enum cpu_type cpu ) return 0; }
-/* return the cpu mask for supported cpus */ -unsigned int get_supported_cpu_mask(void) -{ - return supported_cpus & get_prefix_cpu_mask(); -} - /* create a new thread */ DECL_HANDLER(new_thread) { diff --git a/server/thread.h b/server/thread.h index 5f8eeeb3c50..0ae0a354695 100644 --- a/server/thread.h +++ b/server/thread.h @@ -120,7 +120,6 @@ 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 unsigned int get_supported_cpu_mask(void); extern int suspend_thread( struct thread *thread ); extern int resume_thread( struct thread *thread );