[pypy-svn] r71712 - in pypy/trunk/pypy: jit/backend/x86 rlib rlib/rsre translator/sandbox translator/sandbox/test
fijal at codespeak.net
fijal at codespeak.net
Wed Mar 3 18:38:51 CET 2010
Author: fijal
Date: Wed Mar 3 18:38:49 2010
New Revision: 71712
Modified:
pypy/trunk/pypy/jit/backend/x86/codebuf.py
pypy/trunk/pypy/jit/backend/x86/valgrind.py
pypy/trunk/pypy/rlib/rmmap.py
pypy/trunk/pypy/rlib/rsre/_rsre_platform.py
pypy/trunk/pypy/translator/sandbox/sandlib.py
pypy/trunk/pypy/translator/sandbox/test/test_sandbox.py
Log:
Merge jit-sandbox branch, that enables jit to cooperate with sandbox, minor
issues only
Modified: pypy/trunk/pypy/jit/backend/x86/codebuf.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/codebuf.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/codebuf.py Wed Mar 3 18:38:49 2010
@@ -155,4 +155,5 @@
separate_module_sources = ['void PYPY_NO_OP(void) {}'],
)
ensure_sse2_floats = rffi.llexternal('PYPY_NO_OP', [], lltype.Void,
- compilation_info=_sse2_eci)
+ compilation_info=_sse2_eci,
+ sandboxsafe=True)
Modified: pypy/trunk/pypy/jit/backend/x86/valgrind.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/valgrind.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/valgrind.py Wed Mar 3 18:38:49 2010
@@ -20,7 +20,8 @@
[llmemory.Address, lltype.Signed],
lltype.Void,
compilation_info=eci,
- _nowrapper=True)
+ _nowrapper=True,
+ sandboxsafe=True)
# ____________________________________________________________
Modified: pypy/trunk/pypy/rlib/rmmap.py
==============================================================================
--- pypy/trunk/pypy/rlib/rmmap.py (original)
+++ pypy/trunk/pypy/rlib/rmmap.py Wed Mar 3 18:38:49 2010
@@ -91,26 +91,32 @@
_ACCESS_DEFAULT, ACCESS_READ, ACCESS_WRITE, ACCESS_COPY = range(4)
def external(name, args, result):
- return rffi.llexternal(name, args, result,
- compilation_info=CConfig._compilation_info_)
+ unsafe = rffi.llexternal(name, args, result,
+ compilation_info=CConfig._compilation_info_)
+ safe = rffi.llexternal(name, args, result,
+ compilation_info=CConfig._compilation_info_,
+ sandboxsafe=True, threadsafe=False)
+ return unsafe, safe
def winexternal(name, args, result):
return rffi.llexternal(name, args, result, compilation_info=CConfig._compilation_info_, calling_conv='win')
PTR = rffi.CCHARP
-c_memmove = external('memmove', [PTR, PTR, size_t], lltype.Void)
+c_memmove, _ = external('memmove', [PTR, PTR, size_t], lltype.Void)
if _POSIX:
has_mremap = cConfig['has_mremap']
- c_mmap = external('mmap', [PTR, size_t, rffi.INT, rffi.INT,
+ c_mmap, c_mmap_safe = external('mmap', [PTR, size_t, rffi.INT, rffi.INT,
rffi.INT, off_t], PTR)
- c_munmap = external('munmap', [PTR, size_t], rffi.INT)
- c_msync = external('msync', [PTR, size_t, rffi.INT], rffi.INT)
+ c_munmap, c_munmap_safe = external('munmap', [PTR, size_t], rffi.INT)
+ c_msync, _ = external('msync', [PTR, size_t, rffi.INT], rffi.INT)
if has_mremap:
- c_mremap = external('mremap', [PTR, size_t, size_t, rffi.ULONG], PTR)
+ c_mremap, _ = external('mremap',
+ [PTR, size_t, size_t, rffi.ULONG], PTR)
- _get_page_size = external('getpagesize', [], rffi.INT)
+ # this one is always safe
+ _, _get_page_size = external('getpagesize', [], rffi.INT)
def _get_error_no():
return rposix.get_errno()
@@ -630,17 +636,21 @@
hint = Hint()
def alloc(map_size):
+ """Allocate memory. This is intended to be used by the JIT,
+ so the memory has the executable bit set and gets allocated
+ internally in case of a sandboxed process.
+ """
flags = MAP_PRIVATE | MAP_ANONYMOUS
prot = PROT_EXEC | PROT_READ | PROT_WRITE
hintp = rffi.cast(PTR, hint.pos)
- res = c_mmap(hintp, map_size, prot, flags, -1, 0)
+ res = c_mmap_safe(hintp, map_size, prot, flags, -1, 0)
if res == rffi.cast(PTR, -1):
raise MemoryError
hint.pos += map_size
return res
alloc._annenforceargs_ = (int,)
- free = c_munmap
+ free = c_munmap_safe
elif _MS_WINDOWS:
def mmap(fileno, length, tagname="", access=_ACCESS_DEFAULT):
@@ -742,6 +752,11 @@
def alloc(map_size):
+ """Allocate memory. This is intended to be used by the JIT,
+ so the memory has the executable bit set.
+ XXX implement me: it should get allocated internally in
+ case of a sandboxed process
+ """
null = lltype.nullptr(rffi.VOIDP.TO)
res = VirtualAlloc(null, map_size, MEM_COMMIT|MEM_RESERVE,
PAGE_EXECUTE_READWRITE)
Modified: pypy/trunk/pypy/rlib/rsre/_rsre_platform.py
==============================================================================
--- pypy/trunk/pypy/rlib/rsre/_rsre_platform.py (original)
+++ pypy/trunk/pypy/rlib/rsre/_rsre_platform.py Wed Mar 3 18:38:49 2010
@@ -10,7 +10,8 @@
return rffi.llexternal(name, args, result, compilation_info=eci, **kwds)
tolower = external('tolower', [lltype.Signed], lltype.Signed,
- oo_primitive='tolower')
+ oo_primitive='tolower',
+ sandboxsafe=True)
isalnum = external('isalnum', [lltype.Signed], lltype.Signed,
- oo_primitive='isalnum')
+ oo_primitive='isalnum', sandboxsafe=True)
Modified: pypy/trunk/pypy/translator/sandbox/sandlib.py
==============================================================================
--- pypy/trunk/pypy/translator/sandbox/sandlib.py (original)
+++ pypy/trunk/pypy/translator/sandbox/sandlib.py Wed Mar 3 18:38:49 2010
@@ -10,7 +10,7 @@
from pypy.rpython.module.ll_os_stat import s_StatResult
from pypy.tool.ansi_print import AnsiLog
from pypy.rlib.rarithmetic import r_longlong
-from py.compat import subprocess
+import subprocess
from pypy.tool.killsubprocess import killsubprocess
class MyAnsiLog(AnsiLog):
Modified: pypy/trunk/pypy/translator/sandbox/test/test_sandbox.py
==============================================================================
--- pypy/trunk/pypy/translator/sandbox/test/test_sandbox.py (original)
+++ pypy/trunk/pypy/translator/sandbox/test/test_sandbox.py Wed Mar 3 18:38:49 2010
@@ -1,6 +1,7 @@
import py
import sys, os, time
import struct
+import subprocess
from pypy.rpython.lltypesystem import rffi
from pypy.translator.interactive import Translation
@@ -19,8 +20,8 @@
write_message(g, result, resulttype)
g.flush()
-def compile(f):
- t = Translation(f, backend='c', standalone=True, sandbox=True, gc='ref')
+def compile(f, gc='ref'):
+ t = Translation(f, backend='c', standalone=True, sandbox=True, gc=gc)
return str(t.compile())
@@ -131,6 +132,72 @@
f.close()
assert tail == ""
+def test_hybrid_gc():
+ def entry_point(argv):
+ l = []
+ for i in range(int(argv[1])):
+ l.append("x" * int(argv[2]))
+ return int(len(l) > 1000)
+
+ exe = compile(entry_point, gc='hybrid')
+ pipe = subprocess.Popen([exe, '10', '10000'], stdout=subprocess.PIPE,
+ stdin=subprocess.PIPE)
+ g = pipe.stdin
+ f = pipe.stdout
+ expect(f, g, "ll_os.ll_os_getenv", ("PYPY_GENERATIONGC_NURSERY",), None)
+ expect(f, g, "ll_os.ll_os_open", ("/proc/cpuinfo", 0, 420), OSError(5232, "xyz"))
+ g.close()
+ tail = f.read()
+ f.close()
+ assert tail == ""
+ rescode = pipe.wait()
+ assert rescode == 0
+
+def test_safe_alloc():
+ from pypy.rlib.rmmap import alloc, free
+
+ def entry_point(argv):
+ one = alloc(1024)
+ free(one, 1024)
+ return 0
+
+ exe = compile(entry_point)
+ pipe = subprocess.Popen([exe], stdout=subprocess.PIPE,
+ stdin=subprocess.PIPE)
+ g = pipe.stdin
+ f = pipe.stdout
+ g.close()
+ tail = f.read()
+ f.close()
+ assert tail == ""
+ rescode = pipe.wait()
+ assert rescode == 0
+
+def test_unsafe_mmap():
+ py.test.skip("Since this stuff is unimplemented, it won't work anyway "
+ "however, the day it starts working, it should pass test")
+ from pypy.rlib.rmmap import mmap
+
+ def entry_point(argv):
+ try:
+ res = mmap(0, 1024)
+ except OSError:
+ return 0
+ return 1
+
+ exe = compile(entry_point)
+ pipe = subprocess.Popen([exe], stdout=subprocess.PIPE,
+ stdin=subprocess.PIPE)
+ g = pipe.stdin
+ f = pipe.stdout
+ expect(f, g, "mmap", ARGS, OSError(1, "xyz"))
+ g.close()
+ tail = f.read()
+ f.close()
+ assert tail == ""
+ rescode = pipe.wait()
+ assert rescode == 0
+
class TestPrintedResults:
def run(self, entry_point, args, expected):
More information about the Pypy-commit
mailing list