[pypy-commit] pypy sandbox-2: in-progress

arigo pypy.commits at gmail.com
Mon Aug 26 05:12:13 EDT 2019


Author: Armin Rigo <arigo at tunes.org>
Branch: sandbox-2
Changeset: r97260:84f2711b0798
Date: 2019-08-26 11:11 +0200
http://bitbucket.org/pypy/pypy/changeset/84f2711b0798/

Log:	in-progress

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -1171,6 +1171,8 @@
 
 
     def unpin(self, obj):
+        if self.safer_variant():
+            out_of_memory("unpin() unexpected")
         ll_assert(self._is_pinned(obj),
             "unpin: object is already not pinned")
         #
@@ -1181,6 +1183,8 @@
         return (self.header(obj).tid & GCFLAG_PINNED) != 0
 
     def shrink_array(self, obj, smallerlength):
+        if self.safer_variant():    # no shrinking in the safer variant
+            return False       # (because the original 'obj' is kind of broken)
         #
         # Only objects in the nursery can be "resized".  Resizing them
         # means recording that they have a smaller size, so that when
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -6,6 +6,7 @@
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import we_are_translated, enforceargs, specialize
 from rpython.rlib.objectmodel import CDefinedIntSymbolic, not_rpython
+from rpython.rlib.objectmodel import sandbox_review
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rtyper.lltypesystem import lltype, llmemory
 
@@ -361,6 +362,7 @@
 
 @jit.oopspec('list.ll_arraycopy(source, dest, source_start, dest_start, length)')
 @enforceargs(None, None, int, int, int)
+ at sandbox_review(check_caller=True)
 @specialize.ll()
 def ll_arraycopy(source, dest, source_start, dest_start, length):
     from rpython.rtyper.lltypesystem.lloperation import llop
@@ -415,6 +417,7 @@
 
 @jit.oopspec('rgc.ll_shrink_array(p, smallerlength)')
 @enforceargs(None, int)
+ at sandbox_review(reviewed=True)
 @specialize.ll()
 def ll_shrink_array(p, smallerlength):
     from rpython.rtyper.lltypesystem.lloperation import llop
@@ -454,6 +457,7 @@
     return newp
 
 @jit.dont_look_inside
+ at sandbox_review(reviewed=True)
 @specialize.ll()
 def ll_arrayclear(p):
     # Equivalent to memset(array, 0).  Only for GcArray(primitive-type) for now.
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -801,6 +801,7 @@
         lastchar = u'\x00'
 
     # str -> char*
+    @sandbox_review(reviewed=True)
     def str2charp(s, track_allocation=True):
         """ str -> char*
         """
@@ -815,6 +816,7 @@
         return array
     str2charp._annenforceargs_ = [strtype, bool]
 
+    @sandbox_review(reviewed=True)
     def free_charp(cp, track_allocation=True):
         if track_allocation:
             lltype.free(cp, flavor='raw', track_allocation=True)
@@ -930,6 +932,7 @@
 
     # int -> (char*, str, int)
     # Can't inline this because of the raw address manipulation.
+    @sandbox_review(reviewed=True)
     @jit.dont_look_inside
     def alloc_buffer(count):
         """
diff --git a/rpython/rtyper/lltypesystem/rlist.py b/rpython/rtyper/lltypesystem/rlist.py
--- a/rpython/rtyper/lltypesystem/rlist.py
+++ b/rpython/rtyper/lltypesystem/rlist.py
@@ -10,6 +10,7 @@
     ADTIList, ADTIFixedList, dum_nocheck)
 from rpython.rtyper.rmodel import Repr, inputconst, externalvsinternal
 from rpython.tool.pairtype import pairtype, pair
+from rpython.rlib.objectmodel import sandbox_review
 
 
 # ____________________________________________________________
@@ -196,6 +197,7 @@
 # adapted C code
 
 @jit.look_inside_iff(lambda l, newsize, overallocate: jit.isconstant(len(l.items)) and jit.isconstant(newsize))
+ at sandbox_review(reviewed=True)
 @signature(types.any(), types.int(), types.bool(), returns=types.none())
 def _ll_list_resize_hint_really(l, newsize, overallocate):
     """
diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -115,7 +115,7 @@
     copy_string_contents = func_with_new_name(copy_string_contents,
                                               'copy_%s_contents' % name)
 
-    @sandbox_review(reviewed=True)
+    @sandbox_review(check_caller=True)
     @jit.oopspec('stroruni.copy_string_to_raw(src, ptrdst, srcstart, length)')
     def copy_string_to_raw(src, ptrdst, srcstart, length):
         """
diff --git a/rpython/translator/sandbox/graphchecker.py b/rpython/translator/sandbox/graphchecker.py
--- a/rpython/translator/sandbox/graphchecker.py
+++ b/rpython/translator/sandbox/graphchecker.py
@@ -7,7 +7,6 @@
 from rpython.flowspace.model import SpaceOperation, Constant
 from rpython.rtyper.rmodel import inputconst
 from rpython.rtyper.lltypesystem import lltype, llmemory, rstr
-from rpython.rtyper.lltypesystem.rffi import sandbox_check_type
 from rpython.rtyper.lltypesystem.lloperation import LL_OPERATIONS
 from rpython.translator.unsimplify import varoftype
 from rpython.tool.ansi_print import AnsiLogger
@@ -22,6 +21,8 @@
     'malloc', 'malloc_varsize', 'free',
     'getfield', 'getarrayitem', 'getinteriorfield',
     'gc_thread_run',
+    'shrink_array', 'gc_pin', 'gc_unpin', 'gc_can_move',
+    'debug_fatalerror',
     ])
 gc_set_operations = set([
     'setfield', 'setarrayitem', 'setinteriorfield',
@@ -39,6 +40,8 @@
     op = SpaceOperation('debug_fatalerror', [c_err], varoftype(lltype.Void))
     graph.startblock.operations.insert(0, op)
 
+def is_gc_ptr(TYPE):
+    return isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc'
 
 
 class GraphChecker(object):
@@ -77,11 +80,12 @@
                 else:
                     return "direct_call to %r" % (obj,)
 
-            elif opname == 'force_cast':
-                if sandbox_check_type(op.result.concretetype):
-                    return "force_cast to pointer type: %r" % (op,)
-                if sandbox_check_type(op.args[0].concretetype):
-                    return "force_cast from pointer type: %r" % (op,)
+            elif opname in ('cast_ptr_to_adr', 'force_cast'):
+                if is_gc_ptr(op.args[0].concretetype):
+                    return "argument is a GC ptr: %r" % (opname,)
+                if is_gc_ptr(op.result.concretetype):
+                    return "result is a GC ptr: %r" % (opname,)
+
             else:
                 return "unsupported llop: %r" % (opname,)
 


More information about the pypy-commit mailing list