Changeset 4287 in vbox for trunk/src/VBox/Runtime/r0drv/solaris
- Timestamp:
- Aug 22, 2007 2:49:19 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv/solaris
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/solaris/alloc-r0drv-solaris.c
r4178 r4287 21 21 *******************************************************************************/ 22 22 #include "the-solaris-kernel.h" 23 #include <malloc.h>24 23 25 24 #include <iprt/alloc.h> 26 25 #include <iprt/assert.h> 27 26 #include <iprt/types.h> 27 #include <iprt/param.h> 28 28 #include "r0drv/alloc-r0drv.h" 29 29 … … 74 74 RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb) 75 75 { 76 /** @todo: implement RTMemContAlloc in Solaris */ 77 /* ddi_umem_alloc without PAGEABLE flag might produce contiguous physical memory, but 78 the documentation doesn't talk about contiguous at all :( 79 If we can use ddi_umem_alloc we need to keep track of the ddi_umem_cookie 80 which kernel allocates, but the ContFree() function only passes us back 81 the address. Maybe we could for each ContAlloc build a linked list of 82 structures that have the cookie and corresponding virtual address. */ 83 return NULL; 76 AssertPtr(pPhys); 77 Assert(cb > 0); 78 79 /* Allocate physically contiguous page-aligned memory. */ 80 caddr_t virtAddr; 81 int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL); 82 if (rc != DDI_SUCCESS) 83 return NULL; 84 85 *pPhys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr); 86 return virtAddr; 84 87 } 85 88 86 89 RTR0DECL(void) RTMemContFree(void *pv, size_t cb) 87 90 { 88 /** @todo implement RTMemContFree on solaris, see RTMemContAlloc() for details. */89 NOREF(pv);90 91 NOREF(cb); 92 if (pv) 93 i_ddi_mem_free(pv, NULL); 91 94 } -
trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c
r4179 r4287 42 42 /** The core structure. */ 43 43 RTR0MEMOBJINTERNAL Core; 44 #if 0 45 /** Lock for the ring-3 / ring-0 pinned objectes. 46 * This member might not be allocated for some object types. */ 47 KernVMLock_t Lock; 48 /** Array of physical pages. 49 * This array can be 0 in length for some object types. */ 50 KernPageList_t aPages[1]; 51 #endif 44 /** Pointer to kernel memory cookie. */ 45 ddi_umem_cookie_t Cookie; 46 /** Shadow locked pages. */ 47 page_t **ppShadowPages; 52 48 } RTR0MEMOBJSOLARIS, *PRTR0MEMOBJSOLARIS; 53 49 … … 61 57 { 62 58 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem; 63 // int rc;64 59 65 60 switch (pMemSolaris->Core.enmType) 66 61 { 62 case RTR0MEMOBJTYPE_CONT: 63 ddi_mem_free(pMemSolaris->Core.pv); 64 break; 65 66 case RTR0MEMOBJTYPE_PAGE: 67 #if 0 68 ddi_umem_free(pMemSolaris->Cookie); 69 #endif 70 ddi_mem_free(pMemSolaris->Core.pv); 71 break; 72 73 case RTR0MEMOBJTYPE_LOCK: 74 { 75 struct as* addrSpace; 76 if (pMemSolaris->Core.u.Lock.R0Process == NIL_RTR0PROCESS) 77 addrSpace = &kas; 78 else 79 addrSpace = ((proc_t *)pMemSolaris->Core.u.Lock.R0Process)->p_as; 80 81 as_pageunlock(addrSpace, pMemSolaris->ppShadowPages, pMemSolaris->Core.pv, pMemSolaris->Core.cb, S_WRITE); 82 break; 83 } 84 85 case RTR0MEMOBJTYPE_MAPPING: 86 { 87 if (pMemSolaris->Core.u.Mapping.R0Process == NIL_RTR0PROCESS) 88 { 89 /* Kernel process*/ 90 hat_unload(kas.a_hat, (caddr_t)pMemSolaris->Core.pv, pMemSolaris->Core.cb, HAT_UNLOAD_UNLOCK); 91 vmem_xfree(heap32_arena, (caddr_t)pMemSolaris->Core.pv, pMemSolaris->Core.cb); 92 } 93 else 94 { 95 /* User process */ 96 proc_t *p = (proc_t *)pMemSolaris->Core.u.Mapping.R0Process; 97 struct as *useras = p->p_as; 98 hat_unload(useras->a_hat, (caddr_t)pMemSolaris->Core.pv, pMemSolaris->Core.cb, HAT_UNLOAD_UNLOCK); 99 } 100 101 break; 102 } 103 104 /* unused */ 105 case RTR0MEMOBJTYPE_LOW: 67 106 case RTR0MEMOBJTYPE_PHYS: 68 if (!pMemSolaris->Core.pv)69 break;70 71 case RTR0MEMOBJTYPE_MAPPING:72 if (pMemSolaris->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)73 break;74 75 case RTR0MEMOBJTYPE_PAGE:76 case RTR0MEMOBJTYPE_LOW:77 case RTR0MEMOBJTYPE_CONT:78 kmem_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);79 //rc = KernVMFree(pMemSolaris->Core.pv);80 //AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemSolaris->Core.enmType, pMemSolaris->Core.pv, pMemSolaris->Core.cb));81 break;82 83 case RTR0MEMOBJTYPE_LOCK:84 //rc = KernVMUnlock(&pMemSolaris->Lock);85 //AssertMsg(!rc, ("rc=%d\n", rc));86 break;87 88 107 case RTR0MEMOBJTYPE_RES_VIRT: 89 108 default: … … 91 110 return VERR_INTERNAL_ERROR; 92 111 } 93 112 94 113 return VINF_SUCCESS; 95 114 } … … 98 117 int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable) 99 118 { 119 /* Create the object */ 120 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb); 121 if (!pMemSolaris) 122 return VERR_NO_MEMORY; 123 #if 1 124 /* Allocate physically contiguous page-aligned memory. */ 125 caddr_t virtAddr; 126 int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL); 127 if (rc != DDI_SUCCESS) 128 { 129 rtR0MemObjDelete(&pMemSolaris->Core); 130 return VERR_NO_MEMORY; 131 } 132 133 pMemSolaris->Core.pv = virtAddr; 134 pMemSolaris->Core.u.Cont.Phys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr); 135 *ppMem = &pMemSolaris->Core; 136 cmn_err(CE_NOTE, "xAllocPage success physAddr=%p virt=%p\n", PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr), virtAddr); 137 #endif 100 138 #if 0 101 int rc = VERR_NO_PAGE_MEMORY; 102 void *pv = kmem_alloc(cb, KM_SLEEP); 103 if (!pv) 104 return rc; 105 106 IOMemoryDescriptor *pMemDesc = IOMemoryDescriptor::withAddress((vm_address_t)pv, cb, kIODirectionInOut, kernel_task); 107 if (pMemDesc) 108 { 109 /* 110 * Create the IPRT memory object. 111 */ 112 PRTR0MEMOBJDARWIN pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, pv, cb); 113 if (pMemSolaris) 114 { 115 pMemSolaris->pMemDesc = pMemDesc; 116 *ppMem = &pMemSolaris->Core; 117 return VINF_SUCCESS; 118 } 119 120 rc = VERR_NO_MEMORY; 121 pMemDesc->release(); 122 } 123 else 124 rc = VERR_MEMOBJ_INIT_FAILED; 125 IOFreeAligned(pv, cb); 126 #endif 127 return VERR_NOT_IMPLEMENTED; 139 /* Allocate page-aligned kernel memory */ 140 void *pv = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie); 141 if (pv == NULL) 142 { 143 rtR0MemObjDelete(&pMemSolaris->Core); 144 return VERR_NO_MEMORY; 145 } 146 147 pMemSolaris->Core.pv = pv; 148 *ppMem = &pMemSolaris->Core; 149 cmn_err(CE_NOTE, "ddi_umem_alloc, success\n"); 150 #endif 151 return VINF_SUCCESS; 128 152 } 129 153 … … 131 155 int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable) 132 156 { 133 /* create the object */ 134 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOW, NULL, cb); 157 /* Try page alloc first */ 158 int rc = rtR0MemObjNativeAllocPage(ppMem, cb, fExecutable); 159 if (RT_SUCCESS(rc)) 160 { 161 size_t iPage = cb >> PAGE_SHIFT; 162 while (iPage-- > 0) 163 if (rtR0MemObjNativeGetPagePhysAddr(*ppMem, iPage) > (_4G - PAGE_SIZE)) 164 { 165 /* Failed! Fall back to physical contiguous alloc */ 166 cmn_err(CE_NOTE, "4G boundary exceeded\n"); 167 RTR0MemObjFree(*ppMem, false); 168 rc = rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable); 169 break; 170 } 171 } 172 173 return rc; 174 } 175 176 177 int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable) 178 { 179 NOREF(fExecutable); 180 181 /* Create the object */ 182 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_CONT, NULL, cb); 135 183 if (!pMemSolaris) 136 184 return VERR_NO_MEMORY; 137 185 138 /* do the allocation, patiently */ 139 void* pv = kmem_alloc(cb, KM_SLEEP); 140 if (!pv) 186 /* Allocate physically contiguous page-aligned memory. */ 187 caddr_t virtAddr; 188 int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL); 189 if (rc != DDI_SUCCESS) 141 190 { 142 191 rtR0MemObjDelete(&pMemSolaris->Core); 143 192 return VERR_NO_MEMORY; 144 193 } 145 146 /* associate object with allocated memory */ 147 pMemSolaris->Core.pv = pv; /* This would be NULL by rtR0MemObjNew(), set it correctly */ 148 *ppMem = &pMemSolaris->Core; 149 return VINF_SUCCESS; 150 } 151 152 153 int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable) 154 { 155 NOREF(fExecutable); 156 157 #if 0 158 /* create the object. */ 159 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb); 194 195 pMemSolaris->Core.pv = virtAddr; 196 pMemSolaris->Core.u.Cont.Phys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr); 197 *ppMem = &pMemSolaris->Core; 198 return VINF_SUCCESS; 199 } 200 201 202 int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest) 203 { 204 /** @todo rtR0MemObjNativeAllocPhys / solaris */ 205 return rtR0MemObjNativeAllocPhys(ppMem, cb, PhysHighest); 206 } 207 208 209 int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest) 210 { 211 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%VHp\n", PhysHighest), VERR_NOT_IMPLEMENTED); 212 213 return rtR0MemObjNativeAllocCont(ppMem, cb, false); 214 } 215 216 217 int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb) 218 { 219 /* Create the object */ 220 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb); 160 221 if (!pMemSolaris) 161 222 return VERR_NO_MEMORY; 162 163 /* do the allocation. */ 164 ULONG ulPhys = ~0UL; 165 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemSolaris->Core.pv, (PPVOID)&ulPhys, NULL); 166 if (!rc) 167 { 168 Assert(ulPhys != ~0UL); 169 pMemSolaris->Core.u.Cont.Phys = ulPhys; 170 *ppMem = &pMemSolaris->Core; 171 return VINF_SUCCESS; 172 } 173 rtR0MemObjDelete(&pMemSolaris->Core); 174 return RTErrConvertFromOS2(rc); 175 #endif 176 return VERR_NOT_IMPLEMENTED; 177 } 178 179 180 int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest) 181 { 182 #if 0 183 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%VHp\n", PhysHighest), VERR_NOT_IMPLEMENTED); 184 185 /* create the object. */ 186 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb); 187 if (!pMemSolaris) 188 return VERR_NO_MEMORY; 189 190 /* do the allocation. */ 191 ULONG ulPhys = ~0UL; 192 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMemSolaris->Core.pv, (PPVOID)&ulPhys, NULL); 193 if (!rc) 194 { 195 Assert(ulPhys != ~0UL); 196 pMemSolaris->Core.u.Phys.fAllocated = true; 197 pMemSolaris->Core.u.Phys.PhysBase = ulPhys; 198 *ppMem = &pMemSolaris->Core; 199 return VINF_SUCCESS; 200 } 201 rtR0MemObjDelete(&pMemSolaris->Core); 202 return RTErrConvertFromOS2(rc); 203 #endif 204 return VERR_NOT_IMPLEMENTED; 205 } 206 207 208 int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest) 209 { 210 return VERR_NOT_IMPLEMENTED; 211 } 212 213 214 int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb) 215 { 216 #if 0 217 /* create the object. */ 218 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb); 219 if (!pMemSolaris) 220 return VERR_NO_MEMORY; 221 222 /* there is no allocation here, right? it needs to be mapped somewhere first. */ 223 224 /* @todo validate Phys as a proper physical address */ 225 226 /* There is no allocation here, it needs to be mapped somewhere first */ 223 227 pMemSolaris->Core.u.Phys.fAllocated = false; 224 228 pMemSolaris->Core.u.Phys.PhysBase = Phys; 225 229 *ppMem = &pMemSolaris->Core; 226 230 return VINF_SUCCESS; 227 #endif 231 } 232 233 234 int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process) 235 { 236 /* Create the object */ 237 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void*)R3Ptr, cb); 238 if (!pMemSolaris) 239 return VERR_NO_MEMORY; 240 241 proc_t *userProcess = curproc; 242 if (R0Process != NIL_RTR0PROCESS) 243 userProcess = (proc_t *)R0Process; 244 245 struct as* userAddrSpace = userProcess->p_as; 246 caddr_t userAddr = (caddr_t)((uintptr_t)R3Ptr & (uintptr_t)PAGEMASK); 247 page_t **ppl; 248 249 int rc = as_pagelock(userAddrSpace, &ppl, userAddr, cb, S_WRITE); 250 if (rc != 0) 251 return VERR_NO_MEMORY; 252 253 pMemSolaris->Core.u.Lock.R0Process = (RTR0PROCESS)userProcess; 254 pMemSolaris->ppShadowPages = ppl; 255 *ppMem = &pMemSolaris->Core; 256 257 return VINF_SUCCESS; 258 259 #if 0 260 /* Lock down the physical pages of current process' virtual address space */ 261 int rc = ddi_umem_lock(pv, cb, DDI_UMEMLOCK_WRITE, &pMemSolaris->Cookie); 262 if (rc != 0) 263 { 264 rtR0MemObjDelete(&pMemSolaris->Core); 265 return VERR_NO_MEMORY; /** @todo fix mach -> vbox error conversion for Solaris. */ 266 } 267 268 pMemSolaris->Core.u.Lock.R0Process = R0Process; 269 *ppMem = &pMemSolaris->Core; 270 return VINF_SUCCESS; 271 #endif 272 } 273 274 275 int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb) 276 { 277 /* Create the object */ 278 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb); 279 if (!pMemSolaris) 280 return VERR_NO_MEMORY; 281 282 caddr_t userAddr = (caddr_t)((uintptr_t)pv & (uintptr_t)PAGEMASK); 283 page_t **ppl; 284 285 int rc = as_pagelock(&kas, &ppl, userAddr, cb, S_WRITE); 286 if (rc != 0) 287 return VERR_NO_MEMORY; 288 289 pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS; /* means kernel, see rtR0MemObjNativeFree() */ 290 pMemSolaris->ppShadowPages = ppl; 291 *ppMem = &pMemSolaris->Core; 292 293 return VINF_SUCCESS; 294 } 295 296 297 int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment) 298 { 228 299 return VERR_NOT_IMPLEMENTED; 229 300 } 230 301 231 302 232 int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process) 233 { 234 #if 0 235 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED); 236 237 /* create the object. */ 238 const ULONG cPages = cb >> PAGE_SHIFT; 239 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb); 240 if (!pMemSolaris) 241 return VERR_NO_MEMORY; 242 243 /* lock it. */ 244 ULONG cPagesRet = cPages; 245 int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, (void *)R3Ptr, cb, &pMemSolaris->Lock, &pMemSolaris->aPages[0], &cPagesRet); 246 if (!rc) 247 { 248 rtR0MemObjFixPageList(&pMemSolaris->aPages[0], cPages, cPagesRet); 249 pMemSolaris->Core.u.Lock.R0Process = R0Process; 250 *ppMem = &pMemSolaris->Core; 251 return VINF_SUCCESS; 252 } 253 rtR0MemObjDelete(&pMemSolaris->Core); 254 return RTErrConvertFromOS2(rc); 255 #endif 303 int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process) 304 { 256 305 return VERR_NOT_IMPLEMENTED; 257 306 } 258 307 259 260 int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb)261 {262 #if 0263 /* create the object. */264 const ULONG cPages = cb >> PAGE_SHIFT;265 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);266 if (!pMemSolaris)267 return VERR_NO_MEMORY;268 269 /* lock it. */270 ULONG cPagesRet = cPages;271 int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemSolaris->Lock, &pMemSolaris->aPages[0], &cPagesRet);272 if (!rc)273 {274 rtR0MemObjFixPageList(&pMemSolaris->aPages[0], cPages, cPagesRet);275 pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;276 *ppMem = &pMemSolaris->Core;277 return VINF_SUCCESS;278 }279 rtR0MemObjDelete(&pMemSolaris->Core);280 return RTErrConvertFromOS2(rc);281 #endif282 return VERR_NOT_IMPLEMENTED;283 }284 285 286 int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)287 {288 return VERR_NOT_IMPLEMENTED;289 }290 291 292 int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)293 {294 return VERR_NOT_IMPLEMENTED;295 }296 297 298 308 int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, unsigned fProt) 299 309 { 300 AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED); 301 302 #if 0 303 /** @todo finish the implementation. */ 304 310 PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap; 311 size_t size = P2ROUNDUP(pMemToMapSolaris->Core.cb, PAGE_SIZE); 312 void* pv = pMemToMapSolaris->Core.pv; 313 314 void* kernVirtAddr = vmem_xalloc(heap32_arena, size, PAGE_SIZE, 0, PAGE_SIZE, NULL, 0, VM_SLEEP); 315 if (kernVirtAddr == NULL) 316 return VERR_NO_MEMORY; 317 318 hat_devload(kas.a_hat, (caddr_t)kernVirtAddr, size, hat_getpfnum(kas.a_hat, pv), PROT_READ | PROT_WRITE | PROT_EXEC, 319 HAT_STRICTORDER | HAT_LOAD_NOCONSIST | HAT_LOAD_LOCK); 320 321 /* Create the mapping object */ 322 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, 323 kernVirtAddr, pMemToMapSolaris->Core.cb); 324 if (pMemSolaris == NULL) 325 { 326 hat_unload(kas.a_hat, (caddr_t)kernVirtAddr, size, HAT_UNLOAD_UNLOCK); 327 vmem_xfree(heap32_arena, kernVirtAddr, size); 328 return VERR_NO_MEMORY; 329 } 330 331 pMemSolaris->Core.u.Mapping.R0Process = NIL_RTR0PROCESS; /* NIL_RTR0PROCESS means kernel process */ 332 *ppMem = &pMemSolaris->Core; 333 return VINF_SUCCESS; 334 } 335 336 337 int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process) 338 { 339 PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap; 340 size_t size = P2ROUNDUP(pMemToMapSolaris->Core.cb, PAGE_SIZE); 341 proc_t *userproc = (proc_t *)R0Process; 342 struct as *useras = userproc->p_as; 343 void *pv = pMemToMapSolaris->Core.pv; 344 pfn_t pfnum = hat_getpfnum(kas.a_hat, pv); 305 345 int rc; 306 void *pvR0 = NULL; 307 PRTR0MEMOBJSOLARIS pMemToMapOs2 = (PRTR0MEMOBJSOLARIS)pMemToMap; 308 switch (pMemToMapOs2->Core.enmType) 309 { 310 /* 311 * These has kernel mappings. 312 */ 346 347 void* kernVirtAddr = vmem_xalloc(heap32_arena, size, PAGE_SIZE, 0, PAGE_SIZE, NULL, 0, VM_SLEEP); 348 if (kernVirtAddr == NULL) 349 return VERR_NO_MEMORY; 350 351 cmn_err(CE_NOTE, "vmem_xalloc successful.\n"); 352 353 /* Wrong ones to use: as_map() */ 354 hat_devload(kas.a_hat, (caddr_t)kernVirtAddr, size, pfnum, PROT_READ | PROT_WRITE | PROT_EXEC, 355 HAT_STRICTORDER | HAT_LOAD_NOCONSIST | HAT_LOAD_LOCK); 356 357 cmn_err(CE_NOTE, "hat_devload successful.\n"); 358 359 /* Create the mapping object */ 360 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, 361 pv, pMemToMapSolaris->Core.cb); 362 if (pMemSolaris == NULL) 363 { 364 /* @todo cleanup */ 365 return VERR_NO_MEMORY; 366 } 367 368 pMemSolaris->Core.u.Mapping.R0Process = R0Process; 369 *ppMem = &pMemSolaris->Core; 370 return VINF_SUCCESS; 371 } 372 373 374 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage) 375 { 376 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem; 377 378 switch (pMemSolaris->Core.enmType) 379 { 380 case RTR0MEMOBJTYPE_LOCK: 381 { 382 /* @todo figure this one out */ 383 return NIL_RTHCPHYS; 384 } 385 313 386 case RTR0MEMOBJTYPE_PAGE: 314 387 case RTR0MEMOBJTYPE_LOW: 315 case RTR0MEMOBJTYPE_CONT:316 pvR0 = pMemToMapOs2->Core.pv;317 break;318 319 case RTR0MEMOBJTYPE_PHYS:320 pvR0 = pMemToMapOs2->Core.pv;321 if (!pvR0)322 {323 /* no ring-0 mapping, so allocate a mapping in the process. */324 AssertMsgReturn(uAlignment == PAGE_SIZE, ("%#zx\n", uAlignment), VERR_NOT_SUPPORTED);325 AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);326 Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);327 ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;328 rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS, &pvR0, (PPVOID)&ulPhys, NULL);329 if (rc)330 return RTErrConvertFromOS2(rc);331 pMemToMapOs2->Core.pv = pvR0;332 }333 break;334 335 case RTR0MEMOBJTYPE_LOCK:336 if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)337 return VERR_NOT_SUPPORTED; /** @todo implement this... */338 pvR0 = pMemToMapOs2->Core.pv;339 break;340 341 case RTR0MEMOBJTYPE_RES_VIRT:342 case RTR0MEMOBJTYPE_MAPPING:343 default:344 AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));345 return VERR_INTERNAL_ERROR;346 }347 348 /*349 * Create a dummy mapping object for it.350 *351 * All mappings are read/write/execute in OS/2 and there isn't352 * any cache options, so sharing is ok. And the main memory object353 * isn't actually freed until all the mappings have been freed up354 * (reference counting).355 */356 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);357 if (pMemSolaris)358 {359 pMemSolaris->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;360 *ppMem = &pMemSolaris->Core;361 return VINF_SUCCESS;362 }363 return VERR_NO_MEMORY;364 #endif365 return VERR_NOT_IMPLEMENTED;366 }367 368 /*369 * Maps a memory object into user virtual address space in the current process.370 */371 int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)372 {373 #if 0374 int rc = VERR_INVALID_PARAMETER;375 376 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);377 AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);378 379 PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;380 caddr_t virtAddr = mmap(pMemToMapSolaris->Core.pv, pMemToMapSolaris->Core.cb, fProt, MAP_ANON, -1, 0);381 382 if (virtAddr != MAP_FAILED)383 {384 /*385 * Create the IPRT memory object.386 */387 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING,388 virtAddr, pMemToMapSolaris->Core.cb);389 if (pMemSolaris)390 388 { 391 pMemSolaris->Core.u.Mapping.R0Process = R0Process; 392 *ppMem = &pMemSolaris->Core; 393 return VINF_SUCCESS; 389 uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT); 390 return PAGE_SIZE * hat_getpfnum(kas.a_hat, pb); 394 391 } 395 396 munmap(virtAddr, pMemSolaris->Core.cb);397 rc = VERR_NO_MEMORY;398 }399 else400 rc = VERR_MAP_FAILED;401 402 return rc;403 #endif404 return VERR_NOT_IMPLEMENTED;405 }406 407 408 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage)409 {410 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;411 412 switch (pMemSolaris->Core.enmType)413 {414 case RTR0MEMOBJTYPE_PAGE:415 case RTR0MEMOBJTYPE_LOW:416 case RTR0MEMOBJTYPE_LOCK:417 // return pMemSolaris->aPages[iPage].Addr;418 return NIL_RTHCPHYS;419 392 420 393 case RTR0MEMOBJTYPE_CONT: -
trunk/src/VBox/Runtime/r0drv/solaris/process-r0drv-solaris.c
r4071 r4287 26 26 RTDECL(RTPROCESS) RTProcSelf(void) 27 27 { 28 struct proc *pCurProc = curproc; 29 struct pid *pPidInfo = pCurProc->p_pidp; 30 28 struct pid *pPidInfo = curproc->p_pidp; 31 29 return pPidInfo->pid_id; 32 30 } -
trunk/src/VBox/Runtime/r0drv/solaris/semevent-r0drv-solaris.c
r4178 r4287 15 15 * be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 19 17 20 18 /******************************************************************************* … … 155 153 else 156 154 { 157 unsigned long timeout;158 drv_getparm(LBOLT, &timeout);159 160 155 /* 161 156 * Translate milliseconds into ticks and go to sleep. 162 157 */ 163 158 int cTicks; 159 unsigned long timeout; 164 160 if (cMillies != RT_INDEFINITE_WAIT) 165 161 cTicks = drv_usectohz((clock_t)(cMillies * 1000L)); -
trunk/src/VBox/Runtime/r0drv/solaris/semfastmutex-r0drv-solaris.c
r4178 r4287 35 35 *******************************************************************************/ 36 36 /** 37 * Wrapper for the FreeBSD (sleep)mutex.37 * Wrapper for the Solaris mutex. 38 38 */ 39 39 typedef struct RTSEMFASTMUTEXINTERNAL -
trunk/src/VBox/Runtime/r0drv/solaris/the-solaris-kernel.h
r4178 r4287 21 21 #include <sys/kmem.h> 22 22 #include <sys/types.h> 23 #include <sys/sunddi.h>24 #include <sys/ddi.h>25 23 #include <sys/mman.h> 26 24 #include <sys/thread.h> … … 30 28 #include <sys/schedctl.h> 31 29 #include <sys/time.h> 30 #include <sys/sysmacros.h> 31 #include <vm/hat.h> 32 #include <vm/seg_kmem.h> 33 #include <sys/ddi.h> 34 #include <sys/sunddi.h> 35 36 #include <iprt/param.h> /* for PAGE_SIZE */ 37 38 /** 39 * Used in alloc-r0drv-solaris.c and in memobj-r0drv-solaris.cpp 40 * Basically needs to be used anywhere where contiguous allocation 41 * is needed. 42 * 43 * @todo r=bird: This should be moved out of this header as it will probably 44 * be instantiated in all the files using this header and 45 * the compiler will bitch about it not being used. 46 */ 47 static struct ddi_dma_attr g_SolarisX86PhysMemLimits = 48 { 49 DMA_ATTR_V0, /* Version Number */ 50 (uint64_t)0, /* lower limit */ 51 (uint64_t)0xffffffff, /* high limit (32-bit PA) */ 52 (uint64_t)0xffffffff, /* counter limit */ 53 (uint64_t)PAGE_SIZE, /* alignment */ 54 (uint64_t)PAGE_SIZE, /* burst size */ 55 (uint64_t)PAGE_SIZE, /* effective DMA size */ 56 (uint64_t)0xffffffff, /* max DMA xfer size */ 57 (uint64_t)0xffffffff, /* segment boundary */ 58 512, /* s/g length */ 59 1, /* device granularity */ 60 0 /* bus-specific flags */ 61 }; 32 62 33 63 /* commented for now -
trunk/src/VBox/Runtime/r0drv/solaris/thread-r0drv-solaris.c
r4178 r4287 47 47 else 48 48 cTicks = 0; 49 49 50 #if 0 50 51 timeout = ddi_get_lbolt(); … … 56 57 cv_init(&cnd, "IPRT Sleep CV", CV_DRIVER, NULL); 57 58 mutex_enter(&mtx); 58 cv_timedwait (&cnd, &mtx, 9000 *timeout);59 cv_timedwait (&cnd, &mtx, timeout); 59 60 mutex_exit(&mtx); 60 61 cv_destroy(&cnd); -
trunk/src/VBox/Runtime/r0drv/solaris/time-r0drv-solaris.c
r4179 r4287 26 26 27 27 28 /**29 * Gets the current nanosecond timestamp.30 *31 * @returns nanosecond timestamp.32 */33 28 RTDECL(uint64_t) RTTimeNanoTS(void) 34 29 { … … 37 32 38 33 39 /**40 * Gets the current millisecond timestamp.41 *42 * @returns millisecond timestamp.43 */44 34 RTDECL(uint64_t) RTTimeMilliTS(void) 45 35 { 46 return RTTimeNanoTS() / 1000 ;36 return RTTimeNanoTS() / 1000000; 47 37 } 48 38 49 39 50 /**51 * Gets the current nanosecond timestamp.52 *53 * This differs from RTTimeNanoTS in that it will use system APIs and not do any54 * resolution or performance optimizations.55 *56 * @returns nanosecond timestamp.57 */58 40 RTDECL(uint64_t) RTTimeSystemNanoTS(void) 59 41 { … … 62 44 63 45 64 /**65 * Gets the current millisecond timestamp.66 *67 * This differs from RTTimeNanoTS in that it will use system APIs and not do any68 * resolution or performance optimizations.69 *70 * @returns millisecond timestamp.71 */72 46 RTDECL(uint64_t) RTTimeSystemMilliTS(void) 73 47 { 74 return RTTime MilliTS();48 return RTTimeNanoTS() / 1000000; 75 49 } 76 50 77 51 78 /**79 * Gets the current system time.80 *81 * @returns pTime.82 * @param pTime Where to store the time.83 */84 52 RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime) 85 53 {
Note:
See TracChangeset
for help on using the changeset viewer.