| 1 |
/* -*- linux-c -*- |
| 2 |
* |
| 3 |
* 32-bit x86 dwarf unwinder header file |
| 4 |
* Copyright (C) 2008, 2010, 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_I386_UNWIND_H |
| 13 |
#define _STP_I386_UNWIND_H |
| 14 |
|
| 15 |
#include <linux/sched.h> |
| 16 |
#include <asm/fixmap.h> |
| 17 |
#include <asm/ptrace.h> |
| 18 |
#include <asm/uaccess.h> |
| 19 |
|
| 20 |
/* these are simple for i386 */ |
| 21 |
#define _stp_get_unaligned(ptr) (*(ptr)) |
| 22 |
|
| 23 |
#define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1)) |
| 24 |
|
| 25 |
#ifdef STAPCONF_X86_UNIREGS |
| 26 |
|
| 27 |
#define UNW_PC(frame) (frame)->regs.ip |
| 28 |
#define UNW_SP(frame) (frame)->regs.sp |
| 29 |
|
| 30 |
#define UNW_REGISTER_INFO \ |
| 31 |
PTREGS_INFO(ax), \ |
| 32 |
PTREGS_INFO(cx), \ |
| 33 |
PTREGS_INFO(dx), \ |
| 34 |
PTREGS_INFO(bx), \ |
| 35 |
PTREGS_INFO(sp), \ |
| 36 |
PTREGS_INFO(bp), \ |
| 37 |
PTREGS_INFO(si), \ |
| 38 |
PTREGS_INFO(di), \ |
| 39 |
PTREGS_INFO(ip) /* Note, placeholder for "fake" dwarf ret reg. */ |
| 40 |
|
| 41 |
#else /* !STAPCONF_X86_UNIREGS */ |
| 42 |
|
| 43 |
#define UNW_PC(frame) (frame)->regs.eip |
| 44 |
#define UNW_SP(frame) (frame)->regs.esp |
| 45 |
|
| 46 |
#define UNW_REGISTER_INFO \ |
| 47 |
PTREGS_INFO(eax), \ |
| 48 |
PTREGS_INFO(ecx), \ |
| 49 |
PTREGS_INFO(edx), \ |
| 50 |
PTREGS_INFO(ebx), \ |
| 51 |
PTREGS_INFO(esp), \ |
| 52 |
PTREGS_INFO(ebp), \ |
| 53 |
PTREGS_INFO(esi), \ |
| 54 |
PTREGS_INFO(edi), \ |
| 55 |
PTREGS_INFO(eip) /* Note, placeholder for "fake" dwarf ret reg. */ |
| 56 |
|
| 57 |
#endif /* STAPCONF_X86_UNIREGS */ |
| 58 |
|
| 59 |
#define UNW_PC_IDX 8 |
| 60 |
#define UNW_SP_IDX 4 |
| 61 |
|
| 62 |
#define UNW_NR_REAL_REGS 8 |
| 63 |
#define UNW_PC_FROM_RA 0 /* Because [e]ip == return address column already. */ |
| 64 |
|
| 65 |
|
| 66 |
/* 2.6.9-era compatibility */ |
| 67 |
#ifndef user_mode_vm |
| 68 |
#define user_mode_vm(regs) user_mode(regs) |
| 69 |
#endif |
| 70 |
|
| 71 |
static inline void arch_unw_init_frame_info(struct unwind_frame_info *info, |
| 72 |
/*const*/ struct pt_regs *regs, |
| 73 |
int sanitize) |
| 74 |
{ |
| 75 |
if (!regs) { |
| 76 |
/* NB: This uses an "=m" output constraint to indicate we're |
| 77 |
* writing all of info->regs, but then uses an "r" input |
| 78 |
* pointer for the actual writes. This is to be sure we have |
| 79 |
* something we can offset properly. |
| 80 |
* NB2: kernel pt_regs haven't always included fs and gs, which |
| 81 |
* means the offsets of the fields after have changed over |
| 82 |
* time. We'll reconvene at orig_eax to fill the end. */ |
| 83 |
asm("movl $1f, %1; 1: \n\t" |
| 84 |
"mov %%ebx, 0(%2) \n\t" |
| 85 |
"mov %%ecx, 4(%2) \n\t" |
| 86 |
"mov %%edx, 8(%2) \n\t" |
| 87 |
"mov %%esi, 12(%2) \n\t" |
| 88 |
"mov %%edi, 16(%2) \n\t" |
| 89 |
"mov %%ebp, 20(%2) \n\t" |
| 90 |
"mov %%eax, 24(%2) \n\t" |
| 91 |
"mov %%ds, 28(%2) \n\t" |
| 92 |
"mov %%es, 32(%2) \n\t" |
| 93 |
#if defined(STAPCONF_X86_XFS) || defined (STAPCONF_X86_FS) |
| 94 |
"mov %%fs, 36(%2) \n\t" |
| 95 |
#endif |
| 96 |
#ifdef STAPCONF_X86_GS |
| 97 |
"mov %%gs, 40(%2) \n\t" |
| 98 |
#endif |
| 99 |
/* "mov %%orig_eax, 0(%3) \n\t" */ |
| 100 |
/* "mov %%eip, 4(%3) \n\t" */ |
| 101 |
"mov %%cs, 8(%3) \n\t" |
| 102 |
/* "mov %%eflags, 12(%3) \n\t" */ |
| 103 |
"mov %%esp, 16(%3) \n\t" |
| 104 |
"mov %%ss, 20(%3) \n\t" |
| 105 |
: "=m" (info->regs), |
| 106 |
#ifdef STAPCONF_X86_UNIREGS |
| 107 |
"=m" (info->regs.ip) |
| 108 |
#else |
| 109 |
"=m" (info->regs.eip) |
| 110 |
#endif /* STAPCONF_X86_UNIREGS */ |
| 111 |
: "r"(&info->regs), |
| 112 |
#ifdef STAPCONF_X86_UNIREGS |
| 113 |
"r" (&info->regs.orig_ax) |
| 114 |
#else |
| 115 |
"r" (&info->regs.orig_eax) |
| 116 |
#endif /* STAPCONF_X86_UNIREGS */ |
| 117 |
); |
| 118 |
|
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
if (&info->regs == regs) { /* happens when unwinding kernel->user */ |
| 123 |
info->call_frame = 1; |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
memset(info, 0, sizeof(*info)); |
| 128 |
if (sanitize) /* We are only prepared to use full reg sets. */ |
| 129 |
_stp_error("Impossible to sanitize i386 pr_regs"); |
| 130 |
|
| 131 |
if (user_mode_vm(regs)) |
| 132 |
info->regs = *regs; |
| 133 |
else { |
| 134 |
#ifdef STAPCONF_X86_UNIREGS |
| 135 |
memcpy(&info->regs, regs, offsetof(struct pt_regs, sp)); |
| 136 |
info->regs.sp = (unsigned long)®s->sp; |
| 137 |
info->regs.ss = __KERNEL_DS; |
| 138 |
#else |
| 139 |
memcpy(&info->regs, regs, offsetof(struct pt_regs, esp)); |
| 140 |
info->regs.esp = (unsigned long)®s->esp; |
| 141 |
info->regs.xss = __KERNEL_DS; |
| 142 |
#endif |
| 143 |
|
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
#endif /* _STP_I386_UNWIND_H */ |