VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp@ 24287

Last change on this file since 24287 was 23610, checked in by vboxsync, 15 years ago

IPRT,VMM,SUPDrv,VBGLR0: Added a parameter to RTR0MemObjLockUser/Kernel that indicates read/write intent so we can correctly lock readonly memory on Windows and OS/2. (Guest property strings, see #4238.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 18.1 KB
Line 
1/* $Id: memobj-r0drv-os2.cpp 23610 2009-10-07 21:22:10Z vboxsync $ */
2/** @file
3 * IPRT - Ring-0 Memory Objects, OS/2.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-os2-kernel.h"
36
37#include <iprt/memobj.h>
38#include <iprt/mem.h>
39#include <iprt/err.h>
40#include <iprt/assert.h>
41#include <iprt/log.h>
42#include <iprt/param.h>
43#include <iprt/process.h>
44#include "internal/memobj.h"
45
46
47/*******************************************************************************
48* Structures and Typedefs *
49*******************************************************************************/
50/**
51 * The OS/2 version of the memory object structure.
52 */
53typedef struct RTR0MEMOBJDARWIN
54{
55 /** The core structure. */
56 RTR0MEMOBJINTERNAL Core;
57 /** Lock for the ring-3 / ring-0 pinned objectes.
58 * This member might not be allocated for some object types. */
59 KernVMLock_t Lock;
60 /** Array of physical pages.
61 * This array can be 0 in length for some object types. */
62 KernPageList_t aPages[1];
63} RTR0MEMOBJOS2, *PRTR0MEMOBJOS2;
64
65
66/*******************************************************************************
67* Internal Functions *
68*******************************************************************************/
69static void rtR0MemObjFixPageList(KernPageList_t *paPages, ULONG cPages, ULONG cPagesRet);
70
71
72int rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
73{
74 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem;
75 int rc;
76
77 switch (pMemOs2->Core.enmType)
78 {
79 case RTR0MEMOBJTYPE_PHYS_NC:
80 AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
81 return VERR_INTERNAL_ERROR;
82 break;
83
84 case RTR0MEMOBJTYPE_PHYS:
85 if (!pMemOs2->Core.pv)
86 break;
87
88 case RTR0MEMOBJTYPE_MAPPING:
89 if (pMemOs2->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)
90 break;
91
92 /* fall thru */
93 case RTR0MEMOBJTYPE_PAGE:
94 case RTR0MEMOBJTYPE_LOW:
95 case RTR0MEMOBJTYPE_CONT:
96 rc = KernVMFree(pMemOs2->Core.pv);
97 AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemOs2->Core.enmType, pMemOs2->Core.pv, pMemOs2->Core.cb));
98 break;
99
100 case RTR0MEMOBJTYPE_LOCK:
101 rc = KernVMUnlock(&pMemOs2->Lock);
102 AssertMsg(!rc, ("rc=%d\n", rc));
103 break;
104
105 case RTR0MEMOBJTYPE_RES_VIRT:
106 default:
107 AssertMsgFailed(("enmType=%d\n", pMemOs2->Core.enmType));
108 return VERR_INTERNAL_ERROR;
109 }
110
111 return VINF_SUCCESS;
112}
113
114
115int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
116{
117 NOREF(fExecutable);
118
119 /* create the object. */
120 const ULONG cPages = cb >> PAGE_SHIFT;
121 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_PAGE, NULL, cb);
122 if (!pMemOs2)
123 return VERR_NO_MEMORY;
124
125 /* do the allocation. */
126 int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemOs2->Core.pv, (PPVOID)-1, NULL);
127 if (!rc)
128 {
129 ULONG cPagesRet = cPages;
130 rc = KernLinToPageList(pMemOs2->Core.pv, cb, &pMemOs2->aPages[0], &cPagesRet);
131 if (!rc)
132 {
133 rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
134 *ppMem = &pMemOs2->Core;
135 return VINF_SUCCESS;
136 }
137 KernVMFree(pMemOs2->Core.pv);
138 }
139 rtR0MemObjDelete(&pMemOs2->Core);
140 return RTErrConvertFromOS2(rc);
141}
142
143
144int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
145{
146 NOREF(fExecutable);
147
148 /* create the object. */
149 const ULONG cPages = cb >> PAGE_SHIFT;
150 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOW, NULL, cb);
151 if (!pMemOs2)
152 return VERR_NO_MEMORY;
153
154 /* do the allocation. */
155 int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemOs2->Core.pv, (PPVOID)-1, NULL);
156 if (!rc)
157 {
158 ULONG cPagesRet = cPages;
159 rc = KernLinToPageList(pMemOs2->Core.pv, cb, &pMemOs2->aPages[0], &cPagesRet);
160 if (!rc)
161 {
162 rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
163 *ppMem = &pMemOs2->Core;
164 return VINF_SUCCESS;
165 }
166 KernVMFree(pMemOs2->Core.pv);
167 }
168 rtR0MemObjDelete(&pMemOs2->Core);
169 return RTErrConvertFromOS2(rc);
170}
171
172
173int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
174{
175 NOREF(fExecutable);
176
177 /* create the object. */
178 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb);
179 if (!pMemOs2)
180 return VERR_NO_MEMORY;
181
182 /* do the allocation. */
183 ULONG ulPhys = ~0UL;
184 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
185 if (!rc)
186 {
187 Assert(ulPhys != ~0UL);
188 pMemOs2->Core.u.Cont.Phys = ulPhys;
189 *ppMem = &pMemOs2->Core;
190 return VINF_SUCCESS;
191 }
192 rtR0MemObjDelete(&pMemOs2->Core);
193 return RTErrConvertFromOS2(rc);
194}
195
196
197int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
198{
199 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
200
201 /* create the object. */
202 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
203 if (!pMemOs2)
204 return VERR_NO_MEMORY;
205
206 /* do the allocation. */
207 ULONG ulPhys = ~0UL;
208 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
209 if (!rc)
210 {
211 Assert(ulPhys != ~0UL);
212 pMemOs2->Core.u.Phys.fAllocated = true;
213 pMemOs2->Core.u.Phys.PhysBase = ulPhys;
214 *ppMem = &pMemOs2->Core;
215 return VINF_SUCCESS;
216 }
217 rtR0MemObjDelete(&pMemOs2->Core);
218 return RTErrConvertFromOS2(rc);
219}
220
221
222int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
223{
224 /** @todo rtR0MemObjNativeAllocPhys / darwin. */
225 return rtR0MemObjNativeAllocPhys(ppMem, cb, PhysHighest);
226}
227
228
229int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
230{
231 /* create the object. */
232 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
233 if (!pMemOs2)
234 return VERR_NO_MEMORY;
235
236 /* there is no allocation here, right? it needs to be mapped somewhere first. */
237 pMemOs2->Core.u.Phys.fAllocated = false;
238 pMemOs2->Core.u.Phys.PhysBase = Phys;
239 *ppMem = &pMemOs2->Core;
240 return VINF_SUCCESS;
241}
242
243
244int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
245{
246 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
247
248 /* create the object. */
249 const ULONG cPages = cb >> PAGE_SHIFT;
250 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
251 if (!pMemOs2)
252 return VERR_NO_MEMORY;
253
254 /* lock it. */
255 ULONG cPagesRet = cPages;
256 int rc = KernVMLock(VMDHL_LONG | (fAccess & RTMEM_PROT_WRITE ? VMDHL_WRITE : 0),
257 (void *)R3Ptr, cb, &pMemOs2->Lock, &pMemOs2->aPages[0], &cPagesRet);
258 if (!rc)
259 {
260 rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
261 Assert(cb == pMemOs2->Core.cb);
262 Assert(R3Ptr == (RTR3PTR)pMemOs2->Core.pv);
263 pMemOs2->Core.u.Lock.R0Process = R0Process;
264 *ppMem = &pMemOs2->Core;
265 return VINF_SUCCESS;
266 }
267 rtR0MemObjDelete(&pMemOs2->Core);
268 return RTErrConvertFromOS2(rc);
269}
270
271
272int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
273{
274 /* create the object. */
275 const ULONG cPages = cb >> PAGE_SHIFT;
276 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);
277 if (!pMemOs2)
278 return VERR_NO_MEMORY;
279
280 /* lock it. */
281 ULONG cPagesRet = cPages;
282 int rc = KernVMLock(VMDHL_LONG | (fAccess & RTMEM_PROT_WRITE ? VMDHL_WRITE : 0),
283 pv, cb, &pMemOs2->Lock, &pMemOs2->aPages[0], &cPagesRet);
284 if (!rc)
285 {
286 rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
287 pMemOs2->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
288 *ppMem = &pMemOs2->Core;
289 return VINF_SUCCESS;
290 }
291 rtR0MemObjDelete(&pMemOs2->Core);
292 return RTErrConvertFromOS2(rc);
293}
294
295
296int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
297{
298 return VERR_NOT_IMPLEMENTED;
299}
300
301
302int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
303{
304 return VERR_NOT_IMPLEMENTED;
305}
306
307
308int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
309 unsigned fProt, size_t offSub, size_t cbSub)
310{
311 AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED);
312 AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
313
314 /*
315 * Check that the specified alignment is supported.
316 */
317 if (uAlignment > PAGE_SIZE)
318 return VERR_NOT_SUPPORTED;
319
320
321/** @todo finish the implementation. */
322
323 int rc;
324 void *pvR0 = NULL;
325 PRTR0MEMOBJOS2 pMemToMapOs2 = (PRTR0MEMOBJOS2)pMemToMap;
326 switch (pMemToMapOs2->Core.enmType)
327 {
328 /*
329 * These has kernel mappings.
330 */
331 case RTR0MEMOBJTYPE_PAGE:
332 case RTR0MEMOBJTYPE_LOW:
333 case RTR0MEMOBJTYPE_CONT:
334 pvR0 = pMemToMapOs2->Core.pv;
335 break;
336
337 case RTR0MEMOBJTYPE_PHYS:
338 pvR0 = pMemToMapOs2->Core.pv;
339 if (!pvR0)
340 {
341 /* no ring-0 mapping, so allocate a mapping in the process. */
342 AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);
343 Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
344 ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
345 rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS, &pvR0, (PPVOID)&ulPhys, NULL);
346 if (rc)
347 return RTErrConvertFromOS2(rc);
348 pMemToMapOs2->Core.pv = pvR0;
349 }
350 break;
351
352 case RTR0MEMOBJTYPE_PHYS_NC:
353 AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
354 return VERR_NOT_IMPLEMENTED;
355 break;
356
357 case RTR0MEMOBJTYPE_LOCK:
358 if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
359 return VERR_NOT_SUPPORTED; /** @todo implement this... */
360 pvR0 = pMemToMapOs2->Core.pv;
361 break;
362
363 case RTR0MEMOBJTYPE_RES_VIRT:
364 case RTR0MEMOBJTYPE_MAPPING:
365 default:
366 AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
367 return VERR_INTERNAL_ERROR;
368 }
369
370 /*
371 * Create a dummy mapping object for it.
372 *
373 * All mappings are read/write/execute in OS/2 and there isn't
374 * any cache options, so sharing is ok. And the main memory object
375 * isn't actually freed until all the mappings have been freed up
376 * (reference counting).
377 */
378 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);
379 if (pMemOs2)
380 {
381 pMemOs2->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
382 *ppMem = &pMemOs2->Core;
383 return VINF_SUCCESS;
384 }
385 return VERR_NO_MEMORY;
386}
387
388
389int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
390{
391 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
392 AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
393 if (uAlignment > PAGE_SIZE)
394 return VERR_NOT_SUPPORTED;
395
396 int rc;
397 void *pvR0;
398 void *pvR3 = NULL;
399 PRTR0MEMOBJOS2 pMemToMapOs2 = (PRTR0MEMOBJOS2)pMemToMap;
400 switch (pMemToMapOs2->Core.enmType)
401 {
402 /*
403 * These has kernel mappings.
404 */
405 case RTR0MEMOBJTYPE_PAGE:
406 case RTR0MEMOBJTYPE_LOW:
407 case RTR0MEMOBJTYPE_CONT:
408 pvR0 = pMemToMapOs2->Core.pv;
409 break;
410
411 case RTR0MEMOBJTYPE_PHYS:
412 pvR0 = pMemToMapOs2->Core.pv;
413#if 0/* this is wrong. */
414 if (!pvR0)
415 {
416 /* no ring-0 mapping, so allocate a mapping in the process. */
417 AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);
418 Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
419 ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
420 rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS | VMDHA_PROCESS, &pvR3, (PPVOID)&ulPhys, NULL);
421 if (rc)
422 return RTErrConvertFromOS2(rc);
423 }
424 break;
425#endif
426 return VERR_NOT_SUPPORTED;
427
428 case RTR0MEMOBJTYPE_PHYS_NC:
429 AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
430 return VERR_NOT_IMPLEMENTED;
431 break;
432
433 case RTR0MEMOBJTYPE_LOCK:
434 if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
435 return VERR_NOT_SUPPORTED; /** @todo implement this... */
436 pvR0 = pMemToMapOs2->Core.pv;
437 break;
438
439 case RTR0MEMOBJTYPE_RES_VIRT:
440 case RTR0MEMOBJTYPE_MAPPING:
441 default:
442 AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
443 return VERR_INTERNAL_ERROR;
444 }
445
446 /*
447 * Map the ring-0 memory into the current process.
448 */
449 if (!pvR3)
450 {
451 Assert(pvR0);
452 ULONG flFlags = 0;
453 if (uAlignment == PAGE_SIZE)
454 flFlags |= VMDHGP_4MB;
455 if (fProt & RTMEM_PROT_WRITE)
456 flFlags |= VMDHGP_WRITE;
457 rc = RTR0Os2DHVMGlobalToProcess(flFlags, pvR0, pMemToMapOs2->Core.cb, &pvR3);
458 if (rc)
459 return RTErrConvertFromOS2(rc);
460 }
461 Assert(pvR3);
462
463 /*
464 * Create a mapping object for it.
465 */
466 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR3, pMemToMapOs2->Core.cb);
467 if (pMemOs2)
468 {
469 Assert(pMemOs2->Core.pv == pvR3);
470 pMemOs2->Core.u.Mapping.R0Process = R0Process;
471 *ppMem = &pMemOs2->Core;
472 return VINF_SUCCESS;
473 }
474 KernVMFree(pvR3);
475 return VERR_NO_MEMORY;
476}
477
478
479int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
480{
481 NOREF(pMem);
482 NOREF(offSub);
483 NOREF(cbSub);
484 NOREF(fProt);
485 return VERR_NOT_SUPPORTED;
486}
487
488
489RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
490{
491 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem;
492
493 switch (pMemOs2->Core.enmType)
494 {
495 case RTR0MEMOBJTYPE_PAGE:
496 case RTR0MEMOBJTYPE_LOW:
497 case RTR0MEMOBJTYPE_LOCK:
498 case RTR0MEMOBJTYPE_PHYS_NC:
499 return pMemOs2->aPages[iPage].Addr;
500
501 case RTR0MEMOBJTYPE_CONT:
502 return pMemOs2->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
503
504 case RTR0MEMOBJTYPE_PHYS:
505 return pMemOs2->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);
506
507 case RTR0MEMOBJTYPE_RES_VIRT:
508 case RTR0MEMOBJTYPE_MAPPING:
509 default:
510 return NIL_RTHCPHYS;
511 }
512}
513
514
515/**
516 * Expands the page list so we can index pages directly.
517 *
518 * @param paPages The page list array to fix.
519 * @param cPages The number of pages that's supposed to go into the list.
520 * @param cPagesRet The actual number of pages in the list.
521 */
522static void rtR0MemObjFixPageList(KernPageList_t *paPages, ULONG cPages, ULONG cPagesRet)
523{
524 Assert(cPages >= cPagesRet);
525 if (cPages != cPagesRet)
526 {
527 ULONG iIn = cPagesRet;
528 ULONG iOut = cPages;
529 do
530 {
531 iIn--;
532 iOut--;
533 Assert(iIn <= iOut);
534
535 KernPageList_t Page = paPages[iIn];
536 Assert(!(Page.Addr & PAGE_OFFSET_MASK));
537 Assert(Page.Size == RT_ALIGN_Z(Page.Size, PAGE_SIZE));
538
539 if (Page.Size > PAGE_SIZE)
540 {
541 do
542 {
543 Page.Size -= PAGE_SIZE;
544 paPages[iOut].Addr = Page.Addr + Page.Size;
545 paPages[iOut].Size = PAGE_SIZE;
546 iOut--;
547 } while (Page.Size > PAGE_SIZE);
548 }
549
550 paPages[iOut].Addr = Page.Addr;
551 paPages[iOut].Size = PAGE_SIZE;
552 } while ( iIn != iOut
553 && iIn > 0);
554 }
555}
556
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette