[KERNEL32]

- Reapply the ConvertThreadToFiberEx changes from r52804, they were lost in r52805. Confirmed by Alex.
See issue #6394 for more details.

svn path=/trunk/; revision=54162
This commit is contained in:
Thomas Faber 2011-10-16 15:04:26 +00:00
parent 1a1bb9dde4
commit a8c53e6e1a

View file

@ -79,48 +79,58 @@ WINAPI
ConvertThreadToFiberEx(LPVOID lpParameter, ConvertThreadToFiberEx(LPVOID lpParameter,
DWORD dwFlags) DWORD dwFlags)
{ {
PTEB pTeb = NtCurrentTeb(); PTEB Teb;
PFIBER pfCurFiber; PFIBER Fiber;
DPRINT1("Converting Thread to Fiber\n"); DPRINT1("Converting Thread to Fiber\n");
/* the current thread is already a fiber */ /* Check for invalid flags */
if(pTeb->HasFiberData && pTeb->NtTib.FiberData) return pTeb->NtTib.FiberData; if (dwFlags &~ FIBER_FLAG_FLOAT_SWITCH)
{
/* Fail */
SetLastError(ERROR_INVALID_PARAMETER);
return NULL;
}
/* allocate the fiber */ /* Are we already a fiber? */
pfCurFiber = (PFIBER)RtlAllocateHeap(GetProcessHeap(), Teb = NtCurrentTeb();
0, if (Teb->HasFiberData)
sizeof(FIBER)); {
/* Fail */
SetLastError(ERROR_ALREADY_FIBER);
return NULL;
}
/* failure */ /* Allocate the fiber */
if (pfCurFiber == NULL) Fiber = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(FIBER));
if (!Fiber)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL; return NULL;
} }
/* copy some contextual data from the thread to the fiber */ /* Copy some contextual data from the thread to the fiber */
pfCurFiber->Parameter = lpParameter; Fiber->Parameter = lpParameter;
pfCurFiber->ExceptionList = pTeb->NtTib.ExceptionList; Fiber->ExceptionList = Teb->NtTib.ExceptionList;
pfCurFiber->StackBase = pTeb->NtTib.StackBase; Fiber->StackBase = Teb->NtTib.StackBase;
pfCurFiber->StackLimit = pTeb->NtTib.StackLimit; Fiber->StackLimit = Teb->NtTib.StackLimit;
pfCurFiber->DeallocationStack = pTeb->DeallocationStack; Fiber->DeallocationStack = Teb->DeallocationStack;
pfCurFiber->FlsData = pTeb->FlsData; Fiber->FlsData = Teb->FlsData;
pfCurFiber->GuaranteedStackBytes = pTeb->GuaranteedStackBytes; Fiber->GuaranteedStackBytes = Teb->GuaranteedStackBytes;
pfCurFiber->ActivationContextStack = pTeb->ActivationContextStackPointer; Fiber->ActivationContextStack = Teb->ActivationContextStackPointer;
pfCurFiber->Context.ContextFlags = CONTEXT_FULL; Fiber->Context.ContextFlags = CONTEXT_FULL;
/* Save FPU State if requsted */ /* Save FPU State if requested */
if (dwFlags & FIBER_FLAG_FLOAT_SWITCH) if (dwFlags & FIBER_FLAG_FLOAT_SWITCH)
{ {
pfCurFiber->Context.ContextFlags |= CONTEXT_FLOATING_POINT; Fiber->Context.ContextFlags |= CONTEXT_FLOATING_POINT;
} }
/* associate the fiber to the current thread */ /* Associate the fiber to the current thread */
pTeb->NtTib.FiberData = pfCurFiber; Teb->NtTib.FiberData = Fiber;
pTeb->HasFiberData = TRUE; Teb->HasFiberData = TRUE;
/* success */ /* Return opaque fiber data */
return (LPVOID)pfCurFiber; return (LPVOID)Fiber;
} }
/* /*