| 1 |
# clone ______________________________________________________ |
| 2 |
# |
| 3 |
# The sys_clone() call was in arch-specific code (sometimes assembly |
| 4 |
# code), especially in older kernels. Its args varied dramatically, |
| 5 |
# from full args to getting nothing but registers. To get around this, |
| 6 |
# we'll just probe do_fork(). The fork()/vfork()/clone() syscalls are |
| 7 |
# just wrappers around do_fork(). We'll reject all probe hits that |
| 8 |
# aren't really clone syscalls (such as calls to sys_fork(), |
| 9 |
# sys_vfork(), and the kernel's internal use of do_fork()). Kernel |
| 10 |
# commit 3033f14ab78c32 renamed 'do_fork' to '_do_fork'. |
| 11 |
# |
| 12 |
# For ia64, this is complicated by the fact that it has a clone2 |
| 13 |
# syscall. |
| 14 |
# |
| 15 |
|
| 16 |
probe syscall.clone = dw_syscall.clone !, nd_syscall.clone {} |
| 17 |
probe syscall.clone.return = dw_syscall.clone.return !, nd_syscall.clone.return {} |
| 18 |
|
| 19 |
# dw_clone _____________________________________________________ |
| 20 |
|
| 21 |
probe dw_syscall.clone = kernel.function("_do_fork").call !, |
| 22 |
kernel.function("do_fork").call |
| 23 |
{ |
| 24 |
%( arch != "ia64" %? |
| 25 |
@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone")) |
| 26 |
name = "clone" |
| 27 |
%: |
| 28 |
@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2")) |
| 29 |
// This is a bit gross. We're depending on @__syscall_gate2() |
| 30 |
// to set '__nr' for us. If its implementation changes, this will |
| 31 |
// need to change. |
| 32 |
if (__nr == @const("__NR_clone")) |
| 33 |
name = "clone" |
| 34 |
else { |
| 35 |
name = "clone2" |
| 36 |
stack_size = $stack_size |
| 37 |
} |
| 38 |
%) |
| 39 |
clone_flags = @choose_defined($args->flags,$clone_flags) |
| 40 |
stack_start = @choose_defined($args->stack,$stack_start) |
| 41 |
parent_tid_uaddr = @choose_defined($args->parent_tid,$parent_tidptr) |
| 42 |
child_tid_uaddr = @choose_defined($args->child_tid,$child_tidptr) |
| 43 |
|
| 44 |
%( arch != "ia64" %? |
| 45 |
argstr = sprintf("%s, %p, %p, %p", |
| 46 |
__fork_flags(@choose_defined($args->flags,$clone_flags)), |
| 47 |
@choose_defined($args->stack,$stack_start), |
| 48 |
@choose_defined($args->parent_tid,$parent_tidptr), |
| 49 |
@choose_defined($args->child_tid,$child_tidptr)) |
| 50 |
%: |
| 51 |
if (__nr == @const("__NR_clone")) |
| 52 |
argstr = sprintf("%s, %p, %p, %p", __fork_flags($clone_flags), |
| 53 |
$stack_start, $parent_tidptr, $child_tidptr) |
| 54 |
else |
| 55 |
argstr = sprintf("%s, %p, %p, %p, %p", |
| 56 |
__fork_flags($clone_flags), $stack_start, |
| 57 |
$stack_size, $parent_tidptr, $child_tidptr) |
| 58 |
%) |
| 59 |
} |
| 60 |
probe dw_syscall.clone.return = kernel.function("_do_fork").return !, |
| 61 |
kernel.function("do_fork").return |
| 62 |
{ |
| 63 |
%( arch != "ia64" %? |
| 64 |
@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone")) |
| 65 |
name = "clone" |
| 66 |
%: |
| 67 |
@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2")) |
| 68 |
// This is a bit gross. We're depending on @__syscall_gate2() |
| 69 |
// to set '__nr' for us. If its implementation changes, this will |
| 70 |
// need to change. |
| 71 |
if (__nr == @const("__NR_clone")) |
| 72 |
name = "clone" |
| 73 |
else |
| 74 |
name = "clone2" |
| 75 |
%) |
| 76 |
@SYSC_RETVALSTR($return) |
| 77 |
} |
| 78 |
|
| 79 |
# nd_clone _____________________________________________________ |
| 80 |
|
| 81 |
probe nd_syscall.clone = nd1_syscall.clone!, tp_syscall.clone |
| 82 |
{ } |
| 83 |
|
| 84 |
probe nd1_syscall.clone = kprobe.function("_do_fork").call !, |
| 85 |
kprobe.function("do_fork").call |
| 86 |
{ |
| 87 |
%( arch != "ia64" %? |
| 88 |
@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone")) |
| 89 |
name = "clone" |
| 90 |
%: |
| 91 |
@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2")) |
| 92 |
// This is a bit gross. We're depending on @__syscall_gate2() |
| 93 |
// to set '__nr' for us. If its implementation changes, this will |
| 94 |
// need to change. |
| 95 |
if (__nr == @const("__NR_clone")) |
| 96 |
name = "clone" |
| 97 |
else { |
| 98 |
name = "clone2" |
| 99 |
%(kernel_v >= "3.8.0" %? |
| 100 |
stack_size = ulong_arg(3) |
| 101 |
%: |
| 102 |
stack_size = ulong_arg(4) |
| 103 |
%) |
| 104 |
} |
| 105 |
%) |
| 106 |
|
| 107 |
clone_flags = long_arg(1) |
| 108 |
stack_start = pointer_arg(2) |
| 109 |
%(kernel_v >= "3.8.0" %? |
| 110 |
parent_tid_uaddr = pointer_arg(4) |
| 111 |
child_tid_uaddr = pointer_arg(5) |
| 112 |
%: |
| 113 |
parent_tid_uaddr = pointer_arg(5) |
| 114 |
child_tid_uaddr = pointer_arg(6) |
| 115 |
%) |
| 116 |
|
| 117 |
%( arch != "ia64" %? |
| 118 |
argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags), |
| 119 |
stack_start, parent_tid_uaddr, child_tid_uaddr) |
| 120 |
%: |
| 121 |
if (__nr == @const("__NR_clone")) |
| 122 |
argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags), |
| 123 |
stack_start, parent_tid_uaddr, child_tid_uaddr) |
| 124 |
else |
| 125 |
argstr = sprintf("%s, %p, %p, %p, %p", |
| 126 |
__fork_flags(clone_flags), stack_start, |
| 127 |
stack_size, parent_tid_uaddr, child_tid_uaddr) |
| 128 |
%) |
| 129 |
} |
| 130 |
|
| 131 |
probe tp_syscall.clone = kernel.trace("sys_enter") |
| 132 |
{ |
| 133 |
__set_syscall_pt_regs($regs) |
| 134 |
%( arch != "ia64" %? |
| 135 |
@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone")) |
| 136 |
name = "clone" |
| 137 |
%: |
| 138 |
@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2")) |
| 139 |
// This is a bit gross. We're depending on @__syscall_gate2() |
| 140 |
// to set '__nr' for us. If its implementation changes, this will |
| 141 |
// need to change. |
| 142 |
if (__nr == @const("__NR_clone")) |
| 143 |
name = "clone" |
| 144 |
else { |
| 145 |
name = "clone2" |
| 146 |
stack_size = ulong_arg(3) |
| 147 |
} |
| 148 |
%) |
| 149 |
|
| 150 |
clone_flags = long_arg(@SYSC_CLONE_CLONE_FLAGS_ARGNO) |
| 151 |
stack_start = pointer_arg(@SYSC_CLONE_STACK_START_ARGNO) |
| 152 |
parent_tid_uaddr = pointer_arg(@SYSC_CLONE_PARENT_TID_UADDR_ARGNO) |
| 153 |
child_tid_uaddr = pointer_arg(@SYSC_CLONE_CHILD_TID_UADDR_ARGNO) |
| 154 |
|
| 155 |
%( arch != "ia64" %? |
| 156 |
argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags), |
| 157 |
stack_start, parent_tid_uaddr, child_tid_uaddr) |
| 158 |
%: |
| 159 |
if (__nr == @const("__NR_clone")) |
| 160 |
argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags), |
| 161 |
stack_start, parent_tid_uaddr, child_tid_uaddr) |
| 162 |
else |
| 163 |
argstr = sprintf("%s, %p, %p, %p, %p", |
| 164 |
__fork_flags(clone_flags), stack_start, |
| 165 |
stack_size, parent_tid_uaddr, child_tid_uaddr) |
| 166 |
%) |
| 167 |
} |
| 168 |
|
| 169 |
probe nd1_syscall.clone.return = kprobe.function("_do_fork").return !, |
| 170 |
kprobe.function("do_fork").return |
| 171 |
{ |
| 172 |
%( arch != "ia64" %? |
| 173 |
@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone")) |
| 174 |
name = "clone" |
| 175 |
%: |
| 176 |
@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2")) |
| 177 |
// This is a bit gross. We're depending on @__syscall_gate2() |
| 178 |
// to set '__nr' for us. If its implementation changes, this will |
| 179 |
// need to change. |
| 180 |
if (__nr == @const("__NR_clone")) |
| 181 |
name = "clone" |
| 182 |
else |
| 183 |
name = "clone2" |
| 184 |
%) |
| 185 |
@SYSC_RETVALSTR(returnval()) |
| 186 |
} |
| 187 |
|
| 188 |
probe tp_syscall.clone.return = kernel.trace("sys_exit") |
| 189 |
{ |
| 190 |
__set_syscall_pt_regs($regs) |
| 191 |
%( arch != "ia64" %? |
| 192 |
@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone")) |
| 193 |
name = "clone" |
| 194 |
%: |
| 195 |
@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2")) |
| 196 |
// This is a bit gross. We're depending on @__syscall_gate2() |
| 197 |
// to set '__nr' for us. If its implementation changes, this will |
| 198 |
// need to change. |
| 199 |
if (__nr == @const("__NR_clone")) |
| 200 |
name = "clone" |
| 201 |
else |
| 202 |
name = "clone2" |
| 203 |
%) |
| 204 |
@SYSC_RETVALSTR($ret) |
| 205 |
} |