Module: wine Branch: master Commit: 27193d36af35f7cae981eba70aebe44b4c282c49 URL: https://source.winehq.org/git/wine.git/?a=commit;h=27193d36af35f7cae981eba70...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Jan 28 18:22:08 2019 +0100
kernel32/tests: Add helper function for machine type manipulations.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/kernel32/tests/loader.c | 50 +++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c index 23dfc93..cc5af21 100644 --- a/dlls/kernel32/tests/loader.c +++ b/dlls/kernel32/tests/loader.c @@ -167,6 +167,32 @@ static IMAGE_SECTION_HEADER section = static const char filler[0x1000]; static const char section_data[0x10] = "section data";
+/* return an alternate machine of the same 32/64 bitness */ +static WORD get_alt_machine( WORD orig_machine ) +{ + switch (orig_machine) + { + case IMAGE_FILE_MACHINE_I386: return IMAGE_FILE_MACHINE_ARMNT; + case IMAGE_FILE_MACHINE_AMD64: return IMAGE_FILE_MACHINE_ARM64; + case IMAGE_FILE_MACHINE_ARMNT: return IMAGE_FILE_MACHINE_I386; + case IMAGE_FILE_MACHINE_ARM64: return IMAGE_FILE_MACHINE_AMD64; + } + return 0; +} + +/* return the machine of the alternate 32/64 bitness */ +static WORD get_alt_bitness_machine( WORD orig_machine ) +{ + switch (orig_machine) + { + case IMAGE_FILE_MACHINE_I386: return IMAGE_FILE_MACHINE_AMD64; + case IMAGE_FILE_MACHINE_AMD64: return IMAGE_FILE_MACHINE_I386; + case IMAGE_FILE_MACHINE_ARMNT: return IMAGE_FILE_MACHINE_ARM64; + case IMAGE_FILE_MACHINE_ARM64: return IMAGE_FILE_MACHINE_ARMNT; + } + return 0; +} + static DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size, const IMAGE_NT_HEADERS *nt_header, char dll_name[MAX_PATH] ) { @@ -692,7 +718,7 @@ static void test_Loader(void) SIZE_T size; BOOL ret; NTSTATUS status; - WORD alt_machine, orig_machine = nt_header_template.FileHeader.Machine; + WORD orig_machine = nt_header_template.FileHeader.Machine; IMAGE_NT_HEADERS nt_header; IMAGE_COR20_HEADER cor_header;
@@ -1013,26 +1039,12 @@ static void test_Loader(void) ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */ "NtCreateSection error %08x\n", status );
- switch (orig_machine) - { - case IMAGE_FILE_MACHINE_I386: alt_machine = IMAGE_FILE_MACHINE_ARMNT; break; - case IMAGE_FILE_MACHINE_AMD64: alt_machine = IMAGE_FILE_MACHINE_ARM64; break; - case IMAGE_FILE_MACHINE_ARMNT: alt_machine = IMAGE_FILE_MACHINE_I386; break; - case IMAGE_FILE_MACHINE_ARM64: alt_machine = IMAGE_FILE_MACHINE_AMD64; break; - } - nt_header.FileHeader.Machine = alt_machine; + nt_header.FileHeader.Machine = get_alt_machine( orig_machine ); status = map_image_section( &nt_header, §ion, section_data, __LINE__ ); ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */ "NtCreateSection error %08x\n", status );
- switch (orig_machine) - { - case IMAGE_FILE_MACHINE_I386: alt_machine = IMAGE_FILE_MACHINE_AMD64; break; - case IMAGE_FILE_MACHINE_AMD64: alt_machine = IMAGE_FILE_MACHINE_I386; break; - case IMAGE_FILE_MACHINE_ARMNT: alt_machine = IMAGE_FILE_MACHINE_ARM64; break; - case IMAGE_FILE_MACHINE_ARM64: alt_machine = IMAGE_FILE_MACHINE_ARMNT; break; - } - nt_header.FileHeader.Machine = alt_machine; + nt_header.FileHeader.Machine = get_alt_bitness_machine( orig_machine ); status = map_image_section( &nt_header, §ion, section_data, __LINE__ ); ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */ "NtCreateSection error %08x\n", status ); @@ -1118,7 +1130,7 @@ static void test_Loader(void) ok( status == (is_wow64 ? STATUS_INVALID_IMAGE_FORMAT : STATUS_INVALID_IMAGE_WIN_64), "NtCreateSection error %08x\n", status );
- nt64.FileHeader.Machine = alt_machine; + nt64.FileHeader.Machine = get_alt_bitness_machine( orig_machine ); status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ ); ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64), "NtCreateSection error %08x\n", status ); @@ -1232,7 +1244,7 @@ static void test_Loader(void) ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(!status) /* win8 */, "NtCreateSection error %08x\n", status );
- nt32.FileHeader.Machine = alt_machine; + nt32.FileHeader.Machine = get_alt_bitness_machine( orig_machine ); status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ ); ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );