Alexandre Julliard : krnl386: Avoid using the selector functions from libwine.

Alexandre Julliard julliard at winehq.org
Thu Apr 2 14:27:35 CDT 2020


Module: wine
Branch: master
Commit: 1acb481d29319f0ecd0f0ad96ed1ab1e0caf5543
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=1acb481d29319f0ecd0f0ad96ed1ab1e0caf5543

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Apr  2 10:49:36 2020 +0200

krnl386: Avoid using the selector functions from libwine.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/krnl386.exe16/kernel.c           |  4 ++--
 dlls/krnl386.exe16/kernel16_private.h |  5 +++++
 dlls/krnl386.exe16/ne_module.c        |  2 +-
 dlls/krnl386.exe16/relay.c            |  2 +-
 dlls/krnl386.exe16/selector.c         |  4 ++--
 dlls/krnl386.exe16/snoop.c            |  4 ++--
 dlls/krnl386.exe16/syslevel.c         |  2 +-
 dlls/krnl386.exe16/thunk.c            | 19 ++++++++-----------
 dlls/krnl386.exe16/wowthunk.c         |  2 +-
 9 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/dlls/krnl386.exe16/kernel.c b/dlls/krnl386.exe16/kernel.c
index 5fcf19ff85..b1cfccacc7 100644
--- a/dlls/krnl386.exe16/kernel.c
+++ b/dlls/krnl386.exe16/kernel.c
@@ -113,8 +113,8 @@ BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
 
     NE_SetEntryPoint( inst, 178, GetWinFlags16() );
 
-    NE_SetEntryPoint( inst, 454, wine_get_cs() );
-    NE_SetEntryPoint( inst, 455, wine_get_ds() );
+    NE_SetEntryPoint( inst, 454, get_cs() );
+    NE_SetEntryPoint( inst, 455, get_ds() );
 
     NE_SetEntryPoint( inst, 183, DOSMEM_0000H );       /* KERNEL.183: __0000H */
     NE_SetEntryPoint( inst, 173, DOSMEM_BiosSysSeg );  /* KERNEL.173: __ROMBIOS */
diff --git a/dlls/krnl386.exe16/kernel16_private.h b/dlls/krnl386.exe16/kernel16_private.h
index d313188b93..7f4d7629b1 100644
--- a/dlls/krnl386.exe16/kernel16_private.h
+++ b/dlls/krnl386.exe16/kernel16_private.h
@@ -261,6 +261,11 @@ extern void SELECTOR_FreeBlock( WORD sel ) DECLSPEC_HIDDEN;
 #define IS_SELECTOR_32BIT(sel) \
    (ldt_is_system(sel) || (ldt_copy->flags[LOWORD(sel) >> 3] & LDT_FLAGS_32BIT))
 
+static inline WORD get_cs(void) { WORD res; __asm__( "movw %%cs,%0" : "=r" (res) ); return res; }
+static inline WORD get_ds(void) { WORD res; __asm__( "movw %%ds,%0" : "=r" (res) ); return res; }
+static inline WORD get_fs(void) { WORD res; __asm__( "movw %%fs,%0" : "=r" (res) ); return res; }
+static inline WORD get_gs(void) { WORD res; __asm__( "movw %%gs,%0" : "=r" (res) ); return res; }
+
 /* relay16.c */
 extern int relay_call_from_16( void *entry_point, unsigned char *args16, CONTEXT *context ) DECLSPEC_HIDDEN;
 extern void RELAY16_InitDebugLists(void) DECLSPEC_HIDDEN;
diff --git a/dlls/krnl386.exe16/ne_module.c b/dlls/krnl386.exe16/ne_module.c
index 3d8a5fe15a..b8c658566d 100644
--- a/dlls/krnl386.exe16/ne_module.c
+++ b/dlls/krnl386.exe16/ne_module.c
@@ -95,7 +95,7 @@ static inline void patch_code_segment( NE_MODULE *pModule )
             call[i].glue = __wine_call_from_16_regs;
         else
             call[i].glue = __wine_call_from_16;
-        call[i].flatcs = wine_get_cs();
+        call[i].flatcs = get_cs();
     }
 
     if (TRACE_ON(relay))  /* patch relay functions to all point to relay_call_from_16 */
diff --git a/dlls/krnl386.exe16/relay.c b/dlls/krnl386.exe16/relay.c
index 837f389230..c7bdab6f95 100644
--- a/dlls/krnl386.exe16/relay.c
+++ b/dlls/krnl386.exe16/relay.c
@@ -725,6 +725,6 @@ void DOSVM_BuildCallFrame( CONTEXT *context, DOSRELAY relay, LPVOID data )
     /*
      * Adjust code pointer.
      */
-    context->SegCs = wine_get_cs();
+    context->SegCs = get_cs();
     context->Eip = (DWORD)__wine_call_from_16_regs;
 }
diff --git a/dlls/krnl386.exe16/selector.c b/dlls/krnl386.exe16/selector.c
index 73284cf073..fd29081900 100644
--- a/dlls/krnl386.exe16/selector.c
+++ b/dlls/krnl386.exe16/selector.c
@@ -72,8 +72,8 @@ static LDT_ENTRY ldt_make_entry( const void *base, unsigned int limit, unsigned
  */
 void init_selectors(void)
 {
-    if (!is_gdt_sel( wine_get_gs() )) first_ldt_entry += 512;
-    if (!is_gdt_sel( wine_get_fs() )) first_ldt_entry += 512;
+    if (!is_gdt_sel( get_gs() )) first_ldt_entry += 512;
+    if (!is_gdt_sel( get_fs() )) first_ldt_entry += 512;
     RtlSetBits( &ldt_bitmap, 0, first_ldt_entry );
     ldt_copy = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"), "__wine_ldt_copy" );
 }
diff --git a/dlls/krnl386.exe16/snoop.c b/dlls/krnl386.exe16/snoop.c
index 941c656f28..4953e7e7ac 100644
--- a/dlls/krnl386.exe16/snoop.c
+++ b/dlls/krnl386.exe16/snoop.c
@@ -116,7 +116,7 @@ SNOOP16_RegisterDLL(HMODULE16 hModule,LPCSTR name) {
 		snr[0].realfun	= (DWORD)SNOOP16_Entry;
 		snr[0].lcall 	= 0x9a;
 		snr[0].callfromregs = (DWORD)__wine_call_from_16_regs;
-		snr[0].seg      = wine_get_cs();
+		snr[0].seg      = get_cs();
 		snr[0].lret     = 0xcb66;
 
 		snr[1].pushbp	= 0x5566;
@@ -126,7 +126,7 @@ SNOOP16_RegisterDLL(HMODULE16 hModule,LPCSTR name) {
 		snr[1].realfun	= (DWORD)SNOOP16_Return;
 		snr[1].lcall 	= 0x9a;
 		snr[1].callfromregs = (DWORD)__wine_call_from_16_regs;
-		snr[1].seg      = wine_get_cs();
+		snr[1].seg      = get_cs();
 		snr[1].lret     = 0xcb66;
 	}
 	while (*dll) {
diff --git a/dlls/krnl386.exe16/syslevel.c b/dlls/krnl386.exe16/syslevel.c
index 88b7ea9459..f9f0f2de13 100644
--- a/dlls/krnl386.exe16/syslevel.c
+++ b/dlls/krnl386.exe16/syslevel.c
@@ -108,7 +108,7 @@ VOID WINAPI _EnterSysLevel(SYSLEVEL *lock)
     TRACE("(%p, level %d): thread %x count after  %d\n",
           lock, lock->level, GetCurrentThreadId(), thread_data->sys_count[lock->level] );
 
-    if (lock == &Win16Mutex) CallTo16_TebSelector = wine_get_fs();
+    if (lock == &Win16Mutex) CallTo16_TebSelector = get_fs();
 }
 
 /************************************************************************
diff --git a/dlls/krnl386.exe16/thunk.c b/dlls/krnl386.exe16/thunk.c
index 06a6b4beb2..a9d81c5b3f 100644
--- a/dlls/krnl386.exe16/thunk.c
+++ b/dlls/krnl386.exe16/thunk.c
@@ -1168,7 +1168,7 @@ DEFINE_REGS_ENTRYPOINT( FreeMappedBuffer )
  */
 void WINAPI GetTEBSelectorFS16(void)
 {
-    CURRENT_STACK16->fs = wine_get_fs();
+    CURRENT_STACK16->fs = get_fs();
 }
 
 /**********************************************************************
@@ -1421,8 +1421,6 @@ UINT WINAPI ThunkConnect16(
 void WINAPI C16ThkSL(CONTEXT *context)
 {
     LPBYTE stub = MapSL(context->Eax), x = stub;
-    WORD cs = wine_get_cs();
-    WORD ds = wine_get_ds();
 
     /* We produce the following code:
      *
@@ -1437,7 +1435,7 @@ void WINAPI C16ThkSL(CONTEXT *context)
      *   call __FLATCS:__wine_call_from_16_thunk
      */
 
-    *x++ = 0xB8; *(WORD *)x = ds; x += sizeof(WORD);
+    *x++ = 0xB8; *(WORD *)x = get_ds(); x += sizeof(WORD);
     *x++ = 0x8E; *x++ = 0xC0;
     *x++ = 0x66; *x++ = 0x0F; *x++ = 0xB7; *x++ = 0xC9;
     *x++ = 0x67; *x++ = 0x66; *x++ = 0x26; *x++ = 0x8B;
@@ -1449,7 +1447,7 @@ void WINAPI C16ThkSL(CONTEXT *context)
     *x++ = 0x66; *x++ = 0x52;
     *x++ = 0x66; *x++ = 0x9A;
     *(void **)x = __wine_call_from_16_thunk; x += sizeof(void *);
-    *(WORD *)x = cs; x += sizeof(WORD);
+    *(WORD *)x = get_cs(); x += sizeof(WORD);
 
     /* Jump to the stub code just created */
     context->Eip = LOWORD(context->Eax);
@@ -1474,7 +1472,6 @@ void WINAPI C16ThkSL01(CONTEXT *context)
         struct ThunkDataSL *td = SL16->fpData;
 
         DWORD procAddress = (DWORD)GetProcAddress16(GetModuleHandle16("KERNEL"), (LPCSTR)631);
-        WORD cs = wine_get_cs();
 
         if (!td)
         {
@@ -1507,7 +1504,7 @@ void WINAPI C16ThkSL01(CONTEXT *context)
         *x++ = 0x66; *x++ = 0x52;
         *x++ = 0x66; *x++ = 0x9A;
         *(void **)x = __wine_call_from_16_thunk; x += sizeof(void *);
-        *(WORD *)x = cs; x += sizeof(WORD);
+        *(WORD *)x = get_cs(); x += sizeof(WORD);
 
         /* Jump to the stub code just created */
         context->Eip = LOWORD(context->Eax);
@@ -1979,7 +1976,7 @@ void WINAPI CBClientThunkSL( CONTEXT *context )
     SEGPTR stack = stack16_push( 12 );
     LPWORD stackLin = MapSL(stack);
     /* stackLin[0] and stackLin[1] reserved for the 32-bit stack ptr */
-    stackLin[2] = wine_get_ss();
+    stackLin[2] = get_ds();
     stackLin[3] = 0;
     stackLin[4] = OFFSETOF(stack) + 12;
     stackLin[5] = SELECTOROF(stack);
@@ -2007,10 +2004,10 @@ void WINAPI CBClientThunkSLEx( CONTEXT *context )
     stackLin = MapSL(stack);
     stackLin[0] = OFFSETOF(stack) + 4;
     stackLin[1] = SELECTOROF(stack);
-    stackLin[2] = wine_get_ds();
+    stackLin[2] = get_ds();
     stackLin[5] = OFFSETOF(stack) + 24;
     /* stackLin[6] and stackLin[7] reserved for the 32-bit stack ptr */
-    stackLin[8] = wine_get_ss();
+    stackLin[8] = get_ds();
     stackLin[9] = 0;
     stackLin[10] = OFFSETOF(CALL32_CBClientEx_RetAddr);
     stackLin[11] = SELECTOROF(CALL32_CBClientEx_RetAddr);
@@ -2065,7 +2062,7 @@ SEGPTR WINAPI Get16DLLAddress(HMODULE16 handle, LPSTR func_name)
     *thunk++ = 0xea;
     *(void **)thunk = QT_Thunk;
     thunk += sizeof(FARPROC16);
-    *(WORD *)thunk = wine_get_cs();
+    *(WORD *)thunk = get_cs();
 
     return MAKESEGPTR( code_sel32, (char *)thunk - (char *)ThunkletHeap );
 }
diff --git a/dlls/krnl386.exe16/wowthunk.c b/dlls/krnl386.exe16/wowthunk.c
index cde3a2175b..616a0a1052 100644
--- a/dlls/krnl386.exe16/wowthunk.c
+++ b/dlls/krnl386.exe16/wowthunk.c
@@ -64,7 +64,7 @@ BOOL WOWTHUNK_Init(void)
 
       /* Patch the return addresses for CallTo16 routines */
 
-    CallTo16_DataSelector = wine_get_ds();
+    CallTo16_DataSelector = get_ds();
     call16_ret_addr = MAKESEGPTR( codesel, (BYTE *)__wine_call_to_16_ret - __wine_call16_start );
     CALL32_CBClient_RetAddr =
         MAKESEGPTR( codesel, (BYTE *)CALL32_CBClient_Ret - __wine_call16_start );




More information about the wine-cvs mailing list