ReactOS  0.4.15-dev-2771-g6d441f7
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 
13 void
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,
28  &MaximumSize,
30  SEC_COMMIT,
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,
42  &BaseAddress,
43  0,
44  0,
46  &ViewSize,
47  ViewShare,
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,
58  &BaseAddress,
59  0,
60  0,
62  &ViewSize,
63  ViewShare,
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,
74  &BaseAddress,
75  0,
76  PAGE_SIZE,
78  &ViewSize,
79  ViewShare,
80  MEM_COMMIT,
83 
84  /* Try to map 1 page, with free base address and zero bits compatible with 64k granularity */
85  BaseAddress = NULL;
86  SectionOffset.QuadPart = 0;
87  ViewSize = 0x1000;
88  Status = NtMapViewOfSection(SectionHandle,
90  &BaseAddress,
91  10,
92  0,
94  &ViewSize,
95  ViewShare,
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 */
117  BaseAddress = NULL;
118  SectionOffset.QuadPart = 0;
119  ViewSize = 0x1000;
120  Status = NtMapViewOfSection(SectionHandle,
122  &BaseAddress,
123  11,
124  0,
125  &SectionOffset,
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,
138  &BaseAddress,
139  2,
140  0,
141  &SectionOffset,
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,
156  &BaseAddress,
157  3,
158  0,
159  &SectionOffset,
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,
172  &BaseAddress,
173  0,
174  0,
175  &SectionOffset,
176  &ViewSize,
177  ViewShare,
178  0,
181 
182  /* We must be able to access the memory */
183  _SEH2_TRY
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;
197  &BaseAddress,
198  0,
199  &ViewSize,
200  MEM_COMMIT,
203 
204  /* Try to decommit a page in the section */
206  &BaseAddress,
207  &ViewSize,
208  MEM_DECOMMIT);
210 
211  /* Try to commit a range larger than the section */
212  BaseAddress = (PVOID)0x30000000;
213  ViewSize = 0x3000;
215  &BaseAddress,
216  0,
217  &ViewSize,
218  MEM_COMMIT,
221 
222  /* Try to commit a page after the section */
223  BaseAddress = (PVOID)0x30002000;
224  ViewSize = 0x1000;
226  &BaseAddress,
227  0,
228  &ViewSize,
229  MEM_COMMIT,
232 
233  /* Try to allocate a page after the section */
234  BaseAddress = (PVOID)0x30002000;
235  ViewSize = 0x1000;
237  &BaseAddress,
238  0,
239  &ViewSize,
243 
244  /* Need to go to next 64k boundary */
245  BaseAddress = (PVOID)0x30010000;
246  ViewSize = 0x1000;
248  &BaseAddress,
249  0,
250  &ViewSize,
254  if (!NT_SUCCESS(Status))
255  return;
256 
257  /* Free the allocation */
258  BaseAddress = (PVOID)0x30010000;
259  ViewSize = 0x1000;
261  &BaseAddress,
262  &ViewSize,
263  MEM_RELEASE);
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;
270  &BaseAddress,
271  &ViewSize,
272  MEM_RELEASE);
274 
275  /* Commit a page in the section */
276  BaseAddress = (PVOID)0x30001000;
277  ViewSize = 0x1000;
279  &BaseAddress,
280  0,
281  &ViewSize,
282  MEM_COMMIT,
285 
286  /* Try to decommit the page */
287  BaseAddress = (PVOID)0x30001000;
288  ViewSize = 0x1000;
290  &BaseAddress,
291  &ViewSize,
292  MEM_DECOMMIT);
294 
295  BaseAddress = UlongToPtr(0x40000000);
296  SectionOffset.QuadPart = 0;
297  ViewSize = 0x1000;
298  Status = NtMapViewOfSection(SectionHandle,
300  &BaseAddress,
301  0,
302  0,
303  &SectionOffset,
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,
319  &BaseAddress,
320  0,
321  0,
322  &SectionOffset,
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;
334  &BaseAddress,
335  0,
336  &ViewSize,
337  MEM_COMMIT,
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,
355  &MaximumSize,
357  SEC_RESERVE,
358  NULL);
360 
361  /* Try to map 1 page, passing MEM_RESERVE */
362  BaseAddress = NULL;
363  SectionOffset.QuadPart = 0;
365  Status = NtMapViewOfSection(SectionHandle,
367  &BaseAddress,
368  0,
369  PAGE_SIZE,
370  &SectionOffset,
371  &ViewSize,
372  ViewShare,
373  MEM_RESERVE,
376 
377  /* Try to map 1 page using MEM_COMMIT */
378  BaseAddress = NULL;
379  SectionOffset.QuadPart = 0;
381  Status = NtMapViewOfSection(SectionHandle,
383  &BaseAddress,
384  0,
385  PAGE_SIZE,
386  &SectionOffset,
387  &ViewSize,
388  ViewShare,
389  MEM_COMMIT,
392 
393  /* Map 2 pages, but commit 1 */
394  BaseAddress = NULL;
395  SectionOffset.QuadPart = 0;
396  ViewSize = 2 * PAGE_SIZE;
397  Status = NtMapViewOfSection(SectionHandle,
399  &BaseAddress,
400  0,
401  PAGE_SIZE,
402  &SectionOffset,
403  &ViewSize,
404  ViewShare,
405  0,
408 
409  /* We must be able to access the 1st page */
411  _SEH2_TRY
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 */
424  _SEH2_TRY
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,
442  &SectionOffset,
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,
456  MEM_COMMIT,
457  PAGE_READONLY);
459 
460  /* Try to commit again (the already committed page) */
462  &BaseAddress2,
463  0,
464  &ViewSize,
465  MEM_COMMIT,
466  PAGE_READONLY);
468 
469  /* We must be able to access the memory in the 2nd page of the 1st memory location */
471  _SEH2_TRY
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,
497  &MaximumSize,
499  SEC_COMMIT,
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,
508  &MaximumSize,
510  SEC_COMMIT,
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,
519  &MaximumSize,
521  SEC_RESERVE,
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,
536  &MaximumSize,
538  SEC_RESERVE,
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,
547  &MaximumSize,
549  SEC_RESERVE,
550  NULL);
552 
553  /* Pass a too large region size */
554  BaseAddress = NULL;
555  SectionOffset.QuadPart = 0;
557  Status = NtMapViewOfSection(SectionHandle,
559  &BaseAddress,
560  0,
561  0,
562  &SectionOffset,
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 */
576  BaseAddress = NULL;
577  SectionOffset.QuadPart = 0;
578  ViewSize = 0;
579  Status = NtMapViewOfSection(SectionHandle,
581  &BaseAddress,
582  0,
583  0,
584  &SectionOffset,
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 */
600  BaseAddress = NULL;
601  SectionOffset.QuadPart = 0;
602  ViewSize = 0x20000000;
603  Status = NtMapViewOfSection(SectionHandle,
605  &BaseAddress,
606  0,
607  0,
608  &SectionOffset,
609  &ViewSize,
610  ViewShare,
611  0,
612  PAGE_NOACCESS);
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 */
626  _SEH2_TRY
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 */
677  _SEH2_TRY
678  {
679  (void)(*(volatile char*)BaseAddress2);
680  }
682  {
684  }
685  _SEH2_END;
687 
688  /* Test write access */
690  _SEH2_TRY
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 */
709  _SEH2_TRY
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 
732 void
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 
765  &IoStatusBlock,
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
873  PAGE_READONLY);
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,
913  &IoStatusBlock);
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,
959  PAGE_READONLY);
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 
999 void
1001 {
1003  NTSTATUS Status;
1006  HANDLE FileHandle, ImageSectionHandle;
1007  PVOID ImageBase, BaseAddress;
1008  SIZE_T ViewSize;
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 
1029  &IoStatusBlock,
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,
1054  NtCurrentProcess(),
1055  &ImageBase,
1056  0,
1057  0,
1058  &SectionOffset,
1059  &ViewSize,
1060  ViewShare,
1061  0,
1062  PAGE_READWRITE);
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,
1077  PAGE_READWRITE);
1078  printf("allocation status: %lx\n", Status);
1079  system("PAUSE");
1080 
1081 }
1082 
1083 // doesn't work with WoW64!
1084 void
1086 {
1087  NTSTATUS Status;
1088  HANDLE SectionHandle1, SectionHandle2;
1090  PVOID BaseAddress1, BaseAddress2;
1091  SIZE_T ViewSize;
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,
1109  NtCurrentProcess(),
1110  &BaseAddress1,
1111  0,
1112  0,
1113  &SectionOffset,
1114  &ViewSize,
1115  ViewShare,
1116  0,
1117  PAGE_READWRITE);
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,
1140  NtCurrentProcess(),
1141  &BaseAddress2,
1142  0,
1143  0,
1144  &SectionOffset,
1145  &ViewSize,
1146  ViewShare,
1147  0,
1148  PAGE_READWRITE);
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 {
1173  WORD stub[32];
1179  BYTE pad[488];
1180  BYTE text_data[0x400];
1182  BYTE rsrc_data[0x400];
1183  BYTE clc_data[0x1000];
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  {
1215  IMAGE_NT_OPTIONAL_HDR32_MAGIC, /* Magic */
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  },
1361 };
1362 
1363 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, text_data) == 0x400);
1364 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, rossym_data) == 0x800);
1365 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, rsrc_data) == 0xc00);
1366 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, clc_data) == 0x1000);
1367 
1368 static
1369 void
1371 {
1372  NTSTATUS Status;
1373  WCHAR TempPath[MAX_PATH];
1375  HANDLE Handle;
1376  HANDLE SectionHandle;
1379  SIZE_T ViewSize;
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,
1392  CREATE_ALWAYS,
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 
1412  sizeof(SectionContentsImageFile),
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,
1434  NtCurrentProcess(),
1435  &BaseAddress,
1436  0,
1437  0,
1438  &SectionOffset,
1439  &ViewSize,
1440  ViewShare,
1441  0,
1442  PAGE_READWRITE);
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 {
1495  WORD stub[32];
1501  BYTE pad[488];
1502  BYTE text_data[0x1200];
1503  BYTE data_data[0x1200];
1504  BYTE rsrc_data[0x400];
1505 } RawSizeImageFile =
1506 {
1507  /* IMAGE_DOS_HEADER */
1508  {
1509  IMAGE_DOS_SIGNATURE, 144, 3, 0, 4, 0, 0xFFFF, 0, 0xB8, 0, 0, 0, 0x40,
1510  0, { 0 }, 0, 0, { 0 }, 0x80
1511  },
1512  /* binary to print "This program cannot be run in DOS mode." */
1513  {
1514  0x1F0E, 0x0EBA, 0xB400, 0xCD09, 0xB821, 0x4C01, 0x21CD, 0x6854, 0x7369,
1515  0x7020, 0x6F72, 0x7267, 0x6D61, 0x6320, 0x6E61, 0x6F6E, 0x2074, 0x6562,
1516  0x7220, 0x6E75, 0x6920, 0x206E, 0x4F44, 0x2053, 0x6F6D, 0x6564, 0x0D2E,
1517  0x0A0D, 0x0024, 0x0000, 0x0000, 0x0000
1518  },
1519  /* IMAGE_NT_HEADERS32 */
1520  {
1521  IMAGE_NT_SIGNATURE, /* Signature */
1522  /* IMAGE_FILE_HEADER */
1523  {
1524  IMAGE_FILE_MACHINE_I386, /* Machine */
1525  4, /* NumberOfSections */
1526  0x47EFDF09, /* TimeDateStamp */
1527  0, /* PointerToSymbolTable */
1528  0, /* NumberOfSymbols */
1529  0xE0, /* SizeOfOptionalHeader */
1532  IMAGE_FILE_DLL, /* Characteristics */
1533  },
1534  /* IMAGE_OPTIONAL_HEADER32 */
1535  {
1536  IMAGE_NT_OPTIONAL_HDR32_MAGIC, /* Magic */
1537  8, /* MajorLinkerVersion */
1538  0, /* MinorLinkerVersion */
1539  0x400, /* SizeOfCode */
1540  0x000, /* SizeOfInitializedData */
1541  0, /* SizeOfUninitializedData */
1542  0x1000, /* AddressOfEntryPoint */
1543  0x1000, /* BaseOfCode */
1544  0x0000, /* BaseOfData */
1545  0x400000, /* ImageBase */
1546  0x1000, /* SectionAlignment */
1547  0x200, /* FileAlignment */
1548  4, /* MajorOperatingSystemVersion */
1549  0, /* MinorOperatingSystemVersion */
1550  0, /* MajorImageVersion */
1551  0, /* MinorImageVersion */
1552  4, /* MajorSubsystemVersion */
1553  0, /* MinorSubsystemVersion */
1554  0, /* Win32VersionValue */
1555  0x5000, /* SizeOfImage */
1556  0x400, /* SizeOfHeaders */
1557  0x0, /* CheckSum */
1558  IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
1561  IMAGE_DLLCHARACTERISTICS_NX_COMPAT, /* DllCharacteristics */
1562  0x100000, /* SizeOfStackReserve */
1563  0x1000, /* SizeOfStackCommit */
1564  0x100000, /* SizeOfHeapReserve */
1565  0x1000, /* SizeOfHeapCommit */
1566  0, /* LoaderFlags */
1567  0x10, /* NumberOfRvaAndSizes */
1568  /* IMAGE_DATA_DIRECTORY */
1569  {
1570  { 0 }, /* Export Table */
1571  { 0 }, /* Import Table */
1572  { 0 }, /* Resource Table */
1573  { 0 }, /* Exception Table */
1574  { 0 }, /* Certificate Table */
1575  { 0 }, /* Base Relocation Table */
1576  { 0 }, /* Debug */
1577  { 0 }, /* Copyright */
1578  { 0 }, /* Global Ptr */
1579  { 0 }, /* TLS Table */
1580  { 0 }, /* Load Config Table */
1581  { 0 }, /* Bound Import */
1582  { 0 }, /* IAT */
1583  { 0 }, /* Delay Import Descriptor */
1584  { 0 }, /* CLI Header */
1585  { 0 } /* Reserved */
1586  }
1587  }
1588  },
1589  /* IMAGE_SECTION_HEADER */
1590  {
1591  /* SizeOfRawData larger than VirtualSize */
1592  ".text", /* Name */
1593  { 0x1000 }, /* Misc.VirtualSize */
1594  0x1000, /* VirtualAddress */
1595  0x1200, /* SizeOfRawData */
1596  0x400, /* PointerToRawData */
1597  0, /* PointerToRelocations */
1598  0, /* PointerToLinenumbers */
1599  0, /* NumberOfRelocations */
1600  0, /* NumberOfLinenumbers */
1602  IMAGE_SCN_CNT_CODE, /* Characteristics */
1603  },
1604  /* IMAGE_SECTION_HEADER */
1605  {
1606  /* SizeOfRawData larger than VirtualSize */
1607  ".data", /* Name */
1608  { 0x100 }, /* Misc.VirtualSize */
1609  0x2000, /* VirtualAddress */
1610  0x1200, /* SizeOfRawData */
1611  0x1600, /* PointerToRawData */
1612  0, /* PointerToRelocations */
1613  0, /* PointerToLinenumbers */
1614  0, /* NumberOfRelocations */
1615  0, /* NumberOfLinenumbers */
1617  IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1618  },
1619  /* IMAGE_SECTION_HEADER */
1620  {
1621  /* SizeOfRawData = 0 */
1622  ".zdata", /* Name */
1623  { 0x100 }, /* Misc.VirtualSize */
1624  0x3000, /* VirtualAddress */
1625  0, /* SizeOfRawData */
1626  0x2800, /* PointerToRawData */
1627  0, /* PointerToRelocations */
1628  0, /* PointerToLinenumbers */
1629  0, /* NumberOfRelocations */
1630  0, /* NumberOfLinenumbers */
1632  IMAGE_SCN_CNT_UNINITIALIZED_DATA, /* Characteristics */
1633  },
1634  /* IMAGE_SECTION_HEADER */
1635  {
1636  /* VirtualSize larger than SizeOfRawData */
1637  ".rsrc", /* Name */
1638  { 0x300 }, /* Misc.VirtualSize */
1639  0x4000, /* VirtualAddress */
1640  0x200, /* SizeOfRawData */
1641  0x2800, /* PointerToRawData */
1642  0, /* PointerToRelocations */
1643  0, /* PointerToLinenumbers */
1644  0, /* NumberOfRelocations */
1645  0, /* NumberOfLinenumbers */
1647  IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1648  },
1649  /* fill */
1650  { 0 },
1651  /* text */
1652  {
1653  0xc3, 0, 0, 0, 0, 0, 0, 0,
1654  BYTES8(1),
1655  BYTES16(2),
1656  BYTES32(3),
1657  BYTES64(4),
1658  BYTES128(5),
1659  BYTES256(6),
1660  BYTES512(7),
1661  BYTES1024(8),
1662  BYTES1024(9),
1663  BYTES1024(0xa),
1664  BYTES512(0xb),
1665  },
1666  /* data */
1667  {
1668  0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1669  BYTES8(0xaa),
1670  BYTES16(0xbb),
1671  BYTES32(0xcc),
1672  BYTES64(0xdd),
1673  BYTES128(0xee),
1674  BYTES256(0xff),
1675  BYTES512(0xee),
1676  BYTES1024(0xdd),
1677  BYTES1024(0xcc),
1678  BYTES1024(0xbb),
1679  BYTES512(0xaa),
1680  },
1681  /* rsrc */
1682  {
1683  BYTES256(0xff),
1684  BYTES128(0xee),
1685  BYTES64(0xdd),
1686  BYTES32(0xcc),
1687  BYTES16(0xbb),
1688  BYTES8(0xaa),
1689  0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01,
1690  },
1691 };
1692 
1693 C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, text_data) == 0x400);
1694 C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, data_data) == 0x1600);
1695 C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, rsrc_data) == 0x2800);
1696 
1697 // CORE-17284
1698 static
1699 void
1700 Test_RawSize(ULONG TestNumber)
1701 {
1702  NTSTATUS Status;
1703  WCHAR TempPath[MAX_PATH];
1705  HANDLE Handle;
1706  HANDLE SectionHandle;
1709  SIZE_T ViewSize;
1710  ULONG Written;
1711  ULONG Length;
1712  BOOL Success;
1713 
1714  Length = GetTempPathW(MAX_PATH, TempPath);
1715  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1716  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1717  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1720  0,
1721  NULL,
1722  CREATE_ALWAYS,
1723  0,
1724  NULL);
1726  {
1727  skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1728  return;
1729  }
1730  RawSizeImageFile.nthdrs.OptionalHeader.ImageBase = 0xe400000;
1731  if (TestNumber == 1)
1732  {
1733  /* Just for fun, show that these flags don't matter. */
1738  }
1739  else if (TestNumber == 2)
1740  {
1741  /* SizeOfRawData is too large and will overflow.
1742  * This should cause failure to load the file */
1743  RawSizeImageFile.rsrc_header.SizeOfRawData = (ULONG)-0x200;
1744  }
1745 
1748  sizeof(RawSizeImageFile),
1749  &Written,
1750  NULL);
1751  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1752  ok(Written == sizeof(RawSizeImageFile), "WriteFile wrote %lu bytes\n", Written);
1753 
1754  Status = NtCreateSection(&SectionHandle,
1756  NULL,
1757  NULL,
1759  SEC_IMAGE,
1760  Handle);
1761  if (TestNumber == 2)
1762  {
1763  /* overflow in SizeOfRawData */
1765  }
1766  else
1767  {
1769  }
1770 
1771  if (NT_SUCCESS(Status))
1772  {
1773  /* Map the section with */
1774  BaseAddress = NULL;
1775  SectionOffset.QuadPart = 0;
1776  ViewSize = 0;
1777  Status = NtMapViewOfSection(SectionHandle,
1778  NtCurrentProcess(),
1779  &BaseAddress,
1780  0,
1781  0,
1782  &SectionOffset,
1783  &ViewSize,
1784  ViewShare,
1785  0,
1786  PAGE_READWRITE);
1788  if (NT_SUCCESS(Status))
1789  {
1792 
1793  /* .text section header is unmodified */
1794  ok_hex(ImageFile->text_header.Misc.VirtualSize, RawSizeImageFile.text_header.Misc.VirtualSize);
1795  ok_hex(ImageFile->text_header.VirtualAddress, RawSizeImageFile.text_header.VirtualAddress);
1796  ok_hex(ImageFile->text_header.SizeOfRawData, RawSizeImageFile.text_header.SizeOfRawData);
1797  ok_hex(ImageFile->text_header.PointerToRawData, RawSizeImageFile.text_header.PointerToRawData);
1798 
1799  /* SizeOfRawData = 0 resets PointerToRawData to 0 */
1800  ok_hex(ImageFile->zdata_header.Misc.VirtualSize, RawSizeImageFile.zdata_header.Misc.VirtualSize);
1801  ok_hex(ImageFile->zdata_header.VirtualAddress, RawSizeImageFile.zdata_header.VirtualAddress);
1802  ok_hex(ImageFile->zdata_header.SizeOfRawData, RawSizeImageFile.zdata_header.SizeOfRawData);
1803  ok_hex(ImageFile->zdata_header.PointerToRawData, 0);
1804 
1805 #define TEST_BYTE(n, v) \
1806  StartSeh() \
1807  ok(Bytes[n] == v, "[%lu] Bytes[%u] = 0x%x, expected 0x%x\n", \
1808  TestNumber, n, Bytes[n], v); \
1809  EndSeh(STATUS_SUCCESS);
1810  /* .text section data matches file up to 0x1000 */
1811  TEST_BYTE(0x1000, 0xc3);
1812  TEST_BYTE(0x1001, 0x00);
1813  TEST_BYTE(0x1008, 0x01);
1814  TEST_BYTE(0x1010, 0x02);
1815  TEST_BYTE(0x1fff, 0x0a);
1816 
1817  /* .data section data matches file up to 0x1000 */
1818  TEST_BYTE(0x2000, 0x01);
1819  TEST_BYTE(0x2001, 0x23);
1820  TEST_BYTE(0x20ff, 0xee);
1821  TEST_BYTE(0x2100, 0xff);
1822  TEST_BYTE(0x2fff, 0xbb);
1823 
1824  /* .zdata section data is all zeroes */
1825  TEST_BYTE(0x3000, 0x00);
1826  TEST_BYTE(0x3001, 0x00);
1827  TEST_BYTE(0x3800, 0x00);
1828  TEST_BYTE(0x3fff, 0x00);
1829 
1830  /* .rsrc section data matches file up to VirtualSize 0x200 */
1831  TEST_BYTE(0x4000, 0xff);
1832  TEST_BYTE(0x4100, 0xee);
1833  TEST_BYTE(0x4180, 0xdd);
1834  TEST_BYTE(0x41c0, 0xcc);
1835  TEST_BYTE(0x41e0, 0xbb);
1836  TEST_BYTE(0x41f0, 0xaa);
1837  TEST_BYTE(0x41fe, 0x23);
1838  TEST_BYTE(0x41ff, 0x01);
1839  TEST_BYTE(0x4200, 0x00);
1840  TEST_BYTE(0x4fff, 0x00);
1841 #undef TEST_BYTE
1844  }
1845  Status = NtClose(SectionHandle);
1847  }
1848 
1851 }
1852 
1853 static void
1855 {
1856  NTSTATUS Status;
1857  WCHAR TempPath[MAX_PATH];
1859  HANDLE Handle;
1860  HANDLE SectionHandle;
1861  ULONG Length;
1862 
1863  Length = GetTempPathW(MAX_PATH, TempPath);
1864  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1865  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1866  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1869  0,
1870  NULL,
1871  CREATE_ALWAYS,
1872  0,
1873  NULL);
1875  {
1876  skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1877  return;
1878  }
1879 
1880  Status = NtCreateSection(&SectionHandle,
1882  0, 0, PAGE_READONLY, SEC_COMMIT, Handle);
1884 
1885  if (NT_SUCCESS(Status))
1886  NtClose(SectionHandle);
1887 
1888  Status = NtCreateSection(&SectionHandle,
1890  0, 0, PAGE_READONLY, SEC_IMAGE, Handle);
1892 
1893  if (NT_SUCCESS(Status))
1894  NtClose(SectionHandle);
1895 
1898 }
1899 
1900 // CORE-11206
1901 static void
1903 {
1904  WCHAR TempPath[MAX_PATH];
1906  NTSTATUS Status;
1907  SIZE_T ViewSize = 0;
1908  HANDLE Handle;
1909  HANDLE SectionHandle;
1910 
1911  SIZE_T Length;
1912  BOOL Success;
1913  DWORD Written, Error;
1914  VOID* BaseAddress;
1915 
1916  Length = GetTempPathW(MAX_PATH, TempPath);
1917  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1918  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1919  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1921 
1922  Success = WriteFile(Handle, "TESTDATA", 8, &Written, NULL);
1923  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1924  ok(Written == 8, "WriteFile wrote %lu bytes\n", Written);
1925 
1926  Written = SetFilePointer(Handle, 6, NULL, FILE_BEGIN);
1927  ok(Written == 6, "SetFilePointer returned %lu bytes\n", Written);
1929  ok(Success == TRUE, "SetEndOfFile failed with %lu\n", GetLastError());
1930 
1931  Status = NtCreateSection(&SectionHandle,
1933  0, 0, PAGE_READONLY, SEC_COMMIT, Handle);
1935  BaseAddress = NULL;
1936  ViewSize = 0;
1937  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0,
1938  0, 0, &ViewSize, ViewShare, 0, PAGE_READONLY);
1940 
1941  if (BaseAddress)
1942  {
1943  // First we test data that was truncated even before the file mapping was opened
1944  Length = strlen((char*)BaseAddress);
1945  ok(Length == 6, "Old data was not properly erased! (Length=%lu)\n", Length);
1946  }
1947 
1948  // Now we truncate the file on disk some more
1949  Written = SetFilePointer(Handle, 4, NULL, FILE_BEGIN);
1950  ok(Written == 4, "SetFilePointer returned %lu bytes\n", Written);
1952  Error = GetLastError();
1953  ok(Success == FALSE, "SetEndOfFile succeeded\n");
1954  ok(Error == ERROR_USER_MAPPED_FILE, "SetEndOfFile did not set error to ERROR_USER_MAPPED_FILE (%lu)\n", Error);
1955 
1956  if (BaseAddress)
1957  {
1958  Length = strlen((char*)BaseAddress);
1959  ok(Length == 6, "Length should not have changed! (Length=%lu)\n", Length);
1960  }
1961 
1962  // Unmap and set the end shorter.
1965  Success = CloseHandle(SectionHandle);
1966  ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1967 
1968  Written = SetFilePointer(Handle, 4, NULL, FILE_BEGIN);
1969  ok(Written == 4, "SetFilePointer returned %lu bytes\n", Written);
1971  ok(Success == TRUE, "SetEndOfFile failed with %lu\n", GetLastError());
1972 
1973  Status = NtCreateSection(&SectionHandle,
1975  0, 0, PAGE_READONLY, SEC_COMMIT, Handle);
1977  BaseAddress = NULL;
1978  ViewSize = 0;
1979  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0,
1980  0, 0, &ViewSize, ViewShare, 0, PAGE_READONLY);
1982 
1983  // CLEANUP
1986  Success = CloseHandle(SectionHandle);
1987  ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1989  ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1990 
1992  ok(Success == TRUE, "DeleteFileW failed with %lu\n", GetLastError());
1993 }
1994 
1996 {
2002  Test_RawSize(0);
2003  Test_RawSize(1);
2004  Test_RawSize(2);
2005  Test_EmptyFile();
2006  Test_Truncate();
2007 }
#define ERROR_USER_MAPPED_FILE
Definition: winerror.h:727
signed char * PCHAR
Definition: retypes.h:7
static PWSTR ImageFile
Definition: imagefile.c:10
IMAGE_SECTION_HEADER zdata_header
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR ZeroBits
Definition: mmfuncs.h:404
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3838
#define CloseHandle
Definition: compat.h:598
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
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:3431
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
static void Test_Truncate(VOID)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
IMAGE_SECTION_HEADER text_header
unsigned char * PUCHAR
Definition: retypes.h:3
#define SECTION_QUERY
Definition: nt_native.h:1287
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:3100
LONG NTSTATUS
Definition: precomp.h:26
static struct _SECTION_CONTENTS_IMAGE_FILE SectionContentsImageFile
Definition: stubgen.c:11
_In_ UINT Bytes
Definition: mmcopy.h:9
#define STATUS_INVALID_PARAMETER_9
Definition: ntstatus.h:483
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: ntimage.h:376
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240
IMAGE_SECTION_HEADER text_header
#define MAXULONG_PTR
Definition: basetsd.h:103
C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, text_data)==0x400)
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define BYTES256(x)
#define FILE_BEGIN
Definition: compat.h:620
#define BYTES64(x)
#define BYTES512(x)
#define IMAGE_DLLCHARACTERISTICS_NO_SEH
Definition: ntimage.h:459
#define BYTES128(x)
#define MEM_COMMIT
Definition: nt_native.h:1313
#define ok_hex(expression, result)
Definition: atltest.h:94
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define IMAGE_FILE_DLL
Definition: pedump.c:169
#define FILE_SHARE_READ
Definition: compat.h:136
_In_ PWDFDEVICE_INIT _In_ PWDF_FILEOBJECT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES FileObjectAttributes
Definition: wdfdevice.h:3395
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define SEC_BASED
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
#define MEM_DECOMMIT
Definition: nt_native.h:1315
HANDLE FileHandle
Definition: stats.c:38
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#define SEC_COMMIT
Definition: mmtypes.h:99
#define TEST_WRITE(n)
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
static struct _RAW_SIZE_IMAGE_FILE RawSizeImageFile
#define SEC_RESERVE
Definition: nt_native.h:1323
static void Test_RawSize(ULONG TestNumber)
#define GENERIC_WRITE
Definition: nt_native.h:90
IMAGE_SECTION_HEADER rossym_header
#define MEM_RESERVE
Definition: nt_native.h:1314
#define BYTES16(x)
#define STATUS_MAPPED_ALIGNMENT
Definition: ntstatus.h:676
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
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:3612
NTSTATUS NTAPI NtFlushVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN OUT PSIZE_T NumberOfBytesToFlush, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: virtual.c:4024
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:300
IMAGE_SECTION_HEADER rsrc_header
int __cdecl system(_In_opt_z_ const char *_Command)
void * PVOID
Definition: retypes.h:9
void Test_ImageSection2(void)
#define IMAGE_FILE_LINE_NUMS_STRIPPED
Definition: pedump.c:161
#define UlongToPtr(u)
Definition: config.h:106
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:404
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
Status
Definition: gdiplustypes.h:24
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:3951
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:539
#define IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: ntimage.h:231
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
void Test_PageFileSection(void)
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STATUS_SECTION_PROTECTION
Definition: ntstatus.h:314
BOOL Error
Definition: chkdsk.c:66
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
IMAGE_SECTION_HEADER data_header
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
#define IMAGE_SCN_MEM_WRITE
Definition: ntimage.h:241
#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH
Definition: ntstatus.h:128
static const WCHAR L[]
Definition: oid.c:1250
START_TEST(NtMapViewOfSection)
#define SECTION_MAP_READ
Definition: compat.h:139
#define STATUS_COMMITMENT_LIMIT
Definition: ntstatus.h:537
#define IMAGE_SCN_CNT_CODE
Definition: ntimage.h:230
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED
Definition: pedump.c:162
const char * wine_dbgstr_wn(const WCHAR *str, int n)
Definition: compat.c:367
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define GENERIC_READ
Definition: compat.h:135
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: ntimage.h:232
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
#define wcsrchr
Definition: compat.h:16
#define SYNCHRONIZE
Definition: nt_native.h:61
unsigned char BYTE
Definition: xxhash.c:193
#define BYTES1024(x)
#define BYTES32(x)
void Test_ImageSection(void)
void Test_BasedSection(void)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define STATUS_IMAGE_NOT_AT_BASE
Definition: ntstatus.h:117
#define IMAGE_SCN_TYPE_NOLOAD
Definition: pecoff.h:20
struct _FileName FileName
Definition: fatprocs.h:893
#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
Definition: ntimage.h:455
#define CREATE_ALWAYS
Definition: disk.h:72
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:268
_SEH2_END
Definition: create.c:4400
#define BYTES8(x)
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:4481
#define GetModuleHandle
Definition: winbase.h:3683
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define TEST_BYTE(n, v)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define ok(value,...)
Definition: atltest.h:57
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
IMAGE_SECTION_HEADER rsrc_header
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define MEM_RELEASE
Definition: nt_native.h:1316
_In_ HANDLE Handle
Definition: extypes.h:390
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
unsigned int ULONG
Definition: retypes.h:1
#define SEC_IMAGE
Definition: mmtypes.h:96
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static void Test_EmptyFile(VOID)
IMAGE_NT_HEADERS32 nthdrs
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define TEST_NOWRITE(n)
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:522
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
static void Test_SectionContents(BOOL Relocate)
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define STATUS_UNABLE_TO_DELETE_SECTION
Definition: ntstatus.h:264
#define SetFilePointer
Definition: compat.h:602
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)
#define IMAGE_SCN_MEM_EXECUTE
Definition: ntimage.h:239
#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT
Definition: ntimage.h:457
#define printf
Definition: config.h:203
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define IMAGE_FILE_32BIT_MACHINE
Definition: pedump.c:164
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204