Debian Codegraph @

runtime/unwind/x86_64.h

raw
1 /* -*- linux-c -*-
2 *
3 * x86_64 dwarf unwinder header file
4 * Copyright (C) 2008, 2010, 2011, 2014 Red Hat Inc.
5 * Copyright (C) 2002-2006 Novell, Inc.
6 *
7 * This file is part of systemtap, and is free software. You can
8 * redistribute it and/or modify it under the terms of the GNU General
9 * Public License (GPL); either version 2, or (at your option) any
10 * later version.
11 */
12 #ifndef _STP_X86_64_UNWIND_H
13 #define _STP_X86_64_UNWIND_H
14
15 /*
16 * Copyright (C) 2002-2006 Novell, Inc.
17 * Jan Beulich <[email protected]>
18 * This code is released under version 2 of the GNU GPL.
19 */
20
21 #include <linux/sched.h>
22 #include <asm/ptrace.h>
23
24 /* these are simple for x86_64 */
25 #define _stp_get_unaligned(ptr) (*(ptr))
26
27 #ifdef STAPCONF_X86_UNIREGS
28 #define UNW_PC(frame) (frame)->regs.ip
29 #define UNW_SP(frame) (frame)->regs.sp
30 #else
31 #define UNW_PC(frame) (frame)->regs.rip
32 #define UNW_SP(frame) (frame)->regs.rsp
33 #endif /* STAPCONF_X86_UNIREGS */
34
35 /* Might need to account for the special exception and interrupt handling
36 stacks here, since normally
37 EXCEPTION_STACK_ORDER < THREAD_ORDER < IRQSTACK_ORDER,
38 but the construct is needed only for getting across the stack switch to
39 the interrupt stack - thus considering the IRQ stack itself is unnecessary,
40 and the overhead of comparing against all exception handling stacks seems
41 not desirable. */
42 #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
43
44 #ifdef STAPCONF_X86_UNIREGS
45 #define UNW_REGISTER_INFO \
46 PTREGS_INFO(ax), \
47 PTREGS_INFO(dx), \
48 PTREGS_INFO(cx), \
49 PTREGS_INFO(bx), \
50 PTREGS_INFO(si), \
51 PTREGS_INFO(di), \
52 PTREGS_INFO(bp), \
53 PTREGS_INFO(sp), \
54 PTREGS_INFO(r8), \
55 PTREGS_INFO(r9), \
56 PTREGS_INFO(r10), \
57 PTREGS_INFO(r11), \
58 PTREGS_INFO(r12), \
59 PTREGS_INFO(r13), \
60 PTREGS_INFO(r14), \
61 PTREGS_INFO(r15), \
62 PTREGS_INFO(ip) /* Note, placeholder for "fake" dwarf ret reg. */
63 #else
64 #define UNW_REGISTER_INFO \
65 PTREGS_INFO(rax), \
66 PTREGS_INFO(rdx), \
67 PTREGS_INFO(rcx), \
68 PTREGS_INFO(rbx), \
69 PTREGS_INFO(rsi), \
70 PTREGS_INFO(rdi), \
71 PTREGS_INFO(rbp), \
72 PTREGS_INFO(rsp), \
73 PTREGS_INFO(r8), \
74 PTREGS_INFO(r9), \
75 PTREGS_INFO(r10), \
76 PTREGS_INFO(r11), \
77 PTREGS_INFO(r12), \
78 PTREGS_INFO(r13), \
79 PTREGS_INFO(r14), \
80 PTREGS_INFO(r15), \
81 PTREGS_INFO(rip) /* Note, placeholder for "fake" dwarf ret reg. */
82 #endif /* STAPCONF_X86_UNIREGS */
83
84 /* DWARF registers are ordered differently on 32-bit architectures*/
85 #define COMPAT_REG_MAP(r) \
86 ((r >= 9 && r <= 16) ? r /* r9 - r15 && ip/rip */ \
87 : (r == 0) ? r /* ax/rax */ \
88 : (r == 1) ? 2 /* dx/rdx */ \
89 : (r == 2) ? 1 /* cx/rcx */ \
90 : (r == 3) ? r /* bx/rbx */ \
91 : (r == 4) ? 7 /* sp/rsp */ \
92 : (r == 5) ? 6 /* bp/rpp */ \
93 : (r == 6) ? 4 /* si/rsi */ \
94 : (r == 7) ? 5 /* di/rdi */ \
95 : (r == 8) ? 16 /* ip/rip */ \
96 : 9999)
97
98 #define UNW_PC_IDX 16
99 #define UNW_SP_IDX 7
100
101 #define UNW_NR_REAL_REGS 16
102 #define UNW_PC_FROM_RA 0 /* Because rip == return address column already. */
103
104 static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
105 /*const*/ struct pt_regs *regs,
106 int sanitize)
107 {
108 if(regs == NULL){
109 /* NB: This uses an "=m" output constraint to indicate we're
110 * writing all of info->regs, but then uses an "r" input
111 * pointer for the actual writes. This is to be sure we have
112 * something we can offset properly. */
113 asm("lea (%%rip), %1 \n\t"
114 "mov %%r15, 0(%2) \n\t"
115 "mov %%r14, 8(%2) \n\t"
116 "mov %%r13, 16(%2) \n\t"
117 "mov %%r12, 24(%2) \n\t"
118 "mov %%rbp, 32(%2) \n\t"
119 "mov %%rbx, 40(%2) \n\t"
120 "mov %%r11, 48(%2) \n\t"
121 "mov %%r10, 56(%2) \n\t"
122 "mov %%r9, 64(%2) \n\t"
123 "mov %%r8, 72(%2) \n\t"
124 "mov %%rax, 80(%2) \n\t"
125 "mov %%rcx, 88(%2) \n\t"
126 "mov %%rdx, 96(%2) \n\t"
127 "mov %%rsi, 104(%2) \n\t"
128 "mov %%rdi, 112(%2) \n\t"
129 /* "mov %%orig_rax, 120(%2) \n\t" */
130 /* "mov %%rip, 128(%2) \n\t" */
131 "mov %%cs, 136(%2) \n\t"
132 /* "mov %%eflags, 144(%2) \n\t" */
133 "mov %%rsp, 152(%2) \n\t"
134 "mov %%ss, 160(%2) \n\t"
135 : "=m" (info->regs),
136 #ifdef STAPCONF_X86_UNIREGS
137 "=r" (info->regs.ip)
138 #else
139 "=r" (info->regs.rip)
140 #endif /* STAPCONF_X86_UNIREGS */
141 : "r" (&info->regs)
142 );
143 return;
144 }
145
146 if (&info->regs == regs) { /* happens when unwinding kernel->user */
147 info->call_frame = 1;
148 return;
149 }
150
151 memset(info, 0, sizeof(*info));
152 if (sanitize) {
153 info->regs.r11 = regs->r11;
154 info->regs.r10 = regs->r10;
155 info->regs.r9 = regs->r9;
156 info->regs.r8 = regs->r8;
157 #ifdef STAPCONF_X86_UNIREGS
158 info->regs.ax = regs->ax;
159 info->regs.cx = regs->cx;
160 info->regs.dx = regs->dx;
161 info->regs.si = regs->si;
162 info->regs.di = regs->di;
163 info->regs.orig_ax = regs->orig_ax;
164 info->regs.ip = regs->ip;
165 info->regs.flags = regs->flags;
166 info->regs.sp = regs->sp;
167 #else
168 info->regs.rax = regs->rax;
169 info->regs.rcx = regs->rcx;
170 info->regs.rdx = regs->rdx;
171 info->regs.rsi = regs->rsi;
172 info->regs.rdi = regs->rdi;
173 info->regs.orig_rax = regs->orig_rax;
174 info->regs.rip = regs->rip;
175 info->regs.eflags = regs->eflags;
176 info->regs.rsp = regs->rsp;
177 #endif
178 info->regs.cs = regs->cs;
179 info->regs.ss = regs->ss;
180 } else {
181 info->regs = *regs;
182 }
183 }
184
185 #endif /* _STP_X86_64_UNWIND_H */