| 1 |
/* Dwarfless register access for arm */ |
| 2 |
|
| 3 |
%{ |
| 4 |
// These functions are largely lifted from arch/arm/kernel/ptrace.c. |
| 5 |
|
| 6 |
static inline unsigned long _stp_kernel_stack_pointer(struct pt_regs *regs) |
| 7 |
{ |
| 8 |
return regs->ARM_sp; |
| 9 |
} |
| 10 |
|
| 11 |
/* |
| 12 |
* _stp_regs_within_kernel_stack() - check the address in the stack |
| 13 |
* @regs: pt_regs which contains kernel stack pointer. |
| 14 |
* @addr: address which is checked. |
| 15 |
* |
| 16 |
* _stp_regs_within_kernel_stack() checks @addr is within the kernel |
| 17 |
* stack page(s). If @addr is within the kernel stack, it returns |
| 18 |
* true. If not, returns false. |
| 19 |
*/ |
| 20 |
bool _stp_regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) |
| 21 |
{ |
| 22 |
return ((addr & ~(THREAD_SIZE - 1)) == |
| 23 |
(_stp_kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); |
| 24 |
} |
| 25 |
|
| 26 |
/* |
| 27 |
* _stp_regs_get_kernel_stack_nth_addr() - get address of the Nth entry of the stack |
| 28 |
* @regs: pt_regs which contains kernel stack pointer. |
| 29 |
* @n: stack entry number. |
| 30 |
* |
| 31 |
* _stp_regs_get_kernel_stack_nth_addr() returns the address of the @n |
| 32 |
* th entry of the kernel stack which is specified by @regs. If the @n |
| 33 |
* th entry is NOT in the kernel stack, this returns 0. |
| 34 |
*/ |
| 35 |
long * |
| 36 |
_stp_regs_get_kernel_stack_nth_addr(struct pt_regs *regs, unsigned int n) |
| 37 |
{ |
| 38 |
long *addr = (unsigned long *)_stp_kernel_stack_pointer(regs); |
| 39 |
addr += n; |
| 40 |
if (_stp_regs_within_kernel_stack(regs, (unsigned long)addr)) |
| 41 |
return addr; |
| 42 |
else |
| 43 |
return 0; |
| 44 |
} |
| 45 |
%} |
| 46 |
|
| 47 |
@__private30 global _reg_offsets[30] |
| 48 |
|
| 49 |
probe init { |
| 50 |
|
| 51 |
/* Same order as pt_regs */ |
| 52 |
_reg_offsets["r0"] = 0 _reg_offsets["a1"] = 0 |
| 53 |
_reg_offsets["r1"] = 4 _reg_offsets["a2"] = 4 |
| 54 |
_reg_offsets["r2"] = 8 _reg_offsets["a3"] = 8 |
| 55 |
_reg_offsets["r3"] = 12 _reg_offsets["a4"] = 12 |
| 56 |
_reg_offsets["r4"] = 16 _reg_offsets["v1"] = 16 |
| 57 |
_reg_offsets["r5"] = 20 _reg_offsets["v2"] = 20 |
| 58 |
_reg_offsets["r6"] = 24 _reg_offsets["v3"] = 24 |
| 59 |
_reg_offsets["r7"] = 28 _reg_offsets["v4"] = 28 |
| 60 |
_reg_offsets["r8"] = 32 _reg_offsets["v5"] = 32 |
| 61 |
_reg_offsets["r9"] = 36 _reg_offsets["v6"] = 36 |
| 62 |
_reg_offsets["r10"] = 40 _reg_offsets["v7"] = 40 |
| 63 |
_reg_offsets["fp"] = 44 _reg_offsets["v8"] = 44 |
| 64 |
_reg_offsets["ip"] = 48 |
| 65 |
_reg_offsets["sp"] = 52 |
| 66 |
_reg_offsets["lr"] = 56 |
| 67 |
_reg_offsets["pc"] = 60 |
| 68 |
_reg_offsets["cpsr"] = 64 |
| 69 |
_reg_offsets["orig_r0"] = 68 |
| 70 |
} |
| 71 |
|
| 72 |
function _stp_get_register_by_offset:long (offset:long) %{ /* pure */ |
| 73 |
long value; |
| 74 |
struct pt_regs *regs; |
| 75 |
if (CONTEXT->user_mode_p) { |
| 76 |
regs = CONTEXT->uregs; |
| 77 |
} else { |
| 78 |
regs = CONTEXT->kregs; |
| 79 |
} |
| 80 |
if (!regs) { |
| 81 |
CONTEXT->last_error = "No registers available in this context"; |
| 82 |
return; |
| 83 |
} |
| 84 |
if (STAP_ARG_offset < 0 || STAP_ARG_offset > sizeof(struct pt_regs) - sizeof(long)) { |
| 85 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 86 |
"Bad register offset: %lld", STAP_ARG_offset); |
| 87 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 88 |
return; |
| 89 |
} |
| 90 |
memcpy(&value, ((char *)regs) + STAP_ARG_offset, sizeof(value)); |
| 91 |
STAP_RETVALUE = value; |
| 92 |
%} |
| 93 |
|
| 94 |
function _stp_probing_kernel:long () { |
| 95 |
return !user_mode(); |
| 96 |
} |
| 97 |
|
| 98 |
function arch_bytes:long() %{ /* pure */ |
| 99 |
STAP_RETVALUE = sizeof(long); |
| 100 |
%} |
| 101 |
|
| 102 |
function uarch_bytes:long() { |
| 103 |
assert(user_mode(), "requires user mode") |
| 104 |
return 4 |
| 105 |
} |
| 106 |
|
| 107 |
/* Return the named register value as a signed value. */ |
| 108 |
function register:long (name:string) { |
| 109 |
assert(registers_valid(), "cannot access CPU registers in this context") |
| 110 |
offset = _reg_offsets[name] |
| 111 |
assert(offset != 0 || (name in _reg_offsets), "Unknown register: " . name) |
| 112 |
return _stp_get_register_by_offset(offset) |
| 113 |
} |
| 114 |
|
| 115 |
/* |
| 116 |
* Return the named register value as an unsigned value. Specifically, |
| 117 |
* don't sign-extend the register value when promoting it to 64 bits. |
| 118 |
*/ |
| 119 |
function u_register:long (name:string) { |
| 120 |
return register(name) & 0xffffffff; |
| 121 |
} |
| 122 |
|
| 123 |
function _stp_get_stack_nth:long (n:long) |
| 124 |
%{ /* pure */ |
| 125 |
__label__ deref_fault; |
| 126 |
unsigned int n = (unsigned int)STAP_ARG_n; |
| 127 |
struct pt_regs *regs; |
| 128 |
long *addr; |
| 129 |
|
| 130 |
STAP_RETVALUE = 0; |
| 131 |
if (CONTEXT->user_mode_p) { |
| 132 |
// This function only handles kernel arguments off the stack. |
| 133 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 134 |
"cannot access function args in this context"); |
| 135 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 136 |
return; |
| 137 |
} |
| 138 |
regs = CONTEXT->kregs; |
| 139 |
if (!regs) { |
| 140 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 141 |
"cannot access function args in this context"); |
| 142 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
/* Get the address of the nth item on the stack. */ |
| 147 |
addr = _stp_regs_get_kernel_stack_nth_addr(regs, n); |
| 148 |
if (addr == NULL) { |
| 149 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 150 |
"cannot access stack arg(%d)", n); |
| 151 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 152 |
return; |
| 153 |
} |
| 154 |
STAP_RETVALUE = kread(addr); |
| 155 |
return; |
| 156 |
|
| 157 |
deref_fault: /* branched to from kread() */ |
| 158 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 159 |
"kernel fault at %#lx accessing stack arg(%d)", |
| 160 |
(unsigned long)addr, n); |
| 161 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 162 |
%} |
| 163 |
|
| 164 |
|
| 165 |
/* Return the value of function arg #argnum (1=first arg) as a signed value. |
| 166 |
* |
| 167 |
* We don't yet support extracting arg #5 and beyond, which are passed |
| 168 |
* on stack |
| 169 |
*/ |
| 170 |
function _stp_arg:long (argnum:long) { |
| 171 |
val = 0 |
| 172 |
assert(!(argnum < 1 || argnum > 7), sprintf("Cannot access arg(%d)", argnum)) |
| 173 |
|
| 174 |
if (argnum == 1) |
| 175 |
val = register("r0") |
| 176 |
else if (argnum == 2) |
| 177 |
val = register("r1") |
| 178 |
else if (argnum == 3) |
| 179 |
val = register("r2") |
| 180 |
else if (argnum == 4) |
| 181 |
val = register("r3") |
| 182 |
else |
| 183 |
val = _stp_get_stack_nth(argnum - 5) |
| 184 |
|
| 185 |
return val; |
| 186 |
} |
| 187 |
|
| 188 |
/* Return the value of function arg #argnum as a signed int. */ |
| 189 |
function int_arg:long (argnum:long) { |
| 190 |
return _stp_arg(argnum) |
| 191 |
} |
| 192 |
|
| 193 |
/* Return the value of function arg #argnum as an unsigned int. */ |
| 194 |
function uint_arg:long (argnum:long) { |
| 195 |
return _stp_arg(argnum) & 0xffffffff; |
| 196 |
} |
| 197 |
|
| 198 |
function long_arg:long (argnum:long) { |
| 199 |
return int_arg(argnum) |
| 200 |
} |
| 201 |
|
| 202 |
function ulong_arg:long (argnum:long) { |
| 203 |
return uint_arg(argnum) |
| 204 |
} |
| 205 |
|
| 206 |
function longlong_arg:long (argnum:long) { |
| 207 |
/* |
| 208 |
* gcc has a few odd rules: |
| 209 |
* 1) If argnum == 2, the 64-bit arg will start with arg 3. |
| 210 |
* 2) If argnum == nr_regarg (4), gcc puts the whole 64-bit |
| 211 |
* arg on the stack. |
| 212 |
* |
| 213 |
* Note that following argument numbers will need to be |
| 214 |
* adjusted. |
| 215 |
*/ |
| 216 |
if (argnum == 2 || argnum == 4) |
| 217 |
argnum++ |
| 218 |
lowbits = uint_arg(argnum) |
| 219 |
highbits = uint_arg(argnum+1) |
| 220 |
return ((highbits << 32) | lowbits) |
| 221 |
} |
| 222 |
|
| 223 |
function ulonglong_arg:long (argnum:long) { |
| 224 |
return longlong_arg(argnum) |
| 225 |
} |
| 226 |
|
| 227 |
function pointer_arg:long (argnum:long) { |
| 228 |
return ulong_arg(argnum) |
| 229 |
} |
| 230 |
|
| 231 |
function s32_arg:long (argnum:long) { |
| 232 |
return int_arg(argnum) |
| 233 |
} |
| 234 |
|
| 235 |
function u32_arg:long (argnum:long) { |
| 236 |
return uint_arg(argnum) |
| 237 |
} |
| 238 |
|
| 239 |
function s64_arg:long (argnum:long) { |
| 240 |
return longlong_arg(argnum) |
| 241 |
} |
| 242 |
|
| 243 |
function u64_arg:long (argnum:long) { |
| 244 |
return ulonglong_arg(argnum) |
| 245 |
} |
| 246 |
|
| 247 |
function asmlinkage() %{ /* pure */ %} |
| 248 |
|
| 249 |
function fastcall() %{ /* pure */ %} |
| 250 |
|
| 251 |
function regparm(n:long) %{ |
| 252 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 253 |
"regparm is invalid on arm."); |
| 254 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 255 |
%} |