Author: tfaber
Date: Sun Oct 16 15:04:26 2011
New Revision: 54162
URL:
http://svn.reactos.org/svn/reactos?rev=54162&view=rev
Log:
[KERNEL32]
- Reapply the ConvertThreadToFiberEx changes from r52804, they were lost in r52805.
Confirmed by Alex.
See issue #6394 for more details.
Modified:
trunk/reactos/dll/win32/kernel32/client/fiber.c
Modified: trunk/reactos/dll/win32/kernel32/client/fiber.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/fiber.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/fiber.c [iso-8859-1] Sun Oct 16 15:04:26 2011
@@ -79,48 +79,58 @@
ConvertThreadToFiberEx(LPVOID lpParameter,
DWORD dwFlags)
{
- PTEB pTeb = NtCurrentTeb();
- PFIBER pfCurFiber;
+ PTEB Teb;
+ PFIBER Fiber;
DPRINT1("Converting Thread to Fiber\n");
- /* the current thread is already a fiber */
- if(pTeb->HasFiberData && pTeb->NtTib.FiberData) return
pTeb->NtTib.FiberData;
-
- /* allocate the fiber */
- pfCurFiber = (PFIBER)RtlAllocateHeap(GetProcessHeap(),
- 0,
- sizeof(FIBER));
-
- /* failure */
- if (pfCurFiber == NULL)
+ /* Check for invalid flags */
+ if (dwFlags &~ FIBER_FLAG_FLOAT_SWITCH)
+ {
+ /* Fail */
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ /* Are we already a fiber? */
+ Teb = NtCurrentTeb();
+ if (Teb->HasFiberData)
+ {
+ /* Fail */
+ SetLastError(ERROR_ALREADY_FIBER);
+ return NULL;
+ }
+
+ /* Allocate the fiber */
+ Fiber = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(FIBER));
+ if (!Fiber)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
- /* copy some contextual data from the thread to the fiber */
- pfCurFiber->Parameter = lpParameter;
- pfCurFiber->ExceptionList = pTeb->NtTib.ExceptionList;
- pfCurFiber->StackBase = pTeb->NtTib.StackBase;
- pfCurFiber->StackLimit = pTeb->NtTib.StackLimit;
- pfCurFiber->DeallocationStack = pTeb->DeallocationStack;
- pfCurFiber->FlsData = pTeb->FlsData;
- pfCurFiber->GuaranteedStackBytes = pTeb->GuaranteedStackBytes;
- pfCurFiber->ActivationContextStack = pTeb->ActivationContextStackPointer;
- pfCurFiber->Context.ContextFlags = CONTEXT_FULL;
-
- /* Save FPU State if requsted */
+ /* Copy some contextual data from the thread to the fiber */
+ Fiber->Parameter = lpParameter;
+ Fiber->ExceptionList = Teb->NtTib.ExceptionList;
+ Fiber->StackBase = Teb->NtTib.StackBase;
+ Fiber->StackLimit = Teb->NtTib.StackLimit;
+ Fiber->DeallocationStack = Teb->DeallocationStack;
+ Fiber->FlsData = Teb->FlsData;
+ Fiber->GuaranteedStackBytes = Teb->GuaranteedStackBytes;
+ Fiber->ActivationContextStack = Teb->ActivationContextStackPointer;
+ Fiber->Context.ContextFlags = CONTEXT_FULL;
+
+ /* Save FPU State if requested */
if (dwFlags & FIBER_FLAG_FLOAT_SWITCH)
{
- pfCurFiber->Context.ContextFlags |= CONTEXT_FLOATING_POINT;
- }
-
- /* associate the fiber to the current thread */
- pTeb->NtTib.FiberData = pfCurFiber;
- pTeb->HasFiberData = TRUE;
-
- /* success */
- return (LPVOID)pfCurFiber;
+ Fiber->Context.ContextFlags |= CONTEXT_FLOATING_POINT;
+ }
+
+ /* Associate the fiber to the current thread */
+ Teb->NtTib.FiberData = Fiber;
+ Teb->HasFiberData = TRUE;
+
+ /* Return opaque fiber data */
+ return (LPVOID)Fiber;
}
/*