| 1 |
/* |
| 2 |
* current.stp (requires Guru mode) |
| 3 |
* |
| 4 |
* Test the validity of the current pointer in various contexts. |
| 5 |
*/ |
| 6 |
|
| 7 |
global length |
| 8 |
|
| 9 |
function commlen:long () %{ |
| 10 |
STAP_RETVALUE = strlen(current->comm); |
| 11 |
%} |
| 12 |
|
| 13 |
function pcommlen:long () %{ |
| 14 |
STAP_RETVALUE = strlen(current->parent->comm); |
| 15 |
%} |
| 16 |
|
| 17 |
probe begin { println("systemtap starting probe") } |
| 18 |
|
| 19 |
probe |
| 20 |
timer.profile, |
| 21 |
%( arch != "ia64" && arch != "arm" %? |
| 22 |
# __switch_to is macro definition in ia64, |
| 23 |
# and ia64_switch_to is defined in assemble language |
| 24 |
# PR13734 arm has a similar issue |
| 25 |
%( arch != "x86_64" %? |
| 26 |
# __switch_to can not be probed on x86_64 - see PR2068 |
| 27 |
kernel.function("__switch_to").call ?, |
| 28 |
%( arch != "i386" %? |
| 29 |
# __switch_to.return is broken on i686 - see PR4542 |
| 30 |
kernel.function("__switch_to").return ?, |
| 31 |
%) |
| 32 |
%) |
| 33 |
%) |
| 34 |
|
| 35 |
/* XXX |
| 36 |
* It would be nice if we could just do this: |
| 37 |
* kernel.statement("__switch_to@*:*") |
| 38 |
* to probe every line in the function |
| 39 |
*/ |
| 40 |
|
| 41 |
/* add other kernels/archs here as desired... */ |
| 42 |
%( arch == "x86_64" %? |
| 43 |
%( kernel_vr == "2.6.9-22.ELsmp" %? |
| 44 |
/* the lines before, at, and after the update of pcurrent */ |
| 45 |
kernel.statement("__switch_to@arch/x86_64/kernel/process.c:508"), |
| 46 |
kernel.statement("__switch_to@arch/x86_64/kernel/process.c:509"), |
| 47 |
kernel.statement("__switch_to@arch/x86_64/kernel/process.c:510"), |
| 48 |
%) |
| 49 |
%( kernel_vr == "2.6.9-24.ELsmp" %? |
| 50 |
/* the lines before, at, and after the update of pcurrent */ |
| 51 |
kernel.statement("__switch_to@arch/x86_64/kernel/process.c:501"), |
| 52 |
kernel.statement("__switch_to@arch/x86_64/kernel/process.c:502"), |
| 53 |
kernel.statement("__switch_to@arch/x86_64/kernel/process.c:503"), |
| 54 |
%) |
| 55 |
%) |
| 56 |
|
| 57 |
kernel.function("*@kernel/time.c").call, |
| 58 |
kernel.function("*@kernel/time.c").return, |
| 59 |
module("usb*").function("*interrupt*").call ?, |
| 60 |
module("usb*").function("*interrupt*").return ? |
| 61 |
{ |
| 62 |
length <<< commlen() |
| 63 |
length <<< pcommlen() |
| 64 |
} |
| 65 |
|
| 66 |
function get_TASK_COMM_LEN:long() %{ |
| 67 |
/* TASK_COMM_LEN was introduced in 2.6.11, before which |
| 68 |
* the length of the comm string was hard-coded to 16 */ |
| 69 |
#ifdef TASK_COMM_LEN |
| 70 |
STAP_RETVALUE = TASK_COMM_LEN; |
| 71 |
#else |
| 72 |
STAP_RETVALUE = 16; |
| 73 |
#endif |
| 74 |
%} |
| 75 |
|
| 76 |
probe end { |
| 77 |
println("systemtap ending probe") |
| 78 |
printf("count = %d\n", @count(length)) |
| 79 |
printf("sum = %d\n", @sum(length)) |
| 80 |
printf("min = %d\n", @min(length)) |
| 81 |
printf("max = %d\n", @max(length)) |
| 82 |
printf("avg = %d\n", @avg(length)) |
| 83 |
|
| 84 |
/* |
| 85 |
* Check that the min & max lengths look reasonable. If any string was |
| 86 |
* either empty or too big, then the current pointer probably wasn't |
| 87 |
* valid, even though it dereferenced without crashing. |
| 88 |
*/ |
| 89 |
if (@min(length) > 0) { |
| 90 |
println("systemtap test success") |
| 91 |
} else { |
| 92 |
println("unexpected minimum length") |
| 93 |
println("systemtap test failure") |
| 94 |
} |
| 95 |
if (@max(length) < get_TASK_COMM_LEN()) { |
| 96 |
println("systemtap test success") |
| 97 |
} else { |
| 98 |
println("unexpected maximum length") |
| 99 |
println("systemtap test failure") |
| 100 |
} |
| 101 |
} |