21#define STANDARD_PAGING_FILE_NAME L"\\??\\?:\\pagefile.sys"
22#define STANDARD_DRIVE_LETTER_OFFSET 4
23#define MAX_PAGING_FILES 16
24#define MEGABYTE (1024 * 1024)
30#define GIGABYTE (1024ULL * MEGABYTE)
31#define TERABYTE (1024ULL * GIGABYTE)
34#if (NTDDI_VERSION >= NTDDI_WINBLUE)
35#define MAXIMUM_PAGEFILE_SIZE32 ((1ULL * 1024 * 1024 - 1) * PAGE_SIZE)
39#define MAXIMUM_PAGEFILE_SIZE32 (4095ULL * MEGABYTE)
43#if (NTDDI_VERSION >= NTDDI_WINBLUE)
44#define MAXIMUM_PAGEFILE_SIZE64 ((4ULL * 1024 * 1024 * 1024 - 1) * PAGE_SIZE)
48#define MAXIMUM_PAGEFILE_SIZE64 (16ULL * TERABYTE)
52 #define MAXIMUM_PAGEFILE_SIZE MAXIMUM_PAGEFILE_SIZE32
54 #define MAXIMUM_PAGEFILE_SIZE_PAE MAXIMUM_PAGEFILE_SIZE64
55#elif defined (_M_AMD64) || defined(_M_ARM64)
56 #define MAXIMUM_PAGEFILE_SIZE MAXIMUM_PAGEFILE_SIZE64
57#elif defined (_M_IA64)
59 #define MAXIMUM_PAGEFILE_SIZE (32ULL * TERABYTE)
63 #if (NTDDI_VERSION >= NTDDI_WINBLUE)
64 #define MAXIMUM_PAGEFILE_SIZE ((512ULL * 1024 - 1) * PAGE_SIZE)
68 #define MAXIMUM_PAGEFILE_SIZE MAXIMUM_PAGEFILE_SIZE32
72#pragma message("Unknown architecture")
74 #define MAXIMUM_PAGEFILE_SIZE MAXIMUM_PAGEFILE_SIZE64
76 #define MAXIMUM_PAGEFILE_SIZE MAXIMUM_PAGEFILE_SIZE32
81#define MINIMUM_TO_KEEP_FREE (256 * MEGABYTE)
82#define FUZZ_FACTOR (16 * MEGABYTE)
87#define SMP_PAGEFILE_CREATED 0x01
88#define SMP_PAGEFILE_DEFAULT 0x02
89#define SMP_PAGEFILE_SYSTEM_MANAGED 0x04
90#define SMP_PAGEFILE_WAS_TOO_BIG 0x08
91#define SMP_PAGEFILE_ON_ANY_DRIVE 0x10
92#define SMP_PAGEFILE_EMERGENCY 0x20
93#define SMP_PAGEFILE_DUMP_PROCESSED 0x40
109#define SMP_VOLUME_INSERTED 0x01
110#define SMP_VOLUME_PAGEFILE_CREATED 0x04
111#define SMP_VOLUME_IS_BOOT 0x08
142 ULONG MinSize = 0, MaxSize = 0;
153 DPRINT1(
"SMSS:PFILE: Too many paging files specified - %lu\n",
159 DPRINT(
"SMSS:PFILE: Paging file specifier `%wZ'\n", PageFileToken);
168 DPRINT1(
"SMSS:PFILE: SmpParseCommandLine(%wZ) failed - Status == %lx\n",
184 if ((
c !=
L' ') && (
c !=
L'\t') && (
c !=
L'0'))
194 if (!(Arguments.
Buffer) || (ZeroSize))
197 SystemManaged =
TRUE;
275 DPRINT(
"SMSS:PFILE: Created descriptor for `%wZ' (`%wZ')\n",
282 NextEntry = NextEntry->
Flink;
287 DPRINT1(
"SMSS:PFILE: Skipping duplicate specifier `%wZ'\n", PageFileToken);
323 sizeof(StandardInfo),
327 DPRINT1(
"SMSS:PFILE: Failed query for size potential pagefile `%wZ' with status %X\n",
371 DPRINT1(
"SMSS:PFILE: Failed to delete page file `%wZ' (status %X)\n",
376 DPRINT(
"SMSS:PFILE: Deleted stale paging file - %wZ\n",
FileName);
384 DPRINT1(
"SMSS:PFILE: Failed to open for deletion page file `%wZ' (status %X)\n",
403 WCHAR PathString[32];
407 wcscpy(PathString,
L"\\??\\A:\\");
439 DPRINT1(
"SMSS:PFILE: Query volume `%wZ' (handle %p) for size failed"
458 Volume->FreeSpace.QuadPart = 0;
493 if (
Volume->DriveLetter == UpLetter)
break;
494 NextEntry = NextEntry->
Flink;
515 DPRINT(
"SMSS:PFILE: NtCreatePagingFile(%wZ, 0x%I64X, 0x%I64X) succeeded\n",
522 DPRINT1(
"SMSS:PFILE: NtCreatePagingFile(%wZ, 0x%I64X, 0x%I64X) failed with %X\n",
546 ShouldDelete =
FALSE;
551 DPRINT1(
"SMSS:PFILE: No volume descriptor for `%wZ'\n",
563 DPRINT(
"SMSS:PFILE: Checking for crash dump in `%wZ' on boot volume\n",
571 DPRINT1(
"SMSS:PFILE: Failed to query free space for boot volume `%wC'\n",
576 DPRINT(
"Queried free space for boot volume `%wC: 0x%I64x'\n",
587 DPRINT(
"SMSS:PFILE: Skipping crash dump checking for `%wZ' on non boot"
600 DPRINT(
"SMSS:PFILE: Detected size 0x%I64X for future paging file `%wZ'\n",
603 DPRINT(
"SMSS:PFILE: Free space on volume `%wC' is 0x%I64X\n",
605 Volume->FreeSpace.QuadPart);
617 DPRINT(
"SMSS:PFILE: min 0x%I64X, max 0x%I64X, real min 0x%I64X\n",
620 MinimumSize->QuadPart);
623 while (
Descriptor->ActualMinSize.QuadPart >= MinimumSize->QuadPart)
640 Descriptor->ActualMinSize.QuadPart -= FuzzFactor->QuadPart;
644 if (
Descriptor->ActualMinSize.QuadPart < MinimumSize->QuadPart)
654 DPRINT1(
"SMSS:PFILE: Failing for min 0x%I64X, max 0x%I64X, real min 0x%I64X\n",
657 MinimumSize->QuadPart);
696 NextEntry = NextEntry->
Flink;
729 DPRINT1(
"SMSS:PFILE: NtQuerySystemInformation failed with %x\n",
Status);
766 DPRINT(
"SMSS:PFILE: Validating sizes for `%wZ' 0x%I64X 0x%I64X\n",
770 if (MinSize > MaxSize)
774 if (MinSize > MaxPageFileSize)
777 MinSize = MaxPageFileSize;
779 if (MaxSize > MaxPageFileSize)
782 MaxSize = MaxPageFileSize;
788 DPRINT(
"SMSS:PFILE: Trimmed size of `%wZ' to maximum allowed\n",
891 &ProcessInformation.
Query,
892 sizeof(ProcessInformation.
Query),
896 DPRINT1(
"SMSS:PFILE: Query(ProcessDeviceMap) failed with status %X\n",
907 for (
Drive = StartChar, DriveDiff = StartChar -
L'A';
Drive <=
L'Z';
Drive++, DriveDiff++)
910 if (!((1 << DriveDiff) & ProcessInformation.
Query.DriveMap))
continue;
928 DPRINT1(
"SMSS:PFILE: Open volume `%wZ' failed with status %X\n",
942 DPRINT1(
"SMSS:PFILE: Query volume `%wZ' (handle %p) for device info"
943 " failed with status %X\n",
958 DPRINT1(
"SMSS:PFILE: Volume `%wZ' (%X) cannot store a paging file\n",
972 DPRINT1(
"SMSS:PFILE: Failed to allocate a volume descriptor (%u bytes)\n",
989 BootVolumeFound =
TRUE;
1001 DPRINT1(
"SMSS:PFILE: Query volume `%wZ' (handle %p) for size failed"
1002 " with status %X\n",
1023 Volume->FreeSpace.QuadPart = 0;
1035 DPRINT(
"SMSS:PFILE: Created volume descriptor for`%wZ'\n", &VolumePath);
1062 DPRINT1(
"SMSS:PFILE: No paging file was requested\n");
1071 DPRINT1(
"SMSS:PFILE: Failed to create volume descriptors (status %X)\n",
1088 DPRINT(
"SMSS:PFILE: Creating a system managed paging file (`%wZ')\n",
1094 DPRINT(
"SMSS:PFILE: Trying lower sizes for (`%wZ')\n",
1105 DPRINT(
"SMSS:PFILE: Creating a normal paging file (`%wZ')\n",
1117 DPRINT(
"SMSS:PFILE: Trying lower sizes for (`%wZ')\n",
1137 NextEntry = NextEntry->
Flink;
1144 DPRINT1(
"SMSS:PFILE: Creating emergency paging file.\n");
#define FILE_DIRECTORY_FILE
#define FILE_NON_DIRECTORY_FILE
#define SMP_PAGEFILE_DEFAULT
PSMP_VOLUME_DESCRIPTOR NTAPI SmpSearchVolumeDescriptor(IN WCHAR DriveLetter)
LIST_ENTRY SmpVolumeDescriptorList
struct _SMP_PAGEFILE_DESCRIPTOR * PSMP_PAGEFILE_DESCRIPTOR
NTSTATUS NTAPI SmpCreateEmergencyPagingFile(VOID)
#define SMP_PAGEFILE_DUMP_PROCESSED
VOID NTAPI SmpPagingFileInitialize(VOID)
NTSTATUS NTAPI SmpCreatePagingFileOnAnyDrive(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor, IN PLARGE_INTEGER FuzzFactor, IN PLARGE_INTEGER MinimumSize)
#define SMP_VOLUME_INSERTED
NTSTATUS NTAPI SmpCreatePagingFiles(VOID)
struct _SMP_VOLUME_DESCRIPTOR SMP_VOLUME_DESCRIPTOR
#define STANDARD_DRIVE_LETTER_OFFSET
NTSTATUS NTAPI SmpCreatePagingFile(IN PUNICODE_STRING Name, IN PLARGE_INTEGER MinSize, IN PLARGE_INTEGER MaxSize, IN ULONG Priority)
#define SMP_PAGEFILE_SYSTEM_MANAGED
#define SMP_PAGEFILE_WAS_TOO_BIG
#define STANDARD_PAGING_FILE_NAME
#define SMP_PAGEFILE_CREATED
NTSTATUS NTAPI SmpCreatePagingFileDescriptor(IN PUNICODE_STRING PageFileToken)
NTSTATUS NTAPI SmpGetVolumeFreeSpace(IN PSMP_VOLUME_DESCRIPTOR Volume)
NTSTATUS NTAPI SmpCreatePagingFileOnFixedDrive(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor, IN PLARGE_INTEGER FuzzFactor, IN PLARGE_INTEGER MinimumSize)
VOID NTAPI SmpMakeDefaultPagingFileDescriptor(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
#define SMP_PAGEFILE_ON_ANY_DRIVE
VOID NTAPI SmpMakeSystemManagedPagingFileDescriptor(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
BOOLEAN SmpRegistrySpecifierPresent
NTSTATUS NTAPI SmpDeletePagingFile(IN PUNICODE_STRING FileName)
#define MAXIMUM_PAGEFILE_SIZE
#define SMP_VOLUME_IS_BOOT
ULONG SmpNumberOfPagingFiles
NTSTATUS NTAPI SmpCreateSystemManagedPagingFile(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor, IN BOOLEAN DecreaseSize)
LIST_ENTRY SmpPagingFileDescriptorList
struct _SMP_VOLUME_DESCRIPTOR * PSMP_VOLUME_DESCRIPTOR
#define MINIMUM_TO_KEEP_FREE
NTSTATUS NTAPI SmpCreateVolumeDescriptors(VOID)
#define SMP_PAGEFILE_EMERGENCY
struct _SMP_PAGEFILE_DESCRIPTOR SMP_PAGEFILE_DESCRIPTOR
NTSTATUS NTAPI SmpValidatePagingFileSizes(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
NTSTATUS NTAPI SmpGetPagingFileSize(IN PUNICODE_STRING FileName, OUT PLARGE_INTEGER Size)
#define SMP_VOLUME_PAGEFILE_CREATED
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
BOOLEAN NTAPI SmpCheckForCrashDump(IN PUNICODE_STRING FileName)
#define NT_SUCCESS(StatCode)
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
#define InitializeListHead(ListHead)
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING VolumeName
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
_Must_inspect_result_ _Out_ PHANDLE VolumeHandle
@ FileDispositionInformation
#define FILE_SYNCHRONOUS_IO_NONALERT
@ FileFsDeviceInformation
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
#define OBJ_CASE_INSENSITIVE
static OUT PIO_STATUS_BLOCK IoStatusBlock
#define InitializeObjectAttributes(p, n, a, r, s)
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
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)
#define FILE_REMOTE_DEVICE
#define FILE_READ_ATTRIBUTES
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NtCurrentProcess()
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define FILE_READ_ONLY_DEVICE
#define FILE_SHARE_DELETE
#define FILE_WRITE_ATTRIBUTES
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
#define FILE_FLOPPY_DISKETTE
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define FILE_REMOVABLE_MEDIA
NTSTATUS NTAPI NtCreatePagingFile(_In_ PUNICODE_STRING FileName, _In_ PLARGE_INTEGER MinimumSize, _In_ PLARGE_INTEGER MaximumSize, _In_ ULONG Reserved)
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
#define STATUS_UNEXPECTED_IO_ERROR
#define STATUS_TOO_MANY_PAGING_FILES
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define FileStandardInformation
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
NTSTATUS NTAPI SmpParseCommandLine(IN PUNICODE_STRING CommandLine, OUT PULONG Flags, OUT PUNICODE_STRING FileName, OUT PUNICODE_STRING Directory, OUT PUNICODE_STRING Arguments)
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
base of all file and directory entries
struct _LIST_ENTRY * Flink
LARGE_INTEGER ActualMinSize
LARGE_INTEGER ActualMaxSize
FILE_FS_DEVICE_INFORMATION DeviceInfo
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INVALID_PARAMETER
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor