- Timestamp:
- Mar 24, 2025 6:53:21 PM (3 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168147
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r106998 r108724 49 49 # Targets 50 50 # 51 if "$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" != "linux.arm64" || defined(VBOX_WITH_STATIC_ARM64_PAGE_SHIFT) # @todo Required by LoadGenerator in the validationkit but uses PAGE_SIZE++ 52 LIBRARIES += SUPR3 SUPR3Static 53 endif 51 LIBRARIES += SUPR3 SUPR3Static 54 52 if defined(VBOX_WITH_HARDENING) \ 55 53 && !defined(VBOX_ONLY_VALIDATIONKIT) -
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r108481 r108724 75 75 #include <iprt/path.h> 76 76 #include <iprt/string.h> 77 #include <iprt/system.h> 77 78 #include <iprt/env.h> 78 79 #include <iprt/rand.h> … … 551 552 552 553 /* fake the GIP. */ 553 g_pSUPGlobalInfoPage = (PSUPGLOBALINFOPAGE)RTMemPageAllocZ( PAGE_SIZE);554 g_pSUPGlobalInfoPage = (PSUPGLOBALINFOPAGE)RTMemPageAllocZ(SUP_PAGE_SIZE); 554 555 if (g_pSUPGlobalInfoPage) 555 556 { 556 557 g_pSUPGlobalInfoPageR0 = g_pSUPGlobalInfoPage; 557 g_HCPhysSUPGlobalInfoPage = NIL_RTHCPHYS & ~(RTHCPHYS) PAGE_OFFSET_MASK;558 g_HCPhysSUPGlobalInfoPage = NIL_RTHCPHYS & ~(RTHCPHYS)SUP_PAGE_OFFSET_MASK; 558 559 /* the page is supposed to be invalid, so don't set the magic. */ 559 560 return VINF_SUCCESS; … … 1002 1003 SUPR3DECL(int) supR3PageLock(void *pvStart, size_t cPages, PSUPPAGE paPages) 1003 1004 { 1005 uint32_t const cbPage = SUP_PAGE_SIZE; 1006 1004 1007 /* 1005 1008 * Validate. 1006 1009 */ 1007 1010 AssertPtr(pvStart); 1008 AssertMsg(RT_ALIGN_P(pvStart, PAGE_SIZE) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart));1011 AssertMsg(RT_ALIGN_P(pvStart, cbPage) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart)); 1009 1012 AssertPtr(paPages); 1010 1013 … … 1012 1015 if (RT_UNLIKELY(g_uSupFakeMode)) 1013 1016 { 1014 RTHCPHYS Phys = (uintptr_t)pvStart + PAGE_SIZE* 1024;1017 RTHCPHYS Phys = (uintptr_t)pvStart + cbPage * 1024; 1015 1018 size_t iPage = cPages; 1016 1019 while (iPage-- > 0) 1017 paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT);1020 paPages[iPage].Phys = Phys + (iPage << SUP_PAGE_SHIFT); 1018 1021 return VINF_SUCCESS; 1019 1022 } … … 1068 1071 */ 1069 1072 AssertPtr(pvStart); 1070 AssertMsg(RT_ALIGN_P(pvStart, PAGE_SIZE) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart));1073 AssertMsg(RT_ALIGN_P(pvStart, SUP_PAGE_SIZE) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart)); 1071 1074 1072 1075 /* fake */ … … 1117 1120 1118 1121 1122 #ifdef VBOX_WITH_R0_MODULES 1119 1123 /** 1120 1124 * Fallback for SUPR3PageAllocEx on systems where RTR0MemObjPhysAllocNC isn't … … 1135 1139 return rc; 1136 1140 } 1141 #endif /* VBOX_WITH_R0_MODULES */ 1137 1142 1138 1143 … … 1148 1153 *pR0Ptr = NIL_RTR0PTR; 1149 1154 AssertPtrNullReturn(paPages, VERR_INVALID_POINTER); 1150 AssertMsgReturn(cPages > 0 && cPages <= VBOX_MAX_ALLOC_ PAGE_COUNT, ("cPages=%zu\n", cPages), VERR_PAGE_COUNT_OUT_OF_RANGE);1155 AssertMsgReturn(cPages > 0 && cPages <= VBOX_MAX_ALLOC_SIZE / SUP_PAGE_SIZE, ("cPages=%zu\n", cPages), VERR_PAGE_COUNT_OUT_OF_RANGE); 1151 1156 AssertReturn(!fFlags, VERR_INVALID_FLAGS); 1152 1157 … … 1157 1162 { 1158 1163 int rc = SUPR3PageAlloc(cPages, 0 /*fFlags*/, ppvPages); 1159 Assert(RT_FAILURE(rc) || ASMMemIsZero(*ppvPages, cPages << PAGE_SHIFT));1164 Assert(RT_FAILURE(rc) || ASMMemIsZero(*ppvPages, cPages << SUP_PAGE_SHIFT)); 1160 1165 if (pR0Ptr) 1161 1166 *pR0Ptr = NIL_RTR0PTR; … … 1176 1181 return VERR_WRONG_ORDER; 1177 1182 1183 #ifdef VBOX_WITH_R0_MODULES 1178 1184 /* 1179 1185 * Use fallback for non-R0 mapping? … … 1240 1246 rc = VERR_NO_TMP_MEMORY; 1241 1247 return rc; 1242 1243 } 1244 1245 1248 #else 1249 AssertFailedReturn(VERR_NOT_SUPPORTED); 1250 #endif /* VBOX_WITH_R0_MODULES */ 1251 } 1252 1253 1254 #ifdef VBOX_WITH_R0_MODULES 1246 1255 SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr) 1247 1256 { … … 1282 1291 return rc; 1283 1292 } 1293 #endif 1284 1294 1285 1295 … … 1290 1300 */ 1291 1301 AssertPtrReturn(pvR3, VERR_INVALID_POINTER); 1292 Assert(!(off & PAGE_OFFSET_MASK));1293 Assert(!(cb & PAGE_OFFSET_MASK) && cb);1302 Assert(!(off & SUP_PAGE_OFFSET_MASK)); 1303 Assert(!(cb & SUP_PAGE_OFFSET_MASK) && cb); 1294 1304 AssertReturn(!(fProt & ~(RTMEM_PROT_NONE | RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC)), VERR_INVALID_PARAMETER); 1295 1305 … … 1476 1486 if (RT_UNLIKELY(g_uSupFakeMode)) 1477 1487 { 1478 *ppvPages = RTMemPageAllocZ((size_t)cPages * PAGE_SIZE);1488 *ppvPages = RTMemPageAllocZ((size_t)cPages * SUP_PAGE_SIZE); 1479 1489 if (!*ppvPages) 1480 1490 return VERR_NO_LOW_MEMORY; 1481 1491 1482 1492 /* fake physical addresses. */ 1483 RTHCPHYS Phys = (uintptr_t)*ppvPages + PAGE_SIZE * 1024;1493 RTHCPHYS Phys = (uintptr_t)*ppvPages + SUP_PAGE_SIZE * 1024; 1484 1494 size_t iPage = cPages; 1485 1495 while (iPage-- > 0) 1486 paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT);1496 paPages[iPage].Phys = Phys + (iPage << SUP_PAGE_SHIFT); 1487 1497 return VINF_SUCCESS; 1488 1498 } … … 1544 1554 if (RT_UNLIKELY(g_uSupFakeMode)) 1545 1555 { 1546 RTMemPageFree(pv, cPages * PAGE_SIZE);1556 RTMemPageFree(pv, cPages * SUP_PAGE_SIZE); 1547 1557 return VINF_SUCCESS; 1548 1558 } -
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r107800 r108724 44 44 #include <VBox/types.h> 45 45 #include <iprt/stdarg.h> 46 #if defined(RT_OS_LINUX) && defined(RT_ARCH_ARM64) 47 # include <iprt/system.h> 48 #endif 46 49 47 50 … … 83 86 # undef SUP_HARDENED_SUID 84 87 #endif 88 89 /** @def SUP_PAGE_SIZE 90 * Page size of the host, can evaluate to a function call on certain hosts where 91 * the page size is not known during compile time. 92 */ 93 #if defined(RT_OS_LINUX) && defined(RT_ARCH_ARM64) 94 # define SUP_PAGE_SIZE RTSystemGetPageSize() 95 #else 96 # define SUP_PAGE_SIZE HOST_PAGE_SIZE 97 #endif 98 99 /** @def SUP_PAGE_SHIFT 100 * Page shift of the host, can evaluate to a function call on certain hosts where 101 * the page size is not known during compile time. 102 */ 103 #if defined(RT_OS_LINUX) && defined(RT_ARCH_ARM64) 104 # define SUP_PAGE_SHIFT RTSystemGetPageShift() 105 #else 106 # define SUP_PAGE_SHIFT HOST_PAGE_SHIFT 107 #endif 108 109 /** @def SUP_PAGE_OFFSET_MASK 110 * Page shift of the host, can evaluate to a function call on certain hosts where 111 * the page size is not known during compile time. 112 */ 113 #if defined(RT_OS_LINUX) && defined(RT_ARCH_ARM64) 114 # define SUP_PAGE_OFFSET_MASK RTSystemGetPageOffsetMask() 115 #else 116 # define SUP_PAGE_OFFSET_MASK HOST_PAGE_OFFSET_MASK 117 #endif 118 85 119 86 120 #ifdef IN_SUP_HARDENED_R3 -
trunk/src/VBox/HostDrivers/Support/SUPLibLdr.cpp
r107675 r108724 413 413 * a little more complicated... 414 414 */ 415 uint32_t const cbPage = SUP_PAGE_SIZE; 416 uint32_t const cPageShift = SUP_PAGE_SHIFT; 417 uintptr_t const offPageMask = SUP_PAGE_OFFSET_MASK; 415 418 if (pArgs->uStartRva < pArgs->uEndRva) 416 419 { 417 if (((pArgs->uEndRva - 1) >> PAGE_SHIFT) != (uRvaSeg >> PAGE_SHIFT))420 if (((pArgs->uEndRva - 1) >> cPageShift) != (uRvaSeg >> cPageShift)) 418 421 { 419 422 /* No common page, so make the new segment start on a page boundrary. */ 420 cbMapped += uRvaSeg & PAGE_OFFSET_MASK;421 uRvaSeg &= ~(uint32_t) PAGE_OFFSET_MASK;423 cbMapped += uRvaSeg & offPageMask; 424 uRvaSeg &= ~(uint32_t)offPageMask; 422 425 Assert(pArgs->uEndRva <= uRvaSeg); 423 426 Log2(("supLoadModuleCompileSegmentsCB: -> new, no common\n")); … … 427 430 /* The current segment includes the memory protections of the 428 431 previous, so include the common page in it: */ 429 uint32_t const cbCommon = PAGE_SIZE - (uRvaSeg & PAGE_OFFSET_MASK);432 uint32_t const cbCommon = cbPage - (uRvaSeg & offPageMask); 430 433 if (cbCommon >= cbMapped) 431 434 { … … 444 447 /* The new segment includes the memory protections of the 445 448 previous, so include the common page in it: */ 446 cbMapped += uRvaSeg & PAGE_OFFSET_MASK;447 uRvaSeg &= ~(uint32_t) PAGE_OFFSET_MASK;449 cbMapped += uRvaSeg & offPageMask; 450 uRvaSeg &= ~(uint32_t)offPageMask; 448 451 if (uRvaSeg == pArgs->uStartRva) 449 452 { … … 453 456 return VINF_SUCCESS; /* Current segment was smaller than a page. */ 454 457 } 455 Log2(("supLoadModuleCompileSegmentsCB: -> new, %#x common into new\n", (uint32_t)(pSeg->RVA & PAGE_OFFSET_MASK)));458 Log2(("supLoadModuleCompileSegmentsCB: -> new, %#x common into new\n", (uint32_t)(pSeg->RVA & offPageMask))); 456 459 } 457 460 else … … 459 462 /* Create a new segment for the common page with the combined protection. */ 460 463 Log2(("supLoadModuleCompileSegmentsCB: -> it's complicated...\n")); 461 pArgs->uEndRva &= ~(uint32_t) PAGE_OFFSET_MASK;464 pArgs->uEndRva &= ~(uint32_t)offPageMask; 462 465 if (pArgs->uEndRva > pArgs->uStartRva) 463 466 { … … 477 480 pArgs->fProt |= fProt; 478 481 479 uint32_t const cbCommon = PAGE_SIZE - (uRvaSeg & PAGE_OFFSET_MASK);482 uint32_t const cbCommon = cbPage - (uRvaSeg & offPageMask); 480 483 if (cbCommon >= cbMapped) 481 484 { … … 485 488 cbMapped -= cbCommon; 486 489 uRvaSeg += cbCommon; 487 Assert(uRvaSeg - pArgs->uStartRva == PAGE_SIZE);490 Assert(uRvaSeg - pArgs->uStartRva == cbPage); 488 491 } 489 492 … … 507 510 508 511 /* Start the new segment. */ 509 Assert(!(uRvaSeg & PAGE_OFFSET_MASK));512 Assert(!(uRvaSeg & offPageMask)); 510 513 pArgs->fProt = fProt; 511 514 pArgs->uStartRva = uRvaSeg; -
trunk/src/VBox/HostDrivers/Support/linux/SUPLib-linux.cpp
r106061 r108724 64 64 #include <VBox/types.h> 65 65 #include <iprt/string.h> 66 #include <iprt/system.h>67 66 #include <VBox/err.h> 68 67 #include <VBox/param.h> … … 100 99 * Check if madvise works. 101 100 */ 102 void *pv = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 101 uint32_t const cbPage = SUP_PAGE_SIZE; 102 void *pv = mmap(NULL, cbPage, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 103 103 if (pv == MAP_FAILED) 104 104 return VERR_NO_MEMORY; 105 pThis->fSysMadviseWorks = (0 == madvise(pv, PAGE_SIZE, MADV_DONTFORK));106 munmap(pv, PAGE_SIZE);105 pThis->fSysMadviseWorks = (0 == madvise(pv, cbPage, MADV_DONTFORK)); 106 munmap(pv, cbPage); 107 107 108 108 /* … … 256 256 #endif 257 257 258 size_t cbMmap = cPages << PAGE_SHIFT; 258 uint32_t const cbPage = SUP_PAGE_SIZE; 259 uint32_t const cPageShift = SUP_PAGE_SHIFT; 260 261 size_t cbMmap = cPages << cPageShift; 259 262 if ( !pThis->fSysMadviseWorks 260 263 && (fFlags & (SUP_PAGE_ALLOC_F_FOR_LOCKING | SUP_PAGE_ALLOC_F_LARGE_PAGES)) == SUP_PAGE_ALLOC_F_FOR_LOCKING) 261 cbMmap += PAGE_SIZE* 2;264 cbMmap += cbPage * 2; 262 265 263 266 uint8_t *pbPages = (uint8_t *)mmap(NULL, cbMmap, PROT_READ | PROT_WRITE, fMmap, -1, 0); … … 268 271 fMmap &= ~MAP_HUGETLB; 269 272 if (!pThis->fSysMadviseWorks && (fFlags & SUP_PAGE_ALLOC_F_FOR_LOCKING)) 270 cbMmap = (cPages + 2) << PAGE_SHIFT;273 cbMmap = (cPages + 2) << cPageShift; 271 274 pbPages = (uint8_t *)mmap(NULL, cbMmap, PROT_READ | PROT_WRITE, fMmap, -1, 0); 272 275 } … … 313 316 * area struct of the very same size as the mmap area. 314 317 */ 315 mprotect(pbPages, PAGE_SIZE, PROT_NONE);316 mprotect(pbPages + cbMmap - PAGE_SIZE, PAGE_SIZE, PROT_NONE);317 pbPages += PAGE_SHIFT;318 mprotect(pbPages, cbPage, PROT_NONE); 319 mprotect(pbPages + cbMmap - cbPage, cbPage, PROT_NONE); 320 pbPages += cPageShift; 318 321 } 319 322 … … 322 325 * so I qualified it with SUP_PAGE_ALLOC_F_FOR_LOCKING (unused) for now... */ 323 326 if (fFlags & SUP_PAGE_ALLOC_F_FOR_LOCKING) 324 memset(pbPages, 0, cPages << PAGE_SHIFT);327 memset(pbPages, 0, cPages << cPageShift); 325 328 326 329 *ppvPages = pbPages; … … 334 337 { 335 338 NOREF(pThis); 336 munmap(pvPages, cPages << PAGE_SHIFT);339 munmap(pvPages, cPages << SUP_PAGE_SHIFT); 337 340 return VINF_SUCCESS; 338 341 }
Note:
See TracChangeset
for help on using the changeset viewer.