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 AC_CHECK_HEADERS(sys/ucontext.h) # ucontext on OS X 10.6 (at least)
15 AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
16 pc_fields=" uc_mcontext.gregs[[REG_PC]]" # Solaris x86 (32 + 64 bit)
17 pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
18 pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
19 pc_fields="$pc_fields uc_mcontext.sc_ip" # Linux (ia64)
20 pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
21 pc_fields="$pc_fields uc_mcontext.gregs[[R15]]" # Linux (arm old [untested])
22 pc_fields="$pc_fields uc_mcontext.arm_pc" # Linux (arm new [untested])
23 pc_fields="$pc_fields uc_mcontext.mc_eip" # FreeBSD (i386)
24 pc_fields="$pc_fields uc_mcontext.mc_rip" # FreeBSD (x86_64 [untested])
25 pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_EIP]]" # NetBSD (i386)
26 pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_RIP]]" # NetBSD (x86_64)
27 pc_fields="$pc_fields uc_mcontext->ss.eip" # OS X (i386, <=10.4)
28 pc_fields="$pc_fields uc_mcontext->__ss.__eip" # OS X (i386, >=10.5)
29 pc_fields="$pc_fields uc_mcontext->ss.rip" # OS X (x86_64)
30 pc_fields="$pc_fields uc_mcontext->__ss.__rip" # OS X (>=10.5 [untested])
31 pc_fields="$pc_fields uc_mcontext->ss.srr0" # OS X (ppc, ppc64 [untested])
32 pc_fields="$pc_fields uc_mcontext->__ss.__srr0" # OS X (>=10.5 [untested])
34 for pc_field in $pc_fields; do
35 if ! $pc_field_found; then
36 if test "x$ac_cv_header_sys_ucontext_h" = xyes; then
37 AC_TRY_COMPILE([#define _GNU_SOURCE 1
38 #include <sys/ucontext.h>],
39 [ucontext_t u; return u.$pc_field == 0;],
40 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
41 How to access the PC from a struct ucontext)
42 AC_MSG_RESULT([$pc_field])
45 AC_TRY_COMPILE([#define _GNU_SOURCE 1
46 #include <ucontext.h>],
47 [ucontext_t u; return u.$pc_field == 0;],
48 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
49 How to access the PC from a struct ucontext)
50 AC_MSG_RESULT([$pc_field])
55 if ! $pc_field_found; then
56 pc_fields=" sc_eip" # OpenBSD (i386)
57 pc_fields="$pc_fields sc_rip" # OpenBSD (x86_64)
58 for pc_field in $pc_fields; do
59 if ! $pc_field_found; then
60 AC_TRY_COMPILE([#include <signal.h>],
61 [ucontext_t u; return u.$pc_field == 0;],
62 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
63 How to access the PC from a struct ucontext)
64 AC_MSG_RESULT([$pc_field])
69 if ! $pc_field_found; then