| 1 |
// kernel process tapset |
| 2 |
// Copyright (C) 2006 Intel Corporation. |
| 3 |
// Copyright (C) 2014-2017 Red Hat Inc. |
| 4 |
// |
| 5 |
// This file is part of systemtap, and is free software. You can |
| 6 |
// redistribute it and/or modify it under the terms of the GNU General |
| 7 |
// Public License (GPL); either version 2, or (at your option) any |
| 8 |
// later version. |
| 9 |
// <tapsetdescription> |
| 10 |
// This family of probe points is used to probe process-related activities. |
| 11 |
// </tapsetdescription> |
| 12 |
|
| 13 |
@__private30 function _IS_ERR:long(ptr:long) %{ /* pure */ |
| 14 |
STAP_RETVALUE = IS_ERR((const void *)(uintptr_t)STAP_ARG_ptr); |
| 15 |
%} |
| 16 |
|
| 17 |
|
| 18 |
/** |
| 19 |
* probe kprocess.create - Fires whenever a new process or thread is successfully created |
| 20 |
* @new_pid: The PID of the newly created process |
| 21 |
* @new_tid: The TID of the newly created task |
| 22 |
* |
| 23 |
* Context: |
| 24 |
* Parent of the created process. |
| 25 |
* |
| 26 |
* Fires whenever a new process is successfully created, either as a result of |
| 27 |
* fork (or one of its syscall variants), or a new kernel thread. |
| 28 |
*/ |
| 29 |
probe tp_kprocess.create = kernel.trace("sched:sched_process_fork") { |
| 30 |
task = $child |
| 31 |
if (_IS_ERR(task)) next |
| 32 |
new_pid = task_pid(task) |
| 33 |
new_tid = task_tid(task) |
| 34 |
} |
| 35 |
|
| 36 |
probe dw_kprocess.create = kernel.function("copy_process").return { |
| 37 |
task = $return |
| 38 |
if (_IS_ERR(task)) next |
| 39 |
new_pid = task_pid(task) |
| 40 |
new_tid = task_tid(task) |
| 41 |
} |
| 42 |
|
| 43 |
probe kprocess.create = tp_kprocess.create!, dw_kprocess.create {} |
| 44 |
|
| 45 |
/** |
| 46 |
* probe kprocess.start - Starting new process |
| 47 |
* |
| 48 |
* Context: |
| 49 |
* Newly created process. |
| 50 |
* |
| 51 |
* Fires immediately before a new process begins execution. |
| 52 |
* |
| 53 |
*/ |
| 54 |
probe kprocess.start = kernel.function("schedule_tail") { } |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* probe kprocess.exec - Attempt to exec to a new program |
| 59 |
* |
| 60 |
* @filename: The path to the new executable |
| 61 |
* @name: Name of the system call ("execve") (SystemTap v2.5+) |
| 62 |
* @args: The arguments to pass to the new executable, including |
| 63 |
* the 0th arg (SystemTap v2.5+) |
| 64 |
* @argstr: A string containing the filename followed by the |
| 65 |
* arguments to pass, excluding 0th arg (SystemTap v2.5+) |
| 66 |
* |
| 67 |
* Context: |
| 68 |
* The caller of exec. |
| 69 |
* |
| 70 |
* Fires whenever a process attempts to exec to a new program. Aliased |
| 71 |
* to the syscall.execve probe in SystemTap v2.5+. |
| 72 |
*/ |
| 73 |
%(systemtap_v <= "2.4" %? |
| 74 |
probe kprocess.exec = |
| 75 |
kernel.function("do_execve"), |
| 76 |
kernel.function("compat_do_execve") ? |
| 77 |
{ |
| 78 |
filename = kernel_string($filename) |
| 79 |
} |
| 80 |
%: |
| 81 |
probe kprocess.exec = syscall.execve |
| 82 |
{ |
| 83 |
/* |
| 84 |
name = "execve" |
| 85 |
filename = user_string_quoted(@choose_defined($filename, $name)) |
| 86 |
# kernel 3.0 changed the pointer's name to __argv |
| 87 |
__argv = @choose_defined($__argv, $argv) |
| 88 |
args = __get_argv(__argv, 0) |
| 89 |
argstr = sprintf("%s %s", filename, __get_argv(__argv, 1)) |
| 90 |
*/ |
| 91 |
} |
| 92 |
%) |
| 93 |
|
| 94 |
|
| 95 |
/** |
| 96 |
* probe kprocess.exec_complete - Return from exec to a new program |
| 97 |
* @errno: The error number resulting from the exec |
| 98 |
* @success: A boolean indicating whether the exec was successful |
| 99 |
* @name: Name of the system call ("execve") (SystemTap v2.5+) |
| 100 |
* @retstr: A string representation of errno (SystemTap v2.5+) |
| 101 |
* |
| 102 |
* Context: |
| 103 |
* On success, the context of the new executable. |
| 104 |
* On failure, remains in the context of the caller. |
| 105 |
* |
| 106 |
* Fires at the completion of an exec call. Aliased to the |
| 107 |
* syscall.execve.return probe in SystemTap v2.5+. |
| 108 |
*/ |
| 109 |
%(systemtap_v <= "2.4" %? |
| 110 |
probe kprocess.exec_complete = |
| 111 |
kernel.function("do_execve").return, |
| 112 |
kernel.function("compat_do_execve").return ? |
| 113 |
%: |
| 114 |
probe kprocess.exec_complete = syscall.execve.return |
| 115 |
%) |
| 116 |
{ |
| 117 |
errno = retval |
| 118 |
success = (errno >= 0) |
| 119 |
/* |
| 120 |
name = "execve" |
| 121 |
retstr = return_str(1, retval) |
| 122 |
*/ |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
/** |
| 127 |
* probe kprocess.exit - Exit from process |
| 128 |
* @code: The exit code of the process |
| 129 |
* |
| 130 |
* Context: |
| 131 |
* The process which is terminating. |
| 132 |
* |
| 133 |
* Fires when a process terminates. This will always be followed by a |
| 134 |
* kprocess.release, though the latter may be delayed if the process waits in a |
| 135 |
* zombie state. |
| 136 |
*/ |
| 137 |
probe kprocess.exit = kernel.function("do_exit") { |
| 138 |
code = $code |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
/** |
| 143 |
* probe kprocess.release - Process released |
| 144 |
* @task: A task handle to the process being released |
| 145 |
* @released_pid: PID of the process being released |
| 146 |
* @released_tid: TID of the task being released |
| 147 |
* @pid: Same as @released_pid for compatibility (deprecated) |
| 148 |
* |
| 149 |
* Context: |
| 150 |
* The context of the parent, if it wanted notification of this process' |
| 151 |
* termination, else the context of the process itself. |
| 152 |
* |
| 153 |
* Fires when a process is released from the kernel. This always follows a |
| 154 |
* kprocess.exit, though it may be delayed somewhat if the process waits in a |
| 155 |
* zombie state. |
| 156 |
*/ |
| 157 |
probe kprocess.release = kernel.function("release_task") { |
| 158 |
task = $p |
| 159 |
%(systemtap_v <= "1.7" %? |
| 160 |
pid = task_pid($p) |
| 161 |
%) |
| 162 |
released_pid = task_pid($p) |
| 163 |
released_tid = task_tid($p) |
| 164 |
} |