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