ReactOS  0.4.15-dev-1397-g19779b3
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 /* GLOBALS *******************************************************************/
36 
37 #define PAIRS_PER_RUN (1024)
38 
39 /* List of paging files, both used and free */
41 
42 /* Lock for examining the list of paging files */
44 
45 /* Number of paging files */
47 
48 /* Number of pages that are available for swapping */
50 
51 /* Number of pages that have been allocated for swapping */
53 
55 
56 /*
57  * Number of pages that have been reserved for swapping but not yet allocated
58  */
60 
61 /*
62  * Ratio between reserved and available swap pages, e.g. setting this to five
63  * forces one swap page to be available for every five swap pages that are
64  * reserved. Setting this to zero turns off commit checking altogether.
65  */
66 #define MM_PAGEFILE_COMMIT_RATIO (1)
67 
68 /*
69  * Number of pages that can be used for potentially swapable memory without
70  * pagefile space being reserved. The intention is that this allows smss
71  * to start up and create page files while ordinarily having a commit
72  * ratio of one.
73  */
74 #define MM_PAGEFILE_COMMIT_GRACE (256)
75 
76 /*
77  * Translate between a swap entry and a file and offset pair.
78  */
79 #define FILE_FROM_ENTRY(i) ((i) & 0x0f)
80 #define OFFSET_FROM_ENTRY(i) ((i) >> 11)
81 #define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | ((j) << 11) | 0x400)
82 
83 /* Make sure there can be only 16 paging files */
85 
87 
89 
90 /* FUNCTIONS *****************************************************************/
91 
92 VOID
93 NTAPI
95 {
96  memcpy(Mdl + 1, Pages, sizeof(PFN_NUMBER) * (PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGE_SIZE));
97 
98  /* FIXME: this flag should be set by the caller perhaps? */
99  Mdl->MdlFlags |= MDL_IO_PAGE_READ;
100 }
101 
102 
103 BOOLEAN
104 NTAPI
106 {
107  ULONG i;
108 
109  /* Loop through all the paging files */
110  for (i = 0; i < MmNumberOfPagingFiles; i++)
111  {
112  /* Check if this is one of them */
113  if (MmPagingFile[i]->FileObject == FileObject) return TRUE;
114  }
115 
116  /* Nothing found */
117  return FALSE;
118 }
119 
120 VOID
121 NTAPI
123 {
124  if (!MmSwapSpaceMessage)
125  {
126  DPRINT1("MM: Out of swap space.\n");
128  }
129 }
130 
131 NTSTATUS
132 NTAPI
134 {
135  ULONG i;
137  LARGE_INTEGER file_offset;
140  KEVENT Event;
141  UCHAR MdlBase[sizeof(MDL) + sizeof(ULONG)];
142  PMDL Mdl = (PMDL)MdlBase;
143 
144  DPRINT("MmWriteToSwapPage\n");
145 
146  if (SwapEntry == 0)
147  {
148  KeBugCheck(MEMORY_MANAGEMENT);
149  return(STATUS_UNSUCCESSFUL);
150  }
151 
152  i = FILE_FROM_ENTRY(SwapEntry);
153  offset = OFFSET_FROM_ENTRY(SwapEntry) - 1;
154 
155  if (MmPagingFile[i]->FileObject == NULL ||
156  MmPagingFile[i]->FileObject->DeviceObject == NULL)
157  {
158  DPRINT1("Bad paging file 0x%.8X\n", SwapEntry);
159  KeBugCheck(MEMORY_MANAGEMENT);
160  }
161 
163  MmBuildMdlFromPages(Mdl, &Page);
164  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
165 
166  file_offset.QuadPart = offset * PAGE_SIZE;
167 
170  Mdl,
171  &file_offset,
172  &Event,
173  &Iosb);
174  if (Status == STATUS_PENDING)
175  {
177  Status = Iosb.Status;
178  }
179 
180  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
181  {
182  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
183  }
184  return(Status);
185 }
186 
187 
188 NTSTATUS
189 NTAPI
191 {
192  return MiReadPageFile(Page, FILE_FROM_ENTRY(SwapEntry), OFFSET_FROM_ENTRY(SwapEntry) - 1);
193 }
194 
195 NTSTATUS
196 NTAPI
198  _In_ PFN_NUMBER Page,
199  _In_ ULONG PageFileIndex,
200  _In_ ULONG_PTR PageFileOffset)
201 {
202  LARGE_INTEGER file_offset;
205  KEVENT Event;
206  UCHAR MdlBase[sizeof(MDL) + sizeof(ULONG)];
207  PMDL Mdl = (PMDL)MdlBase;
208  PMMPAGING_FILE PagingFile;
209 
210  DPRINT("MiReadSwapFile\n");
211 
212  if (PageFileOffset == 0)
213  {
214  KeBugCheck(MEMORY_MANAGEMENT);
215  return(STATUS_UNSUCCESSFUL);
216  }
217 
218  ASSERT(PageFileIndex < MAX_PAGING_FILES);
219 
220  PagingFile = MmPagingFile[PageFileIndex];
221 
222  if (PagingFile->FileObject == NULL || PagingFile->FileObject->DeviceObject == NULL)
223  {
224  DPRINT1("Bad paging file %u\n", PageFileIndex);
225  KeBugCheck(MEMORY_MANAGEMENT);
226  }
227 
229  MmBuildMdlFromPages(Mdl, &Page);
230  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
231 
232  file_offset.QuadPart = PageFileOffset * PAGE_SIZE;
233 
235  Status = IoPageRead(PagingFile->FileObject,
236  Mdl,
237  &file_offset,
238  &Event,
239  &Iosb);
240  if (Status == STATUS_PENDING)
241  {
243  Status = Iosb.Status;
244  }
245  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
246  {
247  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
248  }
249  return(Status);
250 }
251 
252 CODE_SEG("INIT")
253 VOID
254 NTAPI
256 {
257  ULONG i;
258 
260 
261  MiFreeSwapPages = 0;
262  MiUsedSwapPages = 0;
264 
265  for (i = 0; i < MAX_PAGING_FILES; i++)
266  {
267  MmPagingFile[i] = NULL;
268  }
270 }
271 
272 VOID
273 NTAPI
275 {
276  ULONG i;
277  ULONG_PTR off;
278  PMMPAGING_FILE PagingFile;
279 
281  off = OFFSET_FROM_ENTRY(Entry) - 1;
282 
284 
285  PagingFile = MmPagingFile[i];
286  if (PagingFile == NULL)
287  {
288  KeBugCheck(MEMORY_MANAGEMENT);
289  }
290 
291  RtlClearBit(PagingFile->Bitmap, off >> 5);
292 
293  PagingFile->FreeSpace++;
294  PagingFile->CurrentUsage--;
295 
296  MiFreeSwapPages++;
297  MiUsedSwapPages--;
298 
300 }
301 
302 SWAPENTRY
303 NTAPI
305 {
306  ULONG i;
307  ULONG off;
309 
311 
312  if (MiFreeSwapPages == 0)
313  {
315  return(0);
316  }
317 
318  for (i = 0; i < MAX_PAGING_FILES; i++)
319  {
320  if (MmPagingFile[i] != NULL &&
321  MmPagingFile[i]->FreeSpace >= 1)
322  {
324  if (off == 0xFFFFFFFF)
325  {
326  KeBugCheck(MEMORY_MANAGEMENT);
328  return(STATUS_UNSUCCESSFUL);
329  }
330  MiUsedSwapPages++;
331  MiFreeSwapPages--;
333 
334  entry = ENTRY_FROM_FILE_OFFSET(i, off + 1);
335  return(entry);
336  }
337  }
338 
340  KeBugCheck(MEMORY_MANAGEMENT);
341  return(0);
342 }
343 
346  IN PLARGE_INTEGER MinimumSize,
348  IN ULONG Reserved)
349 {
355  PMMPAGING_FILE PagingFile;
356  SIZE_T AllocMapSize;
357  ULONG Count;
359  UNICODE_STRING PageFileName;
360  LARGE_INTEGER SafeMinimumSize, SafeMaximumSize, AllocationSize;
361  FILE_FS_DEVICE_INFORMATION FsDeviceInfo;
363  PACL Dacl;
364  PWSTR Buffer;
366 
367  PAGED_CODE();
368 
369  DPRINT("NtCreatePagingFile(FileName: '%wZ', MinimumSize: %I64d, MaximumSize: %I64d)\n",
370  FileName, MinimumSize->QuadPart, MaximumSize->QuadPart);
371 
373  {
375  }
376 
378 
379  if (PreviousMode != KernelMode)
380  {
382  {
384  }
385 
386  _SEH2_TRY
387  {
388  SafeMinimumSize = ProbeForReadLargeInteger(MinimumSize);
389  SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
390  PageFileName = ProbeForReadUnicodeString(FileName);
391  }
393  {
394  /* Return the exception code */
396  }
397  _SEH2_END;
398  }
399  else
400  {
401  SafeMinimumSize = *MinimumSize;
402  SafeMaximumSize = *MaximumSize;
403  PageFileName = *FileName;
404  }
405 
406  /*
407  * Pagefiles can't be larger than 4GB and of course
408  * the minimum should be smaller than the maximum.
409  */
410  // TODO: Actually validate the lower bound of these sizes!
411  if (0 != SafeMinimumSize.u.HighPart)
412  {
414  }
415  if (0 != SafeMaximumSize.u.HighPart)
416  {
418  }
419  if (SafeMaximumSize.u.LowPart < SafeMinimumSize.u.LowPart)
420  {
422  }
423 
424  /* Validate the name length */
425  if ((PageFileName.Length == 0) ||
426  (PageFileName.Length > 128 * sizeof(WCHAR)))
427  {
429  }
430 
431  /* We don't care about any potential UNICODE_NULL */
432  PageFileName.MaximumLength = PageFileName.Length;
433  /* Allocate a buffer to keep the name copy */
435  if (Buffer == NULL)
436  {
438  }
439 
440  /* Copy the name */
441  if (PreviousMode != KernelMode)
442  {
443  _SEH2_TRY
444  {
445  ProbeForRead(PageFileName.Buffer, PageFileName.Length, sizeof(WCHAR));
446  RtlCopyMemory(Buffer, PageFileName.Buffer, PageFileName.Length);
447  }
449  {
451 
452  /* Return the exception code */
454  }
455  _SEH2_END;
456  }
457  else
458  {
459  RtlCopyMemory(Buffer, PageFileName.Buffer, PageFileName.Length);
460  }
461 
462  /* Replace caller's buffer with ours */
463  PageFileName.Buffer = Buffer;
464 
465  /* Create the security descriptor for the page file */
467  if (!NT_SUCCESS(Status))
468  {
470  return Status;
471  }
472 
473  /* Create the DACL: we will only allow two SIDs */
474  Count = sizeof(ACL) + (sizeof(ACE) + RtlLengthSid(SeLocalSystemSid)) +
475  (sizeof(ACE) + RtlLengthSid(SeAliasAdminsSid));
477  if (Dacl == NULL)
478  {
481  }
482 
483  /* Initialize the DACL */
485  if (!NT_SUCCESS(Status))
486  {
487  ExFreePoolWithTag(Dacl, 'lcaD');
489  return Status;
490  }
491 
492  /* Grant full access to admins */
494  if (!NT_SUCCESS(Status))
495  {
496  ExFreePoolWithTag(Dacl, 'lcaD');
498  return Status;
499  }
500 
501  /* Grant full access to SYSTEM */
503  if (!NT_SUCCESS(Status))
504  {
505  ExFreePoolWithTag(Dacl, 'lcaD');
507  return Status;
508  }
509 
510  /* Attach the DACL to the security descriptor */
512  if (!NT_SUCCESS(Status))
513  {
514  ExFreePoolWithTag(Dacl, 'lcaD');
516  return Status;
517  }
518 
520  &PageFileName,
522  NULL,
524 
525  /* Make sure we can at least store a complete page:
526  * If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
527  * a problem if the paging file is fragmented. Suppose the first cluster
528  * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
529  * paging file but of another file. We can't write a complete page (4096
530  * bytes) to the physical location of cluster 3042 then. */
531  AllocationSize.QuadPart = SafeMinimumSize.QuadPart + PAGE_SIZE;
532 
533  /* First, attempt to replace the page file, if existing */
537  &IoStatus,
543  NULL,
544  0,
546  NULL,
548  /* If we failed, relax a bit constraints, someone may be already holding the
549  * the file, so share write, don't attempt to replace and don't delete on close
550  * (basically, don't do anything conflicting)
551  * This can happen if the caller attempts to extend a page file.
552  */
553  if (!NT_SUCCESS(Status))
554  {
555  ULONG i;
556 
560  &IoStatus,
564  FILE_OPEN,
566  NULL,
567  0,
569  NULL,
571  if (!NT_SUCCESS(Status))
572  {
573  ExFreePoolWithTag(Dacl, 'lcaD');
575  return Status;
576  }
577 
578  /* We opened it! Check we are that "someone" ;-)
579  * First, get the opened file object.
580  */
584  KernelMode,
585  (PVOID*)&FileObject,
586  NULL);
587  if (!NT_SUCCESS(Status))
588  {
590  ExFreePoolWithTag(Dacl, 'lcaD');
592  return Status;
593  }
594 
595  /* Find if it matches a previous page file */
596  PagingFile = NULL;
597 
598  /* FIXME: should be calling unsafe instead,
599  * we should already be in a guarded region
600  */
602  if (MmNumberOfPagingFiles > 0)
603  {
604  i = 0;
605 
606  while (MmPagingFile[i]->FileObject->SectionObjectPointer != FileObject->SectionObjectPointer)
607  {
608  ++i;
609  if (i >= MmNumberOfPagingFiles)
610  {
611  break;
612  }
613  }
614 
615  /* This is the matching page file */
616  PagingFile = MmPagingFile[i];
617  }
618 
619  /* If we didn't find the page file, fail */
620  if (PagingFile == NULL)
621  {
625  ExFreePoolWithTag(Dacl, 'lcaD');
627  return STATUS_NOT_FOUND;
628  }
629 
630  /* Don't allow page file shrinking */
631  if (PagingFile->MinimumSize > (SafeMinimumSize.QuadPart >> PAGE_SHIFT))
632  {
636  ExFreePoolWithTag(Dacl, 'lcaD');
639  }
640 
641  if ((SafeMaximumSize.QuadPart >> PAGE_SHIFT) < PagingFile->MaximumSize)
642  {
646  ExFreePoolWithTag(Dacl, 'lcaD');
649  }
650 
651  /* FIXME: implement parameters checking and page file extension */
653 
657  ExFreePoolWithTag(Dacl, 'lcaD');
659  return STATUS_NOT_IMPLEMENTED;
660  }
661 
662  if (!NT_SUCCESS(Status))
663  {
664  DPRINT1("Failed creating page file: %lx\n", Status);
665  ExFreePoolWithTag(Dacl, 'lcaD');
667  return Status;
668  }
669 
670  /* Set the security descriptor */
671  if (NT_SUCCESS(IoStatus.Status))
672  {
674  if (!NT_SUCCESS(Status))
675  {
676  ExFreePoolWithTag(Dacl, 'lcaD');
679  return Status;
680  }
681  }
682 
683  /* DACL is no longer needed, free it */
684  ExFreePoolWithTag(Dacl, 'lcaD');
685 
686  /* FIXME: To enable once page file managment is moved to ARM3 */
687 #if 0
688  /* Check we won't overflow commit limit with the page file */
690  {
694  }
695 #endif
696 
697  /* Set its end of file to minimal size */
698  Status = ZwSetInformationFile(FileHandle,
699  &IoStatus,
700  &SafeMinimumSize,
701  sizeof(LARGE_INTEGER),
703  if (!NT_SUCCESS(Status) || !NT_SUCCESS(IoStatus.Status))
704  {
707  return Status;
708  }
709 
713  KernelMode,
714  (PVOID*)&FileObject,
715  NULL);
716  if (!NT_SUCCESS(Status))
717  {
720  return Status;
721  }
722 
723  /* Only allow page file on a few device types */
727  {
731  return Status;
732  }
733 
734  /* Deny page file creation on a floppy disk */
735  FsDeviceInfo.Characteristics = 0;
736  IoQueryVolumeInformation(FileObject, FileFsDeviceInformation, sizeof(FsDeviceInfo), &FsDeviceInfo, &Count);
738  {
742  return STATUS_FLOPPY_VOLUME;
743  }
744 
745  PagingFile = ExAllocatePoolWithTag(NonPagedPool, sizeof(*PagingFile), TAG_MM);
746  if (PagingFile == NULL)
747  {
752  }
753 
754  RtlZeroMemory(PagingFile, sizeof(*PagingFile));
755 
756  PagingFile->FileHandle = FileHandle;
757  PagingFile->FileObject = FileObject;
758  PagingFile->MaximumSize = (SafeMaximumSize.QuadPart >> PAGE_SHIFT);
759  PagingFile->Size = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
760  PagingFile->MinimumSize = (SafeMinimumSize.QuadPart >> PAGE_SHIFT);
761  /* First page is never used: it's the header
762  * TODO: write it
763  */
764  PagingFile->FreeSpace = (ULONG)(SafeMinimumSize.QuadPart / PAGE_SIZE) - 1;
765  PagingFile->CurrentUsage = 0;
766  PagingFile->PageFileName = PageFileName;
767  ASSERT(PagingFile->Size == PagingFile->FreeSpace + PagingFile->CurrentUsage + 1);
768 
769  AllocMapSize = sizeof(RTL_BITMAP) + (((PagingFile->MaximumSize + 31) / 32) * sizeof(ULONG));
771  AllocMapSize,
772  TAG_MM);
773  if (PagingFile->Bitmap == NULL)
774  {
775  ExFreePoolWithTag(PagingFile, TAG_MM);
780  }
781 
782  RtlInitializeBitMap(PagingFile->Bitmap,
783  (PULONG)(PagingFile->Bitmap + 1),
784  (ULONG)(PagingFile->MaximumSize));
785  RtlClearAllBits(PagingFile->Bitmap);
786 
787  /* FIXME: should be calling unsafe instead,
788  * we should already be in a guarded region
789  */
792  MmPagingFile[MmNumberOfPagingFiles] = PagingFile;
794  MiFreeSwapPages = MiFreeSwapPages + PagingFile->FreeSpace;
796 
798 
800  {
802  }
803 
804  return STATUS_SUCCESS;
805 }
806 
807 /* EOF */
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define IN
Definition: typedefs.h:39
static PFN_COUNT MiReservedSwapPages
Definition: pagefile.c:59
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define FILE_NO_COMPRESSION
Definition: from_kernel.h:43
#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
USHORT MaximumLength
Definition: env_spec_w32.h:370
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
ULONG PFN_COUNT
Definition: mmtypes.h:102
#define SL_OPEN_PAGING_FILE
Definition: iotypes.h:1797
#define TRUE
Definition: types.h:120
_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:94
#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:56
SWAPENTRY NTAPI MmAllocSwapPage(VOID)
Definition: pagefile.c:304
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
LONG NTSTATUS
Definition: precomp.h:26
PFN_NUMBER Size
Definition: mm.h:435
SIZE_T MmTotalCommitLimitMaximum
Definition: mminit.c:360
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:520
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
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:440
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define STATUS_INVALID_PARAMETER_MIX
Definition: ntstatus.h:285
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
PVOID PMDL
Definition: usb.h:39
VOID NTAPI MmShowOutOfSpaceMessagePagingFile(VOID)
Definition: pagefile.c:122
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
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
NTSTATUS NTAPI MiReadPageFile(_In_ PFN_NUMBER Page, _In_ ULONG PageFileIndex, _In_ ULONG_PTR PageFileOffset)
Definition: pagefile.c:197
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
#define FILE_SHARE_READ
Definition: compat.h:136
_SEH2_TRY
Definition: create.c:4226
BOOLEAN NTAPI IoInitializeCrashDump(IN HANDLE PageFileHandle)
Definition: iomgr.c:656
#define STATUS_TOO_MANY_PAGING_FILES
Definition: ntstatus.h:387
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
uint32_t ULONG_PTR
Definition: typedefs.h:65
#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:9
return STATUS_NOT_IMPLEMENTED
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:9
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#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 FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:524
#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:450
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static BOOLEAN MmSwapSpaceMessage
Definition: pagefile.c:86
unsigned char BOOLEAN
#define DO_SYSTEM_BOOT_PARTITION
Definition: env_spec_w32.h:400
struct _ACL ACL
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
BOOLEAN MmZeroPageFile
Definition: pagefile.c:54
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI MmInitPagingFile(VOID)
Definition: pagefile.c:255
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
Definition: bufpool.h:45
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
DeviceType
Definition: mmdrv.h:41
PFN_NUMBER MaximumSize
Definition: mm.h:436
PFN_NUMBER MinimumSize
Definition: mm.h:437
#define FILE_WRITE_DATA
Definition: nt_native.h:631
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
UNICODE_STRING PageFileName
Definition: mm.h:441
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
Status
Definition: gdiplustypes.h:24
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define STATUS_NOT_FOUND
Definition: shellext.h:72
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
int Count
Definition: noreturn.cpp:7
const LUID SeCreatePagefilePrivilege
Definition: priv.c:32
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define ASSERT(a)
Definition: mode.c:45
PFN_NUMBER FreeSpace
Definition: mm.h:438
#define FILE_FROM_ENTRY(i)
Definition: pagefile.c:79
#define MAX_PAGING_FILES
Definition: mm.h:105
__wchar_t WCHAR
Definition: xmlstorage.h:180
return Iosb
Definition: create.c:4402
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
GLintptr offset
Definition: glext.h:5920
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
BOOLEAN NTAPI MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject)
Definition: pagefile.c:105
#define WRITE_DAC
Definition: nt_native.h:59
#define ENTRY_FROM_FILE_OFFSET(i, j)
Definition: pagefile.c:81
CODE_SEG("INIT")
Definition: fsrtlpc.c:19
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1978
ULONG MmNumberOfPagingFiles
Definition: pagefile.c:46
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
KGUARDED_MUTEX MmPageFileCreationLock
Definition: pagefile.c:43
#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:1552
unsigned char UCHAR
Definition: xmlstorage.h:181
PSID SeAliasAdminsSid
Definition: sid.c:43
NTSTATUS NTAPI MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:133
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
struct _LARGE_INTEGER::@2277 u
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SYNCHRONIZE
Definition: nt_native.h:61
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define FILE_OPEN
Definition: from_kernel.h:54
HANDLE FileHandle
Definition: mm.h:443
#define _In_
Definition: no_sal2.h:158
PMMPAGING_FILE MmPagingFile[MAX_PAGING_FILES]
Definition: pagefile.c:40
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:319
ULONG_PTR SIZE_T
Definition: typedefs.h:80
PFN_NUMBER CurrentUsage
Definition: mm.h:439
struct _FileName FileName
Definition: fatprocs.h:893
PRTL_BITMAP Bitmap
Definition: mm.h:442
_SEH2_END
Definition: create.c:4400
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
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
#define NULL
Definition: types.h:112
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
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:345
PSID SeLocalSystemSid
Definition: sid.c:40
NTSTATUS NTAPI MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:190
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
unsigned int ULONG
Definition: retypes.h:1
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define OFFSET_FROM_ENTRY(i)
Definition: pagefile.c:80
#define UNIMPLEMENTED
Definition: debug.h:115
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PFN_COUNT MiUsedSwapPages
Definition: pagefile.c:52
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
Definition: rtltypes.h:990
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:49
LONGLONG QuadPart
Definition: typedefs.h:114
#define STATUS_FLOPPY_VOLUME
Definition: ntstatus.h:592
#define PAGED_CODE()
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:274
static BOOLEAN MmSystemPageFileLocated
Definition: pagefile.c:88