2005-07-19 21:04:19 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS System Libraries
|
2015-11-14 14:57:11 +00:00
|
|
|
* FILE: dll/win32/kernel32/client/fiber.c
|
2005-07-19 21:04:19 +00:00
|
|
|
* PURPOSE: Fiber Implementation
|
2015-04-28 21:27:16 +00:00
|
|
|
* PROGRAMMERS:
|
2005-07-19 21:04:19 +00:00
|
|
|
* Alex Ionescu (alex@relsoft.net)
|
|
|
|
* KJK::Hyperion <noog@libero.it>
|
2000-08-14 14:34:12 +00:00
|
|
|
*/
|
2003-01-15 21:24:36 +00:00
|
|
|
#include <k32.h>
|
|
|
|
|
2003-05-29 00:36:41 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
2000-08-14 14:34:12 +00:00
|
|
|
|
2015-04-28 21:27:16 +00:00
|
|
|
#ifdef _M_IX86
|
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, ExceptionList) == 0x04);
|
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, StackBase) == 0x08);
|
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, StackLimit) == 0x0C);
|
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, DeallocationStack) == 0x10);
|
2015-04-28 21:27:35 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, FiberContext) == 0x14);
|
2015-04-28 21:27:16 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, GuaranteedStackBytes) == 0x2E0);
|
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, FlsData) == 0x2E4);
|
2015-04-28 21:27:35 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(FIBER, ActivationContextStackPointer) == 0x2E8);
|
2015-04-28 21:27:16 +00:00
|
|
|
#endif // _M_IX86
|
2003-05-29 00:36:41 +00:00
|
|
|
|
2011-07-23 11:55:41 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
BaseRundownFls(_In_ PVOID FlsData)
|
2011-07-23 11:55:41 +00:00
|
|
|
{
|
|
|
|
/* No FLS support yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-07-19 21:04:19 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
ConvertFiberToThread(VOID)
|
2000-08-14 14:34:12 +00:00
|
|
|
{
|
2011-07-23 11:46:57 +00:00
|
|
|
PTEB Teb;
|
|
|
|
PFIBER FiberData;
|
2005-07-19 21:04:19 +00:00
|
|
|
DPRINT1("Converting Fiber to Thread\n");
|
|
|
|
|
2011-07-23 11:46:57 +00:00
|
|
|
/* Check if the thread is already not a fiber */
|
|
|
|
Teb = NtCurrentTeb();
|
|
|
|
if (!Teb->HasFiberData)
|
2005-07-19 21:04:19 +00:00
|
|
|
{
|
2011-07-23 11:46:57 +00:00
|
|
|
/* Fail */
|
|
|
|
SetLastError(ERROR_ALREADY_THREAD);
|
2005-07-19 21:04:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* This thread won't run a fiber anymore */
|
2011-07-23 11:46:57 +00:00
|
|
|
Teb->HasFiberData = FALSE;
|
|
|
|
FiberData = Teb->NtTib.FiberData;
|
|
|
|
Teb->NtTib.FiberData = NULL;
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2011-07-23 11:46:57 +00:00
|
|
|
/* Free the fiber */
|
|
|
|
ASSERT(FiberData != NULL);
|
2015-10-08 16:26:29 +00:00
|
|
|
RtlFreeHeap(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
FiberData);
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Success */
|
2005-07-19 21:04:19 +00:00
|
|
|
return TRUE;
|
2003-05-29 00:36:41 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-07-19 21:04:19 +00:00
|
|
|
LPVOID
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
ConvertThreadToFiberEx(_In_opt_ LPVOID lpParameter,
|
|
|
|
_In_ DWORD dwFlags)
|
2003-05-29 00:36:41 +00:00
|
|
|
{
|
2011-10-16 15:04:26 +00:00
|
|
|
PTEB Teb;
|
|
|
|
PFIBER Fiber;
|
2005-07-19 21:04:19 +00:00
|
|
|
DPRINT1("Converting Thread to Fiber\n");
|
|
|
|
|
2011-10-16 15:04:26 +00:00
|
|
|
/* Check for invalid flags */
|
2015-10-08 16:26:29 +00:00
|
|
|
if (dwFlags & ~FIBER_FLAG_FLOAT_SWITCH)
|
2011-10-16 15:04:26 +00:00
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2011-10-16 15:04:26 +00:00
|
|
|
/* Are we already a fiber? */
|
|
|
|
Teb = NtCurrentTeb();
|
|
|
|
if (Teb->HasFiberData)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastError(ERROR_ALREADY_FIBER);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2011-10-16 15:04:26 +00:00
|
|
|
/* Allocate the fiber */
|
2015-10-08 16:26:29 +00:00
|
|
|
Fiber = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
sizeof(FIBER));
|
2011-10-16 15:04:26 +00:00
|
|
|
if (!Fiber)
|
2005-07-19 21:04:19 +00:00
|
|
|
{
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Fail */
|
2005-07-19 21:04:19 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-16 15:04:26 +00:00
|
|
|
/* Copy some contextual data from the thread to the fiber */
|
2015-04-28 21:27:35 +00:00
|
|
|
Fiber->FiberData = lpParameter;
|
2011-10-16 15:04:26 +00:00
|
|
|
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;
|
2015-04-28 21:27:35 +00:00
|
|
|
Fiber->ActivationContextStackPointer = Teb->ActivationContextStackPointer;
|
2011-10-16 15:04:26 +00:00
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Save FPU State if requested, otherwise just the basic registers */
|
|
|
|
Fiber->FiberContext.ContextFlags = (dwFlags & FIBER_FLAG_FLOAT_SWITCH) ?
|
|
|
|
(CONTEXT_FULL | CONTEXT_FLOATING_POINT) :
|
|
|
|
CONTEXT_FULL;
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2011-10-16 15:04:26 +00:00
|
|
|
/* Associate the fiber to the current thread */
|
|
|
|
Teb->NtTib.FiberData = Fiber;
|
|
|
|
Teb->HasFiberData = TRUE;
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2011-10-16 15:04:26 +00:00
|
|
|
/* Return opaque fiber data */
|
|
|
|
return (LPVOID)Fiber;
|
2003-05-29 00:36:41 +00:00
|
|
|
}
|
|
|
|
|
2004-06-13 20:04:56 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-07-19 21:04:19 +00:00
|
|
|
LPVOID
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
ConvertThreadToFiber(_In_opt_ LPVOID lpParameter)
|
2004-06-13 20:04:56 +00:00
|
|
|
{
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Call the newer function */
|
2015-10-08 16:26:29 +00:00
|
|
|
return ConvertThreadToFiberEx(lpParameter,
|
|
|
|
0);
|
2004-06-13 20:04:56 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-07-19 21:04:19 +00:00
|
|
|
LPVOID
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
CreateFiber(_In_ SIZE_T dwStackSize,
|
|
|
|
_In_ LPFIBER_START_ROUTINE lpStartAddress,
|
|
|
|
_In_opt_ LPVOID lpParameter)
|
2000-08-14 14:34:12 +00:00
|
|
|
{
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Call the Newer Function */
|
2015-10-08 16:26:29 +00:00
|
|
|
return CreateFiberEx(dwStackSize,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
lpStartAddress,
|
|
|
|
lpParameter);
|
2000-08-14 14:34:12 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-07-19 21:04:19 +00:00
|
|
|
LPVOID
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
CreateFiberEx(_In_ SIZE_T dwStackCommitSize,
|
|
|
|
_In_ SIZE_T dwStackReserveSize,
|
|
|
|
_In_ DWORD dwFlags,
|
|
|
|
_In_ LPFIBER_START_ROUTINE lpStartAddress,
|
|
|
|
_In_opt_ LPVOID lpParameter)
|
2003-05-29 00:36:41 +00:00
|
|
|
{
|
2011-07-23 11:55:41 +00:00
|
|
|
PFIBER Fiber;
|
|
|
|
NTSTATUS Status;
|
|
|
|
INITIAL_TEB InitialTeb;
|
2015-10-08 16:26:29 +00:00
|
|
|
PACTIVATION_CONTEXT_STACK ActivationContextStackPointer;
|
2010-05-16 00:30:11 +00:00
|
|
|
DPRINT("Creating Fiber\n");
|
2005-07-19 21:04:19 +00:00
|
|
|
|
2011-07-23 11:55:41 +00:00
|
|
|
/* Check for invalid flags */
|
2015-10-08 16:26:29 +00:00
|
|
|
if (dwFlags & ~FIBER_FLAG_FLOAT_SWITCH)
|
2011-07-23 11:55:41 +00:00
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Allocate the Activation Context Stack */
|
2015-10-08 16:26:29 +00:00
|
|
|
ActivationContextStackPointer = NULL;
|
2015-04-28 21:27:35 +00:00
|
|
|
Status = RtlAllocateActivationContextStack(&ActivationContextStackPointer);
|
2011-07-23 11:55:41 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2011-07-23 11:55:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-09 20:51:33 +00:00
|
|
|
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Allocate the fiber */
|
2015-10-08 16:26:29 +00:00
|
|
|
Fiber = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
sizeof(FIBER));
|
2011-07-23 11:55:41 +00:00
|
|
|
if (!Fiber)
|
2005-07-19 21:04:19 +00:00
|
|
|
{
|
2013-03-17 22:56:49 +00:00
|
|
|
/* Free the activation context stack */
|
2015-04-28 21:27:35 +00:00
|
|
|
RtlFreeActivationContextStack(ActivationContextStackPointer);
|
2013-03-17 22:56:49 +00:00
|
|
|
|
2011-07-23 11:55:41 +00:00
|
|
|
/* Fail */
|
2005-07-19 21:04:19 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the stack for the fiber */
|
2011-11-03 06:46:22 +00:00
|
|
|
Status = BaseCreateStack(NtCurrentProcess(),
|
2011-07-23 11:55:41 +00:00
|
|
|
dwStackCommitSize,
|
|
|
|
dwStackReserveSize,
|
|
|
|
&InitialTeb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-07-19 21:04:19 +00:00
|
|
|
{
|
|
|
|
/* Free the fiber */
|
2015-10-08 16:26:29 +00:00
|
|
|
RtlFreeHeap(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
Fiber);
|
2011-07-23 11:55:41 +00:00
|
|
|
|
2013-03-17 22:50:51 +00:00
|
|
|
/* Free the activation context stack */
|
2015-04-28 21:27:35 +00:00
|
|
|
RtlFreeActivationContextStack(ActivationContextStackPointer);
|
2005-07-19 21:04:19 +00:00
|
|
|
|
|
|
|
/* Failure */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2005-07-19 21:04:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-09 20:51:33 +00:00
|
|
|
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Clear the context */
|
2015-10-08 16:26:29 +00:00
|
|
|
RtlZeroMemory(&Fiber->FiberContext,
|
|
|
|
sizeof(CONTEXT));
|
2010-01-09 20:51:33 +00:00
|
|
|
|
2011-07-23 11:55:41 +00:00
|
|
|
/* Copy the data into the fiber */
|
|
|
|
Fiber->StackBase = InitialTeb.StackBase;
|
|
|
|
Fiber->StackLimit = InitialTeb.StackLimit;
|
|
|
|
Fiber->DeallocationStack = InitialTeb.AllocatedStackBase;
|
2015-04-28 21:27:35 +00:00
|
|
|
Fiber->FiberData = lpParameter;
|
2011-07-23 11:55:41 +00:00
|
|
|
Fiber->ExceptionList = EXCEPTION_CHAIN_END;
|
|
|
|
Fiber->GuaranteedStackBytes = 0;
|
|
|
|
Fiber->FlsData = NULL;
|
2015-04-28 21:27:35 +00:00
|
|
|
Fiber->ActivationContextStackPointer = ActivationContextStackPointer;
|
2010-01-09 20:51:33 +00:00
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Save FPU State if requested, otherwise just the basic registers */
|
|
|
|
Fiber->FiberContext.ContextFlags = (dwFlags & FIBER_FLAG_FLOAT_SWITCH) ?
|
|
|
|
(CONTEXT_FULL | CONTEXT_FLOATING_POINT) :
|
|
|
|
CONTEXT_FULL;
|
2010-01-09 20:51:33 +00:00
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Initialize the context for the fiber */
|
2015-04-28 21:27:35 +00:00
|
|
|
BaseInitializeContext(&Fiber->FiberContext,
|
2011-11-03 00:30:44 +00:00
|
|
|
lpParameter,
|
|
|
|
lpStartAddress,
|
|
|
|
InitialTeb.StackBase,
|
|
|
|
2);
|
2010-01-09 20:51:33 +00:00
|
|
|
|
2011-07-23 11:55:41 +00:00
|
|
|
/* Return the Fiber */
|
|
|
|
return Fiber;
|
2003-05-29 00:36:41 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-07-19 21:04:19 +00:00
|
|
|
VOID
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
DeleteFiber(_In_ LPVOID lpFiber)
|
2000-08-14 14:34:12 +00:00
|
|
|
{
|
2015-10-08 16:26:29 +00:00
|
|
|
SIZE_T Size;
|
|
|
|
PFIBER Fiber;
|
2011-07-23 11:55:41 +00:00
|
|
|
PTEB Teb;
|
2003-05-29 00:36:41 +00:00
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Are we deleting ourselves? */
|
2011-07-23 11:55:41 +00:00
|
|
|
Teb = NtCurrentTeb();
|
2015-10-08 16:26:29 +00:00
|
|
|
Fiber = (PFIBER)lpFiber;
|
|
|
|
if ((Teb->HasFiberData) &&
|
|
|
|
(Teb->NtTib.FiberData == Fiber))
|
|
|
|
{
|
|
|
|
/* Just exit */
|
|
|
|
ExitThread(1);
|
|
|
|
}
|
2003-05-29 00:36:41 +00:00
|
|
|
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Not ourselves, de-allocate the stack */
|
|
|
|
Size = 0 ;
|
2005-07-19 21:04:19 +00:00
|
|
|
NtFreeVirtualMemory(NtCurrentProcess(),
|
2011-07-23 11:55:41 +00:00
|
|
|
&Fiber->DeallocationStack,
|
|
|
|
&Size,
|
2005-07-19 21:04:19 +00:00
|
|
|
MEM_RELEASE);
|
2011-07-23 11:55:41 +00:00
|
|
|
|
|
|
|
/* Get rid of FLS */
|
|
|
|
if (Fiber->FlsData) BaseRundownFls(Fiber->FlsData);
|
|
|
|
|
2013-03-17 22:50:51 +00:00
|
|
|
/* Get rid of the activation context stack */
|
2015-04-28 21:27:35 +00:00
|
|
|
RtlFreeActivationContextStack(Fiber->ActivationContextStackPointer);
|
2011-07-23 11:55:41 +00:00
|
|
|
|
|
|
|
/* Free the fiber data */
|
2015-10-08 16:26:29 +00:00
|
|
|
RtlFreeHeap(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
lpFiber);
|
2000-08-14 14:34:12 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 23:05:07 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
IsThreadAFiber(VOID)
|
|
|
|
{
|
2015-10-08 16:26:29 +00:00
|
|
|
/* Return flag in the TEB */
|
2005-08-24 23:05:07 +00:00
|
|
|
return NtCurrentTeb()->HasFiberData;
|
|
|
|
}
|
|
|
|
|
2011-07-20 15:54:21 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
DWORD
|
2005-07-19 21:04:19 +00:00
|
|
|
WINAPI
|
2011-07-20 15:54:21 +00:00
|
|
|
FlsAlloc(PFLS_CALLBACK_FUNCTION lpCallback)
|
2000-08-14 14:34:12 +00:00
|
|
|
{
|
2011-07-20 15:54:21 +00:00
|
|
|
(void)lpCallback;
|
2007-09-02 18:05:16 +00:00
|
|
|
|
2011-07-20 15:54:21 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FLS_OUT_OF_INDEXES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
FlsFree(DWORD dwFlsIndex)
|
|
|
|
{
|
|
|
|
(void)dwFlsIndex;
|
2008-07-25 11:09:07 +00:00
|
|
|
|
2007-09-02 18:05:16 +00:00
|
|
|
UNIMPLEMENTED;
|
2011-07-20 15:54:21 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
PVOID
|
|
|
|
WINAPI
|
|
|
|
FlsGetValue(DWORD dwFlsIndex)
|
|
|
|
{
|
|
|
|
PVOID *ppFlsSlots;
|
|
|
|
PVOID pRetVal;
|
|
|
|
|
|
|
|
if(dwFlsIndex >= 128) goto l_InvalidParam;
|
|
|
|
|
|
|
|
ppFlsSlots = NtCurrentTeb()->FlsData;
|
|
|
|
|
|
|
|
if(ppFlsSlots == NULL) goto l_InvalidParam;
|
|
|
|
|
|
|
|
SetLastError(0);
|
|
|
|
pRetVal = ppFlsSlots[dwFlsIndex + 2];
|
|
|
|
|
|
|
|
return pRetVal;
|
|
|
|
|
|
|
|
l_InvalidParam:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2015-10-08 16:26:29 +00:00
|
|
|
FlsSetValue(DWORD dwFlsIndex,
|
|
|
|
PVOID lpFlsData)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
|
|
|
PVOID *ppFlsSlots;
|
|
|
|
TEB *pTeb = NtCurrentTeb();
|
|
|
|
|
|
|
|
if(dwFlsIndex >= 128) goto l_InvalidParam;
|
|
|
|
|
|
|
|
ppFlsSlots = pTeb->FlsData;
|
|
|
|
|
|
|
|
if (ppFlsSlots == NULL)
|
|
|
|
{
|
|
|
|
PEB *pPeb = pTeb->ProcessEnvironmentBlock;
|
|
|
|
|
|
|
|
ppFlsSlots = RtlAllocateHeap(pPeb->ProcessHeap,
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
(128 + 2) * sizeof(PVOID));
|
|
|
|
if(ppFlsSlots == NULL) goto l_OutOfMemory;
|
|
|
|
|
|
|
|
pTeb->FlsData = ppFlsSlots;
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
|
|
|
/* TODO: initialization */
|
|
|
|
|
|
|
|
RtlReleasePebLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
ppFlsSlots[dwFlsIndex + 2] = lpFlsData;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
l_OutOfMemory:
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
goto l_Fail;
|
|
|
|
|
|
|
|
l_InvalidParam:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
|
|
|
|
l_Fail:
|
|
|
|
return FALSE;
|
2000-08-14 14:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|