Debian Codegraph @

tapset/linux/syscalls.stpm

raw
1 // syscalls tapset macros
2 // Copyright (C) 2013-2019 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9
10 @define __syscall_nr_gate(syscall_nr)
11 %(
12 # Here we don't care if we're in a compat task or not, we just
13 # want to make sure we've got the correct syscall number.
14 #
15 # If _stp_syscall_nr() fails, that means we aren't in user
16 # context. So, skip this call.
17 try { if (_stp_syscall_nr() != @syscall_nr) next } catch { next }
18 %)
19
20 @define __syscall_gate(syscall_nr)
21 %(
22 # On some platforms (like s390x and ppc64), the 32-bit
23 # syscalls use the same syscall number as the 64-bit
24 # syscall. So, we have to check to see if this is a
25 # 32-on-64-bit user task.
26 @__syscall_gate_compat_simple
27
28 # If _stp_syscall_nr() fails, that means we aren't in user
29 # context. So, skip this call.
30 try { if (_stp_syscall_nr() != @syscall_nr) next } catch { next }
31 %)
32
33 @define __syscall_gate2(syscall_nr1, syscall_nr2)
34 %(
35 # On some platforms (like s390x and ppc64), the 32-bit
36 # syscalls use the same syscall number as the 64-bit
37 # syscall. So, we have to check to see if this is a
38 # 32-on-64-bit user task.
39 @__syscall_gate_compat_simple
40
41 try { __nr = _stp_syscall_nr() } catch { next }
42 if ((__nr != @syscall_nr1) && (__nr != @syscall_nr2)) next
43 %)
44
45 @define __syscall_compat_gate(syscall_nr, compat_syscall_nr)
46 %(
47 %( CONFIG_COMPAT == "y" %?
48 try { __nr = _stp_syscall_nr() } catch { next }
49 if (@__compat_task) {
50 if (__nr != @compat_syscall_nr)
51 next
52 }
53 else if (__nr != @syscall_nr)
54 next
55 %:
56 try { if (_stp_syscall_nr() != @syscall_nr) next } catch { next }
57 %)
58 %)
59
60 @define __compat_syscall_gate(compat_syscall_nr)
61 %(
62 @__syscall_gate_noncompat_simple
63 %( CONFIG_COMPAT == "y" %?
64 try { __nr = _stp_syscall_nr() } catch { next }
65 if (@__compat_task) {
66 if (__nr != @compat_syscall_nr) next
67 }
68 %)
69 %)
70
71 @define __compat_syscall_gate_negative(compat_syscall_nr)
72 %(
73 %( CONFIG_COMPAT == "y" %?
74 try { __nr = _stp_syscall_nr() } catch { next }
75 if (@__compat_task) {
76 if (__nr == @compat_syscall_nr) next
77 }
78 %)
79 %)
80
81 @define __syscall_gate_compat_simple
82 %(
83 %( CONFIG_COMPAT == "y" %?
84 if (@__compat_task) next
85 %)
86 %)
87
88 @define __syscall_gate_noncompat_simple
89 %(
90 %( CONFIG_COMPAT == "y" %?
91 if (! @__compat_task) next
92 %:
93 next
94 %)
95 %)
96 @define __pointer(val)
97 %(
98 %( CONFIG_64BIT == "y" %?
99 %( CONFIG_COMPAT == "y" %?
100 # If this is a compat task, the high bits of a pointer may be
101 # garbage.
102 (@__compat_task ? (@val & 0xffffffff) : @val)
103 %:
104 @val
105 %)
106 %:
107 (@val & 0xffffffff)
108 %)
109 %)
110
111 @define _af_inet_info_u(my_addr_uaddr, addrlen)
112 %(
113 %( systemtap_v >= "2.5" %?
114 uaddr_af = _struct_sockaddr_u_sa_family(@my_addr_uaddr, @addrlen)
115 if (_struct_sockaddr_u_sa_family(@my_addr_uaddr, @addrlen) =~ "AF_INET.*") {
116 uaddr_ip = _struct_sockaddr_u_ip_addr(@my_addr_uaddr, @addrlen)
117 uaddr_ip_port = _struct_sockaddr_u_tcp_port(@my_addr_uaddr, @addrlen)
118 if (_struct_sockaddr_u_sa_family(@my_addr_uaddr, @addrlen) == "AF_INET6") {
119 uaddr_ipv6_flowinfo = _struct_sockaddr_u_ipv6_flowinfo(@my_addr_uaddr, @addrlen)
120 uaddr_ipv6_scope_id = _struct_sockaddr_u_ipv6_scope_id(@my_addr_uaddr, @addrlen)
121 }
122 }
123 %)
124 %)
125
126 # The following argstr processing is modeled on strace's handling of
127 # futex. Because it is so complicated and is used in 4 places
128 # (syscall.futex, syscall.compat_futex, nd_syscall.futex, and
129 # nd_syscall.compat_futex), a macro is used to handle all the
130 # details.
131 @define __futex_argstr(uaddr, op, val, utime, uaddr2, val3)
132 %(
133 if (@op == @const("FUTEX_WAKE_BITSET")) {
134 argstr = sprintf("%p, %s, %d, %#x", @uaddr, _futex_op_str(@op),
135 @val, @val3)
136 }
137 else if (@op == @const("FUTEX_WAIT")) {
138 argstr = sprintf("%p, %s, %d, %s", @uaddr, _futex_op_str(@op),
139 @val,
140 (@__compat_task
141 ? _struct_compat_timespec_u(@utime, 1)
142 : _struct_timespec_u(@utime, 1)))
143 }
144 else if (@op == @const("FUTEX_WAIT_BITSET")) {
145 argstr = sprintf("%p, %s, %d, %s, %#x", @uaddr,
146 _futex_op_str(@op), @val,
147 (@__compat_task
148 ? _struct_compat_timespec_u(@utime, 1)
149 : _struct_timespec_u(@utime, 1)), @val3)
150 }
151 else if (@op == @const("FUTEX_REQUEUE")) {
152 argstr = sprintf("%p, %s, %d, %d, %p", @uaddr,
153 _futex_op_str(@op), @val, @utime,
154 @uaddr2)
155 }
156 else if (@op == @const("FUTEX_CMP_REQUEUE")
157 || @op == @const("FUTEX_CMP_REQUEUE_PI")) {
158 argstr = sprintf("%p, %s, %d, %u, %p, %d", @uaddr,
159 _futex_op_str(@op), @val, @utime,
160 @uaddr2, @val3)
161 }
162 else if (@op == @const("FUTEX_WAKE_OP")) {
163 argstr = sprintf("%p, %s, %d, %u, %p, %s", @uaddr,
164 _futex_op_str(@op), @val, @utime,
165 @uaddr2, _futex_wake_op_str(@val3))
166 }
167 else if (@op == @const("FUTEX_WAIT_REQUEUE_PI")) {
168 argstr = sprintf("%p, %s, %d, %s, %p", @uaddr,
169 _futex_op_str(@op), @val,
170 (@__compat_task
171 ? _struct_compat_timespec_u(@utime, 1)
172 : _struct_timespec_u(@utime, 1)),
173 @uaddr2)
174 }
175 else {
176 argstr = sprintf("%p, %s, %d", @uaddr, _futex_op_str(@op),
177 @val)
178 }
179 %)
180
181 %( systemtap_v <= "2.9" %?
182 @define __int32_compat(arg)
183 %(
184 %( CONFIG_64BIT == "y" %?
185 (@__compat_task ? __int32(@arg) : @arg)
186 %:
187 (__int32(@arg))
188 %)
189 %)
190 %)
191
192 @define __keyctl_argstr(option, arg2, arg3, arg4, arg5)
193 %(
194 if ((@option == @const("KEYCTL_READ")) ||
195 (@option == @const("KEYCTL_DESCRIBE")) ||
196 (@option == @const("KEYCTL_GET_SECURITY"))) {
197 argstr = sprintf("%s, %s, %p, %d", _stp_keyctl_cmd_str(@option),
198 _stp_keyctl_keyring_shortcut_str(@arg2),
199 @arg3, @__compat_long(@arg4))
200 }
201 else if (@option == @const("KEYCTL_UPDATE")) {
202 argstr = sprintf("%s, %d, %s, %d", _stp_keyctl_cmd_str(@option),
203 @__compat_long(@arg2), user_string_quoted(@arg3),
204 @__compat_long(@arg4))
205 }
206 else if ((@option == @const("KEYCTL_REVOKE")) ||
207 (@option == @const("KEYCTL_CLEAR")) ||
208 (@option == @const("KEYCTL_INVALIDATE")) ||
209 (@option == @const("KEYCTL_ASSUME_AUTHORITY"))) {
210 argstr = sprintf("%s, %d", _stp_keyctl_cmd_str(@option),
211 @__compat_long(@arg2))
212 }
213 else if ((@option == @const("KEYCTL_LINK")) ||
214 (@option == @const("KEYCTL_UNLINK"))) {
215 argstr = sprintf("%s, %d, %d", _stp_keyctl_cmd_str(@option),
216 @__compat_long(@arg2), @__compat_long(@arg3))
217 }
218 else if (@option == @const("KEYCTL_SEARCH")) {
219 argstr = sprintf("%s, %d, %s, %s, %d", _stp_keyctl_cmd_str(@option),
220 @__compat_long(@arg2), user_string_quoted(@arg3),
221 user_string_quoted(@arg4), @__compat_long(@arg5))
222 }
223 else if (@option == @const("KEYCTL_CHOWN")) {
224 argstr = sprintf("%s, %d, %d, %d", _stp_keyctl_cmd_str(@option),
225 @__compat_long(@arg2), @__compat_long(@arg3),
226 @__compat_long(@arg4))
227 }
228 else if (@option == @const("KEYCTL_SETPERM")) {
229 argstr = sprintf("%s, %d, %s", _stp_keyctl_cmd_str(@option),
230 @__compat_long(@arg2), _stp_keyctl_perm_str(@arg3))
231 }
232 else if ((@option == @const("KEYCTL_INSTANTIATE"))) {
233 argstr = sprintf("%s, %d, %s, %d, %d", _stp_keyctl_cmd_str(@option),
234 @__compat_long(@arg2), user_string_quoted(@arg3),
235 @__compat_long(@arg4), @__compat_long(@arg5))
236 }
237 else if ((@option == @const("KEYCTL_INSTANTIATE_IOV"))) {
238 argstr = sprintf("%s, %d, %p, %d, %d", _stp_keyctl_cmd_str(@option),
239 @__compat_long(@arg2), @arg3, @__compat_long(@arg4),
240 @__compat_long(@arg5))
241 }
242 else if (@option == @const("KEYCTL_NEGATE")) {
243 argstr = sprintf("%s, %d, %u, %d", _stp_keyctl_cmd_str(@option),
244 @__compat_long(@arg2), @arg3, @__compat_long(@arg4))
245 }
246 else if (@option == @const("KEYCTL_REJECT")) {
247 argstr = sprintf("%s, %d, %u, %u, %d", _stp_keyctl_cmd_str(@option),
248 @__compat_long(@arg2), @arg3, @arg4,
249 @__compat_long(@arg5))
250 }
251 else if (@option == @const("KEYCTL_SET_TIMEOUT")) {
252 argstr = sprintf("%s, %d, %u", _stp_keyctl_cmd_str(@option),
253 @__compat_long(@arg2), @arg3)
254 }
255 else if (@option == @const("KEYCTL_GET_KEYRING_ID")) {
256 argstr = sprintf("%s, %s, %d", _stp_keyctl_cmd_str(@option),
257 _stp_keyctl_keyring_shortcut_str(@arg2),
258 @__compat_long(@arg3))
259 }
260 else if (@option == @const("KEYCTL_SET_REQKEY_KEYRING")) {
261 argstr = sprintf("%s, %s", _stp_keyctl_cmd_str(@option),
262 _stp_keyctl_default_keyrings_str(@arg2))
263 }
264 else if (@option == @const("KEYCTL_JOIN_SESSION_KEYRING")) {
265 argstr = sprintf("%s, %p", _stp_keyctl_cmd_str(@option), @arg2)
266 }
267 else if (@option == @const("KEYCTL_GET_PERSISTENT")) {
268 argstr = sprintf("%s, %d, %d", _stp_keyctl_cmd_str(@option),
269 @__compat_long(@arg2), @__compat_long(@arg3))
270 }
271 else {
272 argstr = sprintf("%d, %d, %d, %d, %d", @option,
273 @__compat_long(@arg2), @__compat_long(@arg3),
274 @__compat_long(@arg4), @__compat_long(@arg5))
275 }
276 %)
277
278 @define __quotactl_argstr(subcmd, arg1, arg2, arg3, arg4)
279 %(
280 if (@subcmd == @const("Q_QUOTAON")) {
281 argstr = sprintf("%s, %s, %s, %s",
282 _quotactl_cmd_str(@arg1), user_string_quoted(@arg2),
283 _quotactl_quota_type_str(@arg3),
284 user_string_quoted(@arg4))
285 }
286 else if ((@subcmd == @const("Q_GETQUOTA")) ||
287 (@subcmd == @const("Q_SETQUOTA"))) {
288 argstr = sprintf("%s, %s, %d, %s",
289 _quotactl_cmd_str(@arg1), user_string_quoted(@arg2),
290 @arg3, _struct_dqblk_u(@arg4))
291 }
292 else if ((@subcmd == @const("Q_GETINFO")) ||
293 (@subcmd == @const("Q_SETINFO"))) {
294 argstr = sprintf("%s, %s, %d, %s",
295 _quotactl_cmd_str(@arg1), user_string_quoted(@arg2),
296 @arg3, _struct_dqinfo_u(@arg4))
297 }
298 else if (@subcmd == @const("Q_GETFMT")) {
299 argstr = sprintf("%s, %s, %d, %x",
300 _quotactl_cmd_str(@arg1), user_string_quoted(@arg2),
301 @arg3, @arg4)
302 }
303 else if ((@subcmd == @const("Q_SYNC")) ||
304 (@subcmd == @const("Q_QUOTAOFF"))) {
305 argstr = sprintf("%s, %s, %d, %p",
306 _quotactl_cmd_str(@arg1), user_string_quoted(@arg2),
307 @arg3, @arg4)
308 }
309 else {
310 argstr = sprintf("%s, %p, %d, %p", _quotactl_cmd_str(@arg1),
311 @arg2, @arg3, @arg4)
312 }
313 %)
314
315 # @__compat_ulong() macro adds the ability to distinguish between compat and non-compat
316 # task to the __ulong() function making it full-featured couterpart to ulong_arg().
317 @define __compat_ulong(arg)
318 %(
319 %( CONFIG_COMPAT == "y" %?
320 (@__compat_task ? __uint32(@arg) : __ulong(@arg))
321 %:
322 __ulong(@arg)
323 %)
324 %)
325
326 # @__compat_long() macro adds the ability to distinguish between compat and non-compat
327 # task to the __long() function making it full-featured couterpart to long_arg().
328 @define __compat_long(arg)
329 %(
330 %( CONFIG_COMPAT == "y" %?
331 (@__compat_task ? __int32(@arg) : __long(@arg))
332 %:
333 __long(@arg)
334 %)
335 %)
336
337 @define __BIG_ENDIAN
338 %(
339 %{ /* pure */
340 #ifdef __BIG_ENDIAN
341 1
342 #else
343 0
344 #endif
345 %}
346 %)
347
348 # @__pos_from_hilo() is lifted straight from fs/read_write.c and only
349 # used by preadv*/pwritev*.
350 @define __pos_from_hilo(high, low)
351 %(
352 (((__ulong(@high) << (@const("BITS_PER_LONG") / 2)) << (@const("BITS_PER_LONG") / 2)) | __ulong(@low))
353 %)
354
355 @define ulong_cast(val)
356 %(
357 @cast(@val, "ulong", "kernel<uapi/linux/types.h>")
358 %)
359
360 @define uint_cast(val)
361 %(
362 @cast(@val, "unsigned int", "kernel<uapi/linux/types.h>")
363 %)
364
365
366 // As other architectures adopt the 4.17 syscall wrapper mechanism,
367 // these macros will have to be conditionalized on %( arch %).
368
369 %( arch == "ia64" %?
370 @define arch_syscall_prefix %( "" %)
371 @define arch_syscall0_prefix %( "" %)
372 @define SYSC_CLONE_CLONE_FLAGS_ARGNO %( 1 %)
373 @define SYSC_CLONE_STACK_START_ARGNO %( 2 %)
374 @define SYSC_CLONE_PARENT_TID_UADDR_ARGNO %( 4 %)
375 @define SYSC_CLONE_CHILD_TID_UADDR_ARGNO %( 5 %)
376 %)
377
378 %( arch == "s390" %?
379 @define arch_syscall_prefix %( "" %)
380 @define arch_syscall0_prefix %( "" %)
381 @define SYSC_CLONE_CLONE_FLAGS_ARGNO %( 2 %)
382 @define SYSC_CLONE_STACK_START_ARGNO %( 1 %)
383 @define SYSC_CLONE_PARENT_TID_UADDR_ARGNO %( 3 %)
384 @define SYSC_CLONE_CHILD_TID_UADDR_ARGNO %( 4 %)
385 %)
386
387 %( arch == "x86_64" %?
388 @define arch_syscall_prefix %( "__{ia32,x64}_" %)
389 @define arch_syscall0_prefix %( "__x64_" %)
390 @define SYSC_CLONE_CLONE_FLAGS_ARGNO %( 1 %)
391 @define SYSC_CLONE_STACK_START_ARGNO %( 2 %)
392 @define SYSC_CLONE_PARENT_TID_UADDR_ARGNO %( 3 %)
393 @define SYSC_CLONE_CHILD_TID_UADDR_ARGNO %( @__compat_task ? 5 : 4 %)
394 %)
395
396 %( arch == "arm64" %?
397 @define arch_syscall_prefix %( "__arm64_" %)
398 @define arch_syscall0_prefix %( "__arm64_" %)
399 @define SYSC_CLONE_CLONE_FLAGS_ARGNO %( 1 %)
400 @define SYSC_CLONE_STACK_START_ARGNO %( 2 %)
401 @define SYSC_CLONE_PARENT_TID_UADDR_ARGNO %( 3 %)
402 @define SYSC_CLONE_CHILD_TID_UADDR_ARGNO %( 5 %)
403 %)
404
405 %( arch == "i386" || arch == "arm" || arch == "powerpc" || arch == "mips" || arch == "riscv" %?
406 @define arch_syscall_prefix %( "" %)
407 @define arch_syscall0_prefix %( "" %)
408 @define SYSC_CLONE_CLONE_FLAGS_ARGNO %( 1 %)
409 @define SYSC_CLONE_STACK_START_ARGNO %( 2 %)
410 @define SYSC_CLONE_PARENT_TID_UADDR_ARGNO %( 3 %)
411 @define SYSC_CLONE_CHILD_TID_UADDR_ARGNO %( 5 %)
412 %)
413
414
415 @define SYSC_RETVALSTR(val)
416 %(
417 %( systemtap_v >= "4.0" %? retval = @val; %)
418 %( systemtap_v <= "4.0" %? set_returnval(@val); %)
419 retstr = return_str(1,@val);
420 %)
421
422 @define SYSC_RETVALSTR2(val)
423 %(
424 %( systemtap_v >= "4.0" %? retval = @val; %)
425 %( systemtap_v <= "4.0" %? set_returnval(@val); %)
426 retstr = return_str(2,@val);
427 %)
428
429 @define SYSC_RETVALSTR3(val)
430 %(
431 %( systemtap_v >= "4.0" %? retval = @val; %)
432 %( systemtap_v <= "4.0" %? set_returnval(@val); %)
433 retstr = return_str(3,@val);
434 %)