ReactOS 0.4.15-dev-7958-gcd0bb1a
NtMapViewOfSection.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for NtMapViewOfSection
5 * PROGRAMMERS: Timo Kreuzer
6 * Thomas Faber
7 */
8
9#include "precomp.h"
10
11#include <pseh/pseh2.h>
12
13void
15{
17 HANDLE SectionHandle;
19 PVOID BaseAddress, BaseAddress2;
21 ULONG OldProtect;
22
23 /* Create a page file backed section with SEC_COMMIT */
24 MaximumSize.QuadPart = 0x20000;
25 Status = NtCreateSection(&SectionHandle,
27 NULL,
31 NULL);
33 if (!NT_SUCCESS(Status))
34 return;
35
36 /* Try to map a page at an address that is not 64k aligned */
37 BaseAddress = (PVOID)0x30001000;
38 SectionOffset.QuadPart = 0;
39 ViewSize = 0x1000;
40 Status = NtMapViewOfSection(SectionHandle,
43 0,
44 0,
46 &ViewSize,
48 0,
51
52 /* Try to map a page with execute rights */
53 BaseAddress = (PVOID)0x30000000;
54 SectionOffset.QuadPart = 0;
55 ViewSize = 0x1000;
56 Status = NtMapViewOfSection(SectionHandle,
59 0,
60 0,
62 &ViewSize,
64 0,
67
68 /* Try to map 2 pages with MEM_COMMIT */
69 BaseAddress = (PVOID)0x30000000;
70 SectionOffset.QuadPart = 0;
71 ViewSize = 0x2000;
72 Status = NtMapViewOfSection(SectionHandle,
75 0,
78 &ViewSize,
83
84 /* Try to map 1 page, with free base address and zero bits compatible with 64k granularity */
86 SectionOffset.QuadPart = 0;
87 ViewSize = 0x1000;
88 Status = NtMapViewOfSection(SectionHandle,
91 10,
92 0,
94 &ViewSize,
96 0,
101
102{
103 ULONG_PTR gran = 64 * 1024;
104 ULONG_PTR ZeroBits = 11;
105
106 ok_hex(gran, 0x10000);
107 gran <<= ZeroBits;
108 ok_hex(gran, 0x8000000);
109 gran >>= ZeroBits;
110 ok_hex(gran, 0x10000);
111
112 ok_hex((gran << ZeroBits) >> ZeroBits, gran);
113
114}
115
116 /* Try to map 1 page, with free base address and zero bits incompatible with 64k granularity */
118 SectionOffset.QuadPart = 0;
119 ViewSize = 0x1000;
120 Status = NtMapViewOfSection(SectionHandle,
123 11,
124 0,
126 &ViewSize,
127 ViewShare,
128 0,
131
132 /* Try to map 1 page, with base address and zero bits being compatible */
133 BaseAddress = (PVOID)0x30000000;
134 SectionOffset.QuadPart = 0;
135 ViewSize = 0x1000;
136 Status = NtMapViewOfSection(SectionHandle,
139 2,
140 0,
142 &ViewSize,
143 ViewShare,
144 0,
149
150 /* Try to map 1 page, with base address and zero bits being incompatible */
151 BaseAddress = (PVOID)0x30000000;
152 SectionOffset.QuadPart = 0;
153 ViewSize = 0x1000;
154 Status = NtMapViewOfSection(SectionHandle,
157 3,
158 0,
160 &ViewSize,
161 ViewShare,
162 0,
165
166 /* Map 2 pages, without MEM_COMMIT */
167 BaseAddress = (PVOID)0x30000000;
168 SectionOffset.QuadPart = 0;
169 ViewSize = 0x2000;
170 Status = NtMapViewOfSection(SectionHandle,
173 0,
174 0,
176 &ViewSize,
177 ViewShare,
178 0,
181
182 /* We must be able to access the memory */
184 {
185 *(PULONG)BaseAddress = 1;
186 }
187 _SEH2_EXCEPT(1)
188 {
189 ok(FALSE, "Got an exception\n");
190 }
191 _SEH2_END;
192
193 /* Commit a page in the section */
194 BaseAddress = (PVOID)0x30000000;
195 ViewSize = 0x1000;
198 0,
199 &ViewSize,
203
204 /* Try to decommit a page in the section */
207 &ViewSize,
210
211 /* Try to commit a range larger than the section */
212 BaseAddress = (PVOID)0x30000000;
213 ViewSize = 0x3000;
216 0,
217 &ViewSize,
221
222 /* Try to commit a page after the section */
223 BaseAddress = (PVOID)0x30002000;
224 ViewSize = 0x1000;
227 0,
228 &ViewSize,
232
233 /* Try to allocate a page after the section */
234 BaseAddress = (PVOID)0x30002000;
235 ViewSize = 0x1000;
238 0,
239 &ViewSize,
243
244 /* Need to go to next 64k boundary */
245 BaseAddress = (PVOID)0x30010000;
246 ViewSize = 0x1000;
249 0,
250 &ViewSize,
254 if (!NT_SUCCESS(Status))
255 return;
256
257 /* Free the allocation */
258 BaseAddress = (PVOID)0x30010000;
259 ViewSize = 0x1000;
262 &ViewSize,
264 ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed with Status %lx\n", Status);
265
266 /* Try to release the section mapping with NtFreeVirtualMemory */
267 BaseAddress = (PVOID)0x30000000;
268 ViewSize = 0x1000;
271 &ViewSize,
274
275 /* Commit a page in the section */
276 BaseAddress = (PVOID)0x30001000;
277 ViewSize = 0x1000;
280 0,
281 &ViewSize,
285
286 /* Try to decommit the page */
287 BaseAddress = (PVOID)0x30001000;
288 ViewSize = 0x1000;
291 &ViewSize,
294
295 BaseAddress = UlongToPtr(0x40000000);
296 SectionOffset.QuadPart = 0;
297 ViewSize = 0x1000;
298 Status = NtMapViewOfSection(SectionHandle,
301 0,
302 0,
304 &ViewSize,
305 ViewShare,
306 0,
309 if (!NT_SUCCESS(Status))
310 return;
311
312 ok(BaseAddress == UlongToPtr(0x40000000), "Invalid BaseAddress: %p\n", BaseAddress);
313
314 BaseAddress = (PVOID)0x40080000;
315 SectionOffset.QuadPart = 0x10000;
316 ViewSize = 0x1000;
317 Status = NtMapViewOfSection(SectionHandle,
320 0,
321 0,
323 &ViewSize,
324 ViewShare,
325 0,
328
329 ok(BaseAddress == (PVOID)0x40080000, "Invalid BaseAddress: %p\n", BaseAddress);
330
331 /* Commit a page in the section */
332 BaseAddress = (PVOID)0x40000000;
335 0,
336 &ViewSize,
340
341 /* Close the mapping */
344 BaseAddress = (PVOID)0x30000000;
347 Status = NtClose(SectionHandle);
349
350 /* Create a page file backed section, but only reserved */
351 MaximumSize.QuadPart = 0x20000;
352 Status = NtCreateSection(&SectionHandle,
354 NULL,
358 NULL);
360
361 /* Try to map 1 page, passing MEM_RESERVE */
363 SectionOffset.QuadPart = 0;
365 Status = NtMapViewOfSection(SectionHandle,
368 0,
369 PAGE_SIZE,
371 &ViewSize,
372 ViewShare,
376
377 /* Try to map 1 page using MEM_COMMIT */
379 SectionOffset.QuadPart = 0;
381 Status = NtMapViewOfSection(SectionHandle,
384 0,
385 PAGE_SIZE,
387 &ViewSize,
388 ViewShare,
392
393 /* Map 2 pages, but commit 1 */
395 SectionOffset.QuadPart = 0;
396 ViewSize = 2 * PAGE_SIZE;
397 Status = NtMapViewOfSection(SectionHandle,
400 0,
401 PAGE_SIZE,
403 &ViewSize,
404 ViewShare,
405 0,
408
409 /* We must be able to access the 1st page */
412 {
413 *(PUCHAR)BaseAddress = 1;
414 }
415 _SEH2_EXCEPT(1)
416 {
418 }
419 _SEH2_END;
421
422 /* We must not be able to access the 2nd page */
425 {
426 *((PUCHAR)BaseAddress + PAGE_SIZE) = 1;
427 }
428 _SEH2_EXCEPT(1)
429 {
431 }
432 _SEH2_END;
434
435 /* Map the 2 pages again into a different memory location */
436 BaseAddress2 = NULL;
437 Status = NtMapViewOfSection(SectionHandle,
439 &BaseAddress2,
440 0,
441 0,
443 &ViewSize,
444 ViewShare,
445 0,
448
449 /* Commit a the 2nd page in the 2nd memory location */
450 BaseAddress2 = (PUCHAR)BaseAddress2 + PAGE_SIZE;
453 &BaseAddress2,
454 0,
455 &ViewSize,
459
460 /* Try to commit again (the already committed page) */
462 &BaseAddress2,
463 0,
464 &ViewSize,
468
469 /* We must be able to access the memory in the 2nd page of the 1st memory location */
472 {
473 *((PUCHAR)BaseAddress + PAGE_SIZE) = 2;
474 }
475 _SEH2_EXCEPT(1)
476 {
478 }
479 _SEH2_END;
481
482 ok(*(PULONG)BaseAddress2 == 2, "Value in memory was wrong\n");
483
484 /* Close the mapping */
489 Status = NtClose(SectionHandle);
491
492 /* Try to create a 512 GB page file backed section with committed pages */
493 MaximumSize.QuadPart = 0x8000000000;
494 Status = NtCreateSection(&SectionHandle,
496 NULL,
500 NULL);
502
503 /* Try to create a huge page file backed section with PAGE_NOACCESS protection */
504 MaximumSize.QuadPart = 0x8000000000;
505 Status = NtCreateSection(&SectionHandle,
507 NULL,
511 NULL);
513
514 /* Try to create a very huge page file backed section, but only reserved */
515 MaximumSize.QuadPart = 0x80000000000;
516 Status = NtCreateSection(&SectionHandle,
518 NULL,
522 NULL);
523#ifdef _WIN64
525#else
526 /* WoW64 returns STATUS_INSUFFICIENT_RESOURCES */
528 "got wrong Status: 0x%lx\n", Status);
529#endif
530
531 /* Try to create a even huger page file backed section, but only reserved */
532 MaximumSize.QuadPart = 0x800000000000;
533 Status = NtCreateSection(&SectionHandle,
535 NULL,
539 NULL);
541
542 /* Create a 8 GB page file backed section, but only reserved */
543 MaximumSize.QuadPart = 0x200000000;
544 Status = NtCreateSection(&SectionHandle,
546 NULL,
550 NULL);
552
553 /* Pass a too large region size */
555 SectionOffset.QuadPart = 0;
557 Status = NtMapViewOfSection(SectionHandle,
560 0,
561 0,
563 &ViewSize,
564 ViewShare,
565 0,
567#ifdef _WIN64
569#else
570 /* WoW64 returns STATUS_INVALID_PARAMETER_4 */
572 "got wrong Status: 0x%lx\n", Status);
573#endif
574
575 /* Pass 0 region size */
577 SectionOffset.QuadPart = 0;
578 ViewSize = 0;
579 Status = NtMapViewOfSection(SectionHandle,
582 0,
583 0,
585 &ViewSize,
586 ViewShare,
587 0,
589#ifdef _WIN64
591 ok(ViewSize == 0x200000000, "wrong ViewSize: 0x%Ix\n", ViewSize);
592#else
593 /* WoW64 returns STATUS_NO_MEMORY */
595 "got wrong Status: 0x%lx\n", Status);
596 ok(ViewSize == 0, "wrong ViewSize: 0x%Ix\n", ViewSize);
597#endif
598
599 /* Map with PAGE_NOACCESS */
601 SectionOffset.QuadPart = 0;
602 ViewSize = 0x20000000;
603 Status = NtMapViewOfSection(SectionHandle,
606 0,
607 0,
609 &ViewSize,
610 ViewShare,
611 0,
614
615 /* Try to change protection to read/write */
616 ViewSize = 0x1000;
617 OldProtect = -1;
618 BaseAddress2 = BaseAddress;
619 Status = NtProtectVirtualMemory(NtCurrentProcess(), &BaseAddress2, &ViewSize, PAGE_READWRITE, &OldProtect);
621 // Windows 2003 returns bogus
622 //ok(OldProtect == PAGE_READWRITE, "Wrong protection returned: %u\n", OldProtect);
623
624 /* Test read access */
627 {
628 (void)(*(volatile char*)BaseAddress2);
629 }
631 {
633 }
634 _SEH2_END;
636
637 /* Try to change protection to read/write */
638 ViewSize = 0x1000;
639 OldProtect = -1;
640 BaseAddress2 = BaseAddress;
641 Status = NtProtectVirtualMemory(NtCurrentProcess(), &BaseAddress2, &ViewSize, PAGE_READWRITE, &OldProtect);
643#ifdef _WIN64
644 ok(OldProtect == 0, "Wrong protection returned: 0x%lx\n", OldProtect);
645#else
646 // Windows 2003 returns bogus
647#endif
648
649 /* Try to change protection to readonly */
650 ViewSize = 0x1000;
651 OldProtect = -1;
652 BaseAddress2 = BaseAddress;
653 Status = NtProtectVirtualMemory(NtCurrentProcess(), &BaseAddress2, &ViewSize, PAGE_READONLY, &OldProtect);
655#ifdef _WIN64
656 //ok(OldProtect == 0, "Wrong protection returned: 0x%lx\n", OldProtect);
657#else
658 // Windows 2003 returns bogus
659#endif
660
661 /* Commit a page */
662 ViewSize = 0x1000;
663 BaseAddress2 = BaseAddress;
666 ok(BaseAddress2 == BaseAddress, "Invalid base address: %p\n", BaseAddress2);
667
668 /* Commit the page again */
669 ViewSize = 0x1000;
670 BaseAddress2 = BaseAddress;
673 ok(BaseAddress2 == BaseAddress, "Invalid base address: %p\n", BaseAddress2);
674
675 /* Test read access */
678 {
679 (void)(*(volatile char*)BaseAddress2);
680 }
682 {
684 }
685 _SEH2_END;
687
688 /* Test write access */
691 {
692 *(char*)BaseAddress2 = 1;
693 }
695 {
697 }
698 _SEH2_END;
700
701 /* Update protection to PAGE_READWRITE */
702 ViewSize = 0x1000;
703 BaseAddress2 = BaseAddress;
706
707 /* Test write access */
710 {
711 *(char*)BaseAddress2 = 1;
712 }
714 {
716 }
717 _SEH2_END;
719
720 /* Update protection to PAGE_EXECUTE_READWRITE (1 page) */
721 ViewSize = 0x1000;
722 BaseAddress2 = BaseAddress;
725
728 Status = NtClose(SectionHandle);
730}
731
732void
734{
739 WCHAR TestDllPath[MAX_PATH];
740 HANDLE FileHandle, DataSectionHandle, ImageSectionHandle;
741 PVOID DataBase, ImageBase;
743
744 GetModuleFileNameW(NULL, TestDllPath, RTL_NUMBER_OF(TestDllPath));
745 wcsrchr(TestDllPath, L'\\')[1] = UNICODE_NULL;
746 StringCbCatW(TestDllPath, sizeof(TestDllPath), L"testdata\\test.dll");
747 if (!RtlDosPathNameToNtPathName_U(TestDllPath,
748 &FileName,
749 NULL,
750 NULL))
751 {
752 ok(0, "RtlDosPathNameToNtPathName_U failed\n");
753 return;
754 }
755
757 &FileName,
758 0,
759 NULL,
760 NULL);
761
769 if (!NT_SUCCESS(Status))
770 {
771 skip("Failed to open file %s\n", wine_dbgstr_wn(FileName.Buffer, FileName.Length / sizeof(WCHAR)));
772 return;
773 }
774
775 /* Create a data section with write access */
776 Status = NtCreateSection(&DataSectionHandle,
777 SECTION_ALL_ACCESS, // DesiredAccess
778 NULL, // ObjectAttributes
779 NULL, // MaximumSize
780 PAGE_READWRITE, // SectionPageProtection
781 SEC_COMMIT, // AllocationAttributes
782 FileHandle);
784 if (!NT_SUCCESS(Status))
785 {
786 skip("Failed to create data section\n");
788 return;
789 }
790
791 /* Map the data section as flat mapping */
792 DataBase = NULL;
793 ViewSize = 0;
794 Status = NtMapViewOfSection(DataSectionHandle,
796 &DataBase,
797 0,
798 0,
799 NULL,
800 &ViewSize,
801 ViewShare,
802 0,
805 //ok(ViewSize == 0x3f95cc48, "ViewSize wrong: 0x%lx\n");
806 if (!NT_SUCCESS(Status))
807 {
808 skip("Failed to map view of data section\n");
809 NtClose(DataSectionHandle);
811 return;
812 }
813
814 /* Check the original data */
815 ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
816
817 /* Modify the PE header (but do not flush!) */
818 *(ULONG*)DataBase = 0xdeadbabe;
819 ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n");
820
821 /* Modify data in the .data section (but do not flush!) */
822 ok(*(ULONG*)((PUCHAR)DataBase + 0x800) == 0x12345678,
823 "Data in .data section invalid: 0x%lx!\n", *(ULONG*)((PUCHAR)DataBase + 0x800));
824 *(ULONG*)((PUCHAR)DataBase + 0x800) = 0x87654321;
825
826 /* Now try to create an image section (should fail) */
827 Status = NtCreateSection(&ImageSectionHandle,
828 SECTION_ALL_ACCESS, // DesiredAccess
829 NULL, // ObjectAttributes
830 NULL, // MaximumSize
831 PAGE_READWRITE, // SectionPageProtection
832 SEC_IMAGE, // AllocationAttributes
833 FileHandle);
835 if (NT_SUCCESS(Status)) NtClose(ImageSectionHandle);
836
837 /* Restore the original header */
838 *(ULONG*)DataBase = 0x00905a4d;
839
840 /* Modify data in the .data section (but do not flush!) */
841 ok_hex(*(ULONG*)((PUCHAR)DataBase + 0x800), 0x87654321);
842 *(ULONG*)((PUCHAR)DataBase + 0x800) = 0xdeadbabe;
843
844 /* Try to create an image section again */
845 Status = NtCreateSection(&ImageSectionHandle,
846 SECTION_ALL_ACCESS, // DesiredAccess
847 NULL, // ObjectAttributes
848 NULL, // MaximumSize
849 PAGE_READWRITE, // SectionPageProtection
850 SEC_IMAGE, // AllocationAttributes
851 FileHandle);
853 if (!NT_SUCCESS(Status))
854 {
855 skip("Failed to create image section\n");
856 NtClose(DataSectionHandle);
858 return;
859 }
860
861 /* Map the image section */
862 ImageBase = NULL;
863 ViewSize = 0;
864 Status = NtMapViewOfSection(ImageSectionHandle,
866 &ImageBase,
867 0, // ZeroBits
868 0, // CommitSize
869 NULL, // SectionOffset
870 &ViewSize,
871 ViewShare,
872 0, // AllocationType
874#ifdef _M_IX86
876#else
878#endif
879 if (!NT_SUCCESS(Status))
880 {
881 skip("Failed to map view of image section\n");
882 NtClose(ImageSectionHandle);
883 NtClose(DataSectionHandle);
885 return;
886 }
887
888 /* Check the header */
889 ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
890 ok(*(ULONG*)ImageBase == 0x00905a4d, "Header not ok\n");
891
892 /* Check the data section. Either of these can be present! */
893 ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
894 (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
895 "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
896
897 /* Now modify the data again */
898 *(ULONG*)DataBase = 0xdeadbabe;
899 *(ULONG*)((PUCHAR)DataBase + 0x800) = 0xf00dada;
900
901 /* Check the data */
902 ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n");
903 ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n");
904 ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
905 (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
906 "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
907
908 /* Flush the view */
909 ViewSize = 0x1000;
911 &DataBase,
912 &ViewSize,
915
916 /* Check the data again */
917 ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n");
918 ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
919 (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
920 "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
921
922 /* Restore the original header */
923 *(ULONG*)DataBase = 0x00905a4d;
924 ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
925
926 /* Close the image mapping */
928 NtClose(ImageSectionHandle);
929
930 /* Create an image section again */
931 Status = NtCreateSection(&ImageSectionHandle,
932 SECTION_ALL_ACCESS, // DesiredAccess
933 NULL, // ObjectAttributes
934 NULL, // MaximumSize
935 PAGE_READWRITE, // SectionPageProtection
936 SEC_IMAGE, // AllocationAttributes
937 FileHandle);
939 if (!NT_SUCCESS(Status))
940 {
941 skip("Failed to create image section\n");
942 NtClose(DataSectionHandle);
944 return;
945 }
946
947 /* Map the image section again */
948 ImageBase = NULL;
949 ViewSize = 0;
950 Status = NtMapViewOfSection(ImageSectionHandle,
952 &ImageBase,
953 0,
954 0,
955 NULL,
956 &ViewSize,
957 ViewShare,
958 0,
960#ifdef _M_IX86
962#else
964#endif
965 if (!NT_SUCCESS(Status))
966 {
967 skip("Failed to map view of image section\n");
968 NtClose(ImageSectionHandle);
969 NtClose(DataSectionHandle);
971 return;
972 }
973
974 // This one doesn't always work, needs investigation
975 /* Check the .data section again */
976 //ok(*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0xf00dada,
977 // "Data should be synced: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
978
979 /* Restore the original data */
980 *(ULONG*)((PUCHAR)DataBase + 0x800) = 0x12345678;
981
982 /* Close the data mapping */
984
985 NtClose(DataSectionHandle);
986
987 /* Try to allocate memory inside the image mapping */
988 DataBase = (PUCHAR)ImageBase + 0x20000;
989 ViewSize = 0x1000;
992
993 /* Cleanup */
995 NtClose(ImageSectionHandle);
997}
998
999void
1001{
1006 HANDLE FileHandle, ImageSectionHandle;
1007 PVOID ImageBase, BaseAddress;
1010
1011 if (!RtlDosPathNameToNtPathName_U(L"testdata\\nvoglv32.dll",
1012 &FileName,
1013 NULL,
1014 NULL))
1015 {
1016 ok(0, "RtlDosPathNameToNtPathName_U failed\n");
1017 return;
1018 }
1019
1021 &FileName,
1022 0,
1023 NULL,
1024 NULL);
1025
1033 printf("Opened file with handle %p\n", FileHandle);
1034
1035 /* Create a data section with write access */
1036 MaximumSize.QuadPart = 0x20000;
1037 Status = NtCreateSection(&ImageSectionHandle,
1038 SECTION_ALL_ACCESS, // DesiredAccess
1039 NULL, // ObjectAttributes
1040 &MaximumSize, // MaximumSize
1041 PAGE_READWRITE, // SectionPageProtection
1042 SEC_IMAGE, // AllocationAttributes
1043 FileHandle);
1045
1046 printf("Created image section with handle %p\n", ImageSectionHandle);
1047 //system("PAUSE");
1048
1049 /* Map the image section */
1050 ImageBase = NULL;
1051 ViewSize = 0x0000;
1052 SectionOffset.QuadPart = 0x00000;
1053 Status = NtMapViewOfSection(ImageSectionHandle,
1055 &ImageBase,
1056 0,
1057 0,
1059 &ViewSize,
1060 ViewShare,
1061 0,
1064
1065 printf("Mapped image section at %p, value in text section: %lx\n",
1066 ImageBase, *((ULONG*)((PCHAR)ImageBase + 0x1196)));
1067 system("PAUSE");
1068
1069 /* Try to allocate a page after the section */
1070 BaseAddress = (PUCHAR)ImageBase + 0x10000;
1071 ViewSize = 0x1000;
1073 &BaseAddress,
1074 0,
1075 &ViewSize,
1078 printf("allocation status: %lx\n", Status);
1079 system("PAUSE");
1080
1081}
1082
1083// doesn't work with WoW64!
1084void
1086{
1088 HANDLE SectionHandle1, SectionHandle2;
1090 PVOID BaseAddress1, BaseAddress2;
1092
1093 /* Create a based section with SEC_COMMIT */
1094 MaximumSize.QuadPart = 0x1000;
1095 Status = NtCreateSection(&SectionHandle1,
1097 NULL,
1098 &MaximumSize,
1101 NULL);
1103
1104 /* Map the 1st section */
1105 BaseAddress1 = NULL;
1106 SectionOffset.QuadPart = 0;
1107 ViewSize = 0;
1108 Status = NtMapViewOfSection(SectionHandle1,
1110 &BaseAddress1,
1111 0,
1112 0,
1114 &ViewSize,
1115 ViewShare,
1116 0,
1118#if 0 // WOW64?
1120#else
1122#endif
1123
1124 /* Create a 2nd based section with SEC_COMMIT */
1125 MaximumSize.QuadPart = 0x1000;
1126 Status = NtCreateSection(&SectionHandle2,
1128 NULL,
1129 &MaximumSize,
1132 NULL);
1134
1135 /* Map the 2nd section */
1136 BaseAddress2 = NULL;
1137 SectionOffset.QuadPart = 0;
1138 ViewSize = 0;
1139 Status = NtMapViewOfSection(SectionHandle2,
1141 &BaseAddress2,
1142 0,
1143 0,
1145 &ViewSize,
1146 ViewShare,
1147 0,
1149#if 0 // WOW64?
1151#else
1153 ok((ULONG_PTR)BaseAddress2 < (ULONG_PTR)BaseAddress1,
1154 "Invalid addresses: BaseAddress1=%p, BaseAddress2=%p\n", BaseAddress1, BaseAddress2);
1155 ok(((ULONG_PTR)BaseAddress1 - (ULONG_PTR)BaseAddress2) == 0x10000,
1156 "Invalid addresses: BaseAddress1=%p, BaseAddress2=%p\n", BaseAddress1, BaseAddress2);
1157#endif
1158}
1159
1160#define BYTES4(x) x, x, x, x
1161#define BYTES8(x) BYTES4(x), BYTES4(x)
1162#define BYTES16(x) BYTES8(x), BYTES8(x)
1163#define BYTES32(x) BYTES16(x), BYTES16(x)
1164#define BYTES64(x) BYTES32(x), BYTES32(x)
1165#define BYTES128(x) BYTES64(x), BYTES64(x)
1166#define BYTES256(x) BYTES128(x), BYTES128(x)
1167#define BYTES512(x) BYTES256(x), BYTES256(x)
1168#define BYTES1024(x) BYTES512(x), BYTES512(x)
1169
1171{
1179 BYTE pad[488];
1185{
1186 /* IMAGE_DOS_HEADER */
1187 {
1188 IMAGE_DOS_SIGNATURE, 144, 3, 0, 4, 0, 0xFFFF, 0, 0xB8, 0, 0, 0, 0x40,
1189 0, { 0 }, 0, 0, { 0 }, 0x80
1190 },
1191 /* binary to print "This program cannot be run in DOS mode." */
1192 {
1193 0x1F0E, 0x0EBA, 0xB400, 0xCD09, 0xB821, 0x4C01, 0x21CD, 0x6854, 0x7369,
1194 0x7020, 0x6F72, 0x7267, 0x6D61, 0x6320, 0x6E61, 0x6F6E, 0x2074, 0x6562,
1195 0x7220, 0x6E75, 0x6920, 0x206E, 0x4F44, 0x2053, 0x6F6D, 0x6564, 0x0D2E,
1196 0x0A0D, 0x0024, 0x0000, 0x0000, 0x0000
1197 },
1198 /* IMAGE_NT_HEADERS32 */
1199 {
1200 IMAGE_NT_SIGNATURE, /* Signature */
1201 /* IMAGE_FILE_HEADER */
1202 {
1203 IMAGE_FILE_MACHINE_I386, /* Machine */
1204 4, /* NumberOfSections */
1205 0x47EFDF09, /* TimeDateStamp */
1206 0, /* PointerToSymbolTable */
1207 0, /* NumberOfSymbols */
1208 0xE0, /* SizeOfOptionalHeader */
1211 IMAGE_FILE_DLL, /* Characteristics */
1212 },
1213 /* IMAGE_OPTIONAL_HEADER32 */
1214 {
1216 8, /* MajorLinkerVersion */
1217 0, /* MinorLinkerVersion */
1218 0x400, /* SizeOfCode */
1219 0x000, /* SizeOfInitializedData */
1220 0, /* SizeOfUninitializedData */
1221 0x2000, /* AddressOfEntryPoint */
1222 0x2000, /* BaseOfCode */
1223 0x0000, /* BaseOfData */
1224 0x400000, /* ImageBase */
1225 0x2000, /* SectionAlignment */
1226 0x200, /* FileAlignment */
1227 4, /* MajorOperatingSystemVersion */
1228 0, /* MinorOperatingSystemVersion */
1229 0, /* MajorImageVersion */
1230 0, /* MinorImageVersion */
1231 4, /* MajorSubsystemVersion */
1232 0, /* MinorSubsystemVersion */
1233 0, /* Win32VersionValue */
1234 0xa000, /* SizeOfImage */
1235 0x400, /* SizeOfHeaders */
1236 0x0, /* CheckSum */
1237 IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
1240 IMAGE_DLLCHARACTERISTICS_NX_COMPAT, /* DllCharacteristics */
1241 0x100000, /* SizeOfStackReserve */
1242 0x1000, /* SizeOfStackCommit */
1243 0x100000, /* SizeOfHeapReserve */
1244 0x1000, /* SizeOfHeapCommit */
1245 0, /* LoaderFlags */
1246 0x10, /* NumberOfRvaAndSizes */
1247 /* IMAGE_DATA_DIRECTORY */
1248 {
1249 { 0 }, /* Export Table */
1250 { 0 }, /* Import Table */
1251 { 0 }, /* Resource Table */
1252 { 0 }, /* Exception Table */
1253 { 0 }, /* Certificate Table */
1254 { 0 }, /* Base Relocation Table */
1255 { 0 }, /* Debug */
1256 { 0 }, /* Copyright */
1257 { 0 }, /* Global Ptr */
1258 { 0 }, /* TLS Table */
1259 { 0 }, /* Load Config Table */
1260 { 0 }, /* Bound Import */
1261 { 0 }, /* IAT */
1262 { 0 }, /* Delay Import Descriptor */
1263 { 0 }, /* CLI Header */
1264 { 0 } /* Reserved */
1265 }
1266 }
1267 },
1268 /* IMAGE_SECTION_HEADER */
1269 {
1270 ".text", /* Name */
1271 { 0x394 }, /* Misc.VirtualSize */
1272 0x2000, /* VirtualAddress */
1273 0x400, /* SizeOfRawData */
1274 0x400, /* PointerToRawData */
1275 0, /* PointerToRelocations */
1276 0, /* PointerToLinenumbers */
1277 0, /* NumberOfRelocations */
1278 0, /* NumberOfLinenumbers */
1280 IMAGE_SCN_CNT_CODE, /* Characteristics */
1281 },
1282 /* IMAGE_SECTION_HEADER */
1283 {
1284 ".rossym", /* Name */
1285 { 0x100 }, /* Misc.VirtualSize */
1286 0x4000, /* VirtualAddress */
1287 0x400, /* SizeOfRawData */
1288 0x800, /* PointerToRawData */
1289 0, /* PointerToRelocations */
1290 0, /* PointerToLinenumbers */
1291 0, /* NumberOfRelocations */
1292 0, /* NumberOfLinenumbers */
1293 /* CORE-8384 */
1294 IMAGE_SCN_MEM_READ | IMAGE_SCN_TYPE_NOLOAD, /* Characteristics */
1295 },
1296 /* IMAGE_SECTION_HEADER */
1297 {
1298 ".rsrc", /* Name */
1299 { 0x100 }, /* Misc.VirtualSize */
1300 0x6000, /* VirtualAddress */
1301 0x400, /* SizeOfRawData */
1302 0xC00, /* PointerToRawData */
1303 0, /* PointerToRelocations */
1304 0, /* PointerToLinenumbers */
1305 0, /* NumberOfRelocations */
1306 0, /* NumberOfLinenumbers */
1308 IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1309 },
1310 /* IMAGE_SECTION_HEADER */
1311 {
1312 ".clc", /* Name */
1313 { 0x2000 }, /* Misc.VirtualSize */
1314 0x8000, /* VirtualAddress */
1315 0x1000, /* SizeOfRawData */
1316 0x1000, /* PointerToRawData */
1317 0, /* PointerToRelocations */
1318 0, /* PointerToLinenumbers */
1319 0, /* NumberOfRelocations */
1320 0, /* NumberOfLinenumbers */
1321 /* CORE-12582 */
1324 },
1325 /* fill */
1326 { 0 },
1327 /* text */
1328 { 0xc3, 0 },
1329 /* rossym */
1330 {
1331 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1332 BYTES8(0xaa),
1333 BYTES16(0xbb),
1334 BYTES32(0xcc),
1335 BYTES64(0xdd),
1336 BYTES64(0xee),
1337 BYTES64(0xff),
1338 },
1339 /* rsrc */
1340 {
1341 BYTES128(0xee),
1342 BYTES128(0x55),
1343 BYTES128(0xee),
1344 BYTES128(0x11),
1345 BYTES128(0xff),
1346 BYTES128(0x00),
1347 BYTES128(0x00),
1348 BYTES128(0xdd),
1349 },
1350 /* clc */
1351 {
1352 BYTES512(0x11),
1353 BYTES512(0x22),
1354 BYTES512(0x33),
1355 BYTES512(0x44),
1356 BYTES512(0x55),
1357 BYTES512(0x66),
1358 BYTES512(0x77),
1359 BYTES512(0x88),
1360 },
1362
1367
1368static
1369void
1371{
1373 WCHAR TempPath[MAX_PATH];
1375 HANDLE Handle;
1376 HANDLE SectionHandle;
1380 ULONG Written;
1381 ULONG Length;
1382 BOOL Success;
1383
1384 Length = GetTempPathW(MAX_PATH, TempPath);
1385 ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1386 Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1387 ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1390 0,
1391 NULL,
1393 0,
1394 NULL);
1396 {
1397 skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1398 return;
1399 }
1400 if (Relocate)
1401 {
1402 ok((ULONG_PTR)GetModuleHandle(NULL) <= 0x80000000, "Module at %p\n", GetModuleHandle(NULL));
1403 SectionContentsImageFile.nthdrs.OptionalHeader.ImageBase = (ULONG)(ULONG_PTR)GetModuleHandle(NULL);
1404 }
1405 else
1406 {
1407 SectionContentsImageFile.nthdrs.OptionalHeader.ImageBase = 0xe400000;
1408 }
1409
1413 &Written,
1414 NULL);
1415 ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1416 ok(Written == sizeof(SectionContentsImageFile), "WriteFile wrote %lu bytes\n", Written);
1417
1418 Status = NtCreateSection(&SectionHandle,
1420 NULL,
1421 NULL,
1423 SEC_IMAGE,
1424 Handle);
1426
1427 if (NT_SUCCESS(Status))
1428 {
1429 /* Map the section with */
1430 BaseAddress = NULL;
1431 SectionOffset.QuadPart = 0;
1432 ViewSize = 0;
1433 Status = NtMapViewOfSection(SectionHandle,
1435 &BaseAddress,
1436 0,
1437 0,
1439 &ViewSize,
1440 ViewShare,
1441 0,
1443 if (Relocate)
1445 else
1447 if (NT_SUCCESS(Status))
1448 {
1450#define TEST_BYTE(n, v) StartSeh() ok_hex(Bytes[n], v); EndSeh(STATUS_SUCCESS);
1451#define TEST_WRITE(n) StartSeh() *(volatile UCHAR *)&Bytes[n] = Bytes[n]; EndSeh(STATUS_SUCCESS);
1452#define TEST_NOWRITE(n) StartSeh() *(volatile UCHAR *)&Bytes[n] = Bytes[n]; EndSeh(STATUS_ACCESS_VIOLATION);
1453 TEST_NOWRITE(0x2000);
1454 TEST_BYTE(0x2000, 0xc3);
1455 TEST_BYTE(0x2001, 0x00);
1456 TEST_NOWRITE(0x4000);
1457 TEST_BYTE(0x4000, 0x01);
1458 TEST_BYTE(0x4001, 0x23);
1459 TEST_BYTE(0x4007, 0xef);
1460 TEST_BYTE(0x4008, 0xaa);
1461 TEST_BYTE(0x4010, 0xbb);
1462 TEST_BYTE(0x4020, 0xcc);
1463 TEST_BYTE(0x4040, 0xdd);
1464 TEST_BYTE(0x4080, 0xee);
1465 TEST_BYTE(0x40c0, 0xff);
1466 TEST_BYTE(0x40ff, 0xff);
1467 TEST_BYTE(0x4100, 0x00);
1468 TEST_BYTE(0x41ff, 0x00);
1469 TEST_NOWRITE(0x6000);
1470 TEST_BYTE(0x6000, 0xee);
1471 TEST_BYTE(0x60ff, 0x55);
1472 TEST_BYTE(0x6100, 0xee);
1473 TEST_BYTE(0x63ff, 0xdd);
1474 TEST_BYTE(0x6400, 0x00);
1475 TEST_WRITE(0x8000);
1476 TEST_BYTE(0x8000, 0x11);
1477 TEST_BYTE(0x8400, 0x33);
1478#undef TEST_BYTE
1479#undef TEST_WRITE
1480#undef TEST_NOWRITE
1483 }
1484 Status = NtClose(SectionHandle);
1486 }
1487
1490}
1491
1493{
1502 BYTE pad[448];
1507{
1508 /* IMAGE_DOS_HEADER */
1509 {
1510 IMAGE_DOS_SIGNATURE, 144, 3, 0, 4, 0, 0xFFFF, 0, 0xB8, 0, 0, 0, 0x40,
1511 0, { 0 }, 0, 0, { 0 }, 0x80
1512 },
1513 /* binary to print "This program cannot be run in DOS mode." */
1514 {
1515 0x1F0E, 0x0EBA, 0xB400, 0xCD09, 0xB821, 0x4C01, 0x21CD, 0x6854, 0x7369,
1516 0x7020, 0x6F72, 0x7267, 0x6D61, 0x6320, 0x6E61, 0x6F6E, 0x2074, 0x6562,
1517 0x7220, 0x6E75, 0x6920, 0x206E, 0x4F44, 0x2053, 0x6F6D, 0x6564, 0x0D2E,
1518 0x0A0D, 0x0024, 0x0000, 0x0000, 0x0000
1519 },
1520 /* IMAGE_NT_HEADERS32 */
1521 {
1522 IMAGE_NT_SIGNATURE, /* Signature */
1523 /* IMAGE_FILE_HEADER */
1524 {
1525 IMAGE_FILE_MACHINE_I386, /* Machine */
1526 5, /* NumberOfSections */
1527 0x47EFDF09, /* TimeDateStamp */
1528 0, /* PointerToSymbolTable */
1529 0, /* NumberOfSymbols */
1530 0xE0, /* SizeOfOptionalHeader */
1533 IMAGE_FILE_DLL, /* Characteristics */
1534 },
1535 /* IMAGE_OPTIONAL_HEADER32 */
1536 {
1538 8, /* MajorLinkerVersion */
1539 0, /* MinorLinkerVersion */
1540 0x400, /* SizeOfCode */
1541 0x000, /* SizeOfInitializedData */
1542 0, /* SizeOfUninitializedData */
1543 0x1000, /* AddressOfEntryPoint */
1544 0x1000, /* BaseOfCode */
1545 0x0000, /* BaseOfData */
1546 0x400000, /* ImageBase */
1547 0x1000, /* SectionAlignment */
1548 0x200, /* FileAlignment */
1549 4, /* MajorOperatingSystemVersion */
1550 0, /* MinorOperatingSystemVersion */
1551 0, /* MajorImageVersion */
1552 0, /* MinorImageVersion */
1553 4, /* MajorSubsystemVersion */
1554 0, /* MinorSubsystemVersion */
1555 0, /* Win32VersionValue */
1556 0x6000, /* SizeOfImage */
1557 0x400, /* SizeOfHeaders */
1558 0x0, /* CheckSum */
1559 IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
1562 IMAGE_DLLCHARACTERISTICS_NX_COMPAT, /* DllCharacteristics */
1563 0x100000, /* SizeOfStackReserve */
1564 0x1000, /* SizeOfStackCommit */
1565 0x100000, /* SizeOfHeapReserve */
1566 0x1000, /* SizeOfHeapCommit */
1567 0, /* LoaderFlags */
1568 0x10, /* NumberOfRvaAndSizes */
1569 /* IMAGE_DATA_DIRECTORY */
1570 {
1571 { 0 }, /* Export Table */
1572 { 0 }, /* Import Table */
1573 { 0 }, /* Resource Table */
1574 { 0 }, /* Exception Table */
1575 { 0 }, /* Certificate Table */
1576 { 0 }, /* Base Relocation Table */
1577 { 0 }, /* Debug */
1578 { 0 }, /* Copyright */
1579 { 0 }, /* Global Ptr */
1580 { 0 }, /* TLS Table */
1581 { 0 }, /* Load Config Table */
1582 { 0 }, /* Bound Import */
1583 { 0 }, /* IAT */
1584 { 0 }, /* Delay Import Descriptor */
1585 { 0 }, /* CLI Header */
1586 { 0 } /* Reserved */
1587 }
1588 }
1589 },
1590 /* IMAGE_SECTION_HEADER */
1591 {
1592 /* SizeOfRawData larger than VirtualSize */
1593 ".text", /* Name */
1594 { 0x1000 }, /* Misc.VirtualSize */
1595 0x1000, /* VirtualAddress */
1596 0x1200, /* SizeOfRawData */
1597 0x400, /* PointerToRawData */
1598 0, /* PointerToRelocations */
1599 0, /* PointerToLinenumbers */
1600 0, /* NumberOfRelocations */
1601 0, /* NumberOfLinenumbers */
1603 IMAGE_SCN_CNT_CODE, /* Characteristics */
1604 },
1605 /* IMAGE_SECTION_HEADER */
1606 {
1607 /* SizeOfRawData larger than VirtualSize */
1608 ".data", /* Name */
1609 { 0x100 }, /* Misc.VirtualSize */
1610 0x2000, /* VirtualAddress */
1611 0x1200, /* SizeOfRawData */
1612 0x1600, /* PointerToRawData */
1613 0, /* PointerToRelocations */
1614 0, /* PointerToLinenumbers */
1615 0, /* NumberOfRelocations */
1616 0, /* NumberOfLinenumbers */
1618 IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1619 },
1620 /* IMAGE_SECTION_HEADER */
1621 {
1622 /* SizeOfRawData = 0 */
1623 ".zdata", /* Name */
1624 { 0x100 }, /* Misc.VirtualSize */
1625 0x3000, /* VirtualAddress */
1626 0, /* SizeOfRawData */
1627 0x2800, /* PointerToRawData */
1628 0, /* PointerToRelocations */
1629 0, /* PointerToLinenumbers */
1630 0, /* NumberOfRelocations */
1631 0, /* NumberOfLinenumbers */
1633 IMAGE_SCN_CNT_UNINITIALIZED_DATA, /* Characteristics */
1634 },
1635 /* IMAGE_SECTION_HEADER */
1636 {
1637 /* VirtualSize larger than SizeOfRawData */
1638 ".rsrc", /* Name */
1639 { 0x300 }, /* Misc.VirtualSize */
1640 0x4000, /* VirtualAddress */
1641 0x200, /* SizeOfRawData */
1642 0x2800, /* PointerToRawData */
1643 0, /* PointerToRelocations */
1644 0, /* PointerToLinenumbers */
1645 0, /* NumberOfRelocations */
1646 0, /* NumberOfLinenumbers */
1648 IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1649 },
1650 /* IMAGE_SECTION_HEADER */
1651 {
1652 /* PointerToRawData = 0 while SizeOfRawData != 0, CORE-18797 */
1653 ".bss", /* Name */
1654 { 0x400 }, /* Misc.VirtualSize */
1655 0x5000, /* VirtualAddress */
1656 0x600, /* SizeOfRawData */
1657 0, /* PointerToRawData */
1658 0, /* PointerToRelocations */
1659 0, /* PointerToLinenumbers */
1660 0, /* NumberOfRelocations */
1661 0, /* NumberOfLinenumbers */
1663 IMAGE_SCN_CNT_UNINITIALIZED_DATA, /* Characteristics */
1664 },
1665 /* fill */
1666 { 0 },
1667 /* text */
1668 {
1669 0xc3, 0, 0, 0, 0, 0, 0, 0,
1670 BYTES8(1),
1671 BYTES16(2),
1672 BYTES32(3),
1673 BYTES64(4),
1674 BYTES128(5),
1675 BYTES256(6),
1676 BYTES512(7),
1677 BYTES1024(8),
1678 BYTES1024(9),
1679 BYTES1024(0xa),
1680 BYTES512(0xb),
1681 },
1682 /* data */
1683 {
1684 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1685 BYTES8(0xaa),
1686 BYTES16(0xbb),
1687 BYTES32(0xcc),
1688 BYTES64(0xdd),
1689 BYTES128(0xee),
1690 BYTES256(0xff),
1691 BYTES512(0xee),
1692 BYTES1024(0xdd),
1693 BYTES1024(0xcc),
1694 BYTES1024(0xbb),
1695 BYTES512(0xaa),
1696 },
1697 /* rsrc */
1698 {
1699 BYTES256(0xff),
1700 BYTES128(0xee),
1701 BYTES64(0xdd),
1702 BYTES32(0xcc),
1703 BYTES16(0xbb),
1704 BYTES8(0xaa),
1705 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01,
1706 },
1708
1709C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, text_data) == 0x400);
1710C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, data_data) == 0x1600);
1711C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, rsrc_data) == 0x2800);
1712
1713// CORE-17284
1714static
1715void
1717{
1719 WCHAR TempPath[MAX_PATH];
1721 HANDLE Handle;
1722 HANDLE SectionHandle;
1726 ULONG Written;
1727 ULONG Length;
1728 BOOL Success;
1729
1730 Length = GetTempPathW(MAX_PATH, TempPath);
1731 ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1732 Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1733 ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1736 0,
1737 NULL,
1739 0,
1740 NULL);
1742 {
1743 skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1744 return;
1745 }
1746 RawSizeImageFile.nthdrs.OptionalHeader.ImageBase = 0xe400000;
1747 if (TestNumber == 1)
1748 {
1749 /* Just for fun, show that these flags don't matter. */
1754 }
1755 else if (TestNumber == 2)
1756 {
1757 /* SizeOfRawData is too large and will overflow.
1758 * This should cause failure to load the file */
1759 RawSizeImageFile.rsrc_header.SizeOfRawData = (ULONG)-0x200;
1760 }
1761
1764 sizeof(RawSizeImageFile),
1765 &Written,
1766 NULL);
1767 ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1768 ok(Written == sizeof(RawSizeImageFile), "WriteFile wrote %lu bytes\n", Written);
1769
1770 Status = NtCreateSection(&SectionHandle,
1772 NULL,
1773 NULL,
1775 SEC_IMAGE,
1776 Handle);
1777 if (TestNumber == 2)
1778 {
1779 /* overflow in SizeOfRawData */
1781 }
1782 else
1783 {
1785 }
1786
1787 if (NT_SUCCESS(Status))
1788 {
1789 /* Map the section with */
1790 BaseAddress = NULL;
1791 SectionOffset.QuadPart = 0;
1792 ViewSize = 0;
1793 Status = NtMapViewOfSection(SectionHandle,
1795 &BaseAddress,
1796 0,
1797 0,
1799 &ViewSize,
1800 ViewShare,
1801 0,
1804 if (NT_SUCCESS(Status))
1805 {
1808
1809 /* .text section header is unmodified */
1810 ok_hex(ImageFile->text_header.Misc.VirtualSize, RawSizeImageFile.text_header.Misc.VirtualSize);
1811 ok_hex(ImageFile->text_header.VirtualAddress, RawSizeImageFile.text_header.VirtualAddress);
1812 ok_hex(ImageFile->text_header.SizeOfRawData, RawSizeImageFile.text_header.SizeOfRawData);
1813 ok_hex(ImageFile->text_header.PointerToRawData, RawSizeImageFile.text_header.PointerToRawData);
1814
1815 /* SizeOfRawData = 0 resets PointerToRawData to 0 */
1816 ok_hex(ImageFile->zdata_header.Misc.VirtualSize, RawSizeImageFile.zdata_header.Misc.VirtualSize);
1817 ok_hex(ImageFile->zdata_header.VirtualAddress, RawSizeImageFile.zdata_header.VirtualAddress);
1818 ok_hex(ImageFile->zdata_header.SizeOfRawData, RawSizeImageFile.zdata_header.SizeOfRawData);
1819 ok_hex(ImageFile->zdata_header.PointerToRawData, 0);
1820
1821 /* .bss section is unmodified */
1822 ok_hex(ImageFile->bss_header.SizeOfRawData, 0x600);
1823 ok_hex(ImageFile->bss_header.PointerToRawData, 0);
1824
1825#define TEST_BYTE(n, v) \
1826 StartSeh() \
1827 ok(Bytes[n] == v, "[%lu] Bytes[%u] = 0x%x, expected 0x%x\n", \
1828 TestNumber, n, Bytes[n], v); \
1829 EndSeh(STATUS_SUCCESS);
1830 /* .text section data matches file up to 0x1000 */
1831 TEST_BYTE(0x1000, 0xc3);
1832 TEST_BYTE(0x1001, 0x00);
1833 TEST_BYTE(0x1008, 0x01);
1834 TEST_BYTE(0x1010, 0x02);
1835 TEST_BYTE(0x1fff, 0x0a);
1836
1837 /* .data section data matches file up to 0x1000 */
1838 TEST_BYTE(0x2000, 0x01);
1839 TEST_BYTE(0x2001, 0x23);
1840 TEST_BYTE(0x20ff, 0xee);
1841 TEST_BYTE(0x2100, 0xff);
1842 TEST_BYTE(0x2fff, 0xbb);
1843
1844 /* .zdata section data is all zeroes */
1845 TEST_BYTE(0x3000, 0x00);
1846 TEST_BYTE(0x3001, 0x00);
1847 TEST_BYTE(0x3800, 0x00);
1848 TEST_BYTE(0x3fff, 0x00);
1849
1850 /* .rsrc section data matches file up to VirtualSize 0x200 */
1851 TEST_BYTE(0x4000, 0xff);
1852 TEST_BYTE(0x4100, 0xee);
1853 TEST_BYTE(0x4180, 0xdd);
1854 TEST_BYTE(0x41c0, 0xcc);
1855 TEST_BYTE(0x41e0, 0xbb);
1856 TEST_BYTE(0x41f0, 0xaa);
1857 TEST_BYTE(0x41fe, 0x23);
1858 TEST_BYTE(0x41ff, 0x01);
1859 TEST_BYTE(0x4200, 0x00);
1860 TEST_BYTE(0x4fff, 0x00);
1861#undef TEST_BYTE
1864 }
1865 Status = NtClose(SectionHandle);
1867 }
1868
1871}
1872
1873static void
1875{
1877 WCHAR TempPath[MAX_PATH];
1879 HANDLE Handle;
1880 HANDLE SectionHandle;
1881 ULONG Length;
1882
1883 Length = GetTempPathW(MAX_PATH, TempPath);
1884 ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1885 Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1886 ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1889 0,
1890 NULL,
1892 0,
1893 NULL);
1895 {
1896 skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1897 return;
1898 }
1899
1900 Status = NtCreateSection(&SectionHandle,
1904
1905 if (NT_SUCCESS(Status))
1906 NtClose(SectionHandle);
1907
1908 Status = NtCreateSection(&SectionHandle,
1912
1913 if (NT_SUCCESS(Status))
1914 NtClose(SectionHandle);
1915
1918}
1919
1920// CORE-11206
1921static void
1923{
1924 WCHAR TempPath[MAX_PATH];
1927 SIZE_T ViewSize = 0;
1928 HANDLE Handle;
1929 HANDLE SectionHandle;
1930
1931 SIZE_T Length;
1932 BOOL Success;
1933 DWORD Written, Error;
1935
1936 Length = GetTempPathW(MAX_PATH, TempPath);
1937 ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1938 Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1939 ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1941
1942 Success = WriteFile(Handle, "TESTDATA", 8, &Written, NULL);
1943 ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1944 ok(Written == 8, "WriteFile wrote %lu bytes\n", Written);
1945
1946 Written = SetFilePointer(Handle, 6, NULL, FILE_BEGIN);
1947 ok(Written == 6, "SetFilePointer returned %lu bytes\n", Written);
1949 ok(Success == TRUE, "SetEndOfFile failed with %lu\n", GetLastError());
1950
1951 Status = NtCreateSection(&SectionHandle,
1955 BaseAddress = NULL;
1956 ViewSize = 0;
1957 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0,
1958 0, 0, &ViewSize, ViewShare, 0, PAGE_READONLY);
1960
1961 if (BaseAddress)
1962 {
1963 // First we test data that was truncated even before the file mapping was opened
1964 Length = strlen((char*)BaseAddress);
1965 ok(Length == 6, "Old data was not properly erased! (Length=%lu)\n", Length);
1966 }
1967
1968 // Now we truncate the file on disk some more
1969 Written = SetFilePointer(Handle, 4, NULL, FILE_BEGIN);
1970 ok(Written == 4, "SetFilePointer returned %lu bytes\n", Written);
1972 Error = GetLastError();
1973 ok(Success == FALSE, "SetEndOfFile succeeded\n");
1974 ok(Error == ERROR_USER_MAPPED_FILE, "SetEndOfFile did not set error to ERROR_USER_MAPPED_FILE (%lu)\n", Error);
1975
1976 if (BaseAddress)
1977 {
1978 Length = strlen((char*)BaseAddress);
1979 ok(Length == 6, "Length should not have changed! (Length=%lu)\n", Length);
1980 }
1981
1982 // Unmap and set the end shorter.
1985 Success = CloseHandle(SectionHandle);
1986 ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1987
1988 Written = SetFilePointer(Handle, 4, NULL, FILE_BEGIN);
1989 ok(Written == 4, "SetFilePointer returned %lu bytes\n", Written);
1991 ok(Success == TRUE, "SetEndOfFile failed with %lu\n", GetLastError());
1992
1993 Status = NtCreateSection(&SectionHandle,
1997 BaseAddress = NULL;
1998 ViewSize = 0;
1999 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0,
2000 0, 0, &ViewSize, ViewShare, 0, PAGE_READONLY);
2002
2003 // CLEANUP
2006 Success = CloseHandle(SectionHandle);
2007 ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
2009 ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
2010
2012 ok(Success == TRUE, "DeleteFileW failed with %lu\n", GetLastError());
2013}
2014
2016{
2022 Test_RawSize(0);
2023 Test_RawSize(1);
2024 Test_RawSize(2);
2026 Test_Truncate();
2027}
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3848
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3441
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3622
#define BYTES512(x)
#define BYTES256(x)
#define BYTES128(x)
#define BYTES32(x)
#define BYTES1024(x)
void Test_ImageSection2(void)
#define TEST_WRITE(n)
static void Test_SectionContents(BOOL Relocate)
#define TEST_NOWRITE(n)
void Test_PageFileSection(void)
#define BYTES64(x)
#define TEST_BYTE(n, v)
void Test_ImageSection(void)
static void Test_EmptyFile(VOID)
#define BYTES8(x)
static struct _SECTION_CONTENTS_IMAGE_FILE SectionContentsImageFile
void Test_BasedSection(void)
static struct _RAW_SIZE_IMAGE_FILE RawSizeImageFile
static void Test_RawSize(ULONG TestNumber)
static void Test_Truncate(VOID)
#define BYTES16(x)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
BOOL Error
Definition: chkdsk.c:66
#define MAXULONG_PTR
Definition: basetsd.h:103
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const char * wine_dbgstr_wn(const WCHAR *str, int n)
Definition: compat.c:367
#define CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define FILE_BEGIN
Definition: compat.h:761
#define SECTION_MAP_READ
Definition: compat.h:139
#define wcsrchr
Definition: compat.h:16
#define SetFilePointer
Definition: compat.h:743
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
#define UlongToPtr(u)
Definition: config.h:106
#define PAGE_SIZE
Definition: env_spec_w32.h:49
@ Success
Definition: eventcreate.c:712
struct _FileName FileName
Definition: fatprocs.h:896
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define printf
Definition: freeldr.h:97
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
static PWSTR ImageFile
Definition: imagefile.c:10
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define C_ASSERT(e)
Definition: intsafe.h:73
_In_ UINT Bytes
Definition: mmcopy.h:9
#define CREATE_ALWAYS
Definition: disk.h:72
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:362
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR ZeroBits
Definition: mmfuncs.h:405
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:407
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define SEC_COMMIT
Definition: mmtypes.h:100
#define SEC_IMAGE
Definition: mmtypes.h:97
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define SYNCHRONIZE
Definition: nt_native.h:61
#define MEM_DECOMMIT
Definition: nt_native.h:1315
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SECTION_QUERY
Definition: nt_native.h:1287
#define SEC_RESERVE
Definition: nt_native.h:1323
#define NtCurrentProcess()
Definition: nt_native.h:1657
@ ViewShare
Definition: nt_native.h:1278
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define MEM_RESERVE
Definition: nt_native.h:1314
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define MEM_RELEASE
Definition: nt_native.h:1316
#define GENERIC_WRITE
Definition: nt_native.h:90
#define MEM_COMMIT
Definition: nt_native.h:1313
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define SEC_BASED
#define IMAGE_SCN_MEM_WRITE
Definition: ntimage.h:241
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: ntimage.h:376
#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_SCN_CNT_CODE
Definition: ntimage.h:230
#define IMAGE_SCN_MEM_EXECUTE
Definition: ntimage.h:239
#define IMAGE_DLLCHARACTERISTICS_NO_SEH
Definition: ntimage.h:459
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: ntimage.h:232
#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
Definition: ntimage.h:455
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5230
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:3111
NTSTATUS NTAPI NtFlushVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN OUT PSIZE_T NumberOfBytesToFlush, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: virtual.c:4035
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4492
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:268
#define STATUS_MAPPED_ALIGNMENT
Definition: ntstatus.h:676
#define STATUS_SECTION_PROTECTION
Definition: ntstatus.h:314
#define STATUS_UNABLE_TO_DELETE_SECTION
Definition: ntstatus.h:264
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH
Definition: ntstatus.h:128
#define STATUS_INVALID_PARAMETER_9
Definition: ntstatus.h:483
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:539
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:522
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:300
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#define STATUS_IMAGE_NOT_AT_BASE
Definition: ntstatus.h:117
#define STATUS_COMMITMENT_LIMIT
Definition: ntstatus.h:537
#define L(x)
Definition: ntvdm.h:50
#define IMAGE_SCN_TYPE_NOLOAD
Definition: pecoff.h:20
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED
Definition: pedump.c:162
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_FILE_DLL
Definition: pedump.c:169
#define IMAGE_FILE_LINE_NUMS_STRIPPED
Definition: pedump.c:161
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
#define IMAGE_FILE_32BIT_MACHINE
Definition: pedump.c:164
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
int __cdecl system(_In_opt_z_ const char *_Command)
#define STATUS_SUCCESS
Definition: shellext.h:65
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
IMAGE_NT_HEADERS32 nthdrs
IMAGE_SECTION_HEADER zdata_header
IMAGE_SECTION_HEADER data_header
IMAGE_SECTION_HEADER bss_header
IMAGE_SECTION_HEADER text_header
IMAGE_SECTION_HEADER rsrc_header
IMAGE_SECTION_HEADER rossym_header
IMAGE_SECTION_HEADER text_header
IMAGE_SECTION_HEADER rsrc_header
Definition: stubgen.c:11
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PWDFDEVICE_INIT _In_ PWDF_FILEOBJECT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES FileObjectAttributes
Definition: wdfdevice.h:3400
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetModuleHandle
Definition: winbase.h:3827
#define ERROR_USER_MAPPED_FILE
Definition: winerror.h:727
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193