ReactOS  0.4.13-dev-479-gec9c8fd
load_notifications.c File Reference
#include "precomp.h"
Include dependency graph for load_notifications.c:

Go to the source code of this file.

Functions

ULONG CountHandlers (VOID)
 
VOID WINAPI notify_TlsCallback (IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved)
 
BOOL WINAPI notify_DllMain (IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved)
 
static void execute_test (void)
 
BOOL extract_resource (const WCHAR *Filename, LPCWSTR ResourceName)
 
 START_TEST (load_notifications)
 

Variables

WCHAR dllpath [MAX_PATH]
 
LONG g_TlsCalled = 0
 
LONG g_DllMainCalled = 0
 
LONG g_TlsExcept = 0xffffff
 
LONG g_DllMainExcept = 0xffffff
 
ULONG g_BaseHandlers = 0
 
DWORD g_dwWinVer = 0
 
int g_TLS_ATTACH = 4
 
int g_TLS_DETACH = 3
 
int g_DLL_ATTACH = 3
 
int g_DLL_DETACH = 2
 

Function Documentation

◆ CountHandlers()

ULONG CountHandlers ( VOID  )

Definition at line 22 of file load_notifications.c.

23 {
25  ULONG Count = 0;
26 
27  exc = NtCurrentTeb()->NtTib.ExceptionList;
28 
29  while (exc && exc != (EXCEPTION_REGISTRATION_RECORD*)~0)
30  {
31  Count++;
32  exc = exc->Next;
33  }
34 
35  return Count;
36 }
struct _EXCEPTION_REGISTRATION_RECORD * Next
Definition: compat.h:386
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
unsigned int ULONG
Definition: retypes.h:1

Referenced by execute_test(), notify_DllMain(), and notify_TlsCallback().

◆ execute_test()

static void execute_test ( void  )
static

Definition at line 86 of file load_notifications.c.

87 {
88  HMODULE mod;
89  DWORD dwErr;
90  _SEH2_TRY
91  {
92  g_TlsExcept = 0xffffff;
93  g_DllMainExcept = 0xffffff;
94  g_DllMainCalled = 0;
95  g_TlsCalled = 0;
98  dwErr = GetLastError();
99  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
102  ok_hex(g_TlsCalled, 1);
103  if (g_TlsCalled == 0)
104  trace("Tls not active\n");
106  FreeLibrary(mod);
107  dwErr = GetLastError();
108  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
111  ok_hex(g_TlsCalled, 2);
112  }
114  {
115  ok(0, "Unable to load it normally\n");
116  }
117  _SEH2_END;
118 
119 
120  _SEH2_TRY
121  {
122  g_TlsExcept = 0xffffff;
124  g_DllMainCalled = 0;
125  g_TlsCalled = 0;
128  dwErr = GetLastError();
129  ok(GetModuleHandleW(dllpath) == NULL, "Module loaded (0x%lx)\n", dwErr);
132  else
136  ok_hex(g_TlsCalled, 1);
137  if (mod)
138  {
139  FreeLibrary(mod);
140  dwErr = GetLastError();
141  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
144  ok_hex(g_TlsCalled, 1);
145  }
146  }
148  {
149  ok(0, "Unable to execute test\n");
150  }
151  _SEH2_END;
152 
153  _SEH2_TRY
154  {
155  g_TlsExcept = 0xffffff;
157  g_DllMainCalled = 0;
158  g_TlsCalled = 0;
161  dwErr = GetLastError();
162  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
165  ok_hex(g_TlsCalled, 1);
167  FreeLibrary(mod);
168  dwErr = GetLastError();
169  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
172  ok_hex(g_TlsCalled, 2);
173  }
175  {
176  ok(0, "Unable to execute test\n");
177  }
178  _SEH2_END;
179 
180  _SEH2_TRY
181  {
183  g_DllMainExcept = 0xffffff;
184  g_DllMainCalled = 0;
185  g_TlsCalled = 0;
188  dwErr = GetLastError();
189  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
192  ok_hex(g_TlsCalled, 1);
194  FreeLibrary(mod);
195  dwErr = GetLastError();
196  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
199  ok_hex(g_TlsCalled, 2);
200  }
202  {
203  ok(0, "Unable to execute test\n");
204  }
205  _SEH2_END;
206 
207  _SEH2_TRY
208  {
210  g_DllMainExcept = 0xffffff;
211  g_DllMainCalled = 0;
212  g_TlsCalled = 0;
215  dwErr = GetLastError();
216  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
219  ok_hex(g_TlsCalled, 1);
221  FreeLibrary(mod);
222  dwErr = GetLastError();
223  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
226  ok_hex(g_TlsCalled, 2);
227  }
229  {
230  ok(0, "Unable to execute test\n");
231  }
232  _SEH2_END;
233 
234 }
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define trace(...)
Definition: kmt_test.h:217
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
DWORD g_dwWinVer
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
LONG g_DllMainExcept
#define ERROR_DLL_INIT_FAILED
Definition: winerror.h:650
_SEH2_TRY
Definition: create.c:4250
#define ERROR_NOACCESS
Definition: winerror.h:578
ULONG CountHandlers(VOID)
#define ok(value,...)
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
LONG g_TlsCalled
#define DLL_PROCESS_DETACH
Definition: compat.h:119
ULONG g_BaseHandlers
DWORD dwErr
Definition: service.c:36
#define ok_hex(expression, result)
Definition: test.h:759
LONG g_DllMainCalled
#define FreeLibrary(x)
Definition: compat.h:405
WCHAR dllpath[MAX_PATH]
unsigned long DWORD
Definition: ntddk_ex.h:95
_SEH2_END
Definition: create.c:4424
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LONG g_TlsExcept
static int mod
Definition: i386-dis.c:1273

Referenced by START_TEST().

◆ extract_resource()

BOOL extract_resource ( const WCHAR Filename,
LPCWSTR  ResourceName 
)

Definition at line 237 of file load_notifications.c.

238 {
239  BOOL Success;
240  DWORD dwWritten, Size;
241  HGLOBAL hGlobal;
242  LPVOID pData;
243  HANDLE Handle;
244  HRSRC hRsrc = FindResourceW(GetModuleHandleW(NULL), ResourceName, (LPCWSTR)10);
245  ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
246  if (!hRsrc)
247  return FALSE;
248 
249  hGlobal = LoadResource(GetModuleHandleW(NULL), hRsrc);
251  pData = LockResource(hGlobal);
252 
253  ok(Size && !!pData, "Unable to load %s\n", wine_dbgstr_w(ResourceName));
254  if (!Size || !pData)
255  return FALSE;
256 
258 
260  {
261  skip("Failed to create temp file %ls, error %lu\n", Filename, GetLastError());
262  return FALSE;
263  }
264  Success = WriteFile(Handle, pData, Size, &dwWritten, NULL);
265  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
266  ok(dwWritten == Size, "WriteFile wrote %lu bytes instead of %lu\n", dwWritten, Size);
268  Success = Success && (dwWritten == Size);
269 
271  return Success;
272 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define wine_dbgstr_w
Definition: kernel32.h:34
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:925
#define UnlockResource(h)
Definition: winbase.h:3189
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define CreateFileW
Definition: compat.h:400
#define skip(...)
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

Referenced by START_TEST().

◆ notify_DllMain()

BOOL WINAPI notify_DllMain ( IN HINSTANCE  hDllHandle,
IN DWORD  dwReason,
IN LPVOID  lpvReserved 
)

Definition at line 64 of file load_notifications.c.

65 {
67 
70  {
72  }
73  else
74  {
75  ok_int(handlers, g_DLL_DETACH); // For failures, see https://jira.reactos.org/browse/CORE-14857
76  }
77 
79  {
81  }
82  return TRUE;
83 }
#define TRUE
Definition: types.h:120
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1297
#define ok_int(x, y)
Definition: sprintf.c:21
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
#define InterlockedCompareExchange
Definition: interlocked.h:104
int g_DLL_DETACH
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
LONG g_DllMainExcept
ULONG CountHandlers(VOID)
smooth NULL
Definition: ftsmooth.c:416
ULONG g_BaseHandlers
LONG g_DllMainCalled
static IN DWORD dwReason
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:309
int g_DLL_ATTACH
#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
unsigned int ULONG
Definition: retypes.h:1

◆ notify_TlsCallback()

VOID WINAPI notify_TlsCallback ( IN HINSTANCE  hDllHandle,
IN DWORD  dwReason,
IN LPVOID  lpvReserved 
)

Definition at line 41 of file load_notifications.c.

42 {
44 
47  {
49  }
50  else
51  {
53  }
54 
56  {
58  }
59 }
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1297
#define ok_int(x, y)
Definition: sprintf.c:21
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
int g_TLS_DETACH
ULONG CountHandlers(VOID)
smooth NULL
Definition: ftsmooth.c:416
LONG g_TlsCalled
ULONG g_BaseHandlers
int g_TLS_ATTACH
static IN DWORD dwReason
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:309
#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
unsigned int ULONG
Definition: retypes.h:1
LONG g_TlsExcept

◆ START_TEST()

START_TEST ( load_notifications  )

Definition at line 275 of file load_notifications.c.

276 {
278  BOOL ret;
279  UINT Length;
280  PPEB Peb = NtCurrentPeb();
281 
283  trace("Winver: 0x%lx\n", g_dwWinVer);
284 
286  {
287  g_DLL_ATTACH = 4;
288  g_DLL_DETACH = 1;
289  }
290  else if (g_dwWinVer <= _WIN32_WINNT_WS08)
291  {
292  g_TLS_ATTACH = 5;
293  g_DLL_ATTACH = 4;
294  }
295  else if (g_dwWinVer <= _WIN32_WINNT_WIN7)
296  {
297  g_TLS_ATTACH = 3;
298  g_DLL_ATTACH = 2;
299  }
300  else if (g_dwWinVer <= _WIN32_WINNT_WINBLUE)
301  {
302  g_TLS_DETACH = 5;
303  g_DLL_DETACH = 4;
304  }
305 
307  ok(ret, "GetTempPathW error: %lu\n", GetLastError());
308 
309  Length = GetTempFileNameW(workdir, L"ntdll", 0, dllpath);
310  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
311 
312  if (extract_resource(dllpath, (LPCWSTR)101))
313  {
314  _SEH2_TRY
315  {
316  execute_test();
317  }
319  {
320  ok(0, "Ldr didnt handle exception\n");
321  }
322  _SEH2_END;
323  }
324  else
325  {
326  ok(0, "Failed to extract resource\n");
327  }
328 
330 }
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define trace(...)
Definition: kmt_test.h:217
PPEB Peb
Definition: dllmain.c:27
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define _countof(array)
Definition: fontsub.cpp:30
DWORD g_dwWinVer
int g_DLL_DETACH
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
int g_TLS_DETACH
#define DWORD
Definition: nt_native.h:44
_SEH2_TRY
Definition: create.c:4250
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static void execute_test(void)
WCHAR dllpath[MAX_PATH]
__wchar_t WCHAR
Definition: xmlstorage.h:180
static char workdir[MAX_PATH]
Definition: batch.c:26
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
int g_TLS_ATTACH
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
int ret
static const WCHAR L[]
Definition: oid.c:1250
int g_DLL_ATTACH
ULONG OSMinorVersion
Definition: ntddk_ex.h:301
_SEH2_END
Definition: create.c:4424
#define NtCurrentPeb()
Definition: FLS.c:20
#define _WIN32_WINNT_WS08
Definition: sdkddkver.h:26
unsigned int UINT
Definition: ndis.h:50
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
ULONG OSMajorVersion
Definition: ntddk_ex.h:300
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)

Variable Documentation

◆ dllpath

◆ g_BaseHandlers

ULONG g_BaseHandlers = 0

Definition at line 18 of file load_notifications.c.

Referenced by execute_test(), notify_DllMain(), and notify_TlsCallback().

◆ g_DLL_ATTACH

int g_DLL_ATTACH = 3

Definition at line 61 of file load_notifications.c.

Referenced by notify_DllMain(), and START_TEST().

◆ g_DLL_DETACH

int g_DLL_DETACH = 2

Definition at line 62 of file load_notifications.c.

Referenced by notify_DllMain(), and START_TEST().

◆ g_DllMainCalled

LONG g_DllMainCalled = 0

Definition at line 13 of file load_notifications.c.

Referenced by execute_test(), and notify_DllMain().

◆ g_DllMainExcept

LONG g_DllMainExcept = 0xffffff

Definition at line 16 of file load_notifications.c.

Referenced by execute_test(), and notify_DllMain().

◆ g_dwWinVer

DWORD g_dwWinVer = 0

Definition at line 20 of file load_notifications.c.

Referenced by execute_test(), and START_TEST().

◆ g_TLS_ATTACH

int g_TLS_ATTACH = 4

Definition at line 38 of file load_notifications.c.

Referenced by notify_TlsCallback(), and START_TEST().

◆ g_TLS_DETACH

int g_TLS_DETACH = 3

Definition at line 39 of file load_notifications.c.

Referenced by notify_TlsCallback(), and START_TEST().

◆ g_TlsCalled

LONG g_TlsCalled = 0

Definition at line 12 of file load_notifications.c.

Referenced by execute_test(), and notify_TlsCallback().

◆ g_TlsExcept

LONG g_TlsExcept = 0xffffff

Definition at line 15 of file load_notifications.c.

Referenced by execute_test(), and notify_TlsCallback().