[pypy-svn] r71679 - in pypy/branch/jit-sandbox/pypy: rlib translator/sandbox/test
fijal at codespeak.net
fijal at codespeak.net
Wed Mar 3 00:11:57 CET 2010
Author: fijal
Date: Wed Mar 3 00:11:56 2010
New Revision: 71679
Modified:
pypy/branch/jit-sandbox/pypy/rlib/rmmap.py
pypy/branch/jit-sandbox/pypy/translator/sandbox/test/test_sandbox.py
Log:
Be extra paranoid on rmmap. This is non-issue, since this stuff is unsupported
by sandbox anyway, however if one day we start supporting it, there is a test.
Modified: pypy/branch/jit-sandbox/pypy/rlib/rmmap.py
==============================================================================
--- pypy/branch/jit-sandbox/pypy/rlib/rmmap.py (original)
+++ pypy/branch/jit-sandbox/pypy/rlib/rmmap.py Wed Mar 3 00:11:56 2010
@@ -91,27 +91,32 @@
_ACCESS_DEFAULT, ACCESS_READ, ACCESS_WRITE, ACCESS_COPY = range(4)
def external(name, args, result):
- return rffi.llexternal(name, args, result,
+ 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=True)
+ 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', sandboxsafe=True, threadsafe=True)
+ 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()
@@ -634,14 +639,14 @@
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):
Modified: pypy/branch/jit-sandbox/pypy/translator/sandbox/test/test_sandbox.py
==============================================================================
--- pypy/branch/jit-sandbox/pypy/translator/sandbox/test/test_sandbox.py (original)
+++ pypy/branch/jit-sandbox/pypy/translator/sandbox/test/test_sandbox.py Wed Mar 3 00:11:56 2010
@@ -153,6 +153,51 @@
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