From 32e929c0dae76c9050a856a2a250ea4035514dff Mon Sep 17 00:00:00 2001
From: Jukka Heinonen <jhei@iki.fi>
Date: Tue, 19 Aug 2003 00:59:23 +0000
Subject: [PATCH] When forcing call to DOS relay from protected mode, make sure
 that relay sees original stack and code pointers. Make it possible for DOS
 relay to modify code and stack pointers.

---
 dlls/winedos/relay.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/dlls/winedos/relay.c b/dlls/winedos/relay.c
index fa609ad2901..a42b4642224 100644
--- a/dlls/winedos/relay.c
+++ b/dlls/winedos/relay.c
@@ -103,12 +103,37 @@ static void RELAY_MakeShortContext( CONTEXT86 *context )
  * This stub is called by __wine_call_from_16_regs in order to marshall
  * relay parameters.
  */
-static void __stdcall RELAY_RelayStub( DOSRELAY proc, 
+static void __stdcall RELAY_RelayStub( DOSRELAY       proc, 
                                        unsigned char *args, 
-                                       void *context )
+                                       void          *ctx86 )
 {
     if (proc)
-        proc( (CONTEXT86*)context, *(LPVOID *)args );
+    {
+        CONTEXT86     *context    = (CONTEXT86*)ctx86;
+        RELAY_Stack16 *stack      = RELAY_GetPointer( context->Esp );
+
+        DWORD          old_seg_cs = context->SegCs;
+        DWORD          old_eip    = context->Eip;
+        DWORD          old_seg_ss = context->SegSs;
+        DWORD          old_esp    = context->Esp;
+
+        context->SegCs = stack->seg_cs;
+        context->Eip   = stack->eip;
+        context->SegSs = stack->seg_ss;
+        context->Esp   = stack->esp;
+
+        proc( context, *(LPVOID *)args );
+
+        stack->seg_cs = context->SegCs;
+        stack->eip    = context->Eip;
+        stack->seg_ss = context->SegSs;
+        stack->esp    = context->Esp;
+
+        context->SegCs = old_seg_cs;
+        context->Eip   = old_eip;
+        context->SegSs = old_seg_ss;
+        context->Esp   = old_esp;
+    }
 }
 
 
-- 
GitLab