- Timestamp:
- Jan 26, 2020 2:17:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp
r78120 r82860 48 48 #include "internal/memobj.h" 49 49 50 51 /********************************************************************************************************************************* 52 * Defined Constants And Macros * 53 *********************************************************************************************************************************/ 54 #define MY_PRINTF(...) do { printf(__VA_ARGS__); kprintf(__VA_ARGS__); } while (0) 55 50 56 /*#define USE_VM_MAP_WIRE - may re-enable later when non-mapped allocations are added. */ 51 57 … … 241 247 } 242 248 else 243 printf("rtR0MemObjDarwinReadPhys: createMappingInTask failed; HCPhys=%llx\n", HCPhys);249 MY_PRINTF("rtR0MemObjDarwinReadPhys: createMappingInTask failed; HCPhys=%llx\n", HCPhys); 244 250 245 251 pMemDesc->release(); 246 252 } 247 253 else 248 printf("rtR0MemObjDarwinReadPhys: withAddressRanges failed; HCPhys=%llx\n", HCPhys);254 MY_PRINTF("rtR0MemObjDarwinReadPhys: withAddressRanges failed; HCPhys=%llx\n", HCPhys); 249 255 } 250 256 … … 281 287 if (!(u64.u & X86_PML4E_P)) 282 288 { 283 printf("rtR0MemObjDarwinGetPTE: %p -> PML4E !p\n", pvPage);289 MY_PRINTF("rtR0MemObjDarwinGetPTE: %p -> PML4E !p\n", pvPage); 284 290 return 0; 285 291 } … … 289 295 if (!(u64.u & X86_PDPE_P)) 290 296 { 291 printf("rtR0MemObjDarwinGetPTE: %p -> PDPTE !p\n", pvPage);297 MY_PRINTF("rtR0MemObjDarwinGetPTE: %p -> PDPTE !p\n", pvPage); 292 298 return 0; 293 299 } … … 299 305 if (!(u64.u & X86_PDE_P)) 300 306 { 301 printf("rtR0MemObjDarwinGetPTE: %p -> PDE !p\n", pvPage);307 MY_PRINTF("rtR0MemObjDarwinGetPTE: %p -> PDE !p\n", pvPage); 302 308 return 0; 303 309 } … … 309 315 if (!(u64.u & X86_PTE_P)) 310 316 { 311 printf("rtR0MemObjDarwinGetPTE: %p -> PTE !p\n", pvPage);317 MY_PRINTF("rtR0MemObjDarwinGetPTE: %p -> PTE !p\n", pvPage); 312 318 return 0; 313 319 } … … 904 910 if (pMemToMapDarwin->pMemDesc) 905 911 { 906 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 912 /* The kIOMapPrefault option was added in 10.10.0; causes PTEs to be populated with 913 INTEL_PTE_WIRED to be set, just like we desire (see further down). */ 914 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 907 915 IOMemoryMap *pMemMap = pMemToMapDarwin->pMemDesc->createMappingInTask(kernel_task, 908 916 0, 909 kIOMapAnywhere | kIOMapDefaultCache, 917 kIOMapAnywhere | kIOMapDefaultCache | kIOMapPrefault, 918 offSub, 919 cbSub); 920 #elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 921 static uint32_t volatile s_fOptions = UINT32_MAX; 922 uint32_t fOptions = s_fOptions; 923 if (RT_UNLIKELY(fOptions == UINT32_MAX)) 924 s_fOptions = fOptions = version_major >= 14 ? 0x10000000 /*kIOMapPrefault*/ : 0; /* Since 10.10.0. */ 925 IOMemoryMap *pMemMap = pMemToMapDarwin->pMemDesc->createMappingInTask(kernel_task, 926 0, 927 kIOMapAnywhere | kIOMapDefaultCache | fOptions, 910 928 offSub, 911 929 cbSub); … … 921 939 IOVirtualAddress VirtAddr = pMemMap->getVirtualAddress(); 922 940 void *pv = (void *)(uintptr_t)VirtAddr; 923 if ((uintptr_t)pv == VirtAddr )941 if ((uintptr_t)pv == VirtAddr && pv != NULL) 924 942 { 925 //addr64_t Addr = pMemToMapDarwin->pMemDesc->getPhysicalSegment64(offSub, NULL); 926 //printf("pv=%p: %8llx %8llx\n", pv, rtR0MemObjDarwinGetPTE(pv), Addr); 943 //#ifdef __LP64__ 944 // addr64_t Addr = pMemToMapDarwin->pMemDesc->getPhysicalSegment(offSub, NULL, kIOMemoryMapperNone); 945 //#else 946 // addr64_t Addr = pMemToMapDarwin->pMemDesc->getPhysicalSegment64(offSub, NULL); 947 //#endif 948 // MY_PRINTF("pv=%p: %8llx %8llx\n", pv, rtR0MemObjDarwinGetPTE(pv), Addr); 927 949 928 950 // /* … … 945 967 // if (IORet == kIOReturnSuccess) 946 968 // { 947 /* HACK ALERT! */ 948 rtR0MemObjDarwinTouchPages(pv, cbSub); 969 /* HACK ALERT! On kernels older than 10.10 (xnu version 14), we need to fault in 970 the pages here so they can safely be accessed from inside simple 971 locks and when preemption is disabled (no page-ins allowed). 972 Note! This touching does not cause INTEL_PTE_WIRED (bit 10) to be set as we go 973 thru general #PF and vm_fault doesn't figure it should be wired or something. */ 974 rtR0MemObjDarwinTouchPages(pv, cbSub ? cbSub : pMemToMap->cb); 949 975 /** @todo First, the memory should've been mapped by now, and second, it 950 * should have the wired attribute in the PTE (bit 9). Neither 951 * seems to be the case. The disabled locking code doesn't make any 952 * difference, which is extremely odd, and breaks 953 * rtR0MemObjNativeGetPagePhysAddr (getPhysicalSegment64 -> 64 for the 954 * lock descriptor. */ 955 //addr64_t Addr = pMemDesc->getPhysicalSegment64(0, NULL); 956 //printf("pv=%p: %8llx %8llx (%d)\n", pv, rtR0MemObjDarwinGetPTE(pv), Addr, 2); 976 * should have the wired attribute in the PTE (bit 10). Neither seems to 977 * be the case. The disabled locking code doesn't make any difference, 978 * which is extremely odd, and breaks rtR0MemObjNativeGetPagePhysAddr 979 * (getPhysicalSegment64 -> 64 for the lock descriptor. */ 980 //#ifdef __LP64__ 981 // addr64_t Addr2 = pMemToMapDarwin->pMemDesc->getPhysicalSegment(offSub, NULL, kIOMemoryMapperNone); 982 //#else 983 // addr64_t Addr2 = pMemToMapDarwin->pMemDesc->getPhysicalSegment64(offSub, NULL); 984 //#endif 985 // MY_PRINTF("pv=%p: %8llx %8llx (%d)\n", pv, rtR0MemObjDarwinGetPTE(pv), Addr2, 2); 957 986 958 987 /* … … 982 1011 // rc = VERR_MEMOBJ_INIT_FAILED; 983 1012 } 1013 else if (pv) 1014 rc = VERR_ADDRESS_TOO_BIG; 984 1015 else 985 rc = VERR_ ADDRESS_TOO_BIG;1016 rc = VERR_MAP_FAILED; 986 1017 pMemMap->release(); 987 1018 } … … 1034 1065 IOVirtualAddress VirtAddr = pMemMap->getVirtualAddress(); 1035 1066 void *pv = (void *)(uintptr_t)VirtAddr; 1036 if ((uintptr_t)pv == VirtAddr )1067 if ((uintptr_t)pv == VirtAddr && pv != NULL) 1037 1068 { 1038 1069 /* … … 1053 1084 rc = VERR_NO_MEMORY; 1054 1085 } 1086 else if (pv) 1087 rc = VERR_ADDRESS_TOO_BIG; 1055 1088 else 1056 rc = VERR_ ADDRESS_TOO_BIG;1089 rc = VERR_MAP_FAILED; 1057 1090 pMemMap->release(); 1058 1091 }
Note:
See TracChangeset
for help on using the changeset viewer.