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 PMDL Mdl
= Irp
->MdlAddress
;
76 /* Unlock MDL Pages, page 167. */
77 DPRINT("MiSimpleReadComplete %x\n", Irp
);
80 DPRINT("MDL Unlock %x\n", Mdl
);
85 /* Check if there's an MDL */
86 while ((Mdl
= Irp
->MdlAddress
))
88 /* Clear all of them */
89 Irp
->MdlAddress
= Mdl
->Next
;
93 return STATUS_SUCCESS
;
99 (PFILE_OBJECT FileObject
,
100 PLARGE_INTEGER FileOffset
,
106 PIO_STATUS_BLOCK ReadStatus
)
111 PDEVICE_OBJECT DeviceObject
;
112 PIO_STACK_LOCATION IrpSp
;
119 DeviceObject
= MmGetDeviceObjectForFile(FileObject
);
120 ReadStatus
->Status
= STATUS_INTERNAL_ERROR
;
121 ReadStatus
->Information
= 0;
123 ASSERT(DeviceObject
);
126 ("PAGING READ: FileObject %x <%wZ> Offset %08x%08x Length %d\n",
128 &FileObject
->FileName
,
129 FileOffset
->HighPart
,
133 KeInitializeEvent(&ReadWait
, NotificationEvent
, FALSE
);
135 Irp
= IoBuildAsynchronousFsdRequest
145 return STATUS_NO_MEMORY
;
148 #ifndef __ROS_CMAKE__
149 Irp
->Flags
|= IRP_PAGING_IO
| IRP_SYNCHRONOUS_PAGING_IO
| IRP_NOCACHE
| IRP_SYNCHRONOUS_API
;
151 Irp
->Flags
|= (Paging
? IRP_PAGING_IO
| IRP_SYNCHRONOUS_PAGING_IO
| IRP_NOCACHE
: 0) | IRP_SYNCHRONOUS_API
;
154 Irp
->UserEvent
= &ReadWait
;
155 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
156 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
157 IrpSp
= IoGetNextIrpStackLocation(Irp
);
158 IrpSp
->Control
|= SL_INVOKE_ON_SUCCESS
| SL_INVOKE_ON_ERROR
;
159 IrpSp
->FileObject
= FileObject
;
160 IrpSp
->CompletionRoutine
= MiSimpleReadComplete
;
163 ObReferenceObject(FileObject
);
166 Status
= IoCallDriver(DeviceObject
, Irp
);
167 if (Status
== STATUS_PENDING
)
169 DPRINT1("KeWaitForSingleObject(&ReadWait)\n");
171 (KeWaitForSingleObject
178 DPRINT1("Warning: Failed to wait for synchronous IRP\n");
184 DPRINT("Paging IO Done: %08x\n", ReadStatus
->Status
);
186 ReadStatus
->Status
== STATUS_END_OF_FILE
?
187 STATUS_SUCCESS
: ReadStatus
->Status
;
194 (PFILE_OBJECT FileObject
,
195 PLARGE_INTEGER FileOffset
,
198 PIO_STATUS_BLOCK ReadStatus
,
205 PDEVICE_OBJECT DeviceObject
;
206 PIO_STACK_LOCATION IrpSp
;
213 ObReferenceObject(FileObject
);
214 DeviceObject
= MmGetDeviceObjectForFile(FileObject
);
215 ASSERT(DeviceObject
);
218 ("PAGING WRITE: FileObject %x Offset %x Length %d (%s:%d)\n",
225 KeInitializeEvent(&ReadWait
, NotificationEvent
, FALSE
);
227 Irp
= IoBuildAsynchronousFsdRequest
237 ObDereferenceObject(FileObject
);
238 return STATUS_NO_MEMORY
;
241 Irp
->Flags
= IRP_PAGING_IO
| IRP_SYNCHRONOUS_PAGING_IO
| IRP_NOCACHE
| IRP_SYNCHRONOUS_API
;
243 Irp
->UserEvent
= &ReadWait
;
244 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
245 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
246 IrpSp
= IoGetNextIrpStackLocation(Irp
);
247 IrpSp
->Control
|= SL_INVOKE_ON_SUCCESS
| SL_INVOKE_ON_ERROR
;
248 IrpSp
->FileObject
= FileObject
;
249 IrpSp
->CompletionRoutine
= MiSimpleReadComplete
;
251 DPRINT("Call Driver\n");
252 Status
= IoCallDriver(DeviceObject
, Irp
);
253 DPRINT("Status %x\n", Status
);
255 ObDereferenceObject(FileObject
);
257 if (Status
== STATUS_PENDING
)
259 DPRINT1("KeWaitForSingleObject(&ReadWait)\n");
261 (KeWaitForSingleObject
268 DPRINT1("Warning: Failed to wait for synchronous IRP\n");
274 DPRINT("Paging IO Done: %08x\n", ReadStatus
->Status
);
275 return ReadStatus
->Status
;
278 extern KEVENT MpwThreadEvent
;
279 FAST_MUTEX MiWriteMutex
;
284 (PFILE_OBJECT FileObject
,
285 PLARGE_INTEGER FileOffset
,
293 IO_STATUS_BLOCK Iosb
;
295 PVOID PageBuffer
= ExAllocatePool(NonPagedPool
, PAGE_SIZE
);
297 if (!PageBuffer
) return STATUS_NO_MEMORY
;
299 OldIrql
= KfRaiseIrql(DISPATCH_LEVEL
);
300 Hyperspace
= MmCreateHyperspaceMapping(Page
);
301 RtlCopyMemory(PageBuffer
, Hyperspace
, PAGE_SIZE
);
302 MmDeleteHyperspaceMapping(Hyperspace
);
303 KfLowerIrql(OldIrql
);
305 DPRINT1("MiWriteBackPage(%wZ,%08x%08x,%s:%d)\n", &FileObject
->FileName
, FileOffset
->u
.HighPart
, FileOffset
->u
.LowPart
, File
, Line
);
306 Status
= MiSimpleWrite
313 ExFreePool(PageBuffer
);
315 if (!NT_SUCCESS(Status
))
317 DPRINT1("MiSimpleWrite failed (%x)\n", Status
);