init.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2002 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. Modified for x86_64 by Max Asbock <masbock@us.ibm.com>
  5. This file is part of libunwind.
  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. "Software"), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22. #include "unwind_i.h"
  23. /* Avoid a trip to x86_64_r_uc_addr() for purely local initialisation. */
  24. #if defined UNW_LOCAL_ONLY && defined __linux
  25. # define REG_INIT_LOC(c, rlc, ruc) \
  26. DWARF_LOC ((unw_word_t) &c->uc->uc_mcontext.gregs[REG_ ## ruc], 0)
  27. #elif defined UNW_LOCAL_ONLY && defined __FreeBSD__
  28. # define REG_INIT_LOC(c, rlc, ruc) \
  29. DWARF_LOC ((unw_word_t) &c->uc->uc_mcontext.mc_ ## rlc, 0)
  30. #else
  31. # define REG_INIT_LOC(c, rlc, ruc) \
  32. DWARF_REG_LOC (&c->dwarf, UNW_X86_64_ ## ruc)
  33. #endif
  34. static inline int
  35. common_init (struct cursor *c, unsigned use_prev_instr)
  36. {
  37. int ret;
  38. c->dwarf.loc[RAX] = REG_INIT_LOC(c, rax, RAX);
  39. c->dwarf.loc[RDX] = REG_INIT_LOC(c, rdx, RDX);
  40. c->dwarf.loc[RCX] = REG_INIT_LOC(c, rcx, RCX);
  41. c->dwarf.loc[RBX] = REG_INIT_LOC(c, rbx, RBX);
  42. c->dwarf.loc[RSI] = REG_INIT_LOC(c, rsi, RSI);
  43. c->dwarf.loc[RDI] = REG_INIT_LOC(c, rdi, RDI);
  44. c->dwarf.loc[RBP] = REG_INIT_LOC(c, rbp, RBP);
  45. c->dwarf.loc[RSP] = REG_INIT_LOC(c, rsp, RSP);
  46. c->dwarf.loc[R8] = REG_INIT_LOC(c, r8, R8);
  47. c->dwarf.loc[R9] = REG_INIT_LOC(c, r9, R9);
  48. c->dwarf.loc[R10] = REG_INIT_LOC(c, r10, R10);
  49. c->dwarf.loc[R11] = REG_INIT_LOC(c, r11, R11);
  50. c->dwarf.loc[R12] = REG_INIT_LOC(c, r12, R12);
  51. c->dwarf.loc[R13] = REG_INIT_LOC(c, r13, R13);
  52. c->dwarf.loc[R14] = REG_INIT_LOC(c, r14, R14);
  53. c->dwarf.loc[R15] = REG_INIT_LOC(c, r15, R15);
  54. c->dwarf.loc[RIP] = REG_INIT_LOC(c, rip, RIP);
  55. ret = dwarf_get (&c->dwarf, c->dwarf.loc[RIP], &c->dwarf.ip);
  56. if (ret < 0)
  57. return ret;
  58. ret = dwarf_get (&c->dwarf, DWARF_REG_LOC (&c->dwarf, UNW_X86_64_RSP),
  59. &c->dwarf.cfa);
  60. if (ret < 0)
  61. return ret;
  62. c->sigcontext_format = X86_64_SCF_NONE;
  63. c->sigcontext_addr = 0;
  64. c->dwarf.args_size = 0;
  65. c->dwarf.ret_addr_column = RIP;
  66. c->dwarf.stash_frames = 0;
  67. c->dwarf.use_prev_instr = use_prev_instr;
  68. c->dwarf.pi_valid = 0;
  69. c->dwarf.pi_is_dynamic = 0;
  70. c->dwarf.hint = 0;
  71. c->dwarf.prev_rs = 0;
  72. return 0;
  73. }