ReactOS  0.4.13-dev-73-gcfe54aa
fiber.c File Reference
#include <k32.h>
#include <ndk/rtltypes.h>
#include <debug.h>
Include dependency graph for fiber.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID WINAPI BaseRundownFls (_In_ PVOID FlsData)
 
BOOL WINAPI ConvertFiberToThread (VOID)
 
LPVOID WINAPI ConvertThreadToFiberEx (_In_opt_ LPVOID lpParameter, _In_ DWORD dwFlags)
 
LPVOID WINAPI ConvertThreadToFiber (_In_opt_ LPVOID lpParameter)
 
LPVOID WINAPI CreateFiber (_In_ SIZE_T dwStackSize, _In_ LPFIBER_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter)
 
LPVOID WINAPI CreateFiberEx (_In_ SIZE_T dwStackCommitSize, _In_ SIZE_T dwStackReserveSize, _In_ DWORD dwFlags, _In_ LPFIBER_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter)
 
VOID WINAPI DeleteFiber (_In_ LPVOID lpFiber)
 
BOOL WINAPI IsThreadAFiber (VOID)
 
DWORD WINAPI FlsAlloc (PFLS_CALLBACK_FUNCTION lpCallback)
 
BOOL WINAPI FlsFree (DWORD dwFlsIndex)
 
PVOID WINAPI FlsGetValue (DWORD dwFlsIndex)
 
BOOL WINAPI FlsSetValue (DWORD dwFlsIndex, PVOID lpFlsData)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file fiber.c.

Function Documentation

◆ BaseRundownFls()

VOID WINAPI BaseRundownFls ( _In_ PVOID  FlsData)

Definition at line 32 of file fiber.c.

33 {
34  ULONG n, FlsHighIndex;
35  PRTL_FLS_DATA pFlsData;
36  PFLS_CALLBACK_FUNCTION lpCallback;
37 
38  pFlsData = FlsData;
39 
41  FlsHighIndex = NtCurrentPeb()->FlsHighIndex;
42  RemoveEntryList(&pFlsData->ListEntry);
44 
45  for (n = 1; n <= FlsHighIndex; ++n)
46  {
47  lpCallback = NtCurrentPeb()->FlsCallback[n];
48  if (lpCallback && pFlsData->Data[n])
49  {
50  lpCallback(pFlsData->Data[n]);
51  }
52  }
53 
54  RtlFreeHeap(RtlGetProcessHeap(), 0, FlsData);
55 }
VOID(WINAPI * PFLS_CALLBACK_FUNCTION)(PVOID)
Definition: winbase.h:1397
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
GLdouble n
Definition: glext.h:7729
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PVOID Data[RTL_FLS_MAXIMUM_AVAILABLE]
Definition: rtltypes.h:1220
LIST_ENTRY ListEntry
Definition: rtltypes.h:1219
#define NtCurrentPeb()
Definition: FLS.c:19
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
unsigned int ULONG
Definition: retypes.h:1

Referenced by DeleteFiber().

◆ ConvertFiberToThread()

BOOL WINAPI ConvertFiberToThread ( VOID  )

Definition at line 64 of file fiber.c.

65 {
66  PTEB Teb;
68  DPRINT1("Converting Fiber to Thread\n");
69 
70  /* Check if the thread is already not a fiber */
71  Teb = NtCurrentTeb();
72  if (!Teb->HasFiberData)
73  {
74  /* Fail */
76  return FALSE;
77  }
78 
79  /* This thread won't run a fiber anymore */
80  Teb->HasFiberData = FALSE;
81  FiberData = Teb->NtTib.FiberData;
82  Teb->NtTib.FiberData = NULL;
83 
84  /* Free the fiber */
85  ASSERT(FiberData != NULL);
86  RtlFreeHeap(RtlGetProcessHeap(),
87  0,
88  FiberData);
89 
90  /* Success */
91  return TRUE;
92 }
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
#define ERROR_ALREADY_THREAD
Definition: winerror.h:778
smooth NULL
Definition: ftsmooth.c:416
PVOID FiberData
Definition: compat.h:376
#define SetLastError(x)
Definition: compat.h:409
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define DPRINT1
Definition: precomp.h:8
NT_TIB NtTib
Definition: ntddk_ex.h:332

Referenced by init_funcs().

◆ ConvertThreadToFiber()

LPVOID WINAPI ConvertThreadToFiber ( _In_opt_ LPVOID  lpParameter)

Definition at line 162 of file fiber.c.

163 {
164  /* Call the newer function */
166  0);
167 }
LPVOID WINAPI ConvertThreadToFiberEx(_In_opt_ LPVOID lpParameter, _In_ DWORD dwFlags)
Definition: fiber.c:99
LPVOID lpParameter
Definition: kernel32.h:234

Referenced by Fbt_CreateFiber(), and init_funcs().

◆ ConvertThreadToFiberEx()

LPVOID WINAPI ConvertThreadToFiberEx ( _In_opt_ LPVOID  lpParameter,
_In_ DWORD  dwFlags 
)

Definition at line 99 of file fiber.c.

101 {
102  PTEB Teb;
103  PFIBER Fiber;
104  DPRINT1("Converting Thread to Fiber\n");
105 
106  /* Check for invalid flags */
107  if (dwFlags & ~FIBER_FLAG_FLOAT_SWITCH)
108  {
109  /* Fail */
111  return NULL;
112  }
113 
114  /* Are we already a fiber? */
115  Teb = NtCurrentTeb();
116  if (Teb->HasFiberData)
117  {
118  /* Fail */
120  return NULL;
121  }
122 
123  /* Allocate the fiber */
124  Fiber = RtlAllocateHeap(RtlGetProcessHeap(),
125  0,
126  sizeof(FIBER));
127  if (!Fiber)
128  {
129  /* Fail */
131  return NULL;
132  }
133 
134  /* Copy some contextual data from the thread to the fiber */
135  Fiber->FiberData = lpParameter;
136  Fiber->ExceptionList = Teb->NtTib.ExceptionList;
137  Fiber->StackBase = Teb->NtTib.StackBase;
138  Fiber->StackLimit = Teb->NtTib.StackLimit;
139  Fiber->DeallocationStack = Teb->DeallocationStack;
140  Fiber->FlsData = Teb->FlsData;
141  Fiber->GuaranteedStackBytes = Teb->GuaranteedStackBytes;
143 
144  /* Save FPU State if requested, otherwise just the basic registers */
145  Fiber->FiberContext.ContextFlags = (dwFlags & FIBER_FLAG_FLOAT_SWITCH) ?
147  CONTEXT_FULL;
148 
149  /* Associate the fiber to the current thread */
150  Teb->NtTib.FiberData = Fiber;
151  Teb->HasFiberData = TRUE;
152 
153  /* Return opaque fiber data */
154  return (LPVOID)Fiber;
155 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
PVOID StackBase
Definition: ketypes.h:183
CONTEXT FiberContext
Definition: ketypes.h:186
#define TRUE
Definition: types.h:120
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: ketypes.h:182
PVOID StackLimit
Definition: ketypes.h:184
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define CONTEXT_FULL
Definition: compat.h:270
PVOID FiberData
Definition: ketypes.h:181
smooth NULL
Definition: ftsmooth.c:416
PVOID DeallocationStack
Definition: ketypes.h:185
PVOID FlsData
Definition: ketypes.h:190
ULONG ContextFlags
Definition: compat.h:331
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
PVOID DeallocationStack
Definition: compat.h:527
PVOID FiberData
Definition: compat.h:376
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:371
#define SetLastError(x)
Definition: compat.h:409
ULONG GuaranteedStackBytes
Definition: ketypes.h:191
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
LPVOID lpParameter
Definition: kernel32.h:234
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
PVOID StackBase
Definition: compat.h:372
#define CONTEXT_FLOATING_POINT
Definition: compat.h:267
#define DPRINT1
Definition: precomp.h:8
PVOID StackLimit
Definition: compat.h:373
PVOID ActivationContextStackPointer
Definition: compat.h:503
NT_TIB NtTib
Definition: ntddk_ex.h:332
struct _ACTIVATION_CONTEXT_STACK * ActivationContextStackPointer
Definition: ketypes.h:189
#define ERROR_ALREADY_FIBER
Definition: winerror.h:777

Referenced by ConvertThreadToFiber(), and init_funcs().

◆ CreateFiber()

LPVOID WINAPI CreateFiber ( _In_ SIZE_T  dwStackSize,
_In_ LPFIBER_START_ROUTINE  lpStartAddress,
_In_opt_ LPVOID  lpParameter 
)

Definition at line 174 of file fiber.c.

177 {
178  /* Call the Newer Function */
179  return CreateFiberEx(dwStackSize,
180  0,
181  0,
182  lpStartAddress,
183  lpParameter);
184 }
LPVOID WINAPI CreateFiberEx(_In_ SIZE_T dwStackCommitSize, _In_ SIZE_T dwStackReserveSize, _In_ DWORD dwFlags, _In_ LPFIBER_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter)
Definition: fiber.c:191
LPVOID lpParameter
Definition: kernel32.h:234

Referenced by Fbt_CreateFiber(), and init_funcs().

◆ CreateFiberEx()

LPVOID WINAPI CreateFiberEx ( _In_ SIZE_T  dwStackCommitSize,
_In_ SIZE_T  dwStackReserveSize,
_In_ DWORD  dwFlags,
_In_ LPFIBER_START_ROUTINE  lpStartAddress,
_In_opt_ LPVOID  lpParameter 
)

Definition at line 191 of file fiber.c.

196 {
197  PFIBER Fiber;
199  INITIAL_TEB InitialTeb;
200  PACTIVATION_CONTEXT_STACK ActivationContextStackPointer;
201  DPRINT("Creating Fiber\n");
202 
203  /* Check for invalid flags */
204  if (dwFlags & ~FIBER_FLAG_FLOAT_SWITCH)
205  {
206  /* Fail */
208  return NULL;
209  }
210 
211  /* Allocate the Activation Context Stack */
212  ActivationContextStackPointer = NULL;
213  Status = RtlAllocateActivationContextStack(&ActivationContextStackPointer);
214  if (!NT_SUCCESS(Status))
215  {
216  /* Fail */
218  return NULL;
219  }
220 
221  /* Allocate the fiber */
222  Fiber = RtlAllocateHeap(RtlGetProcessHeap(),
223  0,
224  sizeof(FIBER));
225  if (!Fiber)
226  {
227  /* Free the activation context stack */
228  RtlFreeActivationContextStack(ActivationContextStackPointer);
229 
230  /* Fail */
232  return NULL;
233  }
234 
235  /* Create the stack for the fiber */
237  dwStackCommitSize,
238  dwStackReserveSize,
239  &InitialTeb);
240  if (!NT_SUCCESS(Status))
241  {
242  /* Free the fiber */
244  0,
245  Fiber);
246 
247  /* Free the activation context stack */
248  RtlFreeActivationContextStack(ActivationContextStackPointer);
249 
250  /* Failure */
252  return NULL;
253  }
254 
255  /* Clear the context */
256  RtlZeroMemory(&Fiber->FiberContext,
257  sizeof(CONTEXT));
258 
259  /* Copy the data into the fiber */
260  Fiber->StackBase = InitialTeb.StackBase;
261  Fiber->StackLimit = InitialTeb.StackLimit;
262  Fiber->DeallocationStack = InitialTeb.AllocatedStackBase;
263  Fiber->FiberData = lpParameter;
265  Fiber->GuaranteedStackBytes = 0;
266  Fiber->FlsData = NULL;
267  Fiber->ActivationContextStackPointer = ActivationContextStackPointer;
268 
269  /* Save FPU State if requested, otherwise just the basic registers */
270  Fiber->FiberContext.ContextFlags = (dwFlags & FIBER_FLAG_FLOAT_SWITCH) ?
272  CONTEXT_FULL;
273 
274  /* Initialize the context for the fiber */
276  lpParameter,
277  lpStartAddress,
278  InitialTeb.StackBase,
279  2);
280 
281  /* Return the Fiber */
282  return Fiber;
283 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
PVOID StackBase
Definition: ketypes.h:183
CONTEXT FiberContext
Definition: ketypes.h:186
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:503
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: ketypes.h:182
PVOID StackLimit
Definition: ketypes.h:184
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define CONTEXT_FULL
Definition: compat.h:270
PVOID FiberData
Definition: ketypes.h:181
smooth NULL
Definition: ftsmooth.c:416
PVOID StackBase
Definition: pstypes.h:678
void DPRINT(...)
Definition: polytest.cpp:61
PVOID DeallocationStack
Definition: ketypes.h:185
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID FlsData
Definition: ketypes.h:190
ULONG ContextFlags
Definition: compat.h:331
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define GetProcessHeap()
Definition: compat.h:395
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
PVOID StackLimit
Definition: pstypes.h:679
ULONG GuaranteedStackBytes
Definition: ketypes.h:191
NTSTATUS WINAPI BaseCreateStack(HANDLE hProcess, SIZE_T StackCommit, SIZE_T StackReserve, PINITIAL_TEB InitialTeb)
Definition: utils.c:353
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
LPVOID lpParameter
Definition: kernel32.h:234
PVOID AllocatedStackBase
Definition: pstypes.h:680
Status
Definition: gdiplustypes.h:24
#define EXCEPTION_CHAIN_END
Definition: rtltypes.h:63
#define CONTEXT_FLOATING_POINT
Definition: compat.h:267
NTSTATUS NTAPI RtlAllocateActivationContextStack(IN PACTIVATION_CONTEXT_STACK *Stack)
Definition: actctx.c:5829
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _ACTIVATION_CONTEXT_STACK * ActivationContextStackPointer
Definition: ketypes.h:189
VOID NTAPI RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack)
Definition: actctx.c:5363

Referenced by CreateFiber(), and init_funcs().

◆ DeleteFiber()

VOID WINAPI DeleteFiber ( _In_ LPVOID  lpFiber)

Definition at line 290 of file fiber.c.

291 {
292  SIZE_T Size;
293  PFIBER Fiber;
294  PTEB Teb;
295 
296  /* Are we deleting ourselves? */
297  Teb = NtCurrentTeb();
298  Fiber = (PFIBER)lpFiber;
299  if ((Teb->HasFiberData) &&
300  (Teb->NtTib.FiberData == Fiber))
301  {
302  /* Just exit */
303  ExitThread(1);
304  }
305 
306  /* Not ourselves, de-allocate the stack */
307  Size = 0 ;
309  &Fiber->DeallocationStack,
310  &Size,
311  MEM_RELEASE);
312 
313  /* Get rid of FLS */
314  if (Fiber->FlsData) BaseRundownFls(Fiber->FlsData);
315 
316  /* Get rid of the activation context stack */
318 
319  /* Free the fiber data */
320  RtlFreeHeap(RtlGetProcessHeap(),
321  0,
322  lpFiber);
323 }
VOID WINAPI BaseRundownFls(_In_ PVOID FlsData)
Definition: fiber.c:32
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
PVOID DeallocationStack
Definition: ketypes.h:185
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:327
PVOID FlsData
Definition: ketypes.h:190
#define NtCurrentProcess()
Definition: nt_native.h:1657
struct _FIBER * PFIBER
PVOID FiberData
Definition: compat.h:376
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define MEM_RELEASE
Definition: nt_native.h:1316
NT_TIB NtTib
Definition: ntddk_ex.h:332
struct _ACTIVATION_CONTEXT_STACK * ActivationContextStackPointer
Definition: ketypes.h:189
VOID NTAPI RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack)
Definition: actctx.c:5363
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5090

Referenced by Fbt_AfterSwitch(), Fbt_Dispatch(), and init_funcs().

◆ FlsAlloc()

DWORD WINAPI FlsAlloc ( PFLS_CALLBACK_FUNCTION  lpCallback)

Definition at line 341 of file fiber.c.

342 {
343  DWORD dwFlsIndex;
344  PPEB Peb = NtCurrentPeb();
345  PRTL_FLS_DATA pFlsData;
346 
348 
349  pFlsData = NtCurrentTeb()->FlsData;
350 
351  if (!Peb->FlsCallback &&
352  !(Peb->FlsCallback = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY,
353  FLS_MAXIMUM_AVAILABLE * sizeof(PVOID))))
354  {
356  dwFlsIndex = FLS_OUT_OF_INDEXES;
357  }
358  else
359  {
360  dwFlsIndex = RtlFindClearBitsAndSet(Peb->FlsBitmap, 1, 1);
361  if (dwFlsIndex != FLS_OUT_OF_INDEXES)
362  {
363  if (!pFlsData &&
364  !(pFlsData = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RTL_FLS_DATA))))
365  {
366  RtlClearBits(Peb->FlsBitmap, dwFlsIndex, 1);
367  dwFlsIndex = FLS_OUT_OF_INDEXES;
369  }
370  else
371  {
372  if (!NtCurrentTeb()->FlsData)
373  {
374  NtCurrentTeb()->FlsData = pFlsData;
375  InsertTailList(&Peb->FlsListHead, &pFlsData->ListEntry);
376  }
377 
378  pFlsData->Data[dwFlsIndex] = NULL; /* clear the value */
379  Peb->FlsCallback[dwFlsIndex] = lpCallback;
380 
381  if (dwFlsIndex > Peb->FlsHighIndex)
382  Peb->FlsHighIndex = dwFlsIndex;
383  }
384  }
385  else
386  {
388  }
389  }
391  return dwFlsIndex;
392 }
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
PPEB Peb
Definition: dllmain.c:27
#define FLS_OUT_OF_INDEXES
Definition: winbase.h:557
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
LIST_ENTRY FlsListHead
Definition: winternl.h:360
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
PVOID Data[RTL_FLS_MAXIMUM_AVAILABLE]
Definition: rtltypes.h:1220
#define InsertTailList(PLH__, PLE__)
Definition: fiber.c:33
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
LIST_ENTRY ListEntry
Definition: rtltypes.h:1219
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define FLS_MAXIMUM_AVAILABLE
Definition: winnt_old.h:1101
#define NtCurrentPeb()
Definition: FLS.c:19
PVOID * FlsCallback
Definition: winternl.h:359
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
PRTL_BITMAP FlsBitmap
Definition: winternl.h:361

Referenced by init_funcs().

◆ FlsFree()

BOOL WINAPI FlsFree ( DWORD  dwFlsIndex)

Definition at line 400 of file fiber.c.

401 {
402  BOOL ret;
403  PPEB Peb = NtCurrentPeb();
404 
405  if (dwFlsIndex >= FLS_MAXIMUM_AVAILABLE)
406  {
408  return FALSE;
409  }
410 
412 
413  _SEH2_TRY
414  {
415  ret = RtlAreBitsSet(Peb->FlsBitmap, dwFlsIndex, 1);
416  if (ret)
417  {
419  PFLS_CALLBACK_FUNCTION lpCallback;
420 
421  RtlClearBits(Peb->FlsBitmap, dwFlsIndex, 1);
422  lpCallback = Peb->FlsCallback[dwFlsIndex];
423 
424  for (Entry = Peb->FlsListHead.Flink; Entry != &Peb->FlsListHead; Entry = Entry->Flink)
425  {
426  PRTL_FLS_DATA pFlsData;
427 
428  pFlsData = CONTAINING_RECORD(Entry, RTL_FLS_DATA, ListEntry);
429  if (pFlsData->Data[dwFlsIndex])
430  {
431  if (lpCallback)
432  {
433  lpCallback(pFlsData->Data[dwFlsIndex]);
434  }
435  pFlsData->Data[dwFlsIndex] = NULL;
436  }
437  }
438  Peb->FlsCallback[dwFlsIndex] = NULL;
439  }
440  else
441  {
443  }
444  }
446  {
448  }
449  _SEH2_END;
450 
451  return ret;
452 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
PPEB Peb
Definition: dllmain.c:27
struct _Entry Entry
Definition: kefuncs.h:640
VOID(WINAPI * PFLS_CALLBACK_FUNCTION)(PVOID)
Definition: winbase.h:1397
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
_SEH2_TRY
Definition: create.c:4250
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY FlsListHead
Definition: winternl.h:360
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define SetLastError(x)
Definition: compat.h:409
int ret
PVOID Data[RTL_FLS_MAXIMUM_AVAILABLE]
Definition: rtltypes.h:1220
Definition: typedefs.h:117
_SEH2_END
Definition: create.c:4424
NTSYSAPI BOOLEAN WINAPI RtlAreBitsSet(PCRTL_BITMAP, ULONG, ULONG)
#define FLS_MAXIMUM_AVAILABLE
Definition: winnt_old.h:1101
#define NtCurrentPeb()
Definition: FLS.c:19
PVOID * FlsCallback
Definition: winternl.h:359
_SEH2_FINALLY
Definition: create.c:4395
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
PRTL_BITMAP FlsBitmap
Definition: winternl.h:361
base of all file and directory entries
Definition: entries.h:82

Referenced by init_funcs().

◆ FlsGetValue()

PVOID WINAPI FlsGetValue ( DWORD  dwFlsIndex)

Definition at line 460 of file fiber.c.

461 {
462  PRTL_FLS_DATA pFlsData;
463 
464  pFlsData = NtCurrentTeb()->FlsData;
465  if (!dwFlsIndex || dwFlsIndex >= FLS_MAXIMUM_AVAILABLE || !pFlsData)
466  {
468  return NULL;
469  }
470 
472  return pFlsData->Data[dwFlsIndex];
473 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:409
PVOID Data[RTL_FLS_MAXIMUM_AVAILABLE]
Definition: rtltypes.h:1220
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define FLS_MAXIMUM_AVAILABLE
Definition: winnt_old.h:1101

Referenced by init_funcs().

◆ FlsSetValue()

BOOL WINAPI FlsSetValue ( DWORD  dwFlsIndex,
PVOID  lpFlsData 
)

Definition at line 481 of file fiber.c.

483 {
484  PRTL_FLS_DATA pFlsData;
485 
486  if (!dwFlsIndex || dwFlsIndex >= FLS_MAXIMUM_AVAILABLE)
487  {
489  return FALSE;
490  }
491 
492  pFlsData = NtCurrentTeb()->FlsData;
493 
494  if (!NtCurrentTeb()->FlsData &&
495  !(NtCurrentTeb()->FlsData = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY,
496  sizeof(RTL_FLS_DATA))))
497  {
499  return FALSE;
500  }
501  if (!pFlsData)
502  {
503  pFlsData = NtCurrentTeb()->FlsData;
505  InsertTailList(&NtCurrentPeb()->FlsListHead, &pFlsData->ListEntry);
507  }
508  pFlsData->Data[dwFlsIndex] = lpFlsData;
509  return TRUE;
510 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define SetLastError(x)
Definition: compat.h:409
PVOID Data[RTL_FLS_MAXIMUM_AVAILABLE]
Definition: rtltypes.h:1220
#define InsertTailList(PLH__, PLE__)
Definition: fiber.c:33
LIST_ENTRY ListEntry
Definition: rtltypes.h:1219
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define FLS_MAXIMUM_AVAILABLE
Definition: winnt_old.h:1101
#define NtCurrentPeb()
Definition: FLS.c:19
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72

Referenced by init_funcs().

◆ IsThreadAFiber()

BOOL WINAPI IsThreadAFiber ( VOID  )

Definition at line 330 of file fiber.c.

331 {
332  /* Return flag in the TEB */
333  return NtCurrentTeb()->HasFiberData;
334 }
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

Referenced by init_funcs().