dsound: Tune some parameters for alsa waveout.
[wine] / dlls / kernel32 / tests / loader.c
1 /*
2  * Unit test suite for the PE loader.
3  *
4  * Copyright 2006 Dmitry Timoshkov
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 <stdarg.h>
22 #include <assert.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wine/test.h"
27
28 #define ALIGN_SIZE(size, alignment) (((size) + (alignment - 1)) & ~((alignment - 1)))
29
30 static const struct
31 {
32     WORD e_magic;      /* 00: MZ Header signature */
33     WORD unused[29];
34     DWORD e_lfanew;    /* 3c: Offset to extended header */
35 } dos_header =
36 {
37     IMAGE_DOS_SIGNATURE, { 0 }, sizeof(dos_header)
38 };
39
40 static IMAGE_NT_HEADERS nt_header =
41 {
42     IMAGE_NT_SIGNATURE, /* Signature */
43 #if defined __i386__
44     { IMAGE_FILE_MACHINE_I386, /* Machine */
45 #elif defined __x86_64__
46     { IMAGE_FILE_MACHINE_AMD64, /* Machine */
47 #else
48 # error You must specify the machine type
49 #endif
50       1, /* NumberOfSections */
51       0, /* TimeDateStamp */
52       0, /* PointerToSymbolTable */
53       0, /* NumberOfSymbols */
54       sizeof(IMAGE_OPTIONAL_HEADER), /* SizeOfOptionalHeader */
55       IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL /* Characteristics */
56     },
57     { IMAGE_NT_OPTIONAL_HDR_MAGIC, /* Magic */
58       1, /* MajorLinkerVersion */
59       0, /* MinorLinkerVersion */
60       0, /* SizeOfCode */
61       0, /* SizeOfInitializedData */
62       0, /* SizeOfUninitializedData */
63       0, /* AddressOfEntryPoint */
64       0x10, /* BaseOfCode, also serves as e_lfanew in the truncated MZ header */
65       0, /* BaseOfData */
66       0x10000000, /* ImageBase */
67       0, /* SectionAlignment */
68       0, /* FileAlignment */
69       4, /* MajorOperatingSystemVersion */
70       0, /* MinorOperatingSystemVersion */
71       1, /* MajorImageVersion */
72       0, /* MinorImageVersion */
73       4, /* MajorSubsystemVersion */
74       0, /* MinorSubsystemVersion */
75       0, /* Win32VersionValue */
76       sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000, /* SizeOfImage */
77       sizeof(dos_header) + sizeof(nt_header), /* SizeOfHeaders */
78       0, /* CheckSum */
79       IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
80       0, /* DllCharacteristics */
81       0, /* SizeOfStackReserve */
82       0, /* SizeOfStackCommit */
83       0, /* SizeOfHeapReserve */
84       0, /* SizeOfHeapCommit */
85       0, /* LoaderFlags */
86       0, /* NumberOfRvaAndSizes */
87       { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
88     }
89 };
90
91 static IMAGE_SECTION_HEADER section =
92 {
93     ".rodata", /* Name */
94     { 0x10 }, /* Misc */
95     0, /* VirtualAddress */
96     0x0a, /* SizeOfRawData */
97     0, /* PointerToRawData */
98     0, /* PointerToRelocations */
99     0, /* PointerToLinenumbers */
100     0, /* NumberOfRelocations */
101     0, /* NumberOfLinenumbers */
102     IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ, /* Characteristics */
103 };
104
105 START_TEST(loader)
106 {
107     static const struct test_data
108     {
109         const void *dos_header;
110         DWORD size_of_dos_header;
111         WORD number_of_sections, size_of_optional_header;
112         DWORD section_alignment, file_alignment;
113         DWORD size_of_image, size_of_headers;
114         DWORD error; /* 0 means LoadLibrary should succeed */
115     } td[] =
116     {
117         { &dos_header, sizeof(dos_header),
118           1, 0, 0, 0, 0, 0,
119           ERROR_BAD_EXE_FORMAT
120         },
121         { &dos_header, sizeof(dos_header),
122           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x1000,
123           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0xe00,
124           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER),
125           ERROR_BAD_EXE_FORMAT /* XP doesn't like too small image size */
126         },
127         { &dos_header, sizeof(dos_header),
128           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x1000,
129           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
130           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER),
131           ERROR_SUCCESS
132         },
133         { &dos_header, sizeof(dos_header),
134           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x1000,
135           0x1f00,
136           0x1000,
137           ERROR_SUCCESS
138         },
139         { &dos_header, sizeof(dos_header),
140           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x200, 0x200,
141           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
142           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER),
143           ERROR_SUCCESS
144         },
145         { &dos_header, sizeof(dos_header),
146           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x200, 0x1000,
147           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
148           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER),
149           ERROR_BAD_EXE_FORMAT /* XP doesn't like aligments */
150         },
151         { &dos_header, sizeof(dos_header),
152           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x200,
153           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
154           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER),
155           ERROR_SUCCESS
156         },
157         { &dos_header, sizeof(dos_header),
158           1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x200,
159           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
160           0x200,
161           ERROR_SUCCESS
162         },
163         /* Mandatory are all fields up to SizeOfHeaders, everything else
164          * is really optional (at least that's true for XP).
165          */
166         { &dos_header, sizeof(dos_header),
167           1, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
168           sizeof(dos_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum) + sizeof(IMAGE_SECTION_HEADER) + 0x10,
169           sizeof(dos_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum) + sizeof(IMAGE_SECTION_HEADER),
170           ERROR_SUCCESS
171         },
172         { &dos_header, sizeof(dos_header),
173           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
174           0xd0, /* beyond of the end of file */
175           0xc0, /* beyond of the end of file */
176           ERROR_SUCCESS
177         },
178         { &dos_header, sizeof(dos_header),
179           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
180           0x1000,
181           0,
182           ERROR_SUCCESS
183         },
184         { &dos_header, sizeof(dos_header),
185           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
186           1,
187           0,
188           ERROR_SUCCESS
189         },
190 #if 0 /* not power of 2 alignments need more test cases */
191         { &dos_header, sizeof(dos_header),
192           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x300, 0x300,
193           1,
194           0,
195           ERROR_BAD_EXE_FORMAT /* alignment is not power of 2 */
196         },
197 #endif
198         { &dos_header, sizeof(dos_header),
199           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 4, 4,
200           1,
201           0,
202           ERROR_SUCCESS
203         },
204         { &dos_header, sizeof(dos_header),
205           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 1, 1,
206           1,
207           0,
208           ERROR_SUCCESS
209         },
210         { &dos_header, sizeof(dos_header),
211           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
212           0,
213           0,
214           ERROR_BAD_EXE_FORMAT /* image size == 0 -> failure */
215         },
216         /* the following data mimics the PE image which upack creates */
217         { &dos_header, 0x10,
218           1, 0x148, 0x1000, 0x200,
219           sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
220           0x200,
221           ERROR_SUCCESS
222         },
223         /* Minimal PE image that XP is able to load: 92 bytes */
224         { &dos_header, 0x04,
225           0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum),
226           0x04 /* also serves as e_lfanew in the truncated MZ header */, 0x04,
227           1,
228           0,
229           ERROR_SUCCESS
230         }
231     };
232     static const char filler[0x1000];
233     static const char section_data[0x10] = "section data";
234     int i;
235     DWORD dummy, file_size, file_align;
236     HANDLE hfile;
237     HMODULE hlib, hlib_as_data_file;
238     SYSTEM_INFO si;
239     char temp_path[MAX_PATH];
240     char dll_name[MAX_PATH];
241
242     GetSystemInfo(&si);
243     trace("system page size 0x%04x\n", si.dwPageSize);
244
245     /* prevent displaying of the "Unable to load this DLL" message box */
246     SetErrorMode(SEM_FAILCRITICALERRORS);
247
248     GetTempPath(MAX_PATH, temp_path);
249
250     for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
251     {
252         GetTempFileName(temp_path, "ldr", 0, dll_name);
253
254         /*trace("creating %s\n", dll_name);*/
255         hfile = CreateFileA(dll_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
256         if (hfile == INVALID_HANDLE_VALUE)
257         {
258             ok(0, "could not create %s\n", dll_name);
259             break;
260         }
261
262         SetLastError(0xdeadbeef);
263         ok(WriteFile(hfile, td[i].dos_header, td[i].size_of_dos_header, &dummy, NULL),
264            "WriteFile error %d\n", GetLastError());
265
266         nt_header.FileHeader.NumberOfSections = td[i].number_of_sections;
267         nt_header.FileHeader.SizeOfOptionalHeader = td[i].size_of_optional_header;
268
269         nt_header.OptionalHeader.SectionAlignment = td[i].section_alignment;
270         nt_header.OptionalHeader.FileAlignment = td[i].file_alignment;
271         nt_header.OptionalHeader.SizeOfImage = td[i].size_of_image;
272         nt_header.OptionalHeader.SizeOfHeaders = td[i].size_of_headers;
273         SetLastError(0xdeadbeef);
274         ok(WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL),
275            "WriteFile error %d\n", GetLastError());
276
277         if (nt_header.FileHeader.SizeOfOptionalHeader)
278         {
279             SetLastError(0xdeadbeef);
280             ok(WriteFile(hfile, &nt_header.OptionalHeader,
281                          min(nt_header.FileHeader.SizeOfOptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER)),
282                          &dummy, NULL),
283                "WriteFile error %d\n", GetLastError());
284             if (nt_header.FileHeader.SizeOfOptionalHeader > sizeof(IMAGE_OPTIONAL_HEADER))
285             {
286                 file_align = nt_header.FileHeader.SizeOfOptionalHeader - sizeof(IMAGE_OPTIONAL_HEADER);
287                 assert(file_align < sizeof(filler));
288                 SetLastError(0xdeadbeef);
289                 ok(WriteFile(hfile, filler, file_align, &dummy, NULL),
290                    "WriteFile error %d\n", GetLastError());
291             }
292         }
293
294         assert(nt_header.FileHeader.NumberOfSections <= 1);
295         if (nt_header.FileHeader.NumberOfSections)
296         {
297             if (nt_header.OptionalHeader.SectionAlignment >= si.dwPageSize)
298             {
299                 section.PointerToRawData = td[i].size_of_dos_header;
300                 section.VirtualAddress = nt_header.OptionalHeader.SectionAlignment;
301                 section.Misc.VirtualSize = section.SizeOfRawData * 10;
302             }
303             else
304             {
305                 section.PointerToRawData = nt_header.OptionalHeader.SizeOfHeaders;
306                 section.VirtualAddress = nt_header.OptionalHeader.SizeOfHeaders;
307                 section.Misc.VirtualSize = 5;
308             }
309
310             SetLastError(0xdeadbeef);
311             ok(WriteFile(hfile, &section, sizeof(section), &dummy, NULL),
312                "WriteFile error %d\n", GetLastError());
313
314             /* section data */
315             SetLastError(0xdeadbeef);
316             ok(WriteFile(hfile, section_data, sizeof(section_data), &dummy, NULL),
317                "WriteFile error %d\n", GetLastError());
318         }
319
320         file_size = GetFileSize(hfile, NULL);
321         CloseHandle(hfile);
322
323         SetLastError(0xdeadbeef);
324         hlib = LoadLibrary(dll_name);
325         if (td[i].error == ERROR_SUCCESS)
326         {
327             MEMORY_BASIC_INFORMATION info;
328
329             ok(hlib != 0, "%d: LoadLibrary error %d\n", i, GetLastError());
330
331             SetLastError(0xdeadbeef);
332             ok(VirtualQuery(hlib, &info, sizeof(info)) == sizeof(info),
333                 "%d: VirtualQuery error %d\n", i, GetLastError());
334             ok(info.BaseAddress == hlib, "%d: %p != %p\n", i, info.BaseAddress, hlib);
335             ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
336             ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
337             ok(info.RegionSize == ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, si.dwPageSize), "%d: got %lx != expected %x\n",
338                i, info.RegionSize, ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, si.dwPageSize));
339             ok(info.State == MEM_COMMIT, "%d: %x != MEM_COMMIT\n", i, info.State);
340             if (nt_header.OptionalHeader.SectionAlignment < si.dwPageSize)
341                 ok(info.Protect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.Protect);
342             else
343                 ok(info.Protect == PAGE_READONLY, "%d: %x != PAGE_READONLY\n", i, info.Protect);
344             ok(info.Type == SEC_IMAGE, "%d: %x != SEC_IMAGE\n", i, info.Type);
345
346             SetLastError(0xdeadbeef);
347             ok(VirtualQuery((char *)hlib + info.RegionSize, &info, sizeof(info)) == sizeof(info),
348                 "%d: VirtualQuery error %d\n", i, GetLastError());
349             if (nt_header.OptionalHeader.SectionAlignment == si.dwPageSize ||
350                 nt_header.OptionalHeader.SectionAlignment == nt_header.OptionalHeader.FileAlignment)
351             {
352                 ok(info.BaseAddress == (char *)hlib + ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, si.dwPageSize), "%d: got %p != expected %p\n",
353                    i, info.BaseAddress, (char *)hlib + ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, si.dwPageSize));
354                 ok(info.AllocationBase == 0, "%d: %p != 0\n", i, info.AllocationBase);
355                 ok(info.AllocationProtect == 0, "%d: %x != 0\n", i, info.AllocationProtect);
356                 /*ok(info.RegionSize == not_practical_value, "%d: %lx != not_practical_value\n", i, info.RegionSize);*/
357                 ok(info.State == MEM_FREE, "%d: %x != MEM_FREE\n", i, info.State);
358                 ok(info.Type == 0, "%d: %x != 0\n", i, info.Type);
359                 ok(info.Protect == PAGE_NOACCESS, "%d: %x != PAGE_NOACCESS\n", i, info.Protect);
360             }
361             else
362             {
363                 ok(info.Protect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.Protect);
364                 ok(info.BaseAddress == hlib, "%d: got %p != expected %p\n", i, info.BaseAddress, hlib);
365                 ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
366                 ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
367                 ok(info.RegionSize == ALIGN_SIZE(file_size, si.dwPageSize), "%d: got %lx != expected %x\n",
368                    i, info.RegionSize, ALIGN_SIZE(file_size, si.dwPageSize));
369                 ok(info.State == MEM_COMMIT, "%d: %x != MEM_COMMIT\n", i, info.State);
370                 ok(info.Protect == PAGE_READONLY, "%d: %x != PAGE_READONLY\n", i, info.Protect);
371                 ok(info.Type == SEC_IMAGE, "%d: %x != SEC_IMAGE\n", i, info.Type);
372             }
373
374             /* header: check the zeroing of alignment */
375             if (nt_header.OptionalHeader.SectionAlignment >= si.dwPageSize)
376             {
377                 const char *start;
378                 int size;
379
380                 start = (const char *)hlib + nt_header.OptionalHeader.SizeOfHeaders;
381                 size = ALIGN_SIZE((ULONG_PTR)start, si.dwPageSize) - (ULONG_PTR)start;
382                 ok(!memcmp(start, filler, size), "%d: header alignment is not cleared\n", i);
383             }
384
385             if (nt_header.FileHeader.NumberOfSections)
386             {
387                 SetLastError(0xdeadbeef);
388                 ok(VirtualQuery((char *)hlib + section.VirtualAddress, &info, sizeof(info)) == sizeof(info),
389                     "%d: VirtualQuery error %d\n", i, GetLastError());
390                 if (nt_header.OptionalHeader.SectionAlignment < si.dwPageSize)
391                 {
392                     ok(info.BaseAddress == (char *)hlib, "%d: got %p != expected %p\n", i, info.BaseAddress, (char *)hlib);
393                     ok(info.RegionSize == ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, si.dwPageSize), "%d: got %lx != expected %x\n",
394                        i, info.RegionSize, ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, si.dwPageSize));
395                     ok(info.Protect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.Protect);
396                 }
397                 else
398                 {
399                     ok(info.BaseAddress == (char *)hlib + section.VirtualAddress, "%d: got %p != expected %p\n", i, info.BaseAddress, (char *)hlib + section.VirtualAddress);
400                     ok(info.RegionSize == ALIGN_SIZE(section.Misc.VirtualSize, si.dwPageSize), "%d: got %lx != expected %x\n",
401                        i, info.RegionSize, ALIGN_SIZE(section.Misc.VirtualSize, si.dwPageSize));
402                     ok(info.Protect == PAGE_READONLY, "%d: %x != PAGE_READONLY\n", i, info.Protect);
403                 }
404                 ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
405                 ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
406                 ok(info.State == MEM_COMMIT, "%d: %x != MEM_COMMIT\n", i, info.State);
407                 ok(info.Type == SEC_IMAGE, "%d: %x != SEC_IMAGE\n", i, info.Type);
408
409                 if (nt_header.OptionalHeader.SectionAlignment >= si.dwPageSize)
410                     ok(!memcmp((const char *)hlib + section.VirtualAddress + section.PointerToRawData, &nt_header, section.SizeOfRawData), "wrong section data\n");
411                 else
412                     ok(!memcmp((const char *)hlib + section.PointerToRawData, section_data, section.SizeOfRawData), "wrong section data\n");
413
414                 /* check the zeroing of alignment */
415                 if (nt_header.OptionalHeader.SectionAlignment >= si.dwPageSize)
416                 {
417                     const char *start;
418                     int size;
419
420                     start = (const char *)hlib + section.VirtualAddress + section.PointerToRawData + section.SizeOfRawData;
421                     size = ALIGN_SIZE((ULONG_PTR)start, si.dwPageSize) - (ULONG_PTR)start;
422                     ok(memcmp(start, filler, size), "%d: alignment should not be cleared\n", i);
423                 }
424             }
425
426             SetLastError(0xdeadbeef);
427             hlib_as_data_file = LoadLibraryEx(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE);
428             ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
429             ok(hlib_as_data_file == hlib, "hlib_as_file and hlib are different\n");
430
431             SetLastError(0xdeadbeef);
432             ok(FreeLibrary(hlib), "FreeLibrary error %d\n", GetLastError());
433
434             SetLastError(0xdeadbeef);
435             hlib = GetModuleHandle(dll_name);
436             ok(hlib != 0, "GetModuleHandle error %u\n", GetLastError());
437
438             SetLastError(0xdeadbeef);
439             ok(FreeLibrary(hlib_as_data_file), "FreeLibrary error %d\n", GetLastError());
440
441             hlib = GetModuleHandle(dll_name);
442             ok(!hlib, "GetModuleHandle should fail\n");
443
444             SetLastError(0xdeadbeef);
445             hlib_as_data_file = LoadLibraryEx(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE);
446             ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
447             ok((ULONG_PTR)hlib_as_data_file & 1, "hlib_as_data_file is even\n");
448
449             hlib = GetModuleHandle(dll_name);
450             ok(!hlib, "GetModuleHandle should fail\n");
451
452             SetLastError(0xdeadbeef);
453             ok(FreeLibrary(hlib_as_data_file), "FreeLibrary error %d\n", GetLastError());
454         }
455         else
456         {   /* LoadLibrary is expected to fail */
457             ok(!hlib, "%d: LoadLibrary should fail\n", i);
458
459             if (GetLastError() == ERROR_GEN_FAILURE) /* Win9x, broken behaviour */
460             {
461                 trace("skipping the loader test on Win9x\n");
462                 DeleteFile(dll_name);
463                 return;
464             }
465
466             ok(td[i].error == GetLastError(), "%d: expected error %d, got %d\n",
467                i, td[i].error, GetLastError());
468         }
469
470         SetLastError(0xdeadbeef);
471         ok(DeleteFile(dll_name), "DeleteFile error %d\n", GetLastError());
472     }
473 }