- Merge from trunk up to r45543
[reactos.git] / dll / win32 / kernel32 / thread / fls.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/thread/fls.c
6 * PURPOSE: Fiber local storage functions
7 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
8 *
9 * UPDATE HISTORY:
10 * 28/05/2003 - created. Stubs only
11 *
12 */
13
14 #include <k32.h>
15
16 #include <debug.h>
17
18 /*
19 * @unimplemented
20 */
21 DWORD
22 WINAPI
23 FlsAlloc(PFLS_CALLBACK_FUNCTION lpCallback)
24 {
25 (void)lpCallback;
26
27 UNIMPLEMENTED;
28 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
29 return FLS_OUT_OF_INDEXES;
30 }
31
32
33 /*
34 * @unimplemented
35 */
36 BOOL
37 WINAPI
38 FlsFree(DWORD dwFlsIndex)
39 {
40 (void)dwFlsIndex;
41
42 UNIMPLEMENTED;
43 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
44 return FALSE;
45 }
46
47
48 /*
49 * @implemented
50 */
51 PVOID
52 WINAPI
53 FlsGetValue(DWORD dwFlsIndex)
54 {
55 PVOID *ppFlsSlots;
56 PVOID pRetVal;
57
58 if(dwFlsIndex >= 128) goto l_InvalidParam;
59
60 ppFlsSlots = NtCurrentTeb()->FlsData;
61
62 if(ppFlsSlots == NULL) goto l_InvalidParam;
63
64 SetLastError(0);
65 pRetVal = ppFlsSlots[dwFlsIndex + 2];
66
67 return pRetVal;
68
69 l_InvalidParam:
70 SetLastError(ERROR_INVALID_PARAMETER);
71 return NULL;
72 }
73
74
75 /*
76 * @implemented
77 */
78 BOOL
79 WINAPI
80 FlsSetValue(DWORD dwFlsIndex, PVOID lpFlsData)
81 {
82 PVOID *ppFlsSlots;
83 TEB *pTeb = NtCurrentTeb();
84
85 if(dwFlsIndex >= 128) goto l_InvalidParam;
86
87 ppFlsSlots = pTeb->FlsData;
88
89 if (ppFlsSlots == NULL)
90 {
91 PEB *pPeb = pTeb->ProcessEnvironmentBlock;
92
93 ppFlsSlots = RtlAllocateHeap(pPeb->ProcessHeap,
94 HEAP_ZERO_MEMORY,
95 (128 + 2) * sizeof(PVOID));
96 if(ppFlsSlots == NULL) goto l_OutOfMemory;
97
98 pTeb->FlsData = ppFlsSlots;
99
100 RtlAcquirePebLock();
101
102 /* TODO: initialization */
103
104 RtlReleasePebLock();
105 }
106
107 ppFlsSlots[dwFlsIndex + 2] = lpFlsData;
108
109 return TRUE;
110
111 l_OutOfMemory:
112 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
113 goto l_Fail;
114
115 l_InvalidParam:
116 SetLastError(ERROR_INVALID_PARAMETER);
117
118 l_Fail:
119 return FALSE;
120 }
121
122 /* EOF */