[PATCH] D26312: 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 15:09:36 PDT 2016


asbirlea created this revision.
asbirlea added reviewers: loladiro, andrew.w.kaylor, chandlerc.
asbirlea added subscribers: llvm-commits, abadams.

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


https://reviews.llvm.org/D26312

Files:
  lib/Support/Unix/Memory.inc


Index: lib/Support/Unix/Memory.inc
===================================================================
--- lib/Support/Unix/Memory.inc
+++ lib/Support/Unix/Memory.inc
@@ -153,7 +153,14 @@
 
   int Protect = getPosixProtectionFlags(Flags);
 
-  int Result = ::mprotect((void*)((uintptr_t)M.Address & ~(PageSize-1)), PageSize*((M.Size+PageSize-1)/PageSize), Protect);
+  uintptr_t start = (uintptr_t)M.Address;
+  uintptr_t end = start + M.Size;
+  // Round down the start address to a page boundary
+  start = start & ~(PageSize - 1);
+  // Round up the end address to a page boundary
+  end = (end + PageSize - 1) & ~(PageSize - 1);
+  int Result = ::mprotect((void*)start, end - start, Protect);
+
   if (Result != 0)
     return std::error_code(errno, std::generic_category());
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26312.76949.patch
Type: text/x-patch
Size: 782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/cdfd5cdf/attachment.bin>


More information about the llvm-commits mailing list