Author: Edd Barrett <[email protected]>
Branch: asmmemmgr-for-code-only
Changeset: r86511:c7822af728c9
Date: 2016-08-24 23:48 +0100
http://bitbucket.org/pypy/pypy/changeset/c7822af728c9/
Log: Fix a load of W^X violations touched in the x86 backend tests.
diff --git a/rpython/jit/backend/llsupport/asmmemmgr.py
b/rpython/jit/backend/llsupport/asmmemmgr.py
--- a/rpython/jit/backend/llsupport/asmmemmgr.py
+++ b/rpython/jit/backend/llsupport/asmmemmgr.py
@@ -230,8 +230,11 @@
targetindex = self._baserelpos
while targetindex >= 0:
dst = rffi.cast(rffi.CCHARP, addr + targetindex)
+ # XXX see if we can move the page fiddling out the loop
+ rmmap.set_pages_writable(dst, blocksize)
for j in range(blocksize):
dst[j] = block.data[j]
+ rmmap.set_pages_executable(dst, blocksize)
block = block.prev
blocksize = self.SUBBLOCK_SIZE
targetindex -= self.SUBBLOCK_SIZE
diff --git a/rpython/jit/backend/llsupport/gcreftracer.py
b/rpython/jit/backend/llsupport/gcreftracer.py
--- a/rpython/jit/backend/llsupport/gcreftracer.py
+++ b/rpython/jit/backend/llsupport/gcreftracer.py
@@ -2,6 +2,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.jit.backend.llsupport.symbolic import WORD
+from rpython.rlib.rmmap import set_pages_executable, set_pages_writable
GCREFTRACER = lltype.GcStruct(
@@ -43,7 +44,10 @@
def make_boehm_tracer(array_base_addr, gcrefs):
# copy the addresses, but return 'gcrefs' as the object that must be
# kept alive
- for i in range(len(gcrefs)):
+ n_gcrefs = len(gcrefs)
+ set_pages_writable(array_base_addr, n_gcrefs * WORD)
+ for i in range(n_gcrefs):
p = rffi.cast(rffi.SIGNEDP, array_base_addr + i * WORD)
p[0] = rffi.cast(lltype.Signed, gcrefs[i])
+ set_pages_executable(array_base_addr, n_gcrefs * WORD)
return gcrefs
diff --git a/rpython/jit/backend/x86/codebuf.py
b/rpython/jit/backend/x86/codebuf.py
--- a/rpython/jit/backend/x86/codebuf.py
+++ b/rpython/jit/backend/x86/codebuf.py
@@ -7,6 +7,7 @@
from rpython.jit.backend.x86.regloc import LocationCodeBuilder
from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64, WORD
from rpython.jit.backend.x86 import valgrind
+from rpython.rlib.rmmap import set_pages_writable, set_pages_executable
# XXX: Seems nasty to change the superclass of MachineCodeBlockWrapper
# like this
@@ -51,5 +52,6 @@
p = addr + reloc
adr = rffi.cast(rffi.INTP, p - 4)
adr[0] = rffi.cast(rffi.INT, intmask(adr[0]) - p)
+
valgrind.discard_translations(addr, self.get_relative_pos())
self._dump(addr, "jit-backend-dump", backend_name)
diff --git a/rpython/jit/backend/x86/detect_feature.py
b/rpython/jit/backend/x86/detect_feature.py
--- a/rpython/jit/backend/x86/detect_feature.py
+++ b/rpython/jit/backend/x86/detect_feature.py
@@ -1,17 +1,23 @@
import sys
import struct
from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.rmmap import alloc, free
+from rpython.rlib.rmmap import (alloc, free, set_pages_writable,
+ set_pages_executable)
+
+CPUINFO_ALLOC_SZ = 4096
+
def cpu_info(instr):
- data = alloc(4096)
+ data = alloc(CPUINFO_ALLOC_SZ)
pos = 0
+ set_pages_writable(data, CPUINFO_ALLOC_SZ)
for c in instr:
data[pos] = c
pos += 1
+ set_pages_executable(data, CPUINFO_ALLOC_SZ)
fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
code = fnptr()
- free(data, 4096)
+ free(data, CPUINFO_ALLOC_SZ)
return code
def detect_sse2():
diff --git a/rpython/jit/backend/x86/test/test_regloc.py
b/rpython/jit/backend/x86/test/test_regloc.py
--- a/rpython/jit/backend/x86/test/test_regloc.py
+++ b/rpython/jit/backend/x86/test/test_regloc.py
@@ -7,6 +7,7 @@
from rpython.jit.backend.x86 import codebuf
from rpython.jit.backend.x86.callbuilder import follow_jump
from rpython.rlib.rarithmetic import intmask
+from rpython.rlib import rmmap
import py.test
class LocationCodeBuilder32(CodeBuilder32, LocationCodeBuilder):
@@ -78,7 +79,7 @@
mc = codebuf.MachineCodeBlockWrapper()
mc.CALL(ImmedLoc(target))
length = mc.get_relative_pos()
- buf = lltype.malloc(rffi.CCHARP.TO, length, flavor='raw')
+ buf = rmmap.alloc(length)
rawstart = rffi.cast(lltype.Signed, buf)
if IS_X86_32:
assert length == 5
@@ -103,17 +104,18 @@
"\x41\xFF\xD3") # CALL *%r11
mc.copy_to_raw_memory(rawstart)
assert ''.join([buf[i] for i in range(length)]) == expected
- lltype.free(buf, flavor='raw')
+ rmmap.free(buf, length)
class Fake32CodeBlockWrapper(codebuf.MachineCodeBlockWrapper):
def check_stack_size_at_ret(self):
pass
def test_follow_jump_instructions_32():
- buf = lltype.malloc(rffi.CCHARP.TO, 80, flavor='raw')
+ size = 80
+ buf = rmmap.alloc(size)
raw = rffi.cast(lltype.Signed, buf)
if not fits_in_32bits(raw):
- lltype.free(buf, flavor='raw')
+ rmmap.free(buf, size)
py.test.skip("not testable")
mc = Fake32CodeBlockWrapper(); mc.WORD = 4; mc.relocations = []
mc.RET()
@@ -137,7 +139,7 @@
assert buf[43] == '\xFF'
assert buf[44] == '\xFF'
assert follow_jump(raw + 40) == raw
- lltype.free(buf, flavor='raw')
+ rmmap.free(buf)
class Test64Bits:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit