From 67d9f3805972dda5ee4adcd862acdab07f76039e Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 8 Oct 2003 22:59:22 +0000 Subject: [PATCH] Added __wine_set_signal_fs function to avoid sharing the SYSLEVEL_Win16CurrentTeb variable between kernel and ntdll. On the kernel side, replaced SYSLEVEL_Win16CurrentTeb by CallTo16_TebSelector stored directly in the asm relay code to avoid a run-time relocation. --- dlls/kernel/syslevel.c | 12 +++++++++--- dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/signal_i386.c | 17 +++++++++++++---- tools/winebuild/relay.c | 13 +++++-------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dlls/kernel/syslevel.c b/dlls/kernel/syslevel.c index 565378481ed..790749e0e94 100644 --- a/dlls/kernel/syslevel.c +++ b/dlls/kernel/syslevel.c @@ -46,8 +46,10 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; static SYSLEVEL Win16Mutex = { { &critsect_debug, -1, 0, 0, 0, 0 }, 1 }; -/* Global variable to save current TEB while in 16-bit code */ -extern WORD SYSLEVEL_Win16CurrentTeb; +#ifdef __i386__ +extern unsigned int CallTo16_TebSelector; +extern void __wine_set_signal_fs( unsigned int fs ); +#endif /************************************************************************ @@ -114,7 +116,11 @@ VOID WINAPI _EnterSysLevel(SYSLEVEL *lock) lock, lock->level, GetCurrentThreadId(), teb->sys_count[lock->level] ); #ifdef __i386__ - if (lock == &Win16Mutex) SYSLEVEL_Win16CurrentTeb = wine_get_fs(); + if (lock == &Win16Mutex) + { + __wine_set_signal_fs( wine_get_fs() ); + CallTo16_TebSelector = wine_get_fs(); + } #endif } diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 6dead1e104e..f2f1d34e491 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1071,6 +1071,7 @@ # signal handling @ cdecl __wine_set_signal_handler(long ptr) +@ cdecl -norelay -i386 __wine_set_signal_fs(long) ################################################################ # Wine dll separation hacks, these will go away, don't use them diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index 37d7d84018c..e271fcae91d 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -417,8 +417,8 @@ static wine_signal_handler handlers[256]; extern void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); -/* Global variable to save current TEB while in 16-bit code (FIXME) */ -WORD SYSLEVEL_Win16CurrentTeb = 0; +/* Global variable to save the thread %fs register while in 16-bit code (FIXME) */ +static unsigned int signal_fs; /*********************************************************************** * dispatch_signal @@ -542,7 +542,7 @@ static void save_context( CONTEXT *context, const SIGCONTEXT *sigcontext ) * SS is still non-system segment. This is why both CS and SS * are checked. */ - wine_set_fs( SYSLEVEL_Win16CurrentTeb ); + wine_set_fs( signal_fs ); wine_set_gs( NtCurrentTeb()->gs_sel ); } #ifdef __HAVE_VM86 @@ -650,7 +650,7 @@ static void init_handler( const SIGCONTEXT *sigcontext ) if (!IS_SELECTOR_SYSTEM(CS_sig(sigcontext)) || !IS_SELECTOR_SYSTEM(SS_sig(sigcontext))) /* 16-bit mode */ { - wine_set_fs( SYSLEVEL_Win16CurrentTeb ); + wine_set_fs( signal_fs ); wine_set_gs( NtCurrentTeb()->gs_sel ); } #ifdef __HAVE_VM86 @@ -1193,6 +1193,15 @@ int __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh) } +/*********************************************************************** + * __wine_set_signal_fs (NTDLL.@) + */ +void __wine_set_signal_fs( unsigned int fs ) +{ + signal_fs = fs; +} + + /********************************************************************** * SIGNAL_Init */ diff --git a/tools/winebuild/relay.c b/tools/winebuild/relay.c index 7d7272fc790..9e027da5059 100644 --- a/tools/winebuild/relay.c +++ b/tools/winebuild/relay.c @@ -169,11 +169,11 @@ static void BuildCallFrom16Core( FILE *outfile, int reg_func, int thunk, int sho if ( UsePIC ) { - fprintf( outfile, "\tmovl " __ASM_NAME("SYSLEVEL_Win16CurrentTeb@GOT") "(%%ecx), %%edx\n" ); + fprintf( outfile, "\tmovl " __ASM_NAME("CallTo16_TebSelector@GOT") "(%%ecx), %%edx\n" ); fprintf( outfile, "\tmovw (%%edx), %%fs\n" ); } else - fprintf( outfile, "\tmovw " __ASM_NAME("SYSLEVEL_Win16CurrentTeb") ", %%fs\n" ); + fprintf( outfile, "\tmovw " __ASM_NAME("CallTo16_TebSelector") ", %%fs\n" ); fprintf( outfile, "\t.byte 0x64\n\tmovl (%d),%%gs\n", STRUCTOFFSET(TEB,gs_sel) ); @@ -615,11 +615,6 @@ static void BuildCallTo16Core( FILE *outfile, int reg_func ) */ static void BuildRet16Func( FILE *outfile ) { - /* - * Note: This must reside in the .data section to allow - * run-time relocation of the SYSLEVEL_Win16CurrentTeb symbol - */ - function_header( outfile, "CallTo16_Ret" ); /* Save %esp into %esi */ @@ -637,7 +632,7 @@ static void BuildRet16Func( FILE *outfile ) #endif fprintf( outfile, "\tmovw %%di,%%es\n" ); - fprintf( outfile, "\tmovw " __ASM_NAME("SYSLEVEL_Win16CurrentTeb") ",%%fs\n" ); + fprintf( outfile, "\t.byte 0x2e\n\tmovl " __ASM_NAME("CallTo16_TebSelector") "-" __ASM_NAME("Call16_Ret_Start") ",%%fs\n" ); fprintf( outfile, "\t.byte 0x64\n\tmovl (%d),%%gs\n", STRUCTOFFSET(TEB,gs_sel) ); @@ -658,6 +653,8 @@ static void BuildRet16Func( FILE *outfile ) fprintf( outfile, "\n\t.align %d\n", get_alignment(4) ); fprintf( outfile, "\t.globl " __ASM_NAME("CallTo16_DataSelector") "\n" ); fprintf( outfile, __ASM_NAME("CallTo16_DataSelector") ":\t.long 0\n" ); + fprintf( outfile, "\t.globl " __ASM_NAME("CallTo16_TebSelector") "\n" ); + fprintf( outfile, __ASM_NAME("CallTo16_TebSelector") ":\t.long 0\n" ); } -- 2.11.4.GIT