Commits

Armin Rigo committed ad1b2b6

Add jitting to C callbacks only on demand, not systematically. The RPython callback must have
_callback_hook_="somestring". Might fix issue #1363, caused by the callback hook getting in
the way of the shadowstack for the thread's bootstrapper.

Comments (0)

Files changed (4)

pypy/module/_cffi_backend/ccallback.py

         callback.write_error_return_value(ll_res)
     if ec is not None:
         cerrno.restore_errno_from(ec)
+invoke_callback._callback_hook_ = "CFFI"

pypy/module/pyexpat/interp_pyexpat.py

     """ % locals())
 
     exec str(src)
+    callback._callback_hook_ = "XML_" + name
 
     c_name = 'XML_Set' + name
     callback_type = lltype.Ptr(lltype.FuncType(
     else:
         result = 1
     return rffi.cast(rffi.INT, result)
+UnknownEncodingHandlerData_callback._callback_hook_ = None    # no jit needed
 callback_type = lltype.Ptr(lltype.FuncType(
     [rffi.VOIDP, rffi.CCHARP, XML_Encoding_Ptr], rffi.INT))
 XML_SetUnknownEncodingHandler = expat_external(

pypy/rlib/clibffi.py

     """
     userdata = rffi.cast(USERDATA_P, ll_userdata)
     userdata.callback(ll_args, ll_res, userdata)
+ll_callback._callback_hook_ = "CLIBFFI"
 
 class StackCheckError(ValueError):
     message = None

pypy/rpython/lltypesystem/rffi.py

     callable_name = getattr(callable, '__name__', '?')
     if callbackholder is not None:
         callbackholder.callbacks[callable] = True
-    callable_name_descr = str(callable).replace('"', '\\"')
     args = ', '.join(['a%d' % i for i in range(len(TP.TO.ARGS))])
+    invoke_hook = getattr(callable, '_callback_hook_', None)
+    assert invoke_hook is None or isinstance(invoke_hook, str)
+
     source = py.code.Source(r"""
         def inner_wrapper(%(args)s):
-            if aroundstate is not None:
+            if invoke_hook is not None and aroundstate is not None:
                 callback_hook = aroundstate.callback_hook
                 if callback_hook:
-                    callback_hook(llstr("%(callable_name_descr)s"))
+                    callback_hook(llstr(invoke_hook))
             return callable(%(args)s)
         inner_wrapper._never_inline_ = True