ReactOS 0.4.15-dev-7942-gd23573b
load_notifications.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for exception behavior in dll notifications
5 * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include "precomp.h"
9
10#include <pseh/pseh2.h>
11
13
16
17LONG g_TlsExcept = 0xffffff;
19
21
23
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}
39
42
44{
46
49 {
51 }
52 else
53 {
55 }
56
58 {
60 }
61}
62
65
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}
86
87
88static void execute_test(void)
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}
237
238
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}
275
276
277START_TEST(load_notifications)
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 InterlockedIncrement
Definition: armddk.h:53
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
DWORD dwErr
Definition: service.c:36
DWORD dwReason
Definition: misc.cpp:154
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define LoadLibraryW(x)
Definition: compat.h:747
PPEB Peb
Definition: dllmain.c:27
VOID WINAPI RaiseException(_In_ DWORD dwExceptionCode, _In_ DWORD dwExceptionFlags, _In_ DWORD nNumberOfArguments, _In_opt_ const ULONG_PTR *lpArguments)
Definition: except.c:700
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
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
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1317
@ Success
Definition: eventcreate.c:712
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:939
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
static int mod
Definition: i386-dis.c:1288
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define NtCurrentTeb
#define wine_dbgstr_w
Definition: kernel32.h:34
static IN DWORD IN LPVOID lpvReserved
LONG g_TlsExcept
LONG g_DllMainExcept
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
int g_DLL_DETACH
LONG g_DllMainCalled
BOOL WINAPI notify_DllMain(IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved)
int g_TLS_ATTACH
DWORD g_dwWinVer
ULONG g_BaseHandlers
int g_DLL_ATTACH
static void execute_test(void)
VOID WINAPI notify_TlsCallback(IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved)
ULONG CountHandlers(VOID)
LONG g_TlsCalled
WCHAR dllpath[MAX_PATH]
int g_TLS_DETACH
#define CREATE_ALWAYS
Definition: disk.h:72
static char workdir[MAX_PATH]
Definition: batch.c:26
unsigned int UINT
Definition: ndis.h:50
int Count
Definition: noreturn.cpp:7
#define DWORD
Definition: nt_native.h:44
#define GENERIC_WRITE
Definition: nt_native.h:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
#define _WIN32_WINNT_WS08
Definition: sdkddkver.h:26
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define _countof(array)
Definition: sndvol32.h:68
struct _EXCEPTION_REGISTRATION_RECORD * Next
Definition: compat.h:726
ULONG OSMinorVersion
Definition: ntddk_ex.h:301
ULONG OSMajorVersion
Definition: ntddk_ex.h:300
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:312
#define UnlockResource(handle)
Definition: winbase.h:3372
#define WINAPI
Definition: msvc.h:6
#define ERROR_DLL_INIT_FAILED
Definition: winerror.h:650
#define ERROR_NOACCESS
Definition: winerror.h:578
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185