File: sysc_ftruncate.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 (234 lines) | stat: -rw-r--r-- 6,212 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# ftruncate __________________________________________________
# long sys_ftruncate(unsigned int fd, unsigned long length)
# COMPAT_SYSCALL_DEFINE2(ftruncate, unsigned int, fd, compat_ulong_t, length)
#

@define _SYSCALL_FTRUNCATE_NAME
%(
	name = "ftruncate"
%)

@define _SYSCALL_FTRUNCATE_ARGSTR
%(
	argstr = sprintf("%d, %d", fd, length)
%)

@define _SYSCALL_FTRUNCATE_REGARGS
%(
	fd = int_arg(1)
	length = @__compat_task ? int_arg(2) : long_arg(2)
%)

@define _SYSCALL_FTRUNCATE_REGARGS_STORE
%(
        if (@probewrite(fd))
          set_int_arg(1, fd)

	if (@probewrite(length)) {
	  if (@__compat_task)
	    set_int_arg(2, length)
	  else
	    set_long_arg(2, length)
	}
%)

@define _SYSCALL_FTRUNCATE64_REGARGS
%(
	fd = int_arg(1)
	length = longlong_arg(2)
%)

@define _SYSCALL_FTRUNCATE64_REGARGS_STORE
%(
        if (@probewrite(fd))
          set_int_arg(1, fd)

	if (@probewrite(length))
	  set_longlong_arg(2, length)
%)

@define _SYSCALL_GATE
%(
    %( arch == "x86_64" || arch == "s390" %?
	// On x86_64 and s390x RHL6 kernels, the 32-bit compat
	// ftruncate syscall is hooked up directly to sys_ftruncate(),
	// instead of going through compat_sys_ftruncate().
	@__syscall_compat_gate(@const("__NR_ftruncate"),
			       @const("__NR_compat_ftruncate"))
    %:
	@__syscall_gate_compat_simple
    %)
%)

probe syscall.ftruncate = dw_syscall.ftruncate !, nd_syscall.ftruncate ? {}
probe syscall.ftruncate.return = dw_syscall.ftruncate.return !, nd_syscall.ftruncate.return ? {}

# dw_ftruncate _____________________________________________________

probe dw_syscall.ftruncate = __syscall.ftruncate,
	kernel.function("compat_sys_ftruncate").call ?
{
	@_SYSCALL_FTRUNCATE_NAME
	fd = __int32($fd)
	length = @__compat_long($length)
	@_SYSCALL_FTRUNCATE_ARGSTR
}
probe __syscall.ftruncate = kernel.function("sys_ftruncate").call
{
	@_SYSCALL_GATE
}
probe dw_syscall.ftruncate.return = __syscall.ftruncate.return,
	kernel.function("compat_sys_ftruncate").return ?
{
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR($return)
}
probe __syscall.ftruncate.return = kernel.function("sys_ftruncate").return
{
	@_SYSCALL_GATE
}

# nd_ftruncate _____________________________________________________

probe nd_syscall.ftruncate = nd1_syscall.ftruncate!, nd2_syscall.ftruncate!, tp_syscall.ftruncate
  { }

probe nd1_syscall.ftruncate = __nd1_syscall.ftruncate,
	kprobe.function("compat_sys_ftruncate").call?
{
	@_SYSCALL_FTRUNCATE_NAME
	asmlinkage()
	@_SYSCALL_FTRUNCATE_REGARGS
	@_SYSCALL_FTRUNCATE_ARGSTR
}
probe __nd1_syscall.ftruncate = kprobe.function("sys_ftruncate").call
{
	@_SYSCALL_GATE
}

/* kernel 4.17+ */
probe nd2_syscall.ftruncate =
	kprobe.function(@arch_syscall_prefix "sys_ftruncate") ?,
	kprobe.function(@arch_syscall_prefix "comapt_sys_ftruncate") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_FTRUNCATE_NAME
	@_SYSCALL_FTRUNCATE_REGARGS
	@_SYSCALL_FTRUNCATE_ARGSTR
},
{
        @_SYSCALL_FTRUNCATE_REGARGS_STORE
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.ftruncate = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_ftruncate"),
			       @const("__NR_compat_ftruncate"))
	@_SYSCALL_FTRUNCATE_NAME
	@_SYSCALL_FTRUNCATE_REGARGS
	@_SYSCALL_FTRUNCATE_ARGSTR
},
{
        @_SYSCALL_FTRUNCATE_REGARGS_STORE
}

probe nd_syscall.ftruncate.return = nd1_syscall.ftruncate.return!, nd2_syscall.ftruncate.return!, tp_syscall.ftruncate.return
  { }

probe nd1_syscall.ftruncate.return = __nd1_syscall.ftruncate.return,
	kprobe.function("compat_sys_ftruncate").return ?
{
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR(returnval())
}
probe __nd1_syscall.ftruncate.return = kprobe.function("sys_ftruncate").return
{
	@_SYSCALL_GATE
}

/* kernel 4.17+ */
probe nd2_syscall.ftruncate.return =
	kprobe.function(@arch_syscall_prefix "sys_ftruncate").return ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_ftruncate").return ?
{
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.ftruncate.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_ftruncate"),
			       @const("__NR_compat_ftruncate"))
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR($ret)
}

# ftruncate64 ________________________________________________
# long sys_ftruncate64(unsigned int fd, loff_t length)

probe syscall.ftruncate64 = dw_syscall.ftruncate64 !, nd_syscall.ftruncate64 ? {}
probe syscall.ftruncate64.return = dw_syscall.ftruncate64.return !, nd_syscall.ftruncate64.return ? {}

# dw_ftruncate64 _____________________________________________________

probe dw_syscall.ftruncate64 = kernel.function("sys_ftruncate64").call ?
{
	@_SYSCALL_FTRUNCATE_NAME
	fd = __int32($fd)
	length = $length
	@_SYSCALL_FTRUNCATE_ARGSTR
}
probe dw_syscall.ftruncate64.return = kernel.function("sys_ftruncate64").return ?
{
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR($return)
}

# nd_ftruncate64 _____________________________________________________

probe nd_syscall.ftruncate64 = nd1_syscall.ftruncate64!, nd2_syscall.ftruncate64!, tp_syscall.ftruncate64
  { }

probe nd1_syscall.ftruncate64 = kprobe.function("sys_ftruncate64") ?
{
	@_SYSCALL_FTRUNCATE_NAME
	asmlinkage()
	@_SYSCALL_FTRUNCATE64_REGARGS
	@_SYSCALL_FTRUNCATE_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.ftruncate64 = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_ftruncate64"))
	@_SYSCALL_FTRUNCATE_NAME
	@_SYSCALL_FTRUNCATE64_REGARGS
	@_SYSCALL_FTRUNCATE_ARGSTR
},
{
        @_SYSCALL_FTRUNCATE64_REGARGS_STORE
}

probe nd_syscall.ftruncate64.return = nd1_syscall.ftruncate64.return!, nd2_syscall.ftruncate64.return!, tp_syscall.ftruncate64.return
  { }

probe nd1_syscall.ftruncate64.return =
	kprobe.function("sys_ftruncate64").return ?
{
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.ftruncate64.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_ftruncate64"))
	@_SYSCALL_FTRUNCATE_NAME
	@SYSC_RETVALSTR($ret)
}