winebuild-Fake_Dlls: Change layout of system call thunks.

Based on patches by Fabian Maurer.
This commit is contained in:
Zebediah Figura 2019-05-24 19:20:28 -05:00
parent 5634d119e0
commit 5b59788752
2 changed files with 103 additions and 79 deletions

View File

@ -1,23 +1,23 @@
From a3072f7d1387b22f73e947631a1b8d452e944976 Mon Sep 17 00:00:00 2001
From b34e0ac3eee5865a66316f28316b4134c615b078 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Thu, 11 May 2017 05:32:55 +0200
Subject: [PATCH] winebuild: Generate syscall thunks for ntdll exports.
Based on a patch by Erich E. Hoover.
---
dlls/ntdll/signal_i386.c | 6 ++-
dlls/ntdll/tests/exception.c | 2 +
include/winternl.h | 2 +-
tools/winebuild/build.h | 8 +++-
tools/winebuild/import.c | 10 +++--
tools/winebuild/parser.c | 59 +++++++++++++++++++++++++++
tools/winebuild/spec16.c | 22 +----------
tools/winebuild/spec32.c | 94 ++++++++++++++++++++++++++++++++++++++++++++
tools/winebuild/utils.c | 21 ++++++++++
9 files changed, 196 insertions(+), 28 deletions(-)
dlls/ntdll/signal_i386.c | 6 +-
dlls/ntdll/tests/exception.c | 2 +
include/winternl.h | 2 +-
tools/winebuild/build.h | 8 ++-
tools/winebuild/import.c | 10 ++--
tools/winebuild/parser.c | 59 ++++++++++++++++++++
tools/winebuild/spec16.c | 22 +-------
tools/winebuild/spec32.c | 104 +++++++++++++++++++++++++++++++++++
tools/winebuild/utils.c | 21 +++++++
9 files changed, 206 insertions(+), 28 deletions(-)
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index e62a3c3..b504074 100644
index 7c6e1b50c..a62fbd4bf 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -427,6 +427,9 @@ static size_t signal_stack_size;
@ -39,7 +39,7 @@ index e62a3c3..b504074 100644
context->SegCs = wine_get_cs();
context->SegSs = wine_get_ss();
context->EFlags = eflags;
@@ -2348,6 +2351,7 @@ NTSTATUS signal_alloc_thread( TEB **teb )
@@ -2335,6 +2338,7 @@ NTSTATUS signal_alloc_thread( TEB **teb )
*teb = addr;
(*teb)->Tib.Self = &(*teb)->Tib;
(*teb)->Tib.ExceptionList = (void *)~0UL;
@ -48,10 +48,10 @@ index e62a3c3..b504074 100644
if (!(thread_data->fs = wine_ldt_alloc_fs()))
{
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index 78cf355..b68fe58 100644
index ada28c91e..3ed8fa082 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -1632,6 +1632,8 @@ static void test_thread_context(void)
@@ -1651,6 +1651,8 @@ static void test_thread_context(void)
ok( (char *)context.Eip >= (char *)pNtGetContextThread - 0x10000 &&
(char *)context.Eip <= (char *)pNtGetContextThread + 0x10000,
"wrong Eip %08x/%08x\n", context.Eip, (DWORD)pNtGetContextThread );
@ -61,10 +61,10 @@ index 78cf355..b68fe58 100644
ok( context.SegCs == LOWORD(expect.SegCs), "wrong SegCs %08x/%08x\n", context.SegCs, expect.SegCs );
ok( context.SegDs == LOWORD(expect.SegDs), "wrong SegDs %08x/%08x\n", context.SegDs, expect.SegDs );
diff --git a/include/winternl.h b/include/winternl.h
index 2d487ea..8e8b629 100644
index 0e8cf30d7..4ec65ca63 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -358,7 +358,7 @@ typedef struct _TEB
@@ -357,7 +357,7 @@ typedef struct _TEB
PVOID CsrClientThread; /* 03c/0070 */
PVOID Win32ThreadInfo; /* 040/0078 */
ULONG Win32ClientInfo[31]; /* 044/0080 used for user32 private data in Wine */
@ -74,10 +74,10 @@ index 2d487ea..8e8b629 100644
ULONG FpSoftwareStatusRegister; /* 0c8/010c */
PVOID SystemReserved1[54]; /* 0cc/0110 used for krnl386.exe16 private data in Wine */
diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h
index d7b46a6..b8ab56e 100644
index 49473c768..0b7cb370b 100644
--- a/tools/winebuild/build.h
+++ b/tools/winebuild/build.h
@@ -102,6 +102,7 @@ typedef struct
@@ -103,6 +103,7 @@ typedef struct
int flags;
char *name; /* public name of this function */
char *link_name; /* name of the C symbol to link to */
@ -85,7 +85,7 @@ index d7b46a6..b8ab56e 100644
char *export_name; /* name exported under for noname exports */
union
{
@@ -128,6 +129,7 @@ typedef struct
@@ -129,6 +130,7 @@ typedef struct
int alloc_entry_points; /* number of allocated entry points */
int nb_names; /* number of entry points with names */
unsigned int nb_resources; /* number of resources */
@ -93,7 +93,7 @@ index d7b46a6..b8ab56e 100644
int characteristics; /* characteristics for the PE header */
int dll_characteristics;/* DLL characteristics for the PE header */
int subsystem; /* subsystem id */
@@ -137,6 +139,7 @@ typedef struct
@@ -138,6 +140,7 @@ typedef struct
ORDDEF **names; /* array of entry point names (points into entry_points) */
ORDDEF **ordinals; /* array of dll ordinals (points into entry_points) */
struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
@ -101,7 +101,7 @@ index d7b46a6..b8ab56e 100644
} DLLSPEC;
enum target_cpu
@@ -178,8 +181,9 @@ struct strarray
@@ -179,8 +182,9 @@ struct strarray
#define FLAG_FORWARD 0x200 /* function is a forwarded name */
#define FLAG_EXT_LINK 0x400 /* function links to an external symbol */
#define FLAG_EXPORT32 0x800 /* 32-bit export in 16-bit spec file */
@ -112,7 +112,7 @@ index d7b46a6..b8ab56e 100644
#define FLAG_CPU_MASK (FLAG_CPU(CPU_LAST + 1) - FLAG_CPU(0))
#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
#define FLAG_CPU_WIN32 (FLAG_CPU_MASK & ~FLAG_CPU_WIN64)
@@ -317,6 +321,8 @@ extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
@@ -323,6 +327,8 @@ extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
extern int parse_spec_file( FILE *file, DLLSPEC *spec );
extern int parse_def_file( FILE *file, DLLSPEC *spec );
@ -122,10 +122,10 @@ index d7b46a6..b8ab56e 100644
extern int byte_swapped;
diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c
index 6ab7765..628b817 100644
index d8abc9d03..9c7c605b6 100644
--- a/tools/winebuild/import.c
+++ b/tools/winebuild/import.c
@@ -451,6 +451,7 @@ static void check_undefined_forwards( DLLSPEC *spec )
@@ -454,6 +454,7 @@ static void check_undefined_forwards( DLLSPEC *spec )
/* flag the dll exports that link to an undefined symbol */
static void check_undefined_exports( DLLSPEC *spec )
{
@ -133,7 +133,7 @@ index 6ab7765..628b817 100644
int i;
for (i = 0; i < spec->nb_entry_points; i++)
@@ -458,7 +459,8 @@ static void check_undefined_exports( DLLSPEC *spec )
@@ -461,7 +462,8 @@ static void check_undefined_exports( DLLSPEC *spec )
ORDDEF *odp = &spec->entry_points[i];
if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
if (odp->flags & FLAG_FORWARD) continue;
@ -143,7 +143,7 @@ index 6ab7765..628b817 100644
{
switch(odp->type)
{
@@ -469,14 +471,14 @@ static void check_undefined_exports( DLLSPEC *spec )
@@ -472,14 +474,14 @@ static void check_undefined_exports( DLLSPEC *spec )
if (link_ext_symbols)
{
odp->flags |= FLAG_EXT_LINK;
@ -162,10 +162,10 @@ index 6ab7765..628b817 100644
}
}
diff --git a/tools/winebuild/parser.c b/tools/winebuild/parser.c
index dfb7f6f..b758ca0 100644
index bec9f523e..da832de0e 100644
--- a/tools/winebuild/parser.c
+++ b/tools/winebuild/parser.c
@@ -547,6 +547,24 @@ static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
@@ -540,6 +540,24 @@ static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
}
@ -190,7 +190,7 @@ index dfb7f6f..b758ca0 100644
/*******************************************************************
* parse_spec_ordinal
*
@@ -622,6 +640,14 @@ static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
@@ -615,6 +633,14 @@ static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
assert( 0 );
}
@ -205,7 +205,7 @@ index dfb7f6f..b758ca0 100644
if ((odp->flags & FLAG_CPU_MASK) && !(odp->flags & FLAG_CPU(target_cpu)))
{
/* ignore this entry point */
@@ -818,6 +844,37 @@ static void assign_ordinals( DLLSPEC *spec )
@@ -812,6 +838,37 @@ static void assign_ordinals( DLLSPEC *spec )
}
@ -243,7 +243,7 @@ index dfb7f6f..b758ca0 100644
/*******************************************************************
* add_16bit_exports
*
@@ -919,6 +976,8 @@ int parse_spec_file( FILE *file, DLLSPEC *spec )
@@ -913,6 +970,8 @@ int parse_spec_file( FILE *file, DLLSPEC *spec )
current_line = 0; /* no longer parsing the input file */
assign_names( spec );
assign_ordinals( spec );
@ -253,13 +253,14 @@ index dfb7f6f..b758ca0 100644
}
diff --git a/tools/winebuild/spec16.c b/tools/winebuild/spec16.c
index 027580b..6163407 100644
index b21f47277..24a8f1054 100644
--- a/tools/winebuild/spec16.c
+++ b/tools/winebuild/spec16.c
@@ -494,27 +494,6 @@ static int relay_type_compare( const void *e1, const void *e2 )
@@ -495,27 +495,6 @@ static int relay_type_compare( const void *e1, const void *e2 )
}
/*******************************************************************
-/*******************************************************************
- * sort_func_list
- *
- * Sort a list of functions, removing duplicates.
@ -280,11 +281,10 @@ index 027580b..6163407 100644
-}
-
-
-/*******************************************************************
/*******************************************************************
* output_module16
*
* Output code for a 16-bit module.
@@ -542,6 +521,7 @@ static void output_module16( DLLSPEC *spec )
@@ -544,6 +523,7 @@ static void output_module16( DLLSPEC *spec )
entry_point->flags = FLAG_REGISTER;
entry_point->name = NULL;
entry_point->link_name = xstrdup( spec->init_func );
@ -293,13 +293,14 @@ index 027580b..6163407 100644
entry_point->u.func.nb_args = 0;
assert( !spec->ordinals[0] );
diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c
index 89f33c8..dc63c39 100644
index a0aa01754..fea45e398 100644
--- a/tools/winebuild/spec32.c
+++ b/tools/winebuild/spec32.c
@@ -357,6 +357,99 @@ static void output_relay_debug( DLLSPEC *spec )
@@ -371,6 +371,109 @@ static void output_relay_debug( DLLSPEC *spec )
}
}
/*******************************************************************
+/*******************************************************************
+ * output_syscall_thunks
+ *
+ * Output entry points for system call functions
@ -319,16 +320,17 @@ index 89f33c8..dc63c39 100644
+ ORDDEF *odp = spec->syscalls[i];
+ const char *name = odp->link_name;
+
+ /* Chromium attempts to hook system call thunks. It expects them to
+ * have a very specific form, or it will fail. The below matches what
+ * Chromium expects from 64-bit Windows 8. */
+
+ output( "\t.balign 16, 0\n" );
+ output( "\t%s\n", func_declaration(name) );
+ output( "%s\n", asm_globl(name) );
+ output_cfi( ".cfi_startproc" );
+ output( "\t.byte 0xb8\n" ); /* mov eax, SYSCALL */
+ output( "\t.long %d\n", i );
+ output( "\t.byte 0x33,0xc9\n" ); /* xor ecx, ecx */
+ output( "\t.byte 0x8d,0x54,0x24,0x04\n" ); /* lea edx, [esp + 4] */
+ output( "\t.byte 0x64,0xff,0x15,0xc0,0x00,0x00,0x00\n" ); /* call dword ptr fs:[0C0h] */
+ output( "\t.byte 0x83,0xc4,0x04\n" ); /* add esp, 4 */
+ output( "\t.byte 0xc2\n" ); /* ret X */
+ output( "\t.short %d\n", get_args_size(odp) );
+ output_cfi( ".cfi_endproc" );
@ -363,10 +365,15 @@ index 89f33c8..dc63c39 100644
+ output( "%s\n", asm_globl("__wine_syscall_dispatcher") );
+ output_cfi( ".cfi_startproc" );
+ output( "\tpushl %%ebp\n" );
+ output_cfi( ".cfi_adjust_cfa_offset 4\n" );
+ output_cfi( ".cfi_rel_offset %ebp,0\n" );
+ output( "\tmovl %%esp,%%ebp\n" );
+ output_cfi( ".cfi_def_cfa_register %ebp\n" );
+ output( "\tpushl %%esi\n" );
+ output_cfi( ".cfi_rel_offset %esi,-4\n" );
+ output( "\tpushl %%edi\n" );
+ output( "\tmovl %%edx,%%esi\n" );
+ output_cfi( ".cfi_rel_offset %edi,-8\n" );
+ output( "\tleal 12(%%ebp),%%esi\n" );
+ if (UsePIC)
+ {
+ output( "\tcall 1f\n" );
@ -377,26 +384,29 @@ index 89f33c8..dc63c39 100644
+ output( "movzbl %s(%%eax),%%ecx\n", asm_name("__wine_syscall_stack_size") );
+
+ output( "\tsubl %%ecx,%%esp\n" );
+ output( "\tmovl %%esp,%%edi\n" );
+ output( "\tshrl $2,%%ecx\n" );
+ output( "\tmovl %%esp,%%edi\n" );
+ output( "\trep; movsl\n" );
+ if (UsePIC)
+ output( "\tcall *(%s-1b)(%%edx,%%eax,%d)\n", asm_name("__wine_syscall_table"), get_ptr_size() );
+ else
+ output( "\tcall *%s(,%%eax,%d)\n", asm_name("__wine_syscall_table"), get_ptr_size() );
+ output( "\tpop %%edi\n" );
+ output_cfi( ".cfi_same_value %edi\n" );
+ output( "\tpop %%esi\n" );
+ output_cfi( ".cfi_same_value %esi\n" );
+ output( "\tleave\n" );
+ output( "\tjmp *(%%esp)\n" );
+ output_cfi( ".cfi_def_cfa %esp,4\n" );
+ output_cfi( ".cfi_same_value %ebp\n" );
+ output( "\tret\n" );
+ output_cfi( ".cfi_endproc" );
+ output_function_size( "__wine_syscall_dispatcher" );
+}
+
+/*******************************************************************
/*******************************************************************
* output_exports
*
* Output the export table for a Win32 module.
@@ -706,6 +799,7 @@ void BuildSpec32File( DLLSPEC *spec )
@@ -714,6 +817,7 @@ void output_spec32_file( DLLSPEC *spec )
open_output_file();
output_standard_file_header();
output_module( spec );
@ -405,10 +415,10 @@ index 89f33c8..dc63c39 100644
output_exports( spec );
output_imports( spec );
diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c
index 06c3d39..f331903 100644
index dbfe7a4ba..5796af2f6 100644
--- a/tools/winebuild/utils.c
+++ b/tools/winebuild/utils.c
@@ -839,6 +839,7 @@ void free_dll_spec( DLLSPEC *spec )
@@ -838,6 +838,7 @@ void free_dll_spec( DLLSPEC *spec )
free( odp->name );
free( odp->export_name );
free( odp->link_name );
@ -416,7 +426,7 @@ index 06c3d39..f331903 100644
}
free( spec->file_name );
free( spec->dll_name );
@@ -848,6 +849,7 @@ void free_dll_spec( DLLSPEC *spec )
@@ -847,6 +848,7 @@ void free_dll_spec( DLLSPEC *spec )
free( spec->names );
free( spec->ordinals );
free( spec->resources );
@ -424,7 +434,7 @@ index 06c3d39..f331903 100644
free( spec );
}
@@ -1175,3 +1177,22 @@ const char *get_asm_string_section(void)
@@ -1265,3 +1267,22 @@ const char *get_asm_string_section(void)
default: return ".section .rodata";
}
}
@ -448,5 +458,5 @@ index 06c3d39..f331903 100644
+ return j + 1;
+}
--
1.9.1
2.21.0

View File

@ -1,4 +1,4 @@
From a75cddcd2f710f40852647fcb2b4d6da9127c92b Mon Sep 17 00:00:00 2001
From 44cc514c7d00a562240b2180a342e3f647215c1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Thu, 7 Sep 2017 00:38:09 +0200
Subject: [PATCH] tools/winebuild: Add syscall thunks for 64 bit.
@ -6,14 +6,14 @@ Subject: [PATCH] tools/winebuild: Add syscall thunks for 64 bit.
---
dlls/kernel32/tests/loader.c | 7 +-
dlls/ntdll/signal_x86_64.c | 3 +
dlls/ntdll/thread.c | 6 +
dlls/ntdll/thread.c | 9 ++
libs/wine/loader.c | 4 +
tools/winebuild/parser.c | 2 +-
tools/winebuild/spec32.c | 210 ++++++++++++++++++++++++++++++++++-
6 files changed, 224 insertions(+), 8 deletions(-)
tools/winebuild/spec32.c | 221 ++++++++++++++++++++++++++++++++++-
6 files changed, 238 insertions(+), 8 deletions(-)
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 94a5109b4..15ec89f14 100644
index d9b349408..6f9673286 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -1527,7 +1527,7 @@ static void test_filenames(void)
@ -40,7 +40,7 @@ index 94a5109b4..15ec89f14 100644
todo_wine ok(0, "%s: Export is a stub-function, skipping\n", func_name);
continue;
diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index 54871b830..0ce0c22d7 100644
index c2151f78c..cdbc87c70 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -328,6 +328,8 @@ static inline struct amd64_thread_data *amd64_thread_data(void)
@ -52,7 +52,7 @@ index 54871b830..0ce0c22d7 100644
/***********************************************************************
* Dynamic unwind table
*/
@@ -3281,6 +3283,7 @@ NTSTATUS signal_alloc_thread( TEB **teb )
@@ -3284,6 +3286,7 @@ NTSTATUS signal_alloc_thread( TEB **teb )
{
(*teb)->Tib.Self = &(*teb)->Tib;
(*teb)->Tib.ExceptionList = (void *)~0UL;
@ -61,7 +61,7 @@ index 54871b830..0ce0c22d7 100644
return status;
}
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 394b3be60..11963689c 100644
index eeb4c1e27..c2ace3c03 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -60,6 +60,8 @@ struct _KUSER_SHARED_DATA *user_shared_data_external;
@ -73,22 +73,25 @@ index 394b3be60..11963689c 100644
void (WINAPI *kernel32_start_process)(LPTHREAD_START_ROUTINE,void*) = NULL;
/* info passed to a starting thread */
@@ -299,6 +301,10 @@ void thread_init(void)
@@ -298,6 +300,13 @@ void thread_init(void)
InitializeListHead( &ldr.InInitializationOrderModuleList );
*(ULONG_PTR *)peb->Reserved = get_image_addr();
+#if defined(__APPLE__) && defined(__x86_64__)
+ *((DWORD*)((char*)user_shared_data_external + 0x1000)) = __wine_syscall_dispatcher;
+#endif
+ /* Pretend we don't support the SYSCALL instruction on x86-64. Needed for
+ * Chromium; see output_syscall_thunks_x64() in winebuild. */
+ user_shared_data_external->SystemCallPad[0] = 1;
+
/*
* Starting with Vista, the first user to log on has session id 1.
* Session id 0 is for processes that don't interact with the user (like services).
diff --git a/libs/wine/loader.c b/libs/wine/loader.c
index e33e5b669..1fbcfd7f6 100644
index a2eee7aa9..dbfa5ba60 100644
--- a/libs/wine/loader.c
+++ b/libs/wine/loader.c
@@ -468,7 +468,11 @@ static void *map_dll( const IMAGE_NT_HEADERS *nt_descr )
@@ -467,7 +467,11 @@ static void *map_dll( const IMAGE_NT_HEADERS *nt_descr )
sec->SizeOfRawData = code_end - code_start;
sec->Misc.VirtualSize = sec->SizeOfRawData;
sec->VirtualAddress = code_start;
@ -101,10 +104,10 @@ index e33e5b669..1fbcfd7f6 100644
sec++;
diff --git a/tools/winebuild/parser.c b/tools/winebuild/parser.c
index b758ca0db..3e695406d 100644
index da832de0e..a09b9954b 100644
--- a/tools/winebuild/parser.c
+++ b/tools/winebuild/parser.c
@@ -549,7 +549,7 @@ static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
@@ -542,7 +542,7 @@ static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
static int needs_syscall( ORDDEF *odp, DLLSPEC *spec )
{
@ -114,7 +117,7 @@ index b758ca0db..3e695406d 100644
if (odp->flags & (FLAG_FORWARD | FLAG_REGISTER))
return 0;
diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c
index d0b1367ef..de510b3da 100644
index 8df1261e3..086ff747c 100644
--- a/tools/winebuild/spec32.c
+++ b/tools/winebuild/spec32.c
@@ -372,11 +372,11 @@ static void output_relay_debug( DLLSPEC *spec )
@ -131,7 +134,7 @@ index d0b1367ef..de510b3da 100644
{
const unsigned int page_size = get_page_size();
int i;
@@ -475,6 +475,91 @@ static void output_syscall_thunks( DLLSPEC *spec )
@@ -485,6 +485,102 @@ static void output_syscall_thunks( DLLSPEC *spec )
output_function_size( "__wine_syscall_dispatcher" );
}
@ -166,12 +169,25 @@ index d0b1367ef..de510b3da 100644
+ ORDDEF *odp = spec->syscalls[i];
+ const char *name = odp->link_name;
+
+ /* Chromium depends on syscall thunks having the same form as on
+ * Windows. For 64-bit systems the only viable form we can emulate is
+ * having an int $0x2e fallback. Since actually using an interrupt is
+ * expensive, and since for some reason Chromium doesn't actually
+ * validate that instruction, we can just put a jmp there instead. */
+
+ output( "\t.balign 16, 0\n" );
+ output( "\t%s\n", func_declaration(name) );
+ output( "%s\n", asm_globl(name) );
+ output_cfi( ".cfi_startproc" );
+ output( "\t.byte 0x4c,0x8b,0xd1\n" ); /* mov r10, rcx */
+ output( "\t.byte 0xb8\n" ); /* mov eax, SYSCALL */
+ output( "\t.long %d\n", i );
+ output( "\t.byte 0xf6,0x04,0x25,0x08,0x03,0xfe,0x7f,0x01\n" ); /* test byte ptr [0x7ffe0308], 1 */
+ output( "\t.byte 0x75,0x03\n" ); /* jne (over syscall) */
+ output( "\t.byte 0x0f,0x05\n" ); /* syscall */
+ output( "\t.byte 0xc3\n" ); /* ret */
+ output( "\t.byte 0xeb,0x01\n" ); /* jmp over ret */
+ output( "\t.byte 0xc3\n" ); /* ret */
+ if (target_platform == PLATFORM_APPLE)
+ {
+ output( "\t.byte 0xff,0x14,0x25\n" ); /* call [0x7ffe1000] */
@ -182,7 +198,7 @@ index d0b1367ef..de510b3da 100644
+ output( "\t.byte 0x65,0xff,0x14,0x25\n" ); /* call qword ptr gs:[0x100] */
+ output( "\t.long 0x100\n");
+ }
+ output( "\t.byte 0xc3\n" ); /* ret */
+ output( "\t.byte 0xc3\n" ); /* ret */
+ output_cfi( ".cfi_endproc" );
+ output_function_size( name );
+ }
@ -207,8 +223,6 @@ index d0b1367ef..de510b3da 100644
+ output_cfi( ".cfi_startproc" );
+ output( "\tadd $8, %%rsp\n" );
+ output_cfi( ".cfi_adjust_cfa_offset -8" );
+ output( "\tmovq $0xffffffff, %%r10\n" );
+ output( "\tandq %%r10, %%rax\n" );
+ if (UsePIC)
+ {
+ output( "\tleaq (%%rip), %%r10\n" );
@ -223,7 +237,7 @@ index d0b1367ef..de510b3da 100644
/*******************************************************************
* output_exports
*
@@ -803,7 +888,10 @@ void output_spec32_file( DLLSPEC *spec )
@@ -830,7 +926,10 @@ void output_spec32_file( DLLSPEC *spec )
open_output_file();
output_standard_file_header();
output_module( spec );
@ -235,7 +249,7 @@ index d0b1367ef..de510b3da 100644
output_stubs( spec );
output_exports( spec );
output_imports( spec );
@@ -816,7 +904,7 @@ void output_spec32_file( DLLSPEC *spec )
@@ -861,7 +960,7 @@ void output_pe_module( DLLSPEC *spec )
static int needs_stub_exports( DLLSPEC *spec )
{
@ -244,7 +258,7 @@ index d0b1367ef..de510b3da 100644
return 0;
if (!(spec->characteristics & IMAGE_FILE_DLL))
return 0;
@@ -826,7 +914,7 @@ static int needs_stub_exports( DLLSPEC *spec )
@@ -871,7 +970,7 @@ static int needs_stub_exports( DLLSPEC *spec )
}
@ -253,7 +267,7 @@ index d0b1367ef..de510b3da 100644
{
int i, nr_exports = spec->base <= spec->limit ? spec->limit - spec->base + 1 : 0;
size_t rva, thunk;
@@ -988,6 +1076,113 @@ static void create_stub_exports_text( DLLSPEC *spec )
@@ -1033,6 +1132,113 @@ static void create_stub_exports_text( DLLSPEC *spec )
}
@ -367,7 +381,7 @@ index d0b1367ef..de510b3da 100644
static void create_stub_exports_data( DLLSPEC *spec )
{
int i;
@@ -1187,7 +1382,10 @@ static void output_fake_module_pass( DLLSPEC *spec )
@@ -1232,7 +1438,10 @@ static void output_fake_module_pass( DLLSPEC *spec )
if (needs_stub_exports( spec ))
{
put_label( "text_start" );
@ -380,5 +394,5 @@ index d0b1367ef..de510b3da 100644
}
else
--
2.20.1
2.21.0