[KERNEL32]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 16 May 2010 00:30:11 +0000 (00:30 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 16 May 2010 00:30:11 +0000 (00:30 +0000)
- SwitchToFiber: instead of doing a ret to the return address on the stack (which wouldn't work for a newly created fiber) store the returnaddress in the Eip field old fiber context and do a jmp to the Eip of the new fiber.
- BasepInitializeContext: set the Eip member of the Context to BaseFiberStartup for fibers
CreateFiberEx: initialize the fiber context, instead of an unused context on the stack.
- BaseFiberStartup: Use GetCurrentFiber, not GetFiberData to get the current fiber.
Fixes kernel32_wintest fiber

svn path=/trunk/; revision=47232

reactos/dll/win32/kernel32/misc/utils.c
reactos/dll/win32/kernel32/thread/fiber.c
reactos/dll/win32/kernel32/thread/i386/fiber.S

index cebd500..04fde77 100644 (file)
@@ -364,7 +364,7 @@ BasepInitializeContext(IN PCONTEXT Context,
     }
     else if (ContextType == 2) /* For Fibers */
     {
-        //Context->Eip = (ULONG)BaseFiberStartup;
+        Context->Eip = (ULONG)BaseFiberStartup;
     }
     else                       /* For first thread in a Process */
     {
index 656bc6e..6ba2016 100644 (file)
@@ -146,9 +146,8 @@ CreateFiberEx(SIZE_T dwStackCommitSize,
     PFIBER pfCurFiber;
     NTSTATUS nErrCode;
     INITIAL_TEB usFiberInitialTeb;
-    CONTEXT ctxFiberContext;
     PVOID ActivationContextStack = NULL;
-    DPRINT1("Creating Fiber\n");
+    DPRINT("Creating Fiber\n");
 
 #ifdef SXS_SUPPORT_ENABLED
     /* Allocate the Activation Context Stack */
@@ -203,7 +202,7 @@ CreateFiberEx(SIZE_T dwStackCommitSize,
     }
 
     /* initialize the context for the fiber */
-    BasepInitializeContext(&ctxFiberContext,
+    BasepInitializeContext(&pfCurFiber->Context,
                            lpParameter,
                            lpStartAddress,
                            usFiberInitialTeb.StackBase,
@@ -253,10 +252,10 @@ WINAPI
 BaseFiberStartup(VOID)
 {
 #ifdef _M_IX86
-    PFIBER Fiber = GetFiberData();
+    PFIBER Fiber = GetCurrentFiber();
 
     /* Call the Thread Startup Routine */
-    DPRINT1("Starting Fiber\n");
+    DPRINT("Starting Fiber\n");
     BaseThreadStartup((LPTHREAD_START_ROUTINE)Fiber->Context.Eax,
                       (LPVOID)Fiber->Context.Ebx);
 #else
index cf8bbe0..57358ff 100644 (file)
@@ -24,7 +24,11 @@ _SwitchToFiber@4:
     mov [eax+FIBER_CONTEXT_ESI], esi
     mov [eax+FIBER_CONTEXT_EDI], edi
     mov [eax+FIBER_CONTEXT_EBP], ebp
-    
+
+    /* Save the return address */
+    mov ebx, [esp]
+    mov [eax+FIBER_CONTEXT_EIP], ebx
+
     /* Check if we're to save FPU State */
     cmp dword ptr [eax+FIBER_CONTEXT_FLAGS], CONTEXT_FULL | CONTEXT_FLOATING_POINT
     jnz NoFpuStateSave
@@ -115,7 +119,7 @@ NoFpuStateRestore:
     mov eax, [ecx+FIBER_FLS_DATA]
     mov [edx+TEB_FLS_DATA], eax
 
-    /* Return */
-    ret 4
-    
+    /* Jump to new fiber */
+    jmp [ecx+FIBER_CONTEXT_EIP]
+
 /* EOF */