ReactOS  0.4.15-dev-1200-gc3b3fcd
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 void
13 {
15  HANDLE SectionHandle;
17  PVOID BaseAddress, BaseAddress2;
19  ULONG OldProtect;
20 
21  /* Create a page file backed section with SEC_COMMIT */
22  MaximumSize.QuadPart = 0x20000;
23  Status = NtCreateSection(&SectionHandle,
25  NULL,
26  &MaximumSize,
28  SEC_COMMIT,
29  NULL);
31  if (!NT_SUCCESS(Status))
32  return;
33 
34  /* Try to map a page at an address that is not 64k aligned */
35  BaseAddress = (PVOID)0x30001000;
36  SectionOffset.QuadPart = 0;
37  ViewSize = 0x1000;
38  Status = NtMapViewOfSection(SectionHandle,
40  &BaseAddress,
41  0,
42  0,
44  &ViewSize,
45  ViewShare,
46  0,
49 
50  /* Try to map a page with execute rights */
51  BaseAddress = (PVOID)0x30000000;
52  SectionOffset.QuadPart = 0;
53  ViewSize = 0x1000;
54  Status = NtMapViewOfSection(SectionHandle,
56  &BaseAddress,
57  0,
58  0,
60  &ViewSize,
61  ViewShare,
62  0,
65 
66  /* Try to map 2 pages with MEM_COMMIT */
67  BaseAddress = (PVOID)0x30000000;
68  SectionOffset.QuadPart = 0;
69  ViewSize = 0x2000;
70  Status = NtMapViewOfSection(SectionHandle,
72  &BaseAddress,
73  0,
74  PAGE_SIZE,
76  &ViewSize,
77  ViewShare,
78  MEM_COMMIT,
81 
82  /* Try to map 1 page, with free base address and zero bits compatible with 64k granularity */
83  BaseAddress = NULL;
84  SectionOffset.QuadPart = 0;
85  ViewSize = 0x1000;
86  Status = NtMapViewOfSection(SectionHandle,
88  &BaseAddress,
89  10,
90  0,
92  &ViewSize,
93  ViewShare,
94  0,
99 
100 {
101  ULONG_PTR gran = 64 * 1024;
102  ULONG_PTR ZeroBits = 11;
103 
104  ok_hex(gran, 0x10000);
105  gran <<= ZeroBits;
106  ok_hex(gran, 0x8000000);
107  gran >>= ZeroBits;
108  ok_hex(gran, 0x10000);
109 
110  ok_hex((gran << ZeroBits) >> ZeroBits, gran);
111 
112 }
113 
114  /* Try to map 1 page, with free base address and zero bits incompatible with 64k granularity */
115  BaseAddress = NULL;
116  SectionOffset.QuadPart = 0;
117  ViewSize = 0x1000;
118  Status = NtMapViewOfSection(SectionHandle,
120  &BaseAddress,
121  11,
122  0,
123  &SectionOffset,
124  &ViewSize,
125  ViewShare,
126  0,
129 
130  /* Try to map 1 page, with base address and zero bits being compatible */
131  BaseAddress = (PVOID)0x30000000;
132  SectionOffset.QuadPart = 0;
133  ViewSize = 0x1000;
134  Status = NtMapViewOfSection(SectionHandle,
136  &BaseAddress,
137  2,
138  0,
139  &SectionOffset,
140  &ViewSize,
141  ViewShare,
142  0,
147 
148  /* Try to map 1 page, with base address and zero bits being incompatible */
149  BaseAddress = (PVOID)0x30000000;
150  SectionOffset.QuadPart = 0;
151  ViewSize = 0x1000;
152  Status = NtMapViewOfSection(SectionHandle,
154  &BaseAddress,
155  3,
156  0,
157  &SectionOffset,
158  &ViewSize,
159  ViewShare,
160  0,
163 
164  /* Map 2 pages, without MEM_COMMIT */
165  BaseAddress = (PVOID)0x30000000;
166  SectionOffset.QuadPart = 0;
167  ViewSize = 0x2000;
168  Status = NtMapViewOfSection(SectionHandle,
170  &BaseAddress,
171  0,
172  0,
173  &SectionOffset,
174  &ViewSize,
175  ViewShare,
176  0,
179 
180  /* We must be able to access the memory */
181  _SEH2_TRY
182  {
183  *(PULONG)BaseAddress = 1;
184  }
185  _SEH2_EXCEPT(1)
186  {
187  ok(FALSE, "Got an exception\n");
188  }
189  _SEH2_END;
190 
191  /* Commit a page in the section */
192  BaseAddress = (PVOID)0x30000000;
193  ViewSize = 0x1000;
195  &BaseAddress,
196  0,
197  &ViewSize,
198  MEM_COMMIT,
201 
202  /* Try to decommit a page in the section */
204  &BaseAddress,
205  &ViewSize,
206  MEM_DECOMMIT);
208 
209  /* Try to commit a range larger than the section */
210  BaseAddress = (PVOID)0x30000000;
211  ViewSize = 0x3000;
213  &BaseAddress,
214  0,
215  &ViewSize,
216  MEM_COMMIT,
219 
220  /* Try to commit a page after the section */
221  BaseAddress = (PVOID)0x30002000;
222  ViewSize = 0x1000;
224  &BaseAddress,
225  0,
226  &ViewSize,
227  MEM_COMMIT,
230 
231  /* Try to allocate a page after the section */
232  BaseAddress = (PVOID)0x30002000;
233  ViewSize = 0x1000;
235  &BaseAddress,
236  0,
237  &ViewSize,
241 
242  /* Need to go to next 64k boundary */
243  BaseAddress = (PVOID)0x30010000;
244  ViewSize = 0x1000;
246  &BaseAddress,
247  0,
248  &ViewSize,
252  if (!NT_SUCCESS(Status))
253  return;
254 
255  /* Free the allocation */
256  BaseAddress = (PVOID)0x30010000;
257  ViewSize = 0x1000;
259  &BaseAddress,
260  &ViewSize,
261  MEM_RELEASE);
262  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed with Status %lx\n", Status);
263 
264  /* Try to release the section mapping with NtFreeVirtualMemory */
265  BaseAddress = (PVOID)0x30000000;
266  ViewSize = 0x1000;
268  &BaseAddress,
269  &ViewSize,
270  MEM_RELEASE);
272 
273  /* Commit a page in the section */
274  BaseAddress = (PVOID)0x30001000;
275  ViewSize = 0x1000;
277  &BaseAddress,
278  0,
279  &ViewSize,
280  MEM_COMMIT,
283 
284  /* Try to decommit the page */
285  BaseAddress = (PVOID)0x30001000;
286  ViewSize = 0x1000;
288  &BaseAddress,
289  &ViewSize,
290  MEM_DECOMMIT);
292 
293  BaseAddress = UlongToPtr(0x40000000);
294  SectionOffset.QuadPart = 0;
295  ViewSize = 0x1000;
296  Status = NtMapViewOfSection(SectionHandle,
298  &BaseAddress,
299  0,
300  0,
301  &SectionOffset,
302  &ViewSize,
303  ViewShare,
304  0,
307  if (!NT_SUCCESS(Status))
308  return;
309 
310  ok(BaseAddress == UlongToPtr(0x40000000), "Invalid BaseAddress: %p\n", BaseAddress);
311 
312  BaseAddress = (PVOID)0x40080000;
313  SectionOffset.QuadPart = 0x10000;
314  ViewSize = 0x1000;
315  Status = NtMapViewOfSection(SectionHandle,
317  &BaseAddress,
318  0,
319  0,
320  &SectionOffset,
321  &ViewSize,
322  ViewShare,
323  0,
326 
327  ok(BaseAddress == (PVOID)0x40080000, "Invalid BaseAddress: %p\n", BaseAddress);
328 
329  /* Commit a page in the section */
330  BaseAddress = (PVOID)0x40000000;
332  &BaseAddress,
333  0,
334  &ViewSize,
335  MEM_COMMIT,
338 
339  /* Close the mapping */
342  BaseAddress = (PVOID)0x30000000;
345  Status = NtClose(SectionHandle);
347 
348  /* Create a page file backed section, but only reserved */
349  MaximumSize.QuadPart = 0x20000;
350  Status = NtCreateSection(&SectionHandle,
352  NULL,
353  &MaximumSize,
355  SEC_RESERVE,
356  NULL);
358 
359  /* Try to map 1 page, passing MEM_RESERVE */
360  BaseAddress = NULL;
361  SectionOffset.QuadPart = 0;
363  Status = NtMapViewOfSection(SectionHandle,
365  &BaseAddress,
366  0,
367  PAGE_SIZE,
368  &SectionOffset,
369  &ViewSize,
370  ViewShare,
371  MEM_RESERVE,
374 
375  /* Try to map 1 page using MEM_COMMIT */
376  BaseAddress = NULL;
377  SectionOffset.QuadPart = 0;
379  Status = NtMapViewOfSection(SectionHandle,
381  &BaseAddress,
382  0,
383  PAGE_SIZE,
384  &SectionOffset,
385  &ViewSize,
386  ViewShare,
387  MEM_COMMIT,
390 
391  /* Map 2 pages, but commit 1 */
392  BaseAddress = NULL;
393  SectionOffset.QuadPart = 0;
394  ViewSize = 2 * PAGE_SIZE;
395  Status = NtMapViewOfSection(SectionHandle,
397  &BaseAddress,
398  0,
399  PAGE_SIZE,
400  &SectionOffset,
401  &ViewSize,
402  ViewShare,
403  0,
406 
407  /* We must be able to access the 1st page */
409  _SEH2_TRY
410  {
411  *(PUCHAR)BaseAddress = 1;
412  }
413  _SEH2_EXCEPT(1)
414  {
416  }
417  _SEH2_END;
419 
420  /* We must not be able to access the 2nd page */
422  _SEH2_TRY
423  {
424  *((PUCHAR)BaseAddress + PAGE_SIZE) = 1;
425  }
426  _SEH2_EXCEPT(1)
427  {
429  }
430  _SEH2_END;
432 
433  /* Map the 2 pages again into a different memory location */
434  BaseAddress2 = NULL;
435  Status = NtMapViewOfSection(SectionHandle,
437  &BaseAddress2,
438  0,
439  0,
440  &SectionOffset,
441  &ViewSize,
442  ViewShare,
443  0,
446 
447  /* Commit a the 2nd page in the 2nd memory location */
448  BaseAddress2 = (PUCHAR)BaseAddress2 + PAGE_SIZE;
451  &BaseAddress2,
452  0,
453  &ViewSize,
454  MEM_COMMIT,
455  PAGE_READONLY);
457 
458  /* Try to commit again (the already committed page) */
460  &BaseAddress2,
461  0,
462  &ViewSize,
463  MEM_COMMIT,
464  PAGE_READONLY);
466 
467  /* We must be able to access the memory in the 2nd page of the 1st memory location */
469  _SEH2_TRY
470  {
471  *((PUCHAR)BaseAddress + PAGE_SIZE) = 2;
472  }
473  _SEH2_EXCEPT(1)
474  {
476  }
477  _SEH2_END;
479 
480  ok(*(PULONG)BaseAddress2 == 2, "Value in memory was wrong\n");
481 
482  /* Close the mapping */
487  Status = NtClose(SectionHandle);
489 
490  /* Try to create a 512 GB page file backed section with committed pages */
491  MaximumSize.QuadPart = 0x8000000000;
492  Status = NtCreateSection(&SectionHandle,
494  NULL,
495  &MaximumSize,
497  SEC_COMMIT,
498  NULL);
500 
501  /* Try to create a huge page file backed section with PAGE_NOACCESS protection */
502  MaximumSize.QuadPart = 0x8000000000;
503  Status = NtCreateSection(&SectionHandle,
505  NULL,
506  &MaximumSize,
508  SEC_COMMIT,
509  NULL);
511 
512  /* Try to create a very huge page file backed section, but only reserved */
513  MaximumSize.QuadPart = 0x80000000000;
514  Status = NtCreateSection(&SectionHandle,
516  NULL,
517  &MaximumSize,
519  SEC_RESERVE,
520  NULL);
521 #ifdef _WIN64
523 #else
524  /* WoW64 returns STATUS_INSUFFICIENT_RESOURCES */
526  "got wrong Status: 0x%lx\n", Status);
527 #endif
528 
529  /* Try to create a even huger page file backed section, but only reserved */
530  MaximumSize.QuadPart = 0x800000000000;
531  Status = NtCreateSection(&SectionHandle,
533  NULL,
534  &MaximumSize,
536  SEC_RESERVE,
537  NULL);
539 
540  /* Create a 8 GB page file backed section, but only reserved */
541  MaximumSize.QuadPart = 0x200000000;
542  Status = NtCreateSection(&SectionHandle,
544  NULL,
545  &MaximumSize,
547  SEC_RESERVE,
548  NULL);
550 
551  /* Pass a too large region size */
552  BaseAddress = NULL;
553  SectionOffset.QuadPart = 0;
555  Status = NtMapViewOfSection(SectionHandle,
557  &BaseAddress,
558  0,
559  0,
560  &SectionOffset,
561  &ViewSize,
562  ViewShare,
563  0,
565 #ifdef _WIN64
567 #else
568  /* WoW64 returns STATUS_INVALID_PARAMETER_4 */
570  "got wrong Status: 0x%lx\n", Status);
571 #endif
572 
573  /* Pass 0 region size */
574  BaseAddress = NULL;
575  SectionOffset.QuadPart = 0;
576  ViewSize = 0;
577  Status = NtMapViewOfSection(SectionHandle,
579  &BaseAddress,
580  0,
581  0,
582  &SectionOffset,
583  &ViewSize,
584  ViewShare,
585  0,
587 #ifdef _WIN64
589  ok(ViewSize == 0x200000000, "wrong ViewSize: 0x%Ix\n", ViewSize);
590 #else
591  /* WoW64 returns STATUS_NO_MEMORY */
593  "got wrong Status: 0x%lx\n", Status);
594  ok(ViewSize == 0, "wrong ViewSize: 0x%Ix\n", ViewSize);
595 #endif
596 
597  /* Map with PAGE_NOACCESS */
598  BaseAddress = NULL;
599  SectionOffset.QuadPart = 0;
600  ViewSize = 0x20000000;
601  Status = NtMapViewOfSection(SectionHandle,
603  &BaseAddress,
604  0,
605  0,
606  &SectionOffset,
607  &ViewSize,
608  ViewShare,
609  0,
610  PAGE_NOACCESS);
612 
613  /* Try to change protection to read/write */
614  ViewSize = 0x1000;
615  OldProtect = -1;
616  BaseAddress2 = BaseAddress;
617  Status = NtProtectVirtualMemory(NtCurrentProcess(), &BaseAddress2, &ViewSize, PAGE_READWRITE, &OldProtect);
619  // Windows 2003 returns bogus
620  //ok(OldProtect == PAGE_READWRITE, "Wrong protection returned: %u\n", OldProtect);
621 
622  /* Test read access */
624  _SEH2_TRY
625  {
626  (void)(*(volatile char*)BaseAddress2);
627  }
629  {
631  }
632  _SEH2_END;
634 
635  /* Try to change protection to read/write */
636  ViewSize = 0x1000;
637  OldProtect = -1;
638  BaseAddress2 = BaseAddress;
639  Status = NtProtectVirtualMemory(NtCurrentProcess(), &BaseAddress2, &ViewSize, PAGE_READWRITE, &OldProtect);
641 #ifdef _WIN64
642  ok(OldProtect == 0, "Wrong protection returned: 0x%lx\n", OldProtect);
643 #else
644  // Windows 2003 returns bogus
645 #endif
646 
647  /* Try to change protection to readonly */
648  ViewSize = 0x1000;
649  OldProtect = -1;
650  BaseAddress2 = BaseAddress;
651  Status = NtProtectVirtualMemory(NtCurrentProcess(), &BaseAddress2, &ViewSize, PAGE_READONLY, &OldProtect);
653 #ifdef _WIN64
654  //ok(OldProtect == 0, "Wrong protection returned: 0x%lx\n", OldProtect);
655 #else
656  // Windows 2003 returns bogus
657 #endif
658 
659  /* Commit a page */
660  ViewSize = 0x1000;
661  BaseAddress2 = BaseAddress;
664  ok(BaseAddress2 == BaseAddress, "Invalid base address: %p\n", BaseAddress2);
665 
666  /* Commit the page again */
667  ViewSize = 0x1000;
668  BaseAddress2 = BaseAddress;
671  ok(BaseAddress2 == BaseAddress, "Invalid base address: %p\n", BaseAddress2);
672 
673  /* Test read access */
675  _SEH2_TRY
676  {
677  (void)(*(volatile char*)BaseAddress2);
678  }
680  {
682  }
683  _SEH2_END;
685 
686  /* Test write access */
688  _SEH2_TRY
689  {
690  *(char*)BaseAddress2 = 1;
691  }
693  {
695  }
696  _SEH2_END;
698 
699  /* Update protection to PAGE_READWRITE */
700  ViewSize = 0x1000;
701  BaseAddress2 = BaseAddress;
704 
705  /* Test write access */
707  _SEH2_TRY
708  {
709  *(char*)BaseAddress2 = 1;
710  }
712  {
714  }
715  _SEH2_END;
717 
718  /* Update protection to PAGE_EXECUTE_READWRITE (1 page) */
719  ViewSize = 0x1000;
720  BaseAddress2 = BaseAddress;
723 
726  Status = NtClose(SectionHandle);
728 }
729 
730 void
732 {
735  OBJECT_ATTRIBUTES FileObjectAttributes;
737  WCHAR TestDllPath[MAX_PATH];
738  HANDLE FileHandle, DataSectionHandle, ImageSectionHandle;
739  PVOID DataBase, ImageBase;
741 
742  GetModuleFileNameW(NULL, TestDllPath, RTL_NUMBER_OF(TestDllPath));
743  wcsrchr(TestDllPath, L'\\')[1] = UNICODE_NULL;
744  StringCbCatW(TestDllPath, sizeof(TestDllPath), L"testdata\\test.dll");
745  if (!RtlDosPathNameToNtPathName_U(TestDllPath,
746  &FileName,
747  NULL,
748  NULL))
749  {
750  ok(0, "RtlDosPathNameToNtPathName_U failed\n");
751  return;
752  }
753 
754  InitializeObjectAttributes(&FileObjectAttributes,
755  &FileName,
756  0,
757  NULL,
758  NULL);
759 
762  &FileObjectAttributes,
763  &IoStatusBlock,
767  if (!NT_SUCCESS(Status))
768  {
769  skip("Failed to open file %s\n", wine_dbgstr_wn(FileName.Buffer, FileName.Length / sizeof(WCHAR)));
770  return;
771  }
772 
773  /* Create a data section with write access */
774  Status = NtCreateSection(&DataSectionHandle,
775  SECTION_ALL_ACCESS, // DesiredAccess
776  NULL, // ObjectAttributes
777  NULL, // MaximumSize
778  PAGE_READWRITE, // SectionPageProtection
779  SEC_COMMIT, // AllocationAttributes
780  FileHandle);
782  if (!NT_SUCCESS(Status))
783  {
784  skip("Failed to create data section\n");
786  return;
787  }
788 
789  /* Map the data section as flat mapping */
790  DataBase = NULL;
791  ViewSize = 0;
792  Status = NtMapViewOfSection(DataSectionHandle,
794  &DataBase,
795  0,
796  0,
797  NULL,
798  &ViewSize,
799  ViewShare,
800  0,
803  //ok(ViewSize == 0x3f95cc48, "ViewSize wrong: 0x%lx\n");
804  if (!NT_SUCCESS(Status))
805  {
806  skip("Failed to map view of data section\n");
807  NtClose(DataSectionHandle);
809  return;
810  }
811 
812  /* Check the original data */
813  ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
814 
815  /* Modify the PE header (but do not flush!) */
816  *(ULONG*)DataBase = 0xdeadbabe;
817  ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n");
818 
819  /* Modify data in the .data section (but do not flush!) */
820  ok(*(ULONG*)((PUCHAR)DataBase + 0x800) == 0x12345678,
821  "Data in .data section invalid: 0x%lx!\n", *(ULONG*)((PUCHAR)DataBase + 0x800));
822  *(ULONG*)((PUCHAR)DataBase + 0x800) = 0x87654321;
823 
824  /* Now try to create an image section (should fail) */
825  Status = NtCreateSection(&ImageSectionHandle,
826  SECTION_ALL_ACCESS, // DesiredAccess
827  NULL, // ObjectAttributes
828  NULL, // MaximumSize
829  PAGE_READWRITE, // SectionPageProtection
830  SEC_IMAGE, // AllocationAttributes
831  FileHandle);
833  if (NT_SUCCESS(Status)) NtClose(ImageSectionHandle);
834 
835  /* Restore the original header */
836  *(ULONG*)DataBase = 0x00905a4d;
837 
838  /* Modify data in the .data section (but do not flush!) */
839  ok_hex(*(ULONG*)((PUCHAR)DataBase + 0x800), 0x87654321);
840  *(ULONG*)((PUCHAR)DataBase + 0x800) = 0xdeadbabe;
841 
842  /* Try to create an image section again */
843  Status = NtCreateSection(&ImageSectionHandle,
844  SECTION_ALL_ACCESS, // DesiredAccess
845  NULL, // ObjectAttributes
846  NULL, // MaximumSize
847  PAGE_READWRITE, // SectionPageProtection
848  SEC_IMAGE, // AllocationAttributes
849  FileHandle);
851  if (!NT_SUCCESS(Status))
852  {
853  skip("Failed to create image section\n");
854  NtClose(DataSectionHandle);
856  return;
857  }
858 
859  /* Map the image section */
860  ImageBase = NULL;
861  ViewSize = 0;
862  Status = NtMapViewOfSection(ImageSectionHandle,
864  &ImageBase,
865  0, // ZeroBits
866  0, // CommitSize
867  NULL, // SectionOffset
868  &ViewSize,
869  ViewShare,
870  0, // AllocationType
871  PAGE_READONLY);
872 #ifdef _M_IX86
874 #else
876 #endif
877  if (!NT_SUCCESS(Status))
878  {
879  skip("Failed to map view of image section\n");
880  NtClose(ImageSectionHandle);
881  NtClose(DataSectionHandle);
883  return;
884  }
885 
886  /* Check the header */
887  ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
888  ok(*(ULONG*)ImageBase == 0x00905a4d, "Header not ok\n");
889 
890  /* Check the data section. Either of these can be present! */
891  ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
892  (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
893  "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
894 
895  /* Now modify the data again */
896  *(ULONG*)DataBase = 0xdeadbabe;
897  *(ULONG*)((PUCHAR)DataBase + 0x800) = 0xf00dada;
898 
899  /* Check the data */
900  ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n");
901  ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n");
902  ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
903  (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
904  "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
905 
906  /* Flush the view */
907  ViewSize = 0x1000;
909  &DataBase,
910  &ViewSize,
911  &IoStatusBlock);
913 
914  /* Check the data again */
915  ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n");
916  ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
917  (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
918  "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
919 
920  /* Restore the original header */
921  *(ULONG*)DataBase = 0x00905a4d;
922  ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
923 
924  /* Close the image mapping */
926  NtClose(ImageSectionHandle);
927 
928  /* Create an image section again */
929  Status = NtCreateSection(&ImageSectionHandle,
930  SECTION_ALL_ACCESS, // DesiredAccess
931  NULL, // ObjectAttributes
932  NULL, // MaximumSize
933  PAGE_READWRITE, // SectionPageProtection
934  SEC_IMAGE, // AllocationAttributes
935  FileHandle);
937  if (!NT_SUCCESS(Status))
938  {
939  skip("Failed to create image section\n");
940  NtClose(DataSectionHandle);
942  return;
943  }
944 
945  /* Map the image section again */
946  ImageBase = NULL;
947  ViewSize = 0;
948  Status = NtMapViewOfSection(ImageSectionHandle,
950  &ImageBase,
951  0,
952  0,
953  NULL,
954  &ViewSize,
955  ViewShare,
956  0,
957  PAGE_READONLY);
958 #ifdef _M_IX86
960 #else
962 #endif
963  if (!NT_SUCCESS(Status))
964  {
965  skip("Failed to map view of image section\n");
966  NtClose(ImageSectionHandle);
967  NtClose(DataSectionHandle);
969  return;
970  }
971 
972  // This one doesn't always work, needs investigation
973  /* Check the .data section again */
974  //ok(*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0xf00dada,
975  // "Data should be synced: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));
976 
977  /* Restore the original data */
978  *(ULONG*)((PUCHAR)DataBase + 0x800) = 0x12345678;
979 
980  /* Close the data mapping */
982 
983  NtClose(DataSectionHandle);
984 
985  /* Try to allocate memory inside the image mapping */
986  DataBase = (PUCHAR)ImageBase + 0x20000;
987  ViewSize = 0x1000;
990 
991  /* Cleanup */
993  NtClose(ImageSectionHandle);
995 }
996 
997 void
999 {
1001  NTSTATUS Status;
1002  OBJECT_ATTRIBUTES FileObjectAttributes;
1004  HANDLE FileHandle, ImageSectionHandle;
1005  PVOID ImageBase, BaseAddress;
1006  SIZE_T ViewSize;
1008 
1009  if (!RtlDosPathNameToNtPathName_U(L"testdata\\nvoglv32.dll",
1010  &FileName,
1011  NULL,
1012  NULL))
1013  {
1014  ok(0, "RtlDosPathNameToNtPathName_U failed\n");
1015  return;
1016  }
1017 
1018  InitializeObjectAttributes(&FileObjectAttributes,
1019  &FileName,
1020  0,
1021  NULL,
1022  NULL);
1023 
1026  &FileObjectAttributes,
1027  &IoStatusBlock,
1031  printf("Opened file with handle %p\n", FileHandle);
1032 
1033  /* Create a data section with write access */
1034  MaximumSize.QuadPart = 0x20000;
1035  Status = NtCreateSection(&ImageSectionHandle,
1036  SECTION_ALL_ACCESS, // DesiredAccess
1037  NULL, // ObjectAttributes
1038  &MaximumSize, // MaximumSize
1039  PAGE_READWRITE, // SectionPageProtection
1040  SEC_IMAGE, // AllocationAttributes
1041  FileHandle);
1043 
1044  printf("Created image section with handle %p\n", ImageSectionHandle);
1045  //system("PAUSE");
1046 
1047  /* Map the image section */
1048  ImageBase = NULL;
1049  ViewSize = 0x0000;
1050  SectionOffset.QuadPart = 0x00000;
1051  Status = NtMapViewOfSection(ImageSectionHandle,
1052  NtCurrentProcess(),
1053  &ImageBase,
1054  0,
1055  0,
1056  &SectionOffset,
1057  &ViewSize,
1058  ViewShare,
1059  0,
1060  PAGE_READWRITE);
1062 
1063  printf("Mapped image section at %p, value in text section: %lx\n",
1064  ImageBase, *((ULONG*)((PCHAR)ImageBase + 0x1196)));
1065  system("PAUSE");
1066 
1067  /* Try to allocate a page after the section */
1068  BaseAddress = (PUCHAR)ImageBase + 0x10000;
1069  ViewSize = 0x1000;
1071  &BaseAddress,
1072  0,
1073  &ViewSize,
1075  PAGE_READWRITE);
1076  printf("allocation status: %lx\n", Status);
1077  system("PAUSE");
1078 
1079 }
1080 
1081 // doesn't work with WoW64!
1082 void
1084 {
1085  NTSTATUS Status;
1086  HANDLE SectionHandle1, SectionHandle2;
1088  PVOID BaseAddress1, BaseAddress2;
1089  SIZE_T ViewSize;
1090 
1091  /* Create a based section with SEC_COMMIT */
1092  MaximumSize.QuadPart = 0x1000;
1093  Status = NtCreateSection(&SectionHandle1,
1095  NULL,
1096  &MaximumSize,
1099  NULL);
1101 
1102  /* Map the 1st section */
1103  BaseAddress1 = NULL;
1104  SectionOffset.QuadPart = 0;
1105  ViewSize = 0;
1106  Status = NtMapViewOfSection(SectionHandle1,
1107  NtCurrentProcess(),
1108  &BaseAddress1,
1109  0,
1110  0,
1111  &SectionOffset,
1112  &ViewSize,
1113  ViewShare,
1114  0,
1115  PAGE_READWRITE);
1116 #if 0 // WOW64?
1118 #else
1120 #endif
1121 
1122  /* Create a 2nd based section with SEC_COMMIT */
1123  MaximumSize.QuadPart = 0x1000;
1124  Status = NtCreateSection(&SectionHandle2,
1126  NULL,
1127  &MaximumSize,
1130  NULL);
1132 
1133  /* Map the 2nd section */
1134  BaseAddress2 = NULL;
1135  SectionOffset.QuadPart = 0;
1136  ViewSize = 0;
1137  Status = NtMapViewOfSection(SectionHandle2,
1138  NtCurrentProcess(),
1139  &BaseAddress2,
1140  0,
1141  0,
1142  &SectionOffset,
1143  &ViewSize,
1144  ViewShare,
1145  0,
1146  PAGE_READWRITE);
1147 #if 0 // WOW64?
1149 #else
1151  ok((ULONG_PTR)BaseAddress2 < (ULONG_PTR)BaseAddress1,
1152  "Invalid addresses: BaseAddress1=%p, BaseAddress2=%p\n", BaseAddress1, BaseAddress2);
1153  ok(((ULONG_PTR)BaseAddress1 - (ULONG_PTR)BaseAddress2) == 0x10000,
1154  "Invalid addresses: BaseAddress1=%p, BaseAddress2=%p\n", BaseAddress1, BaseAddress2);
1155 #endif
1156 }
1157 
1158 #define BYTES4(x) x, x, x, x
1159 #define BYTES8(x) BYTES4(x), BYTES4(x)
1160 #define BYTES16(x) BYTES8(x), BYTES8(x)
1161 #define BYTES32(x) BYTES16(x), BYTES16(x)
1162 #define BYTES64(x) BYTES32(x), BYTES32(x)
1163 #define BYTES128(x) BYTES64(x), BYTES64(x)
1164 #define BYTES256(x) BYTES128(x), BYTES128(x)
1165 #define BYTES512(x) BYTES256(x), BYTES256(x)
1166 #define BYTES1024(x) BYTES512(x), BYTES512(x)
1167 
1169 {
1171  WORD stub[32];
1177  BYTE pad[488];
1178  BYTE text_data[0x400];
1180  BYTE rsrc_data[0x400];
1181  BYTE clc_data[0x1000];
1183 {
1184  /* IMAGE_DOS_HEADER */
1185  {
1186  IMAGE_DOS_SIGNATURE, 144, 3, 0, 4, 0, 0xFFFF, 0, 0xB8, 0, 0, 0, 0x40,
1187  0, { 0 }, 0, 0, { 0 }, 0x80
1188  },
1189  /* binary to print "This program cannot be run in DOS mode." */
1190  {
1191  0x1F0E, 0x0EBA, 0xB400, 0xCD09, 0xB821, 0x4C01, 0x21CD, 0x6854, 0x7369,
1192  0x7020, 0x6F72, 0x7267, 0x6D61, 0x6320, 0x6E61, 0x6F6E, 0x2074, 0x6562,
1193  0x7220, 0x6E75, 0x6920, 0x206E, 0x4F44, 0x2053, 0x6F6D, 0x6564, 0x0D2E,
1194  0x0A0D, 0x0024, 0x0000, 0x0000, 0x0000
1195  },
1196  /* IMAGE_NT_HEADERS32 */
1197  {
1198  IMAGE_NT_SIGNATURE, /* Signature */
1199  /* IMAGE_FILE_HEADER */
1200  {
1201  IMAGE_FILE_MACHINE_I386, /* Machine */
1202  4, /* NumberOfSections */
1203  0x47EFDF09, /* TimeDateStamp */
1204  0, /* PointerToSymbolTable */
1205  0, /* NumberOfSymbols */
1206  0xE0, /* SizeOfOptionalHeader */
1209  IMAGE_FILE_DLL, /* Characteristics */
1210  },
1211  /* IMAGE_OPTIONAL_HEADER32 */
1212  {
1213  IMAGE_NT_OPTIONAL_HDR32_MAGIC, /* Magic */
1214  8, /* MajorLinkerVersion */
1215  0, /* MinorLinkerVersion */
1216  0x400, /* SizeOfCode */
1217  0x000, /* SizeOfInitializedData */
1218  0, /* SizeOfUninitializedData */
1219  0x2000, /* AddressOfEntryPoint */
1220  0x2000, /* BaseOfCode */
1221  0x0000, /* BaseOfData */
1222  0x400000, /* ImageBase */
1223  0x2000, /* SectionAlignment */
1224  0x200, /* FileAlignment */
1225  4, /* MajorOperatingSystemVersion */
1226  0, /* MinorOperatingSystemVersion */
1227  0, /* MajorImageVersion */
1228  0, /* MinorImageVersion */
1229  4, /* MajorSubsystemVersion */
1230  0, /* MinorSubsystemVersion */
1231  0, /* Win32VersionValue */
1232  0xa000, /* SizeOfImage */
1233  0x400, /* SizeOfHeaders */
1234  0x0, /* CheckSum */
1235  IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
1238  IMAGE_DLLCHARACTERISTICS_NX_COMPAT, /* DllCharacteristics */
1239  0x100000, /* SizeOfStackReserve */
1240  0x1000, /* SizeOfStackCommit */
1241  0x100000, /* SizeOfHeapReserve */
1242  0x1000, /* SizeOfHeapCommit */
1243  0, /* LoaderFlags */
1244  0x10, /* NumberOfRvaAndSizes */
1245  /* IMAGE_DATA_DIRECTORY */
1246  {
1247  { 0 }, /* Export Table */
1248  { 0 }, /* Import Table */
1249  { 0 }, /* Resource Table */
1250  { 0 }, /* Exception Table */
1251  { 0 }, /* Certificate Table */
1252  { 0 }, /* Base Relocation Table */
1253  { 0 }, /* Debug */
1254  { 0 }, /* Copyright */
1255  { 0 }, /* Global Ptr */
1256  { 0 }, /* TLS Table */
1257  { 0 }, /* Load Config Table */
1258  { 0 }, /* Bound Import */
1259  { 0 }, /* IAT */
1260  { 0 }, /* Delay Import Descriptor */
1261  { 0 }, /* CLI Header */
1262  { 0 } /* Reserved */
1263  }
1264  }
1265  },
1266  /* IMAGE_SECTION_HEADER */
1267  {
1268  ".text", /* Name */
1269  { 0x394 }, /* Misc.VirtualSize */
1270  0x2000, /* VirtualAddress */
1271  0x400, /* SizeOfRawData */
1272  0x400, /* PointerToRawData */
1273  0, /* PointerToRelocations */
1274  0, /* PointerToLinenumbers */
1275  0, /* NumberOfRelocations */
1276  0, /* NumberOfLinenumbers */
1278  IMAGE_SCN_CNT_CODE, /* Characteristics */
1279  },
1280  /* IMAGE_SECTION_HEADER */
1281  {
1282  ".rossym", /* Name */
1283  { 0x100 }, /* Misc.VirtualSize */
1284  0x4000, /* VirtualAddress */
1285  0x400, /* SizeOfRawData */
1286  0x800, /* PointerToRawData */
1287  0, /* PointerToRelocations */
1288  0, /* PointerToLinenumbers */
1289  0, /* NumberOfRelocations */
1290  0, /* NumberOfLinenumbers */
1291  /* CORE-8384 */
1292  IMAGE_SCN_MEM_READ | IMAGE_SCN_TYPE_NOLOAD, /* Characteristics */
1293  },
1294  /* IMAGE_SECTION_HEADER */
1295  {
1296  ".rsrc", /* Name */
1297  { 0x100 }, /* Misc.VirtualSize */
1298  0x6000, /* VirtualAddress */
1299  0x400, /* SizeOfRawData */
1300  0xC00, /* PointerToRawData */
1301  0, /* PointerToRelocations */
1302  0, /* PointerToLinenumbers */
1303  0, /* NumberOfRelocations */
1304  0, /* NumberOfLinenumbers */
1306  IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1307  },
1308  /* IMAGE_SECTION_HEADER */
1309  {
1310  ".clc", /* Name */
1311  { 0x2000 }, /* Misc.VirtualSize */
1312  0x8000, /* VirtualAddress */
1313  0x1000, /* SizeOfRawData */
1314  0x1000, /* PointerToRawData */
1315  0, /* PointerToRelocations */
1316  0, /* PointerToLinenumbers */
1317  0, /* NumberOfRelocations */
1318  0, /* NumberOfLinenumbers */
1319  /* CORE-12582 */
1322  },
1323  /* fill */
1324  { 0 },
1325  /* text */
1326  { 0xc3, 0 },
1327  /* rossym */
1328  {
1329  0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1330  BYTES8(0xaa),
1331  BYTES16(0xbb),
1332  BYTES32(0xcc),
1333  BYTES64(0xdd),
1334  BYTES64(0xee),
1335  BYTES64(0xff),
1336  },
1337  /* rsrc */
1338  {
1339  BYTES128(0xee),
1340  BYTES128(0x55),
1341  BYTES128(0xee),
1342  BYTES128(0x11),
1343  BYTES128(0xff),
1344  BYTES128(0x00),
1345  BYTES128(0x00),
1346  BYTES128(0xdd),
1347  },
1348  /* clc */
1349  {
1350  BYTES512(0x11),
1351  BYTES512(0x22),
1352  BYTES512(0x33),
1353  BYTES512(0x44),
1354  BYTES512(0x55),
1355  BYTES512(0x66),
1356  BYTES512(0x77),
1357  BYTES512(0x88),
1358  },
1359 };
1360 
1361 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, text_data) == 0x400);
1362 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, rossym_data) == 0x800);
1363 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, rsrc_data) == 0xc00);
1364 C_ASSERT(FIELD_OFFSET(struct _SECTION_CONTENTS_IMAGE_FILE, clc_data) == 0x1000);
1365 
1366 static
1367 void
1369 {
1370  NTSTATUS Status;
1371  WCHAR TempPath[MAX_PATH];
1373  HANDLE Handle;
1374  HANDLE SectionHandle;
1377  SIZE_T ViewSize;
1378  ULONG Written;
1379  ULONG Length;
1380  BOOL Success;
1381 
1382  Length = GetTempPathW(MAX_PATH, TempPath);
1383  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1384  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1385  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1388  0,
1389  NULL,
1390  CREATE_ALWAYS,
1391  0,
1392  NULL);
1394  {
1395  skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1396  return;
1397  }
1398  if (Relocate)
1399  {
1400  ok((ULONG_PTR)GetModuleHandle(NULL) <= 0x80000000, "Module at %p\n", GetModuleHandle(NULL));
1401  SectionContentsImageFile.nthdrs.OptionalHeader.ImageBase = (ULONG)(ULONG_PTR)GetModuleHandle(NULL);
1402  }
1403  else
1404  {
1405  SectionContentsImageFile.nthdrs.OptionalHeader.ImageBase = 0xe400000;
1406  }
1407 
1410  sizeof(SectionContentsImageFile),
1411  &Written,
1412  NULL);
1413  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1414  ok(Written == sizeof(SectionContentsImageFile), "WriteFile wrote %lu bytes\n", Written);
1415 
1416  Status = NtCreateSection(&SectionHandle,
1418  NULL,
1419  NULL,
1421  SEC_IMAGE,
1422  Handle);
1424 
1425  if (NT_SUCCESS(Status))
1426  {
1427  /* Map the section with */
1428  BaseAddress = NULL;
1429  SectionOffset.QuadPart = 0;
1430  ViewSize = 0;
1431  Status = NtMapViewOfSection(SectionHandle,
1432  NtCurrentProcess(),
1433  &BaseAddress,
1434  0,
1435  0,
1436  &SectionOffset,
1437  &ViewSize,
1438  ViewShare,
1439  0,
1440  PAGE_READWRITE);
1441  if (Relocate)
1443  else
1445  if (NT_SUCCESS(Status))
1446  {
1448 #define TEST_BYTE(n, v) StartSeh() ok_hex(Bytes[n], v); EndSeh(STATUS_SUCCESS);
1449 #define TEST_WRITE(n) StartSeh() *(volatile UCHAR *)&Bytes[n] = Bytes[n]; EndSeh(STATUS_SUCCESS);
1450 #define TEST_NOWRITE(n) StartSeh() *(volatile UCHAR *)&Bytes[n] = Bytes[n]; EndSeh(STATUS_ACCESS_VIOLATION);
1451  TEST_NOWRITE(0x2000);
1452  TEST_BYTE(0x2000, 0xc3);
1453  TEST_BYTE(0x2001, 0x00);
1454  TEST_NOWRITE(0x4000);
1455  TEST_BYTE(0x4000, 0x01);
1456  TEST_BYTE(0x4001, 0x23);
1457  TEST_BYTE(0x4007, 0xef);
1458  TEST_BYTE(0x4008, 0xaa);
1459  TEST_BYTE(0x4010, 0xbb);
1460  TEST_BYTE(0x4020, 0xcc);
1461  TEST_BYTE(0x4040, 0xdd);
1462  TEST_BYTE(0x4080, 0xee);
1463  TEST_BYTE(0x40c0, 0xff);
1464  TEST_BYTE(0x40ff, 0xff);
1465  TEST_BYTE(0x4100, 0x00);
1466  TEST_BYTE(0x41ff, 0x00);
1467  TEST_NOWRITE(0x6000);
1468  TEST_BYTE(0x6000, 0xee);
1469  TEST_BYTE(0x60ff, 0x55);
1470  TEST_BYTE(0x6100, 0xee);
1471  TEST_BYTE(0x63ff, 0xdd);
1472  TEST_BYTE(0x6400, 0x00);
1473  TEST_WRITE(0x8000);
1474  TEST_BYTE(0x8000, 0x11);
1475  TEST_BYTE(0x8400, 0x33);
1476 #undef TEST_BYTE
1477 #undef TEST_WRITE
1478 #undef TEST_NOWRITE
1481  }
1482  Status = NtClose(SectionHandle);
1484  }
1485 
1488 }
1489 
1491 {
1493  WORD stub[32];
1499  BYTE pad[488];
1500  BYTE text_data[0x1200];
1501  BYTE data_data[0x1200];
1502  BYTE rsrc_data[0x400];
1503 } RawSizeImageFile =
1504 {
1505  /* IMAGE_DOS_HEADER */
1506  {
1507  IMAGE_DOS_SIGNATURE, 144, 3, 0, 4, 0, 0xFFFF, 0, 0xB8, 0, 0, 0, 0x40,
1508  0, { 0 }, 0, 0, { 0 }, 0x80
1509  },
1510  /* binary to print "This program cannot be run in DOS mode." */
1511  {
1512  0x1F0E, 0x0EBA, 0xB400, 0xCD09, 0xB821, 0x4C01, 0x21CD, 0x6854, 0x7369,
1513  0x7020, 0x6F72, 0x7267, 0x6D61, 0x6320, 0x6E61, 0x6F6E, 0x2074, 0x6562,
1514  0x7220, 0x6E75, 0x6920, 0x206E, 0x4F44, 0x2053, 0x6F6D, 0x6564, 0x0D2E,
1515  0x0A0D, 0x0024, 0x0000, 0x0000, 0x0000
1516  },
1517  /* IMAGE_NT_HEADERS32 */
1518  {
1519  IMAGE_NT_SIGNATURE, /* Signature */
1520  /* IMAGE_FILE_HEADER */
1521  {
1522  IMAGE_FILE_MACHINE_I386, /* Machine */
1523  4, /* NumberOfSections */
1524  0x47EFDF09, /* TimeDateStamp */
1525  0, /* PointerToSymbolTable */
1526  0, /* NumberOfSymbols */
1527  0xE0, /* SizeOfOptionalHeader */
1530  IMAGE_FILE_DLL, /* Characteristics */
1531  },
1532  /* IMAGE_OPTIONAL_HEADER32 */
1533  {
1534  IMAGE_NT_OPTIONAL_HDR32_MAGIC, /* Magic */
1535  8, /* MajorLinkerVersion */
1536  0, /* MinorLinkerVersion */
1537  0x400, /* SizeOfCode */
1538  0x000, /* SizeOfInitializedData */
1539  0, /* SizeOfUninitializedData */
1540  0x1000, /* AddressOfEntryPoint */
1541  0x1000, /* BaseOfCode */
1542  0x0000, /* BaseOfData */
1543  0x400000, /* ImageBase */
1544  0x1000, /* SectionAlignment */
1545  0x200, /* FileAlignment */
1546  4, /* MajorOperatingSystemVersion */
1547  0, /* MinorOperatingSystemVersion */
1548  0, /* MajorImageVersion */
1549  0, /* MinorImageVersion */
1550  4, /* MajorSubsystemVersion */
1551  0, /* MinorSubsystemVersion */
1552  0, /* Win32VersionValue */
1553  0x5000, /* SizeOfImage */
1554  0x400, /* SizeOfHeaders */
1555  0x0, /* CheckSum */
1556  IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
1559  IMAGE_DLLCHARACTERISTICS_NX_COMPAT, /* DllCharacteristics */
1560  0x100000, /* SizeOfStackReserve */
1561  0x1000, /* SizeOfStackCommit */
1562  0x100000, /* SizeOfHeapReserve */
1563  0x1000, /* SizeOfHeapCommit */
1564  0, /* LoaderFlags */
1565  0x10, /* NumberOfRvaAndSizes */
1566  /* IMAGE_DATA_DIRECTORY */
1567  {
1568  { 0 }, /* Export Table */
1569  { 0 }, /* Import Table */
1570  { 0 }, /* Resource Table */
1571  { 0 }, /* Exception Table */
1572  { 0 }, /* Certificate Table */
1573  { 0 }, /* Base Relocation Table */
1574  { 0 }, /* Debug */
1575  { 0 }, /* Copyright */
1576  { 0 }, /* Global Ptr */
1577  { 0 }, /* TLS Table */
1578  { 0 }, /* Load Config Table */
1579  { 0 }, /* Bound Import */
1580  { 0 }, /* IAT */
1581  { 0 }, /* Delay Import Descriptor */
1582  { 0 }, /* CLI Header */
1583  { 0 } /* Reserved */
1584  }
1585  }
1586  },
1587  /* IMAGE_SECTION_HEADER */
1588  {
1589  /* SizeOfRawData larger than VirtualSize */
1590  ".text", /* Name */
1591  { 0x1000 }, /* Misc.VirtualSize */
1592  0x1000, /* VirtualAddress */
1593  0x1200, /* SizeOfRawData */
1594  0x400, /* PointerToRawData */
1595  0, /* PointerToRelocations */
1596  0, /* PointerToLinenumbers */
1597  0, /* NumberOfRelocations */
1598  0, /* NumberOfLinenumbers */
1600  IMAGE_SCN_CNT_CODE, /* Characteristics */
1601  },
1602  /* IMAGE_SECTION_HEADER */
1603  {
1604  /* SizeOfRawData larger than VirtualSize */
1605  ".data", /* Name */
1606  { 0x100 }, /* Misc.VirtualSize */
1607  0x2000, /* VirtualAddress */
1608  0x1200, /* SizeOfRawData */
1609  0x1600, /* PointerToRawData */
1610  0, /* PointerToRelocations */
1611  0, /* PointerToLinenumbers */
1612  0, /* NumberOfRelocations */
1613  0, /* NumberOfLinenumbers */
1615  IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1616  },
1617  /* IMAGE_SECTION_HEADER */
1618  {
1619  /* SizeOfRawData = 0 */
1620  ".zdata", /* Name */
1621  { 0x100 }, /* Misc.VirtualSize */
1622  0x3000, /* VirtualAddress */
1623  0, /* SizeOfRawData */
1624  0x2800, /* PointerToRawData */
1625  0, /* PointerToRelocations */
1626  0, /* PointerToLinenumbers */
1627  0, /* NumberOfRelocations */
1628  0, /* NumberOfLinenumbers */
1630  IMAGE_SCN_CNT_UNINITIALIZED_DATA, /* Characteristics */
1631  },
1632  /* IMAGE_SECTION_HEADER */
1633  {
1634  /* VirtualSize larger than SizeOfRawData */
1635  ".rsrc", /* Name */
1636  { 0x300 }, /* Misc.VirtualSize */
1637  0x4000, /* VirtualAddress */
1638  0x200, /* SizeOfRawData */
1639  0x2800, /* PointerToRawData */
1640  0, /* PointerToRelocations */
1641  0, /* PointerToLinenumbers */
1642  0, /* NumberOfRelocations */
1643  0, /* NumberOfLinenumbers */
1645  IMAGE_SCN_CNT_INITIALIZED_DATA, /* Characteristics */
1646  },
1647  /* fill */
1648  { 0 },
1649  /* text */
1650  {
1651  0xc3, 0, 0, 0, 0, 0, 0, 0,
1652  BYTES8(1),
1653  BYTES16(2),
1654  BYTES32(3),
1655  BYTES64(4),
1656  BYTES128(5),
1657  BYTES256(6),
1658  BYTES512(7),
1659  BYTES1024(8),
1660  BYTES1024(9),
1661  BYTES1024(0xa),
1662  BYTES512(0xb),
1663  },
1664  /* data */
1665  {
1666  0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1667  BYTES8(0xaa),
1668  BYTES16(0xbb),
1669  BYTES32(0xcc),
1670  BYTES64(0xdd),
1671  BYTES128(0xee),
1672  BYTES256(0xff),
1673  BYTES512(0xee),
1674  BYTES1024(0xdd),
1675  BYTES1024(0xcc),
1676  BYTES1024(0xbb),
1677  BYTES512(0xaa),
1678  },
1679  /* rsrc */
1680  {
1681  BYTES256(0xff),
1682  BYTES128(0xee),
1683  BYTES64(0xdd),
1684  BYTES32(0xcc),
1685  BYTES16(0xbb),
1686  BYTES8(0xaa),
1687  0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01,
1688  },
1689 };
1690 
1691 C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, text_data) == 0x400);
1692 C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, data_data) == 0x1600);
1693 C_ASSERT(FIELD_OFFSET(struct _RAW_SIZE_IMAGE_FILE, rsrc_data) == 0x2800);
1694 
1695 // CORE-17284
1696 static
1697 void
1698 Test_RawSize(ULONG TestNumber)
1699 {
1700  NTSTATUS Status;
1701  WCHAR TempPath[MAX_PATH];
1703  HANDLE Handle;
1704  HANDLE SectionHandle;
1707  SIZE_T ViewSize;
1708  ULONG Written;
1709  ULONG Length;
1710  BOOL Success;
1711 
1712  Length = GetTempPathW(MAX_PATH, TempPath);
1713  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1714  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1715  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1718  0,
1719  NULL,
1720  CREATE_ALWAYS,
1721  0,
1722  NULL);
1724  {
1725  skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1726  return;
1727  }
1728  RawSizeImageFile.nthdrs.OptionalHeader.ImageBase = 0xe400000;
1729  if (TestNumber == 1)
1730  {
1731  /* Just for fun, show that these flags don't matter. */
1736  }
1737  else if (TestNumber == 2)
1738  {
1739  /* SizeOfRawData is too large and will overflow.
1740  * This should cause failure to load the file */
1741  RawSizeImageFile.rsrc_header.SizeOfRawData = (ULONG)-0x200;
1742  }
1743 
1746  sizeof(RawSizeImageFile),
1747  &Written,
1748  NULL);
1749  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1750  ok(Written == sizeof(RawSizeImageFile), "WriteFile wrote %lu bytes\n", Written);
1751 
1752  Status = NtCreateSection(&SectionHandle,
1754  NULL,
1755  NULL,
1757  SEC_IMAGE,
1758  Handle);
1759  if (TestNumber == 2)
1760  {
1761  /* overflow in SizeOfRawData */
1763  }
1764  else
1765  {
1767  }
1768 
1769  if (NT_SUCCESS(Status))
1770  {
1771  /* Map the section with */
1772  BaseAddress = NULL;
1773  SectionOffset.QuadPart = 0;
1774  ViewSize = 0;
1775  Status = NtMapViewOfSection(SectionHandle,
1776  NtCurrentProcess(),
1777  &BaseAddress,
1778  0,
1779  0,
1780  &SectionOffset,
1781  &ViewSize,
1782  ViewShare,
1783  0,
1784  PAGE_READWRITE);
1786  if (NT_SUCCESS(Status))
1787  {
1790 
1791  /* .text section header is unmodified */
1792  ok_hex(ImageFile->text_header.Misc.VirtualSize, RawSizeImageFile.text_header.Misc.VirtualSize);
1793  ok_hex(ImageFile->text_header.VirtualAddress, RawSizeImageFile.text_header.VirtualAddress);
1794  ok_hex(ImageFile->text_header.SizeOfRawData, RawSizeImageFile.text_header.SizeOfRawData);
1795  ok_hex(ImageFile->text_header.PointerToRawData, RawSizeImageFile.text_header.PointerToRawData);
1796 
1797  /* SizeOfRawData = 0 resets PointerToRawData to 0 */
1798  ok_hex(ImageFile->zdata_header.Misc.VirtualSize, RawSizeImageFile.zdata_header.Misc.VirtualSize);
1799  ok_hex(ImageFile->zdata_header.VirtualAddress, RawSizeImageFile.zdata_header.VirtualAddress);
1800  ok_hex(ImageFile->zdata_header.SizeOfRawData, RawSizeImageFile.zdata_header.SizeOfRawData);
1801  ok_hex(ImageFile->zdata_header.PointerToRawData, 0);
1802 
1803 #define TEST_BYTE(n, v) \
1804  StartSeh() \
1805  ok(Bytes[n] == v, "[%lu] Bytes[%u] = 0x%x, expected 0x%x\n", \
1806  TestNumber, n, Bytes[n], v); \
1807  EndSeh(STATUS_SUCCESS);
1808  /* .text section data matches file up to 0x1000 */
1809  TEST_BYTE(0x1000, 0xc3);
1810  TEST_BYTE(0x1001, 0x00);
1811  TEST_BYTE(0x1008, 0x01);
1812  TEST_BYTE(0x1010, 0x02);
1813  TEST_BYTE(0x1fff, 0x0a);
1814 
1815  /* .data section data matches file up to 0x1000 */
1816  TEST_BYTE(0x2000, 0x01);
1817  TEST_BYTE(0x2001, 0x23);
1818  TEST_BYTE(0x20ff, 0xee);
1819  TEST_BYTE(0x2100, 0xff);
1820  TEST_BYTE(0x2fff, 0xbb);
1821 
1822  /* .zdata section data is all zeroes */
1823  TEST_BYTE(0x3000, 0x00);
1824  TEST_BYTE(0x3001, 0x00);
1825  TEST_BYTE(0x3800, 0x00);
1826  TEST_BYTE(0x3fff, 0x00);
1827 
1828  /* .rsrc section data matches file up to VirtualSize 0x200 */
1829  TEST_BYTE(0x4000, 0xff);
1830  TEST_BYTE(0x4100, 0xee);
1831  TEST_BYTE(0x4180, 0xdd);
1832  TEST_BYTE(0x41c0, 0xcc);
1833  TEST_BYTE(0x41e0, 0xbb);
1834  TEST_BYTE(0x41f0, 0xaa);
1835  TEST_BYTE(0x41fe, 0x23);
1836  TEST_BYTE(0x41ff, 0x01);
1837  TEST_BYTE(0x4200, 0x00);
1838  TEST_BYTE(0x4fff, 0x00);
1839 #undef TEST_BYTE
1842  }
1843  Status = NtClose(SectionHandle);
1845  }
1846 
1849 }
1850 
1851 static void
1853 {
1854  NTSTATUS Status;
1855  WCHAR TempPath[MAX_PATH];
1857  HANDLE Handle;
1858  HANDLE SectionHandle;
1859  ULONG Length;
1860 
1861  Length = GetTempPathW(MAX_PATH, TempPath);
1862  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1863  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1864  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1867  0,
1868  NULL,
1869  CREATE_ALWAYS,
1870  0,
1871  NULL);
1873  {
1874  skip("Failed to create temp file %ls, error %lu\n", FileName, GetLastError());
1875  return;
1876  }
1877 
1878  Status = NtCreateSection(&SectionHandle,
1880  0, 0, PAGE_READONLY, SEC_COMMIT, Handle);
1882 
1883  if (NT_SUCCESS(Status))
1884  NtClose(SectionHandle);
1885 
1886  Status = NtCreateSection(&SectionHandle,
1888  0, 0, PAGE_READONLY, SEC_IMAGE, Handle);
1890 
1891  if (NT_SUCCESS(Status))
1892  NtClose(SectionHandle);
1893 
1896 }
1897 
1898 // CORE-11206
1899 static void
1901 {
1902  WCHAR TempPath[MAX_PATH];
1904  NTSTATUS Status;
1905  SIZE_T ViewSize = 0;
1906  HANDLE Handle;
1907  HANDLE SectionHandle;
1908 
1909  SIZE_T Length;
1910  BOOL Success;
1911  DWORD Written, Error;
1912  VOID* BaseAddress;
1913 
1914  Length = GetTempPathW(MAX_PATH, TempPath);
1915  ok(Length != 0, "GetTempPathW failed with %lu\n", GetLastError());
1916  Length = GetTempFileNameW(TempPath, L"nta", 0, FileName);
1917  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
1919 
1920  Success = WriteFile(Handle, "TESTDATA", 8, &Written, NULL);
1921  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
1922  ok(Written == 8, "WriteFile wrote %lu bytes\n", Written);
1923 
1924  Written = SetFilePointer(Handle, 6, NULL, FILE_BEGIN);
1925  ok(Written == 6, "SetFilePointer returned %lu bytes\n", Written);
1927  ok(Success == TRUE, "SetEndOfFile failed with %lu\n", GetLastError());
1928 
1929  Status = NtCreateSection(&SectionHandle,
1931  0, 0, PAGE_READONLY, SEC_COMMIT, Handle);
1933  BaseAddress = NULL;
1934  ViewSize = 0;
1935  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0,
1936  0, 0, &ViewSize, ViewShare, 0, PAGE_READONLY);
1938 
1939  if (BaseAddress)
1940  {
1941  // First we test data that was truncated even before the file mapping was opened
1942  Length = strlen((char*)BaseAddress);
1943  ok(Length == 6, "Old data was not properly erased! (Length=%lu)\n", Length);
1944  }
1945 
1946  // Now we truncate the file on disk some more
1947  Written = SetFilePointer(Handle, 4, NULL, FILE_BEGIN);
1948  ok(Written == 4, "SetFilePointer returned %lu bytes\n", Written);
1950  Error = GetLastError();
1951  ok(Success == FALSE, "SetEndOfFile succeeded\n");
1952  ok(Error == ERROR_USER_MAPPED_FILE, "SetEndOfFile did not set error to ERROR_USER_MAPPED_FILE (%lu)\n", Error);
1953 
1954  if (BaseAddress)
1955  {
1956  Length = strlen((char*)BaseAddress);
1957  ok(Length == 6, "Length should not have changed! (Length=%lu)\n", Length);
1958  }
1959 
1960  // Unmap and set the end shorter.
1963  Success = CloseHandle(SectionHandle);
1964  ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1965 
1966  Written = SetFilePointer(Handle, 4, NULL, FILE_BEGIN);
1967  ok(Written == 4, "SetFilePointer returned %lu bytes\n", Written);
1969  ok(Success == TRUE, "SetEndOfFile failed with %lu\n", GetLastError());
1970 
1971  Status = NtCreateSection(&SectionHandle,
1973  0, 0, PAGE_READONLY, SEC_COMMIT, Handle);
1975  BaseAddress = NULL;
1976  ViewSize = 0;
1977  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0,
1978  0, 0, &ViewSize, ViewShare, 0, PAGE_READONLY);
1980 
1981  // CLEANUP
1984  Success = CloseHandle(SectionHandle);
1985  ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1987  ok(Success == TRUE, "CloseHandle failed with %lu\n", GetLastError());
1988 
1990  ok(Success == TRUE, "DeleteFileW failed with %lu\n", GetLastError());
1991 }
1992 
1994 {
2000  Test_RawSize(0);
2001  Test_RawSize(1);
2002  Test_RawSize(2);
2003  Test_EmptyFile();
2004  Test_Truncate();
2005 }
#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:3782
#define CloseHandle
Definition: compat.h:598
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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:3373
#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:2986
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:1044
#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
_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:3554
NTSTATUS NTAPI NtFlushVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN OUT PSIZE_T NumberOfBytesToFlush, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: virtual.c:3910
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#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
smooth NULL
Definition: ftsmooth.c:416
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
_In_ HANDLE Handle
Definition: extypes.h:390
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 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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define IMAGE_SCN_MEM_WRITE
Definition: ntimage.h:241
#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH
Definition: ntstatus.h:128
Status
Definition: gdiplustypes.h:24
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:4367
#define GetModuleHandle
Definition: winbase.h:3667
#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 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
#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:6
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#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
return STATUS_SUCCESS
Definition: btrfs.c:3014
#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:5090