VirtualBox

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

Last change on this file since 91478 was 91478, checked in by vboxsync, 3 years ago

IPRT/memobj: Added pszTag to rtR0MemObjNew.

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