[llvm] r286032 - Correct mprotect page boundries to round up end page. Fixes PR30905.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 21:22:16 PDT 2016


Author: asbirlea
Date: Fri Nov  4 23:22:15 2016
New Revision: 286032

URL: http://llvm.org/viewvc/llvm-project?rev=286032&view=rev
Log:
Correct mprotect page boundries to round up end page. Fixes PR30905.

Summary:
Update the boundries for mprotect.
Patch by Andrew Adams. Fixes PR30905.

Reviewers: loladiro, andrew.w.kaylor, chandlerc

Subscribers: abadams, llvm-commits

Differential Revision: https://reviews.llvm.org/D26312

Modified:
    llvm/trunk/lib/Support/Unix/Memory.inc

Modified: llvm/trunk/lib/Support/Unix/Memory.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Memory.inc?rev=286032&r1=286031&r2=286032&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Memory.inc (original)
+++ llvm/trunk/lib/Support/Unix/Memory.inc Fri Nov  4 23:22:15 2016
@@ -153,7 +153,10 @@ Memory::protectMappedMemory(const Memory
 
   int Protect = getPosixProtectionFlags(Flags);
 
-  int Result = ::mprotect((void*)((uintptr_t)M.Address & ~(PageSize-1)), PageSize*((M.Size+PageSize-1)/PageSize), Protect);
+  uintptr_t Start = alignAddr((uint8_t *)M.Address - PageSize + 1, PageSize);
+  uintptr_t End = alignAddr((uint8_t *)M.Address + M.Size, PageSize);
+  int Result = ::mprotect((void *)Start, End - Start, Protect);
+
   if (Result != 0)
     return std::error_code(errno, std::generic_category());
 




More information about the llvm-commits mailing list