More swapping fixes

svn path=/trunk/; revision=2493
This commit is contained in:
David Welch 2002-01-08 00:49:02 +00:00
parent b93878d368
commit 8cb9f1dd16
21 changed files with 484 additions and 163 deletions

View file

@ -2,7 +2,9 @@
#include <string.h> #include <string.h>
#include <windows.h> #include <windows.h>
ULONG x[(4 * 1024 * 1024) / 4096]; #define SIZE (128*1024*1024)
ULONG x[SIZE / 4096];
int main() int main()
{ {
@ -10,7 +12,7 @@ int main()
PUCHAR BaseAddress; PUCHAR BaseAddress;
BaseAddress = VirtualAlloc(NULL, BaseAddress = VirtualAlloc(NULL,
4 * 1024 * 1024, SIZE,
MEM_COMMIT, MEM_COMMIT,
PAGE_READONLY); PAGE_READONLY);
if (BaseAddress == NULL) if (BaseAddress == NULL)
@ -19,9 +21,9 @@ int main()
return(1); return(1);
} }
printf("BaseAddress %p\n", BaseAddress); printf("BaseAddress %p\n", BaseAddress);
for (i = 0; i < ((4 * 1024 * 1024) / 4096); i++) for (i = 0; i < (SIZE / 4096); i++)
{ {
printf("%.6x, ", i*4096); printf("%.8x ", i*4096);
x[i] = BaseAddress[i*4096]; x[i] = BaseAddress[i*4096];
} }

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.34 2001/11/02 22:44:34 hbirr Exp $ /* $Id: create.c,v 1.35 2002/01/08 00:49:01 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -579,12 +579,14 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
PVFATCCB pCcb; PVFATCCB pCcb;
PVFATFCB pFcb; PVFATFCB pFcb;
PWCHAR c; PWCHAR c;
BOOLEAN PagingFileCreate = FALSE;
Stack = IoGetCurrentIrpStackLocation (Irp); Stack = IoGetCurrentIrpStackLocation (Irp);
assert (Stack); assert (Stack);
RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff); RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff);
RequestedOptions = RequestedOptions =
Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS; Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
if ((RequestedOptions & FILE_DIRECTORY_FILE) if ((RequestedOptions & FILE_DIRECTORY_FILE)
&& RequestedDisposition == FILE_SUPERSEDE) && RequestedDisposition == FILE_SUPERSEDE)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
@ -694,6 +696,42 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
} }
} }
/*
* If this create was for a paging file then make sure all the
* information needed to manipulate it is locked in memory.
*/
if (PagingFileCreate)
{
ULONG CurrentCluster, NextCluster, i;
pFcb->Flags |= FCB_IS_PAGE_FILE;
pFcb->FatChainSize =
((pFcb->entry.FileSize / DeviceExt->BytesPerCluster) + 2);
pFcb->FatChain = ExAllocatePool(NonPagedPool,
pFcb->FatChainSize * sizeof(ULONG));
if (DeviceExt->FatType == FAT32)
{
CurrentCluster = pFcb->entry.FirstCluster +
pFcb->entry.FirstClusterHigh * 65536;
}
else
{
CurrentCluster = pFcb->entry.FirstCluster;
}
i = 0;
while (CurrentCluster != 0xffffffff)
{
Status = GetNextCluster (DeviceExt, CurrentCluster, &NextCluster,
FALSE);
pFcb->FatChain[i] = NextCluster;
i++;
CurrentCluster = NextCluster;
}
pFcb->FatChain[i] = 0xFFFFFFFF;
}
/* /*
* Check the file has the requested attributes * Check the file has the requested attributes
*/ */

View file

@ -1,4 +1,4 @@
/* $Id: dirwr.c,v 1.22 2001/10/10 22:15:51 hbirr Exp $ /* $Id: dirwr.c,v 1.23 2002/01/08 00:49:01 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -403,7 +403,7 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
if (RequestedOptions & FILE_DIRECTORY_FILE) if (RequestedOptions & FILE_DIRECTORY_FILE)
{ {
CurrentCluster = 0xffffffff; CurrentCluster = 0xffffffff;
status = NextCluster (DeviceExt, 0, &CurrentCluster, TRUE); status = NextCluster (DeviceExt, NULL, 0, &CurrentCluster, TRUE);
if (CurrentCluster == 0xffffffff || !NT_SUCCESS(status)) if (CurrentCluster == 0xffffffff || !NT_SUCCESS(status))
{ {
vfatReleaseFCB(DeviceExt, pDirFcb); vfatReleaseFCB(DeviceExt, pDirFcb);

View file

@ -1,4 +1,4 @@
/* $Id: fcb.c,v 1.11 2001/11/02 22:40:50 hbirr Exp $ /* $Id: fcb.c,v 1.12 2002/01/08 00:49:01 dwelch Exp $
* *
* *
* FILE: fcb.c * FILE: fcb.c
@ -218,7 +218,7 @@ vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
while (CurrentCluster != 0xffffffff && NT_SUCCESS(Status)) while (CurrentCluster != 0xffffffff && NT_SUCCESS(Status))
{ {
Size += pVCB->BytesPerCluster; Size += pVCB->BytesPerCluster;
Status = NextCluster (pVCB, FirstCluster, &CurrentCluster, FALSE); Status = NextCluster (pVCB, NULL, FirstCluster, &CurrentCluster, FALSE);
} }
} }
else else
@ -304,7 +304,7 @@ vfatMakeFCBFromDirEntry(PVCB vcb,
while (CurrentCluster != 0xffffffff) while (CurrentCluster != 0xffffffff)
{ {
Size += vcb->BytesPerCluster; Size += vcb->BytesPerCluster;
Status = NextCluster (vcb, FirstCluster, &CurrentCluster, FALSE); Status = NextCluster (vcb, NULL, FirstCluster, &CurrentCluster, FALSE);
} }
} }
} }

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.36 2001/11/02 22:47:36 hbirr Exp $ # $Id: makefile,v 1.37 2002/01/08 00:49:01 dwelch Exp $
PATH_TO_TOP = ../../.. PATH_TO_TOP = ../../..
@ -26,6 +26,8 @@ TARGET_OBJECTS = \
DEP_OBJECTS = $(TARGET_OBJECTS) DEP_OBJECTS = $(TARGET_OBJECTS)
TARGET_CFLAGS = -g
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk include $(TOOLS_PATH)/helper.mk

View file

@ -1,5 +1,5 @@
/* $Id: rw.c,v 1.34 2001/11/02 22:47:36 hbirr Exp $ /* $Id: rw.c,v 1.35 2002/01/08 00:49:01 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -29,6 +29,7 @@
NTSTATUS NTSTATUS
NextCluster(PDEVICE_EXTENSION DeviceExt, NextCluster(PDEVICE_EXTENSION DeviceExt,
PVFATFCB Fcb,
ULONG FirstCluster, ULONG FirstCluster,
PULONG CurrentCluster, PULONG CurrentCluster,
BOOLEAN Extend) BOOLEAN Extend)
@ -37,13 +38,24 @@ NextCluster(PDEVICE_EXTENSION DeviceExt,
* necessary * necessary
*/ */
{ {
if (Fcb != NULL && Fcb->Flags & FCB_IS_PAGE_FILE)
{
ULONG NextCluster;
NextCluster = Fcb->FatChain[(*CurrentCluster)];
(*CurrentCluster) = NextCluster;
return(STATUS_SUCCESS);
}
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
(*CurrentCluster) += DeviceExt->Boot->SectorsPerCluster; (*CurrentCluster) += DeviceExt->Boot->SectorsPerCluster;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
else else
/* CN: FIXME: Real bug here or in dirwr, where CurrentCluster isn't initialized when 0*/ {
/*
* CN: FIXME: Real bug here or in dirwr, where CurrentCluster isn't
* initialized when 0
*/
if (FirstCluster == 0) if (FirstCluster == 0)
{ {
NTSTATUS Status; NTSTATUS Status;
@ -61,9 +73,11 @@ NextCluster(PDEVICE_EXTENSION DeviceExt,
return(Status); return(Status);
} }
} }
}
NTSTATUS NTSTATUS
OffsetToCluster(PDEVICE_EXTENSION DeviceExt, OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
PVFATFCB Fcb,
ULONG FirstCluster, ULONG FirstCluster,
ULONG FileOffset, ULONG FileOffset,
PULONG Cluster, PULONG Cluster,
@ -77,6 +91,20 @@ OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
ULONG i; ULONG i;
NTSTATUS Status; NTSTATUS Status;
if (Fcb != NULL && Fcb->Flags & FCB_IS_PAGE_FILE)
{
ULONG NCluster;
ULONG Offset = FileOffset / DeviceExt->BytesPerCluster;
if (Offset == 0)
{
(*Cluster) = FirstCluster;
}
else
{
(*Cluster) = Fcb->FatChain[Offset - 1];
}
return(STATUS_SUCCESS);
}
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
/* root of FAT16 or FAT12 */ /* root of FAT16 or FAT12 */
@ -103,6 +131,7 @@ OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
NTSTATUS NTSTATUS
VfatReadCluster(PDEVICE_EXTENSION DeviceExt, VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
PVFATFCB Fcb,
ULONG FirstCluster, ULONG FirstCluster,
PULONG CurrentCluster, PULONG CurrentCluster,
PVOID Destination, PVOID Destination,
@ -133,7 +162,7 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
{ {
return(Status); return(Status);
} }
Status = NextCluster(DeviceExt, FirstCluster, CurrentCluster, FALSE); Status = NextCluster(DeviceExt, Fcb, FirstCluster, CurrentCluster, FALSE);
return(Status); return(Status);
} }
@ -248,6 +277,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
CurrentCluster = Ccb->LastCluster; CurrentCluster = Ccb->LastCluster;
} }
Status = OffsetToCluster(DeviceExt, Status = OffsetToCluster(DeviceExt,
Fcb,
FirstCluster, FirstCluster,
ROUND_DOWN(ReadOffset, DeviceExt->BytesPerCluster), ROUND_DOWN(ReadOffset, DeviceExt->BytesPerCluster),
&CurrentCluster, &CurrentCluster,
@ -265,8 +295,9 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
TempLength = min (Length, DeviceExt->BytesPerCluster - (ReadOffset % DeviceExt->BytesPerCluster)); TempLength = min (Length, DeviceExt->BytesPerCluster - (ReadOffset % DeviceExt->BytesPerCluster));
Ccb->LastCluster = CurrentCluster; Ccb->LastCluster = CurrentCluster;
Ccb->LastOffset = ROUND_DOWN(ReadOffset, DeviceExt->BytesPerCluster); Ccb->LastOffset = ROUND_DOWN(ReadOffset, DeviceExt->BytesPerCluster);
Status = VfatReadCluster(DeviceExt, FirstCluster, &CurrentCluster, Buffer, Status = VfatReadCluster(DeviceExt, Fcb, FirstCluster, &CurrentCluster,
ReadOffset % DeviceExt->BytesPerCluster, TempLength); Buffer, ReadOffset % DeviceExt->BytesPerCluster,
TempLength);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
(*LengthRead) = (*LengthRead) + TempLength; (*LengthRead) = (*LengthRead) + TempLength;
@ -284,7 +315,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
do do
{ {
ClusterCount++; ClusterCount++;
Status = NextCluster(DeviceExt, FirstCluster, &CurrentCluster, FALSE); Status = NextCluster(DeviceExt, Fcb, FirstCluster, &CurrentCluster, FALSE);
} }
while (StartCluster + ClusterCount == CurrentCluster && NT_SUCCESS(Status) && while (StartCluster + ClusterCount == CurrentCluster && NT_SUCCESS(Status) &&
Length - ClusterCount * DeviceExt->BytesPerCluster >= DeviceExt->BytesPerCluster); Length - ClusterCount * DeviceExt->BytesPerCluster >= DeviceExt->BytesPerCluster);
@ -311,7 +342,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
Ccb->LastCluster = CurrentCluster; Ccb->LastCluster = CurrentCluster;
Ccb->LastOffset = ReadOffset + DeviceExt->BytesPerCluster; Ccb->LastOffset = ReadOffset + DeviceExt->BytesPerCluster;
Status = VfatReadCluster(DeviceExt, FirstCluster, &CurrentCluster, Status = VfatReadCluster(DeviceExt, Fcb, FirstCluster, &CurrentCluster,
Buffer, 0, Length); Buffer, 0, Length);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
@ -323,6 +354,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
NTSTATUS NTSTATUS
VfatWriteCluster(PDEVICE_EXTENSION DeviceExt, VfatWriteCluster(PDEVICE_EXTENSION DeviceExt,
PVFATFCB Fcb,
ULONG StartOffset, ULONG StartOffset,
ULONG FirstCluster, ULONG FirstCluster,
PULONG CurrentCluster, PULONG CurrentCluster,
@ -376,7 +408,7 @@ VfatWriteCluster(PDEVICE_EXTENSION DeviceExt,
{ {
return Status; return Status;
} }
Status = NextCluster(DeviceExt, FirstCluster, CurrentCluster, FALSE); Status = NextCluster(DeviceExt, Fcb, FirstCluster, CurrentCluster, FALSE);
return(Status); return(Status);
} }
@ -485,6 +517,7 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
CurrentCluster = pCcb->LastCluster; CurrentCluster = pCcb->LastCluster;
} }
Status = OffsetToCluster(DeviceExt, Status = OffsetToCluster(DeviceExt,
Fcb,
FirstCluster, FirstCluster,
ROUND_DOWN(WriteOffset, DeviceExt->BytesPerCluster), ROUND_DOWN(WriteOffset, DeviceExt->BytesPerCluster),
&CurrentCluster, &CurrentCluster,
@ -506,6 +539,7 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
{ {
TempLength = min (Length, DeviceExt->BytesPerCluster - (WriteOffset % DeviceExt->BytesPerCluster)); TempLength = min (Length, DeviceExt->BytesPerCluster - (WriteOffset % DeviceExt->BytesPerCluster));
Status = VfatWriteCluster(DeviceExt, Status = VfatWriteCluster(DeviceExt,
Fcb,
ROUND_DOWN(WriteOffset, DeviceExt->BytesPerCluster), ROUND_DOWN(WriteOffset, DeviceExt->BytesPerCluster),
FirstCluster, FirstCluster,
&CurrentCluster, &CurrentCluster,
@ -528,7 +562,7 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
do do
{ {
Count++; Count++;
Status = NextCluster(DeviceExt, FirstCluster, &CurrentCluster, FALSE); Status = NextCluster(DeviceExt, Fcb, FirstCluster, &CurrentCluster, FALSE);
} }
while (StartCluster + Count == CurrentCluster && NT_SUCCESS(Status) && while (StartCluster + Count == CurrentCluster && NT_SUCCESS(Status) &&
Length - Count * DeviceExt->BytesPerCluster >= DeviceExt->BytesPerCluster); Length - Count * DeviceExt->BytesPerCluster >= DeviceExt->BytesPerCluster);
@ -550,6 +584,7 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
if (Length > 0 && CurrentCluster != 0xffffffff && NT_SUCCESS(Status)) if (Length > 0 && CurrentCluster != 0xffffffff && NT_SUCCESS(Status))
{ {
Status = VfatWriteCluster(DeviceExt, Status = VfatWriteCluster(DeviceExt,
Fcb,
WriteOffset, WriteOffset,
FirstCluster, FirstCluster,
&CurrentCluster, &CurrentCluster,
@ -626,7 +661,7 @@ NTSTATUS vfatExtendSpace (PDEVICE_EXTENSION pDeviceExt, PFILE_OBJECT pFileObject
if (FirstCluster == 0) if (FirstCluster == 0)
{ {
// file of size zero // file of size zero
Status = NextCluster (pDeviceExt, FirstCluster, &CurrentCluster, TRUE); Status = NextCluster (pDeviceExt, pFcb, FirstCluster, &CurrentCluster, TRUE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NextCluster failed, Status %x\n", Status); DPRINT1("NextCluster failed, Status %x\n", Status);
@ -636,7 +671,7 @@ NTSTATUS vfatExtendSpace (PDEVICE_EXTENSION pDeviceExt, PFILE_OBJECT pFileObject
} }
else else
{ {
Status = OffsetToCluster(pDeviceExt, FirstCluster, Status = OffsetToCluster(pDeviceExt, pFcb, FirstCluster,
pFcb->RFCB.AllocationSize.QuadPart - pDeviceExt->BytesPerCluster, pFcb->RFCB.AllocationSize.QuadPart - pDeviceExt->BytesPerCluster,
&CurrentCluster, FALSE); &CurrentCluster, FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -651,14 +686,14 @@ NTSTATUS vfatExtendSpace (PDEVICE_EXTENSION pDeviceExt, PFILE_OBJECT pFileObject
} }
// CurrentCluster zeigt jetzt auf den letzten Cluster in der Kette // CurrentCluster zeigt jetzt auf den letzten Cluster in der Kette
NewCluster = CurrentCluster; NewCluster = CurrentCluster;
Status = NextCluster(pDeviceExt, FirstCluster, &NewCluster, FALSE); Status = NextCluster(pDeviceExt, pFcb, FirstCluster, &NewCluster, FALSE);
if (NewCluster != 0xffffffff) if (NewCluster != 0xffffffff)
{ {
DPRINT1("Difference between size from direntry and the FAT.\n"); DPRINT1("Difference between size from direntry and the FAT.\n");
} }
} }
Status = OffsetToCluster(pDeviceExt, FirstCluster, Status = OffsetToCluster(pDeviceExt, pFcb, FirstCluster,
ROUND_DOWN(NewSize-1, pDeviceExt->BytesPerCluster), ROUND_DOWN(NewSize-1, pDeviceExt->BytesPerCluster),
&NewCluster, TRUE); &NewCluster, TRUE);
if (!NT_SUCCESS(Status) || NewCluster == 0xffffffff) if (!NT_SUCCESS(Status) || NewCluster == 0xffffffff)
@ -668,7 +703,7 @@ NTSTATUS vfatExtendSpace (PDEVICE_EXTENSION pDeviceExt, PFILE_OBJECT pFileObject
{ {
NewCluster = CurrentCluster; NewCluster = CurrentCluster;
// FIXME: check status // FIXME: check status
NextCluster(pDeviceExt, FirstCluster, &NewCluster, FALSE); NextCluster(pDeviceExt, pFcb, FirstCluster, &NewCluster, FALSE);
WriteCluster(pDeviceExt, CurrentCluster, 0xffffffff); WriteCluster(pDeviceExt, CurrentCluster, 0xffffffff);
} }
// free the allocated space // free the allocated space
@ -676,7 +711,7 @@ NTSTATUS vfatExtendSpace (PDEVICE_EXTENSION pDeviceExt, PFILE_OBJECT pFileObject
{ {
CurrentCluster = NewCluster; CurrentCluster = NewCluster;
// FIXME: check status // FIXME: check status
NextCluster (pDeviceExt, FirstCluster, &NewCluster, FALSE); NextCluster (pDeviceExt, pFcb, FirstCluster, &NewCluster, FALSE);
WriteCluster (pDeviceExt, CurrentCluster, 0); WriteCluster (pDeviceExt, CurrentCluster, 0);
} }
return STATUS_DISK_FULL; return STATUS_DISK_FULL;

View file

@ -1,4 +1,4 @@
/* $Id: vfat.h,v 1.37 2001/11/02 22:57:14 hbirr Exp $ */ /* $Id: vfat.h,v 1.38 2002/01/08 00:49:01 dwelch Exp $ */
#include <ddk/ntifs.h> #include <ddk/ntifs.h>
@ -137,6 +137,10 @@ typedef struct _VFATFCB
ULONG dirIndex; ULONG dirIndex;
ERESOURCE PagingIoResource; ERESOURCE PagingIoResource;
ERESOURCE MainResource; ERESOURCE MainResource;
/* Structure members used only for paging files. */
ULONG FatChainSize;
PULONG FatChain;
} VFATFCB, *PVFATFCB; } VFATFCB, *PVFATFCB;
typedef struct _VFATCCB typedef struct _VFATCCB
@ -212,6 +216,7 @@ NTSTATUS VfatSetVolumeInformation (PVFAT_IRP_CONTEXT);
NTSTATUS NTSTATUS
NextCluster(PDEVICE_EXTENSION DeviceExt, NextCluster(PDEVICE_EXTENSION DeviceExt,
PVFATFCB Fcb,
ULONG FirstCluster, ULONG FirstCluster,
PULONG CurrentCluster, PULONG CurrentCluster,
BOOLEAN Extend); BOOLEAN Extend);
@ -294,6 +299,7 @@ BOOL vfatIsFileNameValid (PWCHAR pFileName);
*/ */
NTSTATUS NTSTATUS
OffsetToCluster(PDEVICE_EXTENSION DeviceExt, OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
PVFATFCB Fcb,
ULONG FirstCluster, ULONG FirstCluster,
ULONG FileOffset, ULONG FileOffset,
PULONG Cluster, PULONG Cluster,

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: view.c,v 1.34 2002/01/01 00:21:55 dwelch Exp $ /* $Id: view.c,v 1.35 2002/01/08 00:49:00 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -105,13 +105,15 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
{ {
continue; continue;
} }
if (current->MappedCount > 0 || current->Dirty || current->ReferenceCount > 0) if (current->MappedCount > 0 || current->Dirty ||
current->ReferenceCount > 0)
{ {
ExReleaseFastMutex(&current->Lock); ExReleaseFastMutex(&current->Lock);
continue; continue;
} }
ExReleaseFastMutex(&current->Lock); ExReleaseFastMutex(&current->Lock);
DPRINT("current->Bcb->CacheSegmentSize %d\n", current->Bcb->CacheSegmentSize); DPRINT("current->Bcb->CacheSegmentSize %d\n",
current->Bcb->CacheSegmentSize);
PagesPerSegment = current->Bcb->CacheSegmentSize / PAGESIZE; PagesPerSegment = current->Bcb->CacheSegmentSize / PAGESIZE;
CcRosInternalFreeCacheSegment(current->Bcb, current); CcRosInternalFreeCacheSegment(current->Bcb, current);
DPRINT("CcRosTrimCache(): Freed %d\n", PagesPerSegment); DPRINT("CcRosTrimCache(): Freed %d\n", PagesPerSegment);
@ -143,7 +145,8 @@ CcRosReleaseCacheSegment(PBCB Bcb,
ExReleaseFastMutex(&CacheSeg->Lock); ExReleaseFastMutex(&CacheSeg->Lock);
ExAcquireFastMutex(&ViewLock); ExAcquireFastMutex(&ViewLock);
RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry); RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry);
InsertTailList(&CacheSegmentLRUListHead, &CacheSeg->CacheSegmentLRUListEntry); InsertTailList(&CacheSegmentLRUListHead,
&CacheSeg->CacheSegmentLRUListEntry);
ExReleaseFastMutex(&ViewLock); ExReleaseFastMutex(&ViewLock);
InterlockedDecrement(&CacheSeg->ReferenceCount); InterlockedDecrement(&CacheSeg->ReferenceCount);

View file

@ -39,10 +39,6 @@ typedef ULONG SWAPENTRY;
#define NR_SECTION_PAGE_TABLES (1024) #define NR_SECTION_PAGE_TABLES (1024)
#define NR_SECTION_PAGE_ENTRIES (1024) #define NR_SECTION_PAGE_ENTRIES (1024)
/*
* Flags for section objects
*/
#define SO_PHYSICAL_MEMORY (0x1)
/* /*
* Additional flags for protection attributes * Additional flags for protection attributes
@ -72,6 +68,10 @@ typedef struct
#define MM_PAGEFILE_SECTION (0x1) #define MM_PAGEFILE_SECTION (0x1)
#define MM_IMAGE_SECTION (0x2) #define MM_IMAGE_SECTION (0x2)
/*
* Flags for section objects
*/
#define SO_PHYSICAL_MEMORY (0x4)
#define MM_SECTION_SEGMENT_BSS (0x1) #define MM_SECTION_SEGMENT_BSS (0x1)
@ -506,5 +506,8 @@ MmCreatePageFileMapping(PEPROCESS Process,
PVOID Address, PVOID Address,
SWAPENTRY SwapEntry); SWAPENTRY SwapEntry);
BOOLEAN MmIsPageSwapEntry(PEPROCESS Process, PVOID Address); BOOLEAN MmIsPageSwapEntry(PEPROCESS Process, PVOID Address);
VOID
MmTransferOwnershipPage(PVOID PhysicalAddress, ULONG NewConsumer);
VOID MmSetDirtyPage(PEPROCESS Process, PVOID Address);
#endif #endif

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.51 2001/12/05 12:11:55 ekohl Exp $ /* $Id: create.c,v 1.52 2002/01/08 00:49:00 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -294,8 +294,7 @@ IoCreateStreamFileObject(PFILE_OBJECT FileObject,
* *
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
IoCreateFile( IoCreateFile(OUT PHANDLE FileHandle,
OUT PHANDLE FileHandle,
IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PIO_STATUS_BLOCK IoStatusBlock,
@ -395,7 +394,7 @@ IoCreateFile(
break; break;
} }
StackLoc->MinorFunction = 0; StackLoc->MinorFunction = 0;
StackLoc->Flags = 0; StackLoc->Flags = Options;
StackLoc->Control = 0; StackLoc->Control = 0;
StackLoc->DeviceObject = FileObject->DeviceObject; StackLoc->DeviceObject = FileObject->DeviceObject;
StackLoc->FileObject = FileObject; StackLoc->FileObject = FileObject;

View file

@ -1,4 +1,4 @@
/* $Id: page.c,v 1.13 2001/10/10 21:56:59 hbirr Exp $ /* $Id: page.c,v 1.14 2002/01/08 00:49:00 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: balance.c,v 1.4 2002/01/01 00:21:55 dwelch Exp $ /* $Id: balance.c,v 1.5 2002/01/08 00:49:00 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -130,7 +130,8 @@ MiTrimMemoryConsumer(ULONG Consumer)
{ {
LONG Target; LONG Target;
Target = MiMemoryConsumers[Consumer].PagesUsed - MiMemoryConsumers[Consumer].PagesTarget; Target = MiMemoryConsumers[Consumer].PagesUsed -
MiMemoryConsumers[Consumer].PagesTarget;
if (Target < 0) if (Target < 0)
{ {
Target = 1; Target = 1;
@ -254,6 +255,7 @@ MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait, PVOID* AllocatedPag
{ {
KeBugCheck(0); KeBugCheck(0);
} }
MmTransferOwnershipPage(Page, Consumer);
*AllocatedPage = Page; *AllocatedPage = Page;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -49,6 +49,19 @@ static LIST_ENTRY BiosPageListHead;
/* FUNCTIONS *************************************************************/ /* FUNCTIONS *************************************************************/
VOID
MmTransferOwnershipPage(PVOID PhysicalAddress, ULONG NewConsumer)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
KIRQL oldIrql;
KeAcquireSpinLock(&PageListLock, &oldIrql);
RemoveEntryList(&MmPageArray[Start].ListEntry);
InsertTailList(&UsedPageListHeads[NewConsumer],
&MmPageArray[Start].ListEntry);
KeReleaseSpinLock(&PageListLock, oldIrql);
}
PVOID PVOID
MmGetLRUFirstUserPage(VOID) MmGetLRUFirstUserPage(VOID)
{ {
@ -159,7 +172,8 @@ MmGetContinuousPages(ULONG NumberOfBytes,
MmPageArray[i].LockCount = 0; MmPageArray[i].LockCount = 0;
MmPageArray[i].MapCount = 0; MmPageArray[i].MapCount = 0;
MmPageArray[i].SavedSwapEntry = 0; MmPageArray[i].SavedSwapEntry = 0;
InsertTailList(&UsedPageListHeads[MC_NPPOOL], &MmPageArray[i].ListEntry); InsertTailList(&UsedPageListHeads[MC_NPPOOL],
&MmPageArray[i].ListEntry);
} }
KeReleaseSpinLock(&PageListLock, oldIrql); KeReleaseSpinLock(&PageListLock, oldIrql);
return((PVOID)(start * 4096)); return((PVOID)(start * 4096));
@ -646,6 +660,11 @@ VOID MmDereferencePage(PVOID PhysicalAddress)
DbgPrint("Freeing locked page\n"); DbgPrint("Freeing locked page\n");
KeBugCheck(0); KeBugCheck(0);
} }
if (MmPageArray[Start].SavedSwapEntry != 0)
{
DbgPrint("Freeing page with swap entry.\n");
KeBugCheck(0);
}
if (MmPageArray[Start].Flags != MM_PHYSICAL_PAGE_USED) if (MmPageArray[Start].Flags != MM_PHYSICAL_PAGE_USED)
{ {
DbgPrint("Freeing page with flags %x\n", DbgPrint("Freeing page with flags %x\n",
@ -653,7 +672,8 @@ VOID MmDereferencePage(PVOID PhysicalAddress)
KeBugCheck(0); KeBugCheck(0);
} }
MmPageArray[Start].Flags = MM_PHYSICAL_PAGE_FREE; MmPageArray[Start].Flags = MM_PHYSICAL_PAGE_FREE;
InsertTailList(&FreeUnzeroedPageListHead, &MmPageArray[Start].ListEntry); InsertTailList(&FreeUnzeroedPageListHead,
&MmPageArray[Start].ListEntry);
} }
KeReleaseSpinLock(&PageListLock, oldIrql); KeReleaseSpinLock(&PageListLock, oldIrql);
} }
@ -743,6 +763,11 @@ MmAllocPage(ULONG Consumer, SWAPENTRY SavedSwapEntry)
KIRQL oldIrql; KIRQL oldIrql;
BOOLEAN NeedClear = FALSE; BOOLEAN NeedClear = FALSE;
if (SavedSwapEntry == 0x17)
{
KeBugCheck(0);
}
DPRINT("MmAllocPage()\n"); DPRINT("MmAllocPage()\n");
KeAcquireSpinLock(&PageListLock, &oldIrql); KeAcquireSpinLock(&PageListLock, &oldIrql);
@ -779,7 +804,8 @@ MmAllocPage(ULONG Consumer, SWAPENTRY SavedSwapEntry)
PageDescriptor->LockCount = 0; PageDescriptor->LockCount = 0;
PageDescriptor->MapCount = 0; PageDescriptor->MapCount = 0;
PageDescriptor->SavedSwapEntry = SavedSwapEntry; PageDescriptor->SavedSwapEntry = SavedSwapEntry;
ExInterlockedInsertTailList(&UsedPageListHeads[Consumer], ListEntry, &PageListLock); ExInterlockedInsertTailList(&UsedPageListHeads[Consumer], ListEntry,
&PageListLock);
MmStats.NrSystemPages++; MmStats.NrSystemPages++;
MmStats.NrFreePages--; MmStats.NrFreePages--;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: page.c,v 1.33 2002/01/01 03:29:15 dwelch Exp $ /* $Id: page.c,v 1.34 2002/01/08 00:49:01 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/i386/page.c * FILE: ntoskrnl/mm/i386/page.c
@ -505,7 +505,14 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage,
*/ */
if (WasDirty != NULL) if (WasDirty != NULL)
{ {
*WasDirty = Pte & PA_DIRTY; if (Pte & PA_DIRTY)
{
*WasDirty = TRUE;
}
else
{
*WasDirty = FALSE;
}
} }
if (PhysicalAddr != NULL) if (PhysicalAddr != NULL)
{ {
@ -514,7 +521,8 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage,
} }
VOID VOID
MmDeletePageFileMapping(PEPROCESS Process, PVOID Address, SWAPENTRY* SwapEntry) MmDeletePageFileMapping(PEPROCESS Process, PVOID Address,
SWAPENTRY* SwapEntry)
/* /*
* FUNCTION: Delete a virtual mapping * FUNCTION: Delete a virtual mapping
*/ */
@ -741,6 +749,24 @@ VOID MmSetCleanPage(PEPROCESS Process, PVOID Address)
} }
} }
VOID MmSetDirtyPage(PEPROCESS Process, PVOID Address)
{
PULONG PageEntry;
PEPROCESS CurrentProcess = PsGetCurrentProcess();
if (Process != CurrentProcess)
{
KeAttachProcess(Process);
}
PageEntry = MmGetPageEntry(Address);
(*PageEntry) = (*PageEntry) | PA_DIRTY;
FLUSH_TLB;
if (Process != CurrentProcess)
{
KeDetachProcess();
}
}
VOID MmEnableVirtualMapping(PEPROCESS Process, PVOID Address) VOID MmEnableVirtualMapping(PEPROCESS Process, PVOID Address)
{ {
PULONG PageEntry; PULONG PageEntry;
@ -951,8 +977,9 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
Attributes = ProtectToPTE(flProtect); Attributes = ProtectToPTE(flProtect);
if (!(Attributes & PA_PRESENT) && PhysicalAddress != 0) if (!(Attributes & PA_PRESENT) && PhysicalAddress != 0)
{ {
DPRINT1("Setting physical address but not allowing access at address 0x%.8X " DPRINT1("Setting physical address but not allowing access at address "
"with attributes %x/%x.\n", Address, Attributes, flProtect); "0x%.8X with attributes %x/%x.\n",
Address, Attributes, flProtect);
KeBugCheck(0); KeBugCheck(0);
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: pagefile.c,v 1.14 2001/12/31 19:06:47 dwelch Exp $ /* $Id: pagefile.c,v 1.15 2002/01/08 00:49:00 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/pagefile.c * FILE: ntoskrnl/mm/pagefile.c
@ -80,7 +80,7 @@ static ULONG MiReservedSwapPages;
/* /*
* Number of pages that can be used for potentially swapable memory without * Number of pages that can be used for potentially swapable memory without
* pagefile space being reserved. The intention is that is allows smss * pagefile space being reserved. The intention is that this allows smss
* to start up and create page files while ordinarily having a commit * to start up and create page files while ordinarily having a commit
* ratio of one. * ratio of one.
*/ */
@ -116,6 +116,18 @@ NTSTATUS MmWriteToSwapPage(SWAPENTRY SwapEntry, PMDL Mdl)
i = FILE_FROM_ENTRY(SwapEntry); i = FILE_FROM_ENTRY(SwapEntry);
offset = OFFSET_FROM_ENTRY(SwapEntry); offset = OFFSET_FROM_ENTRY(SwapEntry);
if (i > MAX_PAGING_FILES)
{
DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry);
KeBugCheck(0);
}
if (PagingFileList[i]->FileObject == NULL ||
PagingFileList[i]->FileObject->DeviceObject == NULL)
{
DPRINT1("Bad paging file 0x%.8X\n", SwapEntry);
KeBugCheck(0);
}
file_offset.QuadPart = offset * 4096; file_offset.QuadPart = offset * 4096;
Status = IoPageWrite(PagingFileList[i]->FileObject, Status = IoPageWrite(PagingFileList[i]->FileObject,
@ -142,6 +154,18 @@ NTSTATUS MmReadFromSwapPage(SWAPENTRY SwapEntry, PMDL Mdl)
i = FILE_FROM_ENTRY(SwapEntry); i = FILE_FROM_ENTRY(SwapEntry);
offset = OFFSET_FROM_ENTRY(SwapEntry); offset = OFFSET_FROM_ENTRY(SwapEntry);
if (i > MAX_PAGING_FILES)
{
DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry);
KeBugCheck(0);
}
if (PagingFileList[i]->FileObject == NULL ||
PagingFileList[i]->FileObject->DeviceObject == NULL)
{
DPRINT1("Bad paging file 0x%.8X\n", SwapEntry);
KeBugCheck(0);
}
file_offset.QuadPart = offset * 4096; file_offset.QuadPart = offset * 4096;
Status = IoPageRead(PagingFileList[i]->FileObject, Status = IoPageRead(PagingFileList[i]->FileObject,
@ -204,7 +228,6 @@ MiAllocPageFromPagingFile(PPAGINGFILE PagingFile)
{ {
KIRQL oldIrql; KIRQL oldIrql;
ULONG i, j; ULONG i, j;
static BOOLEAN SwapSpaceMessage = FALSE;
KeAcquireSpinLock(&PagingFile->AllocMapLock, &oldIrql); KeAcquireSpinLock(&PagingFile->AllocMapLock, &oldIrql);
@ -229,11 +252,6 @@ MiAllocPageFromPagingFile(PPAGINGFILE PagingFile)
} }
KeReleaseSpinLock(&PagingFile->AllocMapLock, oldIrql); KeReleaseSpinLock(&PagingFile->AllocMapLock, oldIrql);
if (!SwapSpaceMessage)
{
DPRINT1("MM: Out of swap space.\n");
SwapSpaceMessage = TRUE;
}
return(0xFFFFFFFF); return(0xFFFFFFFF);
} }
@ -273,12 +291,18 @@ MmAllocSwapPage(VOID)
ULONG i; ULONG i;
ULONG off; ULONG off;
SWAPENTRY entry; SWAPENTRY entry;
static BOOLEAN SwapSpaceMessage = FALSE;
KeAcquireSpinLock(&PagingFileListLock, &oldIrql); KeAcquireSpinLock(&PagingFileListLock, &oldIrql);
if (MiFreeSwapPages == 0) if (MiFreeSwapPages == 0)
{ {
KeReleaseSpinLock(&PagingFileListLock, oldIrql); KeReleaseSpinLock(&PagingFileListLock, oldIrql);
if (!SwapSpaceMessage)
{
DPRINT1("MM: Out of swap space.\n");
SwapSpaceMessage = TRUE;
}
return(0); return(0);
} }
@ -304,6 +328,11 @@ MmAllocSwapPage(VOID)
} }
KeReleaseSpinLock(&PagingFileListLock, oldIrql); KeReleaseSpinLock(&PagingFileListLock, oldIrql);
if (!SwapSpaceMessage)
{
DPRINT1("MM: Out of swap space.\n");
SwapSpaceMessage = TRUE;
}
return(0); return(0);
} }
@ -355,7 +384,8 @@ NtCreatePagingFile(IN PUNICODE_STRING PageFileName,
0, 0,
NULL, NULL,
NULL); NULL);
Status = NtCreateFile(&FileHandle,
Status = IoCreateFile(&FileHandle,
FILE_ALL_ACCESS, FILE_ALL_ACCESS,
&ObjectAttributes, &ObjectAttributes,
&IoStatus, &IoStatus,
@ -365,7 +395,10 @@ NtCreatePagingFile(IN PUNICODE_STRING PageFileName,
FILE_OPEN_IF, FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT, FILE_SYNCHRONOUS_IO_NONALERT,
NULL, NULL,
0); 0,
CreateFileTypeNone,
NULL,
SL_OPEN_PAGING_FILE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return(Status); return(Status);

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: rmap.c,v 1.2 2002/01/01 03:29:15 dwelch Exp $ /* $Id: rmap.c,v 1.3 2002/01/08 00:49:00 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -94,7 +94,8 @@ MmPageOutPhysicalAddress(PVOID PhysicalAddress)
/* /*
* Get or create a pageop * Get or create a pageop
*/ */
PageOp = MmGetPageOp(MemoryArea, 0, 0, MemoryArea->Data.SectionData.Segment, PageOp = MmGetPageOp(MemoryArea, 0, 0,
MemoryArea->Data.SectionData.Segment,
Offset.u.LowPart, MM_PAGEOP_PAGEOUT); Offset.u.LowPart, MM_PAGEOP_PAGEOUT);
if (PageOp == NULL) if (PageOp == NULL)
{ {
@ -119,7 +120,8 @@ MmPageOutPhysicalAddress(PVOID PhysicalAddress)
/* /*
* Do the actual page out work. * Do the actual page out work.
*/ */
Status = MmPageOutSectionView(&Process->AddressSpace, MemoryArea, Address, PageOp); Status = MmPageOutSectionView(&Process->AddressSpace, MemoryArea,
Address, PageOp);
} }
else if (Type == MEMORY_AREA_VIRTUAL_MEMORY) else if (Type == MEMORY_AREA_VIRTUAL_MEMORY)
{ {
@ -142,7 +144,8 @@ MmPageOutPhysicalAddress(PVOID PhysicalAddress)
/* /*
* Do the actual page out work. * Do the actual page out work.
*/ */
Status = MmPageOutVirtualMemory(&Process->AddressSpace, MemoryArea, Address, PageOp); Status = MmPageOutVirtualMemory(&Process->AddressSpace, MemoryArea,
Address, PageOp);
} }
else else
{ {
@ -157,6 +160,8 @@ MmInsertRmap(PVOID PhysicalAddress, PEPROCESS Process, PVOID Address)
PMM_RMAP_ENTRY current_entry; PMM_RMAP_ENTRY current_entry;
PMM_RMAP_ENTRY new_entry; PMM_RMAP_ENTRY new_entry;
Address = (PVOID)PAGE_ROUND_DOWN(Address);
new_entry = ExAllocatePool(NonPagedPool, sizeof(MM_RMAP_ENTRY)); new_entry = ExAllocatePool(NonPagedPool, sizeof(MM_RMAP_ENTRY));
if (new_entry == NULL) if (new_entry == NULL)
{ {
@ -165,11 +170,13 @@ MmInsertRmap(PVOID PhysicalAddress, PEPROCESS Process, PVOID Address)
new_entry->Address = Address; new_entry->Address = Address;
new_entry->Process = Process; new_entry->Process = Process;
if (MmGetPhysicalAddressForProcess(Process, Address)!= (ULONG)PhysicalAddress) if (MmGetPhysicalAddressForProcess(Process, Address) !=
(ULONG)PhysicalAddress)
{ {
DPRINT1("Insert rmap (%d, 0x%.8X) 0x%.8X which doesn't match physical address 0x%.8X\n", DPRINT1("Insert rmap (%d, 0x%.8X) 0x%.8X which doesn't match physical "
Process->UniqueProcessId, Address, "address 0x%.8X\n", Process->UniqueProcessId, Address,
MmGetPhysicalAddressForProcess(Process, Address), PhysicalAddress) MmGetPhysicalAddressForProcess(Process, Address),
PhysicalAddress)
KeBugCheck(0); KeBugCheck(0);
} }
@ -182,20 +189,27 @@ MmInsertRmap(PVOID PhysicalAddress, PEPROCESS Process, PVOID Address)
VOID VOID
MmDeleteAllRmaps(PVOID PhysicalAddress, PVOID Context, MmDeleteAllRmaps(PVOID PhysicalAddress, PVOID Context,
VOID (*DeleteMapping)(PVOID Context, PEPROCESS Process, PVOID Address)) VOID (*DeleteMapping)(PVOID Context, PEPROCESS Process,
PVOID Address))
{ {
PMM_RMAP_ENTRY current_entry; PMM_RMAP_ENTRY current_entry;
PMM_RMAP_ENTRY previous_entry; PMM_RMAP_ENTRY previous_entry;
ExAcquireFastMutex(&RmapListLock); ExAcquireFastMutex(&RmapListLock);
current_entry = MmGetRmapListHeadPage(PhysicalAddress); current_entry = MmGetRmapListHeadPage(PhysicalAddress);
if (current_entry == NULL)
{
DPRINT1("MmDeleteAllRmaps: No rmaps.\n");
KeBugCheck(0);
}
while (current_entry != NULL) while (current_entry != NULL)
{ {
previous_entry = current_entry; previous_entry = current_entry;
current_entry = current_entry->Next; current_entry = current_entry->Next;
if (DeleteMapping) if (DeleteMapping)
{ {
DeleteMapping(Context, previous_entry->Process, previous_entry->Address); DeleteMapping(Context, previous_entry->Process,
previous_entry->Address);
} }
ExFreePool(previous_entry); ExFreePool(previous_entry);
} }
@ -213,7 +227,8 @@ MmDeleteRmap(PVOID PhysicalAddress, PEPROCESS Process, PVOID Address)
current_entry = MmGetRmapListHeadPage(PhysicalAddress); current_entry = MmGetRmapListHeadPage(PhysicalAddress);
while (current_entry != NULL) while (current_entry != NULL)
{ {
if (current_entry->Process == Process && current_entry->Address == Address) if (current_entry->Process == Process &&
current_entry->Address == Address)
{ {
if (previous_entry == NULL) if (previous_entry == NULL)
{ {

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: section.c,v 1.74 2002/01/01 05:09:50 dwelch Exp $ /* $Id: section.c,v 1.75 2002/01/08 00:49:00 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c * FILE: ntoskrnl/mm/section.c
@ -271,8 +271,8 @@ MmUnsharePageEntrySectionSegment(PSECTION_OBJECT Section,
} }
Entry = MAKE_SSE(PAGE_FROM_SSE(Entry), SHARE_COUNT_FROM_SSE(Entry) - 1); Entry = MAKE_SSE(PAGE_FROM_SSE(Entry), SHARE_COUNT_FROM_SSE(Entry) - 1);
/* /*
* If we reducing the share count of this entry to zero then set the entry to zero and * If we reducing the share count of this entry to zero then set the entry
* tell the cache the page is no longer mapped. * to zero and tell the cache the page is no longer mapped.
*/ */
if (SHARE_COUNT_FROM_SSE(Entry) == 0) if (SHARE_COUNT_FROM_SSE(Entry) == 0)
{ {
@ -372,7 +372,8 @@ MiReadPage(PMEMORY_AREA MemoryArea,
TRUE); TRUE);
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE) if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
{ {
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, FALSE, FALSE, FALSE); CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, FALSE, FALSE,
FALSE);
return(Status); return(Status);
} }
} }
@ -411,7 +412,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
Mdl, Mdl,
Offset, Offset,
&IoStatus, &IoStatus,
FALSE); TRUE);
return(Status); return(Status);
} }
} }
@ -541,7 +542,8 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
DbgPrint("Unable to create virtual mapping\n"); DbgPrint("Unable to create virtual mapping\n");
KeBugCheck(0); KeBugCheck(0);
} }
MmInsertRmap(Page, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(Page, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
} }
if (Locked) if (Locked)
{ {
@ -565,7 +567,9 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MmUnlockSectionSegment(Segment); MmUnlockSectionSegment(Segment);
MmUnlockSection(Section); MmUnlockSection(Section);
Status = MmRequestPageMemoryConsumer(MC_USER, FALSE, &Page); MmDeletePageFileMapping(NULL, (PVOID)PAddress, &SwapEntry);
Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &Page);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
KeBugCheck(0); KeBugCheck(0);
@ -601,10 +605,16 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
return(Status); return(Status);
} }
/*
* Store the swap entry for later use.
*/
MmSetSavedSwapEntryPage(Page, SwapEntry);
/* /*
* Add the page to the process's working set * Add the page to the process's working set
*/ */
MmInsertRmap(Page, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(Page, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
/* /*
* Finish the operation * Finish the operation
@ -633,7 +643,10 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MemoryArea->Attributes, MemoryArea->Attributes,
Offset.QuadPart, Offset.QuadPart,
FALSE); FALSE);
/* Don't add an rmap entry since the page mapped could be for anything. */ /*
* Don't add an rmap entry since the page mapped could be for
* anything.
*/
if (Locked) if (Locked)
{ {
MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address)); MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address));
@ -673,7 +686,8 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MemoryArea->Attributes, MemoryArea->Attributes,
(ULONG)Page, (ULONG)Page,
FALSE); FALSE);
MmInsertRmap(Page, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(Page, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
if (Locked) if (Locked)
{ {
MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address)); MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address));
@ -798,7 +812,8 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MmLockSection(Section); MmLockSection(Section);
MmLockSectionSegment(Segment); MmLockSectionSegment(Segment);
} }
MmInsertRmap(Page, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(Page, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Unable to create virtual mapping\n"); DbgPrint("Unable to create virtual mapping\n");
@ -870,12 +885,18 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MmSetPageEntrySectionSegment(Segment, Offset.QuadPart, Entry); MmSetPageEntrySectionSegment(Segment, Offset.QuadPart, Entry);
MmSharePageEntrySectionSegment(Segment, Offset.QuadPart); MmSharePageEntrySectionSegment(Segment, Offset.QuadPart);
/*
* Save the swap entry.
*/
MmSetSavedSwapEntryPage(Page, SwapEntry);
Status = MmCreateVirtualMapping(PsGetCurrentProcess(), Status = MmCreateVirtualMapping(PsGetCurrentProcess(),
Address, Address,
Attributes, Attributes,
(ULONG)Page, (ULONG)Page,
FALSE); FALSE);
MmInsertRmap(Page, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(Page, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Unable to create virtual mapping\n"); DbgPrint("Unable to create virtual mapping\n");
@ -909,7 +930,8 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
Attributes, Attributes,
(ULONG)Page, (ULONG)Page,
FALSE); FALSE);
MmInsertRmap(Page, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(Page, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Unable to create virtual mapping\n"); DbgPrint("Unable to create virtual mapping\n");
@ -1069,7 +1091,8 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
MemoryArea->Attributes, MemoryArea->Attributes,
(ULONG)NewPage, (ULONG)NewPage,
FALSE); FALSE);
MmInsertRmap(NewPage, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmInsertRmap(NewPage, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Unable to create virtual mapping\n"); DbgPrint("Unable to create virtual mapping\n");
@ -1084,7 +1107,8 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
* Unshare the old page. * Unshare the old page.
*/ */
MmUnsharePageEntrySectionSegment(Section, Segment, Offset.QuadPart, FALSE); MmUnsharePageEntrySectionSegment(Section, Segment, Offset.QuadPart, FALSE);
MmDeleteRmap((PVOID)OldPage, PsGetCurrentProcess(), (PVOID)PAGE_ROUND_DOWN(Address)); MmDeleteRmap((PVOID)OldPage, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
MmDereferencePage((PVOID)OldPage); MmDereferencePage((PVOID)OldPage);
PageOp->Status = STATUS_SUCCESS; PageOp->Status = STATUS_SUCCESS;
@ -1106,7 +1130,10 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
FALSE, FALSE,
&WasDirty, &WasDirty,
(PULONG)&PhysicalAddress); (PULONG)&PhysicalAddress);
PageOutContext->WasDirty = PageOutContext->WasDirty || WasDirty; if (WasDirty)
{
PageOutContext->WasDirty = TRUE;
}
if (!PageOutContext->Private) if (!PageOutContext->Private)
{ {
MmUnsharePageEntrySectionSegment(PageOutContext->Section, MmUnsharePageEntrySectionSegment(PageOutContext->Section,
@ -1137,10 +1164,6 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
PREACTOS_COMMON_FCB_HEADER Fcb; PREACTOS_COMMON_FCB_HEADER Fcb;
BOOLEAN DirectMapped; BOOLEAN DirectMapped;
DPRINT("MmPageOutSection(Process %d, Address 0x%.8X)\n",
AddressSpace->Process->UniqueProcessId,
Address);
Address = (PVOID)PAGE_ROUND_DOWN(Address); Address = (PVOID)PAGE_ROUND_DOWN(Address);
Offset.QuadPart = (ULONG)(Address - (ULONG)MemoryArea->BaseAddress) + Offset.QuadPart = (ULONG)(Address - (ULONG)MemoryArea->BaseAddress) +
@ -1171,11 +1194,13 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
Section = MemoryArea->Data.SectionData.Section; Section = MemoryArea->Data.SectionData.Section;
/* /*
* This should never happen even mapping of the physical memory are never * This should never happen since mappings of physical memory are never
* placed in the rmap lists. * placed in the rmap lists.
*/ */
if (Segment->Flags & SO_PHYSICAL_MEMORY) if (Section->Flags & SO_PHYSICAL_MEMORY)
{ {
DPRINT1("Trying to page out from physical memory section address 0x%X "
"process %d\n", Address, AddressSpace->Process->UniqueProcessId);
KeBugCheck(0); KeBugCheck(0);
} }
@ -1183,8 +1208,16 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
* Get the section segment entry and the physical address. * Get the section segment entry and the physical address.
*/ */
Entry = MmGetPageEntrySectionSegment(Segment, Offset.QuadPart); Entry = MmGetPageEntrySectionSegment(Segment, Offset.QuadPart);
PhysicalAddress = (PVOID)MmGetPhysicalAddressForProcess(AddressSpace->Process, if (!MmIsPagePresent(AddressSpace->Process, Address))
{
DPRINT1("Trying to page out not-present page at (%d,0x%.8X).\n",
AddressSpace->Process->UniqueProcessId, Address);
KeBugCheck(0);
}
PhysicalAddress =
(PVOID)MmGetPhysicalAddressForProcess(AddressSpace->Process,
Address); Address);
SwapEntry = MmGetSavedSwapEntryPage(PhysicalAddress);
/* /*
* Prepare the context structure for the rmap delete call. * Prepare the context structure for the rmap delete call.
@ -1193,7 +1226,15 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
Context.Segment = Segment; Context.Segment = Segment;
Context.Offset = Offset; Context.Offset = Offset;
Context.WasDirty = FALSE; Context.WasDirty = FALSE;
Context.Private = Private = ((PVOID)(Entry & 0xFFFFF000) != PhysicalAddress); if (IS_SWAP_FROM_SSE(Entry) ||
(PVOID)(PAGE_FROM_SSE(Entry)) != PhysicalAddress)
{
Context.Private = Private = TRUE;
}
else
{
Context.Private = Private = FALSE;
}
/* /*
* Take an additional reference to the page. * Take an additional reference to the page.
@ -1201,23 +1242,44 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MmReferencePage(PhysicalAddress); MmReferencePage(PhysicalAddress);
/* /*
* Paging only data mapped read-only is easy. * Paging out data mapped read-only is easy.
*/ */
if (MemoryArea->Attributes & PAGE_READONLY || if (MemoryArea->Attributes & PAGE_READONLY ||
MemoryArea->Attributes & PAGE_EXECUTE_READ) MemoryArea->Attributes & PAGE_EXECUTE_READ)
{ {
/*
* Read-only data should never be in the swapfile.
*/
if (SwapEntry != 0)
{
DPRINT1("SwapEntry != 0 was 0x%.8X at address 0x%.8X, "
"paddress 0x%.8X\n", SwapEntry, Address,
PhysicalAddress);
KeBugCheck(0);
}
/*
* Read-only data should never be COWed
*/
if (Private)
{
DPRINT1("Had private copy of read-only page.\n");
KeBugCheck(0);
}
/* /*
* Delete all mappings of this page. * Delete all mappings of this page.
*/ */
MmDeleteAllRmaps(PhysicalAddress, (PVOID)&Context, MmPageOutDeleteMapping); MmDeleteAllRmaps(PhysicalAddress, (PVOID)&Context,
MmPageOutDeleteMapping);
if (Context.WasDirty) if (Context.WasDirty)
{ {
KeBugCheck(0); KeBugCheck(0);
} }
/* /*
* If this page wasn't direct mapped then we have a private copy so release * If this page wasn't direct mapped then we have a private copy so
* back to the system; otherwise the cache manager will have handled freeing * release back to the system; otherwise the cache manager will have
* the cache segment which we mapped from. * handled freeing the cache segment which we mapped from.
*/ */
if (!DirectMapped) if (!DirectMapped)
{ {
@ -1251,10 +1313,31 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
*/ */
if (!Context.WasDirty) if (!Context.WasDirty)
{ {
if (!DirectMapped) if (!DirectMapped || Private)
{ {
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress); MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress);
} }
if (Private)
{
if (SwapEntry == 0)
{
DPRINT1("Private page, non-dirty but not swapped out "
"process %d address 0x%.8X\n",
AddressSpace->Process->UniqueProcessId,
Address);
KeBugCheck(0);
}
else
{
Status = MmCreatePageFileMapping(AddressSpace->Process,
Address,
SwapEntry);
if (!NT_SUCCESS(Status))
{
KeBugCheck(0);
}
}
}
PageOp->Status = STATUS_SUCCESS; PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
@ -1266,8 +1349,9 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
* If this page was direct mapped from the cache then the cache manager * If this page was direct mapped from the cache then the cache manager
* will already have taken care of writing it back. * will already have taken care of writing it back.
*/ */
if (DirectMapped) if (DirectMapped && !Private)
{ {
assert(SwapEntry == 0);
MmDereferencePage((PVOID)PhysicalAddress); MmDereferencePage((PVOID)PhysicalAddress);
PageOp->Status = STATUS_SUCCESS; PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
@ -1294,6 +1378,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MemoryArea->Attributes, MemoryArea->Attributes,
(ULONG)PhysicalAddress, (ULONG)PhysicalAddress,
FALSE); FALSE);
MmSetDirtyPage(MemoryArea->Process, Address);
MmInsertRmap(PhysicalAddress, MmInsertRmap(PhysicalAddress,
MemoryArea->Process, MemoryArea->Process,
Address); Address);
@ -1302,15 +1387,17 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
{ {
/* /*
* For non-private pages if the page wasn't direct mapped then * For non-private pages if the page wasn't direct mapped then
* set it back into section segment entry so we don't loose our * set it back into the section segment entry so we don't loose
* copy. Otherwise it will be handled by the cache manager. * our copy. Otherwise it will be handled by the cache manager.
*/ */
Status = MmCreateVirtualMapping(MemoryArea->Process, Status = MmCreateVirtualMapping(MemoryArea->Process,
Address, Address,
MemoryArea->Attributes, MemoryArea->Attributes,
(ULONG)PhysicalAddress, (ULONG)PhysicalAddress,
FALSE); FALSE);
MmSetPageEntrySectionSegment(Segment, Offset.QuadPart, (ULONG)PhysicalAddress); MmSetDirtyPage(MemoryArea->Process, Address);
MmSetPageEntrySectionSegment(Segment, Offset.QuadPart,
(ULONG)PhysicalAddress);
MmSharePageEntrySectionSegment(Segment, Offset.QuadPart); MmSharePageEntrySectionSegment(Segment, Offset.QuadPart);
} }
PageOp->Status = STATUS_UNSUCCESSFUL; PageOp->Status = STATUS_UNSUCCESSFUL;
@ -1328,7 +1415,8 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
Status = MmWriteToSwapPage(SwapEntry, Mdl); Status = MmWriteToSwapPage(SwapEntry, Mdl);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n", Status); DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
Status);
/* /*
* As above: undo our actions. * As above: undo our actions.
* FIXME: Also free the swap page. * FIXME: Also free the swap page.
@ -1340,6 +1428,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MemoryArea->Attributes, MemoryArea->Attributes,
(ULONG)PhysicalAddress, (ULONG)PhysicalAddress,
FALSE); FALSE);
MmSetDirtyPage(MemoryArea->Process, Address);
MmInsertRmap(PhysicalAddress, MmInsertRmap(PhysicalAddress,
MemoryArea->Process, MemoryArea->Process,
Address); Address);
@ -1351,7 +1440,9 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MemoryArea->Attributes, MemoryArea->Attributes,
(ULONG)PhysicalAddress, (ULONG)PhysicalAddress,
FALSE); FALSE);
MmSetPageEntrySectionSegment(Segment, Offset.QuadPart, (ULONG)PhysicalAddress); MmSetDirtyPage(MemoryArea->Process, Address);
MmSetPageEntrySectionSegment(Segment, Offset.QuadPart,
(ULONG)PhysicalAddress);
MmSharePageEntrySectionSegment(Segment, Offset.QuadPart); MmSharePageEntrySectionSegment(Segment, Offset.QuadPart);
} }
PageOp->Status = STATUS_UNSUCCESSFUL; PageOp->Status = STATUS_UNSUCCESSFUL;
@ -1364,6 +1455,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
* Otherwise we have succeeded. * Otherwise we have succeeded.
*/ */
DPRINT("MM: Wrote section page 0x%.8X to swap!\n", PhysicalAddress); DPRINT("MM: Wrote section page 0x%.8X to swap!\n", PhysicalAddress);
MmSetSavedSwapEntryPage(PhysicalAddress, 0);
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress); MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress);
if (Private) if (Private)

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.53 2002/01/01 00:21:56 dwelch Exp $ /* $Id: virtual.c,v 1.54 2002/01/08 00:49:01 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -172,7 +172,8 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
Status = MmWriteToSwapPage(SwapEntry, Mdl); Status = MmWriteToSwapPage(SwapEntry, Mdl);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n", Status); DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
Status);
MmEnableVirtualMapping(MemoryArea->Process, Address); MmEnableVirtualMapping(MemoryArea->Process, Address);
PageOp->Status = STATUS_UNSUCCESSFUL; PageOp->Status = STATUS_UNSUCCESSFUL;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
@ -187,6 +188,7 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
MmDeleteVirtualMapping(MemoryArea->Process, Address, FALSE, NULL, NULL); MmDeleteVirtualMapping(MemoryArea->Process, Address, FALSE, NULL, NULL);
MmCreatePageFileMapping(MemoryArea->Process, Address, SwapEntry); MmCreatePageFileMapping(MemoryArea->Process, Address, SwapEntry);
MmDeleteAllRmaps(PhysicalAddress, NULL, NULL); MmDeleteAllRmaps(PhysicalAddress, NULL, NULL);
MmSetSavedSwapEntryPage(PhysicalAddress, 0);
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress); MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress);
PageOp->Status = STATUS_SUCCESS; PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
@ -331,6 +333,7 @@ MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
{ {
KeBugCheck(0); KeBugCheck(0);
} }
MmSetSavedSwapEntryPage(Page, SwapEntry);
} }
/* /*

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.82 2002/01/03 14:03:05 ekohl Exp $ /* $Id: thread.c,v 1.83 2002/01/08 00:49:01 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -108,9 +108,11 @@ VOID PsDumpThreads(BOOLEAN IncludeSystem)
} }
if (IncludeSystem || current->ThreadsProcess->UniqueProcessId >= 6) if (IncludeSystem || current->ThreadsProcess->UniqueProcessId >= 6)
{ {
DbgPrint("current->Tcb.State %d PID.TID %d.%d Name %.8s\n", DbgPrint("current->Tcb.State %d PID.TID %d.%d Name %.8s Stack: \n",
current->Tcb.State, current->ThreadsProcess->UniqueProcessId, current->Tcb.State,
current->Cid.UniqueThread, current->ThreadsProcess->ImageFileName); current->ThreadsProcess->UniqueProcessId,
current->Cid.UniqueThread,
current->ThreadsProcess->ImageFileName);
if (current->Tcb.State == THREAD_STATE_RUNNABLE || if (current->Tcb.State == THREAD_STATE_RUNNABLE ||
current->Tcb.State == THREAD_STATE_SUSPENDED || current->Tcb.State == THREAD_STATE_SUSPENDED ||
current->Tcb.State == THREAD_STATE_BLOCKED) current->Tcb.State == THREAD_STATE_BLOCKED)
@ -121,11 +123,12 @@ VOID PsDumpThreads(BOOLEAN IncludeSystem)
i = 0; i = 0;
while (Ebp != 0 && Ebp >= (PULONG)current->Tcb.StackLimit) while (Ebp != 0 && Ebp >= (PULONG)current->Tcb.StackLimit)
{ {
DbgPrint("Frame: 0x%.8X Eip: 0x%.8X%s", Ebp[0], Ebp[1], DbgPrint("%.8X%s", Ebp[0], Ebp[1],
(i % 2) == 1 ? "\n" : ""); (i % 8) == 7 ? "\n" : " ");
Ebp = (PULONG)Ebp[0]; Ebp = (PULONG)Ebp[0];
i++;
} }
if ((i % 2) == 0) if ((i % 8) != 7)
{ {
DbgPrint("\n"); DbgPrint("\n");
} }

View file

@ -1,4 +1,4 @@
# $Id: helper.mk,v 1.9 2001/12/11 06:00:07 phreak Exp $ # $Id: helper.mk,v 1.10 2002/01/08 00:49:02 dwelch Exp $
# #
# Helper makefile for ReactOS modules # Helper makefile for ReactOS modules
# Variables this makefile accepts: # Variables this makefile accepts:
@ -398,6 +398,7 @@ MK_NOSTRIPNAME := $(MK_BASENAME).nostrip$(MK_EXT)
# We don't want to link header files # We don't want to link header files
MK_OBJECTS := $(filter-out %.h,$(TARGET_OBJECTS)) MK_OBJECTS := $(filter-out %.h,$(TARGET_OBJECTS))
MK_STRIPPED_OBJECT := $(MK_BASENAME).stripped.o
ifeq ($(MK_IMPLIBONLY),yes) ifeq ($(MK_IMPLIBONLY),yes)
@ -415,7 +416,7 @@ $(MK_IMPLIBPATH)/$(MK_IMPLIB_FULLNAME): $(TARGET_OBJECTS)
else # MK_IMPLIBONLY else # MK_IMPLIBONLY
all: $(MK_FULLNAME) all: $(MK_FULLNAME) $(MK_NOSTRIPNAME)
ifeq ($(MK_IMPLIB),yes) ifeq ($(MK_IMPLIB),yes)
@ -453,6 +454,11 @@ endif
$(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS) $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
- $(RM) temp.exp - $(RM) temp.exp
- $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).sym - $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).sym
$(MK_FULLNAME): $(MK_NOSTRIPNAME)
$(CP) $(MK_NOSTRIPNAME) $(MK_FULLNAME)
# $(STRIP) --strip-debug $(MK_FULLNAME)
endif # KM_MODE endif # KM_MODE
# Kernel mode targets # Kernel mode targets
@ -489,11 +495,33 @@ $(MK_NOSTRIPNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_LIBS)
- $(RM) temp.exp - $(RM) temp.exp
- $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).sym - $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).sym
endif # MK_MODE $(MK_FULLNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_LIBS)
$(LD) -r -o $(MK_STRIPPED_OBJECT) $(MK_OBJECTS)
$(STRIP) --strip-debug $(MK_STRIPPED_OBJECT)
$(CC) -Wl,--base-file,base.tmp \
-Wl,--entry,$(TARGET_ENTRY) \
$(TARGET_LFLAGS) \
-nostartfiles -nostdlib \
-o junk.tmp \
$(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
- $(RM) junk.tmp
$(DLLTOOL) --dllname $(MK_FULLNAME) \
--base-file base.tmp \
--output-exp temp.exp $(MK_EXTRACMD)
- $(RM) base.tmp
$(CC) $(TARGET_LFLAGS) \
-Wl,--subsystem,native \
-Wl,--image-base,$(TARGET_BASE) \
-Wl,--file-alignment,0x1000 \
-Wl,--section-alignment,0x1000 \
-Wl,--entry,$(TARGET_ENTRY) \
-Wl,temp.exp \
-mdll -nostartfiles -nostdlib \
-o $(MK_FULLNAME) \
$(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
- $(RM) temp.exp
$(MK_FULLNAME): $(MK_NOSTRIPNAME) endif # MK_MODE
$(CP) $(MK_NOSTRIPNAME) $(MK_FULLNAME)
# $(STRIP) --strip-debug $(MK_FULLNAME)
endif # MK_IMPLIBONLY endif # MK_IMPLIBONLY

View file

@ -10,7 +10,11 @@ typedef const CHAR *LPCSTR;
typedef const WCHAR *LPCWSTR; typedef const WCHAR *LPCWSTR;
typedef unsigned int *LPBOOL; typedef unsigned int *LPBOOL;
#ifndef __unix__
#define STDCALL __attribute__((stdcall)) #define STDCALL __attribute__((stdcall))
#else
#define STDCALL
#endif
int STDCALL MultiByteToWideChar( int STDCALL MultiByteToWideChar(
UINT CodePage, UINT CodePage,