1 # We want to access the "PC" (Program Counter) register from a struct
2 # ucontext. Every system has its own way of doing that. We try all the
3 # possibilities we know about. Note REG_PC should come first (REG_RIP
4 # is also defined on solaris, but does the wrong thing).
6 # OpenBSD doesn't have ucontext.h, but we can get PC from ucontext_t
9 # The first argument of AC_PC_FROM_UCONTEXT will be invoked when we
10 # cannot find a way to obtain PC from ucontext.
12 AC_DEFUN([AC_PC_FROM_UCONTEXT],
13 [AC_CHECK_HEADERS(ucontext.h)
14 # Redhat 7 has <sys/ucontext.h>, but it barfs if we #include it directly
15 # (this was fixed in later redhats). <ucontext.h> works fine, so use that.
16 if grep "Red Hat Linux release 7" /etc/redhat-release >/dev/null 2>&1; then
17 AC_DEFINE(HAVE_SYS_UCONTEXT_H, 0, [<sys/ucontext.h> is broken on redhat 7])
18 ac_cv_header_sys_ucontext_h=no
20 AC_CHECK_HEADERS(sys/ucontext.h) # ucontext on OS X 10.6 (at least)
22 AC_CHECK_HEADERS(cygwin/signal.h) # ucontext on cywgin
23 AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
24 pc_fields=" uc_mcontext.gregs[[REG_PC]]" # Solaris x86 (32 + 64 bit)
25 pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
26 pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
27 pc_fields="$pc_fields uc_mcontext.sc_ip" # Linux (ia64)
28 pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
29 pc_fields="$pc_fields uc_mcontext.gregs[[R15]]" # Linux (arm old [untested])
30 pc_fields="$pc_fields uc_mcontext.arm_pc" # Linux (arm arch 5)
31 pc_fields="$pc_fields uc_mcontext.gp_regs[[PT_NIP]]" # Suse SLES 11 (ppc64)
32 pc_fields="$pc_fields uc_mcontext.mc_eip" # FreeBSD (i386)
33 pc_fields="$pc_fields uc_mcontext.mc_rip" # FreeBSD (x86_64 [untested])
34 pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_EIP]]" # NetBSD (i386)
35 pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_RIP]]" # NetBSD (x86_64)
36 pc_fields="$pc_fields uc_mcontext->ss.eip" # OS X (i386, <=10.4)
37 pc_fields="$pc_fields uc_mcontext->__ss.__eip" # OS X (i386, >=10.5)
38 pc_fields="$pc_fields uc_mcontext->ss.rip" # OS X (x86_64)
39 pc_fields="$pc_fields uc_mcontext->__ss.__rip" # OS X (>=10.5 [untested])
40 pc_fields="$pc_fields uc_mcontext->ss.srr0" # OS X (ppc, ppc64 [untested])
41 pc_fields="$pc_fields uc_mcontext->__ss.__srr0" # OS X (>=10.5 [untested])
43 for pc_field in $pc_fields; do
44 if ! $pc_field_found; then
45 # Prefer sys/ucontext.h to ucontext.h, for OS X's sake.
46 if test "x$ac_cv_header_cygwin_signal_h" = xyes; then
47 AC_TRY_COMPILE([#define _GNU_SOURCE 1
48 #include <cygwin/signal.h>],
49 [ucontext_t u; return u.$pc_field == 0;],
50 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
51 How to access the PC from a struct ucontext)
52 AC_MSG_RESULT([$pc_field])
54 elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then
55 AC_TRY_COMPILE([#define _GNU_SOURCE 1
56 #include <sys/ucontext.h>],
57 [ucontext_t u; return u.$pc_field == 0;],
58 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
59 How to access the PC from a struct ucontext)
60 AC_MSG_RESULT([$pc_field])
62 elif test "x$ac_cv_header_ucontext_h" = xyes; then
63 AC_TRY_COMPILE([#define _GNU_SOURCE 1
64 #include <ucontext.h>],
65 [ucontext_t u; return u.$pc_field == 0;],
66 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
67 How to access the PC from a struct ucontext)
68 AC_MSG_RESULT([$pc_field])
70 else # hope some standard header gives it to us
72 [ucontext_t u; return u.$pc_field == 0;],
73 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
74 How to access the PC from a struct ucontext)
75 AC_MSG_RESULT([$pc_field])
80 if ! $pc_field_found; then
81 pc_fields=" sc_eip" # OpenBSD (i386)
82 pc_fields="$pc_fields sc_rip" # OpenBSD (x86_64)
83 for pc_field in $pc_fields; do
84 if ! $pc_field_found; then
85 AC_TRY_COMPILE([#include <signal.h>],
86 [ucontext_t u; return u.$pc_field == 0;],
87 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
88 How to access the PC from a struct ucontext)
89 AC_MSG_RESULT([$pc_field])
94 if ! $pc_field_found; then