ReactOS  0.4.15-dev-3182-g7b62228
load_notifications.c File Reference
#include "precomp.h"
#include <pseh/pseh2.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 24 of file load_notifications.c.

25 {
27  ULONG Count = 0;
28 
29  exc = NtCurrentTeb()->NtTib.ExceptionList;
30 
31  while (exc && exc != (EXCEPTION_REGISTRATION_RECORD*)~0)
32  {
33  Count++;
34  exc = exc->Next;
35  }
36 
37  return Count;
38 }
struct _EXCEPTION_REGISTRATION_RECORD * Next
Definition: compat.h:585
int Count
Definition: noreturn.cpp:7
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 88 of file load_notifications.c.

89 {
90  HMODULE mod;
91  DWORD dwErr;
92  _SEH2_TRY
93  {
94  g_TlsExcept = 0xffffff;
95  g_DllMainExcept = 0xffffff;
96  g_DllMainCalled = 0;
97  g_TlsCalled = 0;
100  dwErr = GetLastError();
101  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
104  ok_hex(g_TlsCalled, 1);
105  if (g_TlsCalled == 0)
106  trace("Tls not active\n");
108  FreeLibrary(mod);
109  dwErr = GetLastError();
110  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
113  ok_hex(g_TlsCalled, 2);
114  }
116  {
117  ok(0, "Unable to load it normally\n");
118  }
119  _SEH2_END;
120 
121 
122  _SEH2_TRY
123  {
124  g_TlsExcept = 0xffffff;
126  g_DllMainCalled = 0;
127  g_TlsCalled = 0;
130  dwErr = GetLastError();
131  ok(GetModuleHandleW(dllpath) == NULL, "Module loaded (0x%lx)\n", dwErr);
134  else
138  ok_hex(g_TlsCalled, 1);
139  if (mod)
140  {
141  FreeLibrary(mod);
142  dwErr = GetLastError();
143  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
146  ok_hex(g_TlsCalled, 1);
147  }
148  }
150  {
151  ok(0, "Unable to execute test\n");
152  }
153  _SEH2_END;
154 
155  _SEH2_TRY
156  {
157  g_TlsExcept = 0xffffff;
159  g_DllMainCalled = 0;
160  g_TlsCalled = 0;
163  dwErr = GetLastError();
164  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
167  ok_hex(g_TlsCalled, 1);
169  FreeLibrary(mod);
170  dwErr = GetLastError();
171  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
174  ok_hex(g_TlsCalled, 2);
175  }
177  {
178  ok(0, "Unable to execute test\n");
179  }
180  _SEH2_END;
181 
182  _SEH2_TRY
183  {
185  g_DllMainExcept = 0xffffff;
186  g_DllMainCalled = 0;
187  g_TlsCalled = 0;
190  dwErr = GetLastError();
191  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
194  ok_hex(g_TlsCalled, 1);
196  FreeLibrary(mod);
197  dwErr = GetLastError();
198  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
201  ok_hex(g_TlsCalled, 2);
202  }
204  {
205  ok(0, "Unable to execute test\n");
206  }
207  _SEH2_END;
208 
209  _SEH2_TRY
210  {
212  g_DllMainExcept = 0xffffff;
213  g_DllMainCalled = 0;
214  g_TlsCalled = 0;
217  dwErr = GetLastError();
218  ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
221  ok_hex(g_TlsCalled, 1);
223  FreeLibrary(mod);
224  dwErr = GetLastError();
225  ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
228  ok_hex(g_TlsCalled, 2);
229  }
231  {
232  ok(0, "Unable to execute test\n");
233  }
234  _SEH2_END;
235 
236 }
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
DWORD g_dwWinVer
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
LONG g_DllMainExcept
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ERROR_DLL_INIT_FAILED
Definition: winerror.h:650
_SEH2_TRY
Definition: create.c:4226
#define ERROR_NOACCESS
Definition: winerror.h:578
ULONG CountHandlers(VOID)
#define LoadLibraryW(x)
Definition: compat.h:606
LONG g_TlsCalled
#define DLL_PROCESS_DETACH
Definition: compat.h:130
ULONG g_BaseHandlers
DWORD dwErr
Definition: service.c:36
LONG g_DllMainCalled
#define FreeLibrary(x)
Definition: compat.h:607
#define trace
Definition: atltest.h:70
WCHAR dllpath[MAX_PATH]
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned long DWORD
Definition: ntddk_ex.h:95
_SEH2_END
Definition: create.c:4400
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
static int mod
Definition: i386-dis.c:1281
LONG g_TlsExcept

Referenced by START_TEST().

◆ extract_resource()

BOOL extract_resource ( const WCHAR Filename,
LPCWSTR  ResourceName 
)

Definition at line 239 of file load_notifications.c.

240 {
241  BOOL Success;
242  DWORD dwWritten, Size;
243  HGLOBAL hGlobal;
244  LPVOID pData;
245  HANDLE Handle;
246  HRSRC hRsrc = FindResourceW(GetModuleHandleW(NULL), ResourceName, (LPCWSTR)10);
247  ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
248  if (!hRsrc)
249  return FALSE;
250 
251  hGlobal = LoadResource(GetModuleHandleW(NULL), hRsrc);
253  pData = LockResource(hGlobal);
254 
255  ok(Size && !!pData, "Unable to load %s\n", wine_dbgstr_w(ResourceName));
256  if (!Size || !pData)
257  return FALSE;
258 
260 
262  {
263  skip("Failed to create temp file %ls, error %lu\n", Filename, GetLastError());
264  return FALSE;
265  }
266  Success = WriteFile(Handle, pData, Size, &dwWritten, NULL);
267  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
268  ok(dwWritten == Size, "WriteFile wrote %lu bytes instead of %lu\n", dwWritten, Size);
270  Success = Success && (dwWritten == Size);
271 
273  return Success;
274 }
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 CloseHandle
Definition: compat.h:598
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
#define UnlockResource(handle)
Definition: winbase.h:3228
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:934
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
_In_ HANDLE Handle
Definition: extypes.h:390
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
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 66 of file load_notifications.c.

67 {
69 
72  {
74  }
75  else
76  {
77  ok_int(handlers, g_DLL_DETACH); // For failures, see https://jira.reactos.org/browse/CORE-14857
78  }
79 
81  {
83  }
84  return TRUE;
85 }
#define TRUE
Definition: types.h:120
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1307
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:154
#define InterlockedCompareExchange
Definition: interlocked.h:104
int g_DLL_DETACH
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
LONG g_DllMainExcept
ULONG CountHandlers(VOID)
#define ok_int(expression, result)
Definition: atltest.h:134
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:700
#define NULL
Definition: types.h:112
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 43 of file load_notifications.c.

44 {
46 
49  {
51  }
52  else
53  {
55  }
56 
58  {
60  }
61 }
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1307
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:154
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
int g_TLS_DETACH
ULONG CountHandlers(VOID)
#define ok_int(expression, result)
Definition: atltest.h:134
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:700
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
LONG g_TlsExcept

◆ START_TEST()

START_TEST ( load_notifications  )

Definition at line 277 of file load_notifications.c.

278 {
280  BOOL ret;
281  UINT Length;
282  PPEB Peb = NtCurrentPeb();
283 
285  trace("Winver: 0x%lx\n", g_dwWinVer);
286 
288  {
289  g_DLL_ATTACH = 4;
290  g_DLL_DETACH = 1;
291  }
292  else if (g_dwWinVer <= _WIN32_WINNT_WS08)
293  {
294  g_TLS_ATTACH = 5;
295  g_DLL_ATTACH = 4;
296  }
297  else if (g_dwWinVer <= _WIN32_WINNT_WIN7)
298  {
299  g_TLS_ATTACH = 3;
300  g_DLL_ATTACH = 2;
301  }
302  else if (g_dwWinVer <= _WIN32_WINNT_WINBLUE)
303  {
304  g_TLS_DETACH = 5;
305  g_DLL_DETACH = 4;
306  }
307 
309  ok(ret, "GetTempPathW error: %lu\n", GetLastError());
310 
311  Length = GetTempFileNameW(workdir, L"ntdll", 0, dllpath);
312  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
313 
314  if (extract_resource(dllpath, (LPCWSTR)101))
315  {
316  _SEH2_TRY
317  {
318  execute_test();
319  }
321  {
322  ok(0, "Ldr didnt handle exception\n");
323  }
324  _SEH2_END;
325  }
326  else
327  {
328  ok(0, "Failed to extract resource\n");
329  }
330 
332 }
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
PPEB Peb
Definition: dllmain.c:27
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD g_dwWinVer
int g_DLL_DETACH
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
int g_TLS_DETACH
#define DWORD
Definition: nt_native.h:44
_SEH2_TRY
Definition: create.c:4226
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
static void execute_test(void)
#define trace
Definition: atltest.h:70
WCHAR dllpath[MAX_PATH]
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _countof(array)
Definition: sndvol32.h:68
static char workdir[MAX_PATH]
Definition: batch.c:26
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
int g_TLS_ATTACH
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:4400
#define NtCurrentPeb()
Definition: FLS.c:22
#define ok(value,...)
Definition: atltest.h:57
#define _WIN32_WINNT_WS08
Definition: sdkddkver.h:26
unsigned int UINT
Definition: ndis.h:50
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
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 20 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 63 of file load_notifications.c.

Referenced by notify_DllMain(), and START_TEST().

◆ g_DLL_DETACH

int g_DLL_DETACH = 2

Definition at line 64 of file load_notifications.c.

Referenced by notify_DllMain(), and START_TEST().

◆ g_DllMainCalled

LONG g_DllMainCalled = 0

Definition at line 15 of file load_notifications.c.

Referenced by execute_test(), and notify_DllMain().

◆ g_DllMainExcept

LONG g_DllMainExcept = 0xffffff

Definition at line 18 of file load_notifications.c.

Referenced by execute_test(), and notify_DllMain().

◆ g_dwWinVer

DWORD g_dwWinVer = 0

Definition at line 22 of file load_notifications.c.

Referenced by execute_test(), and START_TEST().

◆ g_TLS_ATTACH

int g_TLS_ATTACH = 4

Definition at line 40 of file load_notifications.c.

Referenced by notify_TlsCallback(), and START_TEST().

◆ g_TLS_DETACH

int g_TLS_DETACH = 3

Definition at line 41 of file load_notifications.c.

Referenced by notify_TlsCallback(), and START_TEST().

◆ g_TlsCalled

LONG g_TlsCalled = 0

Definition at line 14 of file load_notifications.c.

Referenced by execute_test(), and notify_TlsCallback().

◆ g_TlsExcept

LONG g_TlsExcept = 0xffffff

Definition at line 17 of file load_notifications.c.

Referenced by execute_test(), and notify_TlsCallback().