Debian Codegraph @

tapset/linux/sysc_ftruncate.stp

raw
1 # ftruncate __________________________________________________
2 # long sys_ftruncate(unsigned int fd, unsigned long length)
3 # COMPAT_SYSCALL_DEFINE2(ftruncate, unsigned int, fd, compat_ulong_t, length)
4 #
5
6 @define _SYSCALL_FTRUNCATE_NAME
7 %(
8 name = "ftruncate"
9 %)
10
11 @define _SYSCALL_FTRUNCATE_ARGSTR
12 %(
13 argstr = sprintf("%d, %d", fd, length)
14 %)
15
16 @define _SYSCALL_FTRUNCATE_REGARGS
17 %(
18 fd = int_arg(1)
19 length = @__compat_task ? int_arg(2) : long_arg(2)
20 %)
21
22 @define _SYSCALL_FTRUNCATE_REGARGS_STORE
23 %(
24 if (@probewrite(fd))
25 set_int_arg(1, fd)
26
27 if (@probewrite(length)) {
28 if (@__compat_task)
29 set_int_arg(2, length)
30 else
31 set_long_arg(2, length)
32 }
33 %)
34
35 @define _SYSCALL_FTRUNCATE64_REGARGS
36 %(
37 fd = int_arg(1)
38 length = longlong_arg(2)
39 %)
40
41 @define _SYSCALL_FTRUNCATE64_REGARGS_STORE
42 %(
43 if (@probewrite(fd))
44 set_int_arg(1, fd)
45
46 if (@probewrite(length))
47 set_longlong_arg(2, length)
48 %)
49
50 @define _SYSCALL_GATE
51 %(
52 %( arch == "x86_64" || arch == "s390" %?
53 // On x86_64 and s390x RHL6 kernels, the 32-bit compat
54 // ftruncate syscall is hooked up directly to sys_ftruncate(),
55 // instead of going through compat_sys_ftruncate().
56 @__syscall_compat_gate(@const("__NR_ftruncate"),
57 @const("__NR_compat_ftruncate"))
58 %:
59 @__syscall_gate_compat_simple
60 %)
61 %)
62
63 probe syscall.ftruncate = dw_syscall.ftruncate !, nd_syscall.ftruncate ? {}
64 probe syscall.ftruncate.return = dw_syscall.ftruncate.return !, nd_syscall.ftruncate.return ? {}
65
66 # dw_ftruncate _____________________________________________________
67
68 probe dw_syscall.ftruncate = __syscall.ftruncate,
69 kernel.function("compat_sys_ftruncate").call ?
70 {
71 @_SYSCALL_FTRUNCATE_NAME
72 fd = __int32($fd)
73 length = @__compat_long($length)
74 @_SYSCALL_FTRUNCATE_ARGSTR
75 }
76 probe __syscall.ftruncate = kernel.function("sys_ftruncate").call
77 {
78 @_SYSCALL_GATE
79 }
80 probe dw_syscall.ftruncate.return = __syscall.ftruncate.return,
81 kernel.function("compat_sys_ftruncate").return ?
82 {
83 @_SYSCALL_FTRUNCATE_NAME
84 @SYSC_RETVALSTR($return)
85 }
86 probe __syscall.ftruncate.return = kernel.function("sys_ftruncate").return
87 {
88 @_SYSCALL_GATE
89 }
90
91 # nd_ftruncate _____________________________________________________
92
93 probe nd_syscall.ftruncate = nd1_syscall.ftruncate!, nd2_syscall.ftruncate!, tp_syscall.ftruncate
94 { }
95
96 probe nd1_syscall.ftruncate = __nd1_syscall.ftruncate,
97 kprobe.function("compat_sys_ftruncate").call?
98 {
99 @_SYSCALL_FTRUNCATE_NAME
100 asmlinkage()
101 @_SYSCALL_FTRUNCATE_REGARGS
102 @_SYSCALL_FTRUNCATE_ARGSTR
103 }
104 probe __nd1_syscall.ftruncate = kprobe.function("sys_ftruncate").call
105 {
106 @_SYSCALL_GATE
107 }
108
109 /* kernel 4.17+ */
110 probe nd2_syscall.ftruncate =
111 kprobe.function(@arch_syscall_prefix "sys_ftruncate") ?,
112 kprobe.function(@arch_syscall_prefix "comapt_sys_ftruncate") ?
113 {
114 __set_syscall_pt_regs(pointer_arg(1))
115 @_SYSCALL_FTRUNCATE_NAME
116 @_SYSCALL_FTRUNCATE_REGARGS
117 @_SYSCALL_FTRUNCATE_ARGSTR
118 },
119 {
120 @_SYSCALL_FTRUNCATE_REGARGS_STORE
121 }
122
123 /* kernel 3.5+, but undesirable because it affects all syscalls */
124 probe tp_syscall.ftruncate = kernel.trace("sys_enter")
125 {
126 __set_syscall_pt_regs($regs)
127 @__syscall_compat_gate(@const("__NR_ftruncate"),
128 @const("__NR_compat_ftruncate"))
129 @_SYSCALL_FTRUNCATE_NAME
130 @_SYSCALL_FTRUNCATE_REGARGS
131 @_SYSCALL_FTRUNCATE_ARGSTR
132 },
133 {
134 @_SYSCALL_FTRUNCATE_REGARGS_STORE
135 }
136
137 probe nd_syscall.ftruncate.return = nd1_syscall.ftruncate.return!, nd2_syscall.ftruncate.return!, tp_syscall.ftruncate.return
138 { }
139
140 probe nd1_syscall.ftruncate.return = __nd1_syscall.ftruncate.return,
141 kprobe.function("compat_sys_ftruncate").return ?
142 {
143 @_SYSCALL_FTRUNCATE_NAME
144 @SYSC_RETVALSTR(returnval())
145 }
146 probe __nd1_syscall.ftruncate.return = kprobe.function("sys_ftruncate").return
147 {
148 @_SYSCALL_GATE
149 }
150
151 /* kernel 4.17+ */
152 probe nd2_syscall.ftruncate.return =
153 kprobe.function(@arch_syscall_prefix "sys_ftruncate").return ?,
154 kprobe.function(@arch_syscall_prefix "compat_sys_ftruncate").return ?
155 {
156 @_SYSCALL_FTRUNCATE_NAME
157 @SYSC_RETVALSTR(returnval())
158 }
159
160 /* kernel 3.5+, but undesirable because it affects all syscalls */
161 probe tp_syscall.ftruncate.return = kernel.trace("sys_exit")
162 {
163 __set_syscall_pt_regs($regs)
164 @__syscall_compat_gate(@const("__NR_ftruncate"),
165 @const("__NR_compat_ftruncate"))
166 @_SYSCALL_FTRUNCATE_NAME
167 @SYSC_RETVALSTR($ret)
168 }
169
170 # ftruncate64 ________________________________________________
171 # long sys_ftruncate64(unsigned int fd, loff_t length)
172
173 probe syscall.ftruncate64 = dw_syscall.ftruncate64 !, nd_syscall.ftruncate64 ? {}
174 probe syscall.ftruncate64.return = dw_syscall.ftruncate64.return !, nd_syscall.ftruncate64.return ? {}
175
176 # dw_ftruncate64 _____________________________________________________
177
178 probe dw_syscall.ftruncate64 = kernel.function("sys_ftruncate64").call ?
179 {
180 @_SYSCALL_FTRUNCATE_NAME
181 fd = __int32($fd)
182 length = $length
183 @_SYSCALL_FTRUNCATE_ARGSTR
184 }
185 probe dw_syscall.ftruncate64.return = kernel.function("sys_ftruncate64").return ?
186 {
187 @_SYSCALL_FTRUNCATE_NAME
188 @SYSC_RETVALSTR($return)
189 }
190
191 # nd_ftruncate64 _____________________________________________________
192
193 probe nd_syscall.ftruncate64 = nd1_syscall.ftruncate64!, nd2_syscall.ftruncate64!, tp_syscall.ftruncate64
194 { }
195
196 probe nd1_syscall.ftruncate64 = kprobe.function("sys_ftruncate64") ?
197 {
198 @_SYSCALL_FTRUNCATE_NAME
199 asmlinkage()
200 @_SYSCALL_FTRUNCATE64_REGARGS
201 @_SYSCALL_FTRUNCATE_ARGSTR
202 }
203
204 /* kernel 3.5+, but undesirable because it affects all syscalls */
205 probe tp_syscall.ftruncate64 = kernel.trace("sys_enter")
206 {
207 __set_syscall_pt_regs($regs)
208 @__syscall_gate(@const("__NR_ftruncate64"))
209 @_SYSCALL_FTRUNCATE_NAME
210 @_SYSCALL_FTRUNCATE64_REGARGS
211 @_SYSCALL_FTRUNCATE_ARGSTR
212 },
213 {
214 @_SYSCALL_FTRUNCATE64_REGARGS_STORE
215 }
216
217 probe nd_syscall.ftruncate64.return = nd1_syscall.ftruncate64.return!, nd2_syscall.ftruncate64.return!, tp_syscall.ftruncate64.return
218 { }
219
220 probe nd1_syscall.ftruncate64.return =
221 kprobe.function("sys_ftruncate64").return ?
222 {
223 @_SYSCALL_FTRUNCATE_NAME
224 @SYSC_RETVALSTR(returnval())
225 }
226
227 /* kernel 3.5+, but undesirable because it affects all syscalls */
228 probe tp_syscall.ftruncate64.return = kernel.trace("sys_exit")
229 {
230 __set_syscall_pt_regs($regs)
231 @__syscall_gate(@const("__NR_ftruncate64"))
232 @_SYSCALL_FTRUNCATE_NAME
233 @SYSC_RETVALSTR($ret)
234 }