-/* $Id: copy.c,v 1.22 2004/06/06 07:52:22 hbirr Exp $
+/* $Id: copy.c,v 1.23 2004/06/06 08:36:30 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#endif
#define MAX_ZERO_LENGTH (256 * 1024)
+#define MAX_RW_LENGTH (64 * 1024)
+
+#if defined(__GNUC__)
+void * alloca(size_t size);
+#elif defined(_MSC_VER)
+void* _alloca(size_t size);
+#else
+#error Unknown compiler for alloca intrinsic stack allocation "function"
+#endif
/* FUNCTIONS *****************************************************************/
NTSTATUS Status;
ULONG TempLength;
KEVENT Event;
+ PMDL Mdl;
+
+ Mdl = alloca(MmSizeOfMdl(NULL, MAX_RW_LENGTH));
Status = CcRosGetCacheSegmentChain(Bcb, ReadOffset, Length, &head);
if (!NT_SUCCESS(Status))
{
PCACHE_SEGMENT current2;
ULONG current_size;
- PMDL Mdl;
ULONG i;
ULONG offset;
/*
* Create an MDL which contains all their pages.
*/
- Mdl = MmCreateMdl(NULL, NULL, current_size);
+ MmInitializeMdl(Mdl, NULL, current_size);
Mdl->MdlFlags |= (MDL_PAGES_LOCKED | MDL_IO_PAGE_READ);
current2 = current;
offset = 0;
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
Status = Iosb.Status;
}
+ MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
{
while (current != NULL)
{
Size = CacheSeg->Bcb->CacheSegmentSize;
}
- Mdl = MmCreateMdl(NULL, CacheSeg->BaseAddress, Size);
+ Mdl = alloca(MmSizeOfMdl(CacheSeg->BaseAddress, Size));
+ MmInitializeMdl(Mdl, CacheSeg->BaseAddress, Size);
MmBuildMdlForNonPagedPool(Mdl);
+ Mdl->MdlFlags |= MDL_IO_PAGE_READ;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Status = IoPageRead(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, & Event, &IoStatus);
if (Status == STATUS_PENDING)
{
Size = CacheSeg->Bcb->CacheSegmentSize;
}
- Mdl = MmCreateMdl(NULL, CacheSeg->BaseAddress, Size);
+ Mdl = alloca(MmSizeOfMdl(CacheSeg->BaseAddress, Size));
+ MmInitializeMdl(Mdl, CacheSeg->BaseAddress, Size);
MmBuildMdlForNonPagedPool(Mdl);
+ Mdl->MdlFlags |= MDL_IO_PAGE_READ;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Status = IoPageWrite(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, &Event, &IoStatus);
if (Status == STATUS_PENDING)
}
while (Length > 0)
{
- TempLength = min(max(Bcb->CacheSegmentSize, 65536), Length);
+ TempLength = min(max(Bcb->CacheSegmentSize, MAX_RW_LENGTH), Length);
ReadCacheSegmentChain(Bcb, ReadOffset, TempLength, Buffer);
ReadLength += TempLength;
Length -= TempLength;
if (FileObject->SectionObjectPointer->SharedCacheMap == NULL)
{
/* File is not cached */
+
+ Mdl = alloca(MmSizeOfMdl(NULL, MAX_ZERO_LENGTH));
while (Length > 0)
{
{
CurrentLength = Length;
}
- Mdl = MmCreateMdl(NULL, (PVOID)WriteOffset.u.LowPart, CurrentLength);
-
- if (Mdl == NULL)
- {
- return(FALSE);
- }
+ MmInitializeMdl(Mdl, (PVOID)WriteOffset.u.LowPart, CurrentLength);
Mdl->MdlFlags |= (MDL_PAGES_LOCKED | MDL_IO_PAGE_READ);
for (i = 0; i < ((Mdl->Size - sizeof(MDL)) / sizeof(ULONG)); i++)
{
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
Status = Iosb.Status;
}
+ MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
if (!NT_SUCCESS(Status))
{
return(FALSE);
PVOID
MmGetDirtyPagesFromWorkingSet(struct _EPROCESS* Process);
NTSTATUS
-MmWriteToSwapPage(SWAPENTRY SwapEntry, PMDL Mdl);
+MmWriteToSwapPage(SWAPENTRY SwapEntry, PHYSICAL_ADDRESS* Page);
NTSTATUS
-MmReadFromSwapPage(SWAPENTRY SwapEntry, PMDL Mdl);
+MmReadFromSwapPage(SWAPENTRY SwapEntry, PHYSICAL_ADDRESS* Page);
VOID
MmSetFlagsPage(PHYSICAL_ADDRESS PhysicalAddress, ULONG Flags);
ULONG
-/* $Id: irp.c,v 1.60 2004/04/20 23:14:35 gdalsnes Exp $
+/* $Id: irp.c,v 1.61 2004/06/06 08:36:31 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* Windows NT File System Internals, page 165 */
if (Irp->Flags & (IRP_PAGING_IO|IRP_CLOSE_OPERATION))
{
- if (Irp->Flags & IRP_PAGING_IO)
+ /*
+ * If MDL_IO_PAGE_READ is set, then the caller is responsible
+ * for deallocating of the mdl.
+ */
+ if (Irp->Flags & IRP_PAGING_IO &&
+ Irp->MdlAddress &&
+ !(Irp->MdlAddress->MdlFlags & MDL_IO_PAGE_READ))
{
- /* FIXME:
- * The mdl should be freed by the caller!
- */
+
if (Irp->MdlAddress->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
{
MmUnmapLockedPages(Irp->MdlAddress->MappedSystemVa, Irp->MdlAddress);
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* $Id: anonmem.c,v 1.27 2004/04/10 22:35:25 gdalsnes Exp $
+/* $Id: anonmem.c,v 1.28 2004/06/06 08:36:31 hbirr Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/anonmem.c
{
SWAPENTRY SwapEntry;
LARGE_INTEGER PhysicalAddress;
- PMDL Mdl;
NTSTATUS Status;
/*
/*
* Write the page to the pagefile
*/
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&PhysicalAddress);
- Status = MmWriteToSwapPage(SwapEntry, Mdl);
+ Status = MmWriteToSwapPage(SwapEntry, &PhysicalAddress);
if (!NT_SUCCESS(Status))
{
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
BOOL WasDirty;
SWAPENTRY SwapEntry;
NTSTATUS Status;
- PMDL Mdl;
DPRINT("MmPageOutVirtualMemory(Address 0x%.8X) PID %d\n",
Address, MemoryArea->Process->UniqueProcessId);
/*
* Write the page to the pagefile
*/
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (ULONG *)&PhysicalAddress.u.LowPart);
- Status = MmWriteToSwapPage(SwapEntry, Mdl);
+ Status = MmWriteToSwapPage(SwapEntry, &PhysicalAddress);
if (!NT_SUCCESS(Status))
{
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
if (MmIsPageSwapEntry(NULL, Address))
{
SWAPENTRY SwapEntry;
- PMDL Mdl;
MmDeletePageFileMapping(MemoryArea->Process, Address, &SwapEntry);
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&Page);
- Status = MmReadFromSwapPage(SwapEntry, Mdl);
+ Status = MmReadFromSwapPage(SwapEntry, &Page);
if (!NT_SUCCESS(Status))
{
KEBUGCHECK(0);
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* $Id: section.c,v 1.150 2004/05/30 12:55:11 hbirr Exp $
+/* $Id: section.c,v 1.151 2004/06/06 08:36:31 hbirr Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c
* process and the current segment (also not within an other process).
*/
NTSTATUS Status;
- PMDL Mdl;
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&Page);
- Status = MmWriteToSwapPage(SavedSwapEntry, Mdl);
+ Status = MmWriteToSwapPage(SavedSwapEntry, &Page);
if (!NT_SUCCESS(Status))
{
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n", Status);
* Must be private page we have swapped out.
*/
SWAPENTRY SwapEntry;
- PMDL Mdl;
/*
* Sanity check
KEBUGCHECK(0);
}
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&Page);
- Status = MmReadFromSwapPage(SwapEntry, Mdl);
+ Status = MmReadFromSwapPage(SwapEntry, &Page);
if (!NT_SUCCESS(Status))
{
DPRINT1("MmReadFromSwapPage failed, status = %x\n", Status);
else if (IS_SWAP_FROM_SSE(Entry))
{
SWAPENTRY SwapEntry;
- PMDL Mdl;
SwapEntry = SWAPENTRY_FROM_SSE(Entry);
KEBUGCHECK(0);
}
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&Page);
- Status = MmReadFromSwapPage(SwapEntry, Mdl);
+ Status = MmReadFromSwapPage(SwapEntry, &Page);
if (!NT_SUCCESS(Status))
{
KEBUGCHECK(0);
PHYSICAL_ADDRESS PhysicalAddress;
MM_SECTION_PAGEOUT_CONTEXT Context;
SWAPENTRY SwapEntry;
- PMDL Mdl;
ULONG Entry;
ULONG FileOffset;
NTSTATUS Status;
/*
* Write the page to the pagefile
*/
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&PhysicalAddress);
- Status = MmWriteToSwapPage(SwapEntry, Mdl);
+ Status = MmWriteToSwapPage(SwapEntry, &PhysicalAddress);
if (!NT_SUCCESS(Status))
{
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
PMM_SECTION_SEGMENT Segment;
PHYSICAL_ADDRESS PhysicalAddress;
SWAPENTRY SwapEntry;
- PMDL Mdl;
ULONG Entry;
BOOLEAN Private;
NTSTATUS Status;
/*
* Write the page to the pagefile
*/
- Mdl = MmCreateMdl(NULL, NULL, PAGE_SIZE);
- MmBuildMdlFromPages(Mdl, (PULONG)&PhysicalAddress);
- Status = MmWriteToSwapPage(SwapEntry, Mdl);
+ Status = MmWriteToSwapPage(SwapEntry, &PhysicalAddress);
if (!NT_SUCCESS(Status))
{
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",