ReactOS  0.4.13-dev-257-gfabbd7c
pagefile.c
Go to the documentation of this file.
1 /*
2  * ReactOS kernel
3  * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 /*
20  * PROJECT: ReactOS kernel
21  * FILE: ntoskrnl/mm/pagefile.c
22  * PURPOSE: Paging file functions
23  * PROGRAMMER: David Welch (welch@mcmail.com)
24  * Pierre Schweitzer
25  * UPDATE HISTORY:
26  * Created 22/05/98
27  */
28 
29 /* INCLUDES *****************************************************************/
30 
31 #include <ntoskrnl.h>
32 #define NDEBUG
33 #include <debug.h>
34 
35 #if defined (ALLOC_PRAGMA)
36 #pragma alloc_text(INIT, MmInitPagingFile)
37 #endif
38 
39 /* GLOBALS *******************************************************************/
40 
41 #define PAIRS_PER_RUN (1024)
42 
43 /* List of paging files, both used and free */
45 
46 /* Lock for examining the list of paging files */
48 
49 /* Number of paging files */
51 
52 /* Number of pages that are available for swapping */
54 
55 /* Number of pages that have been allocated for swapping */
57 
59 
60 /*
61  * Number of pages that have been reserved for swapping but not yet allocated
62  */
64 
65 /*
66  * Ratio between reserved and available swap pages, e.g. setting this to five
67  * forces one swap page to be available for every five swap pages that are
68  * reserved. Setting this to zero turns off commit checking altogether.
69  */
70 #define MM_PAGEFILE_COMMIT_RATIO (1)
71 
72 /*
73  * Number of pages that can be used for potentially swapable memory without
74  * pagefile space being reserved. The intention is that this allows smss
75  * to start up and create page files while ordinarily having a commit
76  * ratio of one.
77  */
78 #define MM_PAGEFILE_COMMIT_GRACE (256)
79 
80 /*
81  * Translate between a swap entry and a file and offset pair.
82  */
83 #define FILE_FROM_ENTRY(i) ((i) & 0x0f)
84 #define OFFSET_FROM_ENTRY(i) ((i) >> 11)
85 #define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | ((j) << 11) | 0x400)
86 
87 /* Make sure there can be only 16 paging files */
89 
91 
93 
94 /* FUNCTIONS *****************************************************************/
95 
96 VOID
97 NTAPI
99 {
100  memcpy(Mdl + 1, Pages, sizeof(PFN_NUMBER) * (PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGE_SIZE));
101 
102  /* FIXME: this flag should be set by the caller perhaps? */
103  Mdl->MdlFlags |= MDL_IO_PAGE_READ;
104 }
105 
106 
107 BOOLEAN
108 NTAPI
110 {
111  ULONG i;
112 
113  /* Loop through all the paging files */
114  for (i = 0; i < MmNumberOfPagingFiles; i++)
115  {
116  /* Check if this is one of them */
117  if (MmPagingFile[i]->FileObject == FileObject) return TRUE;
118  }
119 
120  /* Nothing found */
121  return FALSE;
122 }
123 
124 VOID
125 NTAPI
127 {
128  if (!MmSwapSpaceMessage)
129  {
130  DPRINT1("MM: Out of swap space.\n");
132  }
133 }
134 
135 NTSTATUS
136 NTAPI
138 {
139  ULONG i;
141  LARGE_INTEGER file_offset;
144  KEVENT Event;
145  UCHAR MdlBase[sizeof(MDL) + sizeof(ULONG)];
146  PMDL Mdl = (PMDL)MdlBase;
147 
148  DPRINT("MmWriteToSwapPage\n");
149 
150  if (SwapEntry == 0)
151  {
152  KeBugCheck(MEMORY_MANAGEMENT);
153  return(STATUS_UNSUCCESSFUL);
154  }
155 
156  i = FILE_FROM_ENTRY(SwapEntry);
157  offset = OFFSET_FROM_ENTRY(SwapEntry) - 1;
158 
159  if (MmPagingFile[i]->FileObject == NULL ||
160  MmPagingFile[i]->FileObject->DeviceObject == NULL)
161  {
162  DPRINT1("Bad paging file 0x%.8X\n", SwapEntry);
163  KeBugCheck(MEMORY_MANAGEMENT);
164  }
165 
167  MmBuildMdlFromPages(Mdl, &Page);
168  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
169 
170  file_offset.QuadPart = offset * PAGE_SIZE;
171 
174  Mdl,
175  &file_offset,
176  &Event,
177  &Iosb);
178  if (Status == STATUS_PENDING)
179  {
181  Status = Iosb.Status;
182  }
183 
184  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
185  {
186  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
187  }
188  return(Status);
189 }
190 
191 
192 NTSTATUS
193 NTAPI
195 {
196  return MiReadPageFile(Page, FILE_FROM_ENTRY(SwapEntry), OFFSET_FROM_ENTRY(SwapEntry) - 1);
197 }
198 
199 NTSTATUS
200 NTAPI
202  _In_ PFN_NUMBER Page,
203  _In_ ULONG PageFileIndex,
204  _In_ ULONG_PTR PageFileOffset)
205 {
206  LARGE_INTEGER file_offset;
209  KEVENT Event;
210  UCHAR MdlBase[sizeof(MDL) + sizeof(ULONG)];
211  PMDL Mdl = (PMDL)MdlBase;
212  PMMPAGING_FILE PagingFile;
213 
214  DPRINT("MiReadSwapFile\n");
215 
216  if (PageFileOffset == 0)
217  {
218  KeBugCheck(MEMORY_MANAGEMENT);
219  return(STATUS_UNSUCCESSFUL);
220  }
221 
222  ASSERT(PageFileIndex < MAX_PAGING_FILES);
223 
224  PagingFile = MmPagingFile[PageFileIndex];
225 
226  if (PagingFile->FileObject == NULL || PagingFile->FileObject->DeviceObject == NULL)
227  {
228  DPRINT1("Bad paging file %u\n", PageFileIndex);
229  KeBugCheck(MEMORY_MANAGEMENT);
230  }
231 
233  MmBuildMdlFromPages(Mdl, &Page);
234  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
235 
236  file_offset.QuadPart = PageFileOffset * PAGE_SIZE;
237 
239  Status = IoPageRead(PagingFile->FileObject,
240  Mdl,
241  &file_offset,
242  &Event,
243  &Iosb);
244  if (Status == STATUS_PENDING)
245  {
247  Status = Iosb.Status;
248  }
249  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
250  {
251  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
252  }
253  return(Status);
254 }
255 
256 VOID
257 INIT_FUNCTION
258 NTAPI
260 {
261  ULONG i;
262 
264 
265  MiFreeSwapPages = 0;
266  MiUsedSwapPages = 0;
268 
269  for (i = 0; i < MAX_PAGING_FILES; i++)
270  {
271  MmPagingFile[i] = NULL;
272  }
274 }
275 
276 VOID
277 NTAPI
279 {
280  ULONG i;
281  ULONG_PTR off;
282  PMMPAGING_FILE PagingFile;
283 
285  off = OFFSET_FROM_ENTRY(Entry) - 1;
286 
288 
289  PagingFile = MmPagingFile[i];
290  if (PagingFile == NULL)
291  {
292  KeBugCheck(MEMORY_MANAGEMENT);
293  }
294 
295  RtlClearBit(PagingFile->Bitmap, off >> 5);
296 
297  PagingFile->FreeSpace++;
298  PagingFile->CurrentUsage--;
299 
300  MiFreeSwapPages++;
301  MiUsedSwapPages--;
302 
304 }
305 
306 SWAPENTRY
307 NTAPI
309 {
310  ULONG i;
311  ULONG off;
313 
315 
316  if (MiFreeSwapPages == 0)
317  {
319  return(0);
320  }
321 
322  for (i = 0; i < MAX_PAGING_FILES; i++)
323  {
324  if (MmPagingFile[i] != NULL &&
325  MmPagingFile[i]->FreeSpace >= 1)
326  {
328  if (off == 0xFFFFFFFF)
329  {
330  KeBugCheck(MEMORY_MANAGEMENT);
332  return(STATUS_UNSUCCESSFUL);
333  }
334  MiUsedSwapPages++;
335  MiFreeSwapPages--;
337 
339  return(entry);
340  }
341  }
342 
344  KeBugCheck(MEMORY_MANAGEMENT);
345  return(0);
346 }
347 
350  IN PLARGE_INTEGER MinimumSize,
352  IN ULONG Reserved)
353 {
359  PMMPAGING_FILE PagingFile;
360  ULONG AllocMapSize;
361  ULONG Count;
363  UNICODE_STRING PageFileName;
364  LARGE_INTEGER SafeMinimumSize, SafeMaximumSize, AllocationSize;
365  FILE_FS_DEVICE_INFORMATION FsDeviceInfo;
367  PACL Dacl;
368  PWSTR Buffer;
370 
371  PAGED_CODE();
372 
373  DPRINT("NtCreatePagingFile(FileName: '%wZ', MinimumSize: %I64d, MaximumSize: %I64d)\n",
374  FileName, MinimumSize->QuadPart, MaximumSize->QuadPart);
375 
377  {
379  }
380 
382 
383  if (PreviousMode != KernelMode)
384  {
386  {
388  }
389 
390  _SEH2_TRY
391  {
392  SafeMinimumSize = ProbeForReadLargeInteger(MinimumSize);
393  SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
394  PageFileName = ProbeForReadUnicodeString(FileName);
395  }
397  {
398  /* Return the exception code */
400  }
401  _SEH2_END;
402  }
403  else
404  {
405  SafeMinimumSize = *MinimumSize;
406  SafeMaximumSize = *MaximumSize;
407  PageFileName = *FileName;
408  }
409 
410  /*
411  * Pagefiles can't be larger than 4GB and of course
412  * the minimum should be smaller than the maximum.
413  */
414  // TODO: Actually validate the lower bound of these sizes!
415  if (0 != SafeMinimumSize.u.HighPart)
416  {
418  }
419  if (0 != SafeMaximumSize.u.HighPart)
420  {
422  }
423  if (SafeMaximumSize.u.LowPart < SafeMinimumSize.u.LowPart)
424  {
426  }
427 
428  /* Validate the name length */
429  if ((PageFileName.Length == 0) ||
430  (PageFileName.Length > 128 * sizeof(WCHAR)))
431  {
433  }
434 
435  /* We don't care about any potential UNICODE_NULL */
436  PageFileName.MaximumLength = PageFileName.Length;
437  /* Allocate a buffer to keep the name copy */
439  if (Buffer == NULL)
440  {
442  }
443 
444  /* Copy the name */
445  if (PreviousMode != KernelMode)
446  {
447  _SEH2_TRY
448  {
449  ProbeForRead(PageFileName.Buffer, PageFileName.Length, sizeof(WCHAR));
450  RtlCopyMemory(Buffer, PageFileName.Buffer, PageFileName.Length);
451  }
453  {
455 
456  /* Return the exception code */
458  }
459  _SEH2_END;
460  }
461  else
462  {
463  RtlCopyMemory(Buffer, PageFileName.Buffer, PageFileName.Length);
464  }
465 
466  /* Replace caller's buffer with ours */
467  PageFileName.Buffer = Buffer;
468 
469  /* Create the security descriptor for the page file */
471  if (!NT_SUCCESS(Status))
472  {
474  return Status;
475  }
476 
477  /* Create the DACL: we will only allow two SIDs */
478  Count = sizeof(ACL) + (sizeof(ACE) + RtlLengthSid(SeLocalSystemSid)) +
479  (sizeof(ACE) + RtlLengthSid(SeAliasAdminsSid));
481  if (Dacl == NULL)
482  {
485  }
486 
487  /* Initialize the DACL */
489  if (!NT_SUCCESS(Status))
490  {
491  ExFreePoolWithTag(Dacl, 'lcaD');
493  return Status;
494  }
495 
496  /* Grant full access to admins */
498  if (!NT_SUCCESS(Status))
499  {
500  ExFreePoolWithTag(Dacl, 'lcaD');
502  return Status;
503  }
504 
505  /* Grant full access to SYSTEM */
507  if (!NT_SUCCESS(Status))
508  {
509  ExFreePoolWithTag(Dacl, 'lcaD');
511  return Status;
512  }
513 
514  /* Attach the DACL to the security descriptor */
516  if (!NT_SUCCESS(Status))
517  {
518  ExFreePoolWithTag(Dacl, 'lcaD');
520  return Status;
521  }
522 
524  &PageFileName,
526  NULL,
528 
529  /* Make sure we can at least store a complete page:
530  * If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
531  * a problem if the paging file is fragmented. Suppose the first cluster
532  * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
533  * paging file but of another file. We can't write a complete page (4096
534  * bytes) to the physical location of cluster 3042 then. */
535  AllocationSize.QuadPart = SafeMinimumSize.QuadPart + PAGE_SIZE;
536 
537  /* First, attempt to replace the page file, if existing */
541  &IoStatus,
547  NULL,
548  0,
550  NULL,
552  /* If we failed, relax a bit constraints, someone may be already holding the
553  * the file, so share write, don't attempt to replace and don't delete on close
554  * (basically, don't do anything conflicting)
555  * This can happen if the caller attempts to extend a page file.
556  */
557  if (!NT_SUCCESS(Status))
558  {
559  ULONG i;
560 
564  &IoStatus,
568  FILE_OPEN,
570  NULL,
571  0,
573  NULL,
575  if (!NT_SUCCESS(Status))
576  {
577  ExFreePoolWithTag(Dacl, 'lcaD');
579  return Status;
580  }
581 
582  /* We opened it! Check we are that "someone" ;-)
583  * First, get the opened file object.
584  */
588  KernelMode,
589  (PVOID*)&FileObject,
590  NULL);
591  if (!NT_SUCCESS(Status))
592  {
594  ExFreePoolWithTag(Dacl, 'lcaD');
596  return Status;
597  }
598 
599  /* Find if it matches a previous page file */
600  PagingFile = NULL;
601 
602  /* FIXME: should be calling unsafe instead,
603  * we should already be in a guarded region
604  */
606  if (MmNumberOfPagingFiles > 0)
607  {
608  i = 0;
609 
610  while (MmPagingFile[i]->FileObject->SectionObjectPointer != FileObject->SectionObjectPointer)
611  {
612  ++i;
613  if (i >= MmNumberOfPagingFiles)
614  {
615  break;
616  }
617  }
618 
619  /* This is the matching page file */
620  PagingFile = MmPagingFile[i];
621  }
622 
623  /* If we didn't find the page file, fail */
624  if (PagingFile == NULL)
625  {
629  ExFreePoolWithTag(Dacl, 'lcaD');
631  return STATUS_NOT_FOUND;
632  }
633 
634  /* Don't allow page file shrinking */
635  if (PagingFile->MinimumSize > (SafeMinimumSize.QuadPart >> PAGE_SHIFT))
636  {
640  ExFreePoolWithTag(Dacl, 'lcaD');
643  }
644 
645  if ((SafeMaximumSize.QuadPart >> PAGE_SHIFT) < PagingFile->MaximumSize)
646  {
650  ExFreePoolWithTag(Dacl, 'lcaD');
653  }
654 
655  /* FIXME: implement parameters checking and page file extension */
657 
661  ExFreePoolWithTag(Dacl, 'lcaD');
663  return STATUS_NOT_IMPLEMENTED;
664  }
665 
666  if (!NT_SUCCESS(Status))
667  {
668  DPRINT1("Failed creating page file: %lx\n", Status);
669  ExFreePoolWithTag(Dacl, 'lcaD');
671  return Status;
672  }
673 
674  /* Set the security descriptor */
675  if (NT_SUCCESS(IoStatus.Status))
676  {
678  if (!NT_SUCCESS(Status))
679  {
680  ExFreePoolWithTag(Dacl, 'lcaD');
683  return Status;
684  }
685  }
686 
687  /* DACL is no longer needed, free it */
688  ExFreePoolWithTag(Dacl, 'lcaD');
689 
690  /* FIXME: To enable once page file managment is moved to ARM3 */
691 #if 0
692  /* Check we won't overflow commit limit with the page file */
694  {
698  }
699 #endif
700 
701  /* Set its end of file to minimal size */
702  Status = ZwSetInformationFile(FileHandle,
703  &IoStatus,
704  &SafeMinimumSize,
705  sizeof(LARGE_INTEGER),
707  if (!NT_SUCCESS(Status) || !NT_SUCCESS(IoStatus.Status))
708  {
711  return Status;
712  }
713 
717  KernelMode,
718  (PVOID*)&FileObject,
719  NULL);
720  if (!NT_SUCCESS(Status))
721  {
724  return Status;
725  }
726 
727  /* Only allow page file on a few device types */
731  {
735  return Status;
736  }
737 
738  /* Deny page file creation on a floppy disk */
739  FsDeviceInfo.Characteristics = 0;
740  IoQueryVolumeInformation(FileObject, FileFsDeviceInformation, sizeof(FsDeviceInfo), &FsDeviceInfo, &Count);
742  {
746  return STATUS_FLOPPY_VOLUME;
747  }
748 
749  PagingFile = ExAllocatePoolWithTag(NonPagedPool, sizeof(*PagingFile), TAG_MM);
750  if (PagingFile == NULL)
751  {
756  }
757 
758  RtlZeroMemory(PagingFile, sizeof(*PagingFile));
759 
760  PagingFile->FileHandle = FileHandle;
761  PagingFile->FileObject = FileObject;
762  PagingFile->MaximumSize = (SafeMaximumSize.QuadPart >> PAGE_SHIFT);
763  PagingFile->Size = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
764  PagingFile->MinimumSize = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
765  /* First page is never used: it's the header
766  * TODO: write it
767  */
768  PagingFile->FreeSpace = (ULONG)(SafeMinimumSize.QuadPart / PAGE_SIZE) - 1;
769  PagingFile->CurrentUsage = 0;
770  PagingFile->PageFileName = PageFileName;
771  ASSERT(PagingFile->Size == PagingFile->FreeSpace + PagingFile->CurrentUsage + 1);
772 
773  AllocMapSize = sizeof(RTL_BITMAP) + (((PagingFile->MaximumSize + 31) / 32) * sizeof(ULONG));
775  AllocMapSize,
776  TAG_MM);
777  if (PagingFile->Bitmap == NULL)
778  {
779  ExFreePoolWithTag(PagingFile, TAG_MM);
784  }
785 
786  RtlInitializeBitMap(PagingFile->Bitmap,
787  (PULONG)(PagingFile->Bitmap + 1),
788  (ULONG)(PagingFile->MaximumSize));
789  RtlClearAllBits(PagingFile->Bitmap);
790 
791  /* FIXME: should be calling unsafe instead,
792  * we should already be in a guarded region
793  */
796  MmPagingFile[MmNumberOfPagingFiles] = PagingFile;
798  MiFreeSwapPages = MiFreeSwapPages + PagingFile->FreeSpace;
800 
802 
804  {
806  }
807 
808  return STATUS_SUCCESS;
809 }
810 
811 /* EOF */
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID INIT_FUNCTION NTAPI MmInitPagingFile(VOID)
Definition: pagefile.c:259
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define IN
Definition: typedefs.h:38
static PFN_COUNT MiReservedSwapPages
Definition: pagefile.c:63
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define FILE_NO_COMPRESSION
Definition: from_kernel.h:43
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _RTL_BITMAP RTL_BITMAP
#define MmInitializeMdl(_MemoryDescriptorList, _BaseVa, _Length)
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
USHORT MaximumLength
Definition: env_spec_w32.h:370
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
ULONG PFN_COUNT
Definition: mmtypes.h:102
#define SL_OPEN_PAGING_FILE
Definition: iotypes.h:1773
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
VOID NTAPI MmBuildMdlFromPages(PMDL Mdl, PPFN_NUMBER Pages)
Definition: pagefile.c:98
#define FILE_DEVICE_DFS_FILE_SYSTEM
Definition: winioctl.h:158
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:54
DeviceType
Definition: mmdrv.h:41
SWAPENTRY NTAPI MmAllocSwapPage(VOID)
Definition: pagefile.c:308
LONG NTSTATUS
Definition: precomp.h:26
PFN_NUMBER Size
Definition: mm.h:429
GLintptr offset
Definition: glext.h:5920
SIZE_T MmTotalCommitLimitMaximum
Definition: mminit.c:360
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2982
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI IoPageRead(IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
Definition: iofunc.c:1199
PFILE_OBJECT FileObject
Definition: mm.h:434
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
#define STATUS_INVALID_PARAMETER_MIX
Definition: ntstatus.h:271
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
PVOID PMDL
Definition: usb.h:39
VOID NTAPI MmShowOutOfSpaceMessagePagingFile(VOID)
Definition: pagefile.c:126
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
NTSTATUS NTAPI MiReadPageFile(_In_ PFN_NUMBER Page, _In_ ULONG PageFileIndex, _In_ ULONG_PTR PageFileOffset)
Definition: pagefile.c:201
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
#define PAGED_CODE()
Definition: video.h:57
#define FILE_SHARE_READ
Definition: compat.h:125
_SEH2_TRY
Definition: create.c:4250
BOOLEAN NTAPI IoInitializeCrashDump(IN HANDLE PageFileHandle)
Definition: iomgr.c:656
#define STATUS_TOO_MANY_PAGING_FILES
Definition: ntstatus.h:373
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define FILE_DEVICE_DFS_VOLUME
Definition: winioctl.h:159
HANDLE FileHandle
Definition: stats.c:38
ULONG * PPFN_NUMBER
Definition: ke.h:8
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS NTAPI IoQueryVolumeInformation(IN PFILE_OBJECT FileObject, IN FS_INFORMATION_CLASS FsInformationClass, IN ULONG Length, OUT PVOID FsInformation, OUT PULONG ReturnedLength)
Definition: iofunc.c:1292
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
ULONG PFN_NUMBER
Definition: ke.h:8
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:463
#define TAG_MM
Definition: tag.h:136
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:508
#define FILE_READ_DATA
Definition: nt_native.h:628
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static BOOLEAN MmSwapSpaceMessage
Definition: pagefile.c:90
unsigned char BOOLEAN
#define DO_SYSTEM_BOOT_PARTITION
Definition: env_spec_w32.h:400
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
BOOLEAN MmZeroPageFile
Definition: pagefile.c:58
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1465
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
Definition: bufpool.h:45
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFN_NUMBER MaximumSize
Definition: mm.h:430
PFN_NUMBER MinimumSize
Definition: mm.h:431
#define FILE_WRITE_DATA
Definition: nt_native.h:631
UNICODE_STRING PageFileName
Definition: mm.h:435
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define STATUS_NOT_FOUND
Definition: shellext.h:67
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
const LUID SeCreatePagefilePrivilege
Definition: priv.c:36
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
PFN_NUMBER FreeSpace
Definition: mm.h:432
#define FILE_FROM_ENTRY(i)
Definition: pagefile.c:83
#define MAX_PAGING_FILES
Definition: mm.h:105
__wchar_t WCHAR
Definition: xmlstorage.h:180
return Iosb
Definition: create.c:4426
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
BOOLEAN NTAPI MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject)
Definition: pagefile.c:109
#define WRITE_DAC
Definition: nt_native.h:59
#define ENTRY_FROM_FILE_OFFSET(i, j)
Definition: pagefile.c:85
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1954
ULONG MmNumberOfPagingFiles
Definition: pagefile.c:50
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
KGUARDED_MUTEX MmPageFileCreationLock
Definition: pagefile.c:47
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
unsigned char UCHAR
Definition: xmlstorage.h:181
PSID SeAliasAdminsSid
Definition: sid.c:47
NTSTATUS NTAPI MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:137
MDL
Definition: mmtypes.h:117
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
HANDLE FileHandle
Definition: mm.h:437
#define _In_
Definition: no_sal2.h:204
PMMPAGING_FILE MmPagingFile[MAX_PAGING_FILES]
Definition: pagefile.c:44
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
PFN_NUMBER CurrentUsage
Definition: mm.h:433
struct _FileName FileName
Definition: fatprocs.h:884
PRTL_BITMAP Bitmap
Definition: mm.h:436
_SEH2_END
Definition: create.c:4424
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
ULONG_PTR SWAPENTRY
Definition: mm.h:47
#define DEVICE_TYPE
Definition: guid.c:10
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoSynchronousPageWrite(IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
Definition: iofunc.c:1144
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:125
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3009
#define ACL_REVISION
Definition: setypes.h:39
NTSTATUS NTAPI NtCreatePagingFile(IN PUNICODE_STRING FileName, IN PLARGE_INTEGER MinimumSize, IN PLARGE_INTEGER MaximumSize, IN ULONG Reserved)
Definition: pagefile.c:349
PSID SeLocalSystemSid
Definition: sid.c:44
struct _LARGE_INTEGER::@2192 u
NTSTATUS NTAPI MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:194
unsigned int ULONG
Definition: retypes.h:1
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define OFFSET_FROM_ENTRY(i)
Definition: pagefile.c:84
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PFN_COUNT MiUsedSwapPages
Definition: pagefile.c:56
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
Definition: rtltypes.h:988
base of all file and directory entries
Definition: entries.h:82
C_ASSERT(FILE_FROM_ENTRY(0xffffffff)< MAX_PAGING_FILES)
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125
PFN_COUNT MiFreeSwapPages
Definition: pagefile.c:53
LONGLONG QuadPart
Definition: typedefs.h:112
#define STATUS_FLOPPY_VOLUME
Definition: ntstatus.h:578
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:278
off
Definition: i386-dis.c:3909
static BOOLEAN MmSystemPageFileLocated
Definition: pagefile.c:92