ReactOS 0.4.15-dev-7924-g5949c20
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}
#define NtCurrentTeb
int Count
Definition: noreturn.cpp:7
struct _EXCEPTION_REGISTRATION_RECORD * Next
Definition: compat.h:726
uint32_t ULONG
Definition: typedefs.h:59

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{
93 {
94 g_TlsExcept = 0xffffff;
95 g_DllMainExcept = 0xffffff;
97 g_TlsCalled = 0;
101 ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
105 if (g_TlsCalled == 0)
106 trace("Tls not active\n");
110 ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
114 }
116 {
117 ok(0, "Unable to load it normally\n");
118 }
119 _SEH2_END;
120
121
123 {
124 g_TlsExcept = 0xffffff;
126 g_DllMainCalled = 0;
127 g_TlsCalled = 0;
131 ok(GetModuleHandleW(dllpath) == NULL, "Module loaded (0x%lx)\n", dwErr);
134 else
139 if (mod)
140 {
143 ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
147 }
148 }
150 {
151 ok(0, "Unable to execute test\n");
152 }
153 _SEH2_END;
154
156 {
157 g_TlsExcept = 0xffffff;
159 g_DllMainCalled = 0;
160 g_TlsCalled = 0;
164 ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
171 ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
175 }
177 {
178 ok(0, "Unable to execute test\n");
179 }
180 _SEH2_END;
181
183 {
185 g_DllMainExcept = 0xffffff;
186 g_DllMainCalled = 0;
187 g_TlsCalled = 0;
191 ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
198 ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
202 }
204 {
205 ok(0, "Unable to execute test\n");
206 }
207 _SEH2_END;
208
210 {
212 g_DllMainExcept = 0xffffff;
213 g_DllMainCalled = 0;
214 g_TlsCalled = 0;
218 ok(GetModuleHandleW(dllpath) != NULL, "Unable to load module (0x%lx)\n", dwErr);
225 ok(GetModuleHandleW(dllpath) == NULL, "Unable to unload module (0x%lx)\n", dwErr);
229 }
231 {
232 ok(0, "Unable to execute test\n");
233 }
234 _SEH2_END;
235
236}
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
DWORD dwErr
Definition: service.c:36
#define NULL
Definition: types.h:112
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned long DWORD
Definition: ntddk_ex.h:95
static int mod
Definition: i386-dis.c:1288
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
LONG g_TlsExcept
LONG g_DllMainExcept
LONG g_DllMainCalled
DWORD g_dwWinVer
ULONG g_BaseHandlers
ULONG CountHandlers(VOID)
LONG g_TlsCalled
WCHAR dllpath[MAX_PATH]
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_DLL_INIT_FAILED
Definition: winerror.h:650
#define ERROR_NOACCESS
Definition: winerror.h:578

Referenced by START_TEST().

◆ extract_resource()

BOOL extract_resource ( const WCHAR Filename,
LPCWSTR  ResourceName 
)

Definition at line 239 of file load_notifications.c.

240{
242 DWORD dwWritten, Size;
243 HGLOBAL hGlobal;
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}
#define skip(...)
Definition: atltest.h:64
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
@ Success
Definition: eventcreate.c:712
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:939
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG Handle
Definition: gdb_input.c:15
#define wine_dbgstr_w
Definition: kernel32.h:34
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define UnlockResource(handle)
Definition: winbase.h:3372
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

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 InterlockedIncrement
Definition: armddk.h:53
#define ok_int(expression, result)
Definition: atltest.h:134
DWORD dwReason
Definition: misc.cpp:154
VOID WINAPI RaiseException(_In_ DWORD dwExceptionCode, _In_ DWORD dwExceptionFlags, _In_ DWORD nNumberOfArguments, _In_opt_ const ULONG_PTR *lpArguments)
Definition: except.c:700
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1317
#define InterlockedCompareExchange
Definition: interlocked.h:104
int g_DLL_DETACH
int g_DLL_ATTACH
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:312

◆ notify_TlsCallback()

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

◆ START_TEST()

START_TEST ( load_notifications  )

Definition at line 277 of file load_notifications.c.

278{
280 BOOL ret;
281 UINT Length;
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 }
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
315 {
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 NtCurrentPeb()
Definition: FLS.c:22
#define MAX_PATH
Definition: compat.h:34
PPEB Peb
Definition: dllmain.c:27
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
static void execute_test(void)
static char workdir[MAX_PATH]
Definition: batch.c:26
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
#define _WIN32_WINNT_WS08
Definition: sdkddkver.h:26
#define _countof(array)
Definition: sndvol32.h:68
ULONG OSMinorVersion
Definition: ntddk_ex.h:301
ULONG OSMajorVersion
Definition: ntddk_ex.h:300
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180

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().