From: Stefano Rivera <stefanor@debian.org>
Date: Thu, 16 Aug 2018 14:24:34 -0700
Subject: Disable vmprof entirely when not supported (e.g. hurd)

rvmprof.dummy is not really working, at least for pypy.  Try to fix it
some more, but give up for now.  Instead, robustly detect that vmprof is
not supported from pypyoption and disable the '_vmprof' and
'faulthandler' modules.

Author: Armin Rigo <arigo@tunes.org>
Origin: upstream, https://bitbucket.org/pypy/pypy/commits/0ee5333ce97ea580ca99c024fec9afd96b7e0db4
---
 pypy/config/pypyoption.py         | 13 +++++--------
 rpython/rlib/rvmprof/dummy.py     |  1 +
 rpython/rlib/rvmprof/rvmprof.py   |  1 +
 rpython/rlib/rvmprof/traceback.py |  4 ++++
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
index b827d28..676d2c0 100644
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -39,14 +39,10 @@ working_modules.update([
     "_csv", "_cppyy", "_pypyjson", "_jitlog"
 ])
 
-from rpython.jit.backend import detect_cpu
-try:
-    if detect_cpu.autodetect().startswith('x86'):
-        if not sys.platform.startswith('openbsd'):
-            working_modules.add('_vmprof')
-            working_modules.add('faulthandler')
-except detect_cpu.ProcessorAutodetectError:
-    pass
+import rpython.rlib.rvmprof.cintf
+if rpython.rlib.rvmprof.cintf.IS_SUPPORTED:
+    working_modules.add('_vmprof')
+    working_modules.add('faulthandler')
 
 translation_modules = default_modules.copy()
 translation_modules.update([
@@ -315,3 +311,4 @@ if __name__ == '__main__':
     parser = to_optparse(config) #, useoptions=["translation.*"])
     option, args = parser.parse_args()
     print config
+    print working_modules
diff --git a/rpython/rlib/rvmprof/dummy.py b/rpython/rlib/rvmprof/dummy.py
index 89582e7..42595d8 100644
--- a/rpython/rlib/rvmprof/dummy.py
+++ b/rpython/rlib/rvmprof/dummy.py
@@ -1,6 +1,7 @@
 from rpython.rlib.objectmodel import specialize
 
 class DummyVMProf(object):
+    is_enabled = False
 
     def __init__(self):
         self._unique_id = 0
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
index 083e883..3df3b3c 100644
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -23,6 +23,7 @@ VMPROF_JITTING_TAG = 4
 VMPROF_GC_TAG = 5
 
 class VMProfError(Exception):
+    msg = ''   # annotation hack
     def __init__(self, msg):
         self.msg = msg
     def __str__(self):
diff --git a/rpython/rlib/rvmprof/traceback.py b/rpython/rlib/rvmprof/traceback.py
index 4abede4..566f275 100644
--- a/rpython/rlib/rvmprof/traceback.py
+++ b/rpython/rlib/rvmprof/traceback.py
@@ -13,6 +13,8 @@ def traceback(estimate_number_of_entries):
     array_length).  The caller must free array_p.  Not for signal handlers:
     for these, call vmprof_get_traceback() from C code.
     """
+    if not cintf.IS_SUPPORTED:
+        return (None, 0)
     _cintf = rvmprof._get_vmprof().cintf
     size = estimate_number_of_entries * 2 + 4
     stack = cintf.get_rvmprof_stack()
@@ -47,6 +49,8 @@ def walk_traceback(CodeClass, callback, arg, array_p, array_length):
     'code_obj' may be None if it can't be determined.  'loc' is one
     of the LOC_xxx constants.
     """
+    if not cintf.IS_SUPPORTED:
+        return
     i = 0
     while i < array_length - 1:
         tag = array_p[i]
