Skip to content

Commit 6627d31

Browse files
committed
* Sync with trunk r55820.
svn path=/branches/arty-newcc/; revision=55822
1 parent 51f84a8 commit 6627d31

File tree

39 files changed

+1653
-472
lines changed

39 files changed

+1653
-472
lines changed

base/system/smss2/pagefile.c

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515
/* GLOBALS ********************************************************************/
1616

1717
//
18-
// Taken from ASSERTs
18+
// Constants
1919
//
2020
#define STANDARD_PAGING_FILE_NAME L"\\??\\?:\\pagefile.sys"
2121
#define STANDARD_DRIVE_LETTER_OFFSET 4
22+
#define MEGABYTE 0x100000UL
23+
#define MAXIMUM_PAGEFILE_SIZE (4095 * MEGABYTE)
24+
/* This should be 32 MB, but we need more than that for 2nd stage setup */
25+
#define MINIMUM_TO_KEEP_FREE (64 * MEGABYTE)
26+
#define FUZZ_FACTOR (16 * MEGABYTE)
2227

2328
//
2429
// Structure and flags describing each pagefile
@@ -83,9 +88,8 @@ SmpCreatePagingFileDescriptor(IN PUNICODE_STRING PageFileToken)
8388
PSMP_PAGEFILE_DESCRIPTOR Descriptor, ListDescriptor;
8489
ULONG i;
8590
WCHAR c;
86-
PWCHAR p, ArgBuffer;
8791
PLIST_ENTRY NextEntry;
88-
UNICODE_STRING PageFileName, Arguments;
92+
UNICODE_STRING PageFileName, Arguments, SecondArgument;
8993

9094
/* Make sure we don't have too many */
9195
if (SmpNumberOfPagingFiles >= 16)
@@ -131,7 +135,7 @@ SmpCreatePagingFileDescriptor(IN PUNICODE_STRING PageFileToken)
131135
}
132136

133137
/* Was a pagefile not specified, or was it specified with no size? */
134-
if ((Arguments.Buffer) || (ZeroSize))
138+
if (!(Arguments.Buffer) || (ZeroSize))
135139
{
136140
/* In this case, the system will manage its size */
137141
SystemManaged = TRUE;
@@ -149,17 +153,18 @@ SmpCreatePagingFileDescriptor(IN PUNICODE_STRING PageFileToken)
149153
}
150154

151155
/* Now advance to the next argument */
152-
ArgBuffer = Arguments.Buffer;
153-
p = ArgBuffer;
154-
while (*p++)
156+
for (i = 0; i < Arguments.Length / sizeof(WCHAR); i++)
155157
{
156-
/* Which should be a space... */
157-
if (*p == L' ')
158+
/* Found a space -- second argument must start here */
159+
if (Arguments.Buffer[i] == L' ')
158160
{
159-
/* And use the rest of the arguments as a maximum size */
160-
Arguments.Length -= ((PCHAR)p - (PCHAR)ArgBuffer);
161-
Arguments.Buffer = ArgBuffer;
162-
Status = RtlUnicodeStringToInteger(&Arguments, 0, &MaxSize);
161+
/* Use the rest of the arguments as a maximum size */
162+
SecondArgument.Buffer = &Arguments.Buffer[i];
163+
SecondArgument.Length = Arguments.Length -
164+
i * sizeof(WCHAR);
165+
SecondArgument.MaximumLength = Arguments.MaximumLength -
166+
i * sizeof(WCHAR);
167+
Status = RtlUnicodeStringToInteger(&SecondArgument, 0, &MaxSize);
163168
if (!NT_SUCCESS(Status))
164169
{
165170
/* Fail */
@@ -168,8 +173,6 @@ SmpCreatePagingFileDescriptor(IN PUNICODE_STRING PageFileToken)
168173
return Status;
169174
}
170175

171-
/* We have both min and max, restore argument buffer */
172-
Arguments.Buffer = ArgBuffer; // Actual Windows Bug in faillure case above.
173176
break;
174177
}
175178
}
@@ -192,8 +195,8 @@ SmpCreatePagingFileDescriptor(IN PUNICODE_STRING PageFileToken)
192195
/* Capture all our data into the descriptor */
193196
Descriptor->Token = *PageFileToken;
194197
Descriptor->Name = PageFileName;
195-
Descriptor->MinSize.QuadPart = MinSize * 0x100000;
196-
Descriptor->MaxSize.QuadPart = MaxSize * 0x100000;
198+
Descriptor->MinSize.QuadPart = MinSize * MEGABYTE;
199+
Descriptor->MaxSize.QuadPart = MaxSize * MEGABYTE;
197200
if (SystemManaged) Descriptor->Flags |= SMP_PAGEFILE_SYSTEM_MANAGED;
198201
Descriptor->Name.Buffer[STANDARD_DRIVE_LETTER_OFFSET] =
199202
RtlUpcaseUnicodeChar(Descriptor->Name.Buffer[STANDARD_DRIVE_LETTER_OFFSET]);
@@ -271,8 +274,7 @@ SmpGetPagingFileSize(IN PUNICODE_STRING FileName,
271274
}
272275

273276
NtClose(FileHandle);
274-
Size->LowPart = StandardInfo.AllocationSize.LowPart;
275-
Size->HighPart = StandardInfo.AllocationSize.HighPart;
277+
Size->QuadPart = StandardInfo.AllocationSize.QuadPart;
276278
return STATUS_SUCCESS;
277279
}
278280

@@ -346,9 +348,7 @@ SmpGetVolumeFreeSpace(IN PSMP_VOLUME_DESCRIPTOR Volume)
346348

347349
/* Build the standard path */
348350
wcscpy(PathString, L"\\??\\A:\\");
349-
VolumeName.Buffer = PathString;
350-
VolumeName.Length = wcslen(PathString) * sizeof(WCHAR);
351-
VolumeName.MaximumLength = VolumeName.Length + sizeof(UNICODE_NULL);
351+
RtlInitUnicodeString(&VolumeName, PathString);
352352
VolumeName.Buffer[STANDARD_DRIVE_LETTER_OFFSET] = Volume->DriveLetter;
353353
DPRINT("SMSS:PFILE: Querying volume `%wZ' for free space \n", &VolumeName);
354354

@@ -378,13 +378,12 @@ SmpGetVolumeFreeSpace(IN PSMP_VOLUME_DESCRIPTOR Volume)
378378
FileFsSizeInformation);
379379
if (!NT_SUCCESS(Status))
380380
{
381-
/* We failed -- keep going */
381+
/* We failed */
382382
DPRINT1("SMSS:PFILE: Query volume `%wZ' (handle %p) for size failed"
383383
" with status %X \n",
384384
&VolumeName,
385385
VolumeHandle,
386386
Status);
387-
RtlFreeHeap(RtlGetProcessHeap(), 0, Volume);
388387
NtClose(VolumeHandle);
389388
return Status;
390389
}
@@ -394,18 +393,18 @@ SmpGetVolumeFreeSpace(IN PSMP_VOLUME_DESCRIPTOR Volume)
394393
FreeSpace.QuadPart = SizeInfo.AvailableAllocationUnits.QuadPart *
395394
SizeInfo.SectorsPerAllocationUnit;
396395
FinalFreeSpace.QuadPart = FreeSpace.QuadPart * SizeInfo.BytesPerSector;
397-
Volume->FreeSpace = FinalFreeSpace;
398396

399397
/* Check if there's less than 32MB free so we don't starve the disk */
400-
if (FinalFreeSpace.QuadPart <= 0x2000000)
398+
if (FinalFreeSpace.QuadPart <= MINIMUM_TO_KEEP_FREE)
401399
{
402400
/* In this case, act as if there's no free space */
403401
Volume->FreeSpace.QuadPart = 0;
404402
}
405403
else
406404
{
407405
/* Trim off 32MB to give the disk a bit of breathing room */
408-
Volume->FreeSpace.QuadPart = FinalFreeSpace.QuadPart - 0x2000000;
406+
Volume->FreeSpace.QuadPart = FinalFreeSpace.QuadPart -
407+
MINIMUM_TO_KEEP_FREE;
409408
}
410409

411410
return STATUS_SUCCESS;
@@ -540,7 +539,7 @@ SmpCreatePagingFileOnFixedDrive(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor,
540539

541540
/* Check how big we can make the pagefile */
542541
Status = SmpGetPagingFileSize(&Descriptor->Name, &PageFileSize);
543-
if (PageFileSize.QuadPart > 0) ShouldDelete = TRUE;
542+
if (NT_SUCCESS(Status) && PageFileSize.QuadPart > 0) ShouldDelete = TRUE;
544543
DPRINT("SMSS:PFILE: Detected size %I64X for future paging file `%wZ'\n",
545544
PageFileSize,
546545
&Descriptor->Name);
@@ -588,7 +587,13 @@ SmpCreatePagingFileOnFixedDrive(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor,
588587
if (Descriptor->ActualMinSize.QuadPart < MinimumSize->QuadPart)
589588
{
590589
/* Delete the current page file and fail */
591-
if (ShouldDelete) SmpDeletePagingFile(&Descriptor->Name);
590+
if (ShouldDelete)
591+
{
592+
SmpDeletePagingFile(&Descriptor->Name);
593+
594+
/* FIXFIX: Windows Vista does this, and it seems like we should too, so try to see if this fixes KVM */
595+
Volume->FreeSpace.QuadPart = PageFileSize.QuadPart;
596+
}
592597
DPRINT1("SMSS:PFILE: Failing for min %I64X, max %I64X, real min %I64X \n",
593598
Descriptor->ActualMinSize.QuadPart,
594599
Descriptor->ActualMaxSize.QuadPart,
@@ -644,8 +649,8 @@ SmpMakeDefaultPagingFileDescriptor(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
644649
{
645650
/* The default descriptor uses 128MB as a pagefile size */
646651
Descriptor->Flags |= SMP_PAGEFILE_DEFAULT;
647-
Descriptor->MinSize.QuadPart = 0x8000000;
648-
Descriptor->MaxSize.QuadPart = 0x8000000;
652+
Descriptor->MinSize.QuadPart = 128 * MEGABYTE;
653+
Descriptor->MaxSize.QuadPart = 128 * MEGABYTE;
649654
}
650655

651656
VOID
@@ -674,7 +679,7 @@ SmpMakeSystemManagedPagingFileDescriptor(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
674679
MaximumSize = 3 * Ram;
675680

676681
/* If we have more than 1GB, use that as minimum, otherwise, use 1.5X RAM */
677-
MinimumSize = (Ram >= 0x40000000) ? Ram : MaximumSize / 2;
682+
MinimumSize = (Ram >= 1024 * MEGABYTE) ? Ram : MaximumSize / 2;
678683

679684
/* Write the new sizes in the descriptor and mark it as system managed */
680685
Descriptor->MinSize.QuadPart = MinimumSize;
@@ -708,19 +713,19 @@ SmpValidatePagingFileSizes(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
708713
else
709714
{
710715
/* Check if the minimum is more then 4095 MB */
711-
if (MinSize > 0xFFF00000)
716+
if (MinSize > MAXIMUM_PAGEFILE_SIZE)
712717
{
713718
/* Trim it, this isn't allowed */
714719
WasTooBig = TRUE;
715-
MinSize = 0xFFF00000;
720+
MinSize = MAXIMUM_PAGEFILE_SIZE;
716721
}
717722

718723
/* Check if the maximum is more then 4095 MB */
719-
if (MaxSize > 0xFFF00000)
724+
if (MaxSize > MAXIMUM_PAGEFILE_SIZE)
720725
{
721726
/* Trim it, this isn't allowed */
722727
WasTooBig = TRUE;
723-
MaxSize = 0xFFF00000;
728+
MaxSize = MAXIMUM_PAGEFILE_SIZE;
724729
}
725730
}
726731

@@ -752,14 +757,14 @@ SmpCreateSystemManagedPagingFile(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor,
752757
ASSERT(Descriptor->Flags & SMP_PAGEFILE_SYSTEM_MANAGED); // Descriptor->SystemManaged == 1 in ASSERT.
753758

754759
/* Keep decreasing the pagefile by this amount if we run out of space */
755-
FuzzFactor.QuadPart = 0x1000000;
760+
FuzzFactor.QuadPart = FUZZ_FACTOR;
756761

757762
/* Create the descriptor for it (mainly the right sizes) and validate */
758763
SmpMakeSystemManagedPagingFileDescriptor(Descriptor);
759764
SmpValidatePagingFileSizes(Descriptor);
760765

761766
/* Use either the minimum size in the descriptor, or 16MB in minimal mode */
762-
Size.QuadPart = DecreaseSize ? 0x1000000 : Descriptor->MinSize.QuadPart;
767+
Size.QuadPart = DecreaseSize ? 16 * MEGABYTE : Descriptor->MinSize.QuadPart;
763768

764769
/* Check if this should be a fixed pagefile or an any pagefile*/
765770
if (Descriptor->Name.Buffer[STANDARD_DRIVE_LETTER_OFFSET] == '?')
@@ -777,7 +782,6 @@ NTAPI
777782
SmpCreateEmergencyPagingFile(VOID)
778783
{
779784
PSMP_PAGEFILE_DESCRIPTOR Descriptor;
780-
ULONG Length;
781785
WCHAR Buffer[32];
782786

783787
/* Allocate a descriptor */
@@ -787,18 +791,14 @@ SmpCreateEmergencyPagingFile(VOID)
787791
if (!Descriptor) return STATUS_NO_MEMORY;
788792

789793
/* Initialize it */
790-
RtlInitUnicodeString(&Descriptor->Name, NULL);
791794
RtlInitUnicodeString(&Descriptor->Token, NULL);
792795

793796
/* Copy the default pagefile name */
797+
ASSERT(sizeof(Buffer) >= sizeof(STANDARD_PAGING_FILE_NAME));
794798
wcscpy(Buffer, STANDARD_PAGING_FILE_NAME);
795-
Length = wcslen(Buffer) * sizeof(WCHAR);
796-
ASSERT(sizeof(Buffer) > Length);
797799

798800
/* Fill the rest of the descriptor out */
799-
Descriptor->Name.Buffer = Buffer;
800-
Descriptor->Name.Length = Length;
801-
Descriptor->Name.MaximumLength = Length + sizeof(UNICODE_NULL);
801+
RtlInitUnicodeString(&Descriptor->Name, Buffer);
802802
Descriptor->Name.Buffer[STANDARD_DRIVE_LETTER_OFFSET] = '?';
803803
Descriptor->Flags |= SMP_PAGEFILE_SYSTEM_MANAGED |
804804
SMP_PAGEFILE_EMERGENCY |
@@ -818,7 +818,6 @@ SmpCreateVolumeDescriptors(VOID)
818818
{
819819
NTSTATUS Status;
820820
UNICODE_STRING VolumePath;
821-
ULONG Length;
822821
BOOLEAN BootVolumeFound = FALSE;
823822
WCHAR StartChar, Drive, DriveDiff;
824823
HANDLE VolumeHandle;
@@ -849,14 +848,11 @@ SmpCreateVolumeDescriptors(VOID)
849848

850849
/* Build the volume string, starting with A: (we'll edit this in place) */
851850
wcscpy(Buffer, L"\\??\\A:\\");
852-
Length = wcslen(Buffer);
853-
VolumePath.Buffer = Buffer;
854-
VolumePath.Length = Length * sizeof(WCHAR);
855-
VolumePath.MaximumLength = Length * sizeof(WCHAR) + sizeof(UNICODE_NULL);
851+
RtlInitUnicodeString(&VolumePath, Buffer);
856852

857853
/* Start with the C drive except on weird Japanese NECs... */
858854
StartChar = SharedUserData->AlternativeArchitecture ? L'A' : L'C';
859-
for (Drive = StartChar, DriveDiff = StartChar - 'A'; Drive <= L'Z'; Drive++, DriveDiff++)
855+
for (Drive = StartChar, DriveDiff = StartChar - L'A'; Drive <= L'Z'; Drive++, DriveDiff++)
860856
{
861857
/* Skip the disk if it's not in the drive map */
862858
if (!((1 << DriveDiff) & ProcessInformation.Query.DriveMap)) continue;
@@ -967,18 +963,18 @@ SmpCreateVolumeDescriptors(VOID)
967963
FreeSpace.QuadPart = SizeInfo.AvailableAllocationUnits.QuadPart *
968964
SizeInfo.SectorsPerAllocationUnit;
969965
FinalFreeSpace.QuadPart = FreeSpace.QuadPart * SizeInfo.BytesPerSector;
970-
Volume->FreeSpace = FinalFreeSpace;
971966

972967
/* Check if there's less than 32MB free so we don't starve the disk */
973-
if (FinalFreeSpace.QuadPart <= 0x2000000)
968+
if (FinalFreeSpace.QuadPart <= MINIMUM_TO_KEEP_FREE)
974969
{
975970
/* In this case, act as if there's no free space */
976971
Volume->FreeSpace.QuadPart = 0;
977972
}
978973
else
979974
{
980975
/* Trim off 32MB to give the disk a bit of breathing room */
981-
Volume->FreeSpace.QuadPart = FinalFreeSpace.QuadPart - 0x2000000;
976+
Volume->FreeSpace.QuadPart = FinalFreeSpace.QuadPart -
977+
MINIMUM_TO_KEEP_FREE;
982978
}
983979

984980
/* All done, add this volume to our descriptor list */
@@ -1026,7 +1022,7 @@ SmpCreatePagingFiles(VOID)
10261022
}
10271023

10281024
/* If we fail creating pagefiles, try to reduce by this much each time */
1029-
FuzzFactor.QuadPart = 0x1000000;
1025+
FuzzFactor.QuadPart = FUZZ_FACTOR;
10301026

10311027
/* Loop the descriptor list */
10321028
NextEntry = SmpPagingFileDescriptorList.Flink;
@@ -1068,7 +1064,7 @@ SmpCreatePagingFiles(VOID)
10681064
/* We failed to create it. Try again with a smaller size */
10691065
DPRINT1("SMSS:PFILE: Trying lower sizes for (`%wZ') \n",
10701066
&Descriptor->Name);
1071-
Size.QuadPart = 0x1000000;
1067+
Size.QuadPart = 16 * MEGABYTE;
10721068
Status = SmpCreatePagingFileOnAnyDrive(Descriptor,
10731069
&FuzzFactor,
10741070
&Size);
@@ -1077,7 +1073,7 @@ SmpCreatePagingFiles(VOID)
10771073
else
10781074
{
10791075
/* It's a fixed pagefile: override the minimum and use ours */
1080-
Size.QuadPart = 0x1000000;
1076+
Size.QuadPart = 16 * MEGABYTE;
10811077
Status = SmpCreatePagingFileOnFixedDrive(Descriptor,
10821078
&FuzzFactor,
10831079
&Size);

base/system/smss2/sminit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ NTSTATUS
19771977
NTAPI
19781978
SmpProcessFileRenames(VOID)
19791979
{
1980-
BOOLEAN OldState, HavePrivilege;
1980+
BOOLEAN OldState, HavePrivilege = FALSE;
19811981
NTSTATUS Status;
19821982
HANDLE FileHandle, OtherFileHandle;
19831983
FILE_INFORMATION_CLASS InformationClass;

base/system/smss2/smsubsys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ SmpLoadSubSystem(IN PUNICODE_STRING FileName,
317317
/* This is the POSIX or OS/2 subsystem process, copy its information */
318318
RtlCopyMemory(&CreateSession->ProcessInfo,
319319
&ProcessInformation,
320-
sizeof(&CreateSession->ProcessInfo));
320+
sizeof(CreateSession->ProcessInfo));
321321

322322
/* Not sure these field mean what I think they do -- but clear them */
323323
*(PULONGLONG)&CreateSession->ClientId = 0;

0 commit comments

Comments
 (0)