| 1 |
%{ |
| 2 |
#include "syscall.h" |
| 3 |
%} |
| 4 |
|
| 5 |
function mmap_syscall_no:long () %{ |
| 6 |
STAP_RETVALUE = MMAP_SYSCALL_NO(current); /* pure */ |
| 7 |
%} |
| 8 |
function mmap2_syscall_no:long () %{ |
| 9 |
STAP_RETVALUE = MMAP2_SYSCALL_NO(current); /* pure */ |
| 10 |
%} |
| 11 |
function munmap_syscall_no:long () %{ |
| 12 |
STAP_RETVALUE = MUNMAP_SYSCALL_NO(current); /* pure */ |
| 13 |
%} |
| 14 |
|
| 15 |
global syscalls_seen = 0 |
| 16 |
global failures = 0 |
| 17 |
|
| 18 |
global mmap_found = 0 |
| 19 |
global mmap_args[10] |
| 20 |
|
| 21 |
global munmap_found = 0 |
| 22 |
global munmap_args[10] |
| 23 |
|
| 24 |
global close_found = 0 |
| 25 |
global close_args[10] |
| 26 |
|
| 27 |
global dup_found = 0 |
| 28 |
global dup_args[10] |
| 29 |
|
| 30 |
global bad_syscall_found = 0 |
| 31 |
global bad_syscall_args[10] |
| 32 |
|
| 33 |
probe begin |
| 34 |
{ |
| 35 |
printf("systemtap starting probe\n") |
| 36 |
} |
| 37 |
|
| 38 |
probe syscall.open, syscall.openat { |
| 39 |
if (pid() == target() && filename == "\"foobar\"") { |
| 40 |
syscalls_seen += 1 |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
probe process("utrace_syscall_args").syscall { |
| 45 |
if (syscalls_seen >= 2) { |
| 46 |
syscalls_seen += 1 |
| 47 |
|
| 48 |
# We skip the fstat() syscall, which is the 1st syscall after |
| 49 |
# the open() by not looking at 'syscalls_seen == 3'. |
| 50 |
|
| 51 |
if (syscalls_seen == 4 && ($syscall == mmap_syscall_no() |
| 52 |
|| $syscall == mmap2_syscall_no())) { |
| 53 |
mmap_found = 1 |
| 54 |
mmap_args[0] = $syscall |
| 55 |
mmap_args[1] = $arg1 |
| 56 |
mmap_args[2] = $arg2 |
| 57 |
mmap_args[3] = $arg3 |
| 58 |
mmap_args[4] = $arg4 |
| 59 |
mmap_args[5] = $arg5 |
| 60 |
mmap_args[6] = $arg6 |
| 61 |
|
| 62 |
%(arch == "s390" %? |
| 63 |
# For s390, mmap was handled by arch-specific code in |
| 64 |
# kernels before 2.6.33 that got a structure pointer in |
| 65 |
# argument 1 that holds all the actual arguments. Handle |
| 66 |
# this. After 2.6.33, this was moved to generic code, but |
| 67 |
# s390x defines has __ARCH_WANT_SYS_OLD_MMAP, so it still |
| 68 |
# uses the same structures. |
| 69 |
addr = mmap_args[1] |
| 70 |
if (! %{ _stp_is_compat_task() %}) { |
| 71 |
mmap_args[1] = user_long(&@cast(addr, "mmap_arg_struct")->addr) |
| 72 |
mmap_args[2] = user_long(&@cast(addr, "mmap_arg_struct")->len) |
| 73 |
mmap_args[3] = user_long(&@cast(addr, "mmap_arg_struct")->prot) |
| 74 |
mmap_args[4] = user_long(&@cast(addr, "mmap_arg_struct")->flags) |
| 75 |
mmap_args[5] = user_long(&@cast(addr, "mmap_arg_struct")->fd) |
| 76 |
mmap_args[6] = user_long(&@cast(addr, |
| 77 |
"mmap_arg_struct")->offset) |
| 78 |
} |
| 79 |
else { |
| 80 |
mmap_args[1] = user_int(&@cast(addr, |
| 81 |
"mmap_arg_struct_emu31")->addr) |
| 82 |
mmap_args[2] = user_int(&@cast(addr, |
| 83 |
"mmap_arg_struct_emu31")->len) |
| 84 |
mmap_args[3] = user_int(&@cast(addr, |
| 85 |
"mmap_arg_struct_emu31")->prot) |
| 86 |
mmap_args[4] = user_int(&@cast(addr, |
| 87 |
"mmap_arg_struct_emu31")->flags) |
| 88 |
mmap_args[5] = user_int(&@cast(addr, |
| 89 |
"mmap_arg_struct_emu31")->fd) |
| 90 |
mmap_args[6] = user_int(&@cast(addr, |
| 91 |
"mmap_arg_struct_emu31")->offset) |
| 92 |
} |
| 93 |
%) |
| 94 |
} |
| 95 |
else if (syscalls_seen == 5 && $syscall == munmap_syscall_no()) { |
| 96 |
munmap_found = 1 |
| 97 |
munmap_args[0] = $syscall |
| 98 |
munmap_args[1] = $arg1 |
| 99 |
munmap_args[2] = $arg2 |
| 100 |
} |
| 101 |
else if (syscalls_seen == 6) { |
| 102 |
close_found = 1 |
| 103 |
close_args[0] = $syscall |
| 104 |
close_args[1] = $arg1 |
| 105 |
} |
| 106 |
else if (syscalls_seen == 7) { |
| 107 |
dup_found = 1 |
| 108 |
dup_args[0] = $syscall |
| 109 |
dup_args[1] = $arg1 |
| 110 |
dup_args[2] = $arg2 |
| 111 |
dup_args[3] = $arg3 |
| 112 |
dup_args[4] = $arg4 |
| 113 |
dup_args[5] = $arg5 |
| 114 |
dup_args[6] = $arg6 |
| 115 |
} |
| 116 |
else if (syscalls_seen == 8) { |
| 117 |
bad_syscall_found = 1 |
| 118 |
bad_syscall_args[0] = $syscall |
| 119 |
bad_syscall_args[1] = $arg1 |
| 120 |
bad_syscall_args[2] = $arg2 |
| 121 |
bad_syscall_args[3] = $arg3 |
| 122 |
bad_syscall_args[4] = $arg4 |
| 123 |
bad_syscall_args[5] = $arg5 |
| 124 |
bad_syscall_args[6] = $arg6 |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
probe process("utrace_syscall_args").syscall.return { |
| 129 |
if (syscalls_seen >= 4) { |
| 130 |
if (syscalls_seen == 4) { |
| 131 |
mmap_args[7] = $return |
| 132 |
mmap_args[8] = $syscall |
| 133 |
} |
| 134 |
else if (syscalls_seen == 5) { |
| 135 |
munmap_args[3] = $return |
| 136 |
munmap_args[4] = $syscall |
| 137 |
} |
| 138 |
else if (syscalls_seen == 6) { |
| 139 |
close_args[2] = $return |
| 140 |
close_args[3] = $syscall |
| 141 |
} |
| 142 |
else if (syscalls_seen == 7) { |
| 143 |
dup_args[7] = $return |
| 144 |
dup_args[8] = $syscall |
| 145 |
} |
| 146 |
else if (syscalls_seen == 8) { |
| 147 |
bad_syscall_args[7] = $return |
| 148 |
bad_syscall_args[8] = $syscall |
| 149 |
syscalls_seen = 0 |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
probe end |
| 155 |
{ |
| 156 |
printf("systemtap ending probe\n") |
| 157 |
|
| 158 |
# print mmap info |
| 159 |
if (mmap_found == 0) { |
| 160 |
printf("error: no mmap system call found\n") |
| 161 |
failures += 1 |
| 162 |
} |
| 163 |
else { |
| 164 |
printf("mmap(%d)(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) = 0x%x\n", |
| 165 |
mmap_args[0], mmap_args[1], mmap_args[2], mmap_args[3], |
| 166 |
mmap_args[4], mmap_args[5], mmap_args[6], mmap_args[7]) |
| 167 |
|
| 168 |
# Validate arguments. We can only check certain arguments. |
| 169 |
# It is possible that mmap's 'prot' and 'flags' arguments |
| 170 |
# could vary per platform, so we'll ignore them. |
| 171 |
if (mmap_args[1] != 0) { |
| 172 |
failures += 1 |
| 173 |
printf("mmap bad arg 1: 0x%x vs 0x0\n", mmap_args[1]) |
| 174 |
} |
| 175 |
if (mmap_args[2] != 0x406) { |
| 176 |
failures += 1 |
| 177 |
printf("mmap bad arg 2: 0x%x vs 0x406\n", mmap_args[2]) |
| 178 |
} |
| 179 |
if (mmap_args[6] != 0) { |
| 180 |
failures += 1 |
| 181 |
printf("mmap bad arg 6: 0x%x vs 0x0\n", mmap_args[6]) |
| 182 |
} |
| 183 |
|
| 184 |
# Validate syscall number |
| 185 |
if (mmap_args[0] != mmap_args[8]) { |
| 186 |
failures += 1 |
| 187 |
printf("mmap $syscall mismatch: %d vs. %d\n", |
| 188 |
mmap_args[0], mmap_args[8]) |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
# print munmap info |
| 193 |
if (munmap_found == 0) { |
| 194 |
printf("error: no munmap system call found\n") |
| 195 |
failures += 1 |
| 196 |
} |
| 197 |
else if (munmap_found == 0 || mmap_found == 0) { |
| 198 |
printf("error: no munmap/mmap system call found\n") |
| 199 |
failures += 1 |
| 200 |
} |
| 201 |
else { |
| 202 |
printf("munmap(%d)(0x%x, 0x%x) = 0x%x\n", |
| 203 |
munmap_args[0], munmap_args[1], munmap_args[2], munmap_args[3]) |
| 204 |
|
| 205 |
# Validate arguments. munmap()'s first argument should be the |
| 206 |
# same as the mmap() return value. |
| 207 |
if (munmap_args[1] != mmap_args[7]) { |
| 208 |
failures += 1 |
| 209 |
printf("munmap bad arg 1: 0x%x vs 0x%x\n", munmap_args[1], |
| 210 |
mmap_args[7]) |
| 211 |
} |
| 212 |
if (munmap_args[2] != mmap_args[2]) { |
| 213 |
failures += 1 |
| 214 |
printf("munmap bad arg 2: 0x%x vs 0x%x\n", munmap_args[2], |
| 215 |
mmap_args[2]) |
| 216 |
} |
| 217 |
# Validate return value |
| 218 |
if (munmap_args[7] != 0) { |
| 219 |
failures += 1 |
| 220 |
printf("munmap bad return value: 0x%x vs 0x0\n", munmap_args[7]) |
| 221 |
} |
| 222 |
|
| 223 |
# Validate syscall number |
| 224 |
if (munmap_args[0] != munmap_args[4]) { |
| 225 |
failures += 1 |
| 226 |
printf("munmap $syscall mismatch: %d vs. %d\n", |
| 227 |
munmap_args[0], munmap_args[4]) |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
# print close info |
| 232 |
if (close_found == 0) { |
| 233 |
printf("error: no close system call found\n") |
| 234 |
failures += 1 |
| 235 |
} |
| 236 |
else if (close_found == 1) { |
| 237 |
printf("close(%d)(0x%x) = 0x%x\n", |
| 238 |
close_args[0], close_args[1], close_args[2]) |
| 239 |
|
| 240 |
if (mmap_args[5] != close_args[1]) { |
| 241 |
failures += 1 |
| 242 |
printf("close bad arg 1: 0x%x vs 0x%x\n", |
| 243 |
close_args[1], mmap_args[5]) |
| 244 |
} |
| 245 |
|
| 246 |
# Validate syscall number |
| 247 |
if (close_args[0] != close_args[3]) { |
| 248 |
failures += 1 |
| 249 |
printf("close $syscall mismatch: %d vs. %d\n", |
| 250 |
close_args[0], close_args[3]) |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
# print dup info |
| 255 |
if (dup_found == 0) { |
| 256 |
printf("error: no dup system call found\n") |
| 257 |
failures += 1 |
| 258 |
} |
| 259 |
else { |
| 260 |
printf("dup(%d)(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) = 0x%x\n", |
| 261 |
dup_args[0], dup_args[1], dup_args[2], dup_args[3], |
| 262 |
dup_args[4], dup_args[5], dup_args[6], dup_args[7]) |
| 263 |
|
| 264 |
# Validate arguments - handle 32-bit vs. 64-bit. |
| 265 |
if ((dup_args[1] & 0xffffffff00000000) != 0) { |
| 266 |
if (dup_args[1] != 0xffffffffffffcfc7) { |
| 267 |
failures += 1 |
| 268 |
printf("dup bad arg 1: 0x%x vs 0xffffffffffffcfc7\n", |
| 269 |
dup_args[1]) |
| 270 |
} |
| 271 |
if (dup_args[2] != 0xffffffffffffffff) { |
| 272 |
failures += 1 |
| 273 |
printf("dup bad arg 2: 0x%x vs 0xffffffffffffffff\n", |
| 274 |
dup_args[2]) |
| 275 |
} |
| 276 |
if (dup_args[3] != 0xa5a5a5a5a5a5a5a5) { |
| 277 |
failures += 1 |
| 278 |
printf("dup bad arg 3: 0x%x vs 0xa5a5a5a5a5a5a5a5\n", |
| 279 |
dup_args[3]) |
| 280 |
} |
| 281 |
if (dup_args[4] != 0xf0f0f0f0f0f0f0f0) { |
| 282 |
failures += 1 |
| 283 |
printf("dup bad arg 4: 0x%x vs 0xf0f0f0f0f0f0f0f0\n", |
| 284 |
dup_args[4]) |
| 285 |
} |
| 286 |
if (dup_args[5] != 0x5a5a5a5a5a5a5a5a) { |
| 287 |
failures += 1 |
| 288 |
printf("dup bad arg 5: 0x%x vs 0x5a5a5a5a5a5a5a5a\n", |
| 289 |
dup_args[5]) |
| 290 |
} |
| 291 |
if (dup_args[6] != 0xe38e38e38e38e38e) { |
| 292 |
failures += 1 |
| 293 |
printf("dup bad arg 6: 0x%x vs 0xe38e38e38e38d38e\n", |
| 294 |
dup_args[6]) |
| 295 |
} |
| 296 |
} |
| 297 |
else { |
| 298 |
if (dup_args[1] != 0xffffcfc7) { |
| 299 |
failures += 1 |
| 300 |
printf("dup bad arg 1: 0x%x vs 0xffffcfc7\n", dup_args[1]) |
| 301 |
} |
| 302 |
if (dup_args[2] != 0xffffffff) { |
| 303 |
failures += 1 |
| 304 |
printf("dup bad arg 2: 0x%x vs 0xffffffff\n", dup_args[2]) |
| 305 |
} |
| 306 |
if (dup_args[3] != 0xa5a5a5a5) { |
| 307 |
failures += 1 |
| 308 |
printf("dup bad arg 3: 0x%x vs 0xa5a5a5a5\n", dup_args[3]) |
| 309 |
} |
| 310 |
if (dup_args[4] != 0xf0f0f0f0) { |
| 311 |
failures += 4 |
| 312 |
printf("dup bad arg 4: 0x%x vs 0xf0f0f0f0\n", dup_args[4]) |
| 313 |
} |
| 314 |
if (dup_args[5] != 0x5a5a5a5a) { |
| 315 |
failures += 1 |
| 316 |
printf("dup bad arg 5: 0x%x vs 0x5a5a5a5a\n", dup_args[5]) |
| 317 |
} |
| 318 |
if (dup_args[6] != 0xe38e38e3) { |
| 319 |
failures += 1 |
| 320 |
printf("dup bad arg 6: 0x%x vs 0xe38e38e3\n", dup_args[6]) |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
# Validate syscall number |
| 325 |
if (dup_args[0] != dup_args[8]) { |
| 326 |
failures += 1 |
| 327 |
printf("dup $syscall mismatch: %d vs. %d\n", |
| 328 |
dup_args[0], dup_args[8]) |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
# print bad_syscall info |
| 333 |
if (bad_syscall_found == 0) { |
| 334 |
printf("error: no bad_syscall system call found\n") |
| 335 |
failures += 1 |
| 336 |
} |
| 337 |
else { |
| 338 |
printf("bad_syscall(%d)(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) = 0x%x\n", |
| 339 |
bad_syscall_args[0], bad_syscall_args[1], bad_syscall_args[2], bad_syscall_args[3], |
| 340 |
bad_syscall_args[4], bad_syscall_args[5], bad_syscall_args[6], bad_syscall_args[7]) |
| 341 |
|
| 342 |
# Validate arguments - handle 32-bit vs. 64-bit. |
| 343 |
if (bad_syscall_args[1] > 0xffffffff) { |
| 344 |
if (bad_syscall_args[1] != 0x1c71c71c71c71c71) { |
| 345 |
failures += 1 |
| 346 |
printf("bad_syscall bad arg 1: 0x%x vs 0x1c71c71c71c71c71\n", |
| 347 |
bad_syscall_args[1]) |
| 348 |
} |
| 349 |
if (bad_syscall_args[2] != 0x0f0f0f0f0f0f0f0f) { |
| 350 |
failures += 1 |
| 351 |
printf("bad_syscall bad arg 2: 0x%x vs 0x0f0f0f0f0f0f0f0f\n", |
| 352 |
bad_syscall_args[2]) |
| 353 |
} |
| 354 |
if (bad_syscall_args[3] != 0xdb6db6db6db6db6d) { |
| 355 |
failures += 1 |
| 356 |
printf("bad_syscall bad arg 3: 0x%x vs 0xdb6db6db6db6db6d\n", |
| 357 |
bad_syscall_args[3]) |
| 358 |
} |
| 359 |
if (bad_syscall_args[4] != 0x2492492492492492) { |
| 360 |
failures += 1 |
| 361 |
printf("bad_syscall bad arg 4: 0x%x vs 0x2492492492492492\n", |
| 362 |
bad_syscall_args[4]) |
| 363 |
} |
| 364 |
if (bad_syscall_args[5] != 0xad6b5ad6b5ad6b5a) { |
| 365 |
failures += 1 |
| 366 |
printf("bad_syscall bad arg 5: 0x%x vs 0xad6b5ad6b5ad6b5a\n", |
| 367 |
bad_syscall_args[5]) |
| 368 |
} |
| 369 |
if (bad_syscall_args[6] != 0xdef7ddef7ddef7dd) { |
| 370 |
failures += 1 |
| 371 |
printf("bad_syscall bad arg 6: 0x%x vs 0xdef7ddef7ddef7dd\n", |
| 372 |
bad_syscall_args[6]) |
| 373 |
} |
| 374 |
} |
| 375 |
else { |
| 376 |
if (bad_syscall_args[1] != 0x1c71c71c) { |
| 377 |
failures += 1 |
| 378 |
printf("bad_syscall bad arg 1: 0x%x vs 0x1c71c71c\n", |
| 379 |
bad_syscall_args[1]) |
| 380 |
} |
| 381 |
if (bad_syscall_args[2] != 0x0f0f0f0f) { |
| 382 |
failures += 1 |
| 383 |
printf("bad_syscall bad arg 2: 0x%x vs 0x0f0f0f0f\n", |
| 384 |
bad_syscall_args[2]) |
| 385 |
} |
| 386 |
if (bad_syscall_args[3] != 0xdb6db6db) { |
| 387 |
failures += 1 |
| 388 |
printf("bad_syscall bad arg 3: 0x%x vs 0xdb6db6db\n", |
| 389 |
bad_syscall_args[3]) |
| 390 |
} |
| 391 |
if (bad_syscall_args[4] != 0x24924924) { |
| 392 |
failures += 4 |
| 393 |
printf("bad_syscall bad arg 4: 0x%x vs 0x24924924\n", |
| 394 |
bad_syscall_args[4]) |
| 395 |
} |
| 396 |
if (bad_syscall_args[5] != 0xad6b5ad6) { |
| 397 |
failures += 1 |
| 398 |
printf("bad_syscall bad arg 5: 0x%x vs 0xad6b5ad6\n", |
| 399 |
bad_syscall_args[5]) |
| 400 |
} |
| 401 |
if (bad_syscall_args[6] != 0xdef7ddef) { |
| 402 |
failures += 1 |
| 403 |
printf("bad_syscall bad arg 6: 0x%x vs 0xdef7ddef\n", |
| 404 |
bad_syscall_args[6]) |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
# Validate syscall number |
| 409 |
if (bad_syscall_args[0] != bad_syscall_args[8]) { |
| 410 |
failures += 1 |
| 411 |
printf("bad_syscall $syscall mismatch: %d vs. %d\n", |
| 412 |
bad_syscall_args[0], bad_syscall_args[8]) |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
if (failures == 0) { |
| 417 |
printf("systemtap test success\n") |
| 418 |
} |
| 419 |
else { |
| 420 |
printf("systemtap test failure\n") |
| 421 |
} |
| 422 |
} |