2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
33 #include <sys/ktrace.h>
39 #include <sysdecode.h>
44 #include <amd64/linux/linux.h>
45 #include <amd64/linux32/linux32_syscall.h>
47 #include <arm64/linux/linux.h>
49 #include <i386/linux/linux.h>
52 #include <compat/linux/linux.h>
53 #include <compat/linux/linux_file.h>
56 print_linux_signal(int signo)
60 signame = sysdecode_linux_signal(signo);
62 printf("%s", signame);
64 printf("SIG %d", signo);
68 ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip,
69 int *resnarg, char *resc)
71 int narg = ktr->ktr_narg;
72 register_t *ip, *first;
73 int quad_align, quad_slots;
76 ip = first = &ktr->ktr_args[0];
80 switch (ktr->ktr_code) {
81 case LINUX_SYS_linux_faccessat:
82 case LINUX_SYS_linux_fchmodat:
83 case LINUX_SYS_linux_fchownat:
84 #ifdef LINUX_SYS_linux_newfstatat
85 case LINUX_SYS_linux_newfstatat:
87 #ifdef LINUX_SYS_linux_fstatat64
88 case LINUX_SYS_linux_fstatat64:
90 #ifdef LINUX_SYS_linux_futimesat
91 case LINUX_SYS_linux_futimesat:
93 case LINUX_SYS_linux_linkat:
94 case LINUX_SYS_linux_mkdirat:
95 case LINUX_SYS_linux_mknodat:
96 case LINUX_SYS_linux_openat:
97 case LINUX_SYS_linux_readlinkat:
98 case LINUX_SYS_linux_renameat:
99 case LINUX_SYS_linux_unlinkat:
100 case LINUX_SYS_linux_utimensat:
102 print_integer_arg_valid(sysdecode_atfd, *ip);
108 switch (ktr->ktr_code) {
109 #ifdef LINUX_SYS_linux_access
110 case LINUX_SYS_linux_access:
112 case LINUX_SYS_linux_faccessat:
113 print_number(ip, narg, c);
115 print_mask_arg(sysdecode_access_mode, *ip);
119 #ifdef LINUX_SYS_linux_chmod
120 case LINUX_SYS_linux_chmod:
122 case LINUX_SYS_linux_fchmodat:
123 print_number(ip, narg, c);
125 decode_filemode(*ip);
129 case LINUX_SYS_linux_mknodat:
130 print_number(ip, narg, c);
132 decode_filemode(*ip);
136 #ifdef LINUX_SYS_linux_mkdir
137 case LINUX_SYS_linux_mkdir:
139 case LINUX_SYS_linux_mkdirat:
140 print_number(ip, narg, c);
142 decode_filemode(*ip);
146 case LINUX_SYS_linux_linkat:
147 case LINUX_SYS_linux_renameat:
148 case LINUX_SYS_linux_symlinkat:
149 print_number(ip, narg, c);
151 print_integer_arg_valid(sysdecode_atfd, *ip);
154 print_number(ip, narg, c);
156 case LINUX_SYS_linux_fchownat:
157 print_number(ip, narg, c);
158 print_number(ip, narg, c);
159 print_number(ip, narg, c);
161 #ifdef LINUX_SYS_linux_newfstatat
162 case LINUX_SYS_linux_newfstatat:
164 #ifdef LINUX_SYS_linux_fstatat64
165 case LINUX_SYS_linux_fstatat64:
167 case LINUX_SYS_linux_utimensat:
168 print_number(ip, narg, c);
169 print_number(ip, narg, c);
171 case LINUX_SYS_linux_unlinkat:
172 print_number(ip, narg, c);
174 case LINUX_SYS_linux_clock_gettime:
175 case LINUX_SYS_linux_clock_settime:
176 case LINUX_SYS_linux_clock_getres:
177 case LINUX_SYS_linux_timer_create:
179 sysdecode_linux_clockid(stdout, *ip);
184 case LINUX_SYS_linux_clock_nanosleep:
186 sysdecode_linux_clockid(stdout, *ip);
190 print_mask_arg0(sysdecode_linux_clock_flags, *ip);
195 case LINUX_SYS_linux_kill:
196 case LINUX_SYS_linux_tkill:
197 case LINUX_SYS_linux_rt_sigqueueinfo:
198 print_number(ip, narg, c);
200 print_linux_signal(*ip);
204 case LINUX_SYS_linux_tgkill:
205 case LINUX_SYS_linux_rt_tgsigqueueinfo:
206 print_number(ip, narg, c);
207 print_number(ip, narg, c);
209 print_linux_signal(*ip);
213 #ifdef LINUX_SYS_linux_open
214 case LINUX_SYS_linux_open:
216 case LINUX_SYS_linux_openat:
217 print_number(ip, narg, c);
219 print_mask_arg(sysdecode_linux_open_flags, ip[0]);
220 if ((ip[0] & LINUX_O_CREAT) == LINUX_O_CREAT) {
222 decode_filemode(ip[1]);
227 case LINUX_SYS_linux_rt_sigaction:
229 print_linux_signal(*ip);
234 case LINUX_SYS_linux_ftruncate:
235 case LINUX_SYS_linux_truncate:
236 print_number(ip, narg, c);
237 print_number64(first, ip, narg, c);
239 case LINUX_SYS_linux_getitimer:
240 case LINUX_SYS_linux_setitimer:
242 print_integer_arg(sysdecode_itimer, *ip);
247 case LINUX_SYS_linux_rt_sigprocmask:
248 #ifdef LINUX_SYS_linux_sigprocmask
249 case LINUX_SYS_linux_sigprocmask:
252 print_integer_arg(sysdecode_linux_sigprocmask_how, *ip);
258 switch (ktr->ktr_code) {
259 case LINUX_SYS_linux_fchownat:
260 case LINUX_SYS_linux_faccessat:
261 case LINUX_SYS_linux_fchmodat:
262 #ifdef LINUX_SYS_linux_newfstatat
263 case LINUX_SYS_linux_newfstatat:
265 #ifdef LINUX_SYS_linux_fstatat64
266 case LINUX_SYS_linux_fstatat64:
268 case LINUX_SYS_linux_linkat:
269 case LINUX_SYS_linux_unlinkat:
270 case LINUX_SYS_linux_utimensat:
272 print_mask_arg0(sysdecode_linux_atflags, *ip);
282 #if defined(__amd64__)
284 ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip,
285 int *resnarg, char *resc)
287 int narg = ktr->ktr_narg;
288 register_t *ip, *first;
289 int quad_align, quad_slots;
292 ip = first = &ktr->ktr_args[0];
296 switch (ktr->ktr_code) {
297 case LINUX32_SYS_linux_faccessat:
298 case LINUX32_SYS_linux_fchmodat:
299 case LINUX32_SYS_linux_fchownat:
300 case LINUX32_SYS_linux_fstatat64:
301 case LINUX32_SYS_linux_futimesat:
302 case LINUX32_SYS_linux_linkat:
303 case LINUX32_SYS_linux_mkdirat:
304 case LINUX32_SYS_linux_mknodat:
305 case LINUX32_SYS_linux_openat:
306 case LINUX32_SYS_linux_readlinkat:
307 case LINUX32_SYS_linux_renameat:
308 case LINUX32_SYS_linux_unlinkat:
309 case LINUX32_SYS_linux_utimensat:
311 print_integer_arg_valid(sysdecode_atfd, *ip);
317 switch (ktr->ktr_code) {
318 case LINUX32_SYS_linux_access:
319 case LINUX32_SYS_linux_faccessat:
320 print_number(ip, narg, c);
322 print_mask_arg(sysdecode_access_mode, *ip);
326 case LINUX32_SYS_linux_chmod:
327 case LINUX32_SYS_fchmod:
328 case LINUX32_SYS_linux_fchmodat:
329 print_number(ip, narg, c);
331 decode_filemode(*ip);
335 case LINUX32_SYS_linux_mknodat:
336 print_number(ip, narg, c);
338 decode_filemode(*ip);
342 case LINUX32_SYS_linux_mkdir:
343 case LINUX32_SYS_linux_mkdirat:
344 print_number(ip, narg, c);
346 decode_filemode(*ip);
350 case LINUX32_SYS_linux_linkat:
351 case LINUX32_SYS_linux_renameat:
352 case LINUX32_SYS_linux_symlinkat:
353 print_number(ip, narg, c);
355 print_integer_arg_valid(sysdecode_atfd, *ip);
358 print_number(ip, narg, c);
360 case LINUX32_SYS_linux_fchownat:
361 print_number(ip, narg, c);
362 print_number(ip, narg, c);
363 print_number(ip, narg, c);
365 case LINUX32_SYS_linux_fstatat64:
366 case LINUX32_SYS_linux_utimensat:
367 print_number(ip, narg, c);
368 print_number(ip, narg, c);
370 case LINUX32_SYS_linux_unlinkat:
371 print_number(ip, narg, c);
373 case LINUX32_SYS_linux_clock_gettime:
374 case LINUX32_SYS_linux_clock_settime:
375 case LINUX32_SYS_linux_clock_getres:
376 case LINUX32_SYS_linux_timer_create:
377 case LINUX32_SYS_linux_clock_gettime64:
378 case LINUX32_SYS_linux_clock_settime64:
379 case LINUX32_SYS_linux_clock_getres_time64:
381 sysdecode_linux_clockid(stdout, *ip);
386 case LINUX32_SYS_linux_clock_nanosleep:
388 sysdecode_linux_clockid(stdout, *ip);
392 print_mask_arg0(sysdecode_linux_clock_flags, *ip);
397 case LINUX32_SYS_linux_kill:
398 case LINUX32_SYS_linux_tkill:
399 case LINUX32_SYS_linux_rt_sigqueueinfo:
400 print_number(ip, narg, c);
402 print_linux_signal(*ip);
406 case LINUX32_SYS_linux_tgkill:
407 case LINUX32_SYS_linux_rt_tgsigqueueinfo:
408 print_number(ip, narg, c);
409 print_number(ip, narg, c);
411 print_linux_signal(*ip);
415 case LINUX32_SYS_linux_open:
416 case LINUX32_SYS_linux_openat:
417 print_number(ip, narg, c);
419 print_mask_arg(sysdecode_linux_open_flags, ip[0]);
420 if ((ip[0] & LINUX_O_CREAT) == LINUX_O_CREAT) {
422 decode_filemode(ip[1]);
427 case LINUX32_SYS_linux_signal:
428 case LINUX32_SYS_linux_sigaction:
429 case LINUX32_SYS_linux_rt_sigaction:
431 print_linux_signal(*ip);
436 case LINUX32_SYS_linux_ftruncate:
437 case LINUX32_SYS_linux_truncate:
438 print_number(ip, narg, c);
439 print_number64(first, ip, narg, c);
441 case LINUX32_SYS_linux_getitimer:
442 case LINUX32_SYS_linux_setitimer:
444 print_integer_arg(sysdecode_itimer, *ip);
449 case LINUX32_SYS_linux_rt_sigprocmask:
450 case LINUX32_SYS_linux_sigprocmask:
452 print_integer_arg(sysdecode_linux_sigprocmask_how, *ip);
458 switch (ktr->ktr_code) {
459 case LINUX32_SYS_linux_fchownat:
460 case LINUX32_SYS_linux_faccessat:
461 case LINUX32_SYS_linux_fchmodat:
462 case LINUX32_SYS_linux_fstatat64:
463 case LINUX32_SYS_linux_linkat:
464 case LINUX32_SYS_linux_unlinkat:
465 case LINUX32_SYS_linux_utimensat:
467 print_mask_arg0(sysdecode_linux_atflags, *ip);
476 #endif /* __amd64__ */
479 ktrsigset(const char *name, const l_sigset_t *mask, size_t sz)
483 printf("%s [ ", name);
485 for (i = 1; i <= sz * CHAR_BIT; i++) {
486 if (!LINUX_SIGISMEMBER(*mask, i))
490 printf("%s", sysdecode_linux_signal(i));
500 ktrstruct_linux(const char *name, const char *data, size_t datalen)
504 if (strcmp(name, "l_sigset_t") == 0) {
505 /* Old Linux sigset_t is one word size. */
506 if (datalen < sizeof(int) || datalen > sizeof(l_sigset_t))
508 memcpy(&mask, data, datalen);
509 ktrsigset(name, &mask, datalen);