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 *****************************************************************/
52 #define DPRINTC DPRINT
57 (PMMSUPPORT AddressSpace
,
58 PMEMORY_AREA MemoryArea
,
59 PMM_REQUIRED_RESOURCES Required
)
62 NTSTATUS Status
= STATUS_SUCCESS
;
64 for (i
= 0; i
< Required
->Amount
; i
++)
66 DPRINTC("MiGetOnePage(%s:%d)\n", Required
->File
, Required
->Line
);
67 Status
= MmRequestPageMemoryConsumer(Required
->Consumer
, TRUE
, &Required
->Page
[i
]);
68 if (!NT_SUCCESS(Status
))
72 MmReleasePageMemoryConsumer(MC_CACHE
, Required
->Page
[i
-1]);
85 (PMMSUPPORT AddressSpace
,
86 PMEMORY_AREA MemoryArea
,
87 PMM_REQUIRED_RESOURCES RequiredResources
)
89 PFILE_OBJECT FileObject
= RequiredResources
->Context
;
90 PPFN_NUMBER Page
= &RequiredResources
->Page
[RequiredResources
->Offset
];
91 PLARGE_INTEGER FileOffset
= &RequiredResources
->FileOffset
;
96 PHYSICAL_ADDRESS BoundaryAddressMultiple
;
98 BoundaryAddressMultiple
.QuadPart
= 0;
101 ("Pulling page %08x%08x from %wZ to %x\n",
102 FileOffset
->u
.HighPart
, FileOffset
->u
.LowPart
,
103 &FileObject
->FileName
,
106 Status
= MmRequestPageMemoryConsumer(RequiredResources
->Consumer
, TRUE
, Page
);
107 if (!NT_SUCCESS(Status
))
109 DPRINT1("Status: %x\n", Status
);
113 MmLockAddressSpace(MmGetKernelAddressSpace());
114 Status
= MmCreateMemoryArea
115 (MmGetKernelAddressSpace(),
116 MEMORY_AREA_VIRTUAL_MEMORY
,
123 BoundaryAddressMultiple
);
125 DPRINT("Status %x, PageBuf %x\n", Status
, PageBuf
);
126 if (!NT_SUCCESS(Status
))
128 DPRINT1("STATUS_NO_MEMORY: %x\n", Status
);
129 MmUnlockAddressSpace(MmGetKernelAddressSpace());
130 MmReleasePageMemoryConsumer(MC_CACHE
, *Page
);
131 return STATUS_NO_MEMORY
;
134 Status
= MmCreateVirtualMapping(NULL
, PageBuf
, PAGE_READWRITE
, Page
, 1);
135 if (!NT_SUCCESS(Status
))
137 MmFreeMemoryArea(MmGetKernelAddressSpace(), TmpArea
, NULL
, NULL
);
138 MmUnlockAddressSpace(MmGetKernelAddressSpace());
139 MmReleasePageMemoryConsumer(MC_CACHE
, *Page
);
140 DPRINT1("Status: %x\n", Status
);
144 MmUnlockAddressSpace(MmGetKernelAddressSpace());
146 Status
= MiSimpleRead
150 RequiredResources
->Amount
,
153 ((PCHAR
)PageBuf
+RequiredResources
->Amount
,
154 PAGE_SIZE
-RequiredResources
->Amount
);
156 DPRINT("Read Status %x (Page %x)\n", Status
, *Page
);
158 MmLockAddressSpace(MmGetKernelAddressSpace());
159 MmFreeMemoryArea(MmGetKernelAddressSpace(), TmpArea
, NULL
, NULL
);
160 MmUnlockAddressSpace(MmGetKernelAddressSpace());
162 if (!NT_SUCCESS(Status
))
164 MmReleasePageMemoryConsumer(MC_CACHE
, *Page
);
165 DPRINT("Status: %x\n", Status
);
169 return STATUS_SUCCESS
;
174 MiChecksumPage(PFN_NUMBER Page
, BOOLEAN Lock
)
179 PULONG PageBuf
= NULL
;
180 PMEMORY_AREA TmpArea
;
181 PHYSICAL_ADDRESS BoundaryAddressMultiple
;
183 BoundaryAddressMultiple
.QuadPart
= 0;
185 if (Lock
) MmLockAddressSpace(MmGetKernelAddressSpace());
187 Status
= MmCreateMemoryArea
188 (MmGetKernelAddressSpace(),
189 MEMORY_AREA_VIRTUAL_MEMORY
,
196 BoundaryAddressMultiple
);
198 DPRINT("Status %x, PageBuf %x\n", Status
, PageBuf
);
199 if (!NT_SUCCESS(Status
))
201 DPRINT1("STATUS_NO_MEMORY: %x\n", Status
);
202 if (Lock
) MmUnlockAddressSpace(MmGetKernelAddressSpace());
206 Status
= MmCreateVirtualMapping(NULL
, PageBuf
, PAGE_READWRITE
, &Page
, 1);
207 if (!NT_SUCCESS(Status
))
209 MmFreeMemoryArea(MmGetKernelAddressSpace(), TmpArea
, NULL
, NULL
);
210 if (Lock
) MmUnlockAddressSpace(MmGetKernelAddressSpace());
211 DPRINT1("Status: %x\n", Status
);
215 for (i
= 0; i
< 1024; i
++) {
219 MmFreeMemoryArea(MmGetKernelAddressSpace(), TmpArea
, NULL
, NULL
);
220 if (Lock
) MmUnlockAddressSpace(MmGetKernelAddressSpace());
228 (PMMSUPPORT AddressSpace
,
229 PMEMORY_AREA MemoryArea
,
230 PMM_REQUIRED_RESOURCES Resources
)
234 Status
= MmRequestPageMemoryConsumer(Resources
->Consumer
, TRUE
, &Resources
->Page
[Resources
->Offset
]);
235 if (!NT_SUCCESS(Status
))
237 DPRINT1("MmRequestPageMemoryConsumer failed, status = %x\n", Status
);
241 Status
= MmReadFromSwapPage(Resources
->SwapEntry
, Resources
->Page
[Resources
->Offset
]);
242 if (!NT_SUCCESS(Status
))
244 DPRINT1("MmReadFromSwapPage failed, status = %x\n", Status
);
248 MmSetSavedSwapEntryPage(Resources
->Page
[Resources
->Offset
], Resources
->SwapEntry
);
250 DPRINT1("MiSwapInPage(%x,%x)\n", Resources
->Page
[Resources
->Offset
], Resources
->SwapEntry
);
258 (PMMSUPPORT AddressSpace
,
259 PMEMORY_AREA MemoryArea
,
260 PMM_REQUIRED_RESOURCES Required
)
262 DPRINT1("MiWriteFilePage(%x,%x)\n", Required
->Page
[Required
->Offset
], Required
->FileOffset
.LowPart
);
264 return MiWriteBackPage
266 &Required
->FileOffset
,
268 Required
->Page
[Required
->Offset
]);