Changeset 100356 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jul 4, 2023 6:41:38 AM (17 months ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/include/internal/memobj.h
r100355 r100356 361 361 * @param ppMem Where to store the ring-0 memory object handle. 362 362 * @param cb Number of bytes to allocate, page aligned. 363 * @param PhysHighest The highest permitable address (inclusive).364 * Pass NIL_RTHCPHYS if any address is acceptable.365 363 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 366 364 * @param pszTag Allocation tag used for statistics and such. 367 365 */ 368 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 369 bool fExecutable, const char *pszTag); 366 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag); 370 367 371 368 /** -
trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp
r100355 r100356 885 885 886 886 887 /** 888 * Translates the PhysHighest address into a mask. 889 */ 890 static mach_vm_address_t rtR0MemObjDarwinCalcPhysMask(RTHCPHYS PhysHighest, size_t uAlignment) 891 { 892 if (PhysHighest == NIL_RTHCPHYS) 893 return uAlignment <= PAGE_SIZE ? 0 : ~(mach_vm_address_t)(uAlignment - 1); 894 895 mach_vm_address_t PhysMask = ~(mach_vm_address_t)0; 896 while (PhysMask > (PhysHighest | PAGE_OFFSET_MASK)) 897 PhysMask >>= 1; 898 PhysMask &= ~(mach_vm_address_t)(uAlignment - 1); 899 900 return PhysMask; 901 } 902 903 904 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 905 bool fExecutable, const char *pszTag) 906 { 907 mach_vm_address_t const PhysMask = rtR0MemObjDarwinCalcPhysMask(PhysHighest, PAGE_SIZE); 887 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 888 { 908 889 IPRT_DARWIN_SAVE_EFL_AC(); 909 890 910 int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */, PhysMask, PhysHighest, 891 int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */, 892 ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE, 911 893 RTR0MEMOBJTYPE_CONT, PAGE_SIZE, pszTag, false /*fOnKernelThread*/); 912 894 … … 916 898 */ 917 899 if (RT_FAILURE(rc) && cb <= PAGE_SIZE) 918 rc = rtR0MemObjNativeAllocWorker(ppMem, cb + PAGE_SIZE, fExecutable, true /* fContiguous */, PhysMask, PhysHighest, 900 rc = rtR0MemObjNativeAllocWorker(ppMem, cb + PAGE_SIZE, fExecutable, true /* fContiguous */, 901 ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE, 919 902 RTR0MEMOBJTYPE_CONT, PAGE_SIZE, pszTag, false /*fOnKernelThread*/); 920 903 IPRT_DARWIN_RESTORE_EFL_AC(); … … 932 915 return VERR_NOT_SUPPORTED; 933 916 } 934 mach_vm_address_t const PhysMask = rtR0MemObjDarwinCalcPhysMask(PhysHighest, uAlignment);935 917 936 918 IPRT_DARWIN_SAVE_EFL_AC(); … … 941 923 int rc; 942 924 if (PhysHighest == NIL_RTHCPHYS) 943 rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, PhysMask, UINT64_MAX, 944 RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/); 925 rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, 926 uAlignment <= PAGE_SIZE ? 0 : ~(mach_vm_address_t)(uAlignment - 1) /* PhysMask*/, 927 UINT64_MAX, RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/); 945 928 else 946 929 { 930 mach_vm_address_t PhysMask = 0; 931 PhysMask = ~(mach_vm_address_t)0; 932 while (PhysMask > (PhysHighest | PAGE_OFFSET_MASK)) 933 PhysMask >>= 1; 947 934 AssertReturn(PhysMask + 1 <= cb, VERR_INVALID_PARAMETER); 948 rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, PhysMask, PhysHighest, 935 PhysMask &= ~(mach_vm_address_t)(uAlignment - 1); 936 937 rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, 938 PhysMask, PhysHighest, 949 939 RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/); 950 940 } -
trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
r100355 r100356 410 410 411 411 412 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHigest, 413 bool fExecutable, const char *pszTag) 412 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 414 413 { 415 414 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, … … 417 416 if (pMemFreeBSD) 418 417 { 419 int rc = rtR0MemObjFreeBSDAllocHelper(pMemFreeBSD, fExecutable, PhysHigest, true /*fContiguous*/, VERR_NO_CONT_MEMORY);418 int rc = rtR0MemObjFreeBSDAllocHelper(pMemFreeBSD, fExecutable, _4G - 1, true /*fContiguous*/, VERR_NO_CONT_MEMORY); 420 419 if (RT_SUCCESS(rc)) 421 420 { -
trunk/src/VBox/Runtime/r0drv/haiku/memobj-r0drv-haiku.c
r100355 r100356 277 277 278 278 279 int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,bool fExecutable, const char *pszTag)280 { 281 return rtR0MemObjNativeAllocArea(ppMem, cb, fExecutable, RTR0MEMOBJTYPE_CONT, PhysHighest, 0 /* uAlignment */, pszTag);279 int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 280 { 281 return rtR0MemObjNativeAllocArea(ppMem, cb, fExecutable, RTR0MEMOBJTYPE_CONT, 0 /* PhysHighest */, 0 /* uAlignment */, pszTag); 282 282 } 283 283 -
trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
r100355 r100356 149 149 /** Pointer to the linux memory object. */ 150 150 typedef RTR0MEMOBJLNX *PRTR0MEMOBJLNX; 151 152 153 /*********************************************************************************************************************************154 * Global Variables *155 *********************************************************************************************************************************/156 /*157 * Linux allows only a coarse selection of zones for158 * allocations matching a particular maximum physical address.159 *160 * Sorted from high to low physical address!161 */162 static const struct163 {164 RTHCPHYS PhysHighest;165 gfp_t fGfp;166 } g_aZones[] =167 {168 { NIL_RTHCPHYS, GFP_KERNEL },169 #if (defined(RT_ARCH_AMD64) || defined(CONFIG_X86_PAE)) && defined(GFP_DMA32)170 { _4G - 1, GFP_DMA32 }, /* ZONE_DMA32: 0-4GB */171 #elif defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)172 { _4G - 1, GFP_DMA }, /* ZONE_DMA: 0-4GB */173 #endif174 #if defined(RT_ARCH_AMD64)175 { _16M - 1, GFP_DMA }, /* ZONE_DMA: 0-16MB */176 #elif defined(RT_ARCH_X86)177 { 896 * _1M - 1, GFP_USER }, /* ZONE_NORMAL (32-bit hosts): 0-896MB */178 #endif179 };180 151 181 152 … … 1001 972 1002 973 1003 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 1004 bool fExecutable, const char *pszTag) 974 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 1005 975 { 1006 976 IPRT_LINUX_SAVE_EFL_AC(); 1007 977 PRTR0MEMOBJLNX pMemLnx; 1008 978 int rc; 1009 uint32_t idxZone; 1010 1011 /* 1012 * The last zone must be able to satisfy the PhysHighest requirement or there 1013 * will be no zone at all. 1014 */ 1015 if (g_aZones[RT_ELEMENTS(g_aZones) - 1].PhysHighest > PhysHighest) 1016 { 1017 IPRT_LINUX_RESTORE_EFL_AC(); 1018 AssertMsgFailedReturn(("No zone can satisfy PhysHighest=%RHp!\n", PhysHighest), 1019 VERR_NO_CONT_MEMORY); 1020 } 1021 1022 /* Find the first zone matching our PhysHighest requirement. */ 1023 idxZone = 0; 1024 for (;;) 1025 { 1026 if (g_aZones[idxZone].PhysHighest <= PhysHighest) 1027 break; /* We found a zone satisfying the requirement. */ 1028 idxZone++; 1029 } 1030 1031 /* Now try to allocate pages from all the left zones until one succeeds. */ 1032 for (;;) 1033 { 1034 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, g_aZones[idxZone].fGfp, 979 980 #if (defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64) || defined(CONFIG_X86_PAE)) && defined(GFP_DMA32) 981 /* ZONE_DMA32: 0-4GB */ 982 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_DMA32, 983 true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY, pszTag); 984 if (RT_FAILURE(rc)) 985 #endif 986 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64) 987 /* ZONE_DMA: 0-16MB */ 988 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_DMA, 1035 989 true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY, pszTag); 1036 idxZone++; 1037 if (RT_SUCCESS(rc) || idxZone == RT_ELEMENTS(g_aZones)) 1038 break; 1039 } 990 #else 991 /* ZONE_NORMAL (32-bit hosts): 0-896MB */ 992 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_USER, 993 true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY, pszTag); 994 #endif 1040 995 if (RT_SUCCESS(rc)) 1041 996 { … … 1043 998 if (RT_SUCCESS(rc)) 1044 999 { 1045 #if defined(RT_STRICT) 1000 #if defined(RT_STRICT) && (defined(RT_ARCH_AMD64) || defined(CONFIG_HIGHMEM64G)) 1046 1001 size_t iPage = pMemLnx->cPages; 1047 1002 while (iPage-- > 0) 1048 Assert(page_to_phys(pMemLnx->apPages[iPage]) < PhysHighest);1003 Assert(page_to_phys(pMemLnx->apPages[iPage]) < _4G); 1049 1004 #endif 1050 1005 pMemLnx->Core.u.Cont.Phys = page_to_phys(pMemLnx->apPages[0]); -
trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp
r100355 r100356 474 474 475 475 476 RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest,bool fExecutable, const char *pszTag)476 RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 477 477 { 478 478 /* sanity checks. */ … … 482 482 AssertReturn(cb > 0, VERR_INVALID_PARAMETER); 483 483 AssertReturn(cb <= cbAligned, VERR_INVALID_PARAMETER); 484 AssertReturn(PhysHighest >= cb, VERR_INVALID_PARAMETER);485 484 RT_ASSERT_PREEMPTIBLE(); 486 485 487 486 /* do the allocation. */ 488 return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, PhysHighest,fExecutable, pszTag);487 return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, fExecutable, pszTag); 489 488 } 490 489 RT_EXPORT_SYMBOL(RTR0MemObjAllocContTag); -
trunk/src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c
r100355 r100356 288 288 289 289 290 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 291 bool fExecutable, const char *pszTag) 290 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 292 291 { 293 292 PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_CONT, NULL, cb, pszTag); 294 293 if (pMemNetBSD) 295 294 { 296 int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, cb, fExecutable, PhysHighest, true /*fContiguous*/);295 int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, cb, fExecutable, _4G - 1, true /*fContiguous*/); 297 296 if (RT_SUCCESS(rc)) 298 297 { -
trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp
r100355 r100356 565 565 * Fall back on contiguous memory... 566 566 */ 567 return rtR0MemObjNativeAllocCont(ppMem, cb, _4G - 1,fExecutable, pszTag);567 return rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable, pszTag); 568 568 } 569 569 … … 636 636 637 637 638 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 639 bool fExecutable, const char *pszTag) 640 { 641 return rtR0MemObjNativeAllocContEx(ppMem, cb, fExecutable, PhysHighest, PAGE_SIZE /* alignment */, pszTag); 638 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 639 { 640 return rtR0MemObjNativeAllocContEx(ppMem, cb, fExecutable, _4G-1, PAGE_SIZE /* alignment */, pszTag); 642 641 } 643 642 -
trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp
r100355 r100356 218 218 219 219 220 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 221 bool fExecutable, const char *pszTag) 220 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 222 221 { 223 222 NOREF(fExecutable); 224 AssertMsgReturn(PhysHighest >= _16M - 1, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);225 223 226 224 /* create the object. */ … … 231 229 /* do the allocation. */ 232 230 ULONG ulPhys = ~0UL; 233 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G - 1 ? VMDHA_16M : 0), 234 &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL); 231 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL); 235 232 if (!rc) 236 233 { … … 251 248 const char *pszTag) 252 249 { 253 AssertMsgReturn(PhysHighest >= _16M - 1, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);250 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED); 254 251 255 252 /** @todo alignment */ … … 264 261 /* do the allocation. */ 265 262 ULONG ulPhys = ~0UL; 266 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G - 1? VMDHA_16M : 0),263 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), 267 264 &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL); 268 265 if (!rc) -
trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c
r100355 r100356 727 727 728 728 729 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 730 bool fExecutable, const char *pszTag) 729 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 731 730 { 732 731 AssertReturn(!fExecutable, VERR_NOT_SUPPORTED); 733 return rtR0MemObjNativeAllocPhys(ppMem, cb, PhysHigest, PAGE_SIZE /* alignment */, pszTag);732 return rtR0MemObjNativeAllocPhys(ppMem, cb, _4G - 1, PAGE_SIZE /* alignment */, pszTag); 734 733 } 735 734
Note:
See TracChangeset
for help on using the changeset viewer.