Author: ion Date: Sat Jul 23 11:48:42 2011 New Revision: 52804
URL: http://svn.reactos.org/svn/reactos?rev=52804&view=rev Log: [KERNEL32]: Bug #45: ConvertThreadToFiberEx should return ERROR_INVALID_PARAMETER if an invalid flag is passed. Bug #46: ConvertThreadToFiberEx should return ERROR_ALREADY_FIBER if the thread is already a fiber, not return the current fiber data.
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/f... ============================================================================== --- trunk/reactos/dll/win32/kernel32/client/fiber.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/fiber.c [iso-8859-1] Sat Jul 23 11:48:42 2011 @@ -93,48 +93,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; }
/*