VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c@ 41682

Last change on this file since 41682 was 41682, checked in by vboxsync, 13 years ago

Runtime/r0drv/solaris: Query PG_NORELOC support for large pages.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.2 KB
Line 
1/* $Id: memobj-r0drv-solaris.c 41682 2012-06-13 12:52:01Z vboxsync $ */
2/** @file
3 * IPRT - Ring-0 Memory Objects, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "the-solaris-kernel.h"
32#include "internal/iprt.h"
33#include <iprt/memobj.h>
34
35#include <iprt/asm.h>
36#include <iprt/assert.h>
37#include <iprt/err.h>
38#include <iprt/log.h>
39#include <iprt/mem.h>
40#include <iprt/param.h>
41#include <iprt/process.h>
42#include "internal/memobj.h"
43#include "memobj-r0drv-solaris.h"
44
45/*******************************************************************************
46* Defined Constants And Macros *
47*******************************************************************************/
48#define SOL_IS_KRNL_ADDR(vx) ((uintptr_t)(vx) >= kernelbase)
49
50
51/*******************************************************************************
52* Structures and Typedefs *
53*******************************************************************************/
54/**
55 * The Solaris version of the memory object structure.
56 */
57typedef struct RTR0MEMOBJSOL
58{
59 /** The core structure. */
60 RTR0MEMOBJINTERNAL Core;
61 /** Pointer to kernel memory cookie. */
62 ddi_umem_cookie_t Cookie;
63 /** Shadow locked pages. */
64 void *pvHandle;
65 /** Access during locking. */
66 int fAccess;
67 /** Set if large pages are involved in an RTR0MEMOBJTYPE_PHYS
68 * allocation. */
69 bool fLargePage;
70 /** Whether we have individual pages or a kernel-mapped virtual memory block in
71 * an RTR0MEMOBJTYPE_PHYS_NC allocation. */
72 bool fIndivPages;
73} RTR0MEMOBJSOL, *PRTR0MEMOBJSOL;
74
75
76/*******************************************************************************
77* Global Variables *
78*******************************************************************************/
79static vnode_t g_PageVnode;
80static kmutex_t g_OffsetMtx;
81static u_offset_t g_offPage;
82
83static vnode_t g_LargePageVnode;
84static kmutex_t g_LargePageOffsetMtx;
85static u_offset_t g_offLargePage;
86static bool g_fLargePageNoReloc;
87
88
89/**
90 * Returns the physical address for a virtual address.
91 *
92 * @param pv The virtual address.
93 *
94 * @returns The physical address corresponding to @a pv.
95 */
96static uint64_t rtR0MemObjSolVirtToPhys(void *pv)
97{
98 struct hat *pHat = NULL;
99 pfn_t PageFrameNum = 0;
100 uintptr_t uVirtAddr = (uintptr_t)pv;
101
102 if (SOL_IS_KRNL_ADDR(pv))
103 pHat = kas.a_hat;
104 else
105 {
106 proc_t *pProcess = (proc_t *)RTR0ProcHandleSelf();
107 AssertRelease(pProcess);
108 pHat = pProcess->p_as->a_hat;
109 }
110
111 PageFrameNum = hat_getpfnum(pHat, (caddr_t)(uVirtAddr & PAGEMASK));
112 AssertReleaseMsg(PageFrameNum != PFN_INVALID, ("rtR0MemObjSolVirtToPhys failed. pv=%p\n", pv));
113 return (((uint64_t)PageFrameNum << PAGE_SHIFT) | (uVirtAddr & PAGE_OFFSET_MASK));
114}
115
116
117/**
118 * Returns the physical address for a page.
119 *
120 * @param pPage Pointer to the page.
121 *
122 * @returns The physical address for a page.
123 */
124static inline uint64_t rtR0MemObjSolPagePhys(page_t *pPage)
125{
126 AssertPtr(pPage);
127 pfn_t PageFrameNum = page_pptonum(pPage);
128 AssertReleaseMsg(PageFrameNum != PFN_INVALID, ("rtR0MemObjSolPagePhys failed pPage=%p\n"));
129 return (uint64_t)PageFrameNum << PAGE_SHIFT;
130}
131
132
133/**
134 * Allocates one page.
135 *
136 * @param virtAddr The virtual address to which this page maybe mapped in
137 * the future.
138 *
139 * @returns Pointer to the allocated page, NULL on failure.
140 */
141static page_t *rtR0MemObjSolPageAlloc(caddr_t virtAddr)
142{
143 u_offset_t offPage;
144 seg_t KernelSeg;
145
146 mutex_enter(&g_OffsetMtx);
147 AssertCompileSize(u_offset_t, sizeof(uint64_t)); NOREF(RTASSERTVAR);
148 g_offPage = RT_ALIGN_64(g_offPage, PAGE_SIZE) + PAGE_SIZE;
149 offPage = g_offPage;
150 mutex_exit(&g_OffsetMtx);
151
152 KernelSeg.s_as = &kas;
153 page_t *pPage = page_create_va(&g_PageVnode, offPage, PAGE_SIZE, PG_WAIT | PG_NORELOC, &KernelSeg, virtAddr);
154 if (RT_LIKELY(pPage))
155 {
156 /*
157 * Lock this page into memory "long term" to prevent this page from being paged out
158 * when we drop the page lock temporarily (during free).
159 */
160 page_pp_lock(pPage, 0 /* COW */, 1 /* Kernel */);
161 page_io_unlock(pPage);
162 page_downgrade(pPage);
163 Assert(PAGE_LOCKED_SE(pPage, SE_SHARED));
164 }
165
166 return pPage;
167}
168
169
170/**
171 * Allocates physical, non-contiguous memory of pages.
172 *
173 * @param puPhys Where to store the physical address of first page. Optional,
174 * can be NULL.
175 * @param cb The size of the allocation.
176 *
177 * @return Array of allocated pages, NULL on failure.
178 */
179static page_t **rtR0MemObjSolPagesAlloc(uint64_t *puPhys, size_t cb)
180{
181 /*
182 * VM1:
183 * The page freelist and cachelist both hold pages that are not mapped into any address space.
184 * The cachelist is not really free pages but when memory is exhausted they'll be moved to the
185 * free lists, it's the total of the free+cache list that we see on the 'free' column in vmstat.
186 *
187 * VM2:
188 * @todo Document what happens behind the scenes in VM2 regarding the free and cachelist.
189 */
190
191 /*
192 * Non-pageable memory reservation request for _4K pages, don't sleep.
193 */
194 size_t cPages = (cb + PAGE_SIZE - 1) >> PAGE_SHIFT;
195 int rc = page_resv(cPages, KM_NOSLEEP);
196 if (rc)
197 {
198 size_t cbPages = cPages * sizeof(page_t *);
199 page_t **ppPages = kmem_zalloc(cbPages, KM_SLEEP);
200 if (RT_LIKELY(ppPages))
201 {
202 /*
203 * Get pages from kseg, the 'virtAddr' here is only for colouring but unfortunately
204 * we don't yet have the 'virtAddr' to which this memory may be mapped.
205 */
206 caddr_t virtAddr = 0;
207 for (size_t i = 0; i < cPages; i++, virtAddr += PAGE_SIZE)
208 {
209 /*
210 * Get a page from the free list locked exclusively. The page will be named (hashed in)
211 * and we rely on it during free. Downgrade the page to a shared lock to prevent the page
212 * from being relocated.
213 */
214 page_t *pPage = rtR0MemObjSolPageAlloc(virtAddr);
215 if (RT_UNLIKELY(!pPage))
216 {
217 /*
218 * No page found, release whatever pages we grabbed so far.
219 */
220 for (size_t k = 0; k < i; k++)
221 page_destroy(ppPages[k], 0 /* move it to the free list */);
222 kmem_free(ppPages, cbPages);
223 page_unresv(cPages);
224 return NULL;
225 }
226
227 ppPages[i] = pPage;
228 }
229
230 if (puPhys)
231 *puPhys = rtR0MemObjSolPagePhys(ppPages[0]);
232 return ppPages;
233 }
234
235 page_unresv(cPages);
236 }
237
238 return NULL;
239}
240
241
242/**
243 * Frees the allocates pages.
244 *
245 * @param ppPages Pointer to the page list.
246 * @param cbPages Size of the allocation.
247 */
248static void rtR0MemObjSolPagesFree(page_t **ppPages, size_t cb)
249{
250 size_t cPages = (cb + PAGE_SIZE - 1) >> PAGE_SHIFT;
251 size_t cbPages = cPages * sizeof(page_t *);
252 for (size_t iPage = 0; iPage < cPages; iPage++)
253 {
254 /*
255 * We need to exclusive lock the pages before freeing them.
256 */
257 page_t *pPage = ppPages[iPage];
258 u_offset_t offPage = pPage->p_offset;
259
260 int rc = page_tryupgrade(ppPages[iPage]);
261 if (!rc)
262 {
263 page_unlock(pPage);
264 page_t *pFoundPage = page_lookup(&g_PageVnode, offPage, SE_EXCL);
265
266 /*
267 * Since we allocated the pages as PG_NORELOC we should only get back the exact page always.
268 */
269 AssertReleaseMsg(pFoundPage == pPage, ("Page lookup failed %p:%llx returned %p, expected %p\n",
270 &g_PageVnode, offPage, pFoundPage, pPage));
271 }
272 Assert(PAGE_LOCKED_SE(pPage, SE_EXCL));
273 page_pp_unlock(pPage, 0 /* COW */, 1 /* Kernel */);
274 page_destroy(pPage, 0 /* move it to the free list */);
275 }
276 kmem_free(ppPages, cbPages);
277 page_unresv(cPages);
278}
279
280
281/**
282 * Allocates one large page.
283 *
284 * @param puPhys Where to store the physical address of the allocated
285 * page. Optional, can be NULL.
286 * @param cbLargePage Size of the large page.
287 *
288 * @returns Pointer to a list of pages that cover the large page, NULL on
289 * failure.
290 */
291static page_t **rtR0MemObjSolLargePageAlloc(uint64_t *puPhys, size_t cbLargePage)
292{
293 /*
294 * Check PG_NORELOC support for large pages. Using this helps prevent _1G page
295 * fragementation on systems that support it.
296 */
297 static bool fPageNoRelocChecked = false;
298 if (fPageNoRelocChecked == false)
299 {
300 fPageNoRelocChecked = true;
301 g_fLargePageNoReloc = false;
302 if ( g_pfnrtR0Sol_page_noreloc_supported
303 && g_pfnrtR0Sol_page_noreloc_supported(cbLargePage))
304 {
305 g_fLargePageNoReloc = true;
306 }
307 }
308
309 /*
310 * Non-pageable memory reservation request for _4K pages, don't sleep.
311 */
312 size_t cPages = (cbLargePage + PAGE_SIZE - 1) >> PAGE_SHIFT;
313 size_t cbPages = cPages * sizeof(page_t *);
314 u_offset_t offPage = 0;
315 int rc = page_resv(cPages, KM_NOSLEEP);
316 if (rc)
317 {
318 page_t **ppPages = kmem_zalloc(cbPages, KM_SLEEP);
319 if (RT_LIKELY(ppPages))
320 {
321 mutex_enter(&g_LargePageOffsetMtx);
322 AssertCompileSize(u_offset_t, sizeof(uint64_t)); NOREF(RTASSERTVAR);
323 g_offLargePage = RT_ALIGN_64(g_offLargePage, cbLargePage) + cbLargePage;
324 offPage = g_offLargePage;
325 mutex_exit(&g_LargePageOffsetMtx);
326
327 seg_t KernelSeg;
328 KernelSeg.s_as = &kas;
329 page_t *pRootPage = page_create_va_large(&g_LargePageVnode, offPage, cbLargePage,
330 PG_EXCL | (g_fLargePageNoReloc ? PG_NORELOC : 0), &KernelSeg,
331 0 /* vaddr */,NULL /* locality group */);
332 if (pRootPage)
333 {
334 /*
335 * Split it into sub-pages, downgrade each page to a shared lock to prevent page relocation.
336 */
337 page_t *pPageList = pRootPage;
338 for (size_t iPage = 0; iPage < cPages; iPage++)
339 {
340 page_t *pPage = pPageList;
341 AssertPtr(pPage);
342 AssertMsg(page_pptonum(pPage) == iPage + page_pptonum(pRootPage),
343 ("%p:%lx %lx+%lx\n", pPage, page_pptonum(pPage), iPage, page_pptonum(pRootPage)));
344 AssertMsg(pPage->p_szc == pRootPage->p_szc, ("Size code mismatch %p %d %d\n", pPage,
345 (int)pPage->p_szc, (int)pRootPage->p_szc));
346
347 /*
348 * Lock the page into memory "long term". This prevents callers of page_try_demote_pages() (such as the
349 * pageout scanner) from demoting the large page into smaller pages while we temporarily release the
350 * exclusive lock (during free). We pass "0, 1" since we've already accounted for availrmem during
351 * page_resv().
352 */
353 page_pp_lock(pPage, 0 /* COW */, 1 /* Kernel */);
354
355 page_sub(&pPageList, pPage);
356 page_io_unlock(pPage);
357 page_downgrade(pPage);
358 Assert(PAGE_LOCKED_SE(pPage, SE_SHARED));
359
360 ppPages[iPage] = pPage;
361 }
362 Assert(pPageList == NULL);
363 Assert(ppPages[0] == pRootPage);
364
365 uint64_t uPhys = rtR0MemObjSolPagePhys(pRootPage);
366 AssertMsg(!(uPhys & (cbLargePage - 1)), ("%llx %zx\n", uPhys, cbLargePage));
367 if (puPhys)
368 *puPhys = uPhys;
369 return ppPages;
370 }
371
372 /*
373 * Don't restore offPrev in case of failure (race condition), we have plenty of offset space.
374 * The offset must be unique (for the same vnode) or we'll encounter panics on page_create_va_large().
375 */
376 kmem_free(ppPages, cbPages);
377 }
378
379 page_unresv(cPages);
380 }
381 return NULL;
382}
383
384
385/**
386 * Frees the large page.
387 *
388 * @param ppPages Pointer to the list of small pages that cover the
389 * large page.
390 * @param cbLargePage Size of the allocation (i.e. size of the large
391 * page).
392 */
393static void rtR0MemObjSolLargePageFree(page_t **ppPages, size_t cbLargePage)
394{
395 Assert(ppPages);
396 Assert(cbLargePage > PAGE_SIZE);
397
398 bool fDemoted = false;
399 size_t cPages = (cbLargePage + PAGE_SIZE - 1) >> PAGE_SHIFT;
400 size_t cbPages = cPages * sizeof(page_t *);
401 page_t *pPageList = ppPages[0];
402
403 for (size_t iPage = 0; iPage < cPages; iPage++)
404 {
405 /*
406 * We need the pages exclusively locked, try upgrading the shared lock.
407 * If it fails, drop the shared page lock (cannot access any page_t members once this is done)
408 * and lookup the page from the page hash locking it exclusively.
409 */
410 page_t *pPage = ppPages[iPage];
411 u_offset_t offPage = pPage->p_offset;
412 int rc = page_tryupgrade(pPage);
413 if (!rc)
414 {
415 page_unlock(pPage);
416 page_t *pFoundPage = page_lookup(&g_LargePageVnode, offPage, SE_EXCL);
417 AssertRelease(pFoundPage);
418
419 if (g_fLargePageNoReloc)
420 {
421 /*
422 * This can only be guaranteed if PG_NORELOC is used while allocating the pages.
423 */
424 AssertReleaseMsg(pFoundPage == pPage,
425 ("lookup failed %p:%llu returned %p, expected %p\n", &g_LargePageVnode, offPage,
426 pFoundPage, pPage));
427 }
428
429 /*
430 * Check for page demotion (regardless of relocation). Some places in Solaris (e.g. VM1 page_retire())
431 * could possibly demote the large page to _4K pages between our call to page_unlock() and page_lookup().
432 */
433 if (page_get_pagecnt(pFoundPage->p_szc) == 1) /* Base size of only _4K associated with this page. */
434 fDemoted = true;
435 pPage = pFoundPage;
436 ppPages[iPage] = pFoundPage;
437 }
438 Assert(PAGE_LOCKED_SE(pPage, SE_EXCL));
439 page_pp_unlock(pPage, 0 /* COW */, 1 /* Kernel */);
440 }
441
442 if (fDemoted)
443 {
444 for (size_t iPage = 0; iPage < cPages; iPage++)
445 {
446 Assert(page_get_pagecnt(ppPages[iPage]->p_szc) == 1);
447 page_destroy(ppPages[iPage], 0 /* move it to the free list */);
448 }
449 }
450 else
451 {
452 /*
453 * Although we shred the adjacent pages in the linked list, page_destroy_pages works on
454 * adjacent pages via array increments. So this does indeed free all the pages.
455 */
456 AssertPtr(pPageList);
457 page_destroy_pages(pPageList);
458 }
459 kmem_free(ppPages, cbPages);
460 page_unresv(cPages);
461}
462
463
464/**
465 * Unmaps kernel/user-space mapped memory.
466 *
467 * @param pv Pointer to the mapped memory block.
468 * @param cb Size of the memory block.
469 */
470static void rtR0MemObjSolUnmap(void *pv, size_t cb)
471{
472 if (SOL_IS_KRNL_ADDR(pv))
473 {
474 hat_unload(kas.a_hat, pv, cb, HAT_UNLOAD | HAT_UNLOAD_UNLOCK);
475 vmem_free(heap_arena, pv, cb);
476 }
477 else
478 {
479 struct as *pAddrSpace = ((proc_t *)RTR0ProcHandleSelf())->p_as;
480 AssertPtr(pAddrSpace);
481 as_rangelock(pAddrSpace);
482 as_unmap(pAddrSpace, pv, cb);
483 as_rangeunlock(pAddrSpace);
484 }
485}
486
487
488/**
489 * Lock down memory mappings for a virtual address.
490 *
491 * @param pv Pointer to the memory to lock down.
492 * @param cb Size of the memory block.
493 * @param fAccess Page access rights (S_READ, S_WRITE, S_EXEC)
494 *
495 * @returns IPRT status code.
496 */
497static int rtR0MemObjSolLock(void *pv, size_t cb, int fPageAccess)
498{
499 /*
500 * Kernel memory mappings on x86/amd64 are always locked, only handle user-space memory.
501 */
502 if (!SOL_IS_KRNL_ADDR(pv))
503 {
504 proc_t *pProc = (proc_t *)RTR0ProcHandleSelf();
505 AssertPtr(pProc);
506 faultcode_t rc = as_fault(pProc->p_as->a_hat, pProc->p_as, (caddr_t)pv, cb, F_SOFTLOCK, fPageAccess);
507 if (rc)
508 {
509 LogRel(("rtR0MemObjSolLock failed for pv=%pv cb=%lx fPageAccess=%d rc=%d\n", pv, cb, fPageAccess, rc));
510 return VERR_LOCK_FAILED;
511 }
512 }
513 return VINF_SUCCESS;
514}
515
516
517/**
518 * Unlock memory mappings for a virtual address.
519 *
520 * @param pv Pointer to the locked memory.
521 * @param cb Size of the memory block.
522 * @param fPageAccess Page access rights (S_READ, S_WRITE, S_EXEC).
523 */
524static void rtR0MemObjSolUnlock(void *pv, size_t cb, int fPageAccess)
525{
526 if (!SOL_IS_KRNL_ADDR(pv))
527 {
528 proc_t *pProcess = (proc_t *)RTR0ProcHandleSelf();
529 AssertPtr(pProcess);
530 as_fault(pProcess->p_as->a_hat, pProcess->p_as, (caddr_t)pv, cb, F_SOFTUNLOCK, fPageAccess);
531 }
532}
533
534
535/**
536 * Maps a list of physical pages into user address space.
537 *
538 * @param pVirtAddr Where to store the virtual address of the mapping.
539 * @param fPageAccess Page access rights (PROT_READ, PROT_WRITE,
540 * PROT_EXEC)
541 * @param paPhysAddrs Array of physical addresses to pages.
542 * @param cb Size of memory being mapped.
543 *
544 * @returns IPRT status code.
545 */
546static int rtR0MemObjSolUserMap(caddr_t *pVirtAddr, unsigned fPageAccess, uint64_t *paPhysAddrs, size_t cb, size_t cbPageSize)
547{
548 struct as *pAddrSpace = ((proc_t *)RTR0ProcHandleSelf())->p_as;
549 int rc = VERR_INTERNAL_ERROR;
550 SEGVBOX_CRARGS Args;
551
552 Args.paPhysAddrs = paPhysAddrs;
553 Args.fPageAccess = fPageAccess;
554 Args.cbPageSize = cbPageSize;
555
556 as_rangelock(pAddrSpace);
557 map_addr(pVirtAddr, cb, 0 /* offset */, 0 /* vacalign */, MAP_SHARED);
558 if (*pVirtAddr != NULL)
559 rc = as_map(pAddrSpace, *pVirtAddr, cb, rtR0SegVBoxSolCreate, &Args);
560 else
561 rc = ENOMEM;
562 as_rangeunlock(pAddrSpace);
563
564 return RTErrConvertFromErrno(rc);
565}
566
567
568DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
569{
570 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)pMem;
571
572 switch (pMemSolaris->Core.enmType)
573 {
574 case RTR0MEMOBJTYPE_LOW:
575 rtR0SolMemFree(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
576 break;
577
578 case RTR0MEMOBJTYPE_PHYS:
579 if (pMemSolaris->Core.u.Phys.fAllocated)
580 {
581 if (pMemSolaris->fLargePage)
582 rtR0MemObjSolLargePageFree(pMemSolaris->pvHandle, pMemSolaris->Core.cb);
583 else
584 rtR0SolMemFree(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
585 }
586 break;
587
588 case RTR0MEMOBJTYPE_PHYS_NC:
589 if (pMemSolaris->fIndivPages)
590 rtR0MemObjSolPagesFree(pMemSolaris->pvHandle, pMemSolaris->Core.cb);
591 else
592 rtR0SolMemFree(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
593 break;
594
595 case RTR0MEMOBJTYPE_PAGE:
596 ddi_umem_free(pMemSolaris->Cookie);
597 break;
598
599 case RTR0MEMOBJTYPE_LOCK:
600 rtR0MemObjSolUnlock(pMemSolaris->Core.pv, pMemSolaris->Core.cb, pMemSolaris->fAccess);
601 break;
602
603 case RTR0MEMOBJTYPE_MAPPING:
604 rtR0MemObjSolUnmap(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
605 break;
606
607 case RTR0MEMOBJTYPE_RES_VIRT:
608 {
609 if (pMemSolaris->Core.u.ResVirt.R0Process == NIL_RTR0PROCESS)
610 vmem_xfree(heap_arena, pMemSolaris->Core.pv, pMemSolaris->Core.cb);
611 else
612 AssertFailed();
613 break;
614 }
615
616 case RTR0MEMOBJTYPE_CONT: /* we don't use this type here. */
617 default:
618 AssertMsgFailed(("enmType=%d\n", pMemSolaris->Core.enmType));
619 return VERR_INTERNAL_ERROR;
620 }
621
622 return VINF_SUCCESS;
623}
624
625
626DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
627{
628 /* Create the object. */
629 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb);
630 if (RT_UNLIKELY(!pMemSolaris))
631 return VERR_NO_MEMORY;
632
633 void *pvMem = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
634 if (RT_UNLIKELY(!pvMem))
635 {
636 rtR0MemObjDelete(&pMemSolaris->Core);
637 return VERR_NO_PAGE_MEMORY;
638 }
639
640 pMemSolaris->Core.pv = pvMem;
641 pMemSolaris->pvHandle = NULL;
642 *ppMem = &pMemSolaris->Core;
643 return VINF_SUCCESS;
644}
645
646
647DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
648{
649 NOREF(fExecutable);
650
651 /* Create the object */
652 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOW, NULL, cb);
653 if (!pMemSolaris)
654 return VERR_NO_MEMORY;
655
656 /* Allocate physically low page-aligned memory. */
657 uint64_t uPhysHi = _4G - 1;
658 void *pvMem = rtR0SolMemAlloc(uPhysHi, NULL /* puPhys */, cb, PAGE_SIZE, false /* fContig */);
659 if (RT_UNLIKELY(!pvMem))
660 {
661 rtR0MemObjDelete(&pMemSolaris->Core);
662 return VERR_NO_LOW_MEMORY;
663 }
664 pMemSolaris->Core.pv = pvMem;
665 pMemSolaris->pvHandle = NULL;
666 *ppMem = &pMemSolaris->Core;
667 return VINF_SUCCESS;
668}
669
670
671DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
672{
673 NOREF(fExecutable);
674 return rtR0MemObjNativeAllocPhys(ppMem, cb, _4G - 1, PAGE_SIZE /* alignment */);
675}
676
677
678DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
679{
680#if HC_ARCH_BITS == 64
681 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS_NC, NULL, cb);
682 if (RT_UNLIKELY(!pMemSolaris))
683 return VERR_NO_MEMORY;
684
685 if (PhysHighest == NIL_RTHCPHYS)
686 {
687 uint64_t PhysAddr = UINT64_MAX;
688 void *pvPages = rtR0MemObjSolPagesAlloc(&PhysAddr, cb);
689 if (!pvPages)
690 {
691 LogRel(("rtR0MemObjNativeAllocPhysNC: rtR0MemObjSolPagesAlloc failed for cb=%u.\n", cb));
692 rtR0MemObjDelete(&pMemSolaris->Core);
693 return VERR_NO_MEMORY;
694 }
695 Assert(PhysAddr != UINT64_MAX);
696 Assert(!(PhysAddr & PAGE_OFFSET_MASK));
697
698 pMemSolaris->Core.pv = NULL;
699 pMemSolaris->pvHandle = pvPages;
700 pMemSolaris->fIndivPages = true;
701 *ppMem = &pMemSolaris->Core;
702 return VINF_SUCCESS;
703 }
704 else
705 {
706 /*
707 * If we must satisfy an upper limit constraint, it isn't feasible to grab individual pages.
708 * We fall back to using contig_alloc().
709 */
710 uint64_t PhysAddr = UINT64_MAX;
711 void *pvMem = rtR0SolMemAlloc(PhysHighest, &PhysAddr, cb, PAGE_SIZE, false /* fContig */);
712 if (!pvMem)
713 {
714 LogRel(("rtR0MemObjNativeAllocPhysNC: rtR0SolMemAlloc failed for cb=%u PhysHighest=%RHp.\n", cb, PhysHighest));
715 rtR0MemObjDelete(&pMemSolaris->Core);
716 return VERR_NO_MEMORY;
717 }
718 Assert(PhysAddr != UINT64_MAX);
719 Assert(!(PhysAddr & PAGE_OFFSET_MASK));
720
721 pMemSolaris->Core.pv = pvMem;
722 pMemSolaris->pvHandle = NULL;
723 pMemSolaris->fIndivPages = false;
724 *ppMem = &pMemSolaris->Core;
725 return VINF_SUCCESS;
726 }
727
728#else /* 32 bit: */
729 return VERR_NOT_SUPPORTED; /* see the RTR0MemObjAllocPhysNC specs */
730#endif
731}
732
733
734DECLHIDDEN(int) rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
735{
736 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);
737
738 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
739 if (RT_UNLIKELY(!pMemSolaris))
740 return VERR_NO_MEMORY;
741
742 /*
743 * Allocating one large page gets special treatment.
744 */
745 static uint32_t s_cbLargePage = UINT32_MAX;
746 if (s_cbLargePage == UINT32_MAX)
747 {
748 if (page_num_pagesizes() > 1)
749 ASMAtomicWriteU32(&s_cbLargePage, page_get_pagesize(1)); /* Page-size code 1 maps to _2M on Solaris x86/amd64. */
750 else
751 ASMAtomicWriteU32(&s_cbLargePage, 0);
752 }
753 uint64_t PhysAddr;
754 if ( cb == s_cbLargePage
755 && cb == uAlignment
756 && PhysHighest == NIL_RTHCPHYS)
757 {
758 /*
759 * Allocate one large page (backed by physically contiguous memory).
760 */
761 void *pvPages = rtR0MemObjSolLargePageAlloc(&PhysAddr, cb);
762 if (RT_LIKELY(pvPages))
763 {
764 AssertMsg(!(PhysAddr & (cb - 1)), ("%RHp\n", PhysAddr));
765 pMemSolaris->Core.pv = NULL;
766 pMemSolaris->Core.u.Phys.PhysBase = PhysAddr;
767 pMemSolaris->Core.u.Phys.fAllocated = true;
768 pMemSolaris->pvHandle = pvPages;
769 pMemSolaris->fLargePage = true;
770
771 *ppMem = &pMemSolaris->Core;
772 return VINF_SUCCESS;
773 }
774 }
775 else
776 {
777 /*
778 * Allocate physically contiguous memory aligned as specified.
779 * Note: contig_alloc() can be agonizingly slow for large (e.g. >= _2M) contiguous allocations.
780 * So we shouldn't ideally be in this path for large-page allocations. .
781 */
782 AssertCompile(NIL_RTHCPHYS == UINT64_MAX); NOREF(RTASSERTVAR);
783 PhysAddr = PhysHighest;
784 void *pvMem = rtR0SolMemAlloc(PhysHighest, &PhysAddr, cb, uAlignment, true /* fContig */);
785 if (RT_LIKELY(pvMem))
786 {
787 Assert(!(PhysAddr & PAGE_OFFSET_MASK));
788 Assert(PhysAddr < PhysHighest);
789 Assert(PhysAddr + cb <= PhysHighest);
790
791 pMemSolaris->Core.pv = pvMem;
792 pMemSolaris->Core.u.Phys.PhysBase = PhysAddr;
793 pMemSolaris->Core.u.Phys.fAllocated = true;
794 pMemSolaris->pvHandle = NULL;
795 pMemSolaris->fLargePage = false;
796
797 *ppMem = &pMemSolaris->Core;
798 return VINF_SUCCESS;
799 }
800 }
801 rtR0MemObjDelete(&pMemSolaris->Core);
802 return VERR_NO_CONT_MEMORY;
803}
804
805
806DECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy)
807{
808 AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED);
809
810 /* Create the object. */
811 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
812 if (!pMemSolaris)
813 return VERR_NO_MEMORY;
814
815 /* There is no allocation here, it needs to be mapped somewhere first. */
816 pMemSolaris->Core.u.Phys.fAllocated = false;
817 pMemSolaris->Core.u.Phys.PhysBase = Phys;
818 pMemSolaris->Core.u.Phys.uCachePolicy = uCachePolicy;
819 *ppMem = &pMemSolaris->Core;
820 return VINF_SUCCESS;
821}
822
823
824DECLHIDDEN(int) rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess,
825 RTR0PROCESS R0Process)
826{
827 AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_INVALID_PARAMETER);
828 NOREF(fAccess);
829
830 /* Create the locking object */
831 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
832 if (!pMemSolaris)
833 return VERR_NO_MEMORY;
834
835 /* Lock down user pages. */
836 int fPageAccess = S_READ;
837 if (fAccess & RTMEM_PROT_WRITE)
838 fPageAccess = S_WRITE;
839 if (fAccess & RTMEM_PROT_EXEC)
840 fPageAccess = S_EXEC;
841 int rc = rtR0MemObjSolLock((void *)R3Ptr, cb, fPageAccess);
842 if (RT_FAILURE(rc))
843 {
844 LogRel(("rtR0MemObjNativeLockUser: rtR0MemObjSolLock failed rc=%d\n", rc));
845 rtR0MemObjDelete(&pMemSolaris->Core);
846 return rc;
847 }
848
849 /* Fill in the object attributes and return successfully. */
850 pMemSolaris->Core.u.Lock.R0Process = R0Process;
851 pMemSolaris->pvHandle = NULL;
852 pMemSolaris->fAccess = fPageAccess;
853 *ppMem = &pMemSolaris->Core;
854 return VINF_SUCCESS;
855}
856
857
858DECLHIDDEN(int) rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
859{
860 NOREF(fAccess);
861
862 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
863 if (!pMemSolaris)
864 return VERR_NO_MEMORY;
865
866 /* Lock down kernel pages. */
867 int fPageAccess = S_READ;
868 if (fAccess & RTMEM_PROT_WRITE)
869 fPageAccess = S_WRITE;
870 if (fAccess & RTMEM_PROT_EXEC)
871 fPageAccess = S_EXEC;
872 int rc = rtR0MemObjSolLock(pv, cb, fPageAccess);
873 if (RT_FAILURE(rc))
874 {
875 LogRel(("rtR0MemObjNativeLockKernel: rtR0MemObjSolLock failed rc=%d\n", rc));
876 rtR0MemObjDelete(&pMemSolaris->Core);
877 return rc;
878 }
879
880 /* Fill in the object attributes and return successfully. */
881 pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
882 pMemSolaris->pvHandle = NULL;
883 pMemSolaris->fAccess = fPageAccess;
884 *ppMem = &pMemSolaris->Core;
885 return VINF_SUCCESS;
886}
887
888
889DECLHIDDEN(int) rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
890{
891 PRTR0MEMOBJSOL pMemSolaris;
892
893 /*
894 * Use xalloc.
895 */
896 void *pv = vmem_xalloc(heap_arena, cb, uAlignment, 0 /* phase */, 0 /* nocross */,
897 NULL /* minaddr */, NULL /* maxaddr */, VM_SLEEP);
898 if (RT_UNLIKELY(!pv))
899 return VERR_NO_MEMORY;
900
901 /* Create the object. */
902 pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_RES_VIRT, pv, cb);
903 if (!pMemSolaris)
904 {
905 LogRel(("rtR0MemObjNativeReserveKernel failed to alloc memory object.\n"));
906 vmem_xfree(heap_arena, pv, cb);
907 return VERR_NO_MEMORY;
908 }
909
910 pMemSolaris->Core.u.ResVirt.R0Process = NIL_RTR0PROCESS;
911 *ppMem = &pMemSolaris->Core;
912 return VINF_SUCCESS;
913}
914
915
916DECLHIDDEN(int) rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment,
917 RTR0PROCESS R0Process)
918{
919 return VERR_NOT_SUPPORTED;
920}
921
922
923DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
924 unsigned fProt, size_t offSub, size_t cbSub)
925{
926 /* Fail if requested to do something we can't. */
927 AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
928 if (uAlignment > PAGE_SIZE)
929 return VERR_NOT_SUPPORTED;
930
931 /*
932 * Use xalloc to get address space.
933 */
934 if (!cbSub)
935 cbSub = pMemToMap->cb;
936 void *pv = vmem_xalloc(heap_arena, cbSub, uAlignment, 0 /* phase */, 0 /* nocross */,
937 NULL /* minaddr */, NULL /* maxaddr */, VM_SLEEP);
938 if (RT_UNLIKELY(!pv))
939 return VERR_MAP_FAILED;
940
941 /*
942 * Load the pages from the other object into it.
943 */
944 uint32_t fAttr = HAT_UNORDERED_OK | HAT_MERGING_OK | HAT_LOADCACHING_OK | HAT_STORECACHING_OK;
945 if (fProt & RTMEM_PROT_READ)
946 fAttr |= PROT_READ;
947 if (fProt & RTMEM_PROT_EXEC)
948 fAttr |= PROT_EXEC;
949 if (fProt & RTMEM_PROT_WRITE)
950 fAttr |= PROT_WRITE;
951 fAttr |= HAT_NOSYNC;
952
953 int rc = VINF_SUCCESS;
954 size_t off = 0;
955 while (off < cbSub)
956 {
957 RTHCPHYS HCPhys = rtR0MemObjNativeGetPagePhysAddr(pMemToMap, (offSub + offSub) >> PAGE_SHIFT);
958 AssertBreakStmt(HCPhys != NIL_RTHCPHYS, rc = VERR_INTERNAL_ERROR_2);
959 pfn_t pfn = HCPhys >> PAGE_SHIFT;
960 AssertBreakStmt(((RTHCPHYS)pfn << PAGE_SHIFT) == HCPhys, rc = VERR_INTERNAL_ERROR_3);
961
962 hat_devload(kas.a_hat, (uint8_t *)pv + off, PAGE_SIZE, pfn, fAttr, HAT_LOAD_LOCK);
963
964 /* Advance. */
965 off += PAGE_SIZE;
966 }
967 if (RT_SUCCESS(rc))
968 {
969 /*
970 * Create a memory object for the mapping.
971 */
972 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, cbSub);
973 if (pMemSolaris)
974 {
975 pMemSolaris->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
976 *ppMem = &pMemSolaris->Core;
977 return VINF_SUCCESS;
978 }
979
980 LogRel(("rtR0MemObjNativeMapKernel failed to alloc memory object.\n"));
981 rc = VERR_NO_MEMORY;
982 }
983
984 if (off)
985 hat_unload(kas.a_hat, pv, off, HAT_UNLOAD | HAT_UNLOAD_UNLOCK);
986 vmem_xfree(heap_arena, pv, cbSub);
987 return rc;
988}
989
990
991DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed,
992 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
993{
994 /*
995 * Fend off things we cannot do.
996 */
997 AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
998 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
999 if (uAlignment != PAGE_SIZE)
1000 return VERR_NOT_SUPPORTED;
1001
1002 /*
1003 * Get parameters from the source object.
1004 */
1005 PRTR0MEMOBJSOL pMemToMapSolaris = (PRTR0MEMOBJSOL)pMemToMap;
1006 void *pv = pMemToMapSolaris->Core.pv;
1007 size_t cb = pMemToMapSolaris->Core.cb;
1008 size_t cPages = (cb + PAGE_SIZE - 1) >> PAGE_SHIFT;
1009
1010 /*
1011 * Create the mapping object
1012 */
1013 PRTR0MEMOBJSOL pMemSolaris;
1014 pMemSolaris = (PRTR0MEMOBJSOL)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, cb);
1015 if (RT_UNLIKELY(!pMemSolaris))
1016 return VERR_NO_MEMORY;
1017
1018 int rc = VINF_SUCCESS;
1019 uint64_t *paPhysAddrs = kmem_zalloc(sizeof(uint64_t) * cPages, KM_SLEEP);
1020 if (RT_LIKELY(paPhysAddrs))
1021 {
1022 /*
1023 * Prepare the pages for mapping according to type.
1024 */
1025 if ( pMemToMapSolaris->Core.enmType == RTR0MEMOBJTYPE_PHYS_NC
1026 && pMemToMapSolaris->fIndivPages)
1027 {
1028 page_t **ppPages = pMemToMapSolaris->pvHandle;
1029 AssertPtr(ppPages);
1030 for (size_t iPage = 0; iPage < cPages; iPage++)
1031 paPhysAddrs[iPage] = rtR0MemObjSolPagePhys(ppPages[iPage]);
1032 }
1033 else if ( pMemToMapSolaris->Core.enmType == RTR0MEMOBJTYPE_PHYS
1034 && pMemToMapSolaris->fLargePage)
1035 {
1036 RTHCPHYS Phys = pMemToMapSolaris->Core.u.Phys.PhysBase;
1037 for (size_t iPage = 0; iPage < cPages; iPage++, Phys += PAGE_SIZE)
1038 paPhysAddrs[iPage] = Phys;
1039 }
1040 else
1041 {
1042 /*
1043 * Have kernel mapping, just translate virtual to physical.
1044 */
1045 AssertPtr(pv);
1046 rc = VINF_SUCCESS;
1047 for (size_t iPage = 0; iPage < cPages; iPage++)
1048 {
1049 paPhysAddrs[iPage] = rtR0MemObjSolVirtToPhys(pv);
1050 if (RT_UNLIKELY(paPhysAddrs[iPage] == -(uint64_t)1))
1051 {
1052 LogRel(("rtR0MemObjNativeMapUser: no page to map.\n"));
1053 rc = VERR_MAP_FAILED;
1054 break;
1055 }
1056 pv = (void *)((uintptr_t)pv + PAGE_SIZE);
1057 }
1058 }
1059 if (RT_SUCCESS(rc))
1060 {
1061 unsigned fPageAccess = PROT_READ;
1062 if (fProt & RTMEM_PROT_WRITE)
1063 fPageAccess |= PROT_WRITE;
1064 if (fProt & RTMEM_PROT_EXEC)
1065 fPageAccess |= PROT_EXEC;
1066
1067 /*
1068 * Perform the actual mapping.
1069 */
1070 caddr_t UserAddr = NULL;
1071 rc = rtR0MemObjSolUserMap(&UserAddr, fPageAccess, paPhysAddrs, cb, PAGE_SIZE);
1072 if (RT_SUCCESS(rc))
1073 {
1074 pMemSolaris->Core.u.Mapping.R0Process = R0Process;
1075 pMemSolaris->Core.pv = UserAddr;
1076
1077 *ppMem = &pMemSolaris->Core;
1078 kmem_free(paPhysAddrs, sizeof(uint64_t) * cPages);
1079 return VINF_SUCCESS;
1080 }
1081
1082 LogRel(("rtR0MemObjNativeMapUser: rtR0MemObjSolUserMap failed rc=%d.\n", rc));
1083 }
1084
1085 rc = VERR_MAP_FAILED;
1086 kmem_free(paPhysAddrs, sizeof(uint64_t) * cPages);
1087 }
1088 else
1089 rc = VERR_NO_MEMORY;
1090 rtR0MemObjDelete(&pMemSolaris->Core);
1091 return rc;
1092}
1093
1094
1095DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
1096{
1097 NOREF(pMem);
1098 NOREF(offSub);
1099 NOREF(cbSub);
1100 NOREF(fProt);
1101 return VERR_NOT_SUPPORTED;
1102}
1103
1104
1105DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
1106{
1107 PRTR0MEMOBJSOL pMemSolaris = (PRTR0MEMOBJSOL)pMem;
1108
1109 switch (pMemSolaris->Core.enmType)
1110 {
1111 case RTR0MEMOBJTYPE_PHYS_NC:
1112 if ( pMemSolaris->Core.u.Phys.fAllocated
1113 || !pMemSolaris->fIndivPages)
1114 {
1115 uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
1116 return rtR0MemObjSolVirtToPhys(pb);
1117 }
1118 page_t **ppPages = pMemSolaris->pvHandle;
1119 return rtR0MemObjSolPagePhys(ppPages[iPage]);
1120
1121 case RTR0MEMOBJTYPE_PAGE:
1122 case RTR0MEMOBJTYPE_LOW:
1123 case RTR0MEMOBJTYPE_LOCK:
1124 {
1125 uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
1126 return rtR0MemObjSolVirtToPhys(pb);
1127 }
1128
1129 /*
1130 * Although mapping can be handled by rtR0MemObjSolVirtToPhys(offset) like the above case,
1131 * request it from the parent so that we have a clear distinction between CONT/PHYS_NC.
1132 */
1133 case RTR0MEMOBJTYPE_MAPPING:
1134 return rtR0MemObjNativeGetPagePhysAddr(pMemSolaris->Core.uRel.Child.pParent, iPage);
1135
1136 case RTR0MEMOBJTYPE_CONT:
1137 case RTR0MEMOBJTYPE_PHYS:
1138 AssertFailed(); /* handled by the caller */
1139 case RTR0MEMOBJTYPE_RES_VIRT:
1140 default:
1141 return NIL_RTHCPHYS;
1142 }
1143}
1144
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