- Timestamp:
- Jun 13, 2009 8:13:33 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/memobj.h
r20374 r20525 300 300 RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process); 301 301 302 /** 303 * Change the page level protection of one or more pages in a memory object. 304 * 305 * @returns IPRT status code. 306 * @retval VERR_NOT_SUPPORTED if the OS doesn't provide any way to manipulate 307 * page level protection. The caller must handle this status code 308 * gracefully. (Note that it may also occur if the implementation is 309 * missing, in which case just go ahead and implement it.) 310 * 311 * @param hMemObj Memory object handle. 312 * @param offSub Offset into the memory object. Must be page aligned. 313 * @param cbSub Number of bytes to change the protection of. Must be 314 * page aligned. 315 * @param fProt Combination of RTMEM_PROT_* flags. 316 */ 317 RTR0DECL(int) RTR0MemObjProtect(RTR0MEMOBJ hMemObj, size_t offSub, size_t cbSub, uint32_t fProt); 318 302 319 #endif /* IN_RING0 */ 303 320 -
trunk/src/VBox/Runtime/include/internal/memobj.h
r20374 r20525 90 90 91 91 92 /** @name RTR0MEMOBJINTERNAL::fFlags 93 * @{ */ 94 /** Page level protection was changed. */ 95 #define RTR0MEMOBJ_FLAGS_PROT_CHANGED RT_BIT_32(0) 96 /** @} */ 97 98 92 99 typedef struct RTR0MEMOBJINTERNAL *PRTR0MEMOBJINTERNAL; 93 100 typedef struct RTR0MEMOBJINTERNAL **PPRTR0MEMOBJINTERNAL; … … 111 118 /** The type of allocation. */ 112 119 RTR0MEMOBJTYPE enmType; 120 /** Flags, RTR0MEMOBJ_FLAGS_*. */ 121 uint32_t fFlags; 113 122 /** The size of the memory allocated, pinned down, or mapped. */ 114 123 size_t cb; … … 222 231 { 223 232 case RTR0MEMOBJTYPE_MAPPING: 233 return true; 234 235 default: 236 return false; 237 } 238 } 239 240 241 /** 242 * Checks page level protection can be changed on this object. 243 * 244 * @returns true / false. 245 * @param pMem The ring-0 memory object handle. 246 */ 247 DECLINLINE(bool) rtR0MemObjIsProtectable(PRTR0MEMOBJINTERNAL pMem) 248 { 249 switch (pMem->enmType) 250 { 251 case RTR0MEMOBJTYPE_MAPPING: 252 case RTR0MEMOBJTYPE_PAGE: 253 case RTR0MEMOBJTYPE_LOW: 254 case RTR0MEMOBJTYPE_CONT: 224 255 return true; 225 256 … … 411 442 412 443 /** 444 * Change the page level protection of one or more pages in a memory object. 445 * 446 * @returns IPRT status code. 447 * @retval VERR_NOT_SUPPORTED see RTR0MemObjProtect. 448 * 449 * @param pMem The memory object. 450 * @param offSub Offset into the memory object. Page aligned. 451 * @param cbSub Number of bytes to change the protection of. Page 452 * aligned. 453 * @param fProt Combination of RTMEM_PROT_* flags. 454 */ 455 int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt); 456 457 /** 413 458 * Get the physical address of an page in the memory object. 414 459 * -
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.