File: sysc_clone.stp

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (205 lines) | stat: -rw-r--r-- 6,708 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# clone ______________________________________________________
#
# The sys_clone() call was in arch-specific code (sometimes assembly
# code), especially in older kernels. Its args varied dramatically,
# from full args to getting nothing but registers. To get around this,
# we'll just probe do_fork(). The fork()/vfork()/clone() syscalls are
# just wrappers around do_fork().  We'll reject all probe hits that
# aren't really clone syscalls (such as calls to sys_fork(),
# sys_vfork(), and the kernel's internal use of do_fork()). Kernel
# commit 3033f14ab78c32 renamed 'do_fork' to '_do_fork'.
#
# For ia64, this is complicated by the fact that it has a clone2
# syscall.
#

probe syscall.clone = dw_syscall.clone !, nd_syscall.clone {}
probe syscall.clone.return = dw_syscall.clone.return !, nd_syscall.clone.return {}

# dw_clone _____________________________________________________

probe dw_syscall.clone = kernel.function("_do_fork").call !,
	kernel.function("do_fork").call
{
%( arch != "ia64" %?
	@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone"))
	name = "clone"
%:
	@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2"))
	// This is a bit gross. We're depending on @__syscall_gate2()
	// to set '__nr' for us. If its implementation changes, this will
	// need to change.
	if (__nr == @const("__NR_clone"))
		name = "clone"
	else {
		name = "clone2"
		stack_size = $stack_size
	}	
%)
        clone_flags = @choose_defined($args->flags,$clone_flags)
        stack_start = @choose_defined($args->stack,$stack_start)
        parent_tid_uaddr = @choose_defined($args->parent_tid,$parent_tidptr)
        child_tid_uaddr = @choose_defined($args->child_tid,$child_tidptr)

%( arch != "ia64" %?
	argstr = sprintf("%s, %p, %p, %p",
                         __fork_flags(@choose_defined($args->flags,$clone_flags)),
                         @choose_defined($args->stack,$stack_start),
                         @choose_defined($args->parent_tid,$parent_tidptr),
                         @choose_defined($args->child_tid,$child_tidptr))
%:
	if (__nr == @const("__NR_clone"))
		argstr = sprintf("%s, %p, %p, %p", __fork_flags($clone_flags),
		                 $stack_start, $parent_tidptr, $child_tidptr)
	else
		argstr = sprintf("%s, %p, %p, %p, %p",
		                 __fork_flags($clone_flags), $stack_start,
				 $stack_size, $parent_tidptr, $child_tidptr)
%)
}
probe dw_syscall.clone.return = kernel.function("_do_fork").return !,
	kernel.function("do_fork").return
{
%( arch != "ia64" %?
	@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone"))
	name = "clone"
%:
	@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2"))
	// This is a bit gross. We're depending on @__syscall_gate2()
	// to set '__nr' for us. If its implementation changes, this will
	// need to change.
	if (__nr == @const("__NR_clone"))
		name = "clone"
	else
		name = "clone2"
%)
	@SYSC_RETVALSTR($return)
}

# nd_clone _____________________________________________________

probe nd_syscall.clone = nd1_syscall.clone!, tp_syscall.clone
  { }

probe nd1_syscall.clone = kprobe.function("_do_fork").call !,
	kprobe.function("do_fork").call
{
%( arch != "ia64" %?
	@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone"))
	name = "clone"
%:
	@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2"))
	// This is a bit gross. We're depending on @__syscall_gate2()
	// to set '__nr' for us. If its implementation changes, this will
	// need to change.
	if (__nr == @const("__NR_clone"))
		name = "clone"
	else {
		name = "clone2"
%(kernel_v >= "3.8.0" %?
		stack_size = ulong_arg(3)
%:
		stack_size = ulong_arg(4)
%)
	}	
%)

	clone_flags = long_arg(1)
	stack_start = pointer_arg(2)
%(kernel_v >= "3.8.0" %?
	parent_tid_uaddr = pointer_arg(4)
	child_tid_uaddr = pointer_arg(5)
%:
	parent_tid_uaddr = pointer_arg(5)
	child_tid_uaddr = pointer_arg(6)
%)

%( arch != "ia64" %?
	argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags),
	                 stack_start, parent_tid_uaddr, child_tid_uaddr)
%:
	if (__nr == @const("__NR_clone"))
		argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags),
		                 stack_start, parent_tid_uaddr, child_tid_uaddr)
	else			
		argstr = sprintf("%s, %p, %p, %p, %p",
		                 __fork_flags(clone_flags), stack_start,
				 stack_size, parent_tid_uaddr, child_tid_uaddr)
%)
}

probe tp_syscall.clone = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
%( arch != "ia64" %?
	@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone"))
	name = "clone"
%:
	@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2"))
	// This is a bit gross. We're depending on @__syscall_gate2()
	// to set '__nr' for us. If its implementation changes, this will
	// need to change.
	if (__nr == @const("__NR_clone"))
		name = "clone"
	else {
		name = "clone2"
		stack_size = ulong_arg(3)
	}
%)

	clone_flags = long_arg(@SYSC_CLONE_CLONE_FLAGS_ARGNO)
	stack_start = pointer_arg(@SYSC_CLONE_STACK_START_ARGNO)
	parent_tid_uaddr = pointer_arg(@SYSC_CLONE_PARENT_TID_UADDR_ARGNO)
	child_tid_uaddr = pointer_arg(@SYSC_CLONE_CHILD_TID_UADDR_ARGNO)

%( arch != "ia64" %?
	argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags),
	                 stack_start, parent_tid_uaddr, child_tid_uaddr)
%:
	if (__nr == @const("__NR_clone"))
		argstr = sprintf("%s, %p, %p, %p", __fork_flags(clone_flags),
		                 stack_start, parent_tid_uaddr, child_tid_uaddr)
	else
		argstr = sprintf("%s, %p, %p, %p, %p",
		                 __fork_flags(clone_flags), stack_start,
				 stack_size, parent_tid_uaddr, child_tid_uaddr)
%)
}

probe nd1_syscall.clone.return = kprobe.function("_do_fork").return !,
	kprobe.function("do_fork").return
{
%( arch != "ia64" %?
	@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone"))
	name = "clone"
%:
	@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2"))
	// This is a bit gross. We're depending on @__syscall_gate2()
	// to set '__nr' for us. If its implementation changes, this will
	// need to change.
	if (__nr == @const("__NR_clone"))
		name = "clone"
	else
		name = "clone2"
%)
	@SYSC_RETVALSTR(returnval())
}

probe tp_syscall.clone.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
%( arch != "ia64" %?
	@__syscall_compat_gate(@const("__NR_clone"), @const("__NR_compat_clone"))
	name = "clone"
%:
	@__syscall_gate2(@const("__NR_clone"), @const("__NR_clone2"))
	// This is a bit gross. We're depending on @__syscall_gate2()
	// to set '__nr' for us. If its implementation changes, this will
	// need to change.
	if (__nr == @const("__NR_clone"))
		name = "clone"
	else
		name = "clone2"
%)
	@SYSC_RETVALSTR($ret)
}