pc_from_ucontext.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 cygwin
  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_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <cygwin/signal.h>]],
  79. [[ucontext_t u; return u.$pc_field == 0;]])],
  80. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  81. How to access the PC from a struct ucontext)
  82. AC_MSG_RESULT([$pc_field])
  83. pc_field_found=true)
  84. elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then
  85. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/ucontext.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])
  90. pc_field_found=true)
  91. elif test "x$ac_cv_header_ucontext_h" = xyes; then
  92. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ucontext.h>]],
  93. [[ucontext_t u; return u.$pc_field == 0;]])],
  94. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  95. How to access the PC from a struct ucontext)
  96. AC_MSG_RESULT([$pc_field])
  97. pc_field_found=true)
  98. else # hope some standard header gives it to us
  99. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
  100. [[ucontext_t u; return u.$pc_field == 0;]])],
  101. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  102. How to access the PC from a struct ucontext)
  103. AC_MSG_RESULT([$pc_field])
  104. pc_field_found=true)
  105. fi
  106. fi
  107. done
  108. if ! $pc_field_found; then
  109. pc_fields=" sc_eip" # OpenBSD (i386)
  110. pc_fields="$pc_fields sc_rip" # OpenBSD (x86_64)
  111. for pc_field in $pc_fields; do
  112. if ! $pc_field_found; then
  113. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>]],
  114. [[ucontext_t u; return u.$pc_field == 0;]])],
  115. AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
  116. How to access the PC from a struct ucontext)
  117. AC_MSG_RESULT([$pc_field])
  118. pc_field_found=true)
  119. fi
  120. done
  121. fi
  122. if ! $pc_field_found; then
  123. [$1]
  124. fi])