VirtualBox

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

最後變更 在這個檔案從25720是 24426,由 vboxsync 提交於 15 年 前

Solaris/r0drv: as_pagelock fix typo.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.9 KB
 
1/* $Id: memobj-r0drv-solaris.c 24426 2009-11-06 07:38:42Z 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.alldomusa.eu.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/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51/**
52 * The Solaris version of the memory object structure.
53 */
54typedef struct RTR0MEMOBJSOLARIS
55{
56 /** The core structure. */
57 RTR0MEMOBJINTERNAL Core;
58 /** Pointer to kernel memory cookie. */
59 ddi_umem_cookie_t Cookie;
60 /** Shadow locked pages. */
61 void *pvHandle;
62 /** Access during locking. */
63 int fAccess;
64} RTR0MEMOBJSOLARIS, *PRTR0MEMOBJSOLARIS;
65
66
67
68int rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
69{
70 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
71
72 switch (pMemSolaris->Core.enmType)
73 {
74 case RTR0MEMOBJTYPE_LOW:
75 vbi_lowmem_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
76 break;
77
78 case RTR0MEMOBJTYPE_CONT:
79 vbi_contig_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
80 break;
81
82 case RTR0MEMOBJTYPE_PAGE:
83 ddi_umem_free(pMemSolaris->Cookie);
84 break;
85
86 case RTR0MEMOBJTYPE_LOCK:
87 vbi_unlock_va(pMemSolaris->Core.pv, pMemSolaris->Core.cb, pMemSolaris->fAccess, pMemSolaris->pvHandle);
88 break;
89
90 case RTR0MEMOBJTYPE_MAPPING:
91 vbi_unmap(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
92 break;
93
94 case RTR0MEMOBJTYPE_RES_VIRT:
95 {
96 if (pMemSolaris->Core.u.ResVirt.R0Process == NIL_RTR0PROCESS)
97 vmem_xfree(heap_arena, pMemSolaris->Core.pv, pMemSolaris->Core.cb);
98 else
99 AssertFailed();
100 break;
101 }
102
103 /* unused */
104 case RTR0MEMOBJTYPE_PHYS:
105 default:
106 AssertMsgFailed(("enmType=%d\n", pMemSolaris->Core.enmType));
107 return VERR_INTERNAL_ERROR;
108 }
109
110 return VINF_SUCCESS;
111}
112
113
114int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
115{
116 /* Create the object */
117 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb);
118 if (!pMemSolaris)
119 return VERR_NO_MEMORY;
120
121 void *virtAddr = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
122 if (!virtAddr)
123 {
124 rtR0MemObjDelete(&pMemSolaris->Core);
125 return VERR_NO_PAGE_MEMORY;
126 }
127
128 pMemSolaris->Core.pv = virtAddr;
129 pMemSolaris->pvHandle = NULL;
130 *ppMem = &pMemSolaris->Core;
131 return VINF_SUCCESS;
132}
133
134
135int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
136{
137 NOREF(fExecutable);
138
139 /* Create the object */
140 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOW, NULL, cb);
141 if (!pMemSolaris)
142 return VERR_NO_MEMORY;
143
144 /* Allocate physically low page-aligned memory. */
145 caddr_t virtAddr;
146 uint64_t phys = (unsigned)0xffffffff;
147 virtAddr = vbi_lowmem_alloc(phys, cb);
148 if (virtAddr == NULL)
149 {
150 rtR0MemObjDelete(&pMemSolaris->Core);
151 return VERR_NO_LOW_MEMORY;
152 }
153 pMemSolaris->Core.pv = virtAddr;
154 pMemSolaris->pvHandle = NULL;
155 *ppMem = &pMemSolaris->Core;
156 return VINF_SUCCESS;
157}
158
159
160int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
161{
162 NOREF(fExecutable);
163
164 /* Create the object */
165 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_CONT, NULL, cb);
166 if (!pMemSolaris)
167 return VERR_NO_MEMORY;
168
169 /* Allocate physically contiguous page-aligned memory. */
170 caddr_t virtAddr;
171 uint64_t phys = (unsigned)0xffffffff;
172 virtAddr = vbi_contig_alloc(&phys, cb);
173 if (virtAddr == NULL)
174 {
175 rtR0MemObjDelete(&pMemSolaris->Core);
176 return VERR_NO_CONT_MEMORY;
177 }
178 Assert(phys < (uint64_t)1 << 32);
179 pMemSolaris->Core.pv = virtAddr;
180 pMemSolaris->Core.u.Cont.Phys = phys;
181 pMemSolaris->pvHandle = NULL;
182 *ppMem = &pMemSolaris->Core;
183 return VINF_SUCCESS;
184}
185
186
187int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
188{
189 /** @todo rtR0MemObjNativeAllocPhysNC / solaris */
190 return VERR_NOT_SUPPORTED; /* see the RTR0MemObjAllocPhysNC specs */
191}
192
193
194int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
195{
196 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
197
198 return rtR0MemObjNativeAllocCont(ppMem, cb, false);
199}
200
201
202int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
203{
204 /* Create the object */
205 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
206 if (!pMemSolaris)
207 return VERR_NO_MEMORY;
208
209 /* There is no allocation here, it needs to be mapped somewhere first */
210 pMemSolaris->Core.u.Phys.fAllocated = false;
211 pMemSolaris->Core.u.Phys.PhysBase = Phys;
212 *ppMem = &pMemSolaris->Core;
213 return VINF_SUCCESS;
214}
215
216
217int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
218{
219 AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_INVALID_PARAMETER);
220 NOREF(fAccess);
221
222 /* Create the locking object */
223 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
224 if (!pMemSolaris)
225 return VERR_NO_MEMORY;
226
227 int fPageAccess = S_READ;
228 if (fAccess & RTMEM_PROT_WRITE)
229 fPageAccess = S_WRITE;
230 if (fAccess & RTMEM_PROT_EXEC)
231 fPageAccess = S_EXEC;
232 void *pvPageList = NULL;
233
234 /* Lock down user pages */
235 int rc = vbi_lock_va((caddr_t)R3Ptr, cb, fPageAccess, &pvPageList);
236 if (rc != 0)
237 {
238 cmn_err(CE_NOTE,"rtR0MemObjNativeLockUser: vbi_lock_va failed rc=%d\n", rc);
239 rtR0MemObjDelete(&pMemSolaris->Core);
240 return VERR_LOCK_FAILED;
241 }
242
243 pMemSolaris->Core.u.Lock.R0Process = (RTR0PROCESS)vbi_proc();
244 pMemSolaris->pvHandle = pvPageList;
245 pMemSolaris->fAccess = fPageAccess;
246 *ppMem = &pMemSolaris->Core;
247 return VINF_SUCCESS;
248}
249
250
251int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
252{
253 NOREF(fAccess);
254
255 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
256 if (!pMemSolaris)
257 return VERR_NO_MEMORY;
258
259 int fPageAccess = S_READ;
260 if (fAccess & RTMEM_PROT_WRITE)
261 fPageAccess = S_WRITE;
262 if (fAccess & RTMEM_PROT_EXEC)
263 fPageAccess = S_EXEC;
264 void *pvPageList = NULL;
265 int rc = vbi_lock_va((caddr_t)pv, cb, fPageAccess, &pvPageList);
266 if (rc != 0)
267 {
268 cmn_err(CE_NOTE,"rtR0MemObjNativeLockKernel: vbi_lock_va failed rc=%d\n", rc);
269 rtR0MemObjDelete(&pMemSolaris->Core);
270 return VERR_LOCK_FAILED;
271 }
272
273 pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
274 pMemSolaris->pvHandle = pvPageList;
275 pMemSolaris->fAccess = fPageAccess;
276 *ppMem = &pMemSolaris->Core;
277 return VINF_SUCCESS;
278}
279
280
281int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
282{
283 PRTR0MEMOBJSOLARIS pMemSolaris;
284 void *pv;
285
286 /*
287 * Use xalloc.
288 */
289 pv = vmem_xalloc(heap_arena, cb, uAlignment, 0 /*phase*/, 0 /*nocross*/,
290 NULL /*minaddr*/, NULL /*maxaddr*/, VM_SLEEP);
291 if (!pv)
292 return VERR_NO_MEMORY;
293 pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_RES_VIRT, pv, cb);
294 if (!pMemSolaris)
295 {
296 vmem_xfree(heap_arena, pv, cb);
297 return VERR_NO_MEMORY;
298 }
299
300 pMemSolaris->Core.u.ResVirt.R0Process = NIL_RTR0PROCESS;
301 *ppMem = &pMemSolaris->Core;
302 return VINF_SUCCESS;
303}
304
305
306int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
307{
308 return VERR_NOT_IMPLEMENTED;
309}
310
311int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
312 unsigned fProt, size_t offSub, size_t cbSub)
313{
314 /** @todo rtR0MemObjNativeMapKernel / Solaris - Should be fairly simple alloc kernel memory and memload it. */
315 return VERR_NOT_IMPLEMENTED;
316}
317
318
319int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
320{
321 AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
322 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
323 if (uAlignment > PAGE_SIZE)
324 return VERR_NOT_SUPPORTED;
325
326 PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;
327 size_t size = pMemToMapSolaris->Core.cb;
328 void *pv = pMemToMapSolaris->Core.pv;
329 pgcnt_t cPages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
330 pgcnt_t iPage;
331 uint64_t *paddrs;
332 caddr_t addr;
333 int rc;
334
335 /* Create the mapping object */
336 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, size);
337 if (!pMemSolaris)
338 return VERR_NO_MEMORY;
339
340 paddrs = kmem_zalloc(sizeof(uint64_t) * cPages, KM_SLEEP);
341 for (iPage = 0; iPage < cPages; iPage++)
342 {
343 paddrs[iPage] = vbi_va_to_pa(pv);
344 if (paddrs[iPage] == -(uint64_t)1)
345 {
346 cmn_err(CE_NOTE, "rtR0MemObjNativeMapUser: no page to map.\n");
347 rc = VERR_MAP_FAILED;
348 goto l_done;
349 }
350 pv = (void *)((uintptr_t)pv + PAGE_SIZE);
351 }
352
353 rc = vbi_user_map(&addr, fProt, paddrs, size);
354 if (rc != 0)
355 {
356 cmn_err(CE_NOTE, "rtR0MemObjNativeMapUser: vbi failure.\n");
357 rc = VERR_MAP_FAILED;
358 rtR0MemObjDelete(&pMemSolaris->Core);
359 goto l_done;
360 }
361 else
362 rc = VINF_SUCCESS;
363
364 pMemSolaris->Core.u.Mapping.R0Process = (RTR0PROCESS)vbi_proc();
365 pMemSolaris->Core.pv = addr;
366 *ppMem = &pMemSolaris->Core;
367l_done:
368 kmem_free(paddrs, sizeof(uint64_t) * cPages);
369 return rc;
370}
371
372
373int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
374{
375 NOREF(pMem);
376 NOREF(offSub);
377 NOREF(cbSub);
378 NOREF(fProt);
379 return VERR_NOT_SUPPORTED;
380}
381
382
383RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
384{
385 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
386
387 switch (pMemSolaris->Core.enmType)
388 {
389 case RTR0MEMOBJTYPE_PAGE:
390 case RTR0MEMOBJTYPE_LOW:
391 case RTR0MEMOBJTYPE_MAPPING:
392 case RTR0MEMOBJTYPE_LOCK:
393 {
394 uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
395 return vbi_va_to_pa(pb);
396 }
397
398 case RTR0MEMOBJTYPE_CONT:
399 return pMemSolaris->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
400
401 case RTR0MEMOBJTYPE_PHYS:
402 return pMemSolaris->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);
403
404 case RTR0MEMOBJTYPE_PHYS_NC:
405 AssertFailed(/* not implemented */);
406 case RTR0MEMOBJTYPE_RES_VIRT:
407 default:
408 return NIL_RTHCPHYS;
409 }
410}
411
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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