| 1 |
# arch-specific requests of ptrace ___________________________ |
| 2 |
# |
| 3 |
%{ |
| 4 |
// compat_ptrace_area is defined in a private header |
| 5 |
// (arch/s390/kernel/compat_ptrace.h), so define our own. |
| 6 |
typedef struct |
| 7 |
{ |
| 8 |
__u32 len; |
| 9 |
__u32 kernel_addr; |
| 10 |
__u32 process_addr; |
| 11 |
} __stp_compat_ptrace_area; |
| 12 |
|
| 13 |
%} |
| 14 |
|
| 15 |
function _stp_ptrace_area_u:string(ptrace_area_uaddr:long) |
| 16 |
%{ /* pure */ |
| 17 |
char *area_uaddr = (void *)(uintptr_t)STAP_ARG_ptrace_area_uaddr; |
| 18 |
ptrace_area area; |
| 19 |
if (area_uaddr == NULL) |
| 20 |
strlcpy(STAP_RETVALUE, "NULL", MAXSTRINGLEN); |
| 21 |
else { |
| 22 |
if (_stp_copy_from_user((char*)&area, area_uaddr, |
| 23 |
sizeof(area)) == 0) { |
| 24 |
_stp_snprintf(STAP_RETVALUE, MAXSTRINGLEN, |
| 25 |
"[{%u, %#lx, %#lx}]", area.len, |
| 26 |
area.kernel_addr, area.process_addr); |
| 27 |
} |
| 28 |
else |
| 29 |
_stp_snprintf(STAP_RETVALUE, MAXSTRINGLEN, "0x%lx", |
| 30 |
(unsigned long)area_uaddr); |
| 31 |
} |
| 32 |
%} |
| 33 |
|
| 34 |
function _stp_compat_ptrace_area_u:string(compat_ptrace_area_uaddr:long) |
| 35 |
%{ /* pure */ |
| 36 |
#ifdef CONFIG_COMPAT |
| 37 |
char *area_uaddr = (void *)(uintptr_t)STAP_ARG_compat_ptrace_area_uaddr; |
| 38 |
__stp_compat_ptrace_area area; |
| 39 |
if (area_uaddr == NULL) |
| 40 |
strlcpy(STAP_RETVALUE, "NULL", MAXSTRINGLEN); |
| 41 |
else { |
| 42 |
if (_stp_copy_from_user((char*)&area, area_uaddr, |
| 43 |
sizeof(area)) == 0) { |
| 44 |
_stp_snprintf(STAP_RETVALUE, MAXSTRINGLEN, |
| 45 |
"[{%u, %#x, %#x}]", area.len, |
| 46 |
area.kernel_addr, area.process_addr); |
| 47 |
} |
| 48 |
else |
| 49 |
_stp_snprintf(STAP_RETVALUE, MAXSTRINGLEN, "0x%lx", |
| 50 |
(unsigned long)area_uaddr); |
| 51 |
} |
| 52 |
#endif |
| 53 |
%} |
| 54 |
|
| 55 |
%{ |
| 56 |
// Get _stp_val_array and _stp_lookup_* definitions. |
| 57 |
#include "linux/syscalls-common.h" |
| 58 |
|
| 59 |
// PTRACE_SINGLEBLOCK was added in kernel 3.15. However, its value |
| 60 |
// overlaps with PTRACE_GETREGS (which userspace has defined. So, |
| 61 |
// we'll give PTRACE_SINGLEBLOCK a bogus value on earlier kernels. |
| 62 |
#ifndef PTRACE_SINGLEBLOCK |
| 63 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0) |
| 64 |
#define PTRACE_SINGLEBLOCK 12 |
| 65 |
#else |
| 66 |
#define PTRACE_SINGLEBLOCK 0xABCDEF12 |
| 67 |
#endif |
| 68 |
#endif |
| 69 |
#ifndef PTRACE_GET_LAST_BREAK |
| 70 |
#define PTRACE_GET_LAST_BREAK 0x5006 |
| 71 |
#endif |
| 72 |
#ifndef PTRACE_PEEK_SYSTEM_CALL |
| 73 |
#define PTRACE_PEEK_SYSTEM_CALL 0x5007 |
| 74 |
#endif |
| 75 |
#ifndef PTRACE_POKE_SYSTEM_CALL |
| 76 |
#define PTRACE_POKE_SYSTEM_CALL 0x5008 |
| 77 |
#endif |
| 78 |
#ifndef PTRACE_ENABLE_TE |
| 79 |
#define PTRACE_ENABLE_TE 0x5009 |
| 80 |
#endif |
| 81 |
#ifndef PTRACE_DISABLE_TE |
| 82 |
#define PTRACE_DISABLE_TE 0x5010 |
| 83 |
#endif |
| 84 |
#ifndef PTRACE_TE_ABORT_RAND |
| 85 |
#define PTRACE_TE_ABORT_RAND 0x5011 |
| 86 |
#endif |
| 87 |
|
| 88 |
static const _stp_val_array _stp_arch_ptrace_request_list[] = { |
| 89 |
V(PTRACE_SINGLEBLOCK), |
| 90 |
V(PTRACE_OLDSETOPTIONS), |
| 91 |
V(PTRACE_PEEKUSR_AREA), |
| 92 |
V(PTRACE_POKEUSR_AREA), |
| 93 |
V(PTRACE_PEEKTEXT_AREA), |
| 94 |
V(PTRACE_PEEKDATA_AREA), |
| 95 |
V(PTRACE_POKETEXT_AREA), |
| 96 |
V(PTRACE_POKEDATA_AREA), |
| 97 |
V(PTRACE_GET_LAST_BREAK), |
| 98 |
V(PTRACE_PEEK_SYSTEM_CALL), |
| 99 |
V(PTRACE_POKE_SYSTEM_CALL), |
| 100 |
V(PTRACE_ENABLE_TE), |
| 101 |
V(PTRACE_DISABLE_TE), |
| 102 |
V(PTRACE_TE_ABORT_RAND), |
| 103 |
{0, NULL} |
| 104 |
}; |
| 105 |
%} |
| 106 |
|
| 107 |
function __arch_ptrace_request_str:string(request:long) |
| 108 |
%{ /* pure */ |
| 109 |
_stp_lookup_str(_stp_arch_ptrace_request_list, |
| 110 |
(unsigned long)STAP_ARG_request, STAP_RETVALUE, |
| 111 |
MAXSTRINGLEN); |
| 112 |
%} |
| 113 |
|
| 114 |
function _arch_ptrace_argstr(request, pid, addr, data) |
| 115 |
{ |
| 116 |
if (request == @const("PTRACE_OLDSETOPTIONS")) |
| 117 |
return sprintf("PTRACE_OLDSETOPTIONS, %d, %#x, %s", pid, |
| 118 |
addr, _ptrace_options_str(data)) |
| 119 |
if (request == @const("PTRACE_PEEKUSR_AREA") |
| 120 |
|| request == @const("PTRACE_POKEUSR_AREA") |
| 121 |
|| request == @const("PTRACE_PEEKTEXT_AREA") |
| 122 |
|| request == @const("PTRACE_PEEKDATA_AREA") |
| 123 |
|| request == @const("PTRACE_POKETEXT_AREA") |
| 124 |
|| request == @const("PTRACE_POKEDATA_AREA")) |
| 125 |
return sprintf("%s, %d, %s, %#x", |
| 126 |
__arch_ptrace_request_str(request), pid, |
| 127 |
(@__compat_task |
| 128 |
? _stp_compat_ptrace_area_u(addr) |
| 129 |
: _stp_ptrace_area_u(addr)), data) |
| 130 |
if (request == @const("PTRACE_GET_LAST_BREAK") |
| 131 |
|| request == @const("PTRACE_ENABLE_TE") |
| 132 |
|| request == @const("PTRACE_DISABLE_TE") |
| 133 |
|| request == @const("PTRACE_TE_ABORT_RAND")) |
| 134 |
return sprintf("%s, %d, %#x, %#x", |
| 135 |
__arch_ptrace_request_str(request), |
| 136 |
pid, addr, data) |
| 137 |
|
| 138 |
// Although the following ptrace requests are defined in the |
| 139 |
// ptrace header file, they aren't implemented in the kernel. |
| 140 |
if (request == @const("PTRACE_PEEK_SYSTEM_CALL") |
| 141 |
|| request == @const("PTRACE_POKE_SYSTEM_CALL")) |
| 142 |
return sprintf("%s, %d, %#x, %#x", |
| 143 |
__arch_ptrace_request_str(request), |
| 144 |
pid, addr, data) |
| 145 |
|
| 146 |
if (request == @const("PTRACE_SINGLEBLOCK")) |
| 147 |
return sprintf("%s, %d, %#x, %s", |
| 148 |
__arch_ptrace_request_str(request), pid, |
| 149 |
addr, _signal_name (data)) |
| 150 |
} |
| 151 |
|
| 152 |
function _ptrace_return_arch_prctl_addr:long(request:long, addr:long, data:long) |
| 153 |
{ |
| 154 |
return 0 |
| 155 |
} |
| 156 |
|
| 157 |
%( systemtap_v <= "3.0" %? |
| 158 |
function get_32mmap_args:string(args:long) |
| 159 |
%{ /* pure */ |
| 160 |
struct mmap_arg_struct_emu31 { |
| 161 |
u32 addr; |
| 162 |
u32 len; |
| 163 |
u32 prot; |
| 164 |
u32 flags; |
| 165 |
u32 fd; |
| 166 |
u32 offset; |
| 167 |
} a; |
| 168 |
|
| 169 |
if (_stp_copy_from_user((char *)&a, (char *)(uintptr_t)STAP_ARG_args, |
| 170 |
sizeof(a)) == 0) { |
| 171 |
int len; |
| 172 |
_stp_snprintf(STAP_RETVALUE, MAXSTRINGLEN, "0x%x, %u, ", |
| 173 |
a.addr, a.len); |
| 174 |
_stp_lookup_or_str(_stp_mprotect_list, a.prot, STAP_RETVALUE, |
| 175 |
MAXSTRINGLEN); |
| 176 |
strlcat (STAP_RETVALUE, ", ", MAXSTRINGLEN); |
| 177 |
_stp_lookup_or_str(_stp_mmap_list, a.flags, STAP_RETVALUE, |
| 178 |
MAXSTRINGLEN); |
| 179 |
strlcat (STAP_RETVALUE, ", ", MAXSTRINGLEN); |
| 180 |
len = strlen(STAP_RETVALUE); |
| 181 |
_stp_snprintf(STAP_RETVALUE + len, MAXSTRINGLEN - len, |
| 182 |
"%d, %d", a.fd, a.offset); |
| 183 |
} else { |
| 184 |
strlcpy (STAP_RETVALUE, "UNKNOWN", MAXSTRINGLEN); |
| 185 |
} |
| 186 |
%} |
| 187 |
%) |