ReactOS  0.4.13-dev-235-g7373cb3
FLS.c File Reference
#include "precomp.h"
#include <ndk/pstypes.h>
#include <ndk/rtlfuncs.h>
Include dependency graph for FLS.c:

Go to the source code of this file.

Classes

struct  _FLS_CALLBACK_INFO
 

Macros

#define NtCurrentPeb()   (NtCurrentTeb()->ProcessEnvironmentBlock)
 
#define WINVER_2003   0x0502
 
#define ok_fls   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : ok_fls_
 
#define X(f)   p##f = (void*)GetProcAddress(hKernel32, #f);
 

Typedefs

typedef struct _FLS_CALLBACK_INFO FLS_CALLBACK_INFO
 
typedef struct _FLS_CALLBACK_INFOPFLS_CALLBACK_INFO
 

Functions

static DWORD (WINAPI *pFlsAlloc)(PFLS_CALLBACK_FUNCTION)
 
static BOOL (WINAPI *pFlsFree)(DWORD)
 
static PVOID (WINAPI *pFlsGetValue)(DWORD)
 
VOID WINAPI FlsCallback1 (PVOID lpFlsData)
 
VOID WINAPI FlsCallback2 (PVOID lpFlsData)
 
VOID WINAPI FlsCallback3 (PVOID lpFlsData)
 
void ok_fls_ (DWORD dwIndex, PVOID pValue, PFLS_CALLBACK_FUNCTION lpCallback)
 
static VOID init_funcs (void)
 
 START_TEST (FLS)
 

Variables

static PVOID
 
static DWORD g_WinVersion = 0
 
PVOID g_FlsData1 = NULL
 
LONG g_FlsCalled1 = 0
 
PVOID g_FlsData2 = NULL
 
LONG g_FlsCalled2 = 0
 
PVOID g_FlsData3 = NULL
 
LONG g_FlsCalled3 = 0
 
BOOL g_FlsExcept3 = FALSE
 

Macro Definition Documentation

◆ NtCurrentPeb

#define NtCurrentPeb ( )    (NtCurrentTeb()->ProcessEnvironmentBlock)

Definition at line 19 of file FLS.c.

◆ ok_fls

#define ok_fls   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : ok_fls_

Definition at line 116 of file FLS.c.

◆ WINVER_2003

#define WINVER_2003   0x0502

Definition at line 20 of file FLS.c.

◆ X

#define X (   f)    p##f = (void*)GetProcAddress(hKernel32, #f);

Typedef Documentation

◆ FLS_CALLBACK_INFO

◆ PFLS_CALLBACK_INFO

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pFlsFree)
static

◆ DWORD()

static DWORD ( WINAPI pFlsAlloc)
static

◆ FlsCallback1()

VOID WINAPI FlsCallback1 ( PVOID  lpFlsData)

Definition at line 32 of file FLS.c.

33 {
34  ok(lpFlsData == g_FlsData1, "Expected g_FlsData1(%p), got %p\n", g_FlsData1, lpFlsData);
36 }
LONG g_FlsCalled1
Definition: FLS.c:24
#define ok(value,...)
PVOID g_FlsData1
Definition: FLS.c:23
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by START_TEST().

◆ FlsCallback2()

VOID WINAPI FlsCallback2 ( PVOID  lpFlsData)

Definition at line 38 of file FLS.c.

39 {
40  ok(lpFlsData == g_FlsData2, "Expected g_FlsData2(%p), got %p\n", g_FlsData2, lpFlsData);
42 }
LONG g_FlsCalled2
Definition: FLS.c:26
PVOID g_FlsData2
Definition: FLS.c:25
#define ok(value,...)
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by START_TEST().

◆ FlsCallback3()

VOID WINAPI FlsCallback3 ( PVOID  lpFlsData)

Definition at line 44 of file FLS.c.

45 {
46  ok(lpFlsData == g_FlsData3, "Expected g_FlsData3(%p), got %p\n", g_FlsData3, lpFlsData);
47 
49  ok(RtlIsCriticalSectionLockedByThread(NtCurrentPeb()->FastPebLock), "Expected lock on PEB\n");
51  if (g_FlsExcept3)
52  {
54  }
55 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
NTSYSAPI ULONG NTAPI RtlIsCriticalSectionLockedByThread(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define WINVER_2003
Definition: FLS.c:20
PVOID g_FlsData3
Definition: FLS.c:27
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
Definition: FLS.c:22
BOOL g_FlsExcept3
Definition: FLS.c:29
LONG g_FlsCalled3
Definition: FLS.c:28
#define InterlockedIncrement
Definition: armddk.h:53
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693
#define NtCurrentPeb()
Definition: FLS.c:19
RTL_CRITICAL_SECTION FastPebLock
Definition: ldrinit.c:79

Referenced by ok_fls_(), and START_TEST().

◆ init_funcs()

static VOID init_funcs ( void  )
static

Definition at line 118 of file FLS.c.

119 {
120  HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
121 
122 #define X(f) p##f = (void*)GetProcAddress(hKernel32, #f);
123  X(FlsAlloc);
124  X(FlsFree);
125  X(FlsGetValue);
126  X(FlsSetValue);
127 #undef X
128 }
BOOL WINAPI FlsSetValue(DWORD dwFlsIndex, PVOID lpFlsData)
Definition: fiber.c:481
DWORD WINAPI FlsAlloc(PFLS_CALLBACK_FUNCTION lpCallback)
Definition: fiber.c:341
PVOID WINAPI FlsGetValue(DWORD dwFlsIndex)
Definition: fiber.c:460
#define X(f)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
BOOL WINAPI FlsFree(DWORD dwFlsIndex)
Definition: fiber.c:400

Referenced by START_TEST().

◆ ok_fls_()

void ok_fls_ ( DWORD  dwIndex,
PVOID  pValue,
PFLS_CALLBACK_FUNCTION  lpCallback 
)

Definition at line 64 of file FLS.c.

65 {
66  PFLS_CALLBACK_INFO FlsCallback;
67  PVOID* FlsData;
68  PVOID gotValue;
69 
70  FlsCallback = (PFLS_CALLBACK_INFO)NtCurrentPeb()->FlsCallback;
71  FlsData = (PVOID*)NtCurrentTeb()->FlsData;
72 
73  winetest_ok(FlsData != NULL, "Expected FlsData\n");
74  winetest_ok(FlsCallback != NULL, "Expected FlsCallback\n");
75 
76  if (FlsData == NULL || FlsCallback == NULL)
77  {
78  winetest_skip("Unable to continue test\n");
79  return;
80  }
81 
83  {
84  winetest_ok(NtCurrentPeb()->FlsCallback[dwIndex] == lpCallback,
85  "Expected NtCurrentPeb()->FlsCallback[%lu] to be %p, was %p\n",
86  dwIndex,
87  lpCallback,
88  NtCurrentPeb()->FlsCallback[dwIndex]);
89  }
90  else
91  {
92  winetest_ok(FlsCallback[dwIndex].lpCallback == lpCallback,
93  "Expected FlsCallback[%lu].lpCallback to be %p, was %p\n",
94  dwIndex,
95  lpCallback,
96  FlsCallback[dwIndex].lpCallback);
97  if (lpCallback != &FlsCallback3 || !g_FlsExcept3)
98  {
99  winetest_ok(FlsCallback[dwIndex].Unknown == NULL,
100  "Expected FlsCallback[%lu].Unknown to be %p, was %p\n",
101  dwIndex,
102  NULL,
103  FlsCallback[dwIndex].Unknown);
104  }
105  }
106  winetest_ok(FlsData[dwIndex + 2] == pValue,
107  "Expected FlsData[%lu + 2] to be %p, was %p\n",
108  dwIndex,
109  pValue,
110  FlsData[dwIndex + 2]);
111 
112  gotValue = pFlsGetValue(dwIndex);
113  winetest_ok(gotValue == pValue, "Expected FlsGetValue(%lu) to be %p, was %p\n", dwIndex, pValue, gotValue);
114 }
struct _FLS_CALLBACK_INFO * PFLS_CALLBACK_INFO
#define WINVER_2003
Definition: FLS.c:20
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
Definition: FLS.c:22
BOOL g_FlsExcept3
Definition: FLS.c:29
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
VOID WINAPI FlsCallback3(PVOID lpFlsData)
Definition: FLS.c:44
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define NtCurrentPeb()
Definition: FLS.c:19
void __winetest_cdecl winetest_skip(const char *msg,...)

◆ PVOID()

static PVOID ( WINAPI pFlsGetValue)
static

◆ START_TEST()

START_TEST ( FLS  )

Definition at line 132 of file FLS.c.

133 {
134  RTL_OSVERSIONINFOW rtlinfo = { sizeof(rtlinfo) };
135  DWORD dwIndex1, dwIndex2, dwIndex3, dwErr;
136  BOOL bRet;
137 
138  init_funcs();
139  if (!pFlsAlloc || !pFlsFree || !pFlsGetValue || !pFlsSetValue)
140  {
141  skip("Fls functions not available\n");
142  return;
143  }
144 
145  RtlGetVersion(&rtlinfo);
146  g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
147 
148  dwIndex1 = pFlsAlloc(FlsCallback1);
149  ok(dwIndex1 != FLS_OUT_OF_INDEXES, "Unable to allocate FLS index\n");
150  dwIndex2 = pFlsAlloc(FlsCallback2);
151  ok(dwIndex2 != FLS_OUT_OF_INDEXES, "Unable to allocate FLS index\n");
152  ok(dwIndex1 != dwIndex2, "Expected different indexes, got %lu\n", dwIndex1);
153 
154  dwIndex3 = pFlsAlloc(FlsCallback3);
155  ok(dwIndex3 != FLS_OUT_OF_INDEXES, "Unable to allocate FLS index\n");
156  ok(dwIndex1 != dwIndex3, "Expected different indexes, got %lu\n", dwIndex1);
157 
158  if (dwIndex1 == FLS_OUT_OF_INDEXES || dwIndex2 == FLS_OUT_OF_INDEXES || dwIndex3 == FLS_OUT_OF_INDEXES)
159  {
160  skip("Unable to continue test\n");
161  return;
162  }
163 
164  ok_fls(dwIndex1, g_FlsData1, &FlsCallback1);
165  ok_fls(dwIndex2, g_FlsData2, &FlsCallback2);
166  ok_fls(dwIndex3, g_FlsData3, &FlsCallback3);
167 
168  g_FlsData1 = (PVOID)0x123456;
169  ok(pFlsSetValue(dwIndex1, g_FlsData1), "FlsSetValue(%lu, %p) failed\n", dwIndex1, g_FlsData1);
170 
171  ok_fls(dwIndex1, g_FlsData1, &FlsCallback1);
172  ok_fls(dwIndex2, g_FlsData2, &FlsCallback2);
173  ok_fls(dwIndex3, g_FlsData3, &FlsCallback3);
174 
175  ok_int(g_FlsCalled1, 0);
176  ok_int(g_FlsCalled2, 0);
177  ok_int(g_FlsCalled3, 0);
178 
179  g_FlsData2 = (PVOID)0x9876112;
180  ok(pFlsSetValue(dwIndex2, g_FlsData2), "FlsSetValue(%lu, %p) failed\n", dwIndex2, g_FlsData2);
181 
182  ok_fls(dwIndex1, g_FlsData1, &FlsCallback1);
183  ok_fls(dwIndex2, g_FlsData2, &FlsCallback2);
184  ok_fls(dwIndex3, g_FlsData3, &FlsCallback3);
185 
186 
187  ok_int(g_FlsCalled1, 0);
188  ok_int(g_FlsCalled2, 0);
189  ok_int(g_FlsCalled3, 0);
190 
191  g_FlsData3 = (PVOID)0x98762;
192  ok(pFlsSetValue(dwIndex3, g_FlsData3), "FlsSetValue(%lu, %p) failed\n", dwIndex3, g_FlsData3);
193 
194  ok_fls(dwIndex1, g_FlsData1, &FlsCallback1);
195  ok_fls(dwIndex2, g_FlsData2, &FlsCallback2);
196  ok_fls(dwIndex3, g_FlsData3, &FlsCallback3);
197 
198  ok_int(g_FlsCalled1, 0);
199  ok_int(g_FlsCalled2, 0);
200  ok_int(g_FlsCalled3, 0);
201 
202  ok(pFlsFree(dwIndex1) == TRUE, "FlsFree(%lu) failed\n", dwIndex1);
203  g_FlsData1 = NULL;
204 
205  ok_fls(dwIndex1, g_FlsData1, NULL);
206  ok_fls(dwIndex2, g_FlsData2, &FlsCallback2);
207  ok_fls(dwIndex3, g_FlsData3, &FlsCallback3);
208 
209  ok_int(g_FlsCalled1, 1);
210  ok_int(g_FlsCalled2, 0);
211  ok_int(g_FlsCalled3, 0);
212 
213  g_FlsExcept3 = TRUE;
214  _SEH2_TRY
215  {
216  bRet = pFlsFree(dwIndex3);
217  dwErr = GetLastError();
218  }
220  {
221  bRet = 12345;
222  dwErr = 0xdeaddead;
223  }
224  _SEH2_END;
225  ok(RtlIsCriticalSectionLockedByThread(NtCurrentPeb()->FastPebLock) == FALSE, "Expected no lock on PEB\n");
226 
227  ok(bRet == 12345, "FlsFree(%lu) should have failed, got %u\n", dwIndex3, bRet);
228  ok(dwErr == 0xdeaddead, "Expected GetLastError() to be 0xdeaddead, was %lx\n", dwErr);
229 
230  ok_fls(dwIndex1, g_FlsData1, NULL);
231  ok_fls(dwIndex2, g_FlsData2, &FlsCallback2);
232  ok_fls(dwIndex3, g_FlsData3, &FlsCallback3);
233 
234  ok_int(g_FlsCalled1, 1);
235  ok_int(g_FlsCalled2, 0);
236  ok_int(g_FlsCalled3, 1);
237 }
LONG g_FlsCalled2
Definition: FLS.c:26
LONG g_FlsCalled1
Definition: FLS.c:24
static PVOID
Definition: FLS.c:16
PVOID g_FlsData2
Definition: FLS.c:25
#define TRUE
Definition: types.h:120
NTSYSAPI ULONG NTAPI RtlIsCriticalSectionLockedByThread(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define FLS_OUT_OF_INDEXES
Definition: winbase.h:557
PVOID g_FlsData3
Definition: FLS.c:27
#define ok_int(x, y)
Definition: sprintf.c:21
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
_SEH2_TRY
Definition: create.c:4250
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
Definition: FLS.c:22
DWORD dwErr
Definition: service.c:36
BOOL g_FlsExcept3
Definition: FLS.c:29
ULONG dwMajorVersion
Definition: rtltypes.h:243
LONG g_FlsCalled3
Definition: FLS.c:28
#define ok_fls
Definition: FLS.c:116
VOID WINAPI FlsCallback3(PVOID lpFlsData)
Definition: FLS.c:44
PVOID g_FlsData1
Definition: FLS.c:23
unsigned long DWORD
Definition: ntddk_ex.h:95
_SEH2_END
Definition: create.c:4424
#define NtCurrentPeb()
Definition: FLS.c:19
RTL_CRITICAL_SECTION FastPebLock
Definition: ldrinit.c:79
#define skip(...)
ULONG dwMinorVersion
Definition: rtltypes.h:244
static VOID init_funcs(void)
Definition: FLS.c:118
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
VOID WINAPI FlsCallback2(PVOID lpFlsData)
Definition: FLS.c:38
VOID WINAPI FlsCallback1(PVOID lpFlsData)
Definition: FLS.c:32

Variable Documentation

◆ g_FlsCalled1

LONG g_FlsCalled1 = 0

Definition at line 24 of file FLS.c.

Referenced by FlsCallback1(), and START_TEST().

◆ g_FlsCalled2

LONG g_FlsCalled2 = 0

Definition at line 26 of file FLS.c.

Referenced by FlsCallback2(), and START_TEST().

◆ g_FlsCalled3

LONG g_FlsCalled3 = 0

Definition at line 28 of file FLS.c.

Referenced by FlsCallback3(), and START_TEST().

◆ g_FlsData1

PVOID g_FlsData1 = NULL

Definition at line 23 of file FLS.c.

Referenced by FlsCallback1(), and START_TEST().

◆ g_FlsData2

PVOID g_FlsData2 = NULL

Definition at line 25 of file FLS.c.

Referenced by FlsCallback2(), and START_TEST().

◆ g_FlsData3

PVOID g_FlsData3 = NULL

Definition at line 27 of file FLS.c.

Referenced by FlsCallback3(), and START_TEST().

◆ g_FlsExcept3

BOOL g_FlsExcept3 = FALSE

Definition at line 29 of file FLS.c.

Referenced by FlsCallback3(), ok_fls_(), and START_TEST().

◆ g_WinVersion

DWORD g_WinVersion = 0
static

Definition at line 22 of file FLS.c.

Referenced by FlsCallback3(), ok_fls_(), and START_TEST().

◆ PVOID

Definition at line 16 of file FLS.c.

Referenced by START_TEST().