[pypy-commit] pypy w-xor-x: Only allocate writable pages, and supply functions to change protection mask.
vext01
pypy.commits at gmail.com
Mon Aug 15 09:54:03 EDT 2016
Author: Edd Barrett <vext01 at gmail.com>
Branch: w-xor-x
Changeset: r86197:e32e8a566374
Date: 2016-08-15 14:51 +0100
http://bitbucket.org/pypy/pypy/changeset/e32e8a566374/
Log: Only allocate writable pages, and supply functions to change
protection mask.
diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py
--- a/rpython/rlib/rmmap.py
+++ b/rpython/rlib/rmmap.py
@@ -155,6 +155,8 @@
c_mmap, c_mmap_safe = external('mmap', [PTR, size_t, rffi.INT, rffi.INT,
rffi.INT, off_t], PTR, macro=True,
save_err_on_unsafe=rffi.RFFI_SAVE_ERRNO)
+ c_mprotect, _ = external('mprotect',
+ [PTR, size_t, rffi.INT], rffi.INT)
# 'mmap' on linux32 is a macro that calls 'mmap64'
_, c_munmap_safe = external('munmap', [PTR, size_t], rffi.INT)
c_msync, _ = external('msync', [PTR, size_t, rffi.INT], rffi.INT,
@@ -707,12 +709,22 @@
def alloc_hinted(hintp, map_size):
flags = MAP_PRIVATE | MAP_ANONYMOUS
- prot = PROT_EXEC | PROT_READ | PROT_WRITE
+ prot = PROT_READ | PROT_WRITE
if we_are_translated():
flags = NonConstant(flags)
prot = NonConstant(prot)
return c_mmap_safe(hintp, map_size, prot, flags, -1, 0)
+ def set_pages_executable(addr, size):
+ rv = c_mprotect(addr, size, PROT_EXEC | PROT_READ)
+ if rv < 0:
+ debug.fatalerror_notb("set_pages_executable failed")
+
+ def set_pages_writable(addr, size):
+ rv = c_mprotect(addr, size, PROT_WRITE | PROT_READ)
+ if rv < 0:
+ debug.fatalerror_notb("set_pages_executable failed")
+
def clear_large_memory_chunk_aligned(addr, map_size):
addr = rffi.cast(PTR, addr)
flags = MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS
@@ -951,6 +963,9 @@
return res
alloc._annenforceargs_ = (int,)
+ def set_pages_executable(addr, size):
+ pass # XXX not implemented on windows
+
def free(ptr, map_size):
VirtualFree_safe(ptr, 0, MEM_RELEASE)
More information about the pypy-commit
mailing list