Quellcode durchsuchen

replace PAGE_EXECUTE with PAGE_EXECUTE_READ when appropriate

Li Tian (Intel) vor 8 Jahren
Ursprung
Commit
31b1d8f411

+ 2 - 2
lib/Backend/EmitBuffer.cpp

@@ -296,7 +296,7 @@ EmitBufferManager<TAlloc, TPreReservedAlloc, SyncObject>::AllocateBuffer(__in si
 #if DBG
     MEMORY_BASIC_INFORMATION memBasicInfo;
     size_t resultBytes = VirtualQueryEx(this->processHandle, allocation->allocation->address, &memBasicInfo, sizeof(memBasicInfo));
-    Assert(resultBytes == 0 || memBasicInfo.Protect == PAGE_EXECUTE);
+    Assert(resultBytes == 0 || memBasicInfo.Protect == PAGE_EXECUTE_READ);
 #endif
 
     return allocation;
@@ -334,7 +334,7 @@ bool EmitBufferManager<TAlloc, TPreReservedAlloc, SyncObject>::IsBufferExecuteRe
     AutoRealOrFakeCriticalSection<SyncObject> autoCs(&this->criticalSection);
     MEMORY_BASIC_INFORMATION memBasicInfo;
     size_t resultBytes = VirtualQuery(allocation->allocation->address, &memBasicInfo, sizeof(memBasicInfo));
-    return resultBytes != 0 && memBasicInfo.Protect == PAGE_EXECUTE;
+    return resultBytes != 0 && memBasicInfo.Protect == PAGE_EXECUTE_READ;
 }
 #endif
 

+ 4 - 4
lib/Backend/JITThunkEmitter.cpp

@@ -77,7 +77,7 @@ JITThunkEmitter<TAlloc>::CreateThunk(uintptr_t entryPoint)
 
     if (IsThunkPageEmpty(pageStartAddress))
     {
-        if (this->codeAllocator->Alloc((PVOID)pageStartAddress, AutoSystemInfo::PageSize, MEM_COMMIT, PAGE_EXECUTE, true) == nullptr)
+        if (this->codeAllocator->Alloc((PVOID)pageStartAddress, AutoSystemInfo::PageSize, MEM_COMMIT, PAGE_EXECUTE_READ, true) == nullptr)
         {
             this->codeAllocator->FreeLocal(localPageAddress);
             return NULL;
@@ -165,7 +165,7 @@ JITThunkEmitter<TAlloc>::EnsureInitialized()
         // check again because we did the first one outside of lock
         if (this->baseAddress == NULL)
         {
-            this->baseAddress = (uintptr_t)this->codeAllocator->Alloc(nullptr, TotalThunkSize, MEM_RESERVE, PAGE_EXECUTE, true);
+            this->baseAddress = (uintptr_t)this->codeAllocator->Alloc(nullptr, TotalThunkSize, MEM_RESERVE, PAGE_EXECUTE_READ, true);
         }
     }
     return this->baseAddress;
@@ -230,7 +230,7 @@ JITThunkEmitter<VirtualAllocWrapper>::ProtectPage(void * address)
     AutoEnableDynamicCodeGen enableCodeGen(true);
 #endif
     DWORD oldProtect;
-    BOOL result = VirtualProtectEx(this->processHandle, address, ThunkSize, PAGE_EXECUTE, &oldProtect);
+    BOOL result = VirtualProtectEx(this->processHandle, address, ThunkSize, PAGE_EXECUTE_READ, &oldProtect);
     AssertOrFailFast(result && oldProtect == PAGE_EXECUTE_READWRITE);
 }
 
@@ -243,7 +243,7 @@ JITThunkEmitter<VirtualAllocWrapper>::UnprotectPage(void * address)
 #endif
     DWORD oldProtect;
     BOOL result = VirtualProtectEx(this->processHandle, address, ThunkSize, PAGE_EXECUTE_READWRITE, &oldProtect);
-    AssertOrFailFast(result && oldProtect == PAGE_EXECUTE);
+    AssertOrFailFast(result && oldProtect == PAGE_EXECUTE_READ);
 }
 
 #if ENABLE_OOP_NATIVE_CODEGEN

+ 2 - 2
lib/Common/CommonDefines.h

@@ -69,9 +69,9 @@
 
 // Memory Protections
 #ifdef _CONTROL_FLOW_GUARD
-#define PAGE_EXECUTE_RO_TARGETS_INVALID   (PAGE_EXECUTE | PAGE_TARGETS_INVALID)
+#define PAGE_EXECUTE_RO_TARGETS_INVALID   (PAGE_EXECUTE_READ | PAGE_TARGETS_INVALID)
 #else
-#define PAGE_EXECUTE_RO_TARGETS_INVALID   (PAGE_EXECUTE)
+#define PAGE_EXECUTE_RO_TARGETS_INVALID   (PAGE_EXECUTE_READ)
 #endif
 
 //----------------------------------------------------------------------------------------------------

+ 2 - 2
lib/Common/Memory/CommonMemoryPch.h

@@ -55,9 +55,9 @@ typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
 #ifdef _CONTROL_FLOW_GUARD
 #define PAGE_EXECUTE_RW_TARGETS_INVALID   (PAGE_EXECUTE_READWRITE | PAGE_TARGETS_INVALID)
 #define PAGE_EXECUTE_RW_TARGETS_NO_UPDATE (PAGE_EXECUTE_READWRITE | PAGE_TARGETS_NO_UPDATE)
-#define PAGE_EXECUTE_RO_TARGETS_NO_UPDATE (PAGE_EXECUTE           | PAGE_TARGETS_NO_UPDATE)
+#define PAGE_EXECUTE_RO_TARGETS_NO_UPDATE (PAGE_EXECUTE_READ      | PAGE_TARGETS_NO_UPDATE)
 #else
 #define PAGE_EXECUTE_RW_TARGETS_INVALID   (PAGE_EXECUTE_READWRITE)
 #define PAGE_EXECUTE_RW_TARGETS_NO_UPDATE (PAGE_EXECUTE_READWRITE)
-#define PAGE_EXECUTE_RO_TARGETS_NO_UPDATE (PAGE_EXECUTE)
+#define PAGE_EXECUTE_RO_TARGETS_NO_UPDATE (PAGE_EXECUTE_READ)
 #endif

+ 8 - 8
lib/Common/Memory/CustomHeap.cpp

@@ -266,7 +266,7 @@ Allocation* Heap<TAlloc, TPreReservedAlloc>::Alloc(size_t bytes, ushort pdataCou
         }
         else
         {
-            Assert(memBasicInfo.Protect == PAGE_EXECUTE);
+            Assert(memBasicInfo.Protect == PAGE_EXECUTE_READ);
         }
 #endif
 
@@ -291,7 +291,7 @@ BOOL Heap<TAlloc, TPreReservedAlloc>::ProtectAllocationWithExecuteReadWrite(Allo
     {
         protectFlags = PAGE_EXECUTE_READWRITE;
     }
-    return this->ProtectAllocation(allocation, protectFlags, PAGE_EXECUTE, addressInPage);
+    return this->ProtectAllocation(allocation, protectFlags, PAGE_EXECUTE_READ, addressInPage);
 }
 
 template<typename TAlloc, typename TPreReservedAlloc>
@@ -304,7 +304,7 @@ BOOL Heap<TAlloc, TPreReservedAlloc>::ProtectAllocationWithExecuteReadOnly(Alloc
     }
     else
     {
-        protectFlags = PAGE_EXECUTE;
+        protectFlags = PAGE_EXECUTE_READ;
     }
     return this->ProtectAllocation(allocation, protectFlags, PAGE_EXECUTE_READWRITE, addressInPage);
 }
@@ -418,7 +418,7 @@ Allocation* Heap<TAlloc, TPreReservedAlloc>::AllocLargeObject(size_t bytes, usho
             }
             else
             {
-                protectFlags = PAGE_EXECUTE;
+                protectFlags = PAGE_EXECUTE_READ;
             }
             this->codePageAllocators->ProtectPages(address, pages, segment, protectFlags /*dwVirtualProtectFlags*/, PAGE_READWRITE /*desiredOldProtectFlags*/);
         }
@@ -443,7 +443,7 @@ Allocation* Heap<TAlloc, TPreReservedAlloc>::AllocLargeObject(size_t bytes, usho
     }
     else
     {
-        Assert(memBasicInfo.Protect == PAGE_EXECUTE);
+        Assert(memBasicInfo.Protect == PAGE_EXECUTE_READ);
     }
 #endif
 
@@ -677,7 +677,7 @@ Page* Heap<TAlloc, TPreReservedAlloc>::AllocNewPage(BucketId bucket, bool canAll
     }
     else
     {
-        protectFlags = PAGE_EXECUTE;
+        protectFlags = PAGE_EXECUTE_READ;
     }
 
     //Change the protection of the page to Read-Only Execute, before adding it to the bucket list.
@@ -867,7 +867,7 @@ bool Heap<TAlloc, TPreReservedAlloc>::FreeAllocation(Allocation* object)
         EnsureAllocationExecuteWriteable(object);
         FreeAllocationHelper(object, index, length);
 
-        // after freeing part of the page, the page should be in PAGE_EXECUTE_READWRITE protection, and turning to PAGE_EXECUTE (always with TARGETS_NO_UPDATE state)
+        // after freeing part of the page, the page should be in PAGE_EXECUTE_READWRITE protection, and turning to PAGE_EXECUTE_READ (always with TARGETS_NO_UPDATE state)
 
         DWORD protectFlags = 0;
 
@@ -877,7 +877,7 @@ bool Heap<TAlloc, TPreReservedAlloc>::FreeAllocation(Allocation* object)
         }
         else
         {
-            protectFlags = PAGE_EXECUTE;
+            protectFlags = PAGE_EXECUTE_READ;
         }
 
         this->codePageAllocators->ProtectPages(page->address, 1, segment, protectFlags, PAGE_EXECUTE_READWRITE);

+ 4 - 4
lib/Common/Memory/CustomHeap.h

@@ -481,8 +481,8 @@ private:
     DWORD EnsurePageReadWrite(Page* page)
     {
         Assert(!page->isDecommitted);
-        this->codePageAllocators->ProtectPages(page->address, 1, page->segment, readWriteFlags, PAGE_EXECUTE);
-        return PAGE_EXECUTE;
+        this->codePageAllocators->ProtectPages(page->address, 1, page->segment, readWriteFlags, PAGE_EXECUTE_READ);
+        return PAGE_EXECUTE_READ;
     }
 
     template<DWORD readWriteFlags>
@@ -491,8 +491,8 @@ private:
     {
         if (allocation->IsLargeAllocation())
         {
-            this->ProtectAllocation(allocation, readWriteFlags, PAGE_EXECUTE);
-            return PAGE_EXECUTE;
+            this->ProtectAllocation(allocation, readWriteFlags, PAGE_EXECUTE_READ);
+            return PAGE_EXECUTE_READ;
         }
         else
         {

+ 4 - 4
lib/Common/Memory/SectionAllocWrapper.cpp

@@ -85,7 +85,7 @@ PVOID MapView(HANDLE process, HANDLE sectionHandle, size_t size, size_t offset,
         {
             return nullptr;
         }
-        flags = AutoSystemInfo::Data.IsCFGEnabled() ? PAGE_EXECUTE_RO_TARGETS_INVALID : PAGE_EXECUTE;
+        flags = AutoSystemInfo::Data.IsCFGEnabled() ? PAGE_EXECUTE_RO_TARGETS_INVALID : PAGE_EXECUTE_READ;
     }
 
 #if USEFILEMAP2
@@ -590,7 +590,7 @@ SectionAllocWrapper::Alloc(LPVOID requestAddress, size_t dwSize, DWORD allocatio
 
         if ((allocationType & MEM_COMMIT) == MEM_COMMIT)
         {
-            const DWORD allocProtectFlags = AutoSystemInfo::Data.IsCFGEnabled() ? PAGE_EXECUTE_RO_TARGETS_INVALID : PAGE_EXECUTE;
+            const DWORD allocProtectFlags = AutoSystemInfo::Data.IsCFGEnabled() ? PAGE_EXECUTE_RO_TARGETS_INVALID : PAGE_EXECUTE_READ;
             address = VirtualAllocEx(this->process, address, dwSize, MEM_COMMIT, allocProtectFlags);
         }
     }
@@ -717,7 +717,7 @@ PreReservedSectionAllocWrapper::IsInRange(void * address)
     {
         MEMORY_BASIC_INFORMATION memBasicInfo;
         size_t bytes = VirtualQueryEx(this->process, address, &memBasicInfo, sizeof(memBasicInfo));
-        Assert(bytes == 0 || (memBasicInfo.State == MEM_COMMIT && memBasicInfo.AllocationProtect == PAGE_EXECUTE));
+        Assert(bytes == 0 || (memBasicInfo.State == MEM_COMMIT && memBasicInfo.AllocationProtect == PAGE_EXECUTE_READ));
     }
 #endif
     return isInRange;
@@ -920,7 +920,7 @@ LPVOID PreReservedSectionAllocWrapper::Alloc(LPVOID lpAddress, size_t dwSize, DW
             AutoEnableDynamicCodeGen enableCodeGen;
 #endif
 
-            const DWORD allocProtectFlags = AutoSystemInfo::Data.IsCFGEnabled() ? PAGE_EXECUTE_RO_TARGETS_INVALID : PAGE_EXECUTE;
+            const DWORD allocProtectFlags = AutoSystemInfo::Data.IsCFGEnabled() ? PAGE_EXECUTE_RO_TARGETS_INVALID : PAGE_EXECUTE_READ;
             allocatedAddress = (char *)VirtualAllocEx(this->process, addressToReserve, dwSize, MEM_COMMIT, allocProtectFlags);
             if (allocatedAddress == nullptr)
             {