Changeset 20525 in vbox for trunk/src/VBox/Runtime/r0drv
- Timestamp:
- Jun 13, 2009 8:13:33 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp
r20507 r20525 92 92 } 93 93 } 94 95 96 /** 97 * Gets the virtual memory map the specified object is mapped into. 98 * 99 * @returns VM map handle on success, NULL if no map. 100 * @param pMem The memory object. 101 */ 102 DECLINLINE(vm_map_t) rtR0MemObjDarwinGetMap(PRTR0MEMOBJINTERNAL pMem) 103 { 104 switch (pMem->enmType) 105 { 106 case RTR0MEMOBJTYPE_PAGE: 107 case RTR0MEMOBJTYPE_LOW: 108 case RTR0MEMOBJTYPE_CONT: 109 return kernel_map; 110 111 case RTR0MEMOBJTYPE_PHYS: 112 case RTR0MEMOBJTYPE_PHYS_NC: 113 return NULL; /* pretend these have no mapping atm. */ 114 115 case RTR0MEMOBJTYPE_LOCK: 116 return pMem->u.Lock.R0Process == NIL_RTR0PROCESS 117 ? kernel_map 118 : get_task_map((task_t)pMem->u.Lock.R0Process); 119 120 case RTR0MEMOBJTYPE_RES_VIRT: 121 return pMem->u.ResVirt.R0Process == NIL_RTR0PROCESS 122 ? kernel_map 123 : get_task_map((task_t)pMem->u.ResVirt.R0Process); 124 125 case RTR0MEMOBJTYPE_MAPPING: 126 return pMem->u.Mapping.R0Process == NIL_RTR0PROCESS 127 ? kernel_map 128 : get_task_map((task_t)pMem->u.Mapping.R0Process); 129 130 default: 131 return NULL; 132 } 133 } 134 135 #if 0 /* not necessary after all*/ 136 /* My vm_map mockup. */ 137 struct my_vm_map 138 { 139 struct { char pad[8]; } lock; 140 struct my_vm_map_header 141 { 142 struct vm_map_links 143 { 144 void *prev; 145 void *next; 146 vm_map_offset_t start; 147 vm_map_offset_t end; 148 } links; 149 int nentries; 150 boolean_t entries_pageable; 151 } hdr; 152 pmap_t pmap; 153 vm_map_size_t size; 154 }; 155 156 157 /** 158 * Gets the minimum map address, this is similar to get_map_min. 159 * 160 * @returns The start address of the map. 161 * @param pMap The map. 162 */ 163 static vm_map_offset_t rtR0MemObjDarwinGetMapMin(vm_map_t pMap) 164 { 165 /* lazy discovery of the correct offset. The apple guys is a wonderfully secretive bunch. */ 166 static int32_t volatile s_offAdjust = INT32_MAX; 167 int32_t off = s_offAdjust; 168 if (off == INT32_MAX) 169 { 170 for (off = 0; ; off += sizeof(pmap_t)) 171 { 172 if (*(pmap_t *)((uint8_t *)kernel_map + off) == kernel_pmap) 173 break; 174 AssertReturn(off <= RT_MAX(RT_OFFSETOF(struct my_vm_map, pmap) * 4, 1024), 0x1000); 175 } 176 ASMAtomicWriteS32(&s_offAdjust, off - RT_OFFSETOF(struct my_vm_map, pmap)); 177 } 178 179 /* calculate it. */ 180 struct my_vm_map *pMyMap = (struct my_vm_map *)((uint8_t *)pMap + off); 181 return pMyMap->hdr.links.start; 182 } 183 #endif /* unused */ 94 184 95 185 #ifdef RT_STRICT … … 813 903 814 904 905 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 906 { 907 /* Get the map for the object. */ 908 vm_map_t pVmMap = rtR0MemObjDarwinGetMap(pMem); 909 if (!pVmMap) 910 return VERR_NOT_SUPPORTED; 911 912 /* Convert the protection. */ 913 vm_prot_t fMachProt; 914 switch (fProt) 915 { 916 case RTMEM_PROT_NONE: 917 fMachProt = VM_PROT_NONE; 918 break; 919 case RTMEM_PROT_READ: 920 fMachProt = VM_PROT_READ; 921 break; 922 case RTMEM_PROT_READ | RTMEM_PROT_WRITE: 923 fMachProt = VM_PROT_READ | VM_PROT_WRITE; 924 break; 925 case RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC: 926 fMachProt = VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE; 927 break; 928 case RTMEM_PROT_WRITE | RTMEM_PROT_EXEC: 929 fMachProt = VM_PROT_WRITE | VM_PROT_EXECUTE; 930 break; 931 case RTMEM_PROT_EXEC: 932 fMachProt = VM_PROT_EXECUTE; 933 break; 934 default: 935 AssertFailedReturn(VERR_INVALID_PARAMETER); 936 } 937 938 /* do the job. */ 939 vm_offset_t Start = (uintptr_t)pMem->pv + offSub; 940 kern_return_t krc = vm_protect(pVmMap, 941 Start, 942 cbSub, 943 false, 944 fMachProt); 945 if (krc != KERN_SUCCESS) 946 return RTErrConvertFromDarwinKern(krc); 947 return VINF_SUCCESS; 948 } 949 950 815 951 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 816 952 { -
trunk/src/VBox/Runtime/r0drv/darwin/the-darwin-kernel.h
r20374 r20525 88 88 89 89 RT_C_DECLS_BEGIN 90 90 91 /* mach/vm_types.h */ 91 92 typedef struct pmap *pmap_t; … … 116 117 /* osfmk/i386/cpu_number.h */ 117 118 extern int cpu_number(void); 119 120 /* osfmk/vm/vm_user.c */ 121 extern kern_return_t vm_protect(vm_map_t, vm_offset_t, vm_size_t, boolean_t, vm_prot_t); 118 122 119 123 /* i386/machine_routines.h */ -
trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
r19673 r20525 682 682 683 683 684 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 685 { 686 NOREF(pMem); 687 NOREF(offSub); 688 NOREF(cbSub); 689 NOREF(fProt); 690 return VERR_NOT_SUPPORTED; 691 } 692 693 684 694 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 685 695 { -
trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
r18522 r20525 39 39 #include <iprt/assert.h> 40 40 #include <iprt/log.h> 41 #include <iprt/process.h> 41 42 #include <iprt/string.h> 42 #include <iprt/process.h>43 43 #include "internal/memobj.h" 44 44 … … 1166 1166 1167 1167 1168 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 1169 { 1170 NOREF(pMem); 1171 NOREF(offSub); 1172 NOREF(cbSub); 1173 NOREF(fProt); 1174 return VERR_NOT_SUPPORTED; 1175 } 1176 1177 1168 1178 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 1169 1179 { -
trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp
r15718 r20525 35 35 #define LOG_GROUP RTLOGGROUP_DEFAULT ///@todo RTLOGGROUP_MEM 36 36 #include <iprt/memobj.h> 37 37 38 #include <iprt/alloc.h> 38 #include <iprt/ process.h>39 #include <iprt/asm.h> 39 40 #include <iprt/assert.h> 40 41 #include <iprt/err.h> 41 42 #include <iprt/log.h> 42 43 #include <iprt/param.h> 44 #include <iprt/process.h> 45 43 46 #include "internal/memobj.h" 44 47 … … 72 75 pNew->cbSelf = (uint32_t)cbSelf; 73 76 pNew->enmType = enmType; 77 pNew->fFlags = 0; 74 78 pNew->cb = cb; 75 79 pNew->pv = pv; … … 90 94 if (pMem) 91 95 { 92 pMem->u32Magic++;96 ASMAtomicUoWriteU32(&pMem->u32Magic, ~RTR0MEMOBJ_MAGIC); 93 97 pMem->enmType = RTR0MEMOBJTYPE_END; 94 98 RTMemFree(pMem); … … 818 822 } 819 823 824 825 RTR0DECL(int) RTR0MemObjProtect(RTR0MEMOBJ hMemObj, size_t offSub, size_t cbSub, uint32_t fProt) 826 { 827 PRTR0MEMOBJINTERNAL pMemObj; 828 int rc; 829 830 /* sanity checks. */ 831 pMemObj = (PRTR0MEMOBJINTERNAL)hMemObj; 832 AssertPtrReturn(pMemObj, VERR_INVALID_HANDLE); 833 AssertReturn(pMemObj->u32Magic == RTR0MEMOBJ_MAGIC, VERR_INVALID_HANDLE); 834 AssertReturn(pMemObj->enmType > RTR0MEMOBJTYPE_INVALID && pMemObj->enmType < RTR0MEMOBJTYPE_END, VERR_INVALID_HANDLE); 835 AssertReturn(rtR0MemObjIsProtectable(pMemObj), VERR_INVALID_PARAMETER); 836 AssertReturn(!(offSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER); 837 AssertReturn(offSub < pMemObj->cb, VERR_INVALID_PARAMETER); 838 AssertReturn(!(cbSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER); 839 AssertReturn(cbSub <= pMemObj->cb, VERR_INVALID_PARAMETER); 840 AssertReturn(offSub + cbSub <= pMemObj->cb, VERR_INVALID_PARAMETER); 841 AssertReturn(!(fProt & ~(RTMEM_PROT_NONE | RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC)), VERR_INVALID_PARAMETER); 842 843 /* do the job */ 844 rc = rtR0MemObjNativeProtect(pMemObj, offSub, cbSub, fProt); 845 if (RT_SUCCESS(rc)) 846 pMemObj->fFlags |= RTR0MEMOBJ_FLAGS_PROT_CHANGED; /* record it */ 847 848 return rc; 849 } -
trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp
r14824 r20525 761 761 762 762 763 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 764 { 765 NOREF(pMem); 766 NOREF(offSub); 767 NOREF(cbSub); 768 NOREF(fProt); 769 return VERR_NOT_SUPPORTED; 770 } 771 772 763 773 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 764 774 { -
trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp
r14824 r20525 468 468 469 469 470 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 471 { 472 NOREF(pMem); 473 NOREF(offSub); 474 NOREF(cbSub); 475 NOREF(fProt); 476 return VERR_NOT_SUPPORTED; 477 } 478 479 470 480 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 471 481 { -
trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c
r16722 r20525 401 401 402 402 403 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 404 { 405 NOREF(pMem); 406 NOREF(offSub); 407 NOREF(cbSub); 408 NOREF(fProt); 409 return VERR_NOT_SUPPORTED; 410 } 411 412 403 413 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 404 414 { -
trunk/src/VBox/Runtime/r0drv/solaris/vbi/memobj-r0drv-solaris.c
r20477 r20525 323 323 324 324 325 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt) 326 { 327 NOREF(pMem); 328 NOREF(offSub); 329 NOREF(cbSub); 330 NOREF(fProt); 331 return VERR_NOT_SUPPORTED; 332 } 333 334 325 335 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage) 326 336 {
Note:
See TracChangeset
for help on using the changeset viewer.