2 * Copyright (C) 1998-2005 ReactOS Team (and the authors from the programmers section)
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * PROJECT: ReactOS kernel
20 * FILE: ntoskrnl/mm/section.c
21 * PURPOSE: Implements section objects
23 * PROGRAMMERS: Rex Jolliff
36 * Thomas Weidenmueller
37 * Gunnar Andre' Dalsnes
45 /* INCLUDES *****************************************************************/
51 #include <reactos/exeformat.h>
53 #if defined (ALLOC_PRAGMA)
54 #pragma alloc_text(INIT, MmCreatePhysicalMemorySection)
55 #pragma alloc_text(INIT, MmInitSectionImplementation)
58 KEVENT CcpLazyWriteEvent
;
62 MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject
)
64 return IoGetRelatedDeviceObject(FileObject
);
70 (PDEVICE_OBJECT DeviceObject
,
74 /* Unlock MDL Pages, page 167. */
75 DPRINT("MiSimpleReadComplete %x\n", Irp
);
76 PMDL Mdl
= Irp
->MdlAddress
;
79 DPRINT("MDL Unlock %x\n", Mdl
);
84 /* Check if there's an MDL */
85 while ((Mdl
= Irp
->MdlAddress
))
87 /* Clear all of them */
88 Irp
->MdlAddress
= Mdl
->Next
;
92 return STATUS_SUCCESS
;
98 (PFILE_OBJECT FileObject
,
99 PLARGE_INTEGER FileOffset
,
102 PIO_STATUS_BLOCK ReadStatus
)
107 PDEVICE_OBJECT DeviceObject
;
108 PIO_STACK_LOCATION IrpSp
;
115 DeviceObject
= MmGetDeviceObjectForFile(FileObject
);
116 ReadStatus
->Status
= STATUS_INTERNAL_ERROR
;
117 ReadStatus
->Information
= 0;
119 ASSERT(DeviceObject
);
122 ("PAGING READ: FileObject %x <%wZ> Offset %08x%08x Length %d\n",
124 &FileObject
->FileName
,
125 FileOffset
->HighPart
,
129 KeInitializeEvent(&ReadWait
, NotificationEvent
, FALSE
);
131 Irp
= IoBuildAsynchronousFsdRequest
141 return STATUS_NO_MEMORY
;
144 Irp
->Flags
|= IRP_PAGING_IO
| IRP_SYNCHRONOUS_PAGING_IO
| IRP_NOCACHE
| IRP_SYNCHRONOUS_API
;
146 Irp
->UserEvent
= &ReadWait
;
147 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
148 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
149 IrpSp
= IoGetNextIrpStackLocation(Irp
);
150 IrpSp
->Control
|= SL_INVOKE_ON_SUCCESS
| SL_INVOKE_ON_ERROR
;
151 IrpSp
->FileObject
= FileObject
;
152 IrpSp
->CompletionRoutine
= MiSimpleReadComplete
;
154 Status
= IoCallDriver(DeviceObject
, Irp
);
155 if (Status
== STATUS_PENDING
)
157 DPRINT1("KeWaitForSingleObject(&ReadWait)\n");
159 (KeWaitForSingleObject
166 DPRINT1("Warning: Failed to wait for synchronous IRP\n");
172 DPRINT("Paging IO Done: %08x\n", ReadStatus
->Status
);
174 ReadStatus
->Status
== STATUS_END_OF_FILE
?
175 STATUS_SUCCESS
: ReadStatus
->Status
;
182 (PFILE_OBJECT FileObject
,
183 PLARGE_INTEGER FileOffset
,
186 PIO_STATUS_BLOCK ReadStatus
,
193 PDEVICE_OBJECT DeviceObject
;
194 PIO_STACK_LOCATION IrpSp
;
201 ObReferenceObject(FileObject
);
202 DeviceObject
= MmGetDeviceObjectForFile(FileObject
);
203 ASSERT(DeviceObject
);
206 ("PAGING WRITE: FileObject %x Offset %x Length %d (%s:%d)\n",
213 KeInitializeEvent(&ReadWait
, NotificationEvent
, FALSE
);
215 Irp
= IoBuildAsynchronousFsdRequest
225 ObDereferenceObject(FileObject
);
226 return STATUS_NO_MEMORY
;
229 Irp
->Flags
= IRP_PAGING_IO
| IRP_SYNCHRONOUS_PAGING_IO
| IRP_NOCACHE
| IRP_SYNCHRONOUS_API
;
231 Irp
->UserEvent
= &ReadWait
;
232 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
233 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
234 IrpSp
= IoGetNextIrpStackLocation(Irp
);
235 IrpSp
->Control
|= SL_INVOKE_ON_SUCCESS
| SL_INVOKE_ON_ERROR
;
236 IrpSp
->FileObject
= FileObject
;
237 IrpSp
->CompletionRoutine
= MiSimpleReadComplete
;
239 DPRINT("Call Driver\n");
240 Status
= IoCallDriver(DeviceObject
, Irp
);
241 DPRINT("Status %x\n", Status
);
243 ObDereferenceObject(FileObject
);
245 if (Status
== STATUS_PENDING
)
247 DPRINT1("KeWaitForSingleObject(&ReadWait)\n");
249 (KeWaitForSingleObject
256 DPRINT1("Warning: Failed to wait for synchronous IRP\n");
262 DPRINT("Paging IO Done: %08x\n", ReadStatus
->Status
);
263 return ReadStatus
->Status
;
266 extern KEVENT MpwThreadEvent
;
267 FAST_MUTEX MiWriteMutex
;
272 (PFILE_OBJECT FileObject
,
273 PLARGE_INTEGER FileOffset
,
281 IO_STATUS_BLOCK Iosb
;
283 PVOID PageBuffer
= ExAllocatePool(NonPagedPool
, PAGE_SIZE
);
285 if (!PageBuffer
) return STATUS_NO_MEMORY
;
287 OldIrql
= KfRaiseIrql(DISPATCH_LEVEL
);
288 Hyperspace
= MmCreateHyperspaceMapping(Page
);
289 RtlCopyMemory(PageBuffer
, Hyperspace
, PAGE_SIZE
);
290 MmDeleteHyperspaceMapping(Hyperspace
);
291 KfLowerIrql(OldIrql
);
293 DPRINT1("MiWriteBackPage(%wZ,%08x%08x,%s:%d)\n", &FileObject
->FileName
, FileOffset
->u
.HighPart
, FileOffset
->u
.LowPart
, File
, Line
);
294 Status
= MiSimpleWrite
301 ExFreePool(PageBuffer
);
303 if (!NT_SUCCESS(Status
))
305 DPRINT1("MiSimpleWrite failed (%x)\n", Status
);