2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2022 Dmitry Chagin <dchagin@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 #include <sys/param.h>
31 #include <sys/ktrace.h>
37 #include <sysdecode.h>
42 #include <amd64/linux/linux.h>
43 #include <amd64/linux32/linux32_syscall.h>
45 #include <arm64/linux/linux.h>
47 #include <i386/linux/linux.h>
50 #include <compat/linux/linux.h>
51 #include <compat/linux/linux_file.h>
54 print_linux_signal(int signo)
58 signame = sysdecode_linux_signal(signo);
60 printf("%s", signame);
62 printf("SIG %d", signo);
66 ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip,
67 int *resnarg, char *resc)
69 int narg = ktr->ktr_narg;
70 register_t *ip, *first;
71 int quad_align, quad_slots;
74 ip = first = &ktr->ktr_args[0];
78 switch (ktr->ktr_code) {
79 case LINUX_SYS_linux_faccessat:
80 case LINUX_SYS_linux_fchmodat:
81 case LINUX_SYS_linux_fchownat:
82 #ifdef LINUX_SYS_linux_newfstatat
83 case LINUX_SYS_linux_newfstatat:
85 #ifdef LINUX_SYS_linux_fstatat64
86 case LINUX_SYS_linux_fstatat64:
88 #ifdef LINUX_SYS_linux_futimesat
89 case LINUX_SYS_linux_futimesat:
91 case LINUX_SYS_linux_linkat:
92 case LINUX_SYS_linux_mkdirat:
93 case LINUX_SYS_linux_mknodat:
94 case LINUX_SYS_linux_openat:
95 case LINUX_SYS_linux_readlinkat:
96 case LINUX_SYS_linux_renameat:
97 case LINUX_SYS_linux_unlinkat:
98 case LINUX_SYS_linux_utimensat:
100 print_integer_arg_valid(sysdecode_atfd, *ip);
106 switch (ktr->ktr_code) {
107 #ifdef LINUX_SYS_linux_access
108 case LINUX_SYS_linux_access:
110 case LINUX_SYS_linux_faccessat:
111 print_number(ip, narg, c);
113 print_mask_arg(sysdecode_access_mode, *ip);
117 #ifdef LINUX_SYS_linux_chmod
118 case LINUX_SYS_linux_chmod:
120 case LINUX_SYS_linux_fchmodat:
121 print_number(ip, narg, c);
123 decode_filemode(*ip);
127 case LINUX_SYS_linux_mknodat:
128 print_number(ip, narg, c);
130 decode_filemode(*ip);
134 #ifdef LINUX_SYS_linux_mkdir
135 case LINUX_SYS_linux_mkdir:
137 case LINUX_SYS_linux_mkdirat:
138 print_number(ip, narg, c);
140 decode_filemode(*ip);
144 case LINUX_SYS_linux_linkat:
145 case LINUX_SYS_linux_renameat:
146 case LINUX_SYS_linux_symlinkat:
147 print_number(ip, narg, c);
149 print_integer_arg_valid(sysdecode_atfd, *ip);
152 print_number(ip, narg, c);
154 case LINUX_SYS_linux_fchownat:
155 print_number(ip, narg, c);
156 print_number(ip, narg, c);
157 print_number(ip, narg, c);
159 #ifdef LINUX_SYS_linux_newfstatat
160 case LINUX_SYS_linux_newfstatat:
162 #ifdef LINUX_SYS_linux_fstatat64
163 case LINUX_SYS_linux_fstatat64:
165 case LINUX_SYS_linux_utimensat:
166 print_number(ip, narg, c);
167 print_number(ip, narg, c);
169 case LINUX_SYS_linux_unlinkat:
170 print_number(ip, narg, c);
172 case LINUX_SYS_linux_clock_gettime:
173 case LINUX_SYS_linux_clock_settime:
174 case LINUX_SYS_linux_clock_getres:
175 case LINUX_SYS_linux_timer_create:
177 sysdecode_linux_clockid(stdout, *ip);
182 case LINUX_SYS_linux_clock_nanosleep:
184 sysdecode_linux_clockid(stdout, *ip);
188 print_mask_arg0(sysdecode_linux_clock_flags, *ip);
193 case LINUX_SYS_linux_clone:
195 print_mask_arg(sysdecode_linux_clone_flags, *ip);
200 case LINUX_SYS_linux_kill:
201 case LINUX_SYS_linux_tkill:
202 case LINUX_SYS_linux_rt_sigqueueinfo:
203 print_decimal_number(ip, narg, c);
205 print_linux_signal(*ip);
209 case LINUX_SYS_linux_tgkill:
210 case LINUX_SYS_linux_rt_tgsigqueueinfo:
211 print_decimal_number(ip, narg, c);
212 print_decimal_number(ip, narg, c);
214 print_linux_signal(*ip);
218 #ifdef LINUX_SYS_linux_open
219 case LINUX_SYS_linux_open:
221 case LINUX_SYS_linux_openat:
222 print_number(ip, narg, c);
224 print_mask_arg(sysdecode_linux_open_flags, ip[0]);
225 if ((ip[0] & LINUX_O_CREAT) == LINUX_O_CREAT) {
227 decode_filemode(ip[1]);
232 case LINUX_SYS_linux_rt_sigaction:
234 print_linux_signal(*ip);
239 case LINUX_SYS_linux_ftruncate:
240 case LINUX_SYS_linux_truncate:
241 print_number(ip, narg, c);
242 print_number64(first, ip, narg, c);
244 case LINUX_SYS_linux_getitimer:
245 case LINUX_SYS_linux_setitimer:
247 print_integer_arg(sysdecode_itimer, *ip);
252 case LINUX_SYS_linux_rt_sigprocmask:
253 #ifdef LINUX_SYS_linux_sigprocmask
254 case LINUX_SYS_linux_sigprocmask:
257 print_integer_arg(sysdecode_linux_sigprocmask_how, *ip);
263 switch (ktr->ktr_code) {
264 case LINUX_SYS_linux_fchownat:
265 case LINUX_SYS_linux_faccessat:
266 case LINUX_SYS_linux_fchmodat:
267 #ifdef LINUX_SYS_linux_newfstatat
268 case LINUX_SYS_linux_newfstatat:
270 #ifdef LINUX_SYS_linux_fstatat64
271 case LINUX_SYS_linux_fstatat64:
273 case LINUX_SYS_linux_linkat:
274 case LINUX_SYS_linux_unlinkat:
275 case LINUX_SYS_linux_utimensat:
277 print_mask_arg0(sysdecode_linux_atflags, *ip);
287 #if defined(__amd64__)
289 ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip,
290 int *resnarg, char *resc)
292 int narg = ktr->ktr_narg;
293 register_t *ip, *first;
294 int quad_align, quad_slots;
297 ip = first = &ktr->ktr_args[0];
301 switch (ktr->ktr_code) {
302 case LINUX32_SYS_linux_faccessat:
303 case LINUX32_SYS_linux_fchmodat:
304 case LINUX32_SYS_linux_fchownat:
305 case LINUX32_SYS_linux_fstatat64:
306 case LINUX32_SYS_linux_futimesat:
307 case LINUX32_SYS_linux_linkat:
308 case LINUX32_SYS_linux_mkdirat:
309 case LINUX32_SYS_linux_mknodat:
310 case LINUX32_SYS_linux_openat:
311 case LINUX32_SYS_linux_readlinkat:
312 case LINUX32_SYS_linux_renameat:
313 case LINUX32_SYS_linux_unlinkat:
314 case LINUX32_SYS_linux_utimensat:
316 print_integer_arg_valid(sysdecode_atfd, *ip);
322 switch (ktr->ktr_code) {
323 case LINUX32_SYS_linux_access:
324 case LINUX32_SYS_linux_faccessat:
325 print_number(ip, narg, c);
327 print_mask_arg(sysdecode_access_mode, *ip);
331 case LINUX32_SYS_linux_chmod:
332 case LINUX32_SYS_fchmod:
333 case LINUX32_SYS_linux_fchmodat:
334 print_number(ip, narg, c);
336 decode_filemode(*ip);
340 case LINUX32_SYS_linux_mknodat:
341 print_number(ip, narg, c);
343 decode_filemode(*ip);
347 case LINUX32_SYS_linux_mkdir:
348 case LINUX32_SYS_linux_mkdirat:
349 print_number(ip, narg, c);
351 decode_filemode(*ip);
355 case LINUX32_SYS_linux_linkat:
356 case LINUX32_SYS_linux_renameat:
357 case LINUX32_SYS_linux_symlinkat:
358 print_number(ip, narg, c);
360 print_integer_arg_valid(sysdecode_atfd, *ip);
363 print_number(ip, narg, c);
365 case LINUX32_SYS_linux_fchownat:
366 print_number(ip, narg, c);
367 print_number(ip, narg, c);
368 print_number(ip, narg, c);
370 case LINUX32_SYS_linux_fstatat64:
371 case LINUX32_SYS_linux_utimensat:
372 print_number(ip, narg, c);
373 print_number(ip, narg, c);
375 case LINUX32_SYS_linux_unlinkat:
376 print_number(ip, narg, c);
378 case LINUX32_SYS_linux_clock_gettime:
379 case LINUX32_SYS_linux_clock_settime:
380 case LINUX32_SYS_linux_clock_getres:
381 case LINUX32_SYS_linux_timer_create:
382 case LINUX32_SYS_linux_clock_gettime64:
383 case LINUX32_SYS_linux_clock_settime64:
384 case LINUX32_SYS_linux_clock_getres_time64:
386 sysdecode_linux_clockid(stdout, *ip);
391 case LINUX32_SYS_linux_clock_nanosleep:
393 sysdecode_linux_clockid(stdout, *ip);
397 print_mask_arg0(sysdecode_linux_clock_flags, *ip);
402 case LINUX32_SYS_linux_clone:
404 print_mask_arg(sysdecode_linux_clone_flags, *ip);
409 case LINUX32_SYS_linux_kill:
410 case LINUX32_SYS_linux_tkill:
411 case LINUX32_SYS_linux_rt_sigqueueinfo:
412 print_decimal_number(ip, narg, c);
414 print_linux_signal(*ip);
418 case LINUX32_SYS_linux_tgkill:
419 case LINUX32_SYS_linux_rt_tgsigqueueinfo:
420 print_decimal_number(ip, narg, c);
421 print_decimal_number(ip, narg, c);
423 print_linux_signal(*ip);
427 case LINUX32_SYS_linux_open:
428 case LINUX32_SYS_linux_openat:
429 print_number(ip, narg, c);
431 print_mask_arg(sysdecode_linux_open_flags, ip[0]);
432 if ((ip[0] & LINUX_O_CREAT) == LINUX_O_CREAT) {
434 decode_filemode(ip[1]);
439 case LINUX32_SYS_linux_signal:
440 case LINUX32_SYS_linux_sigaction:
441 case LINUX32_SYS_linux_rt_sigaction:
443 print_linux_signal(*ip);
448 case LINUX32_SYS_linux_ftruncate:
449 case LINUX32_SYS_linux_truncate:
450 print_number(ip, narg, c);
451 print_number64(first, ip, narg, c);
453 case LINUX32_SYS_linux_getitimer:
454 case LINUX32_SYS_linux_setitimer:
456 print_integer_arg(sysdecode_itimer, *ip);
461 case LINUX32_SYS_linux_rt_sigprocmask:
462 case LINUX32_SYS_linux_sigprocmask:
464 print_integer_arg(sysdecode_linux_sigprocmask_how, *ip);
470 switch (ktr->ktr_code) {
471 case LINUX32_SYS_linux_fchownat:
472 case LINUX32_SYS_linux_faccessat:
473 case LINUX32_SYS_linux_fchmodat:
474 case LINUX32_SYS_linux_fstatat64:
475 case LINUX32_SYS_linux_linkat:
476 case LINUX32_SYS_linux_unlinkat:
477 case LINUX32_SYS_linux_utimensat:
479 print_mask_arg0(sysdecode_linux_atflags, *ip);
488 #endif /* __amd64__ */
491 ktrsigset(const char *name, const l_sigset_t *mask, size_t sz)
495 printf("%s [ ", name);
497 for (i = 1; i <= sz * CHAR_BIT; i++) {
498 if (!LINUX_SIGISMEMBER(*mask, i))
502 printf("%s", sysdecode_linux_signal(i));
512 ktrstruct_linux(const char *name, const char *data, size_t datalen)
516 if (strcmp(name, "l_sigset_t") == 0) {
517 /* Old Linux sigset_t is one word size. */
518 if (datalen < sizeof(int) || datalen > sizeof(l_sigset_t))
520 memcpy(&mask, data, datalen);
521 ktrsigset(name, &mask, datalen);