ReactOS 0.4.16-dev-2206-gc56950d
module.c
Go to the documentation of this file.
1/*
2 * Unit tests for module/DLL/library API
3 *
4 * Copyright (c) 2004 Eric Pouech
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdio.h>
22#include "ntstatus.h"
23#define WIN32_NO_STATUS
24#include "windef.h"
25#include "winbase.h"
26#include "winnls.h"
27#include "winternl.h"
28#include <psapi.h>
29#include "wine/test.h"
30
31static DWORD (WINAPI *pGetDllDirectoryA)(DWORD,LPSTR);
32static DWORD (WINAPI *pGetDllDirectoryW)(DWORD,LPWSTR);
33static BOOL (WINAPI *pSetDllDirectoryA)(LPCSTR);
34static DLL_DIRECTORY_COOKIE (WINAPI *pAddDllDirectory)(const WCHAR*);
35static BOOL (WINAPI *pRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
36static BOOL (WINAPI *pSetDefaultDllDirectories)(DWORD);
37static BOOL (WINAPI *pK32GetModuleInformation)(HANDLE process, HMODULE module,
39
40static NTSTATUS (WINAPI *pApiSetQueryApiSetPresence)(const UNICODE_STRING*,BOOLEAN*);
41static NTSTATUS (WINAPI *pApiSetQueryApiSetPresenceEx)(const UNICODE_STRING*,BOOLEAN*,BOOLEAN*);
42static NTSTATUS (WINAPI *pLdrGetDllDirectory)(UNICODE_STRING*);
43static NTSTATUS (WINAPI *pLdrSetDllDirectory)(UNICODE_STRING*);
44static NTSTATUS (WINAPI *pLdrGetDllHandle)( LPCWSTR load_path, ULONG flags, const UNICODE_STRING *name, HMODULE *base );
47static NTSTATUS (WINAPI *pLdrGetDllFullName)( HMODULE module, UNICODE_STRING *name );
48
49static BOOL (WINAPI *pIsApiSetImplemented)(LPCSTR);
50
51static NTSTATUS (WINAPI *pRtlHashUnicodeString)( const UNICODE_STRING *, BOOLEAN, ULONG, ULONG * );
52
54
55static BOOL cmpStrAW(const char* a, const WCHAR* b, DWORD lenA, DWORD lenB)
56{
57 WCHAR aw[1024];
58
60 a, lenA, aw, ARRAY_SIZE(aw));
61 if (len != lenB) return FALSE;
62 return memcmp(aw, b, len * sizeof(WCHAR)) == 0;
63}
64
65static const struct
66{
70} dll_image =
71{
72 { IMAGE_DOS_SIGNATURE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 }, 0, 0, { 0 },
73 sizeof(IMAGE_DOS_HEADER) },
74 {
75 IMAGE_NT_SIGNATURE, /* Signature */
76 {
77#if defined __i386__
78 IMAGE_FILE_MACHINE_I386, /* Machine */
79#elif defined __x86_64__
80 IMAGE_FILE_MACHINE_AMD64, /* Machine */
81#elif defined __arm__
82 IMAGE_FILE_MACHINE_ARMNT, /* Machine */
83#elif defined __aarch64__
84 IMAGE_FILE_MACHINE_ARM64, /* Machine */
85#else
86# error You must specify the machine type
87#endif
88 1, /* NumberOfSections */
89 0, /* TimeDateStamp */
90 0, /* PointerToSymbolTable */
91 0, /* NumberOfSymbols */
92 sizeof(IMAGE_OPTIONAL_HEADER), /* SizeOfOptionalHeader */
93 IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL /* Characteristics */
94 },
95 { IMAGE_NT_OPTIONAL_HDR_MAGIC, /* Magic */
96 1, /* MajorLinkerVersion */
97 0, /* MinorLinkerVersion */
98 0, /* SizeOfCode */
99 0, /* SizeOfInitializedData */
100 0, /* SizeOfUninitializedData */
101 0, /* AddressOfEntryPoint */
102 0x1000, /* BaseOfCode */
103#ifndef _WIN64
104 0, /* BaseOfData */
105#endif
106 0x10000000, /* ImageBase */
107 0x1000, /* SectionAlignment */
108 0x1000, /* FileAlignment */
109 4, /* MajorOperatingSystemVersion */
110 0, /* MinorOperatingSystemVersion */
111 1, /* MajorImageVersion */
112 0, /* MinorImageVersion */
113 4, /* MajorSubsystemVersion */
114 0, /* MinorSubsystemVersion */
115 0, /* Win32VersionValue */
116 0x2000, /* SizeOfImage */
117 sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS), /* SizeOfHeaders */
118 0, /* CheckSum */
119 IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
121 0, /* SizeOfStackReserve */
122 0, /* SizeOfStackCommit */
123 0, /* SizeOfHeapReserve */
124 0, /* SizeOfHeapCommit */
125 0, /* LoaderFlags */
126 0, /* NumberOfRvaAndSizes */
127 { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
128 }
129 },
130 { ".rodata", { 0 }, 0x1000, 0x1000, 0, 0, 0, 0, 0,
133
134static void create_test_dll( const char *name )
135{
136 DWORD dummy;
138
139 ok( handle != INVALID_HANDLE_VALUE, "failed to create file err %lu\n", GetLastError() );
140 WriteFile( handle, &dll_image, sizeof(dll_image), &dummy, NULL );
141 SetFilePointer( handle, dll_image.nt.OptionalHeader.SizeOfImage, NULL, FILE_BEGIN );
144}
145
147{
149 LDR_DDAG_NODE *ddag_node;
151 HMODULE hexe;
152
153 /* Check for old LDR data strcuture. */
154#ifdef __REACTOS__
156 return TRUE;
157#endif
158 hexe = GetModuleHandleW( NULL );
159 ok( !!hexe, "Got NULL exe handle.\n" );
161 ok( !status, "got %#lx.\n", status );
162 if (!(ddag_node = mod->DdagNode))
163 {
164 win_skip( "DdagNode is NULL, skipping tests.\n" );
165 return TRUE;
166 }
167 ok( !!ddag_node->Modules.Flink, "Got NULL module link.\n" );
168 mod2 = CONTAINING_RECORD(ddag_node->Modules.Flink, LDR_DATA_TABLE_ENTRY, NodeModuleLink);
169 ok( mod2 == mod || broken( (void **)mod2 == (void **)mod - 1 ), "got %p, expected %p.\n", mod2, mod );
170 if (mod2 != mod)
171 {
172 win_skip( "Old LDR_DATA_TABLE_ENTRY structure, skipping tests.\n" );
173 return TRUE;
174 }
175 return FALSE;
176}
177
178static void testGetModuleFileName(const char* name)
179{
180 HMODULE hMod;
181 char bufA[MAX_PATH];
182 WCHAR bufW[MAX_PATH];
183 DWORD len1A, len1W = 0, len2A, len2W = 0;
184
185 hMod = (name) ? GetModuleHandleA(name) : NULL;
186
187 /* first test, with enough space in buffer */
188 memset(bufA, '-', sizeof(bufA));
189 SetLastError(0xdeadbeef);
190 len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA));
192 broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */
193 "LastError was not reset: %lu\n", GetLastError());
194 ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
195
197 {
198 memset(bufW, '-', sizeof(bufW));
199 SetLastError(0xdeadbeef);
200 len1W = GetModuleFileNameW(hMod, bufW, ARRAY_SIZE(bufW));
202 broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */
203 "LastError was not reset: %lu\n", GetLastError());
204 ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
205 }
206
207 ok(len1A == strlen(bufA), "Unexpected length of GetModuleFilenameA (%ld/%d)\n", len1A, lstrlenA(bufA));
208
210 {
211 ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%ld/%d)\n", len1W, lstrlenW(bufW));
212 ok(cmpStrAW(bufA, bufW, len1A, len1W), "Comparing GetModuleFilenameAW results\n");
213 }
214
215 /* second test with a buffer too small */
216 memset(bufA, '-', sizeof(bufA));
217 len2A = GetModuleFileNameA(hMod, bufA, len1A / 2);
218 ok(len2A > 0, "Getting module filename for handle %p\n", hMod);
219
221 {
222 memset(bufW, '-', sizeof(bufW));
223 len2W = GetModuleFileNameW(hMod, bufW, len1W / 2);
224 ok(len2W > 0, "Getting module filename for handle %p\n", hMod);
225 ok(cmpStrAW(bufA, bufW, len2A, len2W), "Comparing GetModuleFilenameAW results with buffer too small\n" );
226 ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%ld/%ld)\n", len1W / 2, len2W);
227 }
228
229 ok(len1A / 2 == len2A,
230 "Correct length in GetModuleFilenameA with buffer too small (%ld/%ld)\n", len1A / 2, len2A);
231
232 len1A = GetModuleFileNameA(hMod, bufA, 0x10000);
233 ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
234 len1W = GetModuleFileNameW(hMod, bufW, 0x10000);
235 ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
236}
237
239{
240 char bufA[MAX_PATH];
241 WCHAR bufW[MAX_PATH];
242
243 /* test wrong handle */
245 {
246 bufW[0] = '*';
247 ok(GetModuleFileNameW((void*)0xffffffff, bufW, ARRAY_SIZE(bufW)) == 0,
248 "Unexpected success in module handle\n");
249 ok(bufW[0] == '*', "When failing, buffer shouldn't be written to\n");
250 }
251
252 bufA[0] = '*';
253 ok(GetModuleFileNameA((void*)0xffffffff, bufA, sizeof(bufA)) == 0, "Unexpected success in module handle\n");
254 ok(bufA[0] == '*', "When failing, buffer shouldn't be written to\n");
255}
256
257static void testLoadLibraryA(void)
258{
259 HMODULE hModule, hModule1;
260 FARPROC fp;
261
262 SetLastError(0xdeadbeef);
263 hModule = LoadLibraryA("kernel32.dll");
264 ok( hModule != NULL, "kernel32.dll should be loadable\n");
265 ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %ld\n", GetLastError());
266
267 fp = GetProcAddress(hModule, "CreateFileA");
268 ok( fp != NULL, "CreateFileA should be there\n");
269 ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %ld\n", GetLastError());
270
271 SetLastError(0xdeadbeef);
272 hModule1 = LoadLibraryA("kernel32 ");
273 ok( hModule1 != NULL, "\"kernel32 \" should be loadable\n" );
274 ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %ld\n", GetLastError() );
275 ok( hModule == hModule1, "Loaded wrong module\n" );
276 FreeLibrary(hModule1);
278}
279
280static void testNestedLoadLibraryA(void)
281{
282 static const char dllname[] = "shell32.dll";
284 HMODULE hModule1, hModule2, hModule3;
285
286 /* This is not really a Windows conformance test, but more a Wine
287 * regression test. Wine's builtin dlls can be loaded from multiple paths,
288 * and this test tries to make sure that Wine does not get confused and
289 * really unloads the Unix .so file at the right time. Failure to do so
290 * will result in the dll being unloadable.
291 * This test must be done with a dll that can be unloaded, which means:
292 * - it must not already be loaded
293 * - it must not have a 16-bit counterpart
294 */
296 strcat(path1, "\\system\\");
297 strcat(path1, dllname);
298 hModule1 = LoadLibraryA(path1);
299 if (!hModule1)
300 {
301 /* We must be on Windows, so we cannot test */
302 return;
303 }
304
306 strcat(path2, "\\system32\\");
307 strcat(path2, dllname);
308 hModule2 = LoadLibraryA(path2);
309 ok(hModule2 != NULL, "LoadLibrary(%s) failed\n", path2);
310
311 /* The first LoadLibrary() call may have registered the dll under the
312 * system32 path. So load it, again, under the '...\system\...' path so
313 * Wine does not immediately notice that it is already loaded.
314 */
315 hModule3 = LoadLibraryA(path1);
316 ok(hModule3 != NULL, "LoadLibrary(%s) failed\n", path1);
317
318 /* Now fully unload the dll */
319 ok(FreeLibrary(hModule3), "FreeLibrary() failed\n");
320 ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
321 ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
322 ok(GetModuleHandleA(dllname) == NULL, "%s was not fully unloaded\n", dllname);
323
324 /* Try to load the dll again, if refcounting is ok, this should work */
325 hModule1 = LoadLibraryA(path1);
326 ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", path1);
327 if (hModule1 != NULL)
328 ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
329}
330
331static void testLoadLibraryA_Wrong(void)
332{
334
335 /* Try to load a nonexistent dll */
336 SetLastError(0xdeadbeef);
337 hModule = LoadLibraryA("non_ex_pv.dll");
338 ok( !hModule, "non_ex_pv.dll should be not loadable\n");
339 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "Expected ERROR_MOD_NOT_FOUND, got %ld\n", GetLastError() );
340
341 /* Just in case */
343}
344
346{
347 FARPROC fp;
348
349 SetLastError(0xdeadbeef);
350 fp = GetProcAddress(NULL, "non_ex_call");
351 ok( !fp, "non_ex_call should not be found\n");
352 ok( GetLastError() == ERROR_PROC_NOT_FOUND, "Expected ERROR_PROC_NOT_FOUND, got %ld\n", GetLastError() );
353
354 SetLastError(0xdeadbeef);
355 fp = GetProcAddress((HMODULE)0xdeadbeef, "non_ex_call");
356 ok( !fp, "non_ex_call should not be found\n");
357 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "Expected ERROR_MOD_NOT_FOUND, got %ld\n", GetLastError() );
358}
359
360static void testLoadLibraryEx(void)
361{
364 HANDLE hfile;
365 BOOL ret;
366
367 hfile = CreateFileA("testfile.dll", GENERIC_READ | GENERIC_WRITE,
370 ok(hfile != INVALID_HANDLE_VALUE, "Expected a valid file handle\n");
371
372 /* NULL lpFileName */
373 SetLastError(0xdeadbeef);
375 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
378 "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
379
380 /* empty lpFileName */
381 SetLastError(0xdeadbeef);
382 hmodule = LoadLibraryExA("", NULL, 0);
383 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
386 "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND, got %ld\n", GetLastError());
387
388 /* hFile is non-NULL */
389 SetLastError(0xdeadbeef);
390 hmodule = LoadLibraryExA("testfile.dll", hfile, 0);
391 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
393 GetLastError() == ERROR_INVALID_PARAMETER, /* win2k3 */
394 "Unexpected last error, got %ld\n", GetLastError());
395
396 SetLastError(0xdeadbeef);
397 hmodule = LoadLibraryExA("testfile.dll", (HANDLE)0xdeadbeef, 0);
398 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
400 GetLastError() == ERROR_INVALID_PARAMETER, /* win2k3 */
401 "Unexpected last error, got %ld\n", GetLastError());
402
403 /* try to open a file that is locked */
404 SetLastError(0xdeadbeef);
405 hmodule = LoadLibraryExA("testfile.dll", NULL, 0);
406 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
408 "Expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
409
410 /* lpFileName does not matter */
412 {
413 SetLastError(0xdeadbeef);
414 hmodule = LoadLibraryExA(NULL, hfile, 0);
415 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
417 GetLastError() == ERROR_INVALID_PARAMETER, /* win2k3 */
418 "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
419 }
420
421 CloseHandle(hfile);
422
423 /* load empty file */
424 SetLastError(0xdeadbeef);
426 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
427 ok(GetLastError() == ERROR_FILE_INVALID, "Expected ERROR_FILE_INVALID, got %ld\n", GetLastError());
428
429 DeleteFileA("testfile.dll");
430
432 if (path[lstrlenA(path) - 1] != '\\')
433 lstrcatA(path, "\\");
434 lstrcatA(path, "kernel32.dll");
435
436 /* load kernel32.dll with an absolute path */
437 SetLastError(0xdeadbeef);
439 ok(hmodule != 0, "Expected valid module handle\n");
440 ok(GetLastError() == 0xdeadbeef ||
442 "Expected 0xdeadbeef or ERROR_SUCCESS, got %ld\n", GetLastError());
443
444 /* try invalid file handle */
445 SetLastError(0xdeadbeef);
446 hmodule = LoadLibraryExA(path, (HANDLE)0xdeadbeef, 0);
447 if (!hmodule) /* succeeds on xp and older */
448 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError());
449
451
452 /* load kernel32.dll with no path */
453 SetLastError(0xdeadbeef);
455 ok(hmodule != 0, "Expected valid module handle\n");
456 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError());
457
459
461 if (path[lstrlenA(path) - 1] != '\\')
462 lstrcatA(path, "\\");
463 lstrcatA(path, "kernel32.dll");
464
465 /* load kernel32.dll with an absolute path that does not exist */
466 SetLastError(0xdeadbeef);
468 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
470 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
471
472 /* Free the loaded dll when it's the first time this dll is loaded
473 in process - First time should pass, second fail */
474 SetLastError(0xdeadbeef);
476 ok(hmodule != 0, "Expected valid module handle\n");
477
478 SetLastError(0xdeadbeef);
479 ret = FreeLibrary( (HMODULE)((ULONG_PTR)hmodule + 0x1230));
480 ok(!ret, "Free succeeded on wrong handle\n");
481 ok(GetLastError() == ERROR_BAD_EXE_FORMAT, "wrong error %lu\n", GetLastError());
482
483 SetLastError(0xdeadbeef);
485 ok(ret, "Expected to be able to free the module, failed with %ld\n", GetLastError());
486 SetLastError(0xdeadbeef);
488 ok(!ret, "Unexpected ability to free the module, failed with %ld\n", GetLastError());
489
490 /* load with full path, name without extension */
492 if (path[lstrlenA(path) - 1] != '\\')
493 lstrcatA(path, "\\");
494 lstrcatA(path, "kernel32");
496 ok(hmodule != NULL, "got %p\n", hmodule);
498
499 /* same with alterate search path */
501 ok(hmodule != NULL, "got %p\n", hmodule);
503}
504
506{
507 static const char apiset_dll[] = "api-ms-win-shcore-obsolete-l1-1-0.dll";
508 static const struct
509 {
510 int add_dirs[4];
511 int dll_dir;
512 int expect;
513 } tests[] =
514 {
515 { { 1, 2, 3 }, 4, 3 }, /* 0 */
516 { { 1, 3, 2 }, 4, 2 },
517 { { 3, 1 }, 4, 1 },
518 { { 5, 6 }, 4, 4 },
519 { { 5, 2 }, 4, 2 },
520 { { 0 }, 4, 4 }, /* 5 */
521 { { 0 }, 0, 0 },
522 { { 6, 5 }, 5, 0 },
523 { { 1, 1, 2 }, 0, 2 },
524 };
525 char *p, path[MAX_PATH], buf[MAX_PATH], curdir[MAX_PATH];
526 WCHAR bufW[MAX_PATH];
528 unsigned int i, j, k;
529 BOOL ret;
530 HMODULE mod;
531
532 GetTempPathA( sizeof(path), path );
533 GetTempFileNameA( path, "tmp", 0, buf );
534 DeleteFileA( buf );
536 ok( ret, "CreateDirectory failed err %lu\n", GetLastError() );
537 p = buf + strlen( buf );
538 for (i = 1; i <= 6; i++)
539 {
540 sprintf( p, "\\%u", i );
542 ok( ret, "CreateDirectory failed err %lu\n", GetLastError() );
543 if (i >= 5) continue; /* dirs 5 and 6 are left empty */
544 sprintf( p, "\\%u\\winetestdll.dll", i );
546 }
547
549 *p = 0;
551
552 SetLastError( 0xdeadbeef );
553 mod = LoadLibraryA( "1\\winetestdll.dll" );
554 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
555 FreeLibrary( mod );
556
557 SetLastError( 0xdeadbeef );
558 sprintf( path, "%c:1\\winetestdll.dll", buf[0] );
559 mod = LoadLibraryA( path );
560 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
561 FreeLibrary( mod );
562
563 if (pAddDllDirectory)
564 {
565 SetLastError( 0xdeadbeef );
566 mod = LoadLibraryExA( "1\\winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
567 ok( !mod, "LoadLibrary succeeded\n" );
568 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
569
570 SetLastError( 0xdeadbeef );
572 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
573 FreeLibrary( mod );
574 }
575
576 strcpy( p, "\\1" );
578
579 SetLastError( 0xdeadbeef );
580 mod = LoadLibraryA( "winetestdll.dll" );
581 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
582 FreeLibrary( mod );
583
584 SetLastError( 0xdeadbeef );
585 sprintf( path, "%c:winetestdll.dll", buf[0] );
586 mod = LoadLibraryA( path );
587 ok( mod != NULL || broken(!mod), /* win10 disallows this but allows c:1\\winetestdll.dll */
588 "LoadLibrary failed err %lu\n", GetLastError() );
589 if (!mod) ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
590 else FreeLibrary( mod );
591
592 SetLastError( 0xdeadbeef );
593 sprintf( path, "%s\\winetestdll.dll", buf + 2 );
594 mod = LoadLibraryA( path );
595 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
596 FreeLibrary( mod );
597
598 if (pAddDllDirectory)
599 {
600 SetLastError( 0xdeadbeef );
601 mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
602 ok( !mod, "LoadLibrary succeeded\n" );
603 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
604
605 SetLastError( 0xdeadbeef );
607 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
608 FreeLibrary( mod );
609
610 SetLastError( 0xdeadbeef );
611 sprintf( path, "%s\\winetestdll.dll", buf + 2 );
613 ok( mod != NULL, "LoadLibrary failed err %lu\n", GetLastError() );
614 FreeLibrary( mod );
615
616 SetLastError( 0xdeadbeef );
618 ok( !mod, "LoadLibrary succeeded\n" );
619 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
620
621 SetLastError( 0xdeadbeef );
623 ok( !mod, "LoadLibrary succeeded\n" );
624 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
625
626 SetLastError( 0xdeadbeef );
628 ok( !mod, "LoadLibrary succeeded\n" );
629 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
630
631 SetLastError( 0xdeadbeef );
633 ok( !mod, "LoadLibrary succeeded\n" );
634 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
635
636 SetLastError( 0xdeadbeef );
638 ok( !mod, "LoadLibrary succeeded\n" );
639 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
640 }
641
642 SetCurrentDirectoryA( curdir );
643
644 if (!pAddDllDirectory || !pSetDllDirectoryA) goto done;
645
646 SetLastError( 0xdeadbeef );
647 mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_APPLICATION_DIR );
648 ok( !mod, "LoadLibrary succeeded\n" );
649 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
650
651 if (0) /* crashes on win10 */
652 {
653 SetLastError( 0xdeadbeef );
654 mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_USER_DIRS );
655 ok( !mod, "LoadLibrary succeeded\n" );
657 "wrong error %lu\n", GetLastError() );
658 }
659
660 SetLastError( 0xdeadbeef );
661 mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
662 ok( !mod, "LoadLibrary succeeded\n" );
663 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
664
665 SetLastError( 0xdeadbeef );
666 mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR );
667 ok( !mod, "LoadLibrary succeeded\n" );
668 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
669
670 SetLastError( 0xdeadbeef );
672 ok( !mod, "LoadLibrary succeeded\n" );
673 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
674
675 SetLastError( 0xdeadbeef );
676 mod = LoadLibraryExA( "foo\\winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR );
677 ok( !mod, "LoadLibrary succeeded\n" );
678 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
679
680 SetLastError( 0xdeadbeef );
681 mod = LoadLibraryExA( "\\windows\\winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR );
682 ok( !mod, "LoadLibrary succeeded\n" );
683 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
684
685 SetLastError( 0xdeadbeef );
686 mod = LoadLibraryA( "1\\winetestdll.dll" );
687 ok( !mod, "LoadLibrary succeeded\n" );
688 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
689
690 for (j = 0; j < ARRAY_SIZE(tests); j++)
691 {
692 for (k = 0; tests[j].add_dirs[k]; k++)
693 {
694 sprintf( p, "\\%u", tests[j].add_dirs[k] );
695 MultiByteToWideChar( CP_ACP, 0, buf, -1, bufW, MAX_PATH );
696 cookies[k] = pAddDllDirectory( bufW );
697 ok( cookies[k] != NULL, "failed to add %s\n", buf );
698 }
699 if (tests[j].dll_dir)
700 {
701 sprintf( p, "\\%u", tests[j].dll_dir );
702 pSetDllDirectoryA( buf );
703 }
704 else pSetDllDirectoryA( NULL );
705
706 SetLastError( 0xdeadbeef );
707 mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_USER_DIRS );
708 if (tests[j].expect)
709 {
710 ok( mod != NULL, "%u: LoadLibrary failed err %lu\n", j, GetLastError() );
712 sprintf( p, "\\%u\\winetestdll.dll", tests[j].expect );
713 ok( !lstrcmpiA( path, buf ), "%u: wrong module %s expected %s\n", j, path, buf );
714 }
715 else
716 {
717 ok( !mod, "%u: LoadLibrary succeeded\n", j );
719 "%u: wrong error %lu\n", j, GetLastError() );
720 }
721 FreeLibrary( mod );
722
723 for (k = 0; tests[j].add_dirs[k]; k++) pRemoveDllDirectory( cookies[k] );
724 }
725
726 mod = GetModuleHandleA( apiset_dll );
727 if (mod)
728 {
729 win_skip( "%s already referenced, skipping test.\n", apiset_dll );
730 }
731 else
732 {
733 LoadLibraryA( "ole32.dll" ); /* FIXME: make sure the dependencies are loaded */
734 mod = LoadLibraryA( apiset_dll );
735 if (mod)
736 {
737 HMODULE shcore;
738 char buffer[MAX_PATH];
739
742 ok( !!mod, "Got NULL module, error %lu.\n", GetLastError() );
743 ok( !!GetModuleHandleA( apiset_dll ), "Got NULL handle.\n" );
744 shcore = GetModuleHandleA( "shcore.dll" );
745 ok( mod == shcore, "wrong module %p/%p\n", mod, shcore );
746 ret = FreeLibrary( mod );
747 ok( ret, "FreeLibrary failed, error %lu.\n", GetLastError() );
748 shcore = GetModuleHandleA( "shcore.dll" );
749 ok( !shcore, "shcore not unloaded\n" );
750
751 /* api set without .dll */
752 strcpy( buffer, apiset_dll );
753 buffer[strlen(buffer) - 4] = 0;
755 ok( !!mod, "Got NULL module, error %lu.\n", GetLastError() );
756 ok( !!GetModuleHandleA( apiset_dll ), "Got NULL handle.\n" );
757 shcore = GetModuleHandleA( "shcore.dll" );
758 ok( mod == shcore, "wrong module %p/%p\n", mod, shcore );
759 ret = FreeLibrary( mod );
760 ok( ret, "FreeLibrary failed, error %lu.\n", GetLastError() );
761 shcore = GetModuleHandleA( "shcore.dll" );
762 ok( !shcore, "shcore not unloaded\n" );
763
764 /* api set with different version */
765 strcpy( buffer, apiset_dll );
766 buffer[strlen(buffer) - 5] = '9';
768 ok( !!mod || broken(!mod) /* win8 */, "Got NULL module, error %lu.\n", GetLastError() );
769 if (mod)
770 {
771 ok( !!GetModuleHandleA( apiset_dll ), "Got NULL handle.\n" );
772 shcore = GetModuleHandleA( "shcore.dll" );
773 ok( mod == shcore, "wrong module %p/%p\n", mod, shcore );
774 ret = FreeLibrary( mod );
775 ok( ret, "FreeLibrary failed, error %lu.\n", GetLastError() );
776 }
777 shcore = GetModuleHandleA( "shcore.dll" );
778 ok( !shcore, "shcore not unloaded\n" );
779
780 /* api set with full path */
782 strcat( buffer, "\\" );
783 strcat( buffer, apiset_dll );
784 SetLastError( 0xdeadbeef );
786 ok( !mod, "Loaded %s\n", debugstr_a(buffer) );
787 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
788 SetLastError( 0xdeadbeef );
790 ok( !mod, "Loaded %s\n", debugstr_a(buffer) );
791 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
792 }
793 else
794 {
795 win_skip( "%s not found, skipping test.\n", apiset_dll );
796 }
797
798 /* try a library with dependencies */
799 mod = GetModuleHandleA( "rasapi32.dll" );
800 ok( !mod, "rasapi32 already loaded\n" );
801 mod = LoadLibraryA( "rasapi32.dll" );
802 ok( !!mod, "rasapi32 not found %lu\n", GetLastError() );
803 FreeLibrary( mod );
804 SetLastError( 0xdeadbeef );
806 ok( !mod, "rasapi32 loaded\n" );
807 ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
808 SetLastError( 0xdeadbeef );
809 mod = LoadLibraryExA( "ext-ms-win-ras-rasapi32-l1-1-0.dll", NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR );
810 todo_wine /* rasapi32 doesn't have interesting dependencies on wine */
811 ok( !mod, "rasapi32 loaded\n" );
812 if (mod) FreeLibrary( mod );
813 else ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %lu\n", GetLastError() );
814 mod = LoadLibraryA( "ext-ms-win-ras-rasapi32-l1-1-0.dll" );
815 ok( !!mod || broken(!mod) /* win7 */, "rasapi32 not found %lu\n", GetLastError() );
816 if (mod) FreeLibrary( mod );
817 mod = GetModuleHandleA( "rasapi32.dll" );
818 ok( !mod, "rasapi32 still loaded\n" );
819 }
820done:
821 for (i = 1; i <= 6; i++)
822 {
823 sprintf( p, "\\%u\\winetestdll.dll", i );
824 DeleteFileA( buf );
825 sprintf( p, "\\%u", i );
827 }
828 *p = 0;
830}
831
832static void testGetDllDirectory(void)
833{
834 CHAR bufferA[MAX_PATH];
835 WCHAR bufferW[MAX_PATH];
837 int i;
838 static const char *dll_directories[] =
839 {
840 "",
841 "C:\\Some\\Path",
842 "C:\\Some\\Path\\",
843 "Q:\\A\\Long\\Path with spaces that\\probably\\doesn't exist!",
844 };
845 const int test_count = ARRAY_SIZE(dll_directories);
846
847 if (!pGetDllDirectoryA || !pGetDllDirectoryW)
848 {
849 win_skip("GetDllDirectory not available\n");
850 return;
851 }
852 if (!pSetDllDirectoryA)
853 {
854 win_skip("SetDllDirectoryA not available\n");
855 return;
856 }
857
858 for (i = 0; i < test_count; i++)
859 {
860 length = strlen(dll_directories[i]);
861 if (!pSetDllDirectoryA(dll_directories[i]))
862 {
863 skip("i=%d, SetDllDirectoryA failed\n", i);
864 continue;
865 }
866
867 /* no buffer, determine length */
868 ret = pGetDllDirectoryA(0, NULL);
869 ok(ret == length + 1, "Expected %lu, got %lu\n", length + 1, ret);
870
871 ret = pGetDllDirectoryW(0, NULL);
872 ok(ret == length + 1, "Expected %lu, got %lu\n", length + 1, ret);
873
874 /* buffer of exactly the right size */
875 bufferA[length] = 'A';
876 bufferA[length + 1] = 'A';
877 ret = pGetDllDirectoryA(length + 1, bufferA);
878 ok(ret == length || broken(ret + 1 == length) /* win8 */,
879 "i=%d, Expected %lu(+1), got %lu\n", i, length, ret);
880 ok(bufferA[length + 1] == 'A', "i=%d, Buffer overflow\n", i);
881 ok(strcmp(bufferA, dll_directories[i]) == 0, "i=%d, Wrong path returned: '%s'\n", i, bufferA);
882
883 bufferW[length] = 'A';
884 bufferW[length + 1] = 'A';
885 ret = pGetDllDirectoryW(length + 1, bufferW);
886 ok(ret == length, "i=%d, Expected %lu, got %lu\n", i, length, ret);
887 ok(bufferW[length + 1] == 'A', "i=%d, Buffer overflow\n", i);
888 ok(cmpStrAW(dll_directories[i], bufferW, length, length),
889 "i=%d, Wrong path returned: %s\n", i, wine_dbgstr_w(bufferW));
890
891 /* Zero size buffer. The buffer may or may not be terminated depending
892 * on the Windows version and whether the A or W API is called. */
893 bufferA[0] = 'A';
894 ret = pGetDllDirectoryA(0, bufferA);
895 ok(ret == length + 1, "i=%d, Expected %lu, got %lu\n", i, length + 1, ret);
896
897 bufferW[0] = 'A';
898 ret = pGetDllDirectoryW(0, bufferW);
899 ok(ret == length + 1, "i=%d, Expected %lu, got %lu\n", i, length + 1, ret);
900 ok(bufferW[0] == 'A' || broken(bufferW[0] == 0), /* XP, 2003 */
901 "i=%d, Buffer overflow\n", i);
902
903 /* buffer just one too short */
904 bufferA[0] = 'A';
905 ret = pGetDllDirectoryA(length, bufferA);
906 ok(ret == length + 1, "i=%d, Expected %lu, got %lu\n", i, length + 1, ret);
907 if (length != 0)
908 ok(bufferA[0] == 0, "i=%d, Buffer not null terminated\n", i);
909
910 bufferW[0] = 'A';
911 ret = pGetDllDirectoryW(length, bufferW);
912 ok(ret == length + 1, "i=%d, Expected %lu, got %lu\n", i, length + 1, ret);
913 if (length != 0)
914 ok(bufferW[0] == 0, "i=%d, Buffer overflow\n", i);
915
916 if (0)
917 {
918 /* crashes on win8 */
919 /* no buffer, but too short length */
920 ret = pGetDllDirectoryA(length, NULL);
921 ok(ret == length + 1, "i=%d, Expected %lu, got %lu\n", i, length + 1, ret);
922
923 ret = pGetDllDirectoryW(length, NULL);
924 ok(ret == length + 1, "i=%d, Expected %lu, got %lu\n", i, length + 1, ret);
925 }
926
927 if (pLdrGetDllDirectory)
928 {
931 str.Buffer = bufferW;
932 str.MaximumLength = sizeof(bufferW);
933 status = pLdrGetDllDirectory( &str );
934 ok( !status, "LdrGetDllDirectory failed %lx\n", status );
935 ok( cmpStrAW( dll_directories[i], bufferW, strlen(dll_directories[i]),
936 str.Length / sizeof(WCHAR) ), "%u: got %s instead of %s\n",
937 i, wine_dbgstr_w(bufferW), dll_directories[i] );
938 if (dll_directories[i][0])
939 {
940 memset( bufferW, 0xcc, sizeof(bufferW) );
941 str.MaximumLength = (strlen( dll_directories[i] ) - 1) * sizeof(WCHAR);
942 status = pLdrGetDllDirectory( &str );
943 ok( status == STATUS_BUFFER_TOO_SMALL, "%u: LdrGetDllDirectory failed %lx\n", i, status );
944 ok( bufferW[0] == 0 && bufferW[1] == 0xcccc,
945 "%u: buffer %x %x\n", i, bufferW[0], bufferW[1] );
946 length = (strlen( dll_directories[i] ) + 1) * sizeof(WCHAR);
947 ok( str.Length == length, "%u: wrong len %u / %lu\n", i, str.Length, length );
948 }
949 }
950 }
951
952 /* unset whatever we did so following tests won't be affected */
953 pSetDllDirectoryA(NULL);
954}
955
956static void init_pointers(void)
957{
958 HMODULE mod = GetModuleHandleA("kernel32.dll");
959
960#define MAKEFUNC(f) (p##f = (void*)GetProcAddress(mod, #f))
967 MAKEFUNC(K32GetModuleInformation);
968 mod = GetModuleHandleA( "ntdll.dll" );
977 mod = GetModuleHandleA( "kernelbase.dll" );
979#undef MAKEFUNC
980
981 /* before Windows 7 this was not exported in kernel32 */
982 if (!pK32GetModuleInformation)
983 {
984 HMODULE hPsapi = LoadLibraryA("psapi.dll");
985 pK32GetModuleInformation = (void *)GetProcAddress(hPsapi, "GetModuleInformation");
986 }
987}
988
989static void testGetModuleHandleEx(void)
990{
991 static const char longname[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
992 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
993 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
994 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
995 static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0};
996 static const WCHAR nosuchmodW[] = {'n','o','s','u','c','h','m','o','d',0};
997 BOOL ret;
998 DWORD error;
999 HMODULE mod, mod_kernel32;
1000
1001 SetLastError( 0xdeadbeef );
1003 error = GetLastError();
1004 ok( !ret, "unexpected success\n" );
1005 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1006
1007 SetLastError( 0xdeadbeef );
1008 ret = GetModuleHandleExA( 0, "kernel32", NULL );
1009 error = GetLastError();
1010 ok( !ret, "unexpected success\n" );
1011 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1012
1013 SetLastError( 0xdeadbeef );
1014 mod = (HMODULE)0xdeadbeef;
1015 ret = GetModuleHandleExA( 0, "kernel32", &mod );
1016 ok( ret, "unexpected failure %lu\n", GetLastError() );
1017 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
1018 FreeLibrary( mod );
1019
1020 SetLastError( 0xdeadbeef );
1021 mod = (HMODULE)0xdeadbeef;
1022 ret = GetModuleHandleExA( 0, "nosuchmod", &mod );
1023 error = GetLastError();
1024 ok( !ret, "unexpected success\n" );
1025 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1026 ok( mod == NULL, "got %p\n", mod );
1027
1028 SetLastError( 0xdeadbeef );
1029 ret = GetModuleHandleExA( 0, longname, NULL );
1030 error = GetLastError();
1031 ok( !ret, "unexpected success\n" );
1032 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1033
1034 SetLastError( 0xdeadbeef );
1035 mod = (HMODULE)0xdeadbeef;
1036 ret = GetModuleHandleExA( 0, longname, &mod );
1037 error = GetLastError();
1038 ok( !ret, "unexpected success\n" );
1039#ifdef __REACTOS__
1040 ok( error == ERROR_MOD_NOT_FOUND || broken(error == ERROR_FILENAME_EXCED_RANGE) /* WS03 */, "got %lu\n", error );
1041#else
1042 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1043#endif
1044 ok( mod == NULL, "got %p\n", mod );
1045
1046 SetLastError( 0xdeadbeef );
1048 error = GetLastError();
1049 ok( !ret, "unexpected success\n" );
1050 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1051
1052 SetLastError( 0xdeadbeef );
1053 ret = GetModuleHandleExW( 0, kernel32W, NULL );
1054 error = GetLastError();
1055 ok( !ret, "unexpected success\n" );
1056 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1057
1058 SetLastError( 0xdeadbeef );
1059 mod = (HMODULE)0xdeadbeef;
1060 ret = GetModuleHandleExW( 0, kernel32W, &mod );
1061 ok( ret, "unexpected failure %lu\n", GetLastError() );
1062 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
1063 FreeLibrary( mod );
1064
1065 SetLastError( 0xdeadbeef );
1066 mod = (HMODULE)0xdeadbeef;
1067 ret = GetModuleHandleExW( 0, nosuchmodW, &mod );
1068 error = GetLastError();
1069 ok( !ret, "unexpected success\n" );
1070 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1071 ok( mod == NULL, "got %p\n", mod );
1072
1073 SetLastError( 0xdeadbeef );
1074 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL );
1075 error = GetLastError();
1076 ok( !ret, "unexpected success\n" );
1077 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1078
1079 SetLastError( 0xdeadbeef );
1080 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "kernel32", NULL );
1081 error = GetLastError();
1082 ok( !ret, "unexpected success\n" );
1083 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1084
1085 SetLastError( 0xdeadbeef );
1086 mod = (HMODULE)0xdeadbeef;
1087 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "kernel32", &mod );
1088 ok( ret, "unexpected failure %lu\n", GetLastError() );
1089 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
1090
1091 SetLastError( 0xdeadbeef );
1092 mod = (HMODULE)0xdeadbeef;
1093 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "nosuchmod", &mod );
1094 error = GetLastError();
1095 ok( !ret, "unexpected success\n" );
1096 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1097 ok( mod == NULL, "got %p\n", mod );
1098
1099 SetLastError( 0xdeadbeef );
1100 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL );
1101 error = GetLastError();
1102 ok( !ret, "unexpected success\n" );
1103 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1104
1105 SetLastError( 0xdeadbeef );
1106 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, kernel32W, NULL );
1107 error = GetLastError();
1108 ok( !ret, "unexpected success\n" );
1109 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1110
1111 SetLastError( 0xdeadbeef );
1112 mod = (HMODULE)0xdeadbeef;
1113 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, kernel32W, &mod );
1114 ok( ret, "unexpected failure %lu\n", GetLastError() );
1115 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
1116
1117 SetLastError( 0xdeadbeef );
1118 mod = (HMODULE)0xdeadbeef;
1119 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, nosuchmodW, &mod );
1120 error = GetLastError();
1121 ok( !ret, "unexpected success\n" );
1122 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1123 ok( mod == NULL, "got %p\n", mod );
1124
1125 mod_kernel32 = LoadLibraryA( "kernel32" );
1126
1127 SetLastError( 0xdeadbeef );
1128 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, NULL, NULL );
1129 error = GetLastError();
1130 ok( !ret, "unexpected success\n" );
1131 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1132
1133 SetLastError( 0xdeadbeef );
1134 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)mod_kernel32, NULL );
1135 error = GetLastError();
1136 ok( !ret, "unexpected success\n" );
1137 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1138
1139 SetLastError( 0xdeadbeef );
1140 mod = (HMODULE)0xdeadbeef;
1141 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)mod_kernel32, &mod );
1142 ok( ret, "unexpected failure %lu\n", GetLastError() );
1143 ok( mod == mod_kernel32, "got %p\n", mod );
1144 FreeLibrary( mod );
1145
1146 SetLastError( 0xdeadbeef );
1147 mod = (HMODULE)0xdeadbeef;
1148 ret = GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)0xbeefdead, &mod );
1149 error = GetLastError();
1150 ok( !ret, "unexpected success\n" );
1151 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1152 ok( mod == NULL, "got %p\n", mod );
1153
1154 SetLastError( 0xdeadbeef );
1155 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, NULL, NULL );
1156 error = GetLastError();
1157 ok( !ret, "unexpected success\n" );
1158 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1159
1160 SetLastError( 0xdeadbeef );
1161 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)mod_kernel32, NULL );
1162 error = GetLastError();
1163 ok( !ret, "unexpected success\n" );
1164 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1165
1166 SetLastError( 0xdeadbeef );
1167 mod = (HMODULE)0xdeadbeef;
1168 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)mod_kernel32, &mod );
1169 ok( ret, "unexpected failure %lu\n", GetLastError() );
1170 ok( mod == mod_kernel32, "got %p\n", mod );
1171 FreeLibrary( mod );
1172
1173 SetLastError( 0xdeadbeef );
1174 mod = (HMODULE)0xdeadbeef;
1175 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)0xbeefdead, &mod );
1176 error = GetLastError();
1177 ok( !ret, "unexpected success\n" );
1178 ok( error == ERROR_MOD_NOT_FOUND, "got %lu\n", error );
1179 ok( mod == NULL, "got %p\n", mod );
1180
1181 SetLastError( 0xdeadbeef );
1182 mod = (HMODULE)0xdeadbeef;
1183 ret = GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
1184 | GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCWSTR)mod_kernel32, &mod );
1185 error = GetLastError();
1186 ok( !ret, "unexpected success\n" );
1187 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1188 ok( mod == NULL, "got %p\n", mod );
1189
1190 SetLastError( 0xdeadbeef );
1191 mod = (HMODULE)0xdeadbeef;
1192 ret = GetModuleHandleExW( 8, kernel32W, &mod );
1193 error = GetLastError();
1194 ok( !ret, "unexpected success\n" );
1195 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
1196 ok( mod == NULL, "got %p\n", mod );
1197
1198 FreeLibrary( mod_kernel32 );
1199}
1200
1202{
1204 HMODULE mod;
1205 BOOL ret;
1206
1208 memset(&info, 0xAA, sizeof(info));
1209 ret = pK32GetModuleInformation(GetCurrentProcess(), mod, &info, sizeof(info));
1210 ok(ret, "K32GetModuleInformation failed for main module\n");
1211 ok(info.lpBaseOfDll == mod, "Wrong info.lpBaseOfDll = %p, expected %p\n", info.lpBaseOfDll, mod);
1212 ok(info.EntryPoint != NULL, "Expected nonzero entrypoint\n");
1213
1214 mod = GetModuleHandleA("kernel32.dll");
1215 memset(&info, 0xAA, sizeof(info));
1216 ret = pK32GetModuleInformation(GetCurrentProcess(), mod, &info, sizeof(info));
1217 ok(ret, "K32GetModuleInformation failed for kernel32 module\n");
1218 ok(info.lpBaseOfDll == mod, "Wrong info.lpBaseOfDll = %p, expected %p\n", info.lpBaseOfDll, mod);
1219 ok(info.EntryPoint != NULL, "Expected nonzero entrypoint\n");
1220}
1221
1222static void test_AddDllDirectory(void)
1223{
1224 static const WCHAR tmpW[] = {'t','m','p',0};
1225 static const WCHAR dotW[] = {'.','\\','.',0};
1226 static const WCHAR rootW[] = {'\\',0};
1229 BOOL ret;
1230
1231 if (!pAddDllDirectory || !pRemoveDllDirectory)
1232 {
1233 win_skip( "AddDllDirectory not available\n" );
1234 return;
1235 }
1236
1237 buf[0] = '\0';
1239 ret = GetTempFileNameW( path, tmpW, 0, buf );
1240 ok( ret, "GetTempFileName failed err %lu\n", GetLastError() );
1241 SetLastError( 0xdeadbeef );
1242 cookie = pAddDllDirectory( buf );
1243 ok( cookie != NULL, "AddDllDirectory failed err %lu\n", GetLastError() );
1244 SetLastError( 0xdeadbeef );
1245 ret = pRemoveDllDirectory( cookie );
1246 ok( ret, "RemoveDllDirectory failed err %lu\n", GetLastError() );
1247
1248 DeleteFileW( buf );
1249 SetLastError( 0xdeadbeef );
1250 cookie = pAddDllDirectory( buf );
1251 ok( !cookie, "AddDllDirectory succeeded\n" );
1252 ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %lu\n", GetLastError() );
1253 cookie = pAddDllDirectory( dotW );
1254 ok( !cookie, "AddDllDirectory succeeded\n" );
1255 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1256 cookie = pAddDllDirectory( rootW );
1257 ok( cookie != NULL, "AddDllDirectory failed err %lu\n", GetLastError() );
1258 SetLastError( 0xdeadbeef );
1259 ret = pRemoveDllDirectory( cookie );
1260 ok( ret, "RemoveDllDirectory failed err %lu\n", GetLastError() );
1262 lstrcpyW( buf + 2, tmpW );
1263 cookie = pAddDllDirectory( buf );
1264 ok( !cookie, "AddDllDirectory succeeded\n" );
1265 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1266}
1267
1269{
1270 HMODULE mod;
1271 BOOL ret;
1272
1273 if (!pSetDefaultDllDirectories)
1274 {
1275 win_skip( "SetDefaultDllDirectories not available\n" );
1276 return;
1277 }
1278
1279 mod = LoadLibraryA( "authz.dll" );
1280 ok( mod != NULL, "loading authz failed\n" );
1281 FreeLibrary( mod );
1282 ret = pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_USER_DIRS );
1283 ok( ret, "SetDefaultDllDirectories failed err %lu\n", GetLastError() );
1284 mod = LoadLibraryA( "authz.dll" );
1285 ok( !mod, "loading authz succeeded\n" );
1286 FreeLibrary( mod );
1287 ret = pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_SYSTEM32 );
1288 ok( ret, "SetDefaultDllDirectories failed err %lu\n", GetLastError() );
1289 mod = LoadLibraryA( "authz.dll" );
1290 ok( mod != NULL, "loading authz failed\n" );
1291 FreeLibrary( mod );
1293 ok( !mod, "loading authz succeeded\n" );
1294 FreeLibrary( mod );
1295 ret = pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_APPLICATION_DIR );
1296 ok( ret, "SetDefaultDllDirectories failed err %lu\n", GetLastError() );
1297 mod = LoadLibraryA( "authz.dll" );
1298 ok( !mod, "loading authz succeeded\n" );
1299 FreeLibrary( mod );
1300 ret = pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_DEFAULT_DIRS );
1301 ok( ret, "SetDefaultDllDirectories failed err %lu\n", GetLastError() );
1302 mod = LoadLibraryA( "authz.dll" );
1303 ok( mod != NULL, "loading authz failed\n" );
1304 FreeLibrary( mod );
1305
1306 SetLastError( 0xdeadbeef );
1307 ret = pSetDefaultDllDirectories( 0 );
1308 ok( !ret, "SetDefaultDllDirectories succeeded\n" );
1309 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1310
1311 SetLastError( 0xdeadbeef );
1312 ret = pSetDefaultDllDirectories( 3 );
1313 ok( !ret, "SetDefaultDllDirectories succeeded\n" );
1314 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1315
1316 SetLastError( 0xdeadbeef );
1317 ret = pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 0x8000 );
1318 ok( !ret, "SetDefaultDllDirectories succeeded\n" );
1319 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1320
1321 SetLastError( 0xdeadbeef );
1322 ret = pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR );
1323 ok( !ret || broken(ret) /* win7 */, "SetDefaultDllDirectories succeeded\n" );
1324 if (!ret) ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1325
1326 SetLastError( 0xdeadbeef );
1328 ok( !ret || broken(ret) /* win7 */, "SetDefaultDllDirectories succeeded\n" );
1329 if (!ret) ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
1330
1331 /* restore some sane defaults */
1332 pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_DEFAULT_DIRS );
1333}
1334
1335static void check_refcount( HMODULE mod, unsigned int refcount )
1336{
1337 unsigned int i;
1338 BOOL ret;
1339
1340 for (i = 0; i < min( refcount, 10 ); ++i)
1341 {
1342 ret = FreeLibrary( mod );
1343#ifdef __REACTOS__
1344 ok( ret || broken( refcount == ~0u && GetLastError() == ERROR_MOD_NOT_FOUND && (i == 2) ) /* Win8 */ || broken( refcount == 2 && GetLastError() == ERROR_MOD_NOT_FOUND && i == 1 ) /* WS03 */,
1345#else
1346 ok( ret || broken( refcount == ~0u && GetLastError() == ERROR_MOD_NOT_FOUND && i == 2 ) /* Win8 */,
1347#endif
1348 "Refcount test failed, i %u, error %lu.\n", i, GetLastError(), refcount );
1349 if (!ret) return;
1350 }
1351 if (refcount != ~0u)
1352 {
1353 ret = FreeLibrary( mod );
1354 ok( !ret && GetLastError() == ERROR_MOD_NOT_FOUND, "Refcount test failed, ret %d, error %lu.\n",
1355 ret, GetLastError() );
1356 }
1357}
1358
1359static void test_LdrGetDllHandleEx(void)
1360{
1361 HMODULE mod, loaded_mod;
1365 unsigned int i;
1366 BOOL bret;
1367
1368 if (!pLdrGetDllHandleEx)
1369 {
1370 win_skip( "LdrGetDllHandleEx is not available.\n" );
1371 return;
1372 }
1373
1374 RtlInitUnicodeString( &name, L"unknown.dll" );
1375 status = pLdrGetDllHandleEx( 0, NULL, NULL, &name, &mod );
1376 ok( status == STATUS_DLL_NOT_FOUND, "Got unexpected status %#lx.\n", status );
1377
1378 RtlInitUnicodeString( &name, L"authz.dll" );
1379 loaded_mod = LoadLibraryW( name.Buffer );
1380 ok( !!loaded_mod, "Failed to load module.\n" );
1381 status = pLdrGetDllHandleEx( 0, NULL, NULL, &name, &mod );
1382 ok( !status, "Got unexpected status %#lx.\n", status );
1383 ok( mod == loaded_mod, "got %p\n", mod );
1384 winetest_push_context( "Flags 0" );
1385 check_refcount( loaded_mod, 2 );
1387
1388 loaded_mod = LoadLibraryW( name.Buffer );
1389 ok( !!loaded_mod, "Failed to load module.\n" );
1391 NULL, &name, &mod );
1392 ok( !status, "Got unexpected status %#lx.\n", status );
1393 ok( mod == loaded_mod, "got %p\n", mod );
1394 winetest_push_context( "LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT" );
1395 check_refcount( loaded_mod, 1 );
1397
1398 loaded_mod = LoadLibraryW( name.Buffer );
1399 ok( !!loaded_mod, "Failed to load module.\n" );
1400 status = pLdrGetDllHandle( NULL, ~0u, &name, &mod );
1401 ok( !status, "Got unexpected status %#lx.\n", status );
1402 ok( mod == loaded_mod, "got %p\n", mod );
1403 winetest_push_context( "LdrGetDllHandle" );
1404 check_refcount( loaded_mod, 1 );
1406
1407 loaded_mod = LoadLibraryW( name.Buffer );
1408 ok( !!loaded_mod, "Failed to load module.\n" );
1409 status = pLdrGetDllHandleEx( 4, NULL, NULL, (void *)&name, &mod );
1410#ifdef __REACTOS__
1411 ok( !status || broken(status == STATUS_INVALID_PARAMETER) /* WS03 */, "Got unexpected status %#lx.\n", status );
1412 ok( mod == loaded_mod || broken(mod == NULL) /* WS03 */, "got %p\n", mod );
1413#else
1414 ok( !status, "Got unexpected status %#lx.\n", status );
1415 ok( mod == loaded_mod, "got %p\n", mod );
1416#endif
1417 winetest_push_context( "Flag 4" );
1418 check_refcount( loaded_mod, 2 );
1420
1421 for (i = 3; i < 32; ++i)
1422 {
1423 loaded_mod = LoadLibraryW( name.Buffer );
1424 ok( !!loaded_mod, "Failed to load module.\n" );
1425 status = pLdrGetDllHandleEx( 1 << i, NULL, NULL, &name, &mod );
1426 ok( status == STATUS_INVALID_PARAMETER, "Got unexpected status %#lx.\n", status );
1427 winetest_push_context( "Invalid flags, i %u", i );
1428 check_refcount( loaded_mod, 1 );
1430 }
1431
1433 NULL, NULL, &name, &mod );
1434 ok( status == STATUS_INVALID_PARAMETER, "Got unexpected status %#lx.\n", status );
1435
1436 loaded_mod = LoadLibraryW( name.Buffer );
1437 ok( !!loaded_mod, "Failed to load module.\n" );
1438 status = pLdrGetDllHandleEx( LDR_GET_DLL_HANDLE_EX_FLAG_PIN, NULL,
1439 NULL, &name, &mod );
1440 ok( !status, "Got unexpected status %#lx.\n", status );
1441 ok( mod == loaded_mod, "got %p\n", mod );
1442 winetest_push_context( "LDR_GET_DLL_HANDLE_EX_FLAG_PIN" );
1443 check_refcount( loaded_mod, ~0u );
1445
1447 if (pAddDllDirectory) pAddDllDirectory( path );
1448 create_test_dll( "d01.dll" );
1449 mod = LoadLibraryA( "d01.dll" );
1450 ok( !!mod, "got error %lu.\n", GetLastError() );
1451 RtlInitUnicodeString( &name, L"d01.dll" );
1452 status = pLdrGetDllHandleEx( LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL, &name, &loaded_mod );
1453 ok( !status, "got %#lx.\n", status );
1454
1455 RtlInitUnicodeString( &name, L"d02.dll" );
1456 status = pLdrGetDllHandleEx( LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL, &name, &loaded_mod );
1457 ok( status == STATUS_DLL_NOT_FOUND, "got %#lx.\n", status );
1458
1459 /* Same (moved) file, different name: not found in loaded modules with short name but found with path. */
1460 DeleteFileA( "d02.dll" );
1461 bret = MoveFileA( "d01.dll", "d02.dll" );
1462 ok( bret, "got error %lu.\n", GetLastError() );
1463 status = pLdrGetDllHandleEx( LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL, &name, &loaded_mod );
1464 ok( status == STATUS_DLL_NOT_FOUND, "got %#lx.\n", status );
1465 CreateDirectoryA( "testdir", NULL );
1466 DeleteFileA( "testdir\\d02.dll" );
1467 bret = MoveFileA( "d02.dll", "testdir\\d02.dll" );
1468 ok( bret, "got error %lu.\n", GetLastError() );
1469 RtlInitUnicodeString( &name, L"testdir\\d02.dll" );
1470 status = pLdrGetDllHandleEx( LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL, &name, &loaded_mod );
1471 ok( !status, "got %#lx.\n", status );
1472 ok( loaded_mod == mod, "got %p, %p.\n", loaded_mod, mod );
1473 FreeLibrary( mod );
1474 status = pLdrGetDllHandleEx( LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL, &name, &loaded_mod );
1475 ok( status == STATUS_DLL_NOT_FOUND, "got %#lx.\n", status );
1476
1477 DeleteFileA( "testdir\\d02.dll" );
1478 RemoveDirectoryA( "testdir" );
1479}
1480
1481static void test_LdrGetDllFullName(void)
1482{
1483 WCHAR expected_path[MAX_PATH], path_buffer[MAX_PATH];
1484 UNICODE_STRING path = {0, 0, path_buffer};
1485 WCHAR expected_terminator;
1487 HMODULE ntdll;
1488
1489 if (!pLdrGetDllFullName)
1490 {
1491 win_skip( "LdrGetDllFullName not available.\n" );
1492 return;
1493 }
1494
1495 if (0) /* crashes on Windows */
1496 pLdrGetDllFullName( ntdll, NULL );
1497
1498 ntdll = GetModuleHandleW( L"ntdll.dll" );
1499
1500 memset( path_buffer, 0x23, sizeof(path_buffer) );
1501
1502 status = pLdrGetDllFullName( ntdll, &path );
1503 ok( status == STATUS_BUFFER_TOO_SMALL, "Got unexpected status %#lx.\n", status );
1504 ok( path.Length == 0, "Expected length 0, got %d.\n", path.Length );
1505 ok( path_buffer[0] == 0x2323, "Expected 0x2323, got 0x%x.\n", path_buffer[0] );
1506
1507 GetSystemDirectoryW( expected_path, ARRAY_SIZE(expected_path) );
1508 path.MaximumLength = 5; /* odd numbers produce partially copied characters */
1509
1510 status = pLdrGetDllFullName( ntdll, &path );
1511 ok( status == STATUS_BUFFER_TOO_SMALL, "Got unexpected status %#lx.\n", status );
1512 ok( path.Length == path.MaximumLength, "Expected length %u, got %u.\n", path.MaximumLength, path.Length );
1513 expected_terminator = 0x2300 | (expected_path[path.MaximumLength / sizeof(WCHAR)] & 0xFF);
1514 ok( path_buffer[path.MaximumLength / sizeof(WCHAR)] == expected_terminator,
1515 "Expected 0x%x, got 0x%x.\n", expected_terminator, path_buffer[path.MaximumLength / 2] );
1516 path_buffer[path.MaximumLength / sizeof(WCHAR)] = 0;
1517 expected_path[path.MaximumLength / sizeof(WCHAR)] = 0;
1518 ok( lstrcmpW(path_buffer, expected_path) == 0, "Expected %s, got %s.\n",
1519 wine_dbgstr_w(expected_path), wine_dbgstr_w(path_buffer) );
1520
1521 GetSystemDirectoryW( expected_path, ARRAY_SIZE(expected_path) );
1522 lstrcatW( expected_path, L"\\ntdll.dll" );
1523 path.MaximumLength = sizeof(path_buffer);
1524
1525 status = pLdrGetDllFullName( ntdll, &path );
1526 ok( status == STATUS_SUCCESS, "Got unexpected status %#lx.\n", status );
1527 ok( !lstrcmpiW(path_buffer, expected_path), "Expected %s, got %s\n",
1528 wine_dbgstr_w(expected_path), wine_dbgstr_w(path_buffer) );
1529
1530 status = pLdrGetDllFullName( NULL, &path );
1531 ok( status == STATUS_SUCCESS, "Got unexpected status %#lx.\n", status );
1532 GetModuleFileNameW( NULL, expected_path, ARRAY_SIZE(expected_path) );
1533 ok( !lstrcmpiW(path_buffer, expected_path), "Expected %s, got %s.\n",
1534 wine_dbgstr_w(expected_path), wine_dbgstr_w(path_buffer) );
1535}
1536
1537static void test_apisets(void)
1538{
1539 static const struct
1540 {
1541 const char *name;
1542 BOOLEAN present;
1544 BOOLEAN present_ex, in_schema, broken;
1545 }
1546 tests[] =
1547 {
1548 { "api-ms-win-core-console-l1-1-0", TRUE, STATUS_SUCCESS, TRUE, TRUE },
1549 { "api-ms-win-core-console-l1-1-0.dll", TRUE, STATUS_INVALID_PARAMETER },
1550 { "api-ms-win-core-console-l1-1-9", TRUE, STATUS_SUCCESS, FALSE, FALSE, TRUE },
1551 { "api-ms-win-core-console-l1-1-9.dll", TRUE, STATUS_INVALID_PARAMETER, FALSE, FALSE, TRUE },
1552 { "api-ms-win-core-console-l1-1", FALSE, STATUS_SUCCESS },
1553 { "api-ms-win-core-console-l1-1-0.fake", TRUE, STATUS_INVALID_PARAMETER, FALSE, FALSE, TRUE },
1554 { "api-ms-win-foo-bar-l1-1-0", FALSE, STATUS_SUCCESS },
1555 { "api-ms-win-foo-bar-l1-1-0.dll", FALSE, STATUS_INVALID_PARAMETER },
1556 { "ext-ms-win-gdi-draw-l1-1-1", TRUE, STATUS_SUCCESS, TRUE, TRUE },
1557 { "ext-ms-win-gdi-draw-l1-1-1.dll", TRUE, STATUS_INVALID_PARAMETER },
1558 { "api-ms-win-deprecated-apis-advapi-l1-1-0", FALSE, STATUS_SUCCESS, FALSE, TRUE },
1559 { "foo", FALSE, STATUS_INVALID_PARAMETER },
1560 { "foo.dll", FALSE, STATUS_INVALID_PARAMETER },
1562 };
1563 unsigned int i;
1565 BOOLEAN present, in_schema;
1567
1568 if (!pApiSetQueryApiSetPresence)
1569 {
1570 win_skip( "ApiSetQueryApiSetPresence not implemented\n" );
1571 return;
1572 }
1573 if (!pApiSetQueryApiSetPresenceEx) win_skip( "ApiSetQueryApiSetPresenceEx not implemented\n" );
1574 if (!pIsApiSetImplemented) win_skip( "IsApiSetImplemented not implemented\n" );
1575
1576 for (i = 0; i < ARRAY_SIZE(tests); i++)
1577 {
1579 name.Buffer[name.Length / sizeof(WCHAR)] = 0xcccc; /* test without null termination */
1580 winetest_push_context( "%u:%s", i, tests[i].name );
1581 present = 0xff;
1582 status = pApiSetQueryApiSetPresence( &name, &present );
1583 ok( status == STATUS_SUCCESS, "wrong ret %lx\n", status );
1584 ok( present == tests[i].present || broken(!present && tests[i].broken) /* win8 */,
1585 "wrong present %u\n", present );
1586 if (pApiSetQueryApiSetPresenceEx)
1587 {
1588 present = in_schema = 0xff;
1589 status = pApiSetQueryApiSetPresenceEx( &name, &in_schema, &present );
1590 ok( status == tests[i].status, "wrong ret %lx\n", status );
1591 if (!status)
1592 {
1593 ok( in_schema == tests[i].in_schema, "wrong in_schema %u\n", in_schema );
1594 ok( present == tests[i].present_ex, "wrong present %u\n", present );
1595 }
1596 else
1597 {
1598 ok( in_schema == 0xff, "wrong in_schema %u\n", in_schema );
1599 ok( present == 0xff, "wrong present %u\n", present );
1600 }
1601 }
1602 if (pIsApiSetImplemented)
1603 {
1604 BOOL ret = pIsApiSetImplemented( tests[i].name );
1605 ok( ret == (!tests[i].status && tests[i].present_ex), "wrong result %u\n", ret );
1606 }
1609 }
1610}
1611
1612static void test_ddag_node(void)
1613{
1614#if defined(__REACTOS__) && defined(_MSC_VER)
1615 struct dll_dependency {
1616 const WCHAR *dllname;
1617 BOOL optional;
1618 };
1619
1620 static struct dll_dependency expected_exe_dependencies_Old[] = {
1621 { L"advapi32.dll" },
1622 { L"msvcrt.dll", TRUE },
1623 { L"user32.dll", TRUE },
1624 };
1625
1626 static struct dll_dependency expected_exe_dependencies_Win8[] = {
1627 { L"user32.dll" },
1628 { L"advapi32.dll", TRUE },
1629 { L"msvcrt.dll", TRUE },
1630 };
1631
1632 static struct dll_dependency* expected_exe_dependencies;
1633 static int expected_exe_dependencies_size;
1634#else
1635 static const struct
1636 {
1637 const WCHAR *dllname;
1638 BOOL optional;
1639 }
1640 expected_exe_dependencies[] =
1641 {
1642 { L"advapi32.dll" },
1643 { L"msvcrt.dll", TRUE },
1644 { L"user32.dll", TRUE },
1645 };
1646#endif
1647 LDR_DDAG_NODE *node, *dep_node, *prev_node;
1649 SINGLE_LIST_ENTRY *se, *se2;
1650 LDR_DEPENDENCY *dep, *dep2;
1652 unsigned int i;
1653 HMODULE hexe;
1654
1655#ifdef __REACTOS__
1657 skip("test_ddag_node() crashes on WS03.\n");
1658 return;
1659 }
1660#endif
1661 hexe = GetModuleHandleW( NULL );
1662 ok( !!hexe, "Got NULL exe handle.\n" );
1663
1664 status = LdrFindEntryForAddress( hexe, &mod );
1665 ok( !status, "Got unexpected status %#lx.\n", status );
1666
1667 if (!(node = mod->DdagNode))
1668 {
1669 win_skip( "DdagNode is NULL, skipping tests.\n" );
1670 return;
1671 }
1672
1673 ok( !!node->Modules.Flink, "Got NULL module link.\n" );
1674 mod2 = CONTAINING_RECORD(node->Modules.Flink, LDR_DATA_TABLE_ENTRY, NodeModuleLink);
1675 ok( mod2 == mod || broken( (void **)mod2 == (void **)mod - 1 ), "Got unexpected mod2 %p, expected %p.\n",
1676 mod2, mod );
1677 if (mod2 != mod)
1678 {
1679 win_skip( "Old LDR_DATA_TABLE_ENTRY structure, skipping tests.\n" );
1680 return;
1681 }
1682 ok( node->Modules.Flink->Flink == &node->Modules, "Expected one element in list.\n" );
1683
1684 ok( !node->IncomingDependencies.Tail, "Expected empty incoming dependencies list.\n" );
1685
1686 /* node->Dependencies.Tail is NULL on Windows 10 1507-1607 32 bit test, maybe due to broken structure layout. */
1687 ok( !!node->Dependencies.Tail || broken( sizeof(void *) == 4 && !node->Dependencies.Tail ),
1688 "Expected nonempty dependencies list.\n" );
1689 if (!node->Dependencies.Tail)
1690 {
1691 win_skip( "Empty dependencies list.\n" );
1692 return;
1693 }
1694 todo_wine ok( node->LoadCount == -1, "Got unexpected LoadCount %ld.\n", node->LoadCount );
1695
1696 prev_node = NULL;
1697 se = node->Dependencies.Tail;
1698#if defined(__REACTOS__) && defined(_MSC_VER)
1700 expected_exe_dependencies = expected_exe_dependencies_Win8;
1701 expected_exe_dependencies_size = ARRAY_SIZE(expected_exe_dependencies_Win8);
1702 } else {
1703 expected_exe_dependencies = expected_exe_dependencies_Old;
1704 expected_exe_dependencies_size = ARRAY_SIZE(expected_exe_dependencies_Old);
1705 }
1706 for (i = 0; i < expected_exe_dependencies_size; ++i)
1707#else
1708 for (i = 0; i < ARRAY_SIZE(expected_exe_dependencies); ++i)
1709#endif
1710 {
1711 winetest_push_context( "Dep %u (%s)", i, debugstr_w(expected_exe_dependencies[i].dllname) );
1712
1713 se = se->Next;
1714
1715 ok( !!se, "Got NULL list element.\n" );
1716 dep = CONTAINING_RECORD(se, LDR_DEPENDENCY, dependency_to_entry);
1717 ok( dep->dependency_from == node, "Got unexpected dependency_from %p.\n", dep->dependency_from );
1718 ok( !!dep->dependency_to, "Got null dependency_to.\n" );
1719 dep_node = dep->dependency_to;
1720 ok( !!dep_node, "Got NULL dep_node.\n" );
1721
1722 if (dep_node == prev_node && expected_exe_dependencies[i].optional)
1723 {
1724 win_skip( "Module is not directly referenced.\n" );
1726 prev_node = dep_node;
1727 continue;
1728 }
1729
1730 mod2 = CONTAINING_RECORD(dep_node->Modules.Flink, LDR_DATA_TABLE_ENTRY, NodeModuleLink);
1731 ok( !lstrcmpW( mod2->BaseDllName.Buffer, expected_exe_dependencies[i].dllname ),
1732 "Got unexpected module %s.\n", debugstr_w(mod2->BaseDllName.Buffer));
1733
1734 se2 = dep_node->IncomingDependencies.Tail;
1735 ok( !!se2, "Got empty incoming dependencies list.\n" );
1736 do
1737 {
1738 se2 = se2->Next;
1739 dep2 = CONTAINING_RECORD(se2, LDR_DEPENDENCY, dependency_from_entry);
1740 }
1741 while (dep2 != dep && se2 != dep_node->IncomingDependencies.Tail);
1742 ok( dep2 == dep, "Dependency not found in incoming deps list.\n" );
1743
1744 todo_wine ok( dep_node->LoadCount > 0 || broken(!dep_node->LoadCount) /* Win8 */,
1745 "Got unexpected LoadCount %ld.\n", dep_node->LoadCount );
1746
1748 prev_node = dep_node;
1749 }
1750 ok( se == node->Dependencies.Tail, "Expected end of the list.\n" );
1751}
1752
1754
1755static DWORD WINAPI test_tls_links_thread(void* tlsidx_v)
1756{
1759 return 0;
1760}
1761
1762static void test_tls_links(void)
1763{
1764 TEB *teb = NtCurrentTeb(), *thread_teb;
1767 HANDLE thread;
1768
1769 ok(!!teb->ThreadLocalStoragePointer, "got NULL.\n");
1770
1773
1775 do
1776 {
1777 /* workaround currently present Wine bug when thread teb may be not available immediately
1778 * after creating a thread before it is initialized on the Unix side. */
1779 Sleep(1);
1781 ok(!status, "got %#lx.\n", status );
1782 } while (!(thread_teb = tbi.TebBaseAddress));
1783 ok(!thread_teb->ThreadLocalStoragePointer, "got %p.\n", thread_teb->ThreadLocalStoragePointer);
1786
1787 ok(!!thread_teb->ThreadLocalStoragePointer, "got NULL.\n");
1788 ok(!teb->TlsLinks.Flink, "got %p.\n", teb->TlsLinks.Flink);
1789 ok(!teb->TlsLinks.Blink, "got %p.\n", teb->TlsLinks.Blink);
1790 ok(!thread_teb->TlsLinks.Flink, "got %p.\n", thread_teb->TlsLinks.Flink);
1791 ok(!thread_teb->TlsLinks.Blink, "got %p.\n", thread_teb->TlsLinks.Blink);
1794
1798}
1799
1800
1802{
1804}
1805
1807{
1809 unsigned int count;
1810 char *base;
1811
1812 if (!node) return 0;
1813 ok( (node->ParentValue & RTL_BALANCED_NODE_RESERVED_PARENT_MASK) <= 1, "got ParentValue %#Ix.\n",
1814 node->ParentValue );
1815
1816 mod = CONTAINING_RECORD(node, LDR_DATA_TABLE_ENTRY, BaseAddressIndexNode);
1817 base = mod->DllBase;
1818 if (node->Left)
1819 {
1820 mod = CONTAINING_RECORD(node->Left, LDR_DATA_TABLE_ENTRY, BaseAddressIndexNode);
1821 ok( (char *)mod->DllBase < base, "wrong ordering.\n" );
1822 }
1823 if (node->Right)
1824 {
1825 mod = CONTAINING_RECORD(node->Right, LDR_DATA_TABLE_ENTRY, BaseAddressIndexNode);
1826 ok( (char *)mod->DllBase > base, "wrong ordering.\n" );
1827 }
1828
1830 count += check_address_index_tree( node->Right );
1831 return count + 1;
1832}
1833
1835{
1836 LIST_ENTRY *first = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
1837 unsigned int tree_count, list_count = 0;
1840 char *base;
1841
1842 if (is_old_loader_struct()) return;
1843
1844 mod = CONTAINING_RECORD(first->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
1845 ok( mod->BaseAddressIndexNode.ParentValue || mod->BaseAddressIndexNode.Left || mod->BaseAddressIndexNode.Right,
1846 "got zero BaseAddressIndexNode.\n" );
1847 root = &mod->BaseAddressIndexNode;
1848 while (rtl_node_parent( root ))
1850 tree_count = check_address_index_tree( root );
1851 for (LIST_ENTRY *entry = first->Flink; entry != first; entry = entry->Flink)
1852 {
1853 ++list_count;
1854 mod = CONTAINING_RECORD(entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
1855 base = mod->DllBase;
1856 node = root;
1857 mod2 = NULL;
1858 while (1)
1859 {
1860 ok( !!node, "got NULL.\n" );
1861 if (!node) break;
1862 mod2 = CONTAINING_RECORD(node, LDR_DATA_TABLE_ENTRY, BaseAddressIndexNode);
1863 if (base == (char *)mod2->DllBase) break;
1864 if (base < (char *)mod2->DllBase) node = node->Left;
1865 else node = node->Right;
1866 }
1867 ok( base == (char *)mod2->DllBase, "module %s not found.\n", debugstr_w(mod->BaseDllName.Buffer) );
1868 }
1869 ok( tree_count == list_count, "count mismatch %u, %u.\n", tree_count, list_count );
1870}
1871
1873{
1875 ULONG hash;
1876
1877 status = pRtlHashUnicodeString( basename, TRUE, HASH_STRING_ALGORITHM_DEFAULT, &hash );
1878 ok( !status, "got %#lx.\n", status );
1879 return hash & 31;
1880}
1881
1882static void test_hash_links(void)
1883{
1884 LIST_ENTRY *hash_map, *entry, *entry2, *mark, *root;
1886 const WCHAR *modname;
1887 BOOL found;
1888
1889 /* Hash links structure is the same on older Windows loader but hashing algorithm is different. */
1890 if (is_old_loader_struct()) return;
1891
1892 root = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
1893 module = CONTAINING_RECORD(root->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
1894 hash_map = module->HashLinks.Blink - hash_basename( &module->BaseDllName );
1895
1896 for (entry = root->Flink; entry != root; entry = entry->Flink)
1897 {
1898 module = CONTAINING_RECORD(entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
1899 modname = module->BaseDllName.Buffer;
1900 mark = &hash_map[hash_basename( &module->BaseDllName )];
1901 found = FALSE;
1902 for (entry2 = mark->Flink; entry2 != mark; entry2 = entry2->Flink)
1903 {
1904 module = CONTAINING_RECORD(entry2, LDR_DATA_TABLE_ENTRY, HashLinks);
1905 if ((found = !lstrcmpiW( module->BaseDllName.Buffer, modname ))) break;
1906 }
1907 ok( found, "Could not find %s.\n", debugstr_w(modname) );
1908 }
1909}
1910
1912{
1914
1915 /* Test if we can use GetModuleFileNameW */
1916
1917 SetLastError(0xdeadbeef);
1920 {
1921 win_skip("GetModuleFileNameW not existing on this platform, skipping W-calls\n");
1923 }
1924
1925 init_pointers();
1926
1928 testGetModuleFileName("kernel32.dll");
1930
1932
1945 test_apisets();
1950}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
unsigned char BOOLEAN
@ optional
Definition: SystemMenu.c:34
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define GetNTVersion()
Definition: apitest.h:17
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAY_SIZE(A)
Definition: main.h:20
static HANDLE thread
Definition: service.c:33
struct _root root
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define mod2(n)
Definition: vgavideo.h:71
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NTSTATUS
Definition: precomp.h:19
static const WCHAR rootW[]
Definition: chain.c:69
#define CloseHandle
Definition: compat.h:739
#define IMAGE_FILE_MACHINE_ARMNT
Definition: compat.h:127
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define FILE_BEGIN
Definition: compat.h:761
#define ERROR_MOD_NOT_FOUND
Definition: compat.h:104
int(* FARPROC)()
Definition: compat.h:36
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define CP_ACP
Definition: compat.h:109
#define SetFilePointer
Definition: compat.h:743
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
@ ThreadBasicInformation
Definition: compat.h:935
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FreeLibrary(x)
Definition: compat.h:748
#define GetCurrentProcess()
Definition: compat.h:759
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define IMAGE_FILE_MACHINE_ARM64
Definition: compat.h:129
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define lstrcpyW
Definition: compat.h:749
#define MultiByteToWideChar
Definition: compat.h:110
#define LoadLibraryW(x)
Definition: compat.h:747
#define FILE_SHARE_READ
Definition: compat.h:136
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
BOOL WINAPI MoveFileA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName)
Definition: move.c:1137
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:159
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
BOOL WINAPI GetModuleHandleExW(IN DWORD dwFlags, IN LPCWSTR lpwModuleName OPTIONAL, OUT HMODULE *phModule)
Definition: loader.c:866
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
BOOL WINAPI GetModuleHandleExA(IN DWORD dwFlags, IN LPCSTR lpModuleName OPTIONAL, OUT HMODULE *phModule)
Definition: loader.c:896
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
DWORD WINAPI GetDllDirectoryW(IN DWORD nBufferLength, OUT LPWSTR lpBuffer)
Definition: path.c:887
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
BOOL WINAPI SetDllDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:838
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2337
DWORD WINAPI GetDllDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:915
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2206
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:567
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4265
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4227
BOOL WINAPI DECLSPEC_HOTPATCH AreFileApisANSI(void)
Definition: file.c:483
DLL_DIRECTORY_COOKIE WINAPI DECLSPEC_HOTPATCH AddDllDirectory(const WCHAR *dir)
Definition: loader.c:188
BOOL WINAPI DECLSPEC_HOTPATCH SetDefaultDllDirectories(DWORD flags)
Definition: loader.c:602
BOOL WINAPI IsApiSetImplemented(LPCSTR name)
Definition: loader.c:499
BOOL WINAPI DECLSPEC_HOTPATCH RemoveDllDirectory(DLL_DIRECTORY_COOKIE cookie)
Definition: loader.c:593
static void basename(LPCWSTR path, LPWSTR name)
Definition: profile.c:38
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
#define ULONG_PTR
Definition: config.h:101
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _IMAGE_DOS_HEADER IMAGE_DOS_HEADER
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
const GLint * first
Definition: glext.h:5794
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
NTSYSAPI NTSTATUS WINAPI ApiSetQueryApiSetPresenceEx(const UNICODE_STRING *, BOOLEAN *, BOOLEAN *)
NTSYSAPI NTSTATUS WINAPI ApiSetQueryApiSetPresence(const UNICODE_STRING *, BOOLEAN *)
#define LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
Definition: winternl.h:4028
#define LDR_GET_DLL_HANDLE_EX_FLAG_PIN
Definition: winternl.h:4029
NTSYSAPI NTSTATUS WINAPI LdrSetDllDirectory(const UNICODE_STRING *)
NTSYSAPI NTSTATUS WINAPI LdrGetDllFullName(HMODULE, UNICODE_STRING *)
NTSYSAPI NTSTATUS WINAPI LdrGetDllDirectory(UNICODE_STRING *)
#define HASH_STRING_ALGORITHM_DEFAULT
Definition: winternl.h:4518
#define NtCurrentTeb
uint32_t entry
Definition: isohybrid.c:63
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
#define wine_dbgstr_w
Definition: kernel32.h:34
NTSTATUS NTAPI LdrGetDllHandle(_In_opt_ PWSTR DllPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *DllHandle)
Definition: ldrapi.c:770
NTSTATUS NTAPI LdrGetDllHandleEx(_In_ ULONG Flags, _In_opt_ PWSTR DllPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_opt_ PVOID *DllHandle)
Definition: ldrapi.c:505
NTSTATUS NTAPI LdrFindEntryForAddress(_In_ PVOID Address, _Out_ PLDR_DATA_TABLE_ENTRY *Module)
Definition: ldrapi.c:425
void * DLL_DIRECTORY_COOKIE
Definition: libloaderapi.h:26
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
#define win_skip
Definition: minitest.h:67
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
#define todo_wine
Definition: minitest.h:80
#define error(str)
Definition: mkdosfs.c:1605
#define CREATE_ALWAYS
Definition: disk.h:72
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static struct test_info tests[]
#define sprintf
Definition: sprintf.c:45
static const WCHAR filenameW[]
Definition: amstream.c:41
UINT test_count
Definition: shader.c:5671
static HMODULE hPsapi
Definition: integrity.c:31
static HMODULE ntdll
Definition: debugger.c:59
static HANDLE test_tls_links_done
Definition: module.c:1753
IMAGE_SECTION_HEADER section
Definition: module.c:69
static void test_LdrGetDllFullName(void)
Definition: module.c:1481
static ULONG *static BOOL is_unicode_enabled
Definition: module.c:53
static BOOL cmpStrAW(const char *a, const WCHAR *b, DWORD lenA, DWORD lenB)
Definition: module.c:55
static void test_tls_links(void)
Definition: module.c:1762
static LPSTR
Definition: module.c:31
static void testGetModuleHandleEx(void)
Definition: module.c:989
static void testLoadLibraryA(void)
Definition: module.c:257
static BOOL is_old_loader_struct(void)
Definition: module.c:146
static void test_hash_links(void)
Definition: module.c:1882
static ULONG hash_basename(const UNICODE_STRING *basename)
Definition: module.c:1872
static void create_test_dll(const char *name)
Definition: module.c:134
static void test_LoadLibraryEx_search_flags(void)
Definition: module.c:505
static void testGetDllDirectory(void)
Definition: module.c:832
#define MAKEFUNC(f)
static void testGetModuleFileName_Wrong(void)
Definition: module.c:238
static LPCWSTR ULONG * dll_characteristics
Definition: module.c:45
static void testGetProcAddress_Wrong(void)
Definition: module.c:345
static void test_ddag_node(void)
Definition: module.c:1612
static void check_refcount(HMODULE mod, unsigned int refcount)
Definition: module.c:1335
static LPWSTR
Definition: module.c:32
static ULONG
Definition: module.c:51
static void test_AddDllDirectory(void)
Definition: module.c:1222
static RTL_BALANCED_NODE * rtl_node_parent(RTL_BALANCED_NODE *node)
Definition: module.c:1801
static void testGetModuleFileName(const char *name)
Definition: module.c:178
static HMODULE MODULEINFO DWORD cb
Definition: module.c:38
IMAGE_NT_HEADERS nt
Definition: module.c:68
IMAGE_DOS_HEADER dos
Definition: module.c:67
static LPCWSTR load_path
Definition: module.c:45
static ULONG flags
Definition: module.c:44
static void test_base_address_index_tree(void)
Definition: module.c:1834
static void init_pointers(void)
Definition: module.c:956
static DWORD WINAPI test_tls_links_thread(void *tlsidx_v)
Definition: module.c:1755
static void testLoadLibraryA_Wrong(void)
Definition: module.c:331
static void testLoadLibraryEx(void)
Definition: module.c:360
static ULONG const UNICODE_STRING HMODULE * base
Definition: module.c:44
static const struct @1821 dll_image
static HANDLE test_tls_links_started
Definition: module.c:1753
static void test_SetDefaultDllDirectories(void)
Definition: module.c:1268
static void test_apisets(void)
Definition: module.c:1537
static void testNestedLoadLibraryA(void)
Definition: module.c:280
static BOOLEAN
Definition: module.c:51
static unsigned int check_address_index_tree(RTL_BALANCED_NODE *node)
Definition: module.c:1806
static void test_LdrGetDllHandleEx(void)
Definition: module.c:1359
static void testK32GetModuleInformation(void)
Definition: module.c:1201
static HMODULE MODULEINFO * modinfo
Definition: module.c:38
static const WCHAR dotW[]
Definition: directory.c:80
static HMODULE hmodule
Definition: rasapi.c:29
static const WCHAR path1[]
Definition: path.c:28
static const WCHAR path2[]
Definition: path.c:29
#define min(a, b)
Definition: monoChain.cc:55
int k
Definition: mpi.c:3369
static CookieInternal * cookies
Definition: msctf.cpp:37
NTSYSAPI NTSTATUS NTAPI RtlHashUnicodeString(_In_ CONST UNICODE_STRING *String, _In_ BOOLEAN CaseInSensitive, _In_ ULONG HashAlgorithm, _Out_ PULONG HashValue)
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
HMODULE hModule
Definition: netsh.c:17
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define BOOL
Definition: nt_native.h:43
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define DWORD
Definition: nt_native.h:44
#define GENERIC_WRITE
Definition: nt_native.h:90
#define RTL_BALANCED_NODE_RESERVED_PARENT_MASK
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT
Definition: ntimage.h:457
#define IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: ntimage.h:231
#define IMAGE_FILE_MACHINE_AMD64
Definition: ntimage.h:17
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240
#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
Definition: ntimage.h:455
#define IMAGE_NT_OPTIONAL_HDR_MAGIC
Definition: ntimage.h:387
NTSTATUS NTAPI NtQueryInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _Out_writes_bytes_to_opt_(ThreadInformationLength, *ReturnLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:2881
#define STATUS_DLL_NOT_FOUND
Definition: ntstatus.h:639
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
struct _IMAGE_OPTIONAL_HEADER IMAGE_OPTIONAL_HEADER
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_FILE_DLL
Definition: pedump.c:169
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
const WCHAR * str
strcat
Definition: string.h:92
strcpy
Definition: string.h:131
__WINE_SERVER_LIST_INLINE unsigned int list_count(const struct list *list)
Definition: list.h:155
#define memset(x, y, z)
Definition: compat.h:39
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
SINGLE_LIST_ENTRY * Tail
Definition: winternl.h:3897
Definition: btrfs_drv.h:1876
LIST_ENTRY Modules
Definition: winternl.h:3929
LDRP_CSLIST IncomingDependencies
Definition: winternl.h:3935
struct _LDR_DDAG_NODE * dependency_from
Definition: winternl.h:3905
struct _LDR_DDAG_NODE * dependency_to
Definition: winternl.h:3903
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: ntbasedef.h:640
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:641
Definition: compat.h:836
LIST_ENTRY TlsLinks
Definition: compat.h:880
PVOID ThreadLocalStoragePointer
Definition: compat.h:841
Definition: cookie.c:34
Definition: _hash_fun.h:40
Definition: name.c:39
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
uint32_t ULONG_PTR
Definition: typedefs.h:65
HANDLE HMODULE
Definition: typedefs.h:77
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: dlist.c:348
#define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
Definition: winbase.h:346
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
Definition: winbase.h:350
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:338
#define LOAD_LIBRARY_SEARCH_SYSTEM32
Definition: winbase.h:349
#define LOAD_WITH_ALTERED_SEARCH_PATH
Definition: winbase.h:340
#define CREATE_SUSPENDED
Definition: winbase.h:182
#define LOAD_LIBRARY_SEARCH_USER_DIRS
Definition: winbase.h:348
#define LOAD_LIBRARY_SEARCH_APPLICATION_DIR
Definition: winbase.h:347
#define WINAPI
Definition: msvc.h:6
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:257
#define ERROR_BAD_EXE_FORMAT
Definition: winerror.h:373
#define ERROR_FILE_INVALID
Definition: winerror.h:909
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:385
#define ERROR_PROC_NOT_FOUND
Definition: winerror.h:321
#define CP_OEMCP
Definition: winnls.h:249
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175