[pypy-commit] pypy r15-for-exception: Mostly comments for now, describing the goal.
arigo
noreply at buildbot.pypy.org
Sat Jul 9 11:17:25 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: r15-for-exception
Changeset: r45430:d1c160a1df55
Date: 2011-07-07 12:33 +0200
http://bitbucket.org/pypy/pypy/changeset/d1c160a1df55/
Log: Mostly comments for now, describing the goal.
diff --git a/pypy/translator/register.py b/pypy/translator/register.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/register.py
@@ -0,0 +1,35 @@
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.rpython.tool import rffi_platform
+
+# On platforms with enough hardware registers and with gcc, we can
+# (ab)use gcc to globally assign a register to a single global void*
+# variable. We use it with a double meaning:
+#
+# - when it is NULL upon return from a function, it means that an
+# exception occurred. It allows the caller to quickly check for
+# exceptions.
+#
+# - in other cases, with --gcrootfinder=shadowstack, it points to
+# the top of the shadow stack.
+
+
+# For now, only for x86-64. Tries to use the register r15.
+eci = ExternalCompilationInfo(
+ post_include_bits=['register void* pypy_reg asm("r15");'],
+ )
+
+_test_eci = eci.merge(ExternalCompilationInfo(
+ post_include_bits=["""
+ void f(void) {
+ pypy_reg = &f;
+ }
+ """]))
+
+try:
+ rffi_platform.verify_eci(_test_eci)
+ var_name_in_c = 'pypy_reg'
+ register_number = 15 # r15
+except rffi_platform.CompilationError:
+ eci = None
+ var_name_in_c = None
+ register_number = None
diff --git a/pypy/translator/test/test_register.py b/pypy/translator/test/test_register.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/test/test_register.py
@@ -0,0 +1,13 @@
+
+def test_register():
+ from pypy.translator import register
+ #
+ from pypy.jit.backend.detect_cpu import autodetect
+ if autodetect() == 'x86_64':
+ assert register.eci is not None
+ assert register.var_name_in_c is not None
+ assert register.register_number == 15 # r15
+ else:
+ assert register.eci is None
+ assert register.var_name_in_c is None
+ assert register.register_number is None
More information about the pypy-commit
mailing list