Changeset 87074 in vbox
- Timestamp:
- Dec 9, 2020 6:59:04 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141850
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
r86542 r87074 57 57 * This is a must for 5.8+, but we enable it all the way back to 3.2.x for 58 58 * better W^R compliance (fExecutable flag). */ 59 #if RTLNX_VER_ MIN(3,2,0) || defined(DOXYGEN_RUNNING)59 #if RTLNX_VER_RANGE(3,2,0, 5,10,0) || defined(DOXYGEN_RUNNING) 60 60 # define IPRT_USE_ALLOC_VM_AREA_FOR_EXEC 61 #endif 62 /** @def IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC 63 * alloc_vm_area was removed with 5.10 so we have to resort to a different way 64 * to allocate executable memory. 65 * It would be possible to remove IPRT_USE_ALLOC_VM_AREA_FOR_EXEC and use 66 * this path execlusively for 3.2+ but no time to test it really works on every 67 * supported kernel, so better play safe for now. 68 */ 69 #if RTLNX_VER_MIN(5,10,0) || defined(DOXYGEN_RUNNING) 70 # define IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC 61 71 #endif 62 72 … … 501 511 } 502 512 } 513 514 515 #ifdef IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC 516 /** 517 * User data passed to the apply_to_page_range() callback. 518 */ 519 typedef struct LNXAPPLYPGRANGE 520 { 521 /** Pointer to the memory object. */ 522 PRTR0MEMOBJLNX pMemLnx; 523 /** The page protection flags to apply. */ 524 pgprot_t fPg; 525 } LNXAPPLYPGRANGE; 526 /** Pointer to the user data. */ 527 typedef LNXAPPLYPGRANGE *PLNXAPPLYPGRANGE; 528 /** Pointer to the const user data. */ 529 typedef const LNXAPPLYPGRANGE *PCLNXAPPLYPGRANGE; 530 531 /** 532 * Callback called in apply_to_page_range(). 533 * 534 * @returns Linux status code. 535 * @param pPte Pointer to the page table entry for the given address. 536 * @param uAddr The address to apply the new protection to. 537 * @param pvUser The opaque user data. 538 */ 539 static DECLCALLBACK(int) rtR0MemObjLinuxApplyPageRange(pte_t *pPte, unsigned long uAddr, void *pvUser) 540 { 541 PCLNXAPPLYPGRANGE pArgs = (PCLNXAPPLYPGRANGE)pvUser; 542 PRTR0MEMOBJLNX pMemLnx = pArgs->pMemLnx; 543 size_t idxPg = (uAddr - (unsigned long)pMemLnx->Core.pv) >> PAGE_SHIFT; 544 545 set_pte(pPte, mk_pte(pMemLnx->apPages[idxPg], pArgs->fPg)); 546 return 0; 547 } 548 #endif 503 549 504 550 … … 585 631 # endif 586 632 { 633 # if defined(IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC) 634 if (fExecutable) 635 pgprot_val(fPg) |= _PAGE_NX; /* Uses RTR0MemObjProtect to clear NX when memory ready, W^X fashion. */ 636 # endif 637 587 638 # ifdef VM_MAP 588 639 pMemLnx->Core.pv = vmap(&pMemLnx->apPages[0], pMemLnx->cPages, VM_MAP, fPg); … … 1852 1903 return VINF_SUCCESS; 1853 1904 } 1905 # elif defined(IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC) 1906 PRTR0MEMOBJLNX pMemLnx = (PRTR0MEMOBJLNX)pMem; 1907 if ( pMemLnx->fExecutable 1908 && pMemLnx->fMappedToRing0) 1909 { 1910 LNXAPPLYPGRANGE Args; 1911 Args.pMemLnx = pMemLnx; 1912 Args.fPg = rtR0MemObjLinuxConvertProt(fProt, true /*fKernel*/); 1913 int rcLnx = apply_to_page_range(current->active_mm, (unsigned long)pMemLnx->Core.pv + offSub, cbSub, 1914 rtR0MemObjLinuxApplyPageRange, (void *)&Args); 1915 if (rcLnx) 1916 return VERR_NOT_SUPPORTED; 1917 1918 return VINF_SUCCESS; 1919 } 1854 1920 # endif 1855 1921
Note:
See TracChangeset
for help on using the changeset viewer.