1df57947fSPedro F. Giffuni /*-
2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
3df57947fSPedro F. Giffuni *
40a6c71f8SWarner Losh * Copyright 1997 Sean Eric Fagan
509d64da3SSean Eric Fagan *
609d64da3SSean Eric Fagan * Redistribution and use in source and binary forms, with or without
709d64da3SSean Eric Fagan * modification, are permitted provided that the following conditions
809d64da3SSean Eric Fagan * are met:
909d64da3SSean Eric Fagan * 1. Redistributions of source code must retain the above copyright
1009d64da3SSean Eric Fagan * notice, this list of conditions and the following disclaimer.
1109d64da3SSean Eric Fagan * 2. Redistributions in binary form must reproduce the above copyright
1209d64da3SSean Eric Fagan * notice, this list of conditions and the following disclaimer in the
1309d64da3SSean Eric Fagan * documentation and/or other materials provided with the distribution.
1409d64da3SSean Eric Fagan * 3. All advertising materials mentioning features or use of this software
1509d64da3SSean Eric Fagan * must display the following acknowledgement:
1609d64da3SSean Eric Fagan * This product includes software developed by Sean Eric Fagan
1709d64da3SSean Eric Fagan * 4. Neither the name of the author may be used to endorse or promote
1809d64da3SSean Eric Fagan * products derived from this software without specific prior written
1909d64da3SSean Eric Fagan * permission.
2009d64da3SSean Eric Fagan *
2109d64da3SSean Eric Fagan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2209d64da3SSean Eric Fagan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2309d64da3SSean Eric Fagan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2409d64da3SSean Eric Fagan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2509d64da3SSean Eric Fagan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2609d64da3SSean Eric Fagan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2709d64da3SSean Eric Fagan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2809d64da3SSean Eric Fagan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2909d64da3SSean Eric Fagan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3009d64da3SSean Eric Fagan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3109d64da3SSean Eric Fagan * SUCH DAMAGE.
3209d64da3SSean Eric Fagan */
3309d64da3SSean Eric Fagan
342b75c8adSJohn Baldwin #include <sys/cdefs.h>
3509d64da3SSean Eric Fagan /*
36bbeaf6c0SSean Eric Fagan * This file has routines used to print out system calls and their
37bbeaf6c0SSean Eric Fagan * arguments.
38bbeaf6c0SSean Eric Fagan */
39bbeaf6c0SSean Eric Fagan
40bb24ee2bSThomas Munro #include <sys/aio.h>
417136a1d9SJohn Baldwin #include <sys/capsicum.h>
429ddd1412SDag-Erling Smørgrav #include <sys/types.h>
43ffb66079SJohn Baldwin #define _WANT_FREEBSD11_KEVENT
442b75c8adSJohn Baldwin #include <sys/event.h>
452b75c8adSJohn Baldwin #include <sys/ioccom.h>
465b05dc5aSThomas Munro #include <sys/mman.h>
47a776866bSBryan Drewery #include <sys/mount.h>
486019514bSAlex Richardson #include <sys/poll.h>
4931dddc6aSAlex Richardson #include <sys/procfs.h>
505d2d083cSXin LI #include <sys/ptrace.h>
512b75c8adSJohn Baldwin #include <sys/resource.h>
526019514bSAlex Richardson #include <sys/sched.h>
539ddd1412SDag-Erling Smørgrav #include <sys/socket.h>
548207f12dSWarner Losh #define _WANT_FREEBSD11_STAT
552b75c8adSJohn Baldwin #include <sys/stat.h>
5643ce0d90SKonstantin Belousov #include <sys/sysctl.h>
576040822cSAlan Somers #include <sys/time.h>
589ddd1412SDag-Erling Smørgrav #include <sys/un.h>
5934763d1cSJohn Baldwin #include <sys/wait.h>
609ddd1412SDag-Erling Smørgrav #include <netinet/in.h>
614d7b9809SMichael Tuexen #include <netinet/sctp.h>
629ddd1412SDag-Erling Smørgrav #include <arpa/inet.h>
639ddd1412SDag-Erling Smørgrav
641175b23fSJohn Baldwin #include <assert.h>
65dec17687SBrian Feldman #include <ctype.h>
663cf51049SPhilippe Charnier #include <err.h>
67caa449b6SJohn Baldwin #define _WANT_KERNEL_ERRNO
68caa449b6SJohn Baldwin #include <errno.h>
69894b8f7aSAlfred Perlstein #include <fcntl.h>
709ddd1412SDag-Erling Smørgrav #include <signal.h>
71808d9805SEd Schouten #include <stdbool.h>
72cf0ee873SKonstantin Belousov #include <stddef.h>
73bbeaf6c0SSean Eric Fagan #include <stdio.h>
74bbeaf6c0SSean Eric Fagan #include <stdlib.h>
75bbeaf6c0SSean Eric Fagan #include <string.h>
76d6fb4894SJohn Baldwin #include <sysdecode.h>
77bbeaf6c0SSean Eric Fagan #include <unistd.h>
78081e5c48SPav Lucistnik #include <vis.h>
799ddd1412SDag-Erling Smørgrav
80ec0bed25SMatthew N. Dodd #include "truss.h"
811be5d704SMark Murray #include "extern.h"
82bbeaf6c0SSean Eric Fagan #include "syscall.h"
83bbeaf6c0SSean Eric Fagan
84bbeaf6c0SSean Eric Fagan /*
85081e5c48SPav Lucistnik * This should probably be in its own file, sorted alphabetically.
866019514bSAlex Richardson *
876019514bSAlex Richardson * Note: We only scan this table on the initial syscall number to calling
886019514bSAlex Richardson * convention lookup, i.e. once each time a new syscall is encountered. This
896019514bSAlex Richardson * is unlikely to be a performance issue, but if it is we could sort this array
906019514bSAlex Richardson * and use a binary search instead.
91bbeaf6c0SSean Eric Fagan */
926019514bSAlex Richardson static const struct syscall_decode decoded_syscalls[] = {
93f44fc79dSJohn Baldwin /* Native ABI */
947ce44f08SJohn Baldwin { .name = "__acl_aclcheck_fd", .ret_type = 1, .nargs = 3,
957ce44f08SJohn Baldwin .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
967ce44f08SJohn Baldwin { .name = "__acl_aclcheck_file", .ret_type = 1, .nargs = 3,
977ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
987ce44f08SJohn Baldwin { .name = "__acl_aclcheck_link", .ret_type = 1, .nargs = 3,
997ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1007ce44f08SJohn Baldwin { .name = "__acl_delete_fd", .ret_type = 1, .nargs = 2,
1017ce44f08SJohn Baldwin .args = { { Int, 0 }, { Acltype, 1 } } },
1027ce44f08SJohn Baldwin { .name = "__acl_delete_file", .ret_type = 1, .nargs = 2,
1037ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 } } },
1047ce44f08SJohn Baldwin { .name = "__acl_delete_link", .ret_type = 1, .nargs = 2,
1057ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 } } },
1067ce44f08SJohn Baldwin { .name = "__acl_get_fd", .ret_type = 1, .nargs = 3,
1077ce44f08SJohn Baldwin .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1087ce44f08SJohn Baldwin { .name = "__acl_get_file", .ret_type = 1, .nargs = 3,
1097ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1107ce44f08SJohn Baldwin { .name = "__acl_get_link", .ret_type = 1, .nargs = 3,
1117ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1127ce44f08SJohn Baldwin { .name = "__acl_set_fd", .ret_type = 1, .nargs = 3,
1137ce44f08SJohn Baldwin .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1147ce44f08SJohn Baldwin { .name = "__acl_set_file", .ret_type = 1, .nargs = 3,
1157ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1167ce44f08SJohn Baldwin { .name = "__acl_set_link", .ret_type = 1, .nargs = 3,
1177ce44f08SJohn Baldwin .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1187136a1d9SJohn Baldwin { .name = "__cap_rights_get", .ret_type = 1, .nargs = 3,
1197136a1d9SJohn Baldwin .args = { { Int, 0 }, { Int, 1 }, { CapRights | OUT, 2 } } },
120f44fc79dSJohn Baldwin { .name = "__getcwd", .ret_type = 1, .nargs = 2,
121f44fc79dSJohn Baldwin .args = { { Name | OUT, 0 }, { Int, 1 } } },
1220573d0a9SMateusz Guzik { .name = "__realpathat", .ret_type = 1, .nargs = 5,
1230573d0a9SMateusz Guzik .args = { { Atfd, 0 }, { Name | IN, 1 }, { Name | OUT, 2 },
1240573d0a9SMateusz Guzik { Sizet, 3 }, { Int, 4} } },
125f44fc79dSJohn Baldwin { .name = "_umtx_op", .ret_type = 1, .nargs = 5,
126f44fc79dSJohn Baldwin .args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 },
127f44fc79dSJohn Baldwin { Ptr, 4 } } },
128f44fc79dSJohn Baldwin { .name = "accept", .ret_type = 1, .nargs = 3,
129f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
130f44fc79dSJohn Baldwin { .name = "access", .ret_type = 1, .nargs = 2,
131f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Accessmode, 1 } } },
132bb24ee2bSThomas Munro { .name = "aio_cancel", .ret_type = 1, .nargs = 2,
133bb24ee2bSThomas Munro .args = { { Int, 0 }, { Aiocb, 1 } } },
134bb24ee2bSThomas Munro { .name = "aio_error", .ret_type = 1, .nargs = 1,
135bb24ee2bSThomas Munro .args = { { Aiocb, 0 } } },
136bb24ee2bSThomas Munro { .name = "aio_fsync", .ret_type = 1, .nargs = 2,
137bb24ee2bSThomas Munro .args = { { AiofsyncOp, 0 }, { Aiocb, 1 } } },
138bb24ee2bSThomas Munro { .name = "aio_mlock", .ret_type = 1, .nargs = 1,
139bb24ee2bSThomas Munro .args = { { Aiocb, 0 } } },
140bb24ee2bSThomas Munro { .name = "aio_read", .ret_type = 1, .nargs = 1,
141bb24ee2bSThomas Munro .args = { { Aiocb, 0 } } },
142bb24ee2bSThomas Munro { .name = "aio_return", .ret_type = 1, .nargs = 1,
143bb24ee2bSThomas Munro .args = { { Aiocb, 0 } } },
144bb24ee2bSThomas Munro { .name = "aio_suspend", .ret_type = 1, .nargs = 3,
145bb24ee2bSThomas Munro .args = { { AiocbArray, 0 }, { Int, 1 }, { Timespec, 2 } } },
146bb24ee2bSThomas Munro { .name = "aio_waitcomplete", .ret_type = 1, .nargs = 2,
147bb24ee2bSThomas Munro .args = { { AiocbPointer | OUT, 0 }, { Timespec, 1 } } },
148bb24ee2bSThomas Munro { .name = "aio_write", .ret_type = 1, .nargs = 1,
149bb24ee2bSThomas Munro .args = { { Aiocb, 0 } } },
150f44fc79dSJohn Baldwin { .name = "bind", .ret_type = 1, .nargs = 3,
15158227c60SMichael Tuexen .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Socklent, 2 } } },
152f44fc79dSJohn Baldwin { .name = "bindat", .ret_type = 1, .nargs = 4,
153f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
1547d897327SJohn Baldwin { Int, 3 } } },
155f44fc79dSJohn Baldwin { .name = "break", .ret_type = 1, .nargs = 1,
156f44fc79dSJohn Baldwin .args = { { Ptr, 0 } } },
157bed418c8SJohn Baldwin { .name = "cap_fcntls_get", .ret_type = 1, .nargs = 2,
158bed418c8SJohn Baldwin .args = { { Int, 0 }, { CapFcntlRights | OUT, 1 } } },
159bed418c8SJohn Baldwin { .name = "cap_fcntls_limit", .ret_type = 1, .nargs = 2,
160bed418c8SJohn Baldwin .args = { { Int, 0 }, { CapFcntlRights, 1 } } },
161ebb2cc40SJohn Baldwin { .name = "cap_getmode", .ret_type = 1, .nargs = 1,
162ebb2cc40SJohn Baldwin .args = { { PUInt | OUT, 0 } } },
1637136a1d9SJohn Baldwin { .name = "cap_rights_limit", .ret_type = 1, .nargs = 2,
1647136a1d9SJohn Baldwin .args = { { Int, 0 }, { CapRights, 1 } } },
165f44fc79dSJohn Baldwin { .name = "chdir", .ret_type = 1, .nargs = 1,
166f44fc79dSJohn Baldwin .args = { { Name, 0 } } },
167f44fc79dSJohn Baldwin { .name = "chflags", .ret_type = 1, .nargs = 2,
16827459358SJohn Baldwin .args = { { Name | IN, 0 }, { FileFlags, 1 } } },
16927459358SJohn Baldwin { .name = "chflagsat", .ret_type = 1, .nargs = 4,
17027459358SJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { FileFlags, 2 },
17127459358SJohn Baldwin { Atflags, 3 } } },
172f44fc79dSJohn Baldwin { .name = "chmod", .ret_type = 1, .nargs = 2,
173ee3b0f6eSDiomidis Spinellis .args = { { Name, 0 }, { Octal, 1 } } },
174f44fc79dSJohn Baldwin { .name = "chown", .ret_type = 1, .nargs = 3,
175f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
176f44fc79dSJohn Baldwin { .name = "chroot", .ret_type = 1, .nargs = 1,
177f44fc79dSJohn Baldwin .args = { { Name, 0 } } },
178f44fc79dSJohn Baldwin { .name = "clock_gettime", .ret_type = 1, .nargs = 2,
179f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Timespec | OUT, 1 } } },
180ee3b0f6eSDiomidis Spinellis { .name = "close", .ret_type = 1, .nargs = 1,
181ee3b0f6eSDiomidis Spinellis .args = { { Int, 0 } } },
1827be2c6f3SChristian S.J. Peron { .name = "closefrom", .ret_type = 1, .nargs = 1,
1837be2c6f3SChristian S.J. Peron .args = { { Int, 0 } } },
184f3f3e3c4SMateusz Guzik { .name = "close_range", .ret_type = 1, .nargs = 3,
185f3f3e3c4SMateusz Guzik .args = { { Int, 0 }, { Int, 1 }, { Closerangeflags, 2 } } },
1861b224b09SWarner Losh { .name = "compat11.fstat", .ret_type = 1, .nargs = 2,
1871b224b09SWarner Losh .args = { { Int, 0 }, { Stat11 | OUT, 1 } } },
18875a14d22SMark Johnston { .name = "compat11.fstatat", .ret_type = 1, .nargs = 4,
18975a14d22SMark Johnston .args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat11 | OUT, 2 },
19075a14d22SMark Johnston { Atflags, 3 } } },
191ffb66079SJohn Baldwin { .name = "compat11.kevent", .ret_type = 1, .nargs = 6,
192ffb66079SJohn Baldwin .args = { { Int, 0 }, { Kevent11, 1 }, { Int, 2 },
193ffb66079SJohn Baldwin { Kevent11 | OUT, 3 }, { Int, 4 }, { Timespec, 5 } } },
1941b224b09SWarner Losh { .name = "compat11.lstat", .ret_type = 1, .nargs = 2,
1951b224b09SWarner Losh .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } },
196cd497bd4SMark Johnston { .name = "compat11.mknod", .ret_type = 1, .nargs = 3,
197cd497bd4SMark Johnston .args = { { Name, 0 }, { Octal, 1 }, { Int, 2 } } },
198cd497bd4SMark Johnston { .name = "compat11.mknodat", .ret_type = 1, .nargs = 4,
199cd497bd4SMark Johnston .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Int, 3 } } },
2001b224b09SWarner Losh { .name = "compat11.stat", .ret_type = 1, .nargs = 2,
2011b224b09SWarner Losh .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } },
202f44fc79dSJohn Baldwin { .name = "connect", .ret_type = 1, .nargs = 3,
20358227c60SMichael Tuexen .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Socklent, 2 } } },
204f44fc79dSJohn Baldwin { .name = "connectat", .ret_type = 1, .nargs = 4,
205f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
206f44fc79dSJohn Baldwin { Int, 3 } } },
207b60a095bSJohn Baldwin { .name = "dup", .ret_type = 1, .nargs = 1,
208b60a095bSJohn Baldwin .args = { { Int, 0 } } },
209b60a095bSJohn Baldwin { .name = "dup2", .ret_type = 1, .nargs = 2,
210b60a095bSJohn Baldwin .args = { { Int, 0 }, { Int, 1 } } },
211f44fc79dSJohn Baldwin { .name = "eaccess", .ret_type = 1, .nargs = 2,
212f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Accessmode, 1 } } },
213f44fc79dSJohn Baldwin { .name = "execve", .ret_type = 1, .nargs = 3,
214f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
215f44fc79dSJohn Baldwin { ExecEnv | IN, 2 } } },
216f44fc79dSJohn Baldwin { .name = "exit", .ret_type = 0, .nargs = 1,
217f44fc79dSJohn Baldwin .args = { { Hex, 0 } } },
21826606dcaSJohn Baldwin { .name = "extattr_delete_fd", .ret_type = 1, .nargs = 3,
21926606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
22026606dcaSJohn Baldwin { .name = "extattr_delete_file", .ret_type = 1, .nargs = 3,
22126606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
22226606dcaSJohn Baldwin { .name = "extattr_delete_link", .ret_type = 1, .nargs = 3,
22326606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
22426606dcaSJohn Baldwin { .name = "extattr_get_fd", .ret_type = 1, .nargs = 5,
22526606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
22626606dcaSJohn Baldwin { BinString | OUT, 3 }, { Sizet, 4 } } },
22726606dcaSJohn Baldwin { .name = "extattr_get_file", .ret_type = 1, .nargs = 5,
22826606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
22926606dcaSJohn Baldwin { BinString | OUT, 3 }, { Sizet, 4 } } },
23026606dcaSJohn Baldwin { .name = "extattr_get_link", .ret_type = 1, .nargs = 5,
23126606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
23226606dcaSJohn Baldwin { BinString | OUT, 3 }, { Sizet, 4 } } },
23326606dcaSJohn Baldwin { .name = "extattr_list_fd", .ret_type = 1, .nargs = 4,
23426606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
23526606dcaSJohn Baldwin { Sizet, 3 } } },
23626606dcaSJohn Baldwin { .name = "extattr_list_file", .ret_type = 1, .nargs = 4,
23726606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
23826606dcaSJohn Baldwin { Sizet, 3 } } },
23926606dcaSJohn Baldwin { .name = "extattr_list_link", .ret_type = 1, .nargs = 4,
24026606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
24126606dcaSJohn Baldwin { Sizet, 3 } } },
24226606dcaSJohn Baldwin { .name = "extattr_set_fd", .ret_type = 1, .nargs = 5,
24326606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
24426606dcaSJohn Baldwin { BinString | IN, 3 }, { Sizet, 4 } } },
24526606dcaSJohn Baldwin { .name = "extattr_set_file", .ret_type = 1, .nargs = 5,
24626606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
24726606dcaSJohn Baldwin { BinString | IN, 3 }, { Sizet, 4 } } },
24826606dcaSJohn Baldwin { .name = "extattr_set_link", .ret_type = 1, .nargs = 5,
24926606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
25026606dcaSJohn Baldwin { BinString | IN, 3 }, { Sizet, 4 } } },
25126606dcaSJohn Baldwin { .name = "extattrctl", .ret_type = 1, .nargs = 5,
25226606dcaSJohn Baldwin .args = { { Name, 0 }, { Hex, 1 }, { Name, 2 },
25326606dcaSJohn Baldwin { Extattrnamespace, 3 }, { Name, 4 } } },
254f44fc79dSJohn Baldwin { .name = "faccessat", .ret_type = 1, .nargs = 4,
255f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Accessmode, 2 },
256f44fc79dSJohn Baldwin { Atflags, 3 } } },
25727459358SJohn Baldwin { .name = "fchflags", .ret_type = 1, .nargs = 2,
25827459358SJohn Baldwin .args = { { Int, 0 }, { FileFlags, 1 } } },
259f44fc79dSJohn Baldwin { .name = "fchmod", .ret_type = 1, .nargs = 2,
260f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Octal, 1 } } },
261f44fc79dSJohn Baldwin { .name = "fchmodat", .ret_type = 1, .nargs = 4,
262f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Atflags, 3 } } },
263f44fc79dSJohn Baldwin { .name = "fchown", .ret_type = 1, .nargs = 3,
264f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
265f44fc79dSJohn Baldwin { .name = "fchownat", .ret_type = 1, .nargs = 5,
266f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Int, 2 }, { Int, 3 },
267f44fc79dSJohn Baldwin { Atflags, 4 } } },
268f44fc79dSJohn Baldwin { .name = "fcntl", .ret_type = 1, .nargs = 3,
269f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } },
270b5eab9d4SThomas Munro { .name = "fdatasync", .ret_type = 1, .nargs = 1,
271b5eab9d4SThomas Munro .args = { { Int, 0 } } },
272dd92181fSJohn Baldwin { .name = "flock", .ret_type = 1, .nargs = 2,
273dd92181fSJohn Baldwin .args = { { Int, 0 }, { Flockop, 1 } } },
274f44fc79dSJohn Baldwin { .name = "fstat", .ret_type = 1, .nargs = 2,
275f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Stat | OUT, 1 } } },
276f44fc79dSJohn Baldwin { .name = "fstatat", .ret_type = 1, .nargs = 4,
277f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat | OUT, 2 },
278f44fc79dSJohn Baldwin { Atflags, 3 } } },
279f44fc79dSJohn Baldwin { .name = "fstatfs", .ret_type = 1, .nargs = 2,
280f44fc79dSJohn Baldwin .args = { { Int, 0 }, { StatFs | OUT, 1 } } },
281b5eab9d4SThomas Munro { .name = "fsync", .ret_type = 1, .nargs = 1,
282b5eab9d4SThomas Munro .args = { { Int, 0 } } },
283f44fc79dSJohn Baldwin { .name = "ftruncate", .ret_type = 1, .nargs = 2,
284c05cc0d6SJohn Baldwin .args = { { Int | IN, 0 }, { QuadHex | IN, 1 } } },
285f44fc79dSJohn Baldwin { .name = "futimens", .ret_type = 1, .nargs = 2,
286f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Timespec2 | IN, 1 } } },
287f44fc79dSJohn Baldwin { .name = "futimes", .ret_type = 1, .nargs = 2,
288f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Timeval2 | IN, 1 } } },
289f44fc79dSJohn Baldwin { .name = "futimesat", .ret_type = 1, .nargs = 3,
290f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timeval2 | IN, 2 } } },
291b60a095bSJohn Baldwin { .name = "getdirentries", .ret_type = 1, .nargs = 4,
292b60a095bSJohn Baldwin .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 },
293b60a095bSJohn Baldwin { PQuadHex | OUT, 3 } } },
294ab43bedcSJohn Baldwin { .name = "getfsstat", .ret_type = 1, .nargs = 3,
295ab43bedcSJohn Baldwin .args = { { Ptr, 0 }, { Long, 1 }, { Getfsstatmode, 2 } } },
296f44fc79dSJohn Baldwin { .name = "getitimer", .ret_type = 1, .nargs = 2,
297b9b86b67SDmitry Chagin .args = { { Itimerwhich, 0 }, { Itimerval | OUT, 2 } } },
298f44fc79dSJohn Baldwin { .name = "getpeername", .ret_type = 1, .nargs = 3,
299f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
300f44fc79dSJohn Baldwin { .name = "getpgid", .ret_type = 1, .nargs = 1,
301f44fc79dSJohn Baldwin .args = { { Int, 0 } } },
302ad419d33SJohn Baldwin { .name = "getpriority", .ret_type = 1, .nargs = 2,
303ad419d33SJohn Baldwin .args = { { Priowhich, 0 }, { Int, 1 } } },
304e9ac2743SConrad Meyer { .name = "getrandom", .ret_type = 1, .nargs = 3,
305e9ac2743SConrad Meyer .args = { { BinString | OUT, 0 }, { Sizet, 1 }, { UInt, 2 } } },
306f44fc79dSJohn Baldwin { .name = "getrlimit", .ret_type = 1, .nargs = 2,
307f44fc79dSJohn Baldwin .args = { { Resource, 0 }, { Rlimit | OUT, 1 } } },
308f44fc79dSJohn Baldwin { .name = "getrusage", .ret_type = 1, .nargs = 2,
309ee8aa41dSJohn Baldwin .args = { { RusageWho, 0 }, { Rusage | OUT, 1 } } },
310f44fc79dSJohn Baldwin { .name = "getsid", .ret_type = 1, .nargs = 1,
311f44fc79dSJohn Baldwin .args = { { Int, 0 } } },
312f44fc79dSJohn Baldwin { .name = "getsockname", .ret_type = 1, .nargs = 3,
313f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
314832af457SMichael Tuexen { .name = "getsockopt", .ret_type = 1, .nargs = 5,
315832af457SMichael Tuexen .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 },
316832af457SMichael Tuexen { Ptr | OUT, 3 }, { Ptr | OUT, 4 } } },
317f44fc79dSJohn Baldwin { .name = "gettimeofday", .ret_type = 1, .nargs = 2,
318f44fc79dSJohn Baldwin .args = { { Timeval | OUT, 0 }, { Ptr, 1 } } },
319f44fc79dSJohn Baldwin { .name = "ioctl", .ret_type = 1, .nargs = 3,
320a776eeafSJohn Baldwin .args = { { Int, 0 }, { Ioctl, 1 }, { Ptr, 2 } } },
321f44fc79dSJohn Baldwin { .name = "kevent", .ret_type = 1, .nargs = 6,
322f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 },
323f44fc79dSJohn Baldwin { Int, 4 }, { Timespec, 5 } } },
324f44fc79dSJohn Baldwin { .name = "kill", .ret_type = 1, .nargs = 2,
325f44fc79dSJohn Baldwin .args = { { Int | IN, 0 }, { Signal | IN, 1 } } },
326f44fc79dSJohn Baldwin { .name = "kldfind", .ret_type = 1, .nargs = 1,
327f44fc79dSJohn Baldwin .args = { { Name | IN, 0 } } },
328f44fc79dSJohn Baldwin { .name = "kldfirstmod", .ret_type = 1, .nargs = 1,
329f44fc79dSJohn Baldwin .args = { { Int, 0 } } },
330f44fc79dSJohn Baldwin { .name = "kldload", .ret_type = 1, .nargs = 1,
331f44fc79dSJohn Baldwin .args = { { Name | IN, 0 } } },
332f44fc79dSJohn Baldwin { .name = "kldnext", .ret_type = 1, .nargs = 1,
333f44fc79dSJohn Baldwin .args = { { Int, 0 } } },
334f44fc79dSJohn Baldwin { .name = "kldstat", .ret_type = 1, .nargs = 2,
335f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Ptr, 1 } } },
33694e854c5SJohn Baldwin { .name = "kldsym", .ret_type = 1, .nargs = 3,
33794e854c5SJohn Baldwin .args = { { Int, 0 }, { Kldsymcmd, 1 }, { Ptr, 2 } } },
338f44fc79dSJohn Baldwin { .name = "kldunload", .ret_type = 1, .nargs = 1,
339f44fc79dSJohn Baldwin .args = { { Int, 0 } } },
34094e854c5SJohn Baldwin { .name = "kldunloadf", .ret_type = 1, .nargs = 2,
34194e854c5SJohn Baldwin .args = { { Int, 0 }, { Kldunloadflags, 1 } } },
342f44fc79dSJohn Baldwin { .name = "kse_release", .ret_type = 0, .nargs = 1,
343f44fc79dSJohn Baldwin .args = { { Timespec, 0 } } },
344f44fc79dSJohn Baldwin { .name = "lchflags", .ret_type = 1, .nargs = 2,
34527459358SJohn Baldwin .args = { { Name | IN, 0 }, { FileFlags, 1 } } },
346f44fc79dSJohn Baldwin { .name = "lchmod", .ret_type = 1, .nargs = 2,
347f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 } } },
348f44fc79dSJohn Baldwin { .name = "lchown", .ret_type = 1, .nargs = 3,
349f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
3502b75c8adSJohn Baldwin { .name = "link", .ret_type = 1, .nargs = 2,
351ee3b0f6eSDiomidis Spinellis .args = { { Name, 0 }, { Name, 1 } } },
3522b75c8adSJohn Baldwin { .name = "linkat", .ret_type = 1, .nargs = 5,
3537d897327SJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 },
3547d897327SJohn Baldwin { Atflags, 4 } } },
355bb24ee2bSThomas Munro { .name = "lio_listio", .ret_type = 1, .nargs = 4,
356bb24ee2bSThomas Munro .args = { { LioMode, 0 }, { AiocbArray, 1 }, { Int, 2 },
357bb24ee2bSThomas Munro { Sigevent, 3 } } },
358e8d2c81dSMichael Tuexen { .name = "listen", .ret_type = 1, .nargs = 2,
359e8d2c81dSMichael Tuexen .args = { { Int, 0 }, { Int, 1 } } },
360f44fc79dSJohn Baldwin { .name = "lseek", .ret_type = 2, .nargs = 3,
361c05cc0d6SJohn Baldwin .args = { { Int, 0 }, { QuadHex, 1 }, { Whence, 2 } } },
362f44fc79dSJohn Baldwin { .name = "lstat", .ret_type = 1, .nargs = 2,
363f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
364f44fc79dSJohn Baldwin { .name = "lutimes", .ret_type = 1, .nargs = 2,
365f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
36698fdbeecSJohn Baldwin { .name = "madvise", .ret_type = 1, .nargs = 3,
36798fdbeecSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Madvice, 2 } } },
3682d9c9988SJohn Baldwin { .name = "minherit", .ret_type = 1, .nargs = 3,
3692d9c9988SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Minherit, 2 } } },
370f44fc79dSJohn Baldwin { .name = "mkdir", .ret_type = 1, .nargs = 2,
371f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 } } },
372f44fc79dSJohn Baldwin { .name = "mkdirat", .ret_type = 1, .nargs = 3,
373f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
3742b75c8adSJohn Baldwin { .name = "mkfifo", .ret_type = 1, .nargs = 2,
375e82ce59cSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 } } },
3762b75c8adSJohn Baldwin { .name = "mkfifoat", .ret_type = 1, .nargs = 3,
3777d897327SJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
3782b75c8adSJohn Baldwin { .name = "mknod", .ret_type = 1, .nargs = 3,
379cd497bd4SMark Johnston .args = { { Name, 0 }, { Octal, 1 }, { Quad, 2 } } },
3802b75c8adSJohn Baldwin { .name = "mknodat", .ret_type = 1, .nargs = 4,
381cd497bd4SMark Johnston .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Quad, 3 } } },
38294bde755SJohn Baldwin { .name = "mlock", .ret_type = 1, .nargs = 2,
38394bde755SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 } } },
38494bde755SJohn Baldwin { .name = "mlockall", .ret_type = 1, .nargs = 1,
38594bde755SJohn Baldwin .args = { { Mlockall, 0 } } },
386f44fc79dSJohn Baldwin { .name = "mmap", .ret_type = 1, .nargs = 6,
387e261fb2aSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 }, { Mmapflags, 3 },
388c05cc0d6SJohn Baldwin { Int, 4 }, { QuadHex, 5 } } },
389f44fc79dSJohn Baldwin { .name = "modfind", .ret_type = 1, .nargs = 1,
390f44fc79dSJohn Baldwin .args = { { Name | IN, 0 } } },
3912b75c8adSJohn Baldwin { .name = "mount", .ret_type = 1, .nargs = 4,
3928acc8e78SJohn Baldwin .args = { { Name, 0 }, { Name, 1 }, { Mountflags, 2 }, { Ptr, 3 } } },
393f44fc79dSJohn Baldwin { .name = "mprotect", .ret_type = 1, .nargs = 3,
394e261fb2aSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 } } },
395114aeee0SJohn Baldwin { .name = "msync", .ret_type = 1, .nargs = 3,
396114aeee0SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Msync, 2 } } },
39794bde755SJohn Baldwin { .name = "munlock", .ret_type = 1, .nargs = 2,
39894bde755SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 } } },
399f44fc79dSJohn Baldwin { .name = "munmap", .ret_type = 1, .nargs = 2,
400e261fb2aSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 } } },
401f44fc79dSJohn Baldwin { .name = "nanosleep", .ret_type = 1, .nargs = 1,
402f44fc79dSJohn Baldwin .args = { { Timespec, 0 } } },
4038acc8e78SJohn Baldwin { .name = "nmount", .ret_type = 1, .nargs = 3,
4048acc8e78SJohn Baldwin .args = { { Ptr, 0 }, { UInt, 1 }, { Mountflags, 2 } } },
405f44fc79dSJohn Baldwin { .name = "open", .ret_type = 1, .nargs = 3,
406f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
407f44fc79dSJohn Baldwin { .name = "openat", .ret_type = 1, .nargs = 4,
408f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 },
409f44fc79dSJohn Baldwin { Octal, 3 } } },
410f44fc79dSJohn Baldwin { .name = "pathconf", .ret_type = 1, .nargs = 2,
411f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Pathconf, 1 } } },
412f44fc79dSJohn Baldwin { .name = "pipe", .ret_type = 1, .nargs = 1,
413f44fc79dSJohn Baldwin .args = { { PipeFds | OUT, 0 } } },
414f44fc79dSJohn Baldwin { .name = "pipe2", .ret_type = 1, .nargs = 2,
4159289f547SJohn Baldwin .args = { { Ptr, 0 }, { Pipe2, 1 } } },
416f44fc79dSJohn Baldwin { .name = "poll", .ret_type = 1, .nargs = 3,
417f44fc79dSJohn Baldwin .args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } },
418d2a97485SJohn Baldwin { .name = "posix_fadvise", .ret_type = 1, .nargs = 4,
419d2a97485SJohn Baldwin .args = { { Int, 0 }, { QuadHex, 1 }, { QuadHex, 2 },
420d2a97485SJohn Baldwin { Fadvice, 3 } } },
421f44fc79dSJohn Baldwin { .name = "posix_openpt", .ret_type = 1, .nargs = 1,
422f44fc79dSJohn Baldwin .args = { { Open, 0 } } },
4239bf4983fSChristian Weisgerber { .name = "ppoll", .ret_type = 1, .nargs = 4,
4249bf4983fSChristian Weisgerber .args = { { Pollfd, 0 }, { Int, 1 }, { Timespec | IN, 2 },
4259bf4983fSChristian Weisgerber { Sigset | IN, 3 } } },
426b60a095bSJohn Baldwin { .name = "pread", .ret_type = 1, .nargs = 4,
427b60a095bSJohn Baldwin .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 },
428b60a095bSJohn Baldwin { QuadHex, 3 } } },
42958e3631bSThomas Munro { .name = "preadv", .ret_type = 1, .nargs = 4,
43058e3631bSThomas Munro .args = { { Int, 0 }, { Iovec | OUT, 1 }, { Int, 2 },
43158e3631bSThomas Munro { QuadHex, 3 } } },
432f44fc79dSJohn Baldwin { .name = "procctl", .ret_type = 1, .nargs = 4,
433c05cc0d6SJohn Baldwin .args = { { Idtype, 0 }, { Quad, 1 }, { Procctl, 2 }, { Ptr, 3 } } },
4345ac1c7acSJohn Baldwin { .name = "ptrace", .ret_type = 1, .nargs = 4,
4355ac1c7acSJohn Baldwin .args = { { Ptraceop, 0 }, { Int, 1 }, { Ptr, 2 }, { Int, 3 } } },
436b60a095bSJohn Baldwin { .name = "pwrite", .ret_type = 1, .nargs = 4,
437b60a095bSJohn Baldwin .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 },
438b60a095bSJohn Baldwin { QuadHex, 3 } } },
43958e3631bSThomas Munro { .name = "pwritev", .ret_type = 1, .nargs = 4,
44058e3631bSThomas Munro .args = { { Int, 0 }, { Iovec | IN, 1 }, { Int, 2 },
44158e3631bSThomas Munro { QuadHex, 3 } } },
442dd0c462cSJohn Baldwin { .name = "quotactl", .ret_type = 1, .nargs = 4,
443dd0c462cSJohn Baldwin .args = { { Name, 0 }, { Quotactlcmd, 1 }, { Int, 2 }, { Ptr, 3 } } },
444f44fc79dSJohn Baldwin { .name = "read", .ret_type = 1, .nargs = 3,
445e261fb2aSJohn Baldwin .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 } } },
446f44fc79dSJohn Baldwin { .name = "readlink", .ret_type = 1, .nargs = 3,
447e261fb2aSJohn Baldwin .args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Sizet, 2 } } },
448f44fc79dSJohn Baldwin { .name = "readlinkat", .ret_type = 1, .nargs = 4,
449f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 },
450e261fb2aSJohn Baldwin { Sizet, 3 } } },
451097b25a7SMichael Tuexen { .name = "readv", .ret_type = 1, .nargs = 3,
452097b25a7SMichael Tuexen .args = { { Int, 0 }, { Iovec | OUT, 1 }, { Int, 2 } } },
4534152441fSJohn Baldwin { .name = "reboot", .ret_type = 1, .nargs = 1,
4544152441fSJohn Baldwin .args = { { Reboothowto, 0 } } },
455ee3b0f6eSDiomidis Spinellis { .name = "recvfrom", .ret_type = 1, .nargs = 6,
4568b429b65SMichael Tuexen .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 },
4578b429b65SMichael Tuexen { Msgflags, 3 }, { Sockaddr | OUT, 4 },
4588b429b65SMichael Tuexen { Ptr | OUT, 5 } } },
459fca08fe6SMichael Tuexen { .name = "recvmsg", .ret_type = 1, .nargs = 3,
460a2674e03SMichael Tuexen .args = { { Int, 0 }, { Msghdr | OUT, 1 }, { Msgflags, 2 } } },
461f44fc79dSJohn Baldwin { .name = "rename", .ret_type = 1, .nargs = 2,
462f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Name, 1 } } },
463f44fc79dSJohn Baldwin { .name = "renameat", .ret_type = 1, .nargs = 4,
464f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } },
465f44fc79dSJohn Baldwin { .name = "rfork", .ret_type = 1, .nargs = 1,
466f44fc79dSJohn Baldwin .args = { { Rforkflags, 0 } } },
467cca89ee3SBryan Drewery { .name = "rmdir", .ret_type = 1, .nargs = 1,
468cca89ee3SBryan Drewery .args = { { Name, 0 } } },
4693cd40bc3SJohn Baldwin { .name = "rtprio", .ret_type = 1, .nargs = 3,
4703cd40bc3SJohn Baldwin .args = { { Rtpriofunc, 0 }, { Int, 1 }, { Ptr, 2 } } },
4713cd40bc3SJohn Baldwin { .name = "rtprio_thread", .ret_type = 1, .nargs = 3,
4723cd40bc3SJohn Baldwin .args = { { Rtpriofunc, 0 }, { Int, 1 }, { Ptr, 2 } } },
473a4110f9fSJohn Baldwin { .name = "sched_get_priority_max", .ret_type = 1, .nargs = 1,
474a4110f9fSJohn Baldwin .args = { { Schedpolicy, 0 } } },
475a4110f9fSJohn Baldwin { .name = "sched_get_priority_min", .ret_type = 1, .nargs = 1,
476a4110f9fSJohn Baldwin .args = { { Schedpolicy, 0 } } },
477a4110f9fSJohn Baldwin { .name = "sched_getparam", .ret_type = 1, .nargs = 2,
478a4110f9fSJohn Baldwin .args = { { Int, 0 }, { Schedparam | OUT, 1 } } },
479a4110f9fSJohn Baldwin { .name = "sched_getscheduler", .ret_type = 1, .nargs = 1,
480a4110f9fSJohn Baldwin .args = { { Int, 0 } } },
481a4110f9fSJohn Baldwin { .name = "sched_rr_get_interval", .ret_type = 1, .nargs = 2,
482a4110f9fSJohn Baldwin .args = { { Int, 0 }, { Timespec | OUT, 1 } } },
483a4110f9fSJohn Baldwin { .name = "sched_setparam", .ret_type = 1, .nargs = 2,
484a4110f9fSJohn Baldwin .args = { { Int, 0 }, { Schedparam, 1 } } },
485a4110f9fSJohn Baldwin { .name = "sched_setscheduler", .ret_type = 1, .nargs = 3,
486a4110f9fSJohn Baldwin .args = { { Int, 0 }, { Schedpolicy, 1 }, { Schedparam, 2 } } },
487c0b72375SMichael Tuexen { .name = "sctp_generic_recvmsg", .ret_type = 1, .nargs = 7,
4884d7b9809SMichael Tuexen .args = { { Int, 0 }, { Iovec | OUT, 1 }, { Int, 2 },
4894d7b9809SMichael Tuexen { Sockaddr | OUT, 3 }, { Ptr | OUT, 4 },
4904d7b9809SMichael Tuexen { Sctpsndrcvinfo | OUT, 5 }, { Ptr | OUT, 6 } } },
491c0b72375SMichael Tuexen { .name = "sctp_generic_sendmsg", .ret_type = 1, .nargs = 7,
492c0b72375SMichael Tuexen .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 },
4934d7b9809SMichael Tuexen { Sockaddr | IN, 3 }, { Socklent, 4 },
4944d7b9809SMichael Tuexen { Sctpsndrcvinfo | IN, 5 }, { Msgflags, 6 } } },
4954d7b9809SMichael Tuexen { .name = "sctp_generic_sendmsg_iov", .ret_type = 1, .nargs = 7,
4964d7b9809SMichael Tuexen .args = { { Int, 0 }, { Iovec | IN, 1 }, { Int, 2 },
4974d7b9809SMichael Tuexen { Sockaddr | IN, 3 }, { Socklent, 4 },
4984d7b9809SMichael Tuexen { Sctpsndrcvinfo | IN, 5 }, { Msgflags, 6 } } },
49990da2c79SMark Johnston { .name = "sendfile", .ret_type = 1, .nargs = 7,
50090da2c79SMark Johnston .args = { { Int, 0 }, { Int, 1 }, { QuadHex, 2 }, { Sizet, 3 },
50190da2c79SMark Johnston { Sendfilehdtr, 4 }, { QuadHex | OUT, 5 },
50290da2c79SMark Johnston { Sendfileflags, 6 } } },
503ee3b0f6eSDiomidis Spinellis { .name = "select", .ret_type = 1, .nargs = 5,
5040a46af44SJohn Baldwin .args = { { Int, 0 }, { Fd_set, 1 }, { Fd_set, 2 }, { Fd_set, 3 },
5050a46af44SJohn Baldwin { Timeval, 4 } } },
506fca08fe6SMichael Tuexen { .name = "sendmsg", .ret_type = 1, .nargs = 3,
507a2674e03SMichael Tuexen .args = { { Int, 0 }, { Msghdr | IN, 1 }, { Msgflags, 2 } } },
508f44fc79dSJohn Baldwin { .name = "sendto", .ret_type = 1, .nargs = 6,
5098b429b65SMichael Tuexen .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 },
5108b429b65SMichael Tuexen { Msgflags, 3 }, { Sockaddr | IN, 4 },
5118b429b65SMichael Tuexen { Socklent | IN, 5 } } },
512ee3b0f6eSDiomidis Spinellis { .name = "setitimer", .ret_type = 1, .nargs = 3,
513b9b86b67SDmitry Chagin .args = { { Itimerwhich, 0 }, { Itimerval, 1 },
514b9b86b67SDmitry Chagin { Itimerval | OUT, 2 } } },
515ad419d33SJohn Baldwin { .name = "setpriority", .ret_type = 1, .nargs = 3,
516ad419d33SJohn Baldwin .args = { { Priowhich, 0 }, { Int, 1 }, { Int, 2 } } },
517f44fc79dSJohn Baldwin { .name = "setrlimit", .ret_type = 1, .nargs = 2,
518f44fc79dSJohn Baldwin .args = { { Resource, 0 }, { Rlimit | IN, 1 } } },
519832af457SMichael Tuexen { .name = "setsockopt", .ret_type = 1, .nargs = 5,
520832af457SMichael Tuexen .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 },
521832af457SMichael Tuexen { Ptr | IN, 3 }, { Socklent, 4 } } },
52224eeedb5SAllan Jude { .name = "shm_open", .ret_type = 1, .nargs = 3,
5235b05dc5aSThomas Munro .args = { { ShmName | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
524bcca3425SKyle Evans { .name = "shm_open2", .ret_type = 1, .nargs = 5,
525bcca3425SKyle Evans .args = { { ShmName | IN, 0 }, { Open, 1 }, { Octal, 2 },
526733ba7efSKyle Evans { ShmFlags, 3 }, { Name | IN, 4 } } },
5279afb12baSDavid Bright { .name = "shm_rename", .ret_type = 1, .nargs = 3,
5289afb12baSDavid Bright .args = { { Name | IN, 0 }, { Name | IN, 1 }, { Hex, 2 } } },
52924eeedb5SAllan Jude { .name = "shm_unlink", .ret_type = 1, .nargs = 1,
53024eeedb5SAllan Jude .args = { { Name | IN, 0 } } },
531f44fc79dSJohn Baldwin { .name = "shutdown", .ret_type = 1, .nargs = 2,
532f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Shutdown, 1 } } },
533f44fc79dSJohn Baldwin { .name = "sigaction", .ret_type = 1, .nargs = 3,
534f44fc79dSJohn Baldwin .args = { { Signal, 0 }, { Sigaction | IN, 1 },
535f44fc79dSJohn Baldwin { Sigaction | OUT, 2 } } },
5362b75c8adSJohn Baldwin { .name = "sigpending", .ret_type = 1, .nargs = 1,
537b289a8d7SJohn Baldwin .args = { { Sigset | OUT, 0 } } },
5382b75c8adSJohn Baldwin { .name = "sigprocmask", .ret_type = 1, .nargs = 3,
539ee3b0f6eSDiomidis Spinellis .args = { { Sigprocmask, 0 }, { Sigset, 1 }, { Sigset | OUT, 2 } } },
5402b75c8adSJohn Baldwin { .name = "sigqueue", .ret_type = 1, .nargs = 3,
541b289a8d7SJohn Baldwin .args = { { Int, 0 }, { Signal, 1 }, { LongHex, 2 } } },
5422b75c8adSJohn Baldwin { .name = "sigreturn", .ret_type = 1, .nargs = 1,
543b289a8d7SJohn Baldwin .args = { { Ptr, 0 } } },
5442b75c8adSJohn Baldwin { .name = "sigsuspend", .ret_type = 1, .nargs = 1,
545b289a8d7SJohn Baldwin .args = { { Sigset | IN, 0 } } },
546b289a8d7SJohn Baldwin { .name = "sigtimedwait", .ret_type = 1, .nargs = 3,
54713e5e6b6SJohn Baldwin .args = { { Sigset | IN, 0 }, { Siginfo | OUT, 1 },
54813e5e6b6SJohn Baldwin { Timespec | IN, 2 } } },
549b289a8d7SJohn Baldwin { .name = "sigwait", .ret_type = 1, .nargs = 2,
55013e5e6b6SJohn Baldwin .args = { { Sigset | IN, 0 }, { PSig | OUT, 1 } } },
551b289a8d7SJohn Baldwin { .name = "sigwaitinfo", .ret_type = 1, .nargs = 2,
55213e5e6b6SJohn Baldwin .args = { { Sigset | IN, 0 }, { Siginfo | OUT, 1 } } },
553ee3b0f6eSDiomidis Spinellis { .name = "socket", .ret_type = 1, .nargs = 3,
554ecac235bSMichael Tuexen .args = { { Sockdomain, 0 }, { Socktype, 1 }, { Sockprotocol, 2 } } },
555f44fc79dSJohn Baldwin { .name = "stat", .ret_type = 1, .nargs = 2,
556f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
557f44fc79dSJohn Baldwin { .name = "statfs", .ret_type = 1, .nargs = 2,
558f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } },
559ee3b0f6eSDiomidis Spinellis { .name = "symlink", .ret_type = 1, .nargs = 2,
560ee3b0f6eSDiomidis Spinellis .args = { { Name, 0 }, { Name, 1 } } },
5617d897327SJohn Baldwin { .name = "symlinkat", .ret_type = 1, .nargs = 3,
5627d897327SJohn Baldwin .args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } },
563f44fc79dSJohn Baldwin { .name = "sysarch", .ret_type = 1, .nargs = 2,
564f44fc79dSJohn Baldwin .args = { { Sysarch, 0 }, { Ptr, 1 } } },
56543ce0d90SKonstantin Belousov { .name = "__sysctl", .ret_type = 1, .nargs = 6,
56643ce0d90SKonstantin Belousov .args = { { Sysctl, 0 }, { Sizet, 1 }, { Ptr, 2 }, { Ptr, 3 },
56743ce0d90SKonstantin Belousov { Ptr, 4 }, { Sizet, 5 } } },
56843ce0d90SKonstantin Belousov { .name = "__sysctlbyname", .ret_type = 1, .nargs = 6,
56943ce0d90SKonstantin Belousov .args = { { Name, 0 }, { Sizet, 1 }, { Ptr, 2 }, { Ptr, 3 },
57043ce0d90SKonstantin Belousov { Ptr, 4}, { Sizet, 5 } } },
571f44fc79dSJohn Baldwin { .name = "thr_kill", .ret_type = 1, .nargs = 2,
572f44fc79dSJohn Baldwin .args = { { Long, 0 }, { Signal, 1 } } },
573f44fc79dSJohn Baldwin { .name = "thr_self", .ret_type = 1, .nargs = 1,
574f44fc79dSJohn Baldwin .args = { { Ptr, 0 } } },
575d86cddf0SJohn Baldwin { .name = "thr_set_name", .ret_type = 1, .nargs = 2,
576d86cddf0SJohn Baldwin .args = { { Long, 0 }, { Name, 1 } } },
577f44fc79dSJohn Baldwin { .name = "truncate", .ret_type = 1, .nargs = 2,
578c05cc0d6SJohn Baldwin .args = { { Name | IN, 0 }, { QuadHex | IN, 1 } } },
579f44fc79dSJohn Baldwin { .name = "unlink", .ret_type = 1, .nargs = 1,
580f44fc79dSJohn Baldwin .args = { { Name, 0 } } },
581f44fc79dSJohn Baldwin { .name = "unlinkat", .ret_type = 1, .nargs = 3,
582f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } },
583f44fc79dSJohn Baldwin { .name = "unmount", .ret_type = 1, .nargs = 2,
5848acc8e78SJohn Baldwin .args = { { Name, 0 }, { Mountflags, 1 } } },
585f44fc79dSJohn Baldwin { .name = "utimensat", .ret_type = 1, .nargs = 4,
586f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 },
587f44fc79dSJohn Baldwin { Atflags, 3 } } },
588f44fc79dSJohn Baldwin { .name = "utimes", .ret_type = 1, .nargs = 2,
589f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
590195aef99SBryan Drewery { .name = "utrace", .ret_type = 1, .nargs = 1,
591195aef99SBryan Drewery .args = { { Utrace, 0 } } },
59234763d1cSJohn Baldwin { .name = "wait4", .ret_type = 1, .nargs = 4,
59334763d1cSJohn Baldwin .args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 },
59434763d1cSJohn Baldwin { Rusage | OUT, 3 } } },
59534763d1cSJohn Baldwin { .name = "wait6", .ret_type = 1, .nargs = 6,
596c05cc0d6SJohn Baldwin .args = { { Idtype, 0 }, { Quad, 1 }, { ExitStatus | OUT, 2 },
59713e5e6b6SJohn Baldwin { Waitoptions, 3 }, { Rusage | OUT, 4 },
59813e5e6b6SJohn Baldwin { Siginfo | OUT, 5 } } },
599f44fc79dSJohn Baldwin { .name = "write", .ret_type = 1, .nargs = 3,
600e261fb2aSJohn Baldwin .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 } } },
601ee6e58b2SMichael Tuexen { .name = "writev", .ret_type = 1, .nargs = 3,
602dfcd2888SMichael Tuexen .args = { { Int, 0 }, { Iovec | IN, 1 }, { Int, 2 } } },
603f44fc79dSJohn Baldwin
604f44fc79dSJohn Baldwin /* Linux ABI */
605f44fc79dSJohn Baldwin { .name = "linux_access", .ret_type = 1, .nargs = 2,
606f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Accessmode, 1 } } },
607f44fc79dSJohn Baldwin { .name = "linux_execve", .ret_type = 1, .nargs = 3,
608f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
609f44fc79dSJohn Baldwin { ExecEnv | IN, 2 } } },
610b9b86b67SDmitry Chagin { .name = "linux_getitimer", .ret_type = 1, .nargs = 2,
611b9b86b67SDmitry Chagin .args = { { Itimerwhich, 0 }, { Itimerval | OUT, 2 } } },
612f44fc79dSJohn Baldwin { .name = "linux_lseek", .ret_type = 2, .nargs = 3,
613f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } },
614f44fc79dSJohn Baldwin { .name = "linux_mkdir", .ret_type = 1, .nargs = 2,
615f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Int, 1 } } },
616f44fc79dSJohn Baldwin { .name = "linux_newfstat", .ret_type = 1, .nargs = 2,
617f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Ptr | OUT, 1 } } },
618*55e2187aSJohn F. Carr { .name = "linux_newlstat", .ret_type = 1, .nargs = 2,
619*55e2187aSJohn F. Carr .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
620f44fc79dSJohn Baldwin { .name = "linux_newstat", .ret_type = 1, .nargs = 2,
621f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
622f44fc79dSJohn Baldwin { .name = "linux_open", .ret_type = 1, .nargs = 3,
623f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } },
624f44fc79dSJohn Baldwin { .name = "linux_readlink", .ret_type = 1, .nargs = 3,
625e261fb2aSJohn Baldwin .args = { { Name, 0 }, { Name | OUT, 1 }, { Sizet, 2 } } },
626b9b86b67SDmitry Chagin { .name = "linux_setitimer", .ret_type = 1, .nargs = 3,
627b9b86b67SDmitry Chagin .args = { { Itimerwhich, 0 }, { Itimerval, 1 },
628b9b86b67SDmitry Chagin { Itimerval | OUT, 2 } } },
629f44fc79dSJohn Baldwin { .name = "linux_socketcall", .ret_type = 1, .nargs = 2,
630f44fc79dSJohn Baldwin .args = { { Int, 0 }, { LinuxSockArgs, 1 } } },
63164f4703bSJohn Baldwin { .name = "linux_stat64", .ret_type = 1, .nargs = 2,
63264f4703bSJohn Baldwin .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
633bbeaf6c0SSean Eric Fagan };
6346019514bSAlex Richardson static STAILQ_HEAD(, syscall) seen_syscalls;
635bbeaf6c0SSean Eric Fagan
636081e5c48SPav Lucistnik /* Xlat idea taken from strace */
637081e5c48SPav Lucistnik struct xlat {
638081e5c48SPav Lucistnik int val;
6395d2d083cSXin LI const char *str;
640081e5c48SPav Lucistnik };
641081e5c48SPav Lucistnik
642081e5c48SPav Lucistnik #define X(a) { a, #a },
643081e5c48SPav Lucistnik #define XEND { 0, NULL }
644081e5c48SPav Lucistnik
645a02c83afSEd Schouten static struct xlat poll_flags[] = {
646081e5c48SPav Lucistnik X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR)
647081e5c48SPav Lucistnik X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND)
6483aaaa2efSThomas Munro X(POLLWRBAND) X(POLLINIGNEOF) X(POLLRDHUP) XEND
649081e5c48SPav Lucistnik };
650081e5c48SPav Lucistnik
651081e5c48SPav Lucistnik static struct xlat sigaction_flags[] = {
652081e5c48SPav Lucistnik X(SA_ONSTACK) X(SA_RESTART) X(SA_RESETHAND) X(SA_NOCLDSTOP)
653081e5c48SPav Lucistnik X(SA_NODEFER) X(SA_NOCLDWAIT) X(SA_SIGINFO) XEND
654081e5c48SPav Lucistnik };
655081e5c48SPav Lucistnik
656fb7eabb0SJohn Baldwin static struct xlat linux_socketcall_ops[] = {
657fb7eabb0SJohn Baldwin X(LINUX_SOCKET) X(LINUX_BIND) X(LINUX_CONNECT) X(LINUX_LISTEN)
658fb7eabb0SJohn Baldwin X(LINUX_ACCEPT) X(LINUX_GETSOCKNAME) X(LINUX_GETPEERNAME)
659fb7eabb0SJohn Baldwin X(LINUX_SOCKETPAIR) X(LINUX_SEND) X(LINUX_RECV) X(LINUX_SENDTO)
660fb7eabb0SJohn Baldwin X(LINUX_RECVFROM) X(LINUX_SHUTDOWN) X(LINUX_SETSOCKOPT)
661fb7eabb0SJohn Baldwin X(LINUX_GETSOCKOPT) X(LINUX_SENDMSG) X(LINUX_RECVMSG)
662fb7eabb0SJohn Baldwin XEND
663fb7eabb0SJohn Baldwin };
664fb7eabb0SJohn Baldwin
665bb24ee2bSThomas Munro static struct xlat lio_modes[] = {
666bb24ee2bSThomas Munro X(LIO_WAIT) X(LIO_NOWAIT)
667bb24ee2bSThomas Munro XEND
668bb24ee2bSThomas Munro };
669bb24ee2bSThomas Munro
670bb24ee2bSThomas Munro static struct xlat lio_opcodes[] = {
671f30a1ae8SThomas Munro X(LIO_WRITE) X(LIO_READ) X(LIO_READV) X(LIO_WRITEV) X(LIO_NOP)
672bb24ee2bSThomas Munro XEND
673bb24ee2bSThomas Munro };
674bb24ee2bSThomas Munro
675bb24ee2bSThomas Munro static struct xlat aio_fsync_ops[] = {
676bb24ee2bSThomas Munro X(O_SYNC)
677bb24ee2bSThomas Munro XEND
678bb24ee2bSThomas Munro };
679bb24ee2bSThomas Munro
680081e5c48SPav Lucistnik #undef X
681081e5c48SPav Lucistnik #undef XEND
682081e5c48SPav Lucistnik
683d8984f48SDag-Erling Smørgrav /*
684d8984f48SDag-Erling Smørgrav * Searches an xlat array for a value, and returns it if found. Otherwise
685d8984f48SDag-Erling Smørgrav * return a string representation.
686d8984f48SDag-Erling Smørgrav */
687d8984f48SDag-Erling Smørgrav static const char *
lookup(struct xlat * xlat,int val,int base)688d8984f48SDag-Erling Smørgrav lookup(struct xlat *xlat, int val, int base)
689081e5c48SPav Lucistnik {
690081e5c48SPav Lucistnik static char tmp[16];
691d8984f48SDag-Erling Smørgrav
692081e5c48SPav Lucistnik for (; xlat->str != NULL; xlat++)
693081e5c48SPav Lucistnik if (xlat->val == val)
694d8984f48SDag-Erling Smørgrav return (xlat->str);
695081e5c48SPav Lucistnik switch (base) {
696081e5c48SPav Lucistnik case 8:
697081e5c48SPav Lucistnik sprintf(tmp, "0%o", val);
698081e5c48SPav Lucistnik break;
699081e5c48SPav Lucistnik case 16:
700081e5c48SPav Lucistnik sprintf(tmp, "0x%x", val);
701081e5c48SPav Lucistnik break;
702081e5c48SPav Lucistnik case 10:
703081e5c48SPav Lucistnik sprintf(tmp, "%u", val);
704081e5c48SPav Lucistnik break;
705081e5c48SPav Lucistnik default:
706081e5c48SPav Lucistnik errx(1, "Unknown lookup base");
707081e5c48SPav Lucistnik }
708d8984f48SDag-Erling Smørgrav return (tmp);
709081e5c48SPav Lucistnik }
710081e5c48SPav Lucistnik
7115d2d083cSXin LI static const char *
xlookup(struct xlat * xlat,int val)7125d2d083cSXin LI xlookup(struct xlat *xlat, int val)
713081e5c48SPav Lucistnik {
714d8984f48SDag-Erling Smørgrav
715d8984f48SDag-Erling Smørgrav return (lookup(xlat, val, 16));
716081e5c48SPav Lucistnik }
717081e5c48SPav Lucistnik
7184e3da534SJohn Baldwin /*
7194e3da534SJohn Baldwin * Searches an xlat array containing bitfield values. Remaining bits
7204e3da534SJohn Baldwin * set after removing the known ones are printed at the end:
7214e3da534SJohn Baldwin * IN|0x400.
7224e3da534SJohn Baldwin */
723d8984f48SDag-Erling Smørgrav static char *
xlookup_bits(struct xlat * xlat,int val)724d8984f48SDag-Erling Smørgrav xlookup_bits(struct xlat *xlat, int val)
725081e5c48SPav Lucistnik {
72694355cfdSAndrey Zonov int len, rem;
727081e5c48SPav Lucistnik static char str[512];
728081e5c48SPav Lucistnik
72994355cfdSAndrey Zonov len = 0;
73094355cfdSAndrey Zonov rem = val;
731d8984f48SDag-Erling Smørgrav for (; xlat->str != NULL; xlat++) {
732d8984f48SDag-Erling Smørgrav if ((xlat->val & rem) == xlat->val) {
7334e3da534SJohn Baldwin /*
7344e3da534SJohn Baldwin * Don't print the "all-bits-zero" string unless all
7354e3da534SJohn Baldwin * bits are really zero.
7364e3da534SJohn Baldwin */
737081e5c48SPav Lucistnik if (xlat->val == 0 && val != 0)
738081e5c48SPav Lucistnik continue;
739081e5c48SPav Lucistnik len += sprintf(str + len, "%s|", xlat->str);
740081e5c48SPav Lucistnik rem &= ~(xlat->val);
741081e5c48SPav Lucistnik }
742081e5c48SPav Lucistnik }
7434e3da534SJohn Baldwin
7444e3da534SJohn Baldwin /*
7454e3da534SJohn Baldwin * If we have leftover bits or didn't match anything, print
7464e3da534SJohn Baldwin * the remainder.
7474e3da534SJohn Baldwin */
748081e5c48SPav Lucistnik if (rem || len == 0)
749081e5c48SPav Lucistnik len += sprintf(str + len, "0x%x", rem);
750081e5c48SPav Lucistnik if (len && str[len - 1] == '|')
751081e5c48SPav Lucistnik len--;
752081e5c48SPav Lucistnik str[len] = 0;
753d8984f48SDag-Erling Smørgrav return (str);
754081e5c48SPav Lucistnik }
755081e5c48SPav Lucistnik
7569289f547SJohn Baldwin static void
print_integer_arg(const char * (* decoder)(int),FILE * fp,int value)7579289f547SJohn Baldwin print_integer_arg(const char *(*decoder)(int), FILE *fp, int value)
7589289f547SJohn Baldwin {
7599289f547SJohn Baldwin const char *str;
7609289f547SJohn Baldwin
7619289f547SJohn Baldwin str = decoder(value);
7629289f547SJohn Baldwin if (str != NULL)
7639289f547SJohn Baldwin fputs(str, fp);
7649289f547SJohn Baldwin else
7659289f547SJohn Baldwin fprintf(fp, "%d", value);
7669289f547SJohn Baldwin }
7679289f547SJohn Baldwin
768c2679dd7SKyle Evans static bool
print_mask_arg_part(bool (* decoder)(FILE *,int,int *),FILE * fp,int value,int * rem)769c2679dd7SKyle Evans print_mask_arg_part(bool (*decoder)(FILE *, int, int *), FILE *fp, int value,
770c2679dd7SKyle Evans int *rem)
771c2679dd7SKyle Evans {
772c2679dd7SKyle Evans
773c2679dd7SKyle Evans return (decoder(fp, value, rem));
774c2679dd7SKyle Evans }
775c2679dd7SKyle Evans
7769289f547SJohn Baldwin static void
print_mask_arg(bool (* decoder)(FILE *,int,int *),FILE * fp,int value)7779289f547SJohn Baldwin print_mask_arg(bool (*decoder)(FILE *, int, int *), FILE *fp, int value)
7789289f547SJohn Baldwin {
7799289f547SJohn Baldwin int rem;
7809289f547SJohn Baldwin
781c2679dd7SKyle Evans if (!print_mask_arg_part(decoder, fp, value, &rem))
7829289f547SJohn Baldwin fprintf(fp, "0x%x", rem);
7839289f547SJohn Baldwin else if (rem != 0)
7849289f547SJohn Baldwin fprintf(fp, "|0x%x", rem);
7859289f547SJohn Baldwin }
7869289f547SJohn Baldwin
787bed418c8SJohn Baldwin static void
print_mask_arg32(bool (* decoder)(FILE *,uint32_t,uint32_t *),FILE * fp,uint32_t value)788bed418c8SJohn Baldwin print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *), FILE *fp,
789bed418c8SJohn Baldwin uint32_t value)
790bed418c8SJohn Baldwin {
791bed418c8SJohn Baldwin uint32_t rem;
792bed418c8SJohn Baldwin
793bed418c8SJohn Baldwin if (!decoder(fp, value, &rem))
794bed418c8SJohn Baldwin fprintf(fp, "0x%x", rem);
795bed418c8SJohn Baldwin else if (rem != 0)
796bed418c8SJohn Baldwin fprintf(fp, "|0x%x", rem);
797bed418c8SJohn Baldwin }
798bed418c8SJohn Baldwin
799c05cc0d6SJohn Baldwin /*
800214b7670SJohn Baldwin * Add argument padding to subsequent system calls after Quad
801c05cc0d6SJohn Baldwin * syscall arguments as needed. This used to be done by hand in the
802c05cc0d6SJohn Baldwin * decoded_syscalls table which was ugly and error prone. It is
8035aa0576bSEd Maste * simpler to do the fixup of offsets at initialization time than when
804c05cc0d6SJohn Baldwin * decoding arguments.
805c05cc0d6SJohn Baldwin */
806c05cc0d6SJohn Baldwin static void
quad_fixup(struct syscall_decode * sc)807f4b7018aSOlivier Houchard quad_fixup(struct syscall_decode *sc)
808c05cc0d6SJohn Baldwin {
809c05cc0d6SJohn Baldwin int offset, prev;
810c05cc0d6SJohn Baldwin u_int i;
811c05cc0d6SJohn Baldwin
812c05cc0d6SJohn Baldwin offset = 0;
813c05cc0d6SJohn Baldwin prev = -1;
814c05cc0d6SJohn Baldwin for (i = 0; i < sc->nargs; i++) {
815c05cc0d6SJohn Baldwin /* This arg type is a dummy that doesn't use offset. */
816c05cc0d6SJohn Baldwin if ((sc->args[i].type & ARG_MASK) == PipeFds)
817c05cc0d6SJohn Baldwin continue;
818c05cc0d6SJohn Baldwin
819c05cc0d6SJohn Baldwin assert(prev < sc->args[i].offset);
820c05cc0d6SJohn Baldwin prev = sc->args[i].offset;
821c05cc0d6SJohn Baldwin sc->args[i].offset += offset;
822c05cc0d6SJohn Baldwin switch (sc->args[i].type & ARG_MASK) {
823c05cc0d6SJohn Baldwin case Quad:
824c05cc0d6SJohn Baldwin case QuadHex:
825ebbc3140SOlivier Houchard #if defined(__powerpc__) || defined(__arm__) || defined(__aarch64__)
826c05cc0d6SJohn Baldwin /*
827ebbc3140SOlivier Houchard * 64-bit arguments on 32-bit powerpc and arm must be
828c05cc0d6SJohn Baldwin * 64-bit aligned. If the current offset is
829c05cc0d6SJohn Baldwin * not aligned, the calling convention inserts
830c05cc0d6SJohn Baldwin * a 32-bit pad argument that should be skipped.
831c05cc0d6SJohn Baldwin */
832c05cc0d6SJohn Baldwin if (sc->args[i].offset % 2 == 1) {
833c05cc0d6SJohn Baldwin sc->args[i].offset++;
834c05cc0d6SJohn Baldwin offset++;
835c05cc0d6SJohn Baldwin }
836c05cc0d6SJohn Baldwin #endif
837c05cc0d6SJohn Baldwin offset++;
838c05cc0d6SJohn Baldwin default:
839c05cc0d6SJohn Baldwin break;
840c05cc0d6SJohn Baldwin }
841c05cc0d6SJohn Baldwin }
842c05cc0d6SJohn Baldwin }
843c05cc0d6SJohn Baldwin
8441175b23fSJohn Baldwin static struct syscall *
find_syscall(struct procabi * abi,u_int number)8451175b23fSJohn Baldwin find_syscall(struct procabi *abi, u_int number)
8461175b23fSJohn Baldwin {
8471175b23fSJohn Baldwin struct extra_syscall *es;
8481175b23fSJohn Baldwin
8491175b23fSJohn Baldwin if (number < nitems(abi->syscalls))
8501175b23fSJohn Baldwin return (abi->syscalls[number]);
8511175b23fSJohn Baldwin STAILQ_FOREACH(es, &abi->extra_syscalls, entries) {
8521175b23fSJohn Baldwin if (es->number == number)
8531175b23fSJohn Baldwin return (es->sc);
8541175b23fSJohn Baldwin }
8551175b23fSJohn Baldwin return (NULL);
8561175b23fSJohn Baldwin }
8571175b23fSJohn Baldwin
8581175b23fSJohn Baldwin static void
add_syscall(struct procabi * abi,u_int number,struct syscall * sc)8591175b23fSJohn Baldwin add_syscall(struct procabi *abi, u_int number, struct syscall *sc)
8601175b23fSJohn Baldwin {
8611175b23fSJohn Baldwin struct extra_syscall *es;
8621175b23fSJohn Baldwin
8637daca4e2SAlex Richardson /*
8647daca4e2SAlex Richardson * quad_fixup() is currently needed for all 32-bit ABIs.
8657daca4e2SAlex Richardson * TODO: This should probably be a function pointer inside struct
8667daca4e2SAlex Richardson * procabi instead.
8677daca4e2SAlex Richardson */
8687daca4e2SAlex Richardson if (abi->pointer_size == 4)
869f4b7018aSOlivier Houchard quad_fixup(&sc->decode);
8706019514bSAlex Richardson
8711175b23fSJohn Baldwin if (number < nitems(abi->syscalls)) {
8721175b23fSJohn Baldwin assert(abi->syscalls[number] == NULL);
8731175b23fSJohn Baldwin abi->syscalls[number] = sc;
8741175b23fSJohn Baldwin } else {
8751175b23fSJohn Baldwin es = malloc(sizeof(*es));
8761175b23fSJohn Baldwin es->sc = sc;
8771175b23fSJohn Baldwin es->number = number;
8781175b23fSJohn Baldwin STAILQ_INSERT_TAIL(&abi->extra_syscalls, es, entries);
8791175b23fSJohn Baldwin }
8806019514bSAlex Richardson
8816019514bSAlex Richardson STAILQ_INSERT_HEAD(&seen_syscalls, sc, entries);
8821175b23fSJohn Baldwin }
8831175b23fSJohn Baldwin
884bbeaf6c0SSean Eric Fagan /*
885bbeaf6c0SSean Eric Fagan * If/when the list gets big, it might be desirable to do it
886bbeaf6c0SSean Eric Fagan * as a hash table or binary search.
887bbeaf6c0SSean Eric Fagan */
888bbeaf6c0SSean Eric Fagan struct syscall *
get_syscall(struct threadinfo * t,u_int number,u_int nargs)8891175b23fSJohn Baldwin get_syscall(struct threadinfo *t, u_int number, u_int nargs)
890d8984f48SDag-Erling Smørgrav {
89194355cfdSAndrey Zonov struct syscall *sc;
8927daca4e2SAlex Richardson struct procabi *procabi;
8936019514bSAlex Richardson const char *sysdecode_name;
8947daca4e2SAlex Richardson const char *lookup_name;
8951175b23fSJohn Baldwin const char *name;
8961175b23fSJohn Baldwin u_int i;
897bbeaf6c0SSean Eric Fagan
8987daca4e2SAlex Richardson procabi = t->proc->abi;
8997daca4e2SAlex Richardson sc = find_syscall(procabi, number);
9001175b23fSJohn Baldwin if (sc != NULL)
901d8984f48SDag-Erling Smørgrav return (sc);
9026c61b0f3SBryan Drewery
9036019514bSAlex Richardson /* Memory is not explicitly deallocated, it's released on exit(). */
9047daca4e2SAlex Richardson sysdecode_name = sysdecode_syscallname(procabi->abi, number);
9056019514bSAlex Richardson if (sysdecode_name == NULL)
9066019514bSAlex Richardson asprintf(__DECONST(char **, &name), "#%d", number);
9076019514bSAlex Richardson else
9086019514bSAlex Richardson name = sysdecode_name;
9096019514bSAlex Richardson
9106019514bSAlex Richardson sc = calloc(1, sizeof(*sc));
9116019514bSAlex Richardson sc->name = name;
9126019514bSAlex Richardson
9137daca4e2SAlex Richardson /* Also decode compat syscalls arguments by stripping the prefix. */
9147daca4e2SAlex Richardson lookup_name = name;
9157daca4e2SAlex Richardson if (procabi->compat_prefix != NULL && strncmp(procabi->compat_prefix,
9167daca4e2SAlex Richardson name, strlen(procabi->compat_prefix)) == 0)
9177daca4e2SAlex Richardson lookup_name += strlen(procabi->compat_prefix);
9187daca4e2SAlex Richardson
9196019514bSAlex Richardson for (i = 0; i < nitems(decoded_syscalls); i++) {
9207daca4e2SAlex Richardson if (strcmp(lookup_name, decoded_syscalls[i].name) == 0) {
9216019514bSAlex Richardson sc->decode = decoded_syscalls[i];
9221175b23fSJohn Baldwin add_syscall(t->proc->abi, number, sc);
9231175b23fSJohn Baldwin return (sc);
9241175b23fSJohn Baldwin }
9251175b23fSJohn Baldwin }
9261175b23fSJohn Baldwin
9276c61b0f3SBryan Drewery /* It is unknown. Add it into the list. */
9286c61b0f3SBryan Drewery #if DEBUG
9296c61b0f3SBryan Drewery fprintf(stderr, "unknown syscall %s -- setting args to %d\n", name,
9306c61b0f3SBryan Drewery nargs);
9316c61b0f3SBryan Drewery #endif
9326019514bSAlex Richardson sc->unknown = sysdecode_name == NULL;
9336019514bSAlex Richardson sc->decode.ret_type = 1; /* Assume 1 return value. */
9346019514bSAlex Richardson sc->decode.nargs = nargs;
9356c61b0f3SBryan Drewery for (i = 0; i < nargs; i++) {
9366019514bSAlex Richardson sc->decode.args[i].offset = i;
9376c61b0f3SBryan Drewery /* Treat all unknown arguments as LongHex. */
9386019514bSAlex Richardson sc->decode.args[i].type = LongHex;
939bbeaf6c0SSean Eric Fagan }
9401175b23fSJohn Baldwin add_syscall(t->proc->abi, number, sc);
9416c61b0f3SBryan Drewery return (sc);
942bbeaf6c0SSean Eric Fagan }
943bbeaf6c0SSean Eric Fagan
944bbeaf6c0SSean Eric Fagan /*
9459ddd1412SDag-Erling Smørgrav * Copy a fixed amount of bytes from the process.
9469ddd1412SDag-Erling Smørgrav */
9471be5d704SMark Murray static int
get_struct(pid_t pid,psaddr_t offset,void * buf,size_t len)94831dddc6aSAlex Richardson get_struct(pid_t pid, psaddr_t offset, void *buf, size_t len)
949d8984f48SDag-Erling Smørgrav {
9505d2d083cSXin LI struct ptrace_io_desc iorequest;
9519ddd1412SDag-Erling Smørgrav
9525d2d083cSXin LI iorequest.piod_op = PIOD_READ_D;
95331dddc6aSAlex Richardson iorequest.piod_offs = (void *)(uintptr_t)offset;
9545d2d083cSXin LI iorequest.piod_addr = buf;
9555d2d083cSXin LI iorequest.piod_len = len;
9565d2d083cSXin LI if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0)
957d8984f48SDag-Erling Smørgrav return (-1);
958d8984f48SDag-Erling Smørgrav return (0);
9599ddd1412SDag-Erling Smørgrav }
9609ddd1412SDag-Erling Smørgrav
9615d2d083cSXin LI #define MAXSIZE 4096
962abb3f965SJohn Baldwin
9639ddd1412SDag-Erling Smørgrav /*
964bbeaf6c0SSean Eric Fagan * Copy a string from the process. Note that it is
965bbeaf6c0SSean Eric Fagan * expected to be a C string, but if max is set, it will
966bbeaf6c0SSean Eric Fagan * only get that much.
967bbeaf6c0SSean Eric Fagan */
9685d2d083cSXin LI static char *
get_string(pid_t pid,psaddr_t addr,int max)96931dddc6aSAlex Richardson get_string(pid_t pid, psaddr_t addr, int max)
970d8984f48SDag-Erling Smørgrav {
9715d2d083cSXin LI struct ptrace_io_desc iorequest;
972abb3f965SJohn Baldwin char *buf, *nbuf;
973abb3f965SJohn Baldwin size_t offset, size, totalsize;
974bbeaf6c0SSean Eric Fagan
975abb3f965SJohn Baldwin offset = 0;
976abb3f965SJohn Baldwin if (max)
977abb3f965SJohn Baldwin size = max + 1;
978abb3f965SJohn Baldwin else {
979abb3f965SJohn Baldwin /* Read up to the end of the current page. */
98031dddc6aSAlex Richardson size = PAGE_SIZE - (addr % PAGE_SIZE);
981abb3f965SJohn Baldwin if (size > MAXSIZE)
982abb3f965SJohn Baldwin size = MAXSIZE;
983abb3f965SJohn Baldwin }
984abb3f965SJohn Baldwin totalsize = size;
9855d2d083cSXin LI buf = malloc(totalsize);
9865d2d083cSXin LI if (buf == NULL)
987d8984f48SDag-Erling Smørgrav return (NULL);
9885d2d083cSXin LI for (;;) {
9895d2d083cSXin LI iorequest.piod_op = PIOD_READ_D;
99031dddc6aSAlex Richardson iorequest.piod_offs = (void *)((uintptr_t)addr + offset);
991abb3f965SJohn Baldwin iorequest.piod_addr = buf + offset;
9925d2d083cSXin LI iorequest.piod_len = size;
9935d2d083cSXin LI if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) {
9945d2d083cSXin LI free(buf);
995d8984f48SDag-Erling Smørgrav return (NULL);
996bbeaf6c0SSean Eric Fagan }
997abb3f965SJohn Baldwin if (memchr(buf + offset, '\0', size) != NULL)
998abb3f965SJohn Baldwin return (buf);
999abb3f965SJohn Baldwin offset += size;
1000abb3f965SJohn Baldwin if (totalsize < MAXSIZE && max == 0) {
1001abb3f965SJohn Baldwin size = MAXSIZE - totalsize;
1002abb3f965SJohn Baldwin if (size > PAGE_SIZE)
1003abb3f965SJohn Baldwin size = PAGE_SIZE;
1004abb3f965SJohn Baldwin nbuf = realloc(buf, totalsize + size);
1005abb3f965SJohn Baldwin if (nbuf == NULL) {
1006abb3f965SJohn Baldwin buf[totalsize - 1] = '\0';
10074e92419dSMarcel Moolenaar return (buf);
1008bbeaf6c0SSean Eric Fagan }
1009abb3f965SJohn Baldwin buf = nbuf;
1010abb3f965SJohn Baldwin totalsize += size;
1011d8984f48SDag-Erling Smørgrav } else {
1012cdfc719cSJaakko Heinonen buf[totalsize - 1] = '\0';
1013d8984f48SDag-Erling Smørgrav return (buf);
10145d2d083cSXin LI }
10155d2d083cSXin LI }
10165d2d083cSXin LI }
1017bbeaf6c0SSean Eric Fagan
10189289f547SJohn Baldwin static const char *
strsig2(int sig)101934763d1cSJohn Baldwin strsig2(int sig)
102034763d1cSJohn Baldwin {
10219289f547SJohn Baldwin static char tmp[32];
10229289f547SJohn Baldwin const char *signame;
102334763d1cSJohn Baldwin
10249289f547SJohn Baldwin signame = sysdecode_signal(sig);
10259289f547SJohn Baldwin if (signame == NULL) {
1026f083f689SJohn Baldwin snprintf(tmp, sizeof(tmp), "%d", sig);
10279289f547SJohn Baldwin signame = tmp;
1028f083f689SJohn Baldwin }
10299289f547SJohn Baldwin return (signame);
103034763d1cSJohn Baldwin }
1031bbeaf6c0SSean Eric Fagan
1032c915ff03SJohn Baldwin static void
print_kevent(FILE * fp,struct kevent * ke)1033ffb66079SJohn Baldwin print_kevent(FILE *fp, struct kevent *ke)
1034c915ff03SJohn Baldwin {
1035c915ff03SJohn Baldwin
1036c915ff03SJohn Baldwin switch (ke->filter) {
1037c915ff03SJohn Baldwin case EVFILT_READ:
1038c915ff03SJohn Baldwin case EVFILT_WRITE:
1039c915ff03SJohn Baldwin case EVFILT_VNODE:
1040c915ff03SJohn Baldwin case EVFILT_PROC:
1041c915ff03SJohn Baldwin case EVFILT_TIMER:
1042c915ff03SJohn Baldwin case EVFILT_PROCDESC:
1043ffb66079SJohn Baldwin case EVFILT_EMPTY:
1044c915ff03SJohn Baldwin fprintf(fp, "%ju", (uintmax_t)ke->ident);
1045c915ff03SJohn Baldwin break;
1046c915ff03SJohn Baldwin case EVFILT_SIGNAL:
1047c915ff03SJohn Baldwin fputs(strsig2(ke->ident), fp);
1048c915ff03SJohn Baldwin break;
1049c915ff03SJohn Baldwin default:
1050c915ff03SJohn Baldwin fprintf(fp, "%p", (void *)ke->ident);
1051c915ff03SJohn Baldwin }
1052ffb66079SJohn Baldwin fprintf(fp, ",");
1053ffb66079SJohn Baldwin print_integer_arg(sysdecode_kevent_filter, fp, ke->filter);
1054ffb66079SJohn Baldwin fprintf(fp, ",");
1055ffb66079SJohn Baldwin print_mask_arg(sysdecode_kevent_flags, fp, ke->flags);
1056ffb66079SJohn Baldwin fprintf(fp, ",");
1057ffb66079SJohn Baldwin sysdecode_kevent_fflags(fp, ke->filter, ke->fflags, 16);
10582b34e843SKonstantin Belousov fprintf(fp, ",%#jx,%p", (uintmax_t)ke->data, ke->udata);
1059c915ff03SJohn Baldwin }
1060c915ff03SJohn Baldwin
1061195aef99SBryan Drewery static void
print_utrace(FILE * fp,void * utrace_addr,size_t len)1062195aef99SBryan Drewery print_utrace(FILE *fp, void *utrace_addr, size_t len)
1063195aef99SBryan Drewery {
1064195aef99SBryan Drewery unsigned char *utrace_buffer;
1065195aef99SBryan Drewery
1066195aef99SBryan Drewery fprintf(fp, "{ ");
1067d6fb4894SJohn Baldwin if (sysdecode_utrace(fp, utrace_addr, len)) {
1068195aef99SBryan Drewery fprintf(fp, " }");
1069195aef99SBryan Drewery return;
1070195aef99SBryan Drewery }
1071195aef99SBryan Drewery
1072195aef99SBryan Drewery utrace_buffer = utrace_addr;
1073195aef99SBryan Drewery fprintf(fp, "%zu:", len);
1074195aef99SBryan Drewery while (len--)
1075195aef99SBryan Drewery fprintf(fp, " %02x", *utrace_buffer++);
1076195aef99SBryan Drewery fprintf(fp, " }");
1077195aef99SBryan Drewery }
1078195aef99SBryan Drewery
1079a2674e03SMichael Tuexen static void
print_pointer(FILE * fp,uintptr_t arg)1080cc86d14aSBrooks Davis print_pointer(FILE *fp, uintptr_t arg)
1081cc86d14aSBrooks Davis {
1082cc86d14aSBrooks Davis
1083cc86d14aSBrooks Davis fprintf(fp, "%p", (void *)arg);
1084cc86d14aSBrooks Davis }
1085cc86d14aSBrooks Davis
1086cc86d14aSBrooks Davis static void
print_sockaddr(FILE * fp,struct trussinfo * trussinfo,uintptr_t arg,socklen_t len)1087cc86d14aSBrooks Davis print_sockaddr(FILE *fp, struct trussinfo *trussinfo, uintptr_t arg,
1088cc86d14aSBrooks Davis socklen_t len)
1089a2674e03SMichael Tuexen {
1090a2674e03SMichael Tuexen char addr[64];
1091a2674e03SMichael Tuexen struct sockaddr_in *lsin;
1092a2674e03SMichael Tuexen struct sockaddr_in6 *lsin6;
1093a2674e03SMichael Tuexen struct sockaddr_un *sun;
1094a2674e03SMichael Tuexen struct sockaddr *sa;
1095a2674e03SMichael Tuexen u_char *q;
1096a2674e03SMichael Tuexen pid_t pid = trussinfo->curthread->proc->pid;
1097a2674e03SMichael Tuexen
1098cc86d14aSBrooks Davis if (arg == 0) {
1099a2674e03SMichael Tuexen fputs("NULL", fp);
1100a2674e03SMichael Tuexen return;
1101a2674e03SMichael Tuexen }
1102a2674e03SMichael Tuexen /* If the length is too small, just bail. */
1103a2674e03SMichael Tuexen if (len < sizeof(*sa)) {
1104cc86d14aSBrooks Davis print_pointer(fp, arg);
1105a2674e03SMichael Tuexen return;
1106a2674e03SMichael Tuexen }
1107a2674e03SMichael Tuexen
1108a2674e03SMichael Tuexen sa = calloc(1, len);
1109a2674e03SMichael Tuexen if (get_struct(pid, arg, sa, len) == -1) {
1110a2674e03SMichael Tuexen free(sa);
1111cc86d14aSBrooks Davis print_pointer(fp, arg);
1112a2674e03SMichael Tuexen return;
1113a2674e03SMichael Tuexen }
1114a2674e03SMichael Tuexen
1115a2674e03SMichael Tuexen switch (sa->sa_family) {
1116a2674e03SMichael Tuexen case AF_INET:
1117a2674e03SMichael Tuexen if (len < sizeof(*lsin))
1118a2674e03SMichael Tuexen goto sockaddr_short;
1119a2674e03SMichael Tuexen lsin = (struct sockaddr_in *)(void *)sa;
1120a2674e03SMichael Tuexen inet_ntop(AF_INET, &lsin->sin_addr, addr, sizeof(addr));
1121a2674e03SMichael Tuexen fprintf(fp, "{ AF_INET %s:%d }", addr,
1122a2674e03SMichael Tuexen htons(lsin->sin_port));
1123a2674e03SMichael Tuexen break;
1124a2674e03SMichael Tuexen case AF_INET6:
1125a2674e03SMichael Tuexen if (len < sizeof(*lsin6))
1126a2674e03SMichael Tuexen goto sockaddr_short;
1127a2674e03SMichael Tuexen lsin6 = (struct sockaddr_in6 *)(void *)sa;
1128a2674e03SMichael Tuexen inet_ntop(AF_INET6, &lsin6->sin6_addr, addr,
1129a2674e03SMichael Tuexen sizeof(addr));
1130a2674e03SMichael Tuexen fprintf(fp, "{ AF_INET6 [%s]:%d }", addr,
1131a2674e03SMichael Tuexen htons(lsin6->sin6_port));
1132a2674e03SMichael Tuexen break;
1133a2674e03SMichael Tuexen case AF_UNIX:
1134a2674e03SMichael Tuexen sun = (struct sockaddr_un *)sa;
1135a2674e03SMichael Tuexen fprintf(fp, "{ AF_UNIX \"%.*s\" }",
1136a2674e03SMichael Tuexen (int)(len - offsetof(struct sockaddr_un, sun_path)),
1137a2674e03SMichael Tuexen sun->sun_path);
1138a2674e03SMichael Tuexen break;
1139a2674e03SMichael Tuexen default:
1140a2674e03SMichael Tuexen sockaddr_short:
1141a2674e03SMichael Tuexen fprintf(fp,
1142a2674e03SMichael Tuexen "{ sa_len = %d, sa_family = %d, sa_data = {",
1143a2674e03SMichael Tuexen (int)sa->sa_len, (int)sa->sa_family);
1144a2674e03SMichael Tuexen for (q = (u_char *)sa->sa_data;
1145a2674e03SMichael Tuexen q < (u_char *)sa + len; q++)
1146a2674e03SMichael Tuexen fprintf(fp, "%s 0x%02x",
1147a2674e03SMichael Tuexen q == (u_char *)sa->sa_data ? "" : ",",
1148a2674e03SMichael Tuexen *q);
1149a2674e03SMichael Tuexen fputs(" } }", fp);
1150a2674e03SMichael Tuexen }
1151a2674e03SMichael Tuexen free(sa);
1152a2674e03SMichael Tuexen }
1153a2674e03SMichael Tuexen
1154a2674e03SMichael Tuexen #define IOV_LIMIT 16
1155a2674e03SMichael Tuexen
1156a2674e03SMichael Tuexen static void
print_iovec(FILE * fp,struct trussinfo * trussinfo,uintptr_t arg,int iovcnt)1157cc86d14aSBrooks Davis print_iovec(FILE *fp, struct trussinfo *trussinfo, uintptr_t arg, int iovcnt)
1158a2674e03SMichael Tuexen {
1159a2674e03SMichael Tuexen struct iovec iov[IOV_LIMIT];
1160a2674e03SMichael Tuexen size_t max_string = trussinfo->strsize;
1161a2674e03SMichael Tuexen char tmp2[max_string + 1], *tmp3;
1162a2674e03SMichael Tuexen size_t len;
1163a2674e03SMichael Tuexen pid_t pid = trussinfo->curthread->proc->pid;
1164a2674e03SMichael Tuexen int i;
1165a2674e03SMichael Tuexen bool buf_truncated, iov_truncated;
1166a2674e03SMichael Tuexen
1167a2674e03SMichael Tuexen if (iovcnt <= 0) {
1168cc86d14aSBrooks Davis print_pointer(fp, arg);
1169a2674e03SMichael Tuexen return;
1170a2674e03SMichael Tuexen }
1171a2674e03SMichael Tuexen if (iovcnt > IOV_LIMIT) {
1172a2674e03SMichael Tuexen iovcnt = IOV_LIMIT;
1173a2674e03SMichael Tuexen iov_truncated = true;
1174a2674e03SMichael Tuexen } else {
1175a2674e03SMichael Tuexen iov_truncated = false;
1176a2674e03SMichael Tuexen }
1177a2674e03SMichael Tuexen if (get_struct(pid, arg, &iov, iovcnt * sizeof(struct iovec)) == -1) {
1178cc86d14aSBrooks Davis print_pointer(fp, arg);
1179a2674e03SMichael Tuexen return;
1180a2674e03SMichael Tuexen }
1181a2674e03SMichael Tuexen
1182a2674e03SMichael Tuexen fputs("[", fp);
1183a2674e03SMichael Tuexen for (i = 0; i < iovcnt; i++) {
1184a2674e03SMichael Tuexen len = iov[i].iov_len;
1185a2674e03SMichael Tuexen if (len > max_string) {
1186a2674e03SMichael Tuexen len = max_string;
1187a2674e03SMichael Tuexen buf_truncated = true;
1188a2674e03SMichael Tuexen } else {
1189a2674e03SMichael Tuexen buf_truncated = false;
1190a2674e03SMichael Tuexen }
1191a2674e03SMichael Tuexen fprintf(fp, "%s{", (i > 0) ? "," : "");
1192cc86d14aSBrooks Davis if (len && get_struct(pid, (uintptr_t)iov[i].iov_base, &tmp2, len) != -1) {
1193a2674e03SMichael Tuexen tmp3 = malloc(len * 4 + 1);
1194a2674e03SMichael Tuexen while (len) {
1195a2674e03SMichael Tuexen if (strvisx(tmp3, tmp2, len,
1196a2674e03SMichael Tuexen VIS_CSTYLE|VIS_TAB|VIS_NL) <=
1197a2674e03SMichael Tuexen (int)max_string)
1198a2674e03SMichael Tuexen break;
1199a2674e03SMichael Tuexen len--;
1200a2674e03SMichael Tuexen buf_truncated = true;
1201a2674e03SMichael Tuexen }
1202a2674e03SMichael Tuexen fprintf(fp, "\"%s\"%s", tmp3,
1203a2674e03SMichael Tuexen buf_truncated ? "..." : "");
1204a2674e03SMichael Tuexen free(tmp3);
1205a2674e03SMichael Tuexen } else {
1206cc86d14aSBrooks Davis print_pointer(fp, (uintptr_t)iov[i].iov_base);
1207a2674e03SMichael Tuexen }
1208a2674e03SMichael Tuexen fprintf(fp, ",%zu}", iov[i].iov_len);
1209a2674e03SMichael Tuexen }
1210a2674e03SMichael Tuexen fprintf(fp, "%s%s", iov_truncated ? ",..." : "", "]");
1211a2674e03SMichael Tuexen }
1212a2674e03SMichael Tuexen
1213a2674e03SMichael Tuexen static void
print_sigval(FILE * fp,union sigval * sv)1214bb24ee2bSThomas Munro print_sigval(FILE *fp, union sigval *sv)
1215bb24ee2bSThomas Munro {
1216bb24ee2bSThomas Munro fprintf(fp, "{ %d, %p }", sv->sival_int, sv->sival_ptr);
1217bb24ee2bSThomas Munro }
1218bb24ee2bSThomas Munro
1219bb24ee2bSThomas Munro static void
print_sigevent(FILE * fp,struct sigevent * se)1220bb24ee2bSThomas Munro print_sigevent(FILE *fp, struct sigevent *se)
1221bb24ee2bSThomas Munro {
1222bb24ee2bSThomas Munro fputs("{ sigev_notify=", fp);
1223bb24ee2bSThomas Munro switch (se->sigev_notify) {
1224bb24ee2bSThomas Munro case SIGEV_NONE:
1225bb24ee2bSThomas Munro fputs("SIGEV_NONE", fp);
1226bb24ee2bSThomas Munro break;
1227bb24ee2bSThomas Munro case SIGEV_SIGNAL:
1228bb24ee2bSThomas Munro fprintf(fp, "SIGEV_SIGNAL, sigev_signo=%s, sigev_value=",
1229bb24ee2bSThomas Munro strsig2(se->sigev_signo));
1230bb24ee2bSThomas Munro print_sigval(fp, &se->sigev_value);
1231bb24ee2bSThomas Munro break;
1232bb24ee2bSThomas Munro case SIGEV_THREAD:
1233bb24ee2bSThomas Munro fputs("SIGEV_THREAD, sigev_value=", fp);
1234bb24ee2bSThomas Munro print_sigval(fp, &se->sigev_value);
1235bb24ee2bSThomas Munro break;
1236bb24ee2bSThomas Munro case SIGEV_KEVENT:
1237bb24ee2bSThomas Munro fprintf(fp, "SIGEV_KEVENT, sigev_notify_kqueue=%d, sigev_notify_kevent_flags=",
1238bb24ee2bSThomas Munro se->sigev_notify_kqueue);
1239bb24ee2bSThomas Munro print_mask_arg(sysdecode_kevent_flags, fp, se->sigev_notify_kevent_flags);
1240bb24ee2bSThomas Munro break;
1241bb24ee2bSThomas Munro case SIGEV_THREAD_ID:
1242bb24ee2bSThomas Munro fprintf(fp, "SIGEV_THREAD_ID, sigev_notify_thread_id=%d, sigev_signo=%s, sigev_value=",
1243bb24ee2bSThomas Munro se->sigev_notify_thread_id, strsig2(se->sigev_signo));
1244bb24ee2bSThomas Munro print_sigval(fp, &se->sigev_value);
1245bb24ee2bSThomas Munro break;
1246bb24ee2bSThomas Munro default:
1247bb24ee2bSThomas Munro fprintf(fp, "%d", se->sigev_notify);
1248bb24ee2bSThomas Munro break;
1249bb24ee2bSThomas Munro }
1250bb24ee2bSThomas Munro fputs(" }", fp);
1251bb24ee2bSThomas Munro }
1252bb24ee2bSThomas Munro
1253bb24ee2bSThomas Munro static void
print_aiocb(FILE * fp,struct aiocb * cb)1254bb24ee2bSThomas Munro print_aiocb(FILE *fp, struct aiocb *cb)
1255bb24ee2bSThomas Munro {
1256bb24ee2bSThomas Munro fprintf(fp, "{ %d,%jd,%p,%zu,%s,",
1257bb24ee2bSThomas Munro cb->aio_fildes,
1258bb24ee2bSThomas Munro cb->aio_offset,
1259bb24ee2bSThomas Munro cb->aio_buf,
1260bb24ee2bSThomas Munro cb->aio_nbytes,
1261bb24ee2bSThomas Munro xlookup(lio_opcodes, cb->aio_lio_opcode));
1262bb24ee2bSThomas Munro print_sigevent(fp, &cb->aio_sigevent);
1263bb24ee2bSThomas Munro fputs(" }", fp);
1264bb24ee2bSThomas Munro }
1265bb24ee2bSThomas Munro
1266bb24ee2bSThomas Munro static void
print_gen_cmsg(FILE * fp,struct cmsghdr * cmsghdr)1267a2674e03SMichael Tuexen print_gen_cmsg(FILE *fp, struct cmsghdr *cmsghdr)
1268a2674e03SMichael Tuexen {
1269a2674e03SMichael Tuexen u_char *q;
1270a2674e03SMichael Tuexen
1271a2674e03SMichael Tuexen fputs("{", fp);
1272a2674e03SMichael Tuexen for (q = CMSG_DATA(cmsghdr);
1273a2674e03SMichael Tuexen q < (u_char *)cmsghdr + cmsghdr->cmsg_len; q++) {
1274a2674e03SMichael Tuexen fprintf(fp, "%s0x%02x", q == CMSG_DATA(cmsghdr) ? "" : ",", *q);
1275a2674e03SMichael Tuexen }
1276a2674e03SMichael Tuexen fputs("}", fp);
1277a2674e03SMichael Tuexen }
1278a2674e03SMichael Tuexen
1279a2674e03SMichael Tuexen static void
print_sctp_initmsg(FILE * fp,struct sctp_initmsg * init)1280a2674e03SMichael Tuexen print_sctp_initmsg(FILE *fp, struct sctp_initmsg *init)
1281a2674e03SMichael Tuexen {
1282a2674e03SMichael Tuexen fprintf(fp, "{out=%u,", init->sinit_num_ostreams);
1283a2674e03SMichael Tuexen fprintf(fp, "in=%u,", init->sinit_max_instreams);
1284a2674e03SMichael Tuexen fprintf(fp, "max_rtx=%u,", init->sinit_max_attempts);
1285a2674e03SMichael Tuexen fprintf(fp, "max_rto=%u}", init->sinit_max_init_timeo);
1286a2674e03SMichael Tuexen }
1287a2674e03SMichael Tuexen
1288a2674e03SMichael Tuexen static void
print_sctp_sndrcvinfo(FILE * fp,bool receive,struct sctp_sndrcvinfo * info)128976785d6eSJohn Baldwin print_sctp_sndrcvinfo(FILE *fp, bool receive, struct sctp_sndrcvinfo *info)
1290a2674e03SMichael Tuexen {
1291a2674e03SMichael Tuexen fprintf(fp, "{sid=%u,", info->sinfo_stream);
129276785d6eSJohn Baldwin if (receive) {
1293a2674e03SMichael Tuexen fprintf(fp, "ssn=%u,", info->sinfo_ssn);
1294a2674e03SMichael Tuexen }
1295a2674e03SMichael Tuexen fputs("flgs=", fp);
1296a2674e03SMichael Tuexen sysdecode_sctp_sinfo_flags(fp, info->sinfo_flags);
1297a2674e03SMichael Tuexen fprintf(fp, ",ppid=%u,", ntohl(info->sinfo_ppid));
129876785d6eSJohn Baldwin if (!receive) {
1299a2674e03SMichael Tuexen fprintf(fp, "ctx=%u,", info->sinfo_context);
1300a2674e03SMichael Tuexen fprintf(fp, "ttl=%u,", info->sinfo_timetolive);
1301a2674e03SMichael Tuexen }
130276785d6eSJohn Baldwin if (receive) {
1303a2674e03SMichael Tuexen fprintf(fp, "tsn=%u,", info->sinfo_tsn);
1304a2674e03SMichael Tuexen fprintf(fp, "cumtsn=%u,", info->sinfo_cumtsn);
1305a2674e03SMichael Tuexen }
1306a2674e03SMichael Tuexen fprintf(fp, "id=%u}", info->sinfo_assoc_id);
1307a2674e03SMichael Tuexen }
1308a2674e03SMichael Tuexen
1309a2674e03SMichael Tuexen static void
print_sctp_sndinfo(FILE * fp,struct sctp_sndinfo * info)1310a2674e03SMichael Tuexen print_sctp_sndinfo(FILE *fp, struct sctp_sndinfo *info)
1311a2674e03SMichael Tuexen {
1312a2674e03SMichael Tuexen fprintf(fp, "{sid=%u,", info->snd_sid);
1313a2674e03SMichael Tuexen fputs("flgs=", fp);
1314a2674e03SMichael Tuexen print_mask_arg(sysdecode_sctp_snd_flags, fp, info->snd_flags);
1315a2674e03SMichael Tuexen fprintf(fp, ",ppid=%u,", ntohl(info->snd_ppid));
1316a2674e03SMichael Tuexen fprintf(fp, "ctx=%u,", info->snd_context);
1317a2674e03SMichael Tuexen fprintf(fp, "id=%u}", info->snd_assoc_id);
1318a2674e03SMichael Tuexen }
1319a2674e03SMichael Tuexen
1320a2674e03SMichael Tuexen static void
print_sctp_rcvinfo(FILE * fp,struct sctp_rcvinfo * info)1321a2674e03SMichael Tuexen print_sctp_rcvinfo(FILE *fp, struct sctp_rcvinfo *info)
1322a2674e03SMichael Tuexen {
1323a2674e03SMichael Tuexen fprintf(fp, "{sid=%u,", info->rcv_sid);
1324a2674e03SMichael Tuexen fprintf(fp, "ssn=%u,", info->rcv_ssn);
1325a2674e03SMichael Tuexen fputs("flgs=", fp);
1326a2674e03SMichael Tuexen print_mask_arg(sysdecode_sctp_rcv_flags, fp, info->rcv_flags);
1327a2674e03SMichael Tuexen fprintf(fp, ",ppid=%u,", ntohl(info->rcv_ppid));
1328a2674e03SMichael Tuexen fprintf(fp, "tsn=%u,", info->rcv_tsn);
1329a2674e03SMichael Tuexen fprintf(fp, "cumtsn=%u,", info->rcv_cumtsn);
1330a2674e03SMichael Tuexen fprintf(fp, "ctx=%u,", info->rcv_context);
1331a2674e03SMichael Tuexen fprintf(fp, "id=%u}", info->rcv_assoc_id);
1332a2674e03SMichael Tuexen }
1333a2674e03SMichael Tuexen
1334a2674e03SMichael Tuexen static void
print_sctp_nxtinfo(FILE * fp,struct sctp_nxtinfo * info)1335a2674e03SMichael Tuexen print_sctp_nxtinfo(FILE *fp, struct sctp_nxtinfo *info)
1336a2674e03SMichael Tuexen {
1337a2674e03SMichael Tuexen fprintf(fp, "{sid=%u,", info->nxt_sid);
1338a2674e03SMichael Tuexen fputs("flgs=", fp);
1339a2674e03SMichael Tuexen print_mask_arg(sysdecode_sctp_nxt_flags, fp, info->nxt_flags);
1340a2674e03SMichael Tuexen fprintf(fp, ",ppid=%u,", ntohl(info->nxt_ppid));
1341a2674e03SMichael Tuexen fprintf(fp, "len=%u,", info->nxt_length);
1342a2674e03SMichael Tuexen fprintf(fp, "id=%u}", info->nxt_assoc_id);
1343a2674e03SMichael Tuexen }
1344a2674e03SMichael Tuexen
1345a2674e03SMichael Tuexen static void
print_sctp_prinfo(FILE * fp,struct sctp_prinfo * info)1346a2674e03SMichael Tuexen print_sctp_prinfo(FILE *fp, struct sctp_prinfo *info)
1347a2674e03SMichael Tuexen {
1348a2674e03SMichael Tuexen fputs("{pol=", fp);
1349a2674e03SMichael Tuexen print_integer_arg(sysdecode_sctp_pr_policy, fp, info->pr_policy);
1350a2674e03SMichael Tuexen fprintf(fp, ",val=%u}", info->pr_value);
1351a2674e03SMichael Tuexen }
1352a2674e03SMichael Tuexen
1353a2674e03SMichael Tuexen static void
print_sctp_authinfo(FILE * fp,struct sctp_authinfo * info)1354a2674e03SMichael Tuexen print_sctp_authinfo(FILE *fp, struct sctp_authinfo *info)
1355a2674e03SMichael Tuexen {
1356a2674e03SMichael Tuexen fprintf(fp, "{num=%u}", info->auth_keynumber);
1357a2674e03SMichael Tuexen }
1358a2674e03SMichael Tuexen
1359a2674e03SMichael Tuexen static void
print_sctp_ipv4_addr(FILE * fp,struct in_addr * addr)1360a2674e03SMichael Tuexen print_sctp_ipv4_addr(FILE *fp, struct in_addr *addr)
1361a2674e03SMichael Tuexen {
1362a2674e03SMichael Tuexen char buf[INET_ADDRSTRLEN];
1363a2674e03SMichael Tuexen const char *s;
1364a2674e03SMichael Tuexen
1365a2674e03SMichael Tuexen s = inet_ntop(AF_INET, addr, buf, INET_ADDRSTRLEN);
1366a2674e03SMichael Tuexen if (s != NULL)
1367a2674e03SMichael Tuexen fprintf(fp, "{addr=%s}", s);
1368a2674e03SMichael Tuexen else
1369a2674e03SMichael Tuexen fputs("{addr=???}", fp);
1370a2674e03SMichael Tuexen }
1371a2674e03SMichael Tuexen
1372a2674e03SMichael Tuexen static void
print_sctp_ipv6_addr(FILE * fp,struct in6_addr * addr)1373a2674e03SMichael Tuexen print_sctp_ipv6_addr(FILE *fp, struct in6_addr *addr)
1374a2674e03SMichael Tuexen {
1375a2674e03SMichael Tuexen char buf[INET6_ADDRSTRLEN];
1376a2674e03SMichael Tuexen const char *s;
1377a2674e03SMichael Tuexen
1378a2674e03SMichael Tuexen s = inet_ntop(AF_INET6, addr, buf, INET6_ADDRSTRLEN);
1379a2674e03SMichael Tuexen if (s != NULL)
1380a2674e03SMichael Tuexen fprintf(fp, "{addr=%s}", s);
1381a2674e03SMichael Tuexen else
1382a2674e03SMichael Tuexen fputs("{addr=???}", fp);
1383a2674e03SMichael Tuexen }
1384a2674e03SMichael Tuexen
1385a2674e03SMichael Tuexen static void
print_sctp_cmsg(FILE * fp,bool receive,struct cmsghdr * cmsghdr)138676785d6eSJohn Baldwin print_sctp_cmsg(FILE *fp, bool receive, struct cmsghdr *cmsghdr)
1387a2674e03SMichael Tuexen {
1388a2674e03SMichael Tuexen void *data;
1389a2674e03SMichael Tuexen socklen_t len;
1390a2674e03SMichael Tuexen
1391a2674e03SMichael Tuexen len = cmsghdr->cmsg_len;
1392a2674e03SMichael Tuexen data = CMSG_DATA(cmsghdr);
1393a2674e03SMichael Tuexen switch (cmsghdr->cmsg_type) {
1394a2674e03SMichael Tuexen case SCTP_INIT:
1395a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_initmsg)))
1396a2674e03SMichael Tuexen print_sctp_initmsg(fp, (struct sctp_initmsg *)data);
1397a2674e03SMichael Tuexen else
1398a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1399a2674e03SMichael Tuexen break;
1400a2674e03SMichael Tuexen case SCTP_SNDRCV:
1401a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_sndrcvinfo)))
140276785d6eSJohn Baldwin print_sctp_sndrcvinfo(fp, receive,
1403a2674e03SMichael Tuexen (struct sctp_sndrcvinfo *)data);
1404a2674e03SMichael Tuexen else
1405a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1406a2674e03SMichael Tuexen break;
1407a2674e03SMichael Tuexen #if 0
1408a2674e03SMichael Tuexen case SCTP_EXTRCV:
1409a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_extrcvinfo)))
1410a2674e03SMichael Tuexen print_sctp_extrcvinfo(fp,
1411a2674e03SMichael Tuexen (struct sctp_extrcvinfo *)data);
1412a2674e03SMichael Tuexen else
1413a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1414a2674e03SMichael Tuexen break;
1415a2674e03SMichael Tuexen #endif
1416a2674e03SMichael Tuexen case SCTP_SNDINFO:
1417a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_sndinfo)))
1418a2674e03SMichael Tuexen print_sctp_sndinfo(fp, (struct sctp_sndinfo *)data);
1419a2674e03SMichael Tuexen else
1420a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1421a2674e03SMichael Tuexen break;
1422a2674e03SMichael Tuexen case SCTP_RCVINFO:
1423a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_rcvinfo)))
1424a2674e03SMichael Tuexen print_sctp_rcvinfo(fp, (struct sctp_rcvinfo *)data);
1425a2674e03SMichael Tuexen else
1426a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1427a2674e03SMichael Tuexen break;
1428a2674e03SMichael Tuexen case SCTP_NXTINFO:
1429a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_nxtinfo)))
1430a2674e03SMichael Tuexen print_sctp_nxtinfo(fp, (struct sctp_nxtinfo *)data);
1431a2674e03SMichael Tuexen else
1432a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1433a2674e03SMichael Tuexen break;
1434a2674e03SMichael Tuexen case SCTP_PRINFO:
1435a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_prinfo)))
1436a2674e03SMichael Tuexen print_sctp_prinfo(fp, (struct sctp_prinfo *)data);
1437a2674e03SMichael Tuexen else
1438a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1439a2674e03SMichael Tuexen break;
1440a2674e03SMichael Tuexen case SCTP_AUTHINFO:
1441a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct sctp_authinfo)))
1442a2674e03SMichael Tuexen print_sctp_authinfo(fp, (struct sctp_authinfo *)data);
1443a2674e03SMichael Tuexen else
1444a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1445a2674e03SMichael Tuexen break;
1446a2674e03SMichael Tuexen case SCTP_DSTADDRV4:
1447a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct in_addr)))
1448a2674e03SMichael Tuexen print_sctp_ipv4_addr(fp, (struct in_addr *)data);
1449a2674e03SMichael Tuexen else
1450a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1451a2674e03SMichael Tuexen break;
1452a2674e03SMichael Tuexen case SCTP_DSTADDRV6:
1453a2674e03SMichael Tuexen if (len == CMSG_LEN(sizeof(struct in6_addr)))
1454a2674e03SMichael Tuexen print_sctp_ipv6_addr(fp, (struct in6_addr *)data);
1455a2674e03SMichael Tuexen else
1456a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1457a2674e03SMichael Tuexen break;
1458a2674e03SMichael Tuexen default:
1459a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1460a2674e03SMichael Tuexen }
1461a2674e03SMichael Tuexen }
1462a2674e03SMichael Tuexen
1463a2674e03SMichael Tuexen static void
print_cmsgs(FILE * fp,pid_t pid,bool receive,struct msghdr * msghdr)146476785d6eSJohn Baldwin print_cmsgs(FILE *fp, pid_t pid, bool receive, struct msghdr *msghdr)
1465a2674e03SMichael Tuexen {
1466a2674e03SMichael Tuexen struct cmsghdr *cmsghdr;
1467a2674e03SMichael Tuexen char *cmsgbuf;
1468a2674e03SMichael Tuexen const char *temp;
1469a2674e03SMichael Tuexen socklen_t len;
1470a2674e03SMichael Tuexen int level, type;
1471a2674e03SMichael Tuexen bool first;
1472a2674e03SMichael Tuexen
1473a2674e03SMichael Tuexen len = msghdr->msg_controllen;
14746accaf4aSMichael Tuexen if (len == 0) {
14756accaf4aSMichael Tuexen fputs("{}", fp);
14766accaf4aSMichael Tuexen return;
14776accaf4aSMichael Tuexen }
1478a2674e03SMichael Tuexen cmsgbuf = calloc(1, len);
1479cc86d14aSBrooks Davis if (get_struct(pid, (uintptr_t)msghdr->msg_control, cmsgbuf, len) == -1) {
1480cc86d14aSBrooks Davis print_pointer(fp, (uintptr_t)msghdr->msg_control);
1481a2674e03SMichael Tuexen free(cmsgbuf);
14826accaf4aSMichael Tuexen return;
1483a2674e03SMichael Tuexen }
1484a2674e03SMichael Tuexen msghdr->msg_control = cmsgbuf;
1485a2674e03SMichael Tuexen first = true;
1486a2674e03SMichael Tuexen fputs("{", fp);
1487a2674e03SMichael Tuexen for (cmsghdr = CMSG_FIRSTHDR(msghdr);
1488a2674e03SMichael Tuexen cmsghdr != NULL;
1489a2674e03SMichael Tuexen cmsghdr = CMSG_NXTHDR(msghdr, cmsghdr)) {
14904b0c6fa0SMark Johnston if (cmsghdr->cmsg_len < sizeof(*cmsghdr)) {
14914b0c6fa0SMark Johnston fprintf(fp, "{<invalid cmsg, len=%u>}",
14924b0c6fa0SMark Johnston cmsghdr->cmsg_len);
14934b0c6fa0SMark Johnston if (cmsghdr->cmsg_len == 0) {
14944b0c6fa0SMark Johnston /* Avoid looping forever. */
14954b0c6fa0SMark Johnston break;
14964b0c6fa0SMark Johnston }
14974b0c6fa0SMark Johnston continue;
14984b0c6fa0SMark Johnston }
14994b0c6fa0SMark Johnston
1500a2674e03SMichael Tuexen level = cmsghdr->cmsg_level;
1501a2674e03SMichael Tuexen type = cmsghdr->cmsg_type;
1502a2674e03SMichael Tuexen len = cmsghdr->cmsg_len;
1503a2674e03SMichael Tuexen fprintf(fp, "%s{level=", first ? "" : ",");
1504a2674e03SMichael Tuexen print_integer_arg(sysdecode_sockopt_level, fp, level);
1505a2674e03SMichael Tuexen fputs(",type=", fp);
1506a2674e03SMichael Tuexen temp = sysdecode_cmsg_type(level, type);
1507a2674e03SMichael Tuexen if (temp) {
1508a2674e03SMichael Tuexen fputs(temp, fp);
1509a2674e03SMichael Tuexen } else {
1510a2674e03SMichael Tuexen fprintf(fp, "%d", type);
1511a2674e03SMichael Tuexen }
1512a2674e03SMichael Tuexen fputs(",data=", fp);
1513a2674e03SMichael Tuexen switch (level) {
1514a2674e03SMichael Tuexen case IPPROTO_SCTP:
151576785d6eSJohn Baldwin print_sctp_cmsg(fp, receive, cmsghdr);
1516a2674e03SMichael Tuexen break;
1517a2674e03SMichael Tuexen default:
1518a2674e03SMichael Tuexen print_gen_cmsg(fp, cmsghdr);
1519a2674e03SMichael Tuexen break;
1520a2674e03SMichael Tuexen }
1521a2674e03SMichael Tuexen fputs("}", fp);
1522b8ff144eSMichael Tuexen first = false;
1523a2674e03SMichael Tuexen }
1524a2674e03SMichael Tuexen fputs("}", fp);
1525a2674e03SMichael Tuexen free(cmsgbuf);
1526a2674e03SMichael Tuexen }
1527a2674e03SMichael Tuexen
152843ce0d90SKonstantin Belousov static void
print_sysctl_oid(FILE * fp,int * oid,size_t len)152943ec732aSPawel Biernacki print_sysctl_oid(FILE *fp, int *oid, size_t len)
153043ce0d90SKonstantin Belousov {
153143ec732aSPawel Biernacki size_t i;
153243ec732aSPawel Biernacki bool first;
153343ce0d90SKonstantin Belousov
153443ec732aSPawel Biernacki first = true;
153543ec732aSPawel Biernacki fprintf(fp, "{ ");
153643ec732aSPawel Biernacki for (i = 0; i < len; i++) {
153743ec732aSPawel Biernacki fprintf(fp, "%s%d", first ? "" : ".", oid[i]);
153843ec732aSPawel Biernacki first = false;
153943ec732aSPawel Biernacki }
154043ec732aSPawel Biernacki fprintf(fp, " }");
154143ec732aSPawel Biernacki }
154243ec732aSPawel Biernacki
154343ec732aSPawel Biernacki static void
print_sysctl(FILE * fp,int * oid,size_t len)154443ec732aSPawel Biernacki print_sysctl(FILE *fp, int *oid, size_t len)
154543ec732aSPawel Biernacki {
154643ec732aSPawel Biernacki char name[BUFSIZ];
154743ec732aSPawel Biernacki int qoid[CTL_MAXNAME + 2];
154843ec732aSPawel Biernacki size_t i;
154943ec732aSPawel Biernacki
155043ec732aSPawel Biernacki qoid[0] = CTL_SYSCTL;
155143ec732aSPawel Biernacki qoid[1] = CTL_SYSCTL_NAME;
155243ec732aSPawel Biernacki memcpy(qoid + 2, oid, len * sizeof(int));
155343ec732aSPawel Biernacki i = sizeof(name);
155443ec732aSPawel Biernacki if (sysctl(qoid, len + 2, name, &i, 0, 0) == -1)
155543ec732aSPawel Biernacki print_sysctl_oid(fp, oid, len);
155643ec732aSPawel Biernacki else
155743ec732aSPawel Biernacki fprintf(fp, "%s", name);
155843ce0d90SKonstantin Belousov }
155943ce0d90SKonstantin Belousov
1560bbeaf6c0SSean Eric Fagan /*
15619a86a3cdSEd Maste * Convert a 32-bit user-space pointer to psaddr_t by zero-extending.
156231dddc6aSAlex Richardson */
156331dddc6aSAlex Richardson static psaddr_t
user_ptr32_to_psaddr(int32_t user_pointer)156431dddc6aSAlex Richardson user_ptr32_to_psaddr(int32_t user_pointer)
156531dddc6aSAlex Richardson {
156631dddc6aSAlex Richardson return ((psaddr_t)(uintptr_t)user_pointer);
156731dddc6aSAlex Richardson }
156831dddc6aSAlex Richardson
156931dddc6aSAlex Richardson /*
1570bbeaf6c0SSean Eric Fagan * Converts a syscall argument into a string. Said string is
15714e3da534SJohn Baldwin * allocated via malloc(), so needs to be free()'d. sc is
1572bbeaf6c0SSean Eric Fagan * a pointer to the syscall description (see above); args is
1573bbeaf6c0SSean Eric Fagan * an array of all of the system call arguments.
1574bbeaf6c0SSean Eric Fagan */
1575bbeaf6c0SSean Eric Fagan char *
print_arg(struct syscall_arg * sc,syscallarg_t * args,syscallarg_t * retval,struct trussinfo * trussinfo)1576b1ad6a90SBrooks Davis print_arg(struct syscall_arg *sc, syscallarg_t *args, syscallarg_t *retval,
157794355cfdSAndrey Zonov struct trussinfo *trussinfo)
1578d8984f48SDag-Erling Smørgrav {
1579f083f689SJohn Baldwin FILE *fp;
158094355cfdSAndrey Zonov char *tmp;
1581f083f689SJohn Baldwin size_t tmplen;
158294355cfdSAndrey Zonov pid_t pid;
1583d8984f48SDag-Erling Smørgrav
1584f083f689SJohn Baldwin fp = open_memstream(&tmp, &tmplen);
15852b75c8adSJohn Baldwin pid = trussinfo->curthread->proc->pid;
1586bbeaf6c0SSean Eric Fagan switch (sc->type & ARG_MASK) {
1587bbeaf6c0SSean Eric Fagan case Hex:
1588f083f689SJohn Baldwin fprintf(fp, "0x%x", (int)args[sc->offset]);
1589bbeaf6c0SSean Eric Fagan break;
1590bbeaf6c0SSean Eric Fagan case Octal:
1591f083f689SJohn Baldwin fprintf(fp, "0%o", (int)args[sc->offset]);
1592bbeaf6c0SSean Eric Fagan break;
1593bbeaf6c0SSean Eric Fagan case Int:
1594f083f689SJohn Baldwin fprintf(fp, "%d", (int)args[sc->offset]);
1595bbeaf6c0SSean Eric Fagan break;
1596808d9805SEd Schouten case UInt:
1597808d9805SEd Schouten fprintf(fp, "%u", (unsigned int)args[sc->offset]);
1598808d9805SEd Schouten break;
1599ebb2cc40SJohn Baldwin case PUInt: {
1600ebb2cc40SJohn Baldwin unsigned int val;
1601ebb2cc40SJohn Baldwin
1602cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &val,
1603ebb2cc40SJohn Baldwin sizeof(val)) == 0)
1604ebb2cc40SJohn Baldwin fprintf(fp, "{ %u }", val);
1605ebb2cc40SJohn Baldwin else
1606cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1607ebb2cc40SJohn Baldwin break;
1608ebb2cc40SJohn Baldwin }
1609fdb5bf37SJohn Baldwin case LongHex:
1610b1ad6a90SBrooks Davis fprintf(fp, "0x%lx", (long)args[sc->offset]);
1611fdb5bf37SJohn Baldwin break;
1612b289a8d7SJohn Baldwin case Long:
1613b1ad6a90SBrooks Davis fprintf(fp, "%ld", (long)args[sc->offset]);
1614b289a8d7SJohn Baldwin break;
1615e261fb2aSJohn Baldwin case Sizet:
1616e261fb2aSJohn Baldwin fprintf(fp, "%zu", (size_t)args[sc->offset]);
1617e261fb2aSJohn Baldwin break;
16185b05dc5aSThomas Munro case ShmName:
16195b05dc5aSThomas Munro /* Handle special SHM_ANON value. */
162031dddc6aSAlex Richardson if ((char *)(uintptr_t)args[sc->offset] == SHM_ANON) {
16215b05dc5aSThomas Munro fprintf(fp, "SHM_ANON");
16225b05dc5aSThomas Munro break;
16235b05dc5aSThomas Munro }
16245b05dc5aSThomas Munro /* FALLTHROUGH */
1625d8984f48SDag-Erling Smørgrav case Name: {
1626081e5c48SPav Lucistnik /* NULL-terminated string. */
1627bbeaf6c0SSean Eric Fagan char *tmp2;
16284e3da534SJohn Baldwin
1629cc86d14aSBrooks Davis tmp2 = get_string(pid, args[sc->offset], 0);
1630f083f689SJohn Baldwin fprintf(fp, "\"%s\"", tmp2);
1631bbeaf6c0SSean Eric Fagan free(tmp2);
1632bbeaf6c0SSean Eric Fagan break;
1633d8984f48SDag-Erling Smørgrav }
1634d8984f48SDag-Erling Smørgrav case BinString: {
16354e3da534SJohn Baldwin /*
16364e3da534SJohn Baldwin * Binary block of data that might have printable characters.
16374e3da534SJohn Baldwin * XXX If type|OUT, assume that the length is the syscall's
16384e3da534SJohn Baldwin * return value. Otherwise, assume that the length of the block
16394e3da534SJohn Baldwin * is in the next syscall argument.
16404e3da534SJohn Baldwin */
1641081e5c48SPav Lucistnik int max_string = trussinfo->strsize;
1642081e5c48SPav Lucistnik char tmp2[max_string + 1], *tmp3;
1643081e5c48SPav Lucistnik int len;
1644081e5c48SPav Lucistnik int truncated = 0;
1645081e5c48SPav Lucistnik
1646081e5c48SPav Lucistnik if (sc->type & OUT)
16472b75c8adSJohn Baldwin len = retval[0];
1648081e5c48SPav Lucistnik else
1649081e5c48SPav Lucistnik len = args[sc->offset + 1];
1650081e5c48SPav Lucistnik
16514e3da534SJohn Baldwin /*
16524e3da534SJohn Baldwin * Don't print more than max_string characters, to avoid word
16534e3da534SJohn Baldwin * wrap. If we have to truncate put some ... after the string.
1654081e5c48SPav Lucistnik */
1655081e5c48SPav Lucistnik if (len > max_string) {
1656081e5c48SPav Lucistnik len = max_string;
1657081e5c48SPav Lucistnik truncated = 1;
1658081e5c48SPav Lucistnik }
1659cc86d14aSBrooks Davis if (len && get_struct(pid, args[sc->offset], &tmp2, len)
166094355cfdSAndrey Zonov != -1) {
1661081e5c48SPav Lucistnik tmp3 = malloc(len * 4 + 1);
1662081e5c48SPav Lucistnik while (len) {
166394355cfdSAndrey Zonov if (strvisx(tmp3, tmp2, len,
166494355cfdSAndrey Zonov VIS_CSTYLE|VIS_TAB|VIS_NL) <= max_string)
1665081e5c48SPav Lucistnik break;
1666081e5c48SPav Lucistnik len--;
1667081e5c48SPav Lucistnik truncated = 1;
166880c7cc1cSPedro F. Giffuni }
1669f083f689SJohn Baldwin fprintf(fp, "\"%s\"%s", tmp3, truncated ?
167094355cfdSAndrey Zonov "..." : "");
1671081e5c48SPav Lucistnik free(tmp3);
1672d8984f48SDag-Erling Smørgrav } else {
1673cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1674081e5c48SPav Lucistnik }
1675081e5c48SPav Lucistnik break;
1676d8984f48SDag-Erling Smørgrav }
167768055893SJohn Baldwin case ExecArgs:
167868055893SJohn Baldwin case ExecEnv:
1679d8984f48SDag-Erling Smørgrav case StringArray: {
168031dddc6aSAlex Richardson psaddr_t addr;
1681890843c1SJohn Baldwin union {
16827daca4e2SAlex Richardson int32_t strarray32[PAGE_SIZE / sizeof(int32_t)];
16837daca4e2SAlex Richardson int64_t strarray64[PAGE_SIZE / sizeof(int64_t)];
1684890843c1SJohn Baldwin char buf[PAGE_SIZE];
1685890843c1SJohn Baldwin } u;
16869897b203SMatthew N. Dodd char *string;
1687890843c1SJohn Baldwin size_t len;
16882b75c8adSJohn Baldwin u_int first, i;
16897daca4e2SAlex Richardson size_t pointer_size =
16907daca4e2SAlex Richardson trussinfo->curthread->proc->abi->pointer_size;
16919897b203SMatthew N. Dodd
1692890843c1SJohn Baldwin /*
169368055893SJohn Baldwin * Only parse argv[] and environment arrays from exec calls
169468055893SJohn Baldwin * if requested.
169568055893SJohn Baldwin */
169668055893SJohn Baldwin if (((sc->type & ARG_MASK) == ExecArgs &&
169768055893SJohn Baldwin (trussinfo->flags & EXECVEARGS) == 0) ||
169868055893SJohn Baldwin ((sc->type & ARG_MASK) == ExecEnv &&
169968055893SJohn Baldwin (trussinfo->flags & EXECVEENVS) == 0)) {
1700cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
170168055893SJohn Baldwin break;
170268055893SJohn Baldwin }
170368055893SJohn Baldwin
170468055893SJohn Baldwin /*
1705890843c1SJohn Baldwin * Read a page of pointers at a time. Punt if the top-level
1706890843c1SJohn Baldwin * pointer is not aligned. Note that the first read is of
1707890843c1SJohn Baldwin * a partial page.
1708890843c1SJohn Baldwin */
1709890843c1SJohn Baldwin addr = args[sc->offset];
171031dddc6aSAlex Richardson if (!__is_aligned(addr, pointer_size)) {
1711cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1712890843c1SJohn Baldwin break;
17139897b203SMatthew N. Dodd }
17149897b203SMatthew N. Dodd
1715890843c1SJohn Baldwin len = PAGE_SIZE - (addr & PAGE_MASK);
1716cc86d14aSBrooks Davis if (get_struct(pid, addr, u.buf, len) == -1) {
1717cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1718890843c1SJohn Baldwin break;
17199897b203SMatthew N. Dodd }
17207daca4e2SAlex Richardson assert(len > 0);
1721890843c1SJohn Baldwin
1722890843c1SJohn Baldwin fputc('[', fp);
1723890843c1SJohn Baldwin first = 1;
1724890843c1SJohn Baldwin i = 0;
17257daca4e2SAlex Richardson for (;;) {
172631dddc6aSAlex Richardson psaddr_t straddr;
17277daca4e2SAlex Richardson if (pointer_size == 4) {
172831dddc6aSAlex Richardson straddr = user_ptr32_to_psaddr(u.strarray32[i]);
17297daca4e2SAlex Richardson } else if (pointer_size == 8) {
173031dddc6aSAlex Richardson straddr = (psaddr_t)u.strarray64[i];
17317daca4e2SAlex Richardson } else {
17327daca4e2SAlex Richardson errx(1, "Unsupported pointer size: %zu",
17337daca4e2SAlex Richardson pointer_size);
17347daca4e2SAlex Richardson }
173531dddc6aSAlex Richardson
173631dddc6aSAlex Richardson /* Stop once we read the first NULL pointer. */
173731dddc6aSAlex Richardson if (straddr == 0)
173831dddc6aSAlex Richardson break;
17397daca4e2SAlex Richardson string = get_string(pid, straddr, 0);
1740890843c1SJohn Baldwin fprintf(fp, "%s \"%s\"", first ? "" : ",", string);
1741890843c1SJohn Baldwin free(string);
1742890843c1SJohn Baldwin first = 0;
1743890843c1SJohn Baldwin
1744890843c1SJohn Baldwin i++;
17457daca4e2SAlex Richardson if (i == len / pointer_size) {
1746890843c1SJohn Baldwin addr += len;
1747890843c1SJohn Baldwin len = PAGE_SIZE;
17487daca4e2SAlex Richardson if (get_struct(pid, addr, u.buf, len) == -1) {
1749890843c1SJohn Baldwin fprintf(fp, ", <inval>");
1750890843c1SJohn Baldwin break;
1751890843c1SJohn Baldwin }
1752890843c1SJohn Baldwin i = 0;
1753890843c1SJohn Baldwin }
1754890843c1SJohn Baldwin }
1755890843c1SJohn Baldwin fputs(" ]", fp);
17569897b203SMatthew N. Dodd break;
1757d8984f48SDag-Erling Smørgrav }
175872df19e7SJohn Baldwin case Quad:
175972df19e7SJohn Baldwin case QuadHex: {
17608ba2e89eSAlex Richardson uint64_t value;
17618ba2e89eSAlex Richardson size_t pointer_size =
17628ba2e89eSAlex Richardson trussinfo->curthread->proc->abi->pointer_size;
17634e3da534SJohn Baldwin
17648ba2e89eSAlex Richardson if (pointer_size == 4) {
17652b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN
17668ba2e89eSAlex Richardson value = (uint64_t)args[sc->offset + 1] << 32 |
17672b75c8adSJohn Baldwin args[sc->offset];
17682b75c8adSJohn Baldwin #else
17698ba2e89eSAlex Richardson value = (uint64_t)args[sc->offset] << 32 |
17702b75c8adSJohn Baldwin args[sc->offset + 1];
17712b75c8adSJohn Baldwin #endif
17728ba2e89eSAlex Richardson } else {
17738ba2e89eSAlex Richardson value = (uint64_t)args[sc->offset];
17748ba2e89eSAlex Richardson }
177572df19e7SJohn Baldwin if ((sc->type & ARG_MASK) == Quad)
17768ba2e89eSAlex Richardson fprintf(fp, "%jd", (intmax_t)value);
177772df19e7SJohn Baldwin else
17788ba2e89eSAlex Richardson fprintf(fp, "0x%jx", (intmax_t)value);
1779bbeaf6c0SSean Eric Fagan break;
1780bbeaf6c0SSean Eric Fagan }
1781b60a095bSJohn Baldwin case PQuadHex: {
1782b60a095bSJohn Baldwin uint64_t val;
1783b60a095bSJohn Baldwin
1784cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &val,
1785b60a095bSJohn Baldwin sizeof(val)) == 0)
1786b60a095bSJohn Baldwin fprintf(fp, "{ 0x%jx }", (uintmax_t)val);
1787b60a095bSJohn Baldwin else
1788cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1789b60a095bSJohn Baldwin break;
1790b60a095bSJohn Baldwin }
1791bbeaf6c0SSean Eric Fagan case Ptr:
1792cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1793bbeaf6c0SSean Eric Fagan break;
1794d8984f48SDag-Erling Smørgrav case Readlinkres: {
17952bae4eb3SAlfred Perlstein char *tmp2;
17964e3da534SJohn Baldwin
17972b75c8adSJohn Baldwin if (retval[0] == -1)
17982bae4eb3SAlfred Perlstein break;
1799cc86d14aSBrooks Davis tmp2 = get_string(pid, args[sc->offset], retval[0]);
1800f083f689SJohn Baldwin fprintf(fp, "\"%s\"", tmp2);
18012bae4eb3SAlfred Perlstein free(tmp2);
18022bae4eb3SAlfred Perlstein break;
1803d8984f48SDag-Erling Smørgrav }
1804d8984f48SDag-Erling Smørgrav case Ioctl: {
18054e3da534SJohn Baldwin const char *temp;
18064e3da534SJohn Baldwin unsigned long cmd;
18074e3da534SJohn Baldwin
18084e3da534SJohn Baldwin cmd = args[sc->offset];
1809265e5898SJohn Baldwin temp = sysdecode_ioctlname(cmd);
181094355cfdSAndrey Zonov if (temp)
1811f083f689SJohn Baldwin fputs(temp, fp);
181294355cfdSAndrey Zonov else {
1813f083f689SJohn Baldwin fprintf(fp, "0x%lx { IO%s%s 0x%lx('%c'), %lu, %lu }",
18144e3da534SJohn Baldwin cmd, cmd & IOC_OUT ? "R" : "",
18154e3da534SJohn Baldwin cmd & IOC_IN ? "W" : "", IOCGROUP(cmd),
18164e3da534SJohn Baldwin isprint(IOCGROUP(cmd)) ? (char)IOCGROUP(cmd) : '?',
18174e3da534SJohn Baldwin cmd & 0xFF, IOCPARM_LEN(cmd));
1818081e5c48SPav Lucistnik }
1819081e5c48SPav Lucistnik break;
1820d8984f48SDag-Erling Smørgrav }
1821d8984f48SDag-Erling Smørgrav case Timespec: {
1822e45a5a0dSDavid Malone struct timespec ts;
18234e3da534SJohn Baldwin
1824cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &ts, sizeof(ts)) != -1)
1825a1436773SJohn Baldwin fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec,
182694355cfdSAndrey Zonov ts.tv_nsec);
1827e45a5a0dSDavid Malone else
1828cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1829e45a5a0dSDavid Malone break;
1830d8984f48SDag-Erling Smørgrav }
18317d897327SJohn Baldwin case Timespec2: {
18327d897327SJohn Baldwin struct timespec ts[2];
18337d897327SJohn Baldwin const char *sep;
18347d897327SJohn Baldwin unsigned int i;
18357d897327SJohn Baldwin
1836cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &ts, sizeof(ts)) != -1) {
18371e2ec671SJohn Baldwin fputs("{ ", fp);
18387d897327SJohn Baldwin sep = "";
18397d897327SJohn Baldwin for (i = 0; i < nitems(ts); i++) {
18407d897327SJohn Baldwin fputs(sep, fp);
18417d897327SJohn Baldwin sep = ", ";
18427d897327SJohn Baldwin switch (ts[i].tv_nsec) {
18437d897327SJohn Baldwin case UTIME_NOW:
18447d897327SJohn Baldwin fprintf(fp, "UTIME_NOW");
18457d897327SJohn Baldwin break;
18467d897327SJohn Baldwin case UTIME_OMIT:
18477d897327SJohn Baldwin fprintf(fp, "UTIME_OMIT");
18487d897327SJohn Baldwin break;
18497d897327SJohn Baldwin default:
1850a1436773SJohn Baldwin fprintf(fp, "%jd.%09ld",
1851a1436773SJohn Baldwin (intmax_t)ts[i].tv_sec,
1852a1436773SJohn Baldwin ts[i].tv_nsec);
18537d897327SJohn Baldwin break;
18547d897327SJohn Baldwin }
18557d897327SJohn Baldwin }
18561e2ec671SJohn Baldwin fputs(" }", fp);
18577d897327SJohn Baldwin } else
1858cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
18597d897327SJohn Baldwin break;
18607d897327SJohn Baldwin }
1861d8984f48SDag-Erling Smørgrav case Timeval: {
1862e45a5a0dSDavid Malone struct timeval tv;
18634e3da534SJohn Baldwin
1864cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &tv, sizeof(tv)) != -1)
1865a1436773SJohn Baldwin fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec,
186694355cfdSAndrey Zonov tv.tv_usec);
1867081e5c48SPav Lucistnik else
1868cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1869081e5c48SPav Lucistnik break;
1870d8984f48SDag-Erling Smørgrav }
1871d8984f48SDag-Erling Smørgrav case Timeval2: {
1872081e5c48SPav Lucistnik struct timeval tv[2];
18734e3da534SJohn Baldwin
1874cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &tv, sizeof(tv)) != -1)
1875a1436773SJohn Baldwin fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
1876a1436773SJohn Baldwin (intmax_t)tv[0].tv_sec, tv[0].tv_usec,
1877a1436773SJohn Baldwin (intmax_t)tv[1].tv_sec, tv[1].tv_usec);
1878e45a5a0dSDavid Malone else
1879cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1880e45a5a0dSDavid Malone break;
1881d8984f48SDag-Erling Smørgrav }
1882d8984f48SDag-Erling Smørgrav case Itimerval: {
1883e45a5a0dSDavid Malone struct itimerval itv;
18844e3da534SJohn Baldwin
1885cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &itv, sizeof(itv)) != -1)
1886a1436773SJohn Baldwin fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
1887a1436773SJohn Baldwin (intmax_t)itv.it_interval.tv_sec,
1888081e5c48SPav Lucistnik itv.it_interval.tv_usec,
1889a1436773SJohn Baldwin (intmax_t)itv.it_value.tv_sec,
1890081e5c48SPav Lucistnik itv.it_value.tv_usec);
1891e45a5a0dSDavid Malone else
1892cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1893e45a5a0dSDavid Malone break;
1894d8984f48SDag-Erling Smørgrav }
18951c99a22aSSteven Hartland case LinuxSockArgs:
18961c99a22aSSteven Hartland {
18971c99a22aSSteven Hartland struct linux_socketcall_args largs;
18984e3da534SJohn Baldwin
1899cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], (void *)&largs,
1900fb7eabb0SJohn Baldwin sizeof(largs)) != -1)
1901f083f689SJohn Baldwin fprintf(fp, "{ %s, 0x%lx }",
1902fb7eabb0SJohn Baldwin lookup(linux_socketcall_ops, largs.what, 10),
19030a46af44SJohn Baldwin (long unsigned int)largs.args);
1904fb7eabb0SJohn Baldwin else
1905cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
19061c99a22aSSteven Hartland break;
19071c99a22aSSteven Hartland }
1908d8984f48SDag-Erling Smørgrav case Pollfd: {
1909e45a5a0dSDavid Malone /*
191094355cfdSAndrey Zonov * XXX: A Pollfd argument expects the /next/ syscall argument
191194355cfdSAndrey Zonov * to be the number of fds in the array. This matches the poll
191294355cfdSAndrey Zonov * syscall.
1913e45a5a0dSDavid Malone */
1914e45a5a0dSDavid Malone struct pollfd *pfd;
1915e45a5a0dSDavid Malone int numfds = args[sc->offset + 1];
1916f083f689SJohn Baldwin size_t bytes = sizeof(struct pollfd) * numfds;
1917f083f689SJohn Baldwin int i;
1918e45a5a0dSDavid Malone
1919e45a5a0dSDavid Malone if ((pfd = malloc(bytes)) == NULL)
1920f083f689SJohn Baldwin err(1, "Cannot malloc %zu bytes for pollfd array",
192194355cfdSAndrey Zonov bytes);
1922cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], pfd, bytes) != -1) {
1923f083f689SJohn Baldwin fputs("{", fp);
1924e45a5a0dSDavid Malone for (i = 0; i < numfds; i++) {
1925f083f689SJohn Baldwin fprintf(fp, " %d/%s", pfd[i].fd,
1926081e5c48SPav Lucistnik xlookup_bits(poll_flags, pfd[i].events));
1927e45a5a0dSDavid Malone }
1928f083f689SJohn Baldwin fputs(" }", fp);
1929d8984f48SDag-Erling Smørgrav } else {
1930cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1931e45a5a0dSDavid Malone }
1932d8984f48SDag-Erling Smørgrav free(pfd);
1933e45a5a0dSDavid Malone break;
1934d8984f48SDag-Erling Smørgrav }
1935d8984f48SDag-Erling Smørgrav case Fd_set: {
1936e45a5a0dSDavid Malone /*
193794355cfdSAndrey Zonov * XXX: A Fd_set argument expects the /first/ syscall argument
193894355cfdSAndrey Zonov * to be the number of fds in the array. This matches the
193994355cfdSAndrey Zonov * select syscall.
1940e45a5a0dSDavid Malone */
1941e45a5a0dSDavid Malone fd_set *fds;
1942e45a5a0dSDavid Malone int numfds = args[0];
1943f083f689SJohn Baldwin size_t bytes = _howmany(numfds, _NFDBITS) * _NFDBITS;
1944f083f689SJohn Baldwin int i;
1945e45a5a0dSDavid Malone
1946e45a5a0dSDavid Malone if ((fds = malloc(bytes)) == NULL)
1947f083f689SJohn Baldwin err(1, "Cannot malloc %zu bytes for fd_set array",
194894355cfdSAndrey Zonov bytes);
1949cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], fds, bytes) != -1) {
1950f083f689SJohn Baldwin fputs("{", fp);
1951e45a5a0dSDavid Malone for (i = 0; i < numfds; i++) {
1952f083f689SJohn Baldwin if (FD_ISSET(i, fds))
1953f083f689SJohn Baldwin fprintf(fp, " %d", i);
1954e45a5a0dSDavid Malone }
1955f083f689SJohn Baldwin fputs(" }", fp);
195694355cfdSAndrey Zonov } else
1957cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1958d8984f48SDag-Erling Smørgrav free(fds);
1959e45a5a0dSDavid Malone break;
1960d8984f48SDag-Erling Smørgrav }
196134763d1cSJohn Baldwin case Signal:
1962f083f689SJohn Baldwin fputs(strsig2(args[sc->offset]), fp);
1963f0ebbc29SDag-Erling Smørgrav break;
1964d8984f48SDag-Erling Smørgrav case Sigset: {
1965081e5c48SPav Lucistnik sigset_t ss;
1966f083f689SJohn Baldwin int i, first;
1967081e5c48SPav Lucistnik
1968cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], (void *)&ss,
196994355cfdSAndrey Zonov sizeof(ss)) == -1) {
1970cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
1971081e5c48SPav Lucistnik break;
1972081e5c48SPav Lucistnik }
1973f083f689SJohn Baldwin fputs("{ ", fp);
1974f083f689SJohn Baldwin first = 1;
1975d8984f48SDag-Erling Smørgrav for (i = 1; i < sys_nsig; i++) {
197634763d1cSJohn Baldwin if (sigismember(&ss, i)) {
1977f083f689SJohn Baldwin fprintf(fp, "%s%s", !first ? "|" : "",
19789289f547SJohn Baldwin strsig2(i));
1979f083f689SJohn Baldwin first = 0;
198034763d1cSJohn Baldwin }
1981081e5c48SPav Lucistnik }
1982f083f689SJohn Baldwin if (!first)
1983f083f689SJohn Baldwin fputc(' ', fp);
1984f083f689SJohn Baldwin fputc('}', fp);
1985081e5c48SPav Lucistnik break;
1986d8984f48SDag-Erling Smørgrav }
19879289f547SJohn Baldwin case Sigprocmask:
19889289f547SJohn Baldwin print_integer_arg(sysdecode_sigprocmask_how, fp,
19899289f547SJohn Baldwin args[sc->offset]);
1990894b8f7aSAlfred Perlstein break;
19919289f547SJohn Baldwin case Fcntlflag:
19924e3da534SJohn Baldwin /* XXX: Output depends on the value of the previous argument. */
19939289f547SJohn Baldwin if (sysdecode_fcntl_arg_p(args[sc->offset - 1]))
19949289f547SJohn Baldwin sysdecode_fcntl_arg(fp, args[sc->offset - 1],
19959289f547SJohn Baldwin args[sc->offset], 16);
1996081e5c48SPav Lucistnik break;
1997081e5c48SPav Lucistnik case Open:
19989289f547SJohn Baldwin print_mask_arg(sysdecode_open_flags, fp, args[sc->offset]);
1999081e5c48SPav Lucistnik break;
2000081e5c48SPav Lucistnik case Fcntl:
20019289f547SJohn Baldwin print_integer_arg(sysdecode_fcntl_cmd, fp, args[sc->offset]);
2002081e5c48SPav Lucistnik break;
2003f3f3e3c4SMateusz Guzik case Closerangeflags:
2004f3f3e3c4SMateusz Guzik print_mask_arg(sysdecode_close_range_flags, fp, args[sc->offset]);
2005f3f3e3c4SMateusz Guzik break;
2006894b8f7aSAlfred Perlstein case Mprot:
20079289f547SJohn Baldwin print_mask_arg(sysdecode_mmap_prot, fp, args[sc->offset]);
2008894b8f7aSAlfred Perlstein break;
20099289f547SJohn Baldwin case Mmapflags:
20109289f547SJohn Baldwin print_mask_arg(sysdecode_mmap_flags, fp, args[sc->offset]);
2011894b8f7aSAlfred Perlstein break;
2012fde3a7d1SAlfred Perlstein case Whence:
20139289f547SJohn Baldwin print_integer_arg(sysdecode_whence, fp, args[sc->offset]);
2014081e5c48SPav Lucistnik break;
2015bcca3425SKyle Evans case ShmFlags:
2016bcca3425SKyle Evans print_mask_arg(sysdecode_shmflags, fp, args[sc->offset]);
2017bcca3425SKyle Evans break;
2018081e5c48SPav Lucistnik case Sockdomain:
20199289f547SJohn Baldwin print_integer_arg(sysdecode_socketdomain, fp, args[sc->offset]);
2020081e5c48SPav Lucistnik break;
20219289f547SJohn Baldwin case Socktype:
20229289f547SJohn Baldwin print_mask_arg(sysdecode_socket_type, fp, args[sc->offset]);
2023081e5c48SPav Lucistnik break;
2024081e5c48SPav Lucistnik case Shutdown:
20259289f547SJohn Baldwin print_integer_arg(sysdecode_shutdown_how, fp, args[sc->offset]);
2026081e5c48SPav Lucistnik break;
2027081e5c48SPav Lucistnik case Resource:
20289289f547SJohn Baldwin print_integer_arg(sysdecode_rlimit, fp, args[sc->offset]);
2029081e5c48SPav Lucistnik break;
2030ee8aa41dSJohn Baldwin case RusageWho:
2031ee8aa41dSJohn Baldwin print_integer_arg(sysdecode_getrusage_who, fp, args[sc->offset]);
2032ee8aa41dSJohn Baldwin break;
2033081e5c48SPav Lucistnik case Pathconf:
203439a3a438SJohn Baldwin print_integer_arg(sysdecode_pathconf_name, fp, args[sc->offset]);
2035fde3a7d1SAlfred Perlstein break;
20369e1db66eSMark Johnston case Rforkflags:
20379289f547SJohn Baldwin print_mask_arg(sysdecode_rfork_flags, fp, args[sc->offset]);
20389e1db66eSMark Johnston break;
2039d8984f48SDag-Erling Smørgrav case Sockaddr: {
204066917ca9SJohn Baldwin socklen_t len;
20419ddd1412SDag-Erling Smørgrav
2042a7a08c7eSMarcel Moolenaar if (args[sc->offset] == 0) {
2043f083f689SJohn Baldwin fputs("NULL", fp);
2044a7a08c7eSMarcel Moolenaar break;
2045a7a08c7eSMarcel Moolenaar }
2046a7a08c7eSMarcel Moolenaar
20476a656761SAlfred Perlstein /*
204866917ca9SJohn Baldwin * Extract the address length from the next argument. If
204966917ca9SJohn Baldwin * this is an output sockaddr (OUT is set), then the
205066917ca9SJohn Baldwin * next argument is a pointer to a socklen_t. Otherwise
205166917ca9SJohn Baldwin * the next argument contains a socklen_t by value.
20526a656761SAlfred Perlstein */
205366917ca9SJohn Baldwin if (sc->type & OUT) {
2054cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset + 1], &len,
2055cc86d14aSBrooks Davis sizeof(len)) == -1) {
2056cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
20576a656761SAlfred Perlstein break;
20586a656761SAlfred Perlstein }
205966917ca9SJohn Baldwin } else
206066917ca9SJohn Baldwin len = args[sc->offset + 1];
206166917ca9SJohn Baldwin
2062cc86d14aSBrooks Davis print_sockaddr(fp, trussinfo, args[sc->offset], len);
20639ddd1412SDag-Erling Smørgrav break;
2064d8984f48SDag-Erling Smørgrav }
2065d8984f48SDag-Erling Smørgrav case Sigaction: {
2066e45a5a0dSDavid Malone struct sigaction sa;
2067e45a5a0dSDavid Malone
2068cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &sa, sizeof(sa)) != -1) {
2069f083f689SJohn Baldwin fputs("{ ", fp);
2070e45a5a0dSDavid Malone if (sa.sa_handler == SIG_DFL)
2071f083f689SJohn Baldwin fputs("SIG_DFL", fp);
2072e45a5a0dSDavid Malone else if (sa.sa_handler == SIG_IGN)
2073f083f689SJohn Baldwin fputs("SIG_IGN", fp);
2074e45a5a0dSDavid Malone else
2075f083f689SJohn Baldwin fprintf(fp, "%p", sa.sa_handler);
2076f083f689SJohn Baldwin fprintf(fp, " %s ss_t }",
2077081e5c48SPav Lucistnik xlookup_bits(sigaction_flags, sa.sa_flags));
207894355cfdSAndrey Zonov } else
2079cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2080e45a5a0dSDavid Malone break;
2081d8984f48SDag-Erling Smørgrav }
2082bb24ee2bSThomas Munro case Sigevent: {
2083bb24ee2bSThomas Munro struct sigevent se;
2084bb24ee2bSThomas Munro
2085bb24ee2bSThomas Munro if (get_struct(pid, args[sc->offset], &se, sizeof(se)) != -1)
2086bb24ee2bSThomas Munro print_sigevent(fp, &se);
2087bb24ee2bSThomas Munro else
2088bb24ee2bSThomas Munro print_pointer(fp, args[sc->offset]);
2089bb24ee2bSThomas Munro break;
2090bb24ee2bSThomas Munro }
2091d8984f48SDag-Erling Smørgrav case Kevent: {
2092081e5c48SPav Lucistnik /*
20934e3da534SJohn Baldwin * XXX XXX: The size of the array is determined by either the
2094081e5c48SPav Lucistnik * next syscall argument, or by the syscall return value,
2095081e5c48SPav Lucistnik * depending on which argument number we are. This matches the
2096081e5c48SPav Lucistnik * kevent syscall, but luckily that's the only syscall that uses
2097081e5c48SPav Lucistnik * them.
2098081e5c48SPav Lucistnik */
2099081e5c48SPav Lucistnik struct kevent *ke;
2100081e5c48SPav Lucistnik int numevents = -1;
2101f083f689SJohn Baldwin size_t bytes;
2102f083f689SJohn Baldwin int i;
2103081e5c48SPav Lucistnik
2104081e5c48SPav Lucistnik if (sc->offset == 1)
2105081e5c48SPav Lucistnik numevents = args[sc->offset+1];
21062b75c8adSJohn Baldwin else if (sc->offset == 3 && retval[0] != -1)
21072b75c8adSJohn Baldwin numevents = retval[0];
2108081e5c48SPav Lucistnik
2109f083f689SJohn Baldwin if (numevents >= 0) {
2110081e5c48SPav Lucistnik bytes = sizeof(struct kevent) * numevents;
2111081e5c48SPav Lucistnik if ((ke = malloc(bytes)) == NULL)
2112f083f689SJohn Baldwin err(1,
2113f083f689SJohn Baldwin "Cannot malloc %zu bytes for kevent array",
211494355cfdSAndrey Zonov bytes);
2115f083f689SJohn Baldwin } else
2116f083f689SJohn Baldwin ke = NULL;
2117cc86d14aSBrooks Davis if (numevents >= 0 && get_struct(pid, args[sc->offset],
211894355cfdSAndrey Zonov ke, bytes) != -1) {
2119f083f689SJohn Baldwin fputc('{', fp);
2120c915ff03SJohn Baldwin for (i = 0; i < numevents; i++) {
2121c915ff03SJohn Baldwin fputc(' ', fp);
2122ffb66079SJohn Baldwin print_kevent(fp, &ke[i]);
2123c915ff03SJohn Baldwin }
2124f083f689SJohn Baldwin fputs(" }", fp);
2125d8984f48SDag-Erling Smørgrav } else {
2126cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2127081e5c48SPav Lucistnik }
2128d8984f48SDag-Erling Smørgrav free(ke);
2129081e5c48SPav Lucistnik break;
2130d8984f48SDag-Erling Smørgrav }
2131ffb66079SJohn Baldwin case Kevent11: {
21328e4a3addSBrooks Davis struct freebsd11_kevent *ke11;
2133ffb66079SJohn Baldwin struct kevent ke;
2134ffb66079SJohn Baldwin int numevents = -1;
2135ffb66079SJohn Baldwin size_t bytes;
2136ffb66079SJohn Baldwin int i;
2137ffb66079SJohn Baldwin
2138ffb66079SJohn Baldwin if (sc->offset == 1)
2139ffb66079SJohn Baldwin numevents = args[sc->offset+1];
2140ffb66079SJohn Baldwin else if (sc->offset == 3 && retval[0] != -1)
2141ffb66079SJohn Baldwin numevents = retval[0];
2142ffb66079SJohn Baldwin
2143ffb66079SJohn Baldwin if (numevents >= 0) {
21448e4a3addSBrooks Davis bytes = sizeof(struct freebsd11_kevent) * numevents;
2145ffb66079SJohn Baldwin if ((ke11 = malloc(bytes)) == NULL)
2146ffb66079SJohn Baldwin err(1,
2147ffb66079SJohn Baldwin "Cannot malloc %zu bytes for kevent array",
2148ffb66079SJohn Baldwin bytes);
2149ffb66079SJohn Baldwin } else
2150ffb66079SJohn Baldwin ke11 = NULL;
2151ffb66079SJohn Baldwin memset(&ke, 0, sizeof(ke));
2152cc86d14aSBrooks Davis if (numevents >= 0 && get_struct(pid, args[sc->offset],
2153ffb66079SJohn Baldwin ke11, bytes) != -1) {
2154ffb66079SJohn Baldwin fputc('{', fp);
2155ffb66079SJohn Baldwin for (i = 0; i < numevents; i++) {
2156ffb66079SJohn Baldwin fputc(' ', fp);
2157ffb66079SJohn Baldwin ke.ident = ke11[i].ident;
2158ffb66079SJohn Baldwin ke.filter = ke11[i].filter;
2159ffb66079SJohn Baldwin ke.flags = ke11[i].flags;
2160ffb66079SJohn Baldwin ke.fflags = ke11[i].fflags;
2161ffb66079SJohn Baldwin ke.data = ke11[i].data;
2162ffb66079SJohn Baldwin ke.udata = ke11[i].udata;
2163ffb66079SJohn Baldwin print_kevent(fp, &ke);
2164ffb66079SJohn Baldwin }
2165ffb66079SJohn Baldwin fputs(" }", fp);
2166ffb66079SJohn Baldwin } else {
2167cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2168ffb66079SJohn Baldwin }
2169ffb66079SJohn Baldwin free(ke11);
2170ffb66079SJohn Baldwin break;
2171ffb66079SJohn Baldwin }
2172d8984f48SDag-Erling Smørgrav case Stat: {
2173081e5c48SPav Lucistnik struct stat st;
21744e3da534SJohn Baldwin
2175cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &st, sizeof(st))
217694355cfdSAndrey Zonov != -1) {
2177081e5c48SPav Lucistnik char mode[12];
21784e3da534SJohn Baldwin
2179081e5c48SPav Lucistnik strmode(st.st_mode, mode);
2180f083f689SJohn Baldwin fprintf(fp,
2181b38fbc2eSJohn Baldwin "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode,
2182b38fbc2eSJohn Baldwin (uintmax_t)st.st_ino, (intmax_t)st.st_size,
218394355cfdSAndrey Zonov (long)st.st_blksize);
2184d8984f48SDag-Erling Smørgrav } else {
2185cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2186081e5c48SPav Lucistnik }
2187081e5c48SPav Lucistnik break;
2188d8984f48SDag-Erling Smørgrav }
21898207f12dSWarner Losh case Stat11: {
21908207f12dSWarner Losh struct freebsd11_stat st;
21918207f12dSWarner Losh
2192cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &st, sizeof(st))
21938207f12dSWarner Losh != -1) {
21948207f12dSWarner Losh char mode[12];
21958207f12dSWarner Losh
21968207f12dSWarner Losh strmode(st.st_mode, mode);
21978207f12dSWarner Losh fprintf(fp,
21988207f12dSWarner Losh "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode,
21998207f12dSWarner Losh (uintmax_t)st.st_ino, (intmax_t)st.st_size,
22008207f12dSWarner Losh (long)st.st_blksize);
22018207f12dSWarner Losh } else {
2202cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
22038207f12dSWarner Losh }
22048207f12dSWarner Losh break;
22058207f12dSWarner Losh }
2206a776866bSBryan Drewery case StatFs: {
2207a776866bSBryan Drewery unsigned int i;
2208a776866bSBryan Drewery struct statfs buf;
22090a71c082SBryan Drewery
2210cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &buf,
2211a776866bSBryan Drewery sizeof(buf)) != -1) {
2212a776866bSBryan Drewery char fsid[17];
2213a776866bSBryan Drewery
2214a776866bSBryan Drewery bzero(fsid, sizeof(fsid));
2215a776866bSBryan Drewery if (buf.f_fsid.val[0] != 0 || buf.f_fsid.val[1] != 0) {
2216a776866bSBryan Drewery for (i = 0; i < sizeof(buf.f_fsid); i++)
2217a776866bSBryan Drewery snprintf(&fsid[i*2],
2218a776866bSBryan Drewery sizeof(fsid) - (i*2), "%02x",
2219a776866bSBryan Drewery ((u_char *)&buf.f_fsid)[i]);
2220a776866bSBryan Drewery }
2221a776866bSBryan Drewery fprintf(fp,
2222a776866bSBryan Drewery "{ fstypename=%s,mntonname=%s,mntfromname=%s,"
2223a776866bSBryan Drewery "fsid=%s }", buf.f_fstypename, buf.f_mntonname,
2224a776866bSBryan Drewery buf.f_mntfromname, fsid);
2225a776866bSBryan Drewery } else
2226cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2227a776866bSBryan Drewery break;
2228a776866bSBryan Drewery }
2229a776866bSBryan Drewery
2230d8984f48SDag-Erling Smørgrav case Rusage: {
2231081e5c48SPav Lucistnik struct rusage ru;
22324e3da534SJohn Baldwin
2233cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &ru, sizeof(ru))
223494355cfdSAndrey Zonov != -1) {
2235f083f689SJohn Baldwin fprintf(fp,
2236a1436773SJohn Baldwin "{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }",
2237a1436773SJohn Baldwin (intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec,
2238a1436773SJohn Baldwin (intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec,
2239081e5c48SPav Lucistnik ru.ru_inblock, ru.ru_oublock);
224094355cfdSAndrey Zonov } else
2241cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2242081e5c48SPav Lucistnik break;
2243d8984f48SDag-Erling Smørgrav }
2244d8984f48SDag-Erling Smørgrav case Rlimit: {
2245081e5c48SPav Lucistnik struct rlimit rl;
22464e3da534SJohn Baldwin
2247cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &rl, sizeof(rl))
224894355cfdSAndrey Zonov != -1) {
2249f083f689SJohn Baldwin fprintf(fp, "{ cur=%ju,max=%ju }",
2250081e5c48SPav Lucistnik rl.rlim_cur, rl.rlim_max);
225194355cfdSAndrey Zonov } else
2252cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2253081e5c48SPav Lucistnik break;
2254d8984f48SDag-Erling Smørgrav }
225534763d1cSJohn Baldwin case ExitStatus: {
225634763d1cSJohn Baldwin int status;
2257f083f689SJohn Baldwin
2258cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &status,
225934763d1cSJohn Baldwin sizeof(status)) != -1) {
2260f083f689SJohn Baldwin fputs("{ ", fp);
226134763d1cSJohn Baldwin if (WIFCONTINUED(status))
2262f083f689SJohn Baldwin fputs("CONTINUED", fp);
226334763d1cSJohn Baldwin else if (WIFEXITED(status))
2264f083f689SJohn Baldwin fprintf(fp, "EXITED,val=%d",
226534763d1cSJohn Baldwin WEXITSTATUS(status));
226634763d1cSJohn Baldwin else if (WIFSIGNALED(status))
2267f083f689SJohn Baldwin fprintf(fp, "SIGNALED,sig=%s%s",
2268f083f689SJohn Baldwin strsig2(WTERMSIG(status)),
226934763d1cSJohn Baldwin WCOREDUMP(status) ? ",cored" : "");
227034763d1cSJohn Baldwin else
2271f083f689SJohn Baldwin fprintf(fp, "STOPPED,sig=%s",
2272f083f689SJohn Baldwin strsig2(WTERMSIG(status)));
2273f083f689SJohn Baldwin fputs(" }", fp);
227434763d1cSJohn Baldwin } else
2275cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
227634763d1cSJohn Baldwin break;
227734763d1cSJohn Baldwin }
227834763d1cSJohn Baldwin case Waitoptions:
22799289f547SJohn Baldwin print_mask_arg(sysdecode_wait6_options, fp, args[sc->offset]);
228034763d1cSJohn Baldwin break;
228134763d1cSJohn Baldwin case Idtype:
22829289f547SJohn Baldwin print_integer_arg(sysdecode_idtype, fp, args[sc->offset]);
228334763d1cSJohn Baldwin break;
228455648840SJohn Baldwin case Procctl:
22859289f547SJohn Baldwin print_integer_arg(sysdecode_procctl_cmd, fp, args[sc->offset]);
228655648840SJohn Baldwin break;
2287c2679dd7SKyle Evans case Umtxop: {
2288c2679dd7SKyle Evans int rem;
2289c2679dd7SKyle Evans
2290c2679dd7SKyle Evans if (print_mask_arg_part(sysdecode_umtx_op_flags, fp,
2291c2679dd7SKyle Evans args[sc->offset], &rem))
2292c2679dd7SKyle Evans fprintf(fp, "|");
2293c2679dd7SKyle Evans print_integer_arg(sysdecode_umtx_op, fp, rem);
2294fdb5bf37SJohn Baldwin break;
2295c2679dd7SKyle Evans }
22967d897327SJohn Baldwin case Atfd:
22979289f547SJohn Baldwin print_integer_arg(sysdecode_atfd, fp, args[sc->offset]);
22987d897327SJohn Baldwin break;
22997d897327SJohn Baldwin case Atflags:
230039a3a438SJohn Baldwin print_mask_arg(sysdecode_atflags, fp, args[sc->offset]);
23017d897327SJohn Baldwin break;
23027d897327SJohn Baldwin case Accessmode:
23039289f547SJohn Baldwin print_mask_arg(sysdecode_access_mode, fp, args[sc->offset]);
23047d897327SJohn Baldwin break;
2305b289a8d7SJohn Baldwin case Sysarch:
230639a3a438SJohn Baldwin print_integer_arg(sysdecode_sysarch_number, fp,
230739a3a438SJohn Baldwin args[sc->offset]);
2308b289a8d7SJohn Baldwin break;
230943ce0d90SKonstantin Belousov case Sysctl: {
231043ce0d90SKonstantin Belousov char name[BUFSIZ];
231143ec732aSPawel Biernacki int oid[CTL_MAXNAME + 2];
231243ec732aSPawel Biernacki size_t len;
231343ce0d90SKonstantin Belousov
231443ce0d90SKonstantin Belousov memset(name, 0, sizeof(name));
231543ce0d90SKonstantin Belousov len = args[sc->offset + 1];
2316cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], oid,
231743ce0d90SKonstantin Belousov len * sizeof(oid[0])) != -1) {
231843ce0d90SKonstantin Belousov fprintf(fp, "\"");
231943ce0d90SKonstantin Belousov if (oid[0] == CTL_SYSCTL) {
232043ce0d90SKonstantin Belousov fprintf(fp, "sysctl.");
232143ce0d90SKonstantin Belousov switch (oid[1]) {
232243ce0d90SKonstantin Belousov case CTL_SYSCTL_DEBUG:
232343ce0d90SKonstantin Belousov fprintf(fp, "debug");
232443ce0d90SKonstantin Belousov break;
232543ce0d90SKonstantin Belousov case CTL_SYSCTL_NAME:
232643ce0d90SKonstantin Belousov fprintf(fp, "name ");
232743ce0d90SKonstantin Belousov print_sysctl_oid(fp, oid + 2, len - 2);
232843ce0d90SKonstantin Belousov break;
232943ce0d90SKonstantin Belousov case CTL_SYSCTL_NEXT:
233043ce0d90SKonstantin Belousov fprintf(fp, "next");
233143ce0d90SKonstantin Belousov break;
233243ce0d90SKonstantin Belousov case CTL_SYSCTL_NAME2OID:
233343ec732aSPawel Biernacki fprintf(fp, "name2oid %s",
233443ec732aSPawel Biernacki get_string(pid,
233543ec732aSPawel Biernacki args[sc->offset + 4],
233643ec732aSPawel Biernacki args[sc->offset + 5]));
233743ce0d90SKonstantin Belousov break;
233843ce0d90SKonstantin Belousov case CTL_SYSCTL_OIDFMT:
233943ce0d90SKonstantin Belousov fprintf(fp, "oidfmt ");
234043ec732aSPawel Biernacki print_sysctl(fp, oid + 2, len - 2);
234143ce0d90SKonstantin Belousov break;
234243ce0d90SKonstantin Belousov case CTL_SYSCTL_OIDDESCR:
234343ce0d90SKonstantin Belousov fprintf(fp, "oiddescr ");
234443ec732aSPawel Biernacki print_sysctl(fp, oid + 2, len - 2);
234543ce0d90SKonstantin Belousov break;
234643ce0d90SKonstantin Belousov case CTL_SYSCTL_OIDLABEL:
234743ce0d90SKonstantin Belousov fprintf(fp, "oidlabel ");
234843ec732aSPawel Biernacki print_sysctl(fp, oid + 2, len - 2);
234943ce0d90SKonstantin Belousov break;
235092e17803SRyan Moeller case CTL_SYSCTL_NEXTNOSKIP:
235192e17803SRyan Moeller fprintf(fp, "nextnoskip");
235292e17803SRyan Moeller break;
235343ce0d90SKonstantin Belousov default:
235443ec732aSPawel Biernacki print_sysctl(fp, oid + 1, len - 1);
235543ce0d90SKonstantin Belousov }
235643ce0d90SKonstantin Belousov } else {
235743ec732aSPawel Biernacki print_sysctl(fp, oid, len);
235843ce0d90SKonstantin Belousov }
235943ce0d90SKonstantin Belousov fprintf(fp, "\"");
236043ce0d90SKonstantin Belousov }
236143ce0d90SKonstantin Belousov break;
236243ce0d90SKonstantin Belousov }
23632b75c8adSJohn Baldwin case PipeFds:
23642b75c8adSJohn Baldwin /*
23652b75c8adSJohn Baldwin * The pipe() system call in the kernel returns its
23662b75c8adSJohn Baldwin * two file descriptors via return values. However,
23672b75c8adSJohn Baldwin * the interface exposed by libc is that pipe()
23682b75c8adSJohn Baldwin * accepts a pointer to an array of descriptors.
23692b75c8adSJohn Baldwin * Format the output to match the libc API by printing
23702b75c8adSJohn Baldwin * the returned file descriptors as a fake argument.
23712b75c8adSJohn Baldwin *
23722b75c8adSJohn Baldwin * Overwrite the first retval to signal a successful
23732b75c8adSJohn Baldwin * return as well.
23742b75c8adSJohn Baldwin */
2375caa449b6SJohn Baldwin fprintf(fp, "{ %d, %d }", (int)retval[0], (int)retval[1]);
23762b75c8adSJohn Baldwin retval[0] = 0;
23772b75c8adSJohn Baldwin break;
2378195aef99SBryan Drewery case Utrace: {
2379195aef99SBryan Drewery size_t len;
2380195aef99SBryan Drewery void *utrace_addr;
2381195aef99SBryan Drewery
2382195aef99SBryan Drewery len = args[sc->offset + 1];
2383195aef99SBryan Drewery utrace_addr = calloc(1, len);
2384cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset],
2385195aef99SBryan Drewery (void *)utrace_addr, len) != -1)
2386195aef99SBryan Drewery print_utrace(fp, utrace_addr, len);
2387195aef99SBryan Drewery else
2388cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2389195aef99SBryan Drewery free(utrace_addr);
2390195aef99SBryan Drewery break;
2391195aef99SBryan Drewery }
2392808d9805SEd Schouten case IntArray: {
2393808d9805SEd Schouten int descriptors[16];
2394808d9805SEd Schouten unsigned long i, ndescriptors;
2395808d9805SEd Schouten bool truncated;
2396808d9805SEd Schouten
2397808d9805SEd Schouten ndescriptors = args[sc->offset + 1];
2398808d9805SEd Schouten truncated = false;
2399808d9805SEd Schouten if (ndescriptors > nitems(descriptors)) {
2400808d9805SEd Schouten ndescriptors = nitems(descriptors);
2401808d9805SEd Schouten truncated = true;
2402808d9805SEd Schouten }
2403cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset],
2404808d9805SEd Schouten descriptors, ndescriptors * sizeof(descriptors[0])) != -1) {
2405808d9805SEd Schouten fprintf(fp, "{");
2406808d9805SEd Schouten for (i = 0; i < ndescriptors; i++)
2407808d9805SEd Schouten fprintf(fp, i == 0 ? " %d" : ", %d",
2408808d9805SEd Schouten descriptors[i]);
2409808d9805SEd Schouten fprintf(fp, truncated ? ", ... }" : " }");
2410808d9805SEd Schouten } else
2411cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2412808d9805SEd Schouten break;
2413808d9805SEd Schouten }
24149289f547SJohn Baldwin case Pipe2:
24159289f547SJohn Baldwin print_mask_arg(sysdecode_pipe2_flags, fp, args[sc->offset]);
24169289f547SJohn Baldwin break;
2417bed418c8SJohn Baldwin case CapFcntlRights: {
2418bed418c8SJohn Baldwin uint32_t rights;
2419bed418c8SJohn Baldwin
2420bed418c8SJohn Baldwin if (sc->type & OUT) {
2421cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &rights,
2422bed418c8SJohn Baldwin sizeof(rights)) == -1) {
2423cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2424bed418c8SJohn Baldwin break;
2425bed418c8SJohn Baldwin }
2426bed418c8SJohn Baldwin } else
2427bed418c8SJohn Baldwin rights = args[sc->offset];
2428bed418c8SJohn Baldwin print_mask_arg32(sysdecode_cap_fcntlrights, fp, rights);
2429bed418c8SJohn Baldwin break;
2430bed418c8SJohn Baldwin }
2431d2a97485SJohn Baldwin case Fadvice:
2432d2a97485SJohn Baldwin print_integer_arg(sysdecode_fadvice, fp, args[sc->offset]);
2433d2a97485SJohn Baldwin break;
243427459358SJohn Baldwin case FileFlags: {
243527459358SJohn Baldwin fflags_t rem;
243627459358SJohn Baldwin
243727459358SJohn Baldwin if (!sysdecode_fileflags(fp, args[sc->offset], &rem))
243827459358SJohn Baldwin fprintf(fp, "0x%x", rem);
243927459358SJohn Baldwin else if (rem != 0)
244027459358SJohn Baldwin fprintf(fp, "|0x%x", rem);
244127459358SJohn Baldwin break;
244227459358SJohn Baldwin }
2443dd92181fSJohn Baldwin case Flockop:
2444dd92181fSJohn Baldwin print_mask_arg(sysdecode_flock_operation, fp, args[sc->offset]);
2445dd92181fSJohn Baldwin break;
2446ab43bedcSJohn Baldwin case Getfsstatmode:
2447ab43bedcSJohn Baldwin print_integer_arg(sysdecode_getfsstat_mode, fp,
2448ab43bedcSJohn Baldwin args[sc->offset]);
2449ab43bedcSJohn Baldwin break;
2450b9b86b67SDmitry Chagin case Itimerwhich:
2451b9b86b67SDmitry Chagin print_integer_arg(sysdecode_itimer, fp, args[sc->offset]);
2452b9b86b67SDmitry Chagin break;
245394e854c5SJohn Baldwin case Kldsymcmd:
245494e854c5SJohn Baldwin print_integer_arg(sysdecode_kldsym_cmd, fp, args[sc->offset]);
245594e854c5SJohn Baldwin break;
245694e854c5SJohn Baldwin case Kldunloadflags:
245794e854c5SJohn Baldwin print_integer_arg(sysdecode_kldunload_flags, fp,
245894e854c5SJohn Baldwin args[sc->offset]);
245994e854c5SJohn Baldwin break;
2460bb24ee2bSThomas Munro case AiofsyncOp:
2461bb24ee2bSThomas Munro fputs(xlookup(aio_fsync_ops, args[sc->offset]), fp);
2462bb24ee2bSThomas Munro break;
2463bb24ee2bSThomas Munro case LioMode:
2464bb24ee2bSThomas Munro fputs(xlookup(lio_modes, args[sc->offset]), fp);
2465bb24ee2bSThomas Munro break;
246698fdbeecSJohn Baldwin case Madvice:
246798fdbeecSJohn Baldwin print_integer_arg(sysdecode_madvice, fp, args[sc->offset]);
246898fdbeecSJohn Baldwin break;
246958227c60SMichael Tuexen case Socklent:
247058227c60SMichael Tuexen fprintf(fp, "%u", (socklen_t)args[sc->offset]);
247158227c60SMichael Tuexen break;
2472ecac235bSMichael Tuexen case Sockprotocol: {
2473738a93a4SMichael Tuexen const char *temp;
2474738a93a4SMichael Tuexen int domain, protocol;
2475ecac235bSMichael Tuexen
2476738a93a4SMichael Tuexen domain = args[sc->offset - 2];
2477ecac235bSMichael Tuexen protocol = args[sc->offset];
2478ecac235bSMichael Tuexen if (protocol == 0) {
2479ecac235bSMichael Tuexen fputs("0", fp);
2480ecac235bSMichael Tuexen } else {
2481738a93a4SMichael Tuexen temp = sysdecode_socket_protocol(domain, protocol);
2482738a93a4SMichael Tuexen if (temp) {
2483738a93a4SMichael Tuexen fputs(temp, fp);
2484738a93a4SMichael Tuexen } else {
2485738a93a4SMichael Tuexen fprintf(fp, "%d", protocol);
2486738a93a4SMichael Tuexen }
2487ecac235bSMichael Tuexen }
2488ecac235bSMichael Tuexen break;
2489ecac235bSMichael Tuexen }
2490832af457SMichael Tuexen case Sockoptlevel:
2491832af457SMichael Tuexen print_integer_arg(sysdecode_sockopt_level, fp,
2492832af457SMichael Tuexen args[sc->offset]);
2493832af457SMichael Tuexen break;
2494832af457SMichael Tuexen case Sockoptname: {
2495832af457SMichael Tuexen const char *temp;
2496832af457SMichael Tuexen int level, name;
2497832af457SMichael Tuexen
2498832af457SMichael Tuexen level = args[sc->offset - 1];
2499832af457SMichael Tuexen name = args[sc->offset];
2500832af457SMichael Tuexen temp = sysdecode_sockopt_name(level, name);
2501832af457SMichael Tuexen if (temp) {
2502832af457SMichael Tuexen fputs(temp, fp);
2503832af457SMichael Tuexen } else {
2504832af457SMichael Tuexen fprintf(fp, "%d", name);
2505832af457SMichael Tuexen }
2506832af457SMichael Tuexen break;
2507832af457SMichael Tuexen }
25088b429b65SMichael Tuexen case Msgflags:
25098b429b65SMichael Tuexen print_mask_arg(sysdecode_msg_flags, fp, args[sc->offset]);
25108b429b65SMichael Tuexen break;
25117136a1d9SJohn Baldwin case CapRights: {
25127136a1d9SJohn Baldwin cap_rights_t rights;
25137136a1d9SJohn Baldwin
2514cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &rights,
25157136a1d9SJohn Baldwin sizeof(rights)) != -1) {
25167136a1d9SJohn Baldwin fputs("{ ", fp);
25177136a1d9SJohn Baldwin sysdecode_cap_rights(fp, &rights);
25187136a1d9SJohn Baldwin fputs(" }", fp);
25197136a1d9SJohn Baldwin } else
2520cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
25217136a1d9SJohn Baldwin break;
25227136a1d9SJohn Baldwin }
25237ce44f08SJohn Baldwin case Acltype:
25247ce44f08SJohn Baldwin print_integer_arg(sysdecode_acltype, fp, args[sc->offset]);
25257ce44f08SJohn Baldwin break;
252626606dcaSJohn Baldwin case Extattrnamespace:
252726606dcaSJohn Baldwin print_integer_arg(sysdecode_extattrnamespace, fp,
252826606dcaSJohn Baldwin args[sc->offset]);
252926606dcaSJohn Baldwin break;
25302d9c9988SJohn Baldwin case Minherit:
25312d9c9988SJohn Baldwin print_integer_arg(sysdecode_minherit_inherit, fp,
25322d9c9988SJohn Baldwin args[sc->offset]);
25332d9c9988SJohn Baldwin break;
253494bde755SJohn Baldwin case Mlockall:
253594bde755SJohn Baldwin print_mask_arg(sysdecode_mlockall_flags, fp, args[sc->offset]);
253694bde755SJohn Baldwin break;
25378acc8e78SJohn Baldwin case Mountflags:
25388acc8e78SJohn Baldwin print_mask_arg(sysdecode_mount_flags, fp, args[sc->offset]);
25398acc8e78SJohn Baldwin break;
2540114aeee0SJohn Baldwin case Msync:
2541114aeee0SJohn Baldwin print_mask_arg(sysdecode_msync_flags, fp, args[sc->offset]);
2542114aeee0SJohn Baldwin break;
2543ad419d33SJohn Baldwin case Priowhich:
2544ad419d33SJohn Baldwin print_integer_arg(sysdecode_prio_which, fp, args[sc->offset]);
2545ad419d33SJohn Baldwin break;
25465ac1c7acSJohn Baldwin case Ptraceop:
25475ac1c7acSJohn Baldwin print_integer_arg(sysdecode_ptrace_request, fp,
25485ac1c7acSJohn Baldwin args[sc->offset]);
25495ac1c7acSJohn Baldwin break;
255090da2c79SMark Johnston case Sendfileflags:
255190da2c79SMark Johnston print_mask_arg(sysdecode_sendfile_flags, fp, args[sc->offset]);
255290da2c79SMark Johnston break;
255390da2c79SMark Johnston case Sendfilehdtr: {
255490da2c79SMark Johnston struct sf_hdtr hdtr;
255590da2c79SMark Johnston
255690da2c79SMark Johnston if (get_struct(pid, args[sc->offset], &hdtr, sizeof(hdtr)) !=
255790da2c79SMark Johnston -1) {
255890da2c79SMark Johnston fprintf(fp, "{");
255990da2c79SMark Johnston print_iovec(fp, trussinfo, (uintptr_t)hdtr.headers,
256090da2c79SMark Johnston hdtr.hdr_cnt);
256190da2c79SMark Johnston print_iovec(fp, trussinfo, (uintptr_t)hdtr.trailers,
256290da2c79SMark Johnston hdtr.trl_cnt);
256390da2c79SMark Johnston fprintf(fp, "}");
256490da2c79SMark Johnston } else
256590da2c79SMark Johnston print_pointer(fp, args[sc->offset]);
256690da2c79SMark Johnston break;
256790da2c79SMark Johnston }
2568dd0c462cSJohn Baldwin case Quotactlcmd:
2569dd0c462cSJohn Baldwin if (!sysdecode_quotactl_cmd(fp, args[sc->offset]))
2570dd0c462cSJohn Baldwin fprintf(fp, "%#x", (int)args[sc->offset]);
2571dd0c462cSJohn Baldwin break;
25724152441fSJohn Baldwin case Reboothowto:
25734152441fSJohn Baldwin print_mask_arg(sysdecode_reboot_howto, fp, args[sc->offset]);
25744152441fSJohn Baldwin break;
25753cd40bc3SJohn Baldwin case Rtpriofunc:
25763cd40bc3SJohn Baldwin print_integer_arg(sysdecode_rtprio_function, fp,
25773cd40bc3SJohn Baldwin args[sc->offset]);
25783cd40bc3SJohn Baldwin break;
2579a4110f9fSJohn Baldwin case Schedpolicy:
2580a4110f9fSJohn Baldwin print_integer_arg(sysdecode_scheduler_policy, fp,
2581a4110f9fSJohn Baldwin args[sc->offset]);
2582a4110f9fSJohn Baldwin break;
2583a4110f9fSJohn Baldwin case Schedparam: {
2584a4110f9fSJohn Baldwin struct sched_param sp;
2585a4110f9fSJohn Baldwin
2586cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &sp, sizeof(sp)) != -1)
2587a4110f9fSJohn Baldwin fprintf(fp, "{ %d }", sp.sched_priority);
2588a4110f9fSJohn Baldwin else
2589cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2590a4110f9fSJohn Baldwin break;
2591a4110f9fSJohn Baldwin }
259213e5e6b6SJohn Baldwin case PSig: {
259313e5e6b6SJohn Baldwin int sig;
259413e5e6b6SJohn Baldwin
2595cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &sig, sizeof(sig)) == 0)
259613e5e6b6SJohn Baldwin fprintf(fp, "{ %s }", strsig2(sig));
259713e5e6b6SJohn Baldwin else
2598cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
259913e5e6b6SJohn Baldwin break;
260013e5e6b6SJohn Baldwin }
260113e5e6b6SJohn Baldwin case Siginfo: {
260213e5e6b6SJohn Baldwin siginfo_t si;
260313e5e6b6SJohn Baldwin
2604cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset], &si, sizeof(si)) != -1) {
260513e5e6b6SJohn Baldwin fprintf(fp, "{ signo=%s", strsig2(si.si_signo));
260613e5e6b6SJohn Baldwin decode_siginfo(fp, &si);
260713e5e6b6SJohn Baldwin fprintf(fp, " }");
260813e5e6b6SJohn Baldwin } else
2609cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
261013e5e6b6SJohn Baldwin break;
261113e5e6b6SJohn Baldwin }
2612a2674e03SMichael Tuexen case Iovec:
2613ee6e58b2SMichael Tuexen /*
2614ee6e58b2SMichael Tuexen * Print argument as an array of struct iovec, where the next
2615ee6e58b2SMichael Tuexen * syscall argument is the number of elements of the array.
2616ee6e58b2SMichael Tuexen */
2617ee6e58b2SMichael Tuexen
2618cc86d14aSBrooks Davis print_iovec(fp, trussinfo, args[sc->offset],
2619a2674e03SMichael Tuexen (int)args[sc->offset + 1]);
2620ee6e58b2SMichael Tuexen break;
2621bb24ee2bSThomas Munro case Aiocb: {
2622bb24ee2bSThomas Munro struct aiocb cb;
2623bb24ee2bSThomas Munro
2624bb24ee2bSThomas Munro if (get_struct(pid, args[sc->offset], &cb, sizeof(cb)) != -1)
2625bb24ee2bSThomas Munro print_aiocb(fp, &cb);
2626bb24ee2bSThomas Munro else
2627bb24ee2bSThomas Munro print_pointer(fp, args[sc->offset]);
2628bb24ee2bSThomas Munro break;
2629bb24ee2bSThomas Munro }
2630bb24ee2bSThomas Munro case AiocbArray: {
2631bb24ee2bSThomas Munro /*
2632bb24ee2bSThomas Munro * Print argment as an array of pointers to struct aiocb, where
2633bb24ee2bSThomas Munro * the next syscall argument is the number of elements.
2634bb24ee2bSThomas Munro */
2635bb24ee2bSThomas Munro uintptr_t cbs[16];
2636bb24ee2bSThomas Munro unsigned int nent;
2637bb24ee2bSThomas Munro bool truncated;
2638bb24ee2bSThomas Munro
2639bb24ee2bSThomas Munro nent = args[sc->offset + 1];
2640bb24ee2bSThomas Munro truncated = false;
2641bb24ee2bSThomas Munro if (nent > nitems(cbs)) {
2642bb24ee2bSThomas Munro nent = nitems(cbs);
2643bb24ee2bSThomas Munro truncated = true;
2644bb24ee2bSThomas Munro }
2645bb24ee2bSThomas Munro
2646bb24ee2bSThomas Munro if (get_struct(pid, args[sc->offset], cbs, sizeof(uintptr_t) * nent) != -1) {
2647bb24ee2bSThomas Munro unsigned int i;
2648bb24ee2bSThomas Munro fputs("[", fp);
2649bb24ee2bSThomas Munro for (i = 0; i < nent; ++i) {
2650bb24ee2bSThomas Munro struct aiocb cb;
2651bb24ee2bSThomas Munro if (i > 0)
2652bb24ee2bSThomas Munro fputc(',', fp);
2653bb24ee2bSThomas Munro if (get_struct(pid, cbs[i], &cb, sizeof(cb)) != -1)
2654bb24ee2bSThomas Munro print_aiocb(fp, &cb);
2655bb24ee2bSThomas Munro else
2656bb24ee2bSThomas Munro print_pointer(fp, cbs[i]);
2657bb24ee2bSThomas Munro }
2658bb24ee2bSThomas Munro if (truncated)
2659bb24ee2bSThomas Munro fputs(",...", fp);
2660bb24ee2bSThomas Munro fputs("]", fp);
2661bb24ee2bSThomas Munro } else
2662bb24ee2bSThomas Munro print_pointer(fp, args[sc->offset]);
2663bb24ee2bSThomas Munro break;
2664bb24ee2bSThomas Munro }
2665bb24ee2bSThomas Munro case AiocbPointer: {
2666bb24ee2bSThomas Munro /*
2667bb24ee2bSThomas Munro * aio_waitcomplete(2) assigns a pointer to a pointer to struct
2668bb24ee2bSThomas Munro * aiocb, so we need to handle the extra layer of indirection.
2669bb24ee2bSThomas Munro */
2670bb24ee2bSThomas Munro uintptr_t cbp;
2671bb24ee2bSThomas Munro struct aiocb cb;
2672bb24ee2bSThomas Munro
2673bb24ee2bSThomas Munro if (get_struct(pid, args[sc->offset], &cbp, sizeof(cbp)) != -1) {
2674bb24ee2bSThomas Munro if (get_struct(pid, cbp, &cb, sizeof(cb)) != -1)
2675bb24ee2bSThomas Munro print_aiocb(fp, &cb);
2676bb24ee2bSThomas Munro else
2677bb24ee2bSThomas Munro print_pointer(fp, cbp);
2678bb24ee2bSThomas Munro } else
2679bb24ee2bSThomas Munro print_pointer(fp, args[sc->offset]);
2680bb24ee2bSThomas Munro break;
2681bb24ee2bSThomas Munro }
26824d7b9809SMichael Tuexen case Sctpsndrcvinfo: {
26834d7b9809SMichael Tuexen struct sctp_sndrcvinfo info;
26844d7b9809SMichael Tuexen
2685cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset],
26864d7b9809SMichael Tuexen &info, sizeof(struct sctp_sndrcvinfo)) == -1) {
2687cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
26884d7b9809SMichael Tuexen break;
26894d7b9809SMichael Tuexen }
2690a2674e03SMichael Tuexen print_sctp_sndrcvinfo(fp, sc->type & OUT, &info);
2691a2674e03SMichael Tuexen break;
26924d7b9809SMichael Tuexen }
2693a2674e03SMichael Tuexen case Msghdr: {
2694a2674e03SMichael Tuexen struct msghdr msghdr;
2695a2674e03SMichael Tuexen
2696cc86d14aSBrooks Davis if (get_struct(pid, args[sc->offset],
2697a2674e03SMichael Tuexen &msghdr, sizeof(struct msghdr)) == -1) {
2698cc86d14aSBrooks Davis print_pointer(fp, args[sc->offset]);
2699a2674e03SMichael Tuexen break;
27004d7b9809SMichael Tuexen }
2701a2674e03SMichael Tuexen fputs("{", fp);
2702cc86d14aSBrooks Davis print_sockaddr(fp, trussinfo, (uintptr_t)msghdr.msg_name, msghdr.msg_namelen);
2703a2674e03SMichael Tuexen fprintf(fp, ",%d,", msghdr.msg_namelen);
2704cc86d14aSBrooks Davis print_iovec(fp, trussinfo, (uintptr_t)msghdr.msg_iov, msghdr.msg_iovlen);
2705a2674e03SMichael Tuexen fprintf(fp, ",%d,", msghdr.msg_iovlen);
2706a2674e03SMichael Tuexen print_cmsgs(fp, pid, sc->type & OUT, &msghdr);
2707a2674e03SMichael Tuexen fprintf(fp, ",%u,", msghdr.msg_controllen);
2708a2674e03SMichael Tuexen print_mask_arg(sysdecode_msg_flags, fp, msghdr.msg_flags);
2709a2674e03SMichael Tuexen fputs("}", fp);
27104d7b9809SMichael Tuexen break;
27114d7b9809SMichael Tuexen }
2712808d9805SEd Schouten
2713081e5c48SPav Lucistnik default:
2714081e5c48SPav Lucistnik errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK);
2715bbeaf6c0SSean Eric Fagan }
2716f083f689SJohn Baldwin fclose(fp);
2717d8984f48SDag-Erling Smørgrav return (tmp);
2718bbeaf6c0SSean Eric Fagan }
2719bbeaf6c0SSean Eric Fagan
2720bbeaf6c0SSean Eric Fagan /*
272100ddbdf2SJohn Baldwin * Print (to outfile) the system call and its arguments.
2722bbeaf6c0SSean Eric Fagan */
2723bbeaf6c0SSean Eric Fagan void
print_syscall(struct trussinfo * trussinfo)272400ddbdf2SJohn Baldwin print_syscall(struct trussinfo *trussinfo)
2725d8984f48SDag-Erling Smørgrav {
272600ddbdf2SJohn Baldwin struct threadinfo *t;
272700ddbdf2SJohn Baldwin const char *name;
272800ddbdf2SJohn Baldwin char **s_args;
272900ddbdf2SJohn Baldwin int i, len, nargs;
27300d0bd00eSMatthew N. Dodd
273100ddbdf2SJohn Baldwin t = trussinfo->curthread;
2732c03bfcc8SMatthew N. Dodd
27331175b23fSJohn Baldwin name = t->cs.sc->name;
273400ddbdf2SJohn Baldwin nargs = t->cs.nargs;
273500ddbdf2SJohn Baldwin s_args = t->cs.s_args;
27360d0bd00eSMatthew N. Dodd
2737d70876fdSJohn Baldwin len = print_line_prefix(trussinfo);
2738ec0bed25SMatthew N. Dodd len += fprintf(trussinfo->outfile, "%s(", name);
2739c03bfcc8SMatthew N. Dodd
2740bbeaf6c0SSean Eric Fagan for (i = 0; i < nargs; i++) {
274100ddbdf2SJohn Baldwin if (s_args[i] != NULL)
2742ec0bed25SMatthew N. Dodd len += fprintf(trussinfo->outfile, "%s", s_args[i]);
2743bbeaf6c0SSean Eric Fagan else
274494355cfdSAndrey Zonov len += fprintf(trussinfo->outfile,
274594355cfdSAndrey Zonov "<missing argument>");
274694355cfdSAndrey Zonov len += fprintf(trussinfo->outfile, "%s", i < (nargs - 1) ?
274794355cfdSAndrey Zonov "," : "");
2748bbeaf6c0SSean Eric Fagan }
2749ec0bed25SMatthew N. Dodd len += fprintf(trussinfo->outfile, ")");
27506cb533feSSean Eric Fagan for (i = 0; i < 6 - (len / 8); i++)
2751ec0bed25SMatthew N. Dodd fprintf(trussinfo->outfile, "\t");
27526cb533feSSean Eric Fagan }
27536cb533feSSean Eric Fagan
27546cb533feSSean Eric Fagan void
print_syscall_ret(struct trussinfo * trussinfo,int error,syscallarg_t * retval)2755b1ad6a90SBrooks Davis print_syscall_ret(struct trussinfo *trussinfo, int error, syscallarg_t *retval)
27561bcb5f5aSMarcel Moolenaar {
2757ee3b0f6eSDiomidis Spinellis struct timespec timediff;
275800ddbdf2SJohn Baldwin struct threadinfo *t;
275900ddbdf2SJohn Baldwin struct syscall *sc;
2760ee3b0f6eSDiomidis Spinellis
276100ddbdf2SJohn Baldwin t = trussinfo->curthread;
276200ddbdf2SJohn Baldwin sc = t->cs.sc;
2763ee3b0f6eSDiomidis Spinellis if (trussinfo->flags & COUNTONLY) {
27646040822cSAlan Somers timespecsub(&t->after, &t->before, &timediff);
2765d9dcc463SXin LI timespecadd(&sc->time, &timediff, &sc->time);
2766ee3b0f6eSDiomidis Spinellis sc->ncalls++;
2767caa449b6SJohn Baldwin if (error != 0)
2768ee3b0f6eSDiomidis Spinellis sc->nerror++;
2769ee3b0f6eSDiomidis Spinellis return;
2770ee3b0f6eSDiomidis Spinellis }
2771d8984f48SDag-Erling Smørgrav
277200ddbdf2SJohn Baldwin print_syscall(trussinfo);
27730cf21b4fSBrian Somers fflush(trussinfo->outfile);
2774b9befd33SJohn Baldwin
2775b9befd33SJohn Baldwin if (retval == NULL) {
2776b9befd33SJohn Baldwin /*
2777b9befd33SJohn Baldwin * This system call resulted in the current thread's exit,
2778b9befd33SJohn Baldwin * so there is no return value or error to display.
2779b9befd33SJohn Baldwin */
2780b9befd33SJohn Baldwin fprintf(trussinfo->outfile, "\n");
2781b9befd33SJohn Baldwin return;
2782b9befd33SJohn Baldwin }
2783b9befd33SJohn Baldwin
2784caa449b6SJohn Baldwin if (error == ERESTART)
2785caa449b6SJohn Baldwin fprintf(trussinfo->outfile, " ERESTART\n");
2786caa449b6SJohn Baldwin else if (error == EJUSTRETURN)
2787caa449b6SJohn Baldwin fprintf(trussinfo->outfile, " EJUSTRETURN\n");
2788caa449b6SJohn Baldwin else if (error != 0) {
2789caa449b6SJohn Baldwin fprintf(trussinfo->outfile, " ERR#%d '%s'\n",
2790caa449b6SJohn Baldwin sysdecode_freebsd_to_abi_errno(t->proc->abi->abi, error),
2791caa449b6SJohn Baldwin strerror(error));
27928ba2e89eSAlex Richardson } else if (sc->decode.ret_type == 2 &&
27938ba2e89eSAlex Richardson t->proc->abi->pointer_size == 4) {
27942b75c8adSJohn Baldwin off_t off;
27952b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN
27962b75c8adSJohn Baldwin off = (off_t)retval[1] << 32 | retval[0];
27972b75c8adSJohn Baldwin #else
27982b75c8adSJohn Baldwin off = (off_t)retval[0] << 32 | retval[1];
27992b75c8adSJohn Baldwin #endif
28002b75c8adSJohn Baldwin fprintf(trussinfo->outfile, " = %jd (0x%jx)\n", (intmax_t)off,
28012b75c8adSJohn Baldwin (intmax_t)off);
28028ba2e89eSAlex Richardson } else {
2803caa449b6SJohn Baldwin fprintf(trussinfo->outfile, " = %jd (0x%jx)\n",
2804caa449b6SJohn Baldwin (intmax_t)retval[0], (intmax_t)retval[0]);
2805bbeaf6c0SSean Eric Fagan }
28068ba2e89eSAlex Richardson }
2807ee3b0f6eSDiomidis Spinellis
2808ee3b0f6eSDiomidis Spinellis void
print_summary(struct trussinfo * trussinfo)2809ee3b0f6eSDiomidis Spinellis print_summary(struct trussinfo *trussinfo)
2810ee3b0f6eSDiomidis Spinellis {
2811ee3b0f6eSDiomidis Spinellis struct timespec total = {0, 0};
281294355cfdSAndrey Zonov struct syscall *sc;
2813ee3b0f6eSDiomidis Spinellis int ncall, nerror;
2814ee3b0f6eSDiomidis Spinellis
2815ee3b0f6eSDiomidis Spinellis fprintf(trussinfo->outfile, "%-20s%15s%8s%8s\n",
2816ee3b0f6eSDiomidis Spinellis "syscall", "seconds", "calls", "errors");
2817ee3b0f6eSDiomidis Spinellis ncall = nerror = 0;
28186019514bSAlex Richardson STAILQ_FOREACH(sc, &seen_syscalls, entries) {
2819ee3b0f6eSDiomidis Spinellis if (sc->ncalls) {
282055a8d2bbSJaakko Heinonen fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n",
282155a8d2bbSJaakko Heinonen sc->name, (intmax_t)sc->time.tv_sec,
282255a8d2bbSJaakko Heinonen sc->time.tv_nsec, sc->ncalls, sc->nerror);
2823d9dcc463SXin LI timespecadd(&total, &sc->time, &total);
2824ee3b0f6eSDiomidis Spinellis ncall += sc->ncalls;
2825ee3b0f6eSDiomidis Spinellis nerror += sc->nerror;
2826ee3b0f6eSDiomidis Spinellis }
28276019514bSAlex Richardson }
2828ee3b0f6eSDiomidis Spinellis fprintf(trussinfo->outfile, "%20s%15s%8s%8s\n",
2829ee3b0f6eSDiomidis Spinellis "", "-------------", "-------", "-------");
283055a8d2bbSJaakko Heinonen fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n",
283155a8d2bbSJaakko Heinonen "", (intmax_t)total.tv_sec, total.tv_nsec, ncall, nerror);
2832ee3b0f6eSDiomidis Spinellis }
2833