pc_from_ucontext.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # This file is from Google Performance Tools, svn revision r226.
  2. #
  3. # The Google Performance Tools license is:
  4. ########
  5. # Copyright (c) 2005, Google Inc.
  6. # All rights reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions are
  10. # met:
  11. #
  12. # * Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. # * Redistributions in binary form must reproduce the above
  15. # copyright notice, this list of conditions and the following disclaimer
  16. # in the documentation and/or other materials provided with the
  17. # distribution.
  18. # * Neither the name of Google Inc. nor the names of its
  19. # contributors may be used to endorse or promote products derived from
  20. # this software without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. ########
  34. # Original file follows below.
  35. # We want to access the "PC" (Program Counter) register from a struct
  36. # ucontext. Every system has its own way of doing that. We try all the
  37. # possibilities we know about. Note REG_PC should come first (REG_RIP
  38. # is also defined on solaris, but does the wrong thing).
  39. # OpenBSD doesn't have ucontext.h, but we can get PC from ucontext_t
  40. # by using signal.h.
  41. # The first argument of AC_PC_FROM_UCONTEXT will be invoked when we
  42. # cannot find a way to obtain PC from ucontext.
  43. AC_DEFUN([AC_PC_FROM_UCONTEXT],
  44. [AC_CHECK_HEADERS(ucontext.h)
  45. # Redhat 7 has <sys/ucontext.h>, but it barfs if we #include it directly
  46. # (this was fixed in later redhats). <ucontext.h> works fine, so use that.
  47. if grep "Red Hat Linux release 7" /etc/redhat-release >/dev/null 2>&1; then
  48. AC_DEFINE(HAVE_SYS_UCONTEXT_H, 0, [<sys/ucontext.h> is broken on redhat 7])
  49. ac_cv_header_sys_ucontext_h=no
  50. else
  51. AC_CHECK_HEADERS(sys/ucontext.h) # ucontext on OS X 10.6 (at least)
  52. fi
  53. AC_CHECK_HEADERS(cygwin/signal.h) # ucontext on cywgin
  54. AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
  55. pc_fields=" uc_mcontext.gregs[[REG_PC]]" # Solaris x86 (32 + 64 bit)
  56. pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
  57. pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
  58. pc_fields="$pc_fields uc_mcontext.sc_ip" # Linux (ia64)
  59. pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
  60. pc_fields="$pc_fields uc_mcontext.gregs[[R15]]" # Linux (arm old [untested])
  61. pc_fields="$pc_fields uc_mcontext.arm_pc" # Linux (arm arch 5)
  62. pc_fields="$pc_fields uc_mcontext.gp_regs[[PT_NIP]]" # Suse SLES 11 (ppc64)
  63. pc_fields="$pc_fields uc_mcontext.mc_eip" # FreeBSD (i386)
  64. pc_fields="$pc_fields uc_mcontext.mc_rip" # FreeBSD (x86_64 [untested])
  65. pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_EIP]]" # NetBSD (i386)
  66. pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_RIP]]" # NetBSD (x86_64)
  67. pc_fields="$pc_fields uc_mcontext->ss.eip" # OS X (i386, <=10.4)
  68. pc_fields="$pc_fields uc_mcontext->__ss.__eip" # OS X (i386, >=10.5)
  69. pc_fields="$pc_fields uc_mcontext->ss.rip" # OS X (x86_64)
  70. pc_fields="$pc_fields uc_mcontext->__ss.__rip" # OS X (>=10.5 [untested])
  71. pc_fields="$pc_fields uc_mcontext->ss.srr0" # OS X (ppc, ppc64 [untested])
  72. pc_fields="$pc_fields uc_mcontext->__ss.__srr0" # OS X (>=10.5 [untested])
  73. pc_field_found=false
  74. for pc_field in $pc_fields; do
  75. if ! $pc_field_found; then
  76. # Prefer sys/ucontext.h to ucontext.h, for OS X's sake.
  77. if test "x$ac_cv_header_cygwin_signal_h" = xyes; then
  78. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  79. #include <cygwin/signal.h>],
  80. [ucontext_t u; return u.$pc_field == 0;],
  81. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  82. How to access the PC from a struct ucontext)
  83. AC_MSG_RESULT([$pc_field])
  84. pc_field_found=true)
  85. elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then
  86. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  87. #include <sys/ucontext.h>],
  88. [ucontext_t u; return u.$pc_field == 0;],
  89. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  90. How to access the PC from a struct ucontext)
  91. AC_MSG_RESULT([$pc_field])
  92. pc_field_found=true)
  93. elif test "x$ac_cv_header_ucontext_h" = xyes; then
  94. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  95. #include <ucontext.h>],
  96. [ucontext_t u; return u.$pc_field == 0;],
  97. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  98. How to access the PC from a struct ucontext)
  99. AC_MSG_RESULT([$pc_field])
  100. pc_field_found=true)
  101. else # hope some standard header gives it to us
  102. AC_TRY_COMPILE([],
  103. [ucontext_t u; return u.$pc_field == 0;],
  104. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  105. How to access the PC from a struct ucontext)
  106. AC_MSG_RESULT([$pc_field])
  107. pc_field_found=true)
  108. fi
  109. fi
  110. done
  111. if ! $pc_field_found; then
  112. pc_fields=" sc_eip" # OpenBSD (i386)
  113. pc_fields="$pc_fields sc_rip" # OpenBSD (x86_64)
  114. for pc_field in $pc_fields; do
  115. if ! $pc_field_found; then
  116. AC_TRY_COMPILE([#include <signal.h>],
  117. [ucontext_t u; return u.$pc_field == 0;],
  118. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  119. How to access the PC from a struct ucontext)
  120. AC_MSG_RESULT([$pc_field])
  121. pc_field_found=true)
  122. fi
  123. done
  124. fi
  125. if ! $pc_field_found; then
  126. [$1]
  127. fi])