1 | /* $Id: memobj-r0drv-solaris.c 28018 2010-04-06 15:57:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Ring-0 Memory Objects, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include "../the-solaris-kernel.h"
|
---|
36 | #include "internal/iprt.h"
|
---|
37 | #include <iprt/memobj.h>
|
---|
38 |
|
---|
39 | #include <iprt/assert.h>
|
---|
40 | #include <iprt/err.h>
|
---|
41 | #include <iprt/log.h>
|
---|
42 | #include <iprt/mem.h>
|
---|
43 | #include <iprt/param.h>
|
---|
44 | #include <iprt/process.h>
|
---|
45 | #include "internal/memobj.h"
|
---|
46 |
|
---|
47 | /*******************************************************************************
|
---|
48 | * Structures and Typedefs *
|
---|
49 | *******************************************************************************/
|
---|
50 | /**
|
---|
51 | * The Solaris version of the memory object structure.
|
---|
52 | */
|
---|
53 | typedef struct RTR0MEMOBJSOLARIS
|
---|
54 | {
|
---|
55 | /** The core structure. */
|
---|
56 | RTR0MEMOBJINTERNAL Core;
|
---|
57 | /** Pointer to kernel memory cookie. */
|
---|
58 | ddi_umem_cookie_t Cookie;
|
---|
59 | /** Shadow locked pages. */
|
---|
60 | void *pvHandle;
|
---|
61 | /** Access during locking. */
|
---|
62 | int fAccess;
|
---|
63 | } RTR0MEMOBJSOLARIS, *PRTR0MEMOBJSOLARIS;
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | int rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
|
---|
68 | {
|
---|
69 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
|
---|
70 |
|
---|
71 | switch (pMemSolaris->Core.enmType)
|
---|
72 | {
|
---|
73 | case RTR0MEMOBJTYPE_LOW:
|
---|
74 | vbi_lowmem_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
|
---|
75 | break;
|
---|
76 |
|
---|
77 | case RTR0MEMOBJTYPE_CONT:
|
---|
78 | case RTR0MEMOBJTYPE_PHYS:
|
---|
79 | vbi_phys_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
|
---|
80 | break;
|
---|
81 |
|
---|
82 | case RTR0MEMOBJTYPE_PHYS_NC:
|
---|
83 | #if 0
|
---|
84 | vbi_phys_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
|
---|
85 | #else
|
---|
86 | if (pMemSolaris->Core.u.Phys.fAllocated == true)
|
---|
87 | ddi_umem_free(pMemSolaris->Cookie);
|
---|
88 | else
|
---|
89 | vbi_pages_free(pMemSolaris->pvHandle, pMemSolaris->Core.cb);
|
---|
90 | #endif
|
---|
91 | break;
|
---|
92 |
|
---|
93 | case RTR0MEMOBJTYPE_PAGE:
|
---|
94 | ddi_umem_free(pMemSolaris->Cookie);
|
---|
95 | break;
|
---|
96 |
|
---|
97 | case RTR0MEMOBJTYPE_LOCK:
|
---|
98 | vbi_unlock_va(pMemSolaris->Core.pv, pMemSolaris->Core.cb, pMemSolaris->fAccess, pMemSolaris->pvHandle);
|
---|
99 | break;
|
---|
100 |
|
---|
101 | case RTR0MEMOBJTYPE_MAPPING:
|
---|
102 | vbi_unmap(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
|
---|
103 | break;
|
---|
104 |
|
---|
105 | case RTR0MEMOBJTYPE_RES_VIRT:
|
---|
106 | {
|
---|
107 | if (pMemSolaris->Core.u.ResVirt.R0Process == NIL_RTR0PROCESS)
|
---|
108 | vmem_xfree(heap_arena, pMemSolaris->Core.pv, pMemSolaris->Core.cb);
|
---|
109 | else
|
---|
110 | AssertFailed();
|
---|
111 | break;
|
---|
112 | }
|
---|
113 |
|
---|
114 | default:
|
---|
115 | AssertMsgFailed(("enmType=%d\n", pMemSolaris->Core.enmType));
|
---|
116 | return VERR_INTERNAL_ERROR;
|
---|
117 | }
|
---|
118 |
|
---|
119 | return VINF_SUCCESS;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
|
---|
124 | {
|
---|
125 | /* Create the object. */
|
---|
126 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb);
|
---|
127 | if (!pMemSolaris)
|
---|
128 | return VERR_NO_MEMORY;
|
---|
129 |
|
---|
130 | void *virtAddr = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
|
---|
131 | if (!virtAddr)
|
---|
132 | {
|
---|
133 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
134 | return VERR_NO_PAGE_MEMORY;
|
---|
135 | }
|
---|
136 |
|
---|
137 | pMemSolaris->Core.pv = virtAddr;
|
---|
138 | pMemSolaris->pvHandle = NULL;
|
---|
139 | *ppMem = &pMemSolaris->Core;
|
---|
140 | return VINF_SUCCESS;
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
|
---|
145 | {
|
---|
146 | NOREF(fExecutable);
|
---|
147 |
|
---|
148 | /* Create the object */
|
---|
149 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOW, NULL, cb);
|
---|
150 | if (!pMemSolaris)
|
---|
151 | return VERR_NO_MEMORY;
|
---|
152 |
|
---|
153 | /* Allocate physically low page-aligned memory. */
|
---|
154 | uint64_t physAddr = _4G - 1;
|
---|
155 | caddr_t virtAddr = vbi_lowmem_alloc(physAddr, cb);
|
---|
156 | if (virtAddr == NULL)
|
---|
157 | {
|
---|
158 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
159 | return VERR_NO_LOW_MEMORY;
|
---|
160 | }
|
---|
161 | pMemSolaris->Core.pv = virtAddr;
|
---|
162 | pMemSolaris->pvHandle = NULL;
|
---|
163 | *ppMem = &pMemSolaris->Core;
|
---|
164 | return VINF_SUCCESS;
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
|
---|
169 | {
|
---|
170 | NOREF(fExecutable);
|
---|
171 | return rtR0MemObjNativeAllocPhys(ppMem, cb, NIL_RTHCPHYS, PAGE_SIZE /* alignment */);
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
|
---|
176 | {
|
---|
177 | #if HC_ARCH_BITS == 64
|
---|
178 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS_NC, NULL, cb);
|
---|
179 | if (!pMemSolaris)
|
---|
180 | return VERR_NO_MEMORY;
|
---|
181 |
|
---|
182 | /* Allocate physically non-contiguous page-aligned memory. */
|
---|
183 | uint64_t physAddr = PhysHighest;
|
---|
184 |
|
---|
185 | #if 0
|
---|
186 | /*
|
---|
187 | * The contig_alloc() way of allocating NC pages is broken or does not match our semantics. Refer #4716 for details.
|
---|
188 | */
|
---|
189 | /* caddr_t virtAddr = vbi_phys_alloc(&physAddr, cb, PAGE_SIZE, 0 /* non-contiguous */); */
|
---|
190 | caddr_t virtAddr = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
|
---|
191 | if (RT_UNLIKELY(virtAddr == NULL))
|
---|
192 | {
|
---|
193 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
194 | return VERR_NO_MEMORY;
|
---|
195 | }
|
---|
196 | pMemSolaris->Core.pv = virtAddr;
|
---|
197 | pMemSolaris->Core.u.Phys.PhysBase = physAddr;
|
---|
198 | pMemSolaris->Core.u.Phys.fAllocated = true;
|
---|
199 | pMemSolaris->pvHandle = NULL;
|
---|
200 | #else
|
---|
201 | void *pvPages = vbi_pages_alloc(&physAddr, cb);
|
---|
202 | if (!pvPages)
|
---|
203 | {
|
---|
204 | LogRel(("rtR0MemObjNativeAllocPhysNC: vbi_pages_alloc failed.\n"));
|
---|
205 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
206 | return VERR_NO_MEMORY;
|
---|
207 | }
|
---|
208 | pMemSolaris->Core.pv = NULL;
|
---|
209 | pMemSolaris->Core.u.Phys.PhysBase = physAddr;
|
---|
210 | pMemSolaris->Core.u.Phys.fAllocated = false;
|
---|
211 | pMemSolaris->pvHandle = pvPages;
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | Assert(!(physAddr & PAGE_OFFSET_MASK));
|
---|
215 | *ppMem = &pMemSolaris->Core;
|
---|
216 | return VINF_SUCCESS;
|
---|
217 | #else
|
---|
218 | /** @todo rtR0MemObjNativeAllocPhysNC / solaris */
|
---|
219 | return VERR_NOT_SUPPORTED; /* see the RTR0MemObjAllocPhysNC specs */
|
---|
220 | #endif
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
|
---|
225 | {
|
---|
226 | AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
|
---|
227 |
|
---|
228 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
|
---|
229 | if (!pMemSolaris)
|
---|
230 | return VERR_NO_MEMORY;
|
---|
231 |
|
---|
232 | AssertCompile(NIL_RTHCPHYS == UINT64_MAX);
|
---|
233 |
|
---|
234 | /* Allocate physically contiguous memory aligned as specified. */
|
---|
235 | uint64_t physAddr = PhysHighest;
|
---|
236 | caddr_t virtAddr = vbi_phys_alloc(&physAddr, cb, uAlignment, 1 /* contiguous */);
|
---|
237 | if (RT_UNLIKELY(virtAddr == NULL))
|
---|
238 | {
|
---|
239 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
240 | return VERR_NO_CONT_MEMORY;
|
---|
241 | }
|
---|
242 | Assert(!(physAddr & PAGE_OFFSET_MASK));
|
---|
243 | Assert(physAddr < PhysHighest);
|
---|
244 | Assert(physAddr + cb <= PhysHighest);
|
---|
245 | #if 0
|
---|
246 | if (uAlignment != PAGE_SIZE)
|
---|
247 | {
|
---|
248 | /* uAlignment is always a multiple of PAGE_SIZE */
|
---|
249 | pgcnt_t cPages = (cb + uAlignment - 1) >> PAGE_SHIFT;
|
---|
250 | void *pvPage = virtAddr;
|
---|
251 | while (cPages-- > 0)
|
---|
252 | {
|
---|
253 | uint64_t u64Page = vbi_va_to_pa(pvPage);
|
---|
254 | if (u64Page & (uAlignment - 1))
|
---|
255 | {
|
---|
256 | LogRel(("rtR0MemObjNativeAllocPhys: alignment mismatch! cb=%u uAlignment=%u physAddr=%#x\n", cb, uAlignment, u64Page));
|
---|
257 | vbi_phys_free(virtAddr, cb);
|
---|
258 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
259 | return VERR_NO_MEMORY;
|
---|
260 | }
|
---|
261 | pvPage = (void *)((uintptr_t)pvPage + PAGE_SIZE);
|
---|
262 | }
|
---|
263 | }
|
---|
264 | #endif
|
---|
265 | pMemSolaris->Core.pv = virtAddr;
|
---|
266 | pMemSolaris->Core.u.Cont.Phys = physAddr;
|
---|
267 | pMemSolaris->pvHandle = NULL;
|
---|
268 | *ppMem = &pMemSolaris->Core;
|
---|
269 | return VINF_SUCCESS;
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
|
---|
274 | {
|
---|
275 | /* Create the object. */
|
---|
276 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
|
---|
277 | if (!pMemSolaris)
|
---|
278 | return VERR_NO_MEMORY;
|
---|
279 |
|
---|
280 | /* There is no allocation here, it needs to be mapped somewhere first. */
|
---|
281 | pMemSolaris->Core.u.Phys.fAllocated = false;
|
---|
282 | pMemSolaris->Core.u.Phys.PhysBase = Phys;
|
---|
283 | *ppMem = &pMemSolaris->Core;
|
---|
284 | return VINF_SUCCESS;
|
---|
285 | }
|
---|
286 |
|
---|
287 |
|
---|
288 | int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
|
---|
289 | {
|
---|
290 | AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_INVALID_PARAMETER);
|
---|
291 | NOREF(fAccess);
|
---|
292 |
|
---|
293 | /* Create the locking object */
|
---|
294 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
|
---|
295 | if (!pMemSolaris)
|
---|
296 | return VERR_NO_MEMORY;
|
---|
297 |
|
---|
298 | int fPageAccess = S_READ;
|
---|
299 | if (fAccess & RTMEM_PROT_WRITE)
|
---|
300 | fPageAccess = S_WRITE;
|
---|
301 | if (fAccess & RTMEM_PROT_EXEC)
|
---|
302 | fPageAccess = S_EXEC;
|
---|
303 | void *pvPageList = NULL;
|
---|
304 |
|
---|
305 | /* Lock down user pages */
|
---|
306 | int rc = vbi_lock_va((caddr_t)R3Ptr, cb, fPageAccess, &pvPageList);
|
---|
307 | if (rc != 0)
|
---|
308 | {
|
---|
309 | LogRel(("rtR0MemObjNativeLockUser: vbi_lock_va failed rc=%d\n", rc));
|
---|
310 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
311 | return VERR_LOCK_FAILED;
|
---|
312 | }
|
---|
313 |
|
---|
314 | pMemSolaris->Core.u.Lock.R0Process = (RTR0PROCESS)vbi_proc();
|
---|
315 | pMemSolaris->pvHandle = pvPageList;
|
---|
316 | pMemSolaris->fAccess = fPageAccess;
|
---|
317 | *ppMem = &pMemSolaris->Core;
|
---|
318 | return VINF_SUCCESS;
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
|
---|
323 | {
|
---|
324 | NOREF(fAccess);
|
---|
325 |
|
---|
326 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
|
---|
327 | if (!pMemSolaris)
|
---|
328 | return VERR_NO_MEMORY;
|
---|
329 |
|
---|
330 | int fPageAccess = S_READ;
|
---|
331 | if (fAccess & RTMEM_PROT_WRITE)
|
---|
332 | fPageAccess = S_WRITE;
|
---|
333 | if (fAccess & RTMEM_PROT_EXEC)
|
---|
334 | fPageAccess = S_EXEC;
|
---|
335 | void *pvPageList = NULL;
|
---|
336 | int rc = vbi_lock_va((caddr_t)pv, cb, fPageAccess, &pvPageList);
|
---|
337 | if (rc != 0)
|
---|
338 | {
|
---|
339 | LogRel(("rtR0MemObjNativeLockKernel: vbi_lock_va failed rc=%d\n", rc));
|
---|
340 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
341 | return VERR_LOCK_FAILED;
|
---|
342 | }
|
---|
343 |
|
---|
344 | pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
|
---|
345 | pMemSolaris->pvHandle = pvPageList;
|
---|
346 | pMemSolaris->fAccess = fPageAccess;
|
---|
347 | *ppMem = &pMemSolaris->Core;
|
---|
348 | return VINF_SUCCESS;
|
---|
349 | }
|
---|
350 |
|
---|
351 |
|
---|
352 | int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
|
---|
353 | {
|
---|
354 | PRTR0MEMOBJSOLARIS pMemSolaris;
|
---|
355 |
|
---|
356 | /*
|
---|
357 | * Use xalloc.
|
---|
358 | */
|
---|
359 | void *pv = vmem_xalloc(heap_arena, cb, uAlignment, 0 /*phase*/, 0 /*nocross*/,
|
---|
360 | NULL /*minaddr*/, NULL /*maxaddr*/, VM_SLEEP);
|
---|
361 | if (RT_UNLIKELY(!pv))
|
---|
362 | return VERR_NO_MEMORY;
|
---|
363 |
|
---|
364 | /* Create the object. */
|
---|
365 | pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_RES_VIRT, pv, cb);
|
---|
366 | if (!pMemSolaris)
|
---|
367 | {
|
---|
368 | LogRel(("rtR0MemObjNativeReserveKernel failed to alloc memory object.\n"));
|
---|
369 | vmem_xfree(heap_arena, pv, cb);
|
---|
370 | return VERR_NO_MEMORY;
|
---|
371 | }
|
---|
372 |
|
---|
373 | pMemSolaris->Core.u.ResVirt.R0Process = NIL_RTR0PROCESS;
|
---|
374 | *ppMem = &pMemSolaris->Core;
|
---|
375 | return VINF_SUCCESS;
|
---|
376 | }
|
---|
377 |
|
---|
378 |
|
---|
379 | int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
|
---|
380 | {
|
---|
381 | return VERR_NOT_IMPLEMENTED;
|
---|
382 | }
|
---|
383 |
|
---|
384 | int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
|
---|
385 | unsigned fProt, size_t offSub, size_t cbSub)
|
---|
386 | {
|
---|
387 | /** @todo rtR0MemObjNativeMapKernel / Solaris - Should be fairly simple alloc kernel memory and memload it. */
|
---|
388 | return VERR_NOT_IMPLEMENTED;
|
---|
389 | }
|
---|
390 |
|
---|
391 |
|
---|
392 | int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
|
---|
393 | {
|
---|
394 | AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
|
---|
395 | AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
|
---|
396 | if (uAlignment != PAGE_SIZE)
|
---|
397 | return VERR_NOT_SUPPORTED;
|
---|
398 |
|
---|
399 | PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;
|
---|
400 | size_t cb = pMemToMapSolaris->Core.cb;
|
---|
401 | void *pv = pMemToMapSolaris->Core.pv;
|
---|
402 | pgcnt_t cPages = (cb + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
---|
403 |
|
---|
404 | /* Create the mapping object */
|
---|
405 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, cb);
|
---|
406 | if (RT_UNLIKELY(!pMemSolaris))
|
---|
407 | return VERR_NO_MEMORY;
|
---|
408 |
|
---|
409 | uint64_t *paPhysAddrs = kmem_zalloc(sizeof(uint64_t) * cPages, KM_SLEEP);
|
---|
410 | if (RT_UNLIKELY(!paPhysAddrs))
|
---|
411 | return VERR_NO_MEMORY;
|
---|
412 |
|
---|
413 | if ( pMemToMapSolaris->Core.enmType == RTR0MEMOBJTYPE_PHYS_NC
|
---|
414 | && pMemSolaris->Core.u.Phys.fAllocated == false)
|
---|
415 | {
|
---|
416 | /*
|
---|
417 | * The PhysNC object has no kernel mapping backing it. The call to vbi_pages_premap()
|
---|
418 | * prepares the physical pages to be mapped into user or kernel space.
|
---|
419 | */
|
---|
420 | int rc = vbi_pages_premap(pMemToMapSolaris->pvHandle, cb, paPhysAddrs);
|
---|
421 | if (rc)
|
---|
422 | {
|
---|
423 | LogRel(("rtR0MemObjNativeMapUser: vbi_pages_premap failed. rc=%d\n", rc));
|
---|
424 | kmem_free(paPhysAddrs, sizeof(uint64_t) * cPages);
|
---|
425 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
426 | return VERR_MAP_FAILED;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | else
|
---|
430 | {
|
---|
431 | /*
|
---|
432 | * All other memory object types have allocated memory with kernel mappings.
|
---|
433 | */
|
---|
434 | for (pgcnt_t iPage = 0; iPage < cPages; iPage++)
|
---|
435 | {
|
---|
436 | paPhysAddrs[iPage] = vbi_va_to_pa(pv);
|
---|
437 | if (RT_UNLIKELY(paPhysAddrs[iPage] == -(uint64_t)1))
|
---|
438 | {
|
---|
439 | LogRel(("rtR0MemObjNativeMapUser: no page to map.\n"));
|
---|
440 | kmem_free(paPhysAddrs, sizeof(uint64_t) * cPages);
|
---|
441 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
442 | return VERR_MAP_FAILED;
|
---|
443 | }
|
---|
444 | pv = (void *)((uintptr_t)pv + PAGE_SIZE);
|
---|
445 | }
|
---|
446 | }
|
---|
447 |
|
---|
448 | caddr_t virtAddr = NULL;
|
---|
449 | int rc = vbi_user_map(&virtAddr, fProt, paPhysAddrs, cb);
|
---|
450 | if (rc != 0)
|
---|
451 | {
|
---|
452 | LogRel(("rtR0MemObjNativeMapUser: vbi mapping failure.\n"));
|
---|
453 | kmem_free(paPhysAddrs, sizeof(uint64_t) * cPages);
|
---|
454 | rtR0MemObjDelete(&pMemSolaris->Core);
|
---|
455 | return VERR_MAP_FAILED;
|
---|
456 | }
|
---|
457 | else
|
---|
458 | rc = VINF_SUCCESS;
|
---|
459 |
|
---|
460 | pMemSolaris->Core.u.Mapping.R0Process = (RTR0PROCESS)vbi_proc();
|
---|
461 | pMemSolaris->Core.pv = virtAddr;
|
---|
462 | *ppMem = &pMemSolaris->Core;
|
---|
463 | kmem_free(paPhysAddrs, sizeof(uint64_t) * cPages);
|
---|
464 | return rc;
|
---|
465 | }
|
---|
466 |
|
---|
467 |
|
---|
468 | int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
|
---|
469 | {
|
---|
470 | NOREF(pMem);
|
---|
471 | NOREF(offSub);
|
---|
472 | NOREF(cbSub);
|
---|
473 | NOREF(fProt);
|
---|
474 | return VERR_NOT_SUPPORTED;
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 | RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
|
---|
479 | {
|
---|
480 | PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
|
---|
481 |
|
---|
482 | switch (pMemSolaris->Core.enmType)
|
---|
483 | {
|
---|
484 | case RTR0MEMOBJTYPE_PAGE:
|
---|
485 | case RTR0MEMOBJTYPE_LOW:
|
---|
486 | case RTR0MEMOBJTYPE_LOCK:
|
---|
487 | {
|
---|
488 | uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
|
---|
489 | return vbi_va_to_pa(pb);
|
---|
490 | }
|
---|
491 |
|
---|
492 | /*
|
---|
493 | * Although mapping can be handled by vbi_va_to_pa(offset) like the above case,
|
---|
494 | * request it from the parent so that we have a clear distinction between CONT/PHYS_NC.
|
---|
495 | */
|
---|
496 | case RTR0MEMOBJTYPE_MAPPING:
|
---|
497 | return rtR0MemObjNativeGetPagePhysAddr(pMemSolaris->Core.uRel.Child.pParent, iPage);
|
---|
498 |
|
---|
499 | case RTR0MEMOBJTYPE_CONT:
|
---|
500 | case RTR0MEMOBJTYPE_PHYS:
|
---|
501 | return pMemSolaris->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
|
---|
502 |
|
---|
503 | case RTR0MEMOBJTYPE_PHYS_NC:
|
---|
504 | if (pMemSolaris->Core.u.Phys.fAllocated == true)
|
---|
505 | {
|
---|
506 | uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
|
---|
507 | return vbi_va_to_pa(pb);
|
---|
508 | }
|
---|
509 | return vbi_page_to_pa(pMemSolaris->pvHandle, iPage);
|
---|
510 |
|
---|
511 | case RTR0MEMOBJTYPE_RES_VIRT:
|
---|
512 | default:
|
---|
513 | return NIL_RTHCPHYS;
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|