From 3793a928def37550c9eab897ce0b4f61d1ef4e6d Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Wed, 29 Jun 2016 19:09:31 -0700 Subject: [PATCH] Remove MMAP_DOESNOT_ALLOW_REMAP. --- cross/arm-softfp/tryrun.cmake | 4 - cross/arm/tryrun.cmake | 4 - cross/arm64/tryrun.cmake | 4 - src/pal/src/config.h.in | 1 - src/pal/src/configure.cmake | 28 ------- src/pal/src/include/pal/virtual.h | 7 +- src/pal/src/map/virtual.cpp | 162 +++++--------------------------------- 7 files changed, 20 insertions(+), 190 deletions(-) diff --git a/cross/arm-softfp/tryrun.cmake b/cross/arm-softfp/tryrun.cmake index 2721d08..26a30e5 100644 --- a/cross/arm-softfp/tryrun.cmake +++ b/cross/arm-softfp/tryrun.cmake @@ -34,10 +34,6 @@ SET( HAVE_MMAP_DEV_ZERO_EXITCODE 0 CACHE STRING "Result from TRY_RUN" FORCE) -SET( MMAP_DOESNOT_ALLOW_REMAP_EXITCODE - 1 - CACHE STRING "Result from TRY_RUN" FORCE) - SET( ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1 CACHE STRING "Result from TRY_RUN" FORCE) diff --git a/cross/arm/tryrun.cmake b/cross/arm/tryrun.cmake index 2721d08..26a30e5 100644 --- a/cross/arm/tryrun.cmake +++ b/cross/arm/tryrun.cmake @@ -34,10 +34,6 @@ SET( HAVE_MMAP_DEV_ZERO_EXITCODE 0 CACHE STRING "Result from TRY_RUN" FORCE) -SET( MMAP_DOESNOT_ALLOW_REMAP_EXITCODE - 1 - CACHE STRING "Result from TRY_RUN" FORCE) - SET( ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1 CACHE STRING "Result from TRY_RUN" FORCE) diff --git a/cross/arm64/tryrun.cmake b/cross/arm64/tryrun.cmake index d8a95a6..1751ac5 100644 --- a/cross/arm64/tryrun.cmake +++ b/cross/arm64/tryrun.cmake @@ -34,10 +34,6 @@ SET( HAVE_MMAP_DEV_ZERO_EXITCODE 0 CACHE STRING "Result from TRY_RUN" FORCE) -SET( MMAP_DOESNOT_ALLOW_REMAP_EXITCODE - 1 - CACHE STRING "Result from TRY_RUN" FORCE) - SET( ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1 CACHE STRING "Result from TRY_RUN" FORCE) diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in index 73a79b8..e227e4a 100644 --- a/src/pal/src/config.h.in +++ b/src/pal/src/config.h.in @@ -97,7 +97,6 @@ #cmakedefine01 STATVFS64_PROTOTYPE_BROKEN #cmakedefine01 HAVE_MMAP_DEV_ZERO #cmakedefine01 MMAP_ANON_IGNORES_PROTECTION -#cmakedefine01 MMAP_DOESNOT_ALLOW_REMAP #cmakedefine01 ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS #cmakedefine01 PTHREAD_CREATE_MODIFIES_ERRNO #cmakedefine01 SEM_INIT_MODIFIES_ERRNO diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake index 7e95a77..b3bf48b 100644 --- a/src/pal/src/configure.cmake +++ b/src/pal/src/configure.cmake @@ -483,34 +483,6 @@ int main(void) { exit(0); }" MMAP_ANON_IGNORES_PROTECTION) check_cxx_source_runs(" -#include -#include -#include -#include - -#ifndef MAP_ANON -#define MAP_ANON MAP_ANONYMOUS -#endif - -int main() -{ - int iRet = 1; - void * pAddr = MAP_FAILED; - int MemSize = 1024; - - MemSize = getpagesize(); - pAddr = mmap(0x0, MemSize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (pAddr == MAP_FAILED) - exit(0); - - pAddr = mmap(pAddr, MemSize, PROT_WRITE | PROT_READ, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); - if (pAddr == MAP_FAILED) - iRet = 0; - - munmap(pAddr, MemSize); // don't care of this - exit (iRet); -}" MMAP_DOESNOT_ALLOW_REMAP) -check_cxx_source_runs(" #include #include #include diff --git a/src/pal/src/include/pal/virtual.h b/src/pal/src/include/pal/virtual.h index b740767..2d5896e 100644 --- a/src/pal/src/include/pal/virtual.h +++ b/src/pal/src/include/pal/virtual.h @@ -26,7 +26,7 @@ extern "C" #endif // __cplusplus typedef struct _CMI { - + struct _CMI * pNext; /* Link to the next entry. */ struct _CMI * pLast; /* Link to the previous entry. */ @@ -41,11 +41,8 @@ typedef struct _CMI { BYTE * pProtectionState; /* Individual allocation type tracking for each */ /* page in the region. */ -#if MMAP_DOESNOT_ALLOW_REMAP - BYTE * pDirtyPages; /* Pages that need to be cleared if re-committed */ -#endif // MMAP_DOESNOT_ALLOW_REMAP -}CMI, * PCMI; +} CMI, * PCMI; enum VIRTUAL_CONSTANTS { diff --git a/src/pal/src/map/virtual.cpp b/src/pal/src/map/virtual.cpp index f70d886..b498dbc 100644 --- a/src/pal/src/map/virtual.cpp +++ b/src/pal/src/map/virtual.cpp @@ -125,9 +125,6 @@ void VIRTUALCleanup() pEntry->startBoundary ); InternalFree(pEntry->pAllocState); InternalFree(pEntry->pProtectionState ); -#if MMAP_DOESNOT_ALLOW_REMAP - InternalFree(pEntry->pDirtyPages ); -#endif pTempEntry = pEntry; pEntry = pEntry->pNext; InternalFree(pTempEntry ); @@ -196,45 +193,6 @@ static BOOL VIRTUALIsPageCommitted( SIZE_T nBitToRetrieve, CONST PCMI pInformati } } -#if MMAP_DOESNOT_ALLOW_REMAP -/**** - * - * VIRTUALIsPageDirty - * - * SIZE_T nBitToRetrieve - Which page to check. - * - * Returns TRUE if the page needs to be cleared if re-committed, - * FALSE otherwise. - * - */ -static BOOL VIRTUALIsPageDirty( SIZE_T nBitToRetrieve, CONST PCMI pInformation ) -{ - SIZE_T nByteOffset = 0; - UINT nBitOffset = 0; - UINT byteMask = 0; - - if ( !pInformation ) - { - ERROR( "pInformation was NULL!\n" ); - return FALSE; - } - - nByteOffset = nBitToRetrieve / CHAR_BIT; - nBitOffset = nBitToRetrieve % CHAR_BIT; - - byteMask = 1 << nBitOffset; - - if ( pInformation->pDirtyPages[ nByteOffset ] & byteMask ) - { - return TRUE; - } - else - { - return FALSE; - } -} -#endif // MMAP_DOESNOT_ALLOW_REMAP - /********* * * VIRTUALGetAllocationType @@ -428,40 +386,6 @@ static BOOL VIRTUALSetAllocState( UINT nAction, SIZE_T nStartingBit, nNumberOfBits, pInformation->pAllocState); } -#if MMAP_DOESNOT_ALLOW_REMAP -/**** - * - * VIRTUALSetDirtyPages - * - * IN UINT nStatus - 0: memory clean, any other value: memory is dirty - * IN SIZE_T nStartingBit - The bit to set. - * - * IN SIZE_T nNumberOfBits - The range of bits to set. - * IN PCMI pStateArray - A pointer the array to be manipulated. - * - * Returns TRUE on success, FALSE otherwise. - * Turns bit(s) on/off bit to indicate dirty page(s) - * - */ -static BOOL VIRTUALSetDirtyPages( UINT nStatus, SIZE_T nStartingBit, - SIZE_T nNumberOfBits, CONST PCMI pInformation ) -{ - TRACE( "VIRTUALSetDirtyPages( nStatus = %d, nStartingBit = %d, " - "nNumberOfBits = %d, pStateArray = 0x%p )\n", - nStatus, nStartingBit, nNumberOfBits, pInformation ); - - if ( !pInformation ) - { - ERROR( "pInformation was invalid!\n" ); - return FALSE; - } - - return VIRTUALSetPageBits(nStatus, nStartingBit, - nNumberOfBits, pInformation->pDirtyPages); -} -#endif // MMAP_DOESNOT_ALLOW_REMAP - - /**** * * VIRTUALFindRegionInformation( ) @@ -559,15 +483,10 @@ static BOOL VIRTUALReleaseMemory( PCMI pMemoryToBeReleased ) InternalFree( pMemoryToBeReleased->pAllocState ); pMemoryToBeReleased->pAllocState = NULL; - + InternalFree( pMemoryToBeReleased->pProtectionState ); pMemoryToBeReleased->pProtectionState = NULL; -#if MMAP_DOESNOT_ALLOW_REMAP - InternalFree( pMemoryToBeReleased->pDirtyPages ); - pMemoryToBeReleased->pDirtyPages = NULL; -#endif // MMAP_DOESNOT_ALLOW_REMAP - InternalFree( pMemoryToBeReleased ); pMemoryToBeReleased = NULL; @@ -748,20 +667,10 @@ static BOOL VIRTUALStoreAllocationInfo( pNewEntry->pAllocState = (BYTE*)InternalMalloc( nBufferSize ); pNewEntry->pProtectionState = (BYTE*)InternalMalloc( (memSize / VIRTUAL_PAGE_SIZE) ); -#if MMAP_DOESNOT_ALLOW_REMAP - pNewEntry->pDirtyPages = (BYTE*)InternalMalloc( nBufferSize ); -#endif // - if ( pNewEntry->pAllocState && pNewEntry->pProtectionState -#if MMAP_DOESNOT_ALLOW_REMAP - && pNewEntry->pDirtyPages -#endif // MMAP_DOESNOT_ALLOW_REMAP - ) + if (pNewEntry->pAllocState && pNewEntry->pProtectionState) { /* Set the intial allocation state, and initial allocation protection. */ -#if MMAP_DOESNOT_ALLOW_REMAP - memset (pNewEntry->pDirtyPages, 0, nBufferSize); -#endif // MMAP_DOESNOT_ALLOW_REMAP VIRTUALSetAllocState( MEM_RESERVE, 0, nBufferSize * CHAR_BIT, pNewEntry ); memset( pNewEntry->pProtectionState, VIRTUALConvertWinFlags( flProtection ), @@ -772,14 +681,9 @@ static BOOL VIRTUALStoreAllocationInfo( ERROR( "Unable to allocate memory for the structure.\n"); bRetVal = FALSE; -#if MMAP_DOESNOT_ALLOW_REMAP - if (pNewEntry->pDirtyPages) InternalFree( pNewEntry->pDirtyPages ); - pNewEntry->pDirtyPages = NULL; -#endif // - if (pNewEntry->pProtectionState) InternalFree( pNewEntry->pProtectionState ); pNewEntry->pProtectionState = NULL; - + if (pNewEntry->pAllocState) InternalFree( pNewEntry->pAllocState ); pNewEntry->pAllocState = NULL; @@ -1109,37 +1013,17 @@ VIRTUALCommitMemory( StartBoundary = pInformation->startBoundary + runStart * VIRTUAL_PAGE_SIZE; MemSize = runLength * VIRTUAL_PAGE_SIZE; + if (allocationType != MEM_COMMIT) { // Commit the pages - if (mprotect((void *) StartBoundary, MemSize, PROT_WRITE | PROT_READ) == 0) - { -#if MMAP_DOESNOT_ALLOW_REMAP - SIZE_T i; - char *temp = (char *) StartBoundary; - for(i = 0; i < runLength; i++) - { - - if (VIRTUALIsPageDirty(runStart + i, pInformation)) - { - // This page is being recommitted after being decommitted, - // therefore the memory needs to be cleared - memset (temp, 0, VIRTUAL_PAGE_SIZE); - } - - temp += VIRTUAL_PAGE_SIZE; - } -#endif // MMAP_DOESNOT_ALLOW_REMAP - } - else + if (mprotect((void *) StartBoundary, MemSize, PROT_WRITE | PROT_READ) != 0) { ERROR("mprotect() failed! Error(%d)=%s\n", errno, strerror(errno)); goto error; } + VIRTUALSetAllocState(MEM_COMMIT, runStart, runLength, pInformation); -#if MMAP_DOESNOT_ALLOW_REMAP - VIRTUALSetDirtyPages (0, runStart, runLength, pInformation); -#endif // MMAP_DOESNOT_ALLOW_REMAP if (nProtect == (PROT_WRITE | PROT_READ)) { @@ -1148,8 +1032,10 @@ VIRTUALCommitMemory( memset(pInformation->pProtectionState + runStart, vProtect, runLength); } + protectionState = VIRTUAL_READWRITE; } + if (protectionState != vProtect) { // Change permissions. @@ -1165,14 +1051,14 @@ VIRTUALCommitMemory( goto error; } } - + runStart = index; runLength = 1; allocationType = curAllocationType; protectionState = curProtectionState; } - pRetVal = (void *) (pInformation->startBoundary + - initialRunStart * VIRTUAL_PAGE_SIZE); + + pRetVal = (void *) (pInformation->startBoundary + initialRunStart * VIRTUAL_PAGE_SIZE); goto done; error: @@ -1191,7 +1077,6 @@ error: } done: - return pRetVal; } @@ -1376,19 +1261,13 @@ VirtualFree( TRACE( "Un-committing the following page(s) %d to %d.\n", StartBoundary, MemSize ); -#if MMAP_DOESNOT_ALLOW_REMAP - // if no double mapping is supported, - // just mprotect the memory with no access - if (mprotect((LPVOID)StartBoundary, MemSize, PROT_NONE) == 0) -#else // MMAP_DOESNOT_ALLOW_REMAP // Explicitly calling mmap instead of mprotect here makes it // that much more clear to the operating system that we no // longer need these pages. if ( mmap( (LPVOID)StartBoundary, MemSize, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0 ) != MAP_FAILED ) -#endif // MMAP_DOESNOT_ALLOW_REMAP { -#if (MMAP_ANON_IGNORES_PROTECTION && !MMAP_DOESNOT_ALLOW_REMAP) +#if (MMAP_ANON_IGNORES_PROTECTION) if (mprotect((LPVOID) StartBoundary, MemSize, PROT_NONE) != 0) { ASSERT("mprotect failed to protect the region!\n"); @@ -1397,7 +1276,7 @@ VirtualFree( bRetVal = FALSE; goto VirtualFreeExit; } -#endif // MMAP_ANON_IGNORES_PROTECTION && !MMAP_DOESNOT_ALLOW_REMAP +#endif // MMAP_ANON_IGNORES_PROTECTION SIZE_T index = 0; SIZE_T nNumOfPagesToChange = 0; @@ -1407,13 +1286,9 @@ VirtualFree( nNumOfPagesToChange = MemSize / VIRTUAL_PAGE_SIZE; VIRTUALSetAllocState( MEM_RESERVE, index, - nNumOfPagesToChange, pUnCommittedMem ); -#if MMAP_DOESNOT_ALLOW_REMAP - VIRTUALSetDirtyPages( 1, index, - nNumOfPagesToChange, pUnCommittedMem ); -#endif // MMAP_DOESNOT_ALLOW_REMAP + nNumOfPagesToChange, pUnCommittedMem ); - goto VirtualFreeExit; + goto VirtualFreeExit; } else { @@ -1534,10 +1409,9 @@ VirtualProtect( Index = OffSet = StartBoundary - pEntry->startBoundary == 0 ? 0 : ( StartBoundary - pEntry->startBoundary ) / VIRTUAL_PAGE_SIZE; NumberOfPagesToChange = MemSize / VIRTUAL_PAGE_SIZE; - - TRACE( "Number of pages to check %d, starting page %d \n", - NumberOfPagesToChange, Index ); - + + TRACE( "Number of pages to check %d, starting page %d \n", NumberOfPagesToChange, Index ); + for ( ; Index < NumberOfPagesToChange; Index++ ) { if ( !VIRTUALIsPageCommitted( Index, pEntry ) ) -- 2.7.4