xref: /freebsd/usr.bin/truss/syscalls.c (revision e9ac27430c0c639c1f89b1f048a44f6cea0ec265)
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>
352b75c8adSJohn Baldwin __FBSDID("$FreeBSD$");
363cf51049SPhilippe Charnier 
3709d64da3SSean Eric Fagan /*
38bbeaf6c0SSean Eric Fagan  * This file has routines used to print out system calls and their
39bbeaf6c0SSean Eric Fagan  * arguments.
40bbeaf6c0SSean Eric Fagan  */
41bbeaf6c0SSean Eric Fagan 
427136a1d9SJohn Baldwin #include <sys/capsicum.h>
439ddd1412SDag-Erling Smørgrav #include <sys/types.h>
44ffb66079SJohn Baldwin #define	_WANT_FREEBSD11_KEVENT
452b75c8adSJohn Baldwin #include <sys/event.h>
462b75c8adSJohn Baldwin #include <sys/ioccom.h>
47a776866bSBryan Drewery #include <sys/mount.h>
485d2d083cSXin LI #include <sys/ptrace.h>
492b75c8adSJohn Baldwin #include <sys/resource.h>
509ddd1412SDag-Erling Smørgrav #include <sys/socket.h>
518207f12dSWarner Losh #define _WANT_FREEBSD11_STAT
522b75c8adSJohn Baldwin #include <sys/stat.h>
539ddd1412SDag-Erling Smørgrav #include <sys/un.h>
5434763d1cSJohn Baldwin #include <sys/wait.h>
559ddd1412SDag-Erling Smørgrav #include <netinet/in.h>
564d7b9809SMichael Tuexen #include <netinet/sctp.h>
579ddd1412SDag-Erling Smørgrav #include <arpa/inet.h>
589ddd1412SDag-Erling Smørgrav 
591175b23fSJohn Baldwin #include <assert.h>
60dec17687SBrian Feldman #include <ctype.h>
613cf51049SPhilippe Charnier #include <err.h>
62894b8f7aSAlfred Perlstein #include <fcntl.h>
63e45a5a0dSDavid Malone #include <poll.h>
64a4110f9fSJohn Baldwin #include <sched.h>
659ddd1412SDag-Erling Smørgrav #include <signal.h>
66808d9805SEd Schouten #include <stdbool.h>
67bbeaf6c0SSean Eric Fagan #include <stdio.h>
68bbeaf6c0SSean Eric Fagan #include <stdlib.h>
69bbeaf6c0SSean Eric Fagan #include <string.h>
70d6fb4894SJohn Baldwin #include <sysdecode.h>
71bbeaf6c0SSean Eric Fagan #include <unistd.h>
72081e5c48SPav Lucistnik #include <vis.h>
739ddd1412SDag-Erling Smørgrav 
741f3bbfd8SEd Schouten #include <contrib/cloudabi/cloudabi_types_common.h>
75808d9805SEd Schouten 
76ec0bed25SMatthew N. Dodd #include "truss.h"
771be5d704SMark Murray #include "extern.h"
78bbeaf6c0SSean Eric Fagan #include "syscall.h"
79bbeaf6c0SSean Eric Fagan 
80bbeaf6c0SSean Eric Fagan /*
81081e5c48SPav Lucistnik  * This should probably be in its own file, sorted alphabetically.
82bbeaf6c0SSean Eric Fagan  */
836c61b0f3SBryan Drewery static struct syscall decoded_syscalls[] = {
84f44fc79dSJohn Baldwin 	/* Native ABI */
857ce44f08SJohn Baldwin 	{ .name = "__acl_aclcheck_fd", .ret_type = 1, .nargs = 3,
867ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
877ce44f08SJohn Baldwin 	{ .name = "__acl_aclcheck_file", .ret_type = 1, .nargs = 3,
887ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
897ce44f08SJohn Baldwin 	{ .name = "__acl_aclcheck_link", .ret_type = 1, .nargs = 3,
907ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
917ce44f08SJohn Baldwin 	{ .name = "__acl_delete_fd", .ret_type = 1, .nargs = 2,
927ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 } } },
937ce44f08SJohn Baldwin 	{ .name = "__acl_delete_file", .ret_type = 1, .nargs = 2,
947ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 } } },
957ce44f08SJohn Baldwin 	{ .name = "__acl_delete_link", .ret_type = 1, .nargs = 2,
967ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 } } },
977ce44f08SJohn Baldwin 	{ .name = "__acl_get_fd", .ret_type = 1, .nargs = 3,
987ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
997ce44f08SJohn Baldwin 	{ .name = "__acl_get_file", .ret_type = 1, .nargs = 3,
1007ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1017ce44f08SJohn Baldwin 	{ .name = "__acl_get_link", .ret_type = 1, .nargs = 3,
1027ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1037ce44f08SJohn Baldwin 	{ .name = "__acl_set_fd", .ret_type = 1, .nargs = 3,
1047ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1057ce44f08SJohn Baldwin 	{ .name = "__acl_set_file", .ret_type = 1, .nargs = 3,
1067ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1077ce44f08SJohn Baldwin 	{ .name = "__acl_set_link", .ret_type = 1, .nargs = 3,
1087ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1097136a1d9SJohn Baldwin 	{ .name = "__cap_rights_get", .ret_type = 1, .nargs = 3,
1107136a1d9SJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 }, { CapRights | OUT, 2 } } },
111f44fc79dSJohn Baldwin 	{ .name = "__getcwd", .ret_type = 1, .nargs = 2,
112f44fc79dSJohn Baldwin 	  .args = { { Name | OUT, 0 }, { Int, 1 } } },
113f44fc79dSJohn Baldwin 	{ .name = "_umtx_op", .ret_type = 1, .nargs = 5,
114f44fc79dSJohn Baldwin 	  .args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 },
115f44fc79dSJohn Baldwin 		    { Ptr, 4 } } },
116f44fc79dSJohn Baldwin 	{ .name = "accept", .ret_type = 1, .nargs = 3,
117f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
118f44fc79dSJohn Baldwin 	{ .name = "access", .ret_type = 1, .nargs = 2,
119f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Accessmode, 1 } } },
120f44fc79dSJohn Baldwin 	{ .name = "bind", .ret_type = 1, .nargs = 3,
12158227c60SMichael Tuexen 	  .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Socklent, 2 } } },
122f44fc79dSJohn Baldwin 	{ .name = "bindat", .ret_type = 1, .nargs = 4,
123f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
1247d897327SJohn Baldwin 		    { Int, 3 } } },
125f44fc79dSJohn Baldwin 	{ .name = "break", .ret_type = 1, .nargs = 1,
126f44fc79dSJohn Baldwin 	  .args = { { Ptr, 0 } } },
127bed418c8SJohn Baldwin 	{ .name = "cap_fcntls_get", .ret_type = 1, .nargs = 2,
128bed418c8SJohn Baldwin 	  .args = { { Int, 0 }, { CapFcntlRights | OUT, 1 } } },
129bed418c8SJohn Baldwin 	{ .name = "cap_fcntls_limit", .ret_type = 1, .nargs = 2,
130bed418c8SJohn Baldwin 	  .args = { { Int, 0 }, { CapFcntlRights, 1 } } },
131ebb2cc40SJohn Baldwin 	{ .name = "cap_getmode", .ret_type = 1, .nargs = 1,
132ebb2cc40SJohn Baldwin 	  .args = { { PUInt | OUT, 0 } } },
1337136a1d9SJohn Baldwin 	{ .name = "cap_rights_limit", .ret_type = 1, .nargs = 2,
1347136a1d9SJohn Baldwin 	  .args = { { Int, 0 }, { CapRights, 1 } } },
135f44fc79dSJohn Baldwin 	{ .name = "chdir", .ret_type = 1, .nargs = 1,
136f44fc79dSJohn Baldwin 	  .args = { { Name, 0 } } },
137f44fc79dSJohn Baldwin 	{ .name = "chflags", .ret_type = 1, .nargs = 2,
13827459358SJohn Baldwin 	  .args = { { Name | IN, 0 }, { FileFlags, 1 } } },
13927459358SJohn Baldwin 	{ .name = "chflagsat", .ret_type = 1, .nargs = 4,
14027459358SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { FileFlags, 2 },
14127459358SJohn Baldwin 		    { Atflags, 3 } } },
142f44fc79dSJohn Baldwin 	{ .name = "chmod", .ret_type = 1, .nargs = 2,
143ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Octal, 1 } } },
144f44fc79dSJohn Baldwin 	{ .name = "chown", .ret_type = 1, .nargs = 3,
145f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
146f44fc79dSJohn Baldwin 	{ .name = "chroot", .ret_type = 1, .nargs = 1,
147f44fc79dSJohn Baldwin 	  .args = { { Name, 0 } } },
148f44fc79dSJohn Baldwin 	{ .name = "clock_gettime", .ret_type = 1, .nargs = 2,
149f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Timespec | OUT, 1 } } },
150ee3b0f6eSDiomidis Spinellis 	{ .name = "close", .ret_type = 1, .nargs = 1,
151ee3b0f6eSDiomidis Spinellis 	  .args = { { Int, 0 } } },
1521b224b09SWarner Losh 	{ .name = "compat11.fstat", .ret_type = 1, .nargs = 2,
1531b224b09SWarner Losh 	  .args = { { Int, 0 }, { Stat11 | OUT, 1 } } },
15475a14d22SMark Johnston 	{ .name = "compat11.fstatat", .ret_type = 1, .nargs = 4,
15575a14d22SMark Johnston 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat11 | OUT, 2 },
15675a14d22SMark Johnston 		    { Atflags, 3 } } },
157ffb66079SJohn Baldwin 	{ .name = "compat11.kevent", .ret_type = 1, .nargs = 6,
158ffb66079SJohn Baldwin 	  .args = { { Int, 0 }, { Kevent11, 1 }, { Int, 2 },
159ffb66079SJohn Baldwin 		    { Kevent11 | OUT, 3 }, { Int, 4 }, { Timespec, 5 } } },
1601b224b09SWarner Losh 	{ .name = "compat11.lstat", .ret_type = 1, .nargs = 2,
1611b224b09SWarner Losh 	  .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } },
1621b224b09SWarner Losh 	{ .name = "compat11.stat", .ret_type = 1, .nargs = 2,
1631b224b09SWarner Losh 	  .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } },
164f44fc79dSJohn Baldwin 	{ .name = "connect", .ret_type = 1, .nargs = 3,
16558227c60SMichael Tuexen 	  .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Socklent, 2 } } },
166f44fc79dSJohn Baldwin 	{ .name = "connectat", .ret_type = 1, .nargs = 4,
167f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
168f44fc79dSJohn Baldwin 		    { Int, 3 } } },
169b60a095bSJohn Baldwin 	{ .name = "dup", .ret_type = 1, .nargs = 1,
170b60a095bSJohn Baldwin 	  .args = { { Int, 0 } } },
171b60a095bSJohn Baldwin 	{ .name = "dup2", .ret_type = 1, .nargs = 2,
172b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 } } },
173f44fc79dSJohn Baldwin 	{ .name = "eaccess", .ret_type = 1, .nargs = 2,
174f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Accessmode, 1 } } },
175f44fc79dSJohn Baldwin 	{ .name = "execve", .ret_type = 1, .nargs = 3,
176f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
177f44fc79dSJohn Baldwin 		    { ExecEnv | IN, 2 } } },
178f44fc79dSJohn Baldwin 	{ .name = "exit", .ret_type = 0, .nargs = 1,
179f44fc79dSJohn Baldwin 	  .args = { { Hex, 0 } } },
18026606dcaSJohn Baldwin 	{ .name = "extattr_delete_fd", .ret_type = 1, .nargs = 3,
18126606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
18226606dcaSJohn Baldwin 	{ .name = "extattr_delete_file", .ret_type = 1, .nargs = 3,
18326606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
18426606dcaSJohn Baldwin 	{ .name = "extattr_delete_link", .ret_type = 1, .nargs = 3,
18526606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
18626606dcaSJohn Baldwin 	{ .name = "extattr_get_fd", .ret_type = 1, .nargs = 5,
18726606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
18826606dcaSJohn Baldwin 		    { BinString | OUT, 3 }, { Sizet, 4 } } },
18926606dcaSJohn Baldwin 	{ .name = "extattr_get_file", .ret_type = 1, .nargs = 5,
19026606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
19126606dcaSJohn Baldwin 		    { BinString | OUT, 3 }, { Sizet, 4 } } },
19226606dcaSJohn Baldwin 	{ .name = "extattr_get_link", .ret_type = 1, .nargs = 5,
19326606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
19426606dcaSJohn Baldwin 		    { BinString | OUT, 3 }, { Sizet, 4 } } },
19526606dcaSJohn Baldwin 	{ .name = "extattr_list_fd", .ret_type = 1, .nargs = 4,
19626606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
19726606dcaSJohn Baldwin 		    { Sizet, 3 } } },
19826606dcaSJohn Baldwin 	{ .name = "extattr_list_file", .ret_type = 1, .nargs = 4,
19926606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
20026606dcaSJohn Baldwin 		    { Sizet, 3 } } },
20126606dcaSJohn Baldwin 	{ .name = "extattr_list_link", .ret_type = 1, .nargs = 4,
20226606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
20326606dcaSJohn Baldwin 		    { Sizet, 3 } } },
20426606dcaSJohn Baldwin 	{ .name = "extattr_set_fd", .ret_type = 1, .nargs = 5,
20526606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
20626606dcaSJohn Baldwin 		    { BinString | IN, 3 }, { Sizet, 4 } } },
20726606dcaSJohn Baldwin 	{ .name = "extattr_set_file", .ret_type = 1, .nargs = 5,
20826606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
20926606dcaSJohn Baldwin 		    { BinString | IN, 3 }, { Sizet, 4 } } },
21026606dcaSJohn Baldwin 	{ .name = "extattr_set_link", .ret_type = 1, .nargs = 5,
21126606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
21226606dcaSJohn Baldwin 		    { BinString | IN, 3 }, { Sizet, 4 } } },
21326606dcaSJohn Baldwin 	{ .name = "extattrctl", .ret_type = 1, .nargs = 5,
21426606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Hex, 1 }, { Name, 2 },
21526606dcaSJohn Baldwin 		    { Extattrnamespace, 3 }, { Name, 4 } } },
216f44fc79dSJohn Baldwin 	{ .name = "faccessat", .ret_type = 1, .nargs = 4,
217f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Accessmode, 2 },
218f44fc79dSJohn Baldwin 		    { Atflags, 3 } } },
21927459358SJohn Baldwin 	{ .name = "fchflags", .ret_type = 1, .nargs = 2,
22027459358SJohn Baldwin 	  .args = { { Int, 0 }, { FileFlags, 1 } } },
221f44fc79dSJohn Baldwin 	{ .name = "fchmod", .ret_type = 1, .nargs = 2,
222f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Octal, 1 } } },
223f44fc79dSJohn Baldwin 	{ .name = "fchmodat", .ret_type = 1, .nargs = 4,
224f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Atflags, 3 } } },
225f44fc79dSJohn Baldwin 	{ .name = "fchown", .ret_type = 1, .nargs = 3,
226f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
227f44fc79dSJohn Baldwin 	{ .name = "fchownat", .ret_type = 1, .nargs = 5,
228f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Int, 2 }, { Int, 3 },
229f44fc79dSJohn Baldwin 		    { Atflags, 4 } } },
230f44fc79dSJohn Baldwin 	{ .name = "fcntl", .ret_type = 1, .nargs = 3,
231f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } },
232dd92181fSJohn Baldwin 	{ .name = "flock", .ret_type = 1, .nargs = 2,
233dd92181fSJohn Baldwin 	  .args = { { Int, 0 }, { Flockop, 1 } } },
234f44fc79dSJohn Baldwin 	{ .name = "fstat", .ret_type = 1, .nargs = 2,
235f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Stat | OUT, 1 } } },
236f44fc79dSJohn Baldwin 	{ .name = "fstatat", .ret_type = 1, .nargs = 4,
237f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat | OUT, 2 },
238f44fc79dSJohn Baldwin 		    { Atflags, 3 } } },
239f44fc79dSJohn Baldwin 	{ .name = "fstatfs", .ret_type = 1, .nargs = 2,
240f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { StatFs | OUT, 1 } } },
241f44fc79dSJohn Baldwin 	{ .name = "ftruncate", .ret_type = 1, .nargs = 2,
242c05cc0d6SJohn Baldwin 	  .args = { { Int | IN, 0 }, { QuadHex | IN, 1 } } },
243f44fc79dSJohn Baldwin 	{ .name = "futimens", .ret_type = 1, .nargs = 2,
244f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Timespec2 | IN, 1 } } },
245f44fc79dSJohn Baldwin 	{ .name = "futimes", .ret_type = 1, .nargs = 2,
246f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Timeval2 | IN, 1 } } },
247f44fc79dSJohn Baldwin 	{ .name = "futimesat", .ret_type = 1, .nargs = 3,
248f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timeval2 | IN, 2 } } },
249b60a095bSJohn Baldwin 	{ .name = "getdirentries", .ret_type = 1, .nargs = 4,
250b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 },
251b60a095bSJohn Baldwin 		    { PQuadHex | OUT, 3 } } },
252ab43bedcSJohn Baldwin 	{ .name = "getfsstat", .ret_type = 1, .nargs = 3,
253ab43bedcSJohn Baldwin 	  .args = { { Ptr, 0 }, { Long, 1 }, { Getfsstatmode, 2 } } },
254f44fc79dSJohn Baldwin 	{ .name = "getitimer", .ret_type = 1, .nargs = 2,
255f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Itimerval | OUT, 2 } } },
256f44fc79dSJohn Baldwin 	{ .name = "getpeername", .ret_type = 1, .nargs = 3,
257f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
258f44fc79dSJohn Baldwin 	{ .name = "getpgid", .ret_type = 1, .nargs = 1,
259f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
260ad419d33SJohn Baldwin 	{ .name = "getpriority", .ret_type = 1, .nargs = 2,
261ad419d33SJohn Baldwin 	  .args = { { Priowhich, 0 }, { Int, 1 } } },
262*e9ac2743SConrad Meyer 	{ .name = "getrandom", .ret_type = 1, .nargs = 3,
263*e9ac2743SConrad Meyer 	  .args = { { BinString | OUT, 0 }, { Sizet, 1 }, { UInt, 2 } } },
264f44fc79dSJohn Baldwin 	{ .name = "getrlimit", .ret_type = 1, .nargs = 2,
265f44fc79dSJohn Baldwin 	  .args = { { Resource, 0 }, { Rlimit | OUT, 1 } } },
266f44fc79dSJohn Baldwin 	{ .name = "getrusage", .ret_type = 1, .nargs = 2,
267ee8aa41dSJohn Baldwin 	  .args = { { RusageWho, 0 }, { Rusage | OUT, 1 } } },
268f44fc79dSJohn Baldwin 	{ .name = "getsid", .ret_type = 1, .nargs = 1,
269f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
270f44fc79dSJohn Baldwin 	{ .name = "getsockname", .ret_type = 1, .nargs = 3,
271f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
272832af457SMichael Tuexen 	{ .name = "getsockopt", .ret_type = 1, .nargs = 5,
273832af457SMichael Tuexen 	  .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 },
274832af457SMichael Tuexen 		    { Ptr | OUT, 3 }, { Ptr | OUT, 4 } } },
275f44fc79dSJohn Baldwin 	{ .name = "gettimeofday", .ret_type = 1, .nargs = 2,
276f44fc79dSJohn Baldwin 	  .args = { { Timeval | OUT, 0 }, { Ptr, 1 } } },
277f44fc79dSJohn Baldwin 	{ .name = "ioctl", .ret_type = 1, .nargs = 3,
278a776eeafSJohn Baldwin 	  .args = { { Int, 0 }, { Ioctl, 1 }, { Ptr, 2 } } },
279f44fc79dSJohn Baldwin 	{ .name = "kevent", .ret_type = 1, .nargs = 6,
280f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 },
281f44fc79dSJohn Baldwin 		    { Int, 4 }, { Timespec, 5 } } },
282f44fc79dSJohn Baldwin 	{ .name = "kill", .ret_type = 1, .nargs = 2,
283f44fc79dSJohn Baldwin 	  .args = { { Int | IN, 0 }, { Signal | IN, 1 } } },
284f44fc79dSJohn Baldwin 	{ .name = "kldfind", .ret_type = 1, .nargs = 1,
285f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 } } },
286f44fc79dSJohn Baldwin 	{ .name = "kldfirstmod", .ret_type = 1, .nargs = 1,
287f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
288f44fc79dSJohn Baldwin 	{ .name = "kldload", .ret_type = 1, .nargs = 1,
289f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 } } },
290f44fc79dSJohn Baldwin 	{ .name = "kldnext", .ret_type = 1, .nargs = 1,
291f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
292f44fc79dSJohn Baldwin 	{ .name = "kldstat", .ret_type = 1, .nargs = 2,
293f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Ptr, 1 } } },
29494e854c5SJohn Baldwin 	{ .name = "kldsym", .ret_type = 1, .nargs = 3,
29594e854c5SJohn Baldwin 	  .args = { { Int, 0 }, { Kldsymcmd, 1 }, { Ptr, 2 } } },
296f44fc79dSJohn Baldwin 	{ .name = "kldunload", .ret_type = 1, .nargs = 1,
297f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
29894e854c5SJohn Baldwin 	{ .name = "kldunloadf", .ret_type = 1, .nargs = 2,
29994e854c5SJohn Baldwin 	  .args = { { Int, 0 }, { Kldunloadflags, 1 } } },
300f44fc79dSJohn Baldwin 	{ .name = "kse_release", .ret_type = 0, .nargs = 1,
301f44fc79dSJohn Baldwin 	  .args = { { Timespec, 0 } } },
302f44fc79dSJohn Baldwin 	{ .name = "lchflags", .ret_type = 1, .nargs = 2,
30327459358SJohn Baldwin 	  .args = { { Name | IN, 0 }, { FileFlags, 1 } } },
304f44fc79dSJohn Baldwin 	{ .name = "lchmod", .ret_type = 1, .nargs = 2,
305f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 } } },
306f44fc79dSJohn Baldwin 	{ .name = "lchown", .ret_type = 1, .nargs = 3,
307f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
3082b75c8adSJohn Baldwin 	{ .name = "link", .ret_type = 1, .nargs = 2,
309ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Name, 1 } } },
3102b75c8adSJohn Baldwin 	{ .name = "linkat", .ret_type = 1, .nargs = 5,
3117d897327SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 },
3127d897327SJohn Baldwin 		    { Atflags, 4 } } },
313e8d2c81dSMichael Tuexen 	{ .name = "listen", .ret_type = 1, .nargs = 2,
314e8d2c81dSMichael Tuexen 	  .args = { { Int, 0 }, { Int, 1 } } },
315f44fc79dSJohn Baldwin  	{ .name = "lseek", .ret_type = 2, .nargs = 3,
316c05cc0d6SJohn Baldwin 	  .args = { { Int, 0 }, { QuadHex, 1 }, { Whence, 2 } } },
317f44fc79dSJohn Baldwin 	{ .name = "lstat", .ret_type = 1, .nargs = 2,
318f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
319f44fc79dSJohn Baldwin 	{ .name = "lutimes", .ret_type = 1, .nargs = 2,
320f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
32198fdbeecSJohn Baldwin 	{ .name = "madvise", .ret_type = 1, .nargs = 3,
32298fdbeecSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Madvice, 2 } } },
3232d9c9988SJohn Baldwin 	{ .name = "minherit", .ret_type = 1, .nargs = 3,
3242d9c9988SJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Minherit, 2 } } },
325f44fc79dSJohn Baldwin 	{ .name = "mkdir", .ret_type = 1, .nargs = 2,
326f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 } } },
327f44fc79dSJohn Baldwin 	{ .name = "mkdirat", .ret_type = 1, .nargs = 3,
328f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
3292b75c8adSJohn Baldwin 	{ .name = "mkfifo", .ret_type = 1, .nargs = 2,
330e82ce59cSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 } } },
3312b75c8adSJohn Baldwin 	{ .name = "mkfifoat", .ret_type = 1, .nargs = 3,
3327d897327SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
3332b75c8adSJohn Baldwin 	{ .name = "mknod", .ret_type = 1, .nargs = 3,
334e82ce59cSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 }, { Int, 2 } } },
3352b75c8adSJohn Baldwin 	{ .name = "mknodat", .ret_type = 1, .nargs = 4,
3367d897327SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Int, 3 } } },
33794bde755SJohn Baldwin 	{ .name = "mlock", .ret_type = 1, .nargs = 2,
33894bde755SJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 } } },
33994bde755SJohn Baldwin 	{ .name = "mlockall", .ret_type = 1, .nargs = 1,
34094bde755SJohn Baldwin 	  .args = { { Mlockall, 0 } } },
341f44fc79dSJohn Baldwin 	{ .name = "mmap", .ret_type = 1, .nargs = 6,
342e261fb2aSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 }, { Mmapflags, 3 },
343c05cc0d6SJohn Baldwin 		    { Int, 4 }, { QuadHex, 5 } } },
344f44fc79dSJohn Baldwin 	{ .name = "modfind", .ret_type = 1, .nargs = 1,
345f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 } } },
3462b75c8adSJohn Baldwin 	{ .name = "mount", .ret_type = 1, .nargs = 4,
3478acc8e78SJohn Baldwin 	  .args = { { Name, 0 }, { Name, 1 }, { Mountflags, 2 }, { Ptr, 3 } } },
348f44fc79dSJohn Baldwin 	{ .name = "mprotect", .ret_type = 1, .nargs = 3,
349e261fb2aSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 } } },
350114aeee0SJohn Baldwin 	{ .name = "msync", .ret_type = 1, .nargs = 3,
351114aeee0SJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Msync, 2 } } },
35294bde755SJohn Baldwin 	{ .name = "munlock", .ret_type = 1, .nargs = 2,
35394bde755SJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 } } },
354f44fc79dSJohn Baldwin 	{ .name = "munmap", .ret_type = 1, .nargs = 2,
355e261fb2aSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 } } },
356f44fc79dSJohn Baldwin 	{ .name = "nanosleep", .ret_type = 1, .nargs = 1,
357f44fc79dSJohn Baldwin 	  .args = { { Timespec, 0 } } },
3588acc8e78SJohn Baldwin 	{ .name = "nmount", .ret_type = 1, .nargs = 3,
3598acc8e78SJohn Baldwin 	  .args = { { Ptr, 0 }, { UInt, 1 }, { Mountflags, 2 } } },
360f44fc79dSJohn Baldwin 	{ .name = "open", .ret_type = 1, .nargs = 3,
361f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
362f44fc79dSJohn Baldwin 	{ .name = "openat", .ret_type = 1, .nargs = 4,
363f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 },
364f44fc79dSJohn Baldwin 		    { Octal, 3 } } },
365f44fc79dSJohn Baldwin 	{ .name = "pathconf", .ret_type = 1, .nargs = 2,
366f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Pathconf, 1 } } },
367f44fc79dSJohn Baldwin 	{ .name = "pipe", .ret_type = 1, .nargs = 1,
368f44fc79dSJohn Baldwin 	  .args = { { PipeFds | OUT, 0 } } },
369f44fc79dSJohn Baldwin 	{ .name = "pipe2", .ret_type = 1, .nargs = 2,
3709289f547SJohn Baldwin 	  .args = { { Ptr, 0 }, { Pipe2, 1 } } },
371f44fc79dSJohn Baldwin 	{ .name = "poll", .ret_type = 1, .nargs = 3,
372f44fc79dSJohn Baldwin 	  .args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } },
373d2a97485SJohn Baldwin 	{ .name = "posix_fadvise", .ret_type = 1, .nargs = 4,
374d2a97485SJohn Baldwin 	  .args = { { Int, 0 }, { QuadHex, 1 }, { QuadHex, 2 },
375d2a97485SJohn Baldwin 		    { Fadvice, 3 } } },
376f44fc79dSJohn Baldwin 	{ .name = "posix_openpt", .ret_type = 1, .nargs = 1,
377f44fc79dSJohn Baldwin 	  .args = { { Open, 0 } } },
378b60a095bSJohn Baldwin 	{ .name = "pread", .ret_type = 1, .nargs = 4,
379b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 },
380b60a095bSJohn Baldwin 		    { QuadHex, 3 } } },
381f44fc79dSJohn Baldwin 	{ .name = "procctl", .ret_type = 1, .nargs = 4,
382c05cc0d6SJohn Baldwin 	  .args = { { Idtype, 0 }, { Quad, 1 }, { Procctl, 2 }, { Ptr, 3 } } },
3835ac1c7acSJohn Baldwin 	{ .name = "ptrace", .ret_type = 1, .nargs = 4,
3845ac1c7acSJohn Baldwin 	  .args = { { Ptraceop, 0 }, { Int, 1 }, { Ptr, 2 }, { Int, 3 } } },
385b60a095bSJohn Baldwin 	{ .name = "pwrite", .ret_type = 1, .nargs = 4,
386b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 },
387b60a095bSJohn Baldwin 		    { QuadHex, 3 } } },
388dd0c462cSJohn Baldwin 	{ .name = "quotactl", .ret_type = 1, .nargs = 4,
389dd0c462cSJohn Baldwin 	  .args = { { Name, 0 }, { Quotactlcmd, 1 }, { Int, 2 }, { Ptr, 3 } } },
390f44fc79dSJohn Baldwin 	{ .name = "read", .ret_type = 1, .nargs = 3,
391e261fb2aSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 } } },
392f44fc79dSJohn Baldwin 	{ .name = "readlink", .ret_type = 1, .nargs = 3,
393e261fb2aSJohn Baldwin 	  .args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Sizet, 2 } } },
394f44fc79dSJohn Baldwin 	{ .name = "readlinkat", .ret_type = 1, .nargs = 4,
395f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 },
396e261fb2aSJohn Baldwin 		    { Sizet, 3 } } },
397097b25a7SMichael Tuexen 	{ .name = "readv", .ret_type = 1, .nargs = 3,
398097b25a7SMichael Tuexen 	  .args = { { Int, 0 }, { Iovec | OUT, 1 }, { Int, 2 } } },
3994152441fSJohn Baldwin 	{ .name = "reboot", .ret_type = 1, .nargs = 1,
4004152441fSJohn Baldwin 	  .args = { { Reboothowto, 0 } } },
401ee3b0f6eSDiomidis Spinellis 	{ .name = "recvfrom", .ret_type = 1, .nargs = 6,
4028b429b65SMichael Tuexen 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 },
4038b429b65SMichael Tuexen 	            { Msgflags, 3 }, { Sockaddr | OUT, 4 },
4048b429b65SMichael Tuexen 	            { Ptr | OUT, 5 } } },
405fca08fe6SMichael Tuexen 	{ .name = "recvmsg", .ret_type = 1, .nargs = 3,
406a2674e03SMichael Tuexen 	  .args = { { Int, 0 }, { Msghdr | OUT, 1 }, { Msgflags, 2 } } },
407f44fc79dSJohn Baldwin 	{ .name = "rename", .ret_type = 1, .nargs = 2,
408f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Name, 1 } } },
409f44fc79dSJohn Baldwin 	{ .name = "renameat", .ret_type = 1, .nargs = 4,
410f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } },
411f44fc79dSJohn Baldwin 	{ .name = "rfork", .ret_type = 1, .nargs = 1,
412f44fc79dSJohn Baldwin 	  .args = { { Rforkflags, 0 } } },
413cca89ee3SBryan Drewery 	{ .name = "rmdir", .ret_type = 1, .nargs = 1,
414cca89ee3SBryan Drewery 	  .args = { { Name, 0 } } },
4153cd40bc3SJohn Baldwin 	{ .name = "rtprio", .ret_type = 1, .nargs = 3,
4163cd40bc3SJohn Baldwin 	  .args = { { Rtpriofunc, 0 }, { Int, 1 }, { Ptr, 2 } } },
4173cd40bc3SJohn Baldwin 	{ .name = "rtprio_thread", .ret_type = 1, .nargs = 3,
4183cd40bc3SJohn Baldwin 	  .args = { { Rtpriofunc, 0 }, { Int, 1 }, { Ptr, 2 } } },
419a4110f9fSJohn Baldwin 	{ .name = "sched_get_priority_max", .ret_type = 1, .nargs = 1,
420a4110f9fSJohn Baldwin 	  .args = { { Schedpolicy, 0 } } },
421a4110f9fSJohn Baldwin 	{ .name = "sched_get_priority_min", .ret_type = 1, .nargs = 1,
422a4110f9fSJohn Baldwin 	  .args = { { Schedpolicy, 0 } } },
423a4110f9fSJohn Baldwin 	{ .name = "sched_getparam", .ret_type = 1, .nargs = 2,
424a4110f9fSJohn Baldwin 	  .args = { { Int, 0 }, { Schedparam | OUT, 1 } } },
425a4110f9fSJohn Baldwin 	{ .name = "sched_getscheduler", .ret_type = 1, .nargs = 1,
426a4110f9fSJohn Baldwin 	  .args = { { Int, 0 } } },
427a4110f9fSJohn Baldwin 	{ .name = "sched_rr_get_interval", .ret_type = 1, .nargs = 2,
428a4110f9fSJohn Baldwin 	  .args = { { Int, 0 }, { Timespec | OUT, 1 } } },
429a4110f9fSJohn Baldwin 	{ .name = "sched_setparam", .ret_type = 1, .nargs = 2,
430a4110f9fSJohn Baldwin 	  .args = { { Int, 0 }, { Schedparam, 1 } } },
431a4110f9fSJohn Baldwin 	{ .name = "sched_setscheduler", .ret_type = 1, .nargs = 3,
432a4110f9fSJohn Baldwin 	  .args = { { Int, 0 }, { Schedpolicy, 1 }, { Schedparam, 2 } } },
433c0b72375SMichael Tuexen 	{ .name = "sctp_generic_recvmsg", .ret_type = 1, .nargs = 7,
4344d7b9809SMichael Tuexen 	  .args = { { Int, 0 }, { Iovec | OUT, 1 }, { Int, 2 },
4354d7b9809SMichael Tuexen 	            { Sockaddr | OUT, 3 }, { Ptr | OUT, 4 },
4364d7b9809SMichael Tuexen 	            { Sctpsndrcvinfo | OUT, 5 }, { Ptr | OUT, 6 } } },
437c0b72375SMichael Tuexen 	{ .name = "sctp_generic_sendmsg", .ret_type = 1, .nargs = 7,
438c0b72375SMichael Tuexen 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 },
4394d7b9809SMichael Tuexen 	            { Sockaddr | IN, 3 }, { Socklent, 4 },
4404d7b9809SMichael Tuexen 	            { Sctpsndrcvinfo | IN, 5 }, { Msgflags, 6 } } },
4414d7b9809SMichael Tuexen 	{ .name = "sctp_generic_sendmsg_iov", .ret_type = 1, .nargs = 7,
4424d7b9809SMichael Tuexen 	  .args = { { Int, 0 }, { Iovec | IN, 1 }, { Int, 2 },
4434d7b9809SMichael Tuexen 	            { Sockaddr | IN, 3 }, { Socklent, 4 },
4444d7b9809SMichael Tuexen 	            { Sctpsndrcvinfo | IN, 5 }, { Msgflags, 6 } } },
445ee3b0f6eSDiomidis Spinellis 	{ .name = "select", .ret_type = 1, .nargs = 5,
4460a46af44SJohn Baldwin 	  .args = { { Int, 0 }, { Fd_set, 1 }, { Fd_set, 2 }, { Fd_set, 3 },
4470a46af44SJohn Baldwin 		    { Timeval, 4 } } },
448fca08fe6SMichael Tuexen 	{ .name = "sendmsg", .ret_type = 1, .nargs = 3,
449a2674e03SMichael Tuexen 	  .args = { { Int, 0 }, { Msghdr | IN, 1 }, { Msgflags, 2 } } },
450f44fc79dSJohn Baldwin 	{ .name = "sendto", .ret_type = 1, .nargs = 6,
4518b429b65SMichael Tuexen 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 },
4528b429b65SMichael Tuexen 	            { Msgflags, 3 }, { Sockaddr | IN, 4 },
4538b429b65SMichael Tuexen 	            { Socklent | IN, 5 } } },
454ee3b0f6eSDiomidis Spinellis 	{ .name = "setitimer", .ret_type = 1, .nargs = 3,
455ee3b0f6eSDiomidis Spinellis 	  .args = { { Int, 0 }, { Itimerval, 1 }, { Itimerval | OUT, 2 } } },
456ad419d33SJohn Baldwin 	{ .name = "setpriority", .ret_type = 1, .nargs = 3,
457ad419d33SJohn Baldwin 	  .args = { { Priowhich, 0 }, { Int, 1 }, { Int, 2 } } },
458f44fc79dSJohn Baldwin 	{ .name = "setrlimit", .ret_type = 1, .nargs = 2,
459f44fc79dSJohn Baldwin 	  .args = { { Resource, 0 }, { Rlimit | IN, 1 } } },
460832af457SMichael Tuexen 	{ .name = "setsockopt", .ret_type = 1, .nargs = 5,
461832af457SMichael Tuexen 	  .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 },
462832af457SMichael Tuexen 		    { Ptr | IN, 3 }, { Socklent, 4 } } },
463f44fc79dSJohn Baldwin 	{ .name = "shutdown", .ret_type = 1, .nargs = 2,
464f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Shutdown, 1 } } },
465f44fc79dSJohn Baldwin 	{ .name = "sigaction", .ret_type = 1, .nargs = 3,
466f44fc79dSJohn Baldwin 	  .args = { { Signal, 0 }, { Sigaction | IN, 1 },
467f44fc79dSJohn Baldwin 		    { Sigaction | OUT, 2 } } },
4682b75c8adSJohn Baldwin 	{ .name = "sigpending", .ret_type = 1, .nargs = 1,
469b289a8d7SJohn Baldwin 	  .args = { { Sigset | OUT, 0 } } },
4702b75c8adSJohn Baldwin 	{ .name = "sigprocmask", .ret_type = 1, .nargs = 3,
471ee3b0f6eSDiomidis Spinellis 	  .args = { { Sigprocmask, 0 }, { Sigset, 1 }, { Sigset | OUT, 2 } } },
4722b75c8adSJohn Baldwin 	{ .name = "sigqueue", .ret_type = 1, .nargs = 3,
473b289a8d7SJohn Baldwin 	  .args = { { Int, 0 }, { Signal, 1 }, { LongHex, 2 } } },
4742b75c8adSJohn Baldwin 	{ .name = "sigreturn", .ret_type = 1, .nargs = 1,
475b289a8d7SJohn Baldwin 	  .args = { { Ptr, 0 } } },
4762b75c8adSJohn Baldwin 	{ .name = "sigsuspend", .ret_type = 1, .nargs = 1,
477b289a8d7SJohn Baldwin 	  .args = { { Sigset | IN, 0 } } },
478b289a8d7SJohn Baldwin 	{ .name = "sigtimedwait", .ret_type = 1, .nargs = 3,
47913e5e6b6SJohn Baldwin 	  .args = { { Sigset | IN, 0 }, { Siginfo | OUT, 1 },
48013e5e6b6SJohn Baldwin 		    { Timespec | IN, 2 } } },
481b289a8d7SJohn Baldwin 	{ .name = "sigwait", .ret_type = 1, .nargs = 2,
48213e5e6b6SJohn Baldwin 	  .args = { { Sigset | IN, 0 }, { PSig | OUT, 1 } } },
483b289a8d7SJohn Baldwin 	{ .name = "sigwaitinfo", .ret_type = 1, .nargs = 2,
48413e5e6b6SJohn Baldwin 	  .args = { { Sigset | IN, 0 }, { Siginfo | OUT, 1 } } },
485ee3b0f6eSDiomidis Spinellis 	{ .name = "socket", .ret_type = 1, .nargs = 3,
486ecac235bSMichael Tuexen 	  .args = { { Sockdomain, 0 }, { Socktype, 1 }, { Sockprotocol, 2 } } },
487f44fc79dSJohn Baldwin 	{ .name = "stat", .ret_type = 1, .nargs = 2,
488f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
489f44fc79dSJohn Baldwin 	{ .name = "statfs", .ret_type = 1, .nargs = 2,
490f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } },
491ee3b0f6eSDiomidis Spinellis 	{ .name = "symlink", .ret_type = 1, .nargs = 2,
492ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Name, 1 } } },
4937d897327SJohn Baldwin 	{ .name = "symlinkat", .ret_type = 1, .nargs = 3,
4947d897327SJohn Baldwin 	  .args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } },
495f44fc79dSJohn Baldwin 	{ .name = "sysarch", .ret_type = 1, .nargs = 2,
496f44fc79dSJohn Baldwin 	  .args = { { Sysarch, 0 }, { Ptr, 1 } } },
497f44fc79dSJohn Baldwin 	{ .name = "thr_kill", .ret_type = 1, .nargs = 2,
498f44fc79dSJohn Baldwin 	  .args = { { Long, 0 }, { Signal, 1 } } },
499f44fc79dSJohn Baldwin 	{ .name = "thr_self", .ret_type = 1, .nargs = 1,
500f44fc79dSJohn Baldwin 	  .args = { { Ptr, 0 } } },
501d86cddf0SJohn Baldwin 	{ .name = "thr_set_name", .ret_type = 1, .nargs = 2,
502d86cddf0SJohn Baldwin 	  .args = { { Long, 0 }, { Name, 1 } } },
503f44fc79dSJohn Baldwin 	{ .name = "truncate", .ret_type = 1, .nargs = 2,
504c05cc0d6SJohn Baldwin 	  .args = { { Name | IN, 0 }, { QuadHex | IN, 1 } } },
505f44fc79dSJohn Baldwin #if 0
506f44fc79dSJohn Baldwin 	/* Does not exist */
507f44fc79dSJohn Baldwin 	{ .name = "umount", .ret_type = 1, .nargs = 2,
508f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 2 } } },
509f44fc79dSJohn Baldwin #endif
510f44fc79dSJohn Baldwin 	{ .name = "unlink", .ret_type = 1, .nargs = 1,
511f44fc79dSJohn Baldwin 	  .args = { { Name, 0 } } },
512f44fc79dSJohn Baldwin 	{ .name = "unlinkat", .ret_type = 1, .nargs = 3,
513f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } },
514f44fc79dSJohn Baldwin 	{ .name = "unmount", .ret_type = 1, .nargs = 2,
5158acc8e78SJohn Baldwin 	  .args = { { Name, 0 }, { Mountflags, 1 } } },
516f44fc79dSJohn Baldwin 	{ .name = "utimensat", .ret_type = 1, .nargs = 4,
517f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 },
518f44fc79dSJohn Baldwin 		    { Atflags, 3 } } },
519f44fc79dSJohn Baldwin 	{ .name = "utimes", .ret_type = 1, .nargs = 2,
520f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
521195aef99SBryan Drewery 	{ .name = "utrace", .ret_type = 1, .nargs = 1,
522195aef99SBryan Drewery 	  .args = { { Utrace, 0 } } },
52334763d1cSJohn Baldwin 	{ .name = "wait4", .ret_type = 1, .nargs = 4,
52434763d1cSJohn Baldwin 	  .args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 },
52534763d1cSJohn Baldwin 		    { Rusage | OUT, 3 } } },
52634763d1cSJohn Baldwin 	{ .name = "wait6", .ret_type = 1, .nargs = 6,
527c05cc0d6SJohn Baldwin 	  .args = { { Idtype, 0 }, { Quad, 1 }, { ExitStatus | OUT, 2 },
52813e5e6b6SJohn Baldwin 		    { Waitoptions, 3 }, { Rusage | OUT, 4 },
52913e5e6b6SJohn Baldwin 		    { Siginfo | OUT, 5 } } },
530f44fc79dSJohn Baldwin 	{ .name = "write", .ret_type = 1, .nargs = 3,
531e261fb2aSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 } } },
532ee6e58b2SMichael Tuexen 	{ .name = "writev", .ret_type = 1, .nargs = 3,
533dfcd2888SMichael Tuexen 	  .args = { { Int, 0 }, { Iovec | IN, 1 }, { Int, 2 } } },
534f44fc79dSJohn Baldwin 
535f44fc79dSJohn Baldwin 	/* Linux ABI */
536f44fc79dSJohn Baldwin 	{ .name = "linux_access", .ret_type = 1, .nargs = 2,
537f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Accessmode, 1 } } },
538f44fc79dSJohn Baldwin 	{ .name = "linux_execve", .ret_type = 1, .nargs = 3,
539f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
540f44fc79dSJohn Baldwin 		    { ExecEnv | IN, 2 } } },
541f44fc79dSJohn Baldwin 	{ .name = "linux_lseek", .ret_type = 2, .nargs = 3,
542f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } },
543f44fc79dSJohn Baldwin 	{ .name = "linux_mkdir", .ret_type = 1, .nargs = 2,
544f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Int, 1 } } },
545f44fc79dSJohn Baldwin 	{ .name = "linux_newfstat", .ret_type = 1, .nargs = 2,
546f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Ptr | OUT, 1 } } },
547f44fc79dSJohn Baldwin 	{ .name = "linux_newstat", .ret_type = 1, .nargs = 2,
548f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
549f44fc79dSJohn Baldwin 	{ .name = "linux_open", .ret_type = 1, .nargs = 3,
550f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } },
551f44fc79dSJohn Baldwin 	{ .name = "linux_readlink", .ret_type = 1, .nargs = 3,
552e261fb2aSJohn Baldwin 	  .args = { { Name, 0 }, { Name | OUT, 1 }, { Sizet, 2 } } },
553f44fc79dSJohn Baldwin 	{ .name = "linux_socketcall", .ret_type = 1, .nargs = 2,
554f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { LinuxSockArgs, 1 } } },
55564f4703bSJohn Baldwin 	{ .name = "linux_stat64", .ret_type = 1, .nargs = 2,
55664f4703bSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
557f44fc79dSJohn Baldwin 
558808d9805SEd Schouten 	/* CloudABI system calls. */
559808d9805SEd Schouten 	{ .name = "cloudabi_sys_clock_res_get", .ret_type = 1, .nargs = 1,
560808d9805SEd Schouten 	  .args = { { CloudABIClockID, 0 } } },
561808d9805SEd Schouten 	{ .name = "cloudabi_sys_clock_time_get", .ret_type = 1, .nargs = 2,
562808d9805SEd Schouten 	  .args = { { CloudABIClockID, 0 }, { CloudABITimestamp, 1 } } },
563808d9805SEd Schouten 	{ .name = "cloudabi_sys_condvar_signal", .ret_type = 1, .nargs = 3,
564808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { CloudABIMFlags, 1 }, { UInt, 2 } } },
565808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_close", .ret_type = 1, .nargs = 1,
566808d9805SEd Schouten 	  .args = { { Int, 0 } } },
567808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_create1", .ret_type = 1, .nargs = 1,
568808d9805SEd Schouten 	  .args = { { CloudABIFileType, 0 } } },
569808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_create2", .ret_type = 1, .nargs = 2,
570808d9805SEd Schouten 	  .args = { { CloudABIFileType, 0 }, { PipeFds | OUT, 0 } } },
571808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_datasync", .ret_type = 1, .nargs = 1,
572808d9805SEd Schouten 	  .args = { { Int, 0 } } },
573808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_dup", .ret_type = 1, .nargs = 1,
574808d9805SEd Schouten 	  .args = { { Int, 0 } } },
575808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_replace", .ret_type = 1, .nargs = 2,
576808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 } } },
577808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_seek", .ret_type = 1, .nargs = 3,
578808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { CloudABIWhence, 2 } } },
579808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_stat_get", .ret_type = 1, .nargs = 2,
580808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFDStat | OUT, 1 } } },
581808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_stat_put", .ret_type = 1, .nargs = 3,
582808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFDStat | IN, 1 },
583808d9805SEd Schouten 	            { ClouduABIFDSFlags, 2 } } },
584808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_sync", .ret_type = 1, .nargs = 1,
585808d9805SEd Schouten 	  .args = { { Int, 0 } } },
586808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_advise", .ret_type = 1, .nargs = 4,
587808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { Int, 2 },
588808d9805SEd Schouten 	            { CloudABIAdvice, 3 } } },
589808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_allocate", .ret_type = 1, .nargs = 3,
590808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
591808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_create", .ret_type = 1, .nargs = 3,
592808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
593808d9805SEd Schouten 	            { CloudABIFileType, 3 } } },
594808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_link", .ret_type = 1, .nargs = 4,
595808d9805SEd Schouten 	  .args = { { CloudABILookup, 0 }, { BinString | IN, 1 },
596808d9805SEd Schouten 	            { Int, 3 }, { BinString | IN, 4 } } },
597808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_open", .ret_type = 1, .nargs = 4,
598808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
599808d9805SEd Schouten 	            { CloudABIOFlags, 3 }, { CloudABIFDStat | IN, 4 } } },
600808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_readdir", .ret_type = 1, .nargs = 4,
601808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 },
602808d9805SEd Schouten 	            { Int, 3 } } },
603808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_readlink", .ret_type = 1, .nargs = 4,
604808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
605808d9805SEd Schouten 	            { BinString | OUT, 3 }, { Int, 4 } } },
606808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_rename", .ret_type = 1, .nargs = 4,
607808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
608808d9805SEd Schouten 	            { Int, 3 }, { BinString | IN, 4 } } },
609808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_fget", .ret_type = 1, .nargs = 2,
610808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFileStat | OUT, 1 } } },
611808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_fput", .ret_type = 1, .nargs = 3,
612808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFileStat | IN, 1 },
613808d9805SEd Schouten 	            { CloudABIFSFlags, 2 } } },
614808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_get", .ret_type = 1, .nargs = 3,
615808d9805SEd Schouten 	  .args = { { CloudABILookup, 0 }, { BinString | IN, 1 },
616808d9805SEd Schouten 	            { CloudABIFileStat | OUT, 3 } } },
617808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_put", .ret_type = 1, .nargs = 4,
618808d9805SEd Schouten 	  .args = { { CloudABILookup, 0 }, { BinString | IN, 1 },
619808d9805SEd Schouten 	            { CloudABIFileStat | IN, 3 }, { CloudABIFSFlags, 4 } } },
620808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_symlink", .ret_type = 1, .nargs = 3,
621808d9805SEd Schouten 	  .args = { { BinString | IN, 0 },
622808d9805SEd Schouten 	            { Int, 2 }, { BinString | IN, 3 } } },
623808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_unlink", .ret_type = 1, .nargs = 3,
624808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
625808d9805SEd Schouten 	            { CloudABIULFlags, 3 } } },
626808d9805SEd Schouten 	{ .name = "cloudabi_sys_lock_unlock", .ret_type = 1, .nargs = 2,
627808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } },
628808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_advise", .ret_type = 1, .nargs = 3,
629808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIAdvice, 2 } } },
630808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_map", .ret_type = 1, .nargs = 6,
631808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 },
632808d9805SEd Schouten 	            { CloudABIMFlags, 3 }, { Int, 4 }, { Int, 5 } } },
633808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_protect", .ret_type = 1, .nargs = 3,
634808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 } } },
635808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_sync", .ret_type = 1, .nargs = 3,
636808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMSFlags, 2 } } },
637808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_unmap", .ret_type = 1, .nargs = 2,
638808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 } } },
639808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_exec", .ret_type = 1, .nargs = 5,
640808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 },
641808d9805SEd Schouten 	            { IntArray, 3 }, { Int, 4 } } },
642808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_exit", .ret_type = 1, .nargs = 1,
643808d9805SEd Schouten 	  .args = { { Int, 0 } } },
644808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_fork", .ret_type = 1, .nargs = 0 },
645808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_raise", .ret_type = 1, .nargs = 1,
646808d9805SEd Schouten 	  .args = { { CloudABISignal, 0 } } },
647808d9805SEd Schouten 	{ .name = "cloudabi_sys_random_get", .ret_type = 1, .nargs = 2,
648808d9805SEd Schouten 	  .args = { { BinString | OUT, 0 }, { Int, 1 } } },
649808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_shutdown", .ret_type = 1, .nargs = 2,
650808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABISDFlags, 1 } } },
651808d9805SEd Schouten 	{ .name = "cloudabi_sys_thread_exit", .ret_type = 1, .nargs = 2,
652808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } },
653808d9805SEd Schouten 	{ .name = "cloudabi_sys_thread_yield", .ret_type = 1, .nargs = 0 },
654808d9805SEd Schouten 
655ee3b0f6eSDiomidis Spinellis 	{ .name = 0 },
656bbeaf6c0SSean Eric Fagan };
6576c61b0f3SBryan Drewery static STAILQ_HEAD(, syscall) syscalls;
658bbeaf6c0SSean Eric Fagan 
659081e5c48SPav Lucistnik /* Xlat idea taken from strace */
660081e5c48SPav Lucistnik struct xlat {
661081e5c48SPav Lucistnik 	int val;
6625d2d083cSXin LI 	const char *str;
663081e5c48SPav Lucistnik };
664081e5c48SPav Lucistnik 
665081e5c48SPav Lucistnik #define	X(a)	{ a, #a },
666081e5c48SPav Lucistnik #define	XEND	{ 0, NULL }
667081e5c48SPav Lucistnik 
668a02c83afSEd Schouten static struct xlat poll_flags[] = {
669081e5c48SPav Lucistnik 	X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR)
670081e5c48SPav Lucistnik 	X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND)
671081e5c48SPav Lucistnik 	X(POLLWRBAND) X(POLLINIGNEOF) XEND
672081e5c48SPav Lucistnik };
673081e5c48SPav Lucistnik 
674081e5c48SPav Lucistnik static struct xlat sigaction_flags[] = {
675081e5c48SPav Lucistnik 	X(SA_ONSTACK) X(SA_RESTART) X(SA_RESETHAND) X(SA_NOCLDSTOP)
676081e5c48SPav Lucistnik 	X(SA_NODEFER) X(SA_NOCLDWAIT) X(SA_SIGINFO) XEND
677081e5c48SPav Lucistnik };
678081e5c48SPav Lucistnik 
679fb7eabb0SJohn Baldwin static struct xlat linux_socketcall_ops[] = {
680fb7eabb0SJohn Baldwin 	X(LINUX_SOCKET) X(LINUX_BIND) X(LINUX_CONNECT) X(LINUX_LISTEN)
681fb7eabb0SJohn Baldwin 	X(LINUX_ACCEPT) X(LINUX_GETSOCKNAME) X(LINUX_GETPEERNAME)
682fb7eabb0SJohn Baldwin 	X(LINUX_SOCKETPAIR) X(LINUX_SEND) X(LINUX_RECV) X(LINUX_SENDTO)
683fb7eabb0SJohn Baldwin 	X(LINUX_RECVFROM) X(LINUX_SHUTDOWN) X(LINUX_SETSOCKOPT)
684fb7eabb0SJohn Baldwin 	X(LINUX_GETSOCKOPT) X(LINUX_SENDMSG) X(LINUX_RECVMSG)
685fb7eabb0SJohn Baldwin 	XEND
686fb7eabb0SJohn Baldwin };
687fb7eabb0SJohn Baldwin 
688081e5c48SPav Lucistnik #undef X
689808d9805SEd Schouten #define	X(a)	{ CLOUDABI_##a, #a },
690808d9805SEd Schouten 
691808d9805SEd Schouten static struct xlat cloudabi_advice[] = {
692808d9805SEd Schouten 	X(ADVICE_DONTNEED) X(ADVICE_NOREUSE) X(ADVICE_NORMAL)
693808d9805SEd Schouten 	X(ADVICE_RANDOM) X(ADVICE_SEQUENTIAL) X(ADVICE_WILLNEED)
694808d9805SEd Schouten 	XEND
695808d9805SEd Schouten };
696808d9805SEd Schouten 
697808d9805SEd Schouten static struct xlat cloudabi_clockid[] = {
698808d9805SEd Schouten 	X(CLOCK_MONOTONIC) X(CLOCK_PROCESS_CPUTIME_ID)
699808d9805SEd Schouten 	X(CLOCK_REALTIME) X(CLOCK_THREAD_CPUTIME_ID)
700808d9805SEd Schouten 	XEND
701808d9805SEd Schouten };
702808d9805SEd Schouten 
703808d9805SEd Schouten static struct xlat cloudabi_fdflags[] = {
704808d9805SEd Schouten 	X(FDFLAG_APPEND) X(FDFLAG_DSYNC) X(FDFLAG_NONBLOCK)
705808d9805SEd Schouten 	X(FDFLAG_RSYNC) X(FDFLAG_SYNC)
706808d9805SEd Schouten 	XEND
707808d9805SEd Schouten };
708808d9805SEd Schouten 
709808d9805SEd Schouten static struct xlat cloudabi_fdsflags[] = {
710808d9805SEd Schouten 	X(FDSTAT_FLAGS) X(FDSTAT_RIGHTS)
711808d9805SEd Schouten 	XEND
712808d9805SEd Schouten };
713808d9805SEd Schouten 
714808d9805SEd Schouten static struct xlat cloudabi_filetype[] = {
715808d9805SEd Schouten 	X(FILETYPE_UNKNOWN) X(FILETYPE_BLOCK_DEVICE)
716808d9805SEd Schouten 	X(FILETYPE_CHARACTER_DEVICE) X(FILETYPE_DIRECTORY)
7174e184778SEd Schouten 	X(FILETYPE_PROCESS) X(FILETYPE_REGULAR_FILE)
718733ba7f8SEd Schouten 	X(FILETYPE_SHARED_MEMORY) X(FILETYPE_SOCKET_DGRAM)
719733ba7f8SEd Schouten 	X(FILETYPE_SOCKET_STREAM) X(FILETYPE_SYMBOLIC_LINK)
720808d9805SEd Schouten 	XEND
721808d9805SEd Schouten };
722808d9805SEd Schouten 
723808d9805SEd Schouten static struct xlat cloudabi_fsflags[] = {
724808d9805SEd Schouten 	X(FILESTAT_ATIM) X(FILESTAT_ATIM_NOW) X(FILESTAT_MTIM)
725808d9805SEd Schouten 	X(FILESTAT_MTIM_NOW) X(FILESTAT_SIZE)
726808d9805SEd Schouten 	XEND
727808d9805SEd Schouten };
728808d9805SEd Schouten 
729808d9805SEd Schouten static struct xlat cloudabi_mflags[] = {
730808d9805SEd Schouten 	X(MAP_ANON) X(MAP_FIXED) X(MAP_PRIVATE) X(MAP_SHARED)
731808d9805SEd Schouten 	XEND
732808d9805SEd Schouten };
733808d9805SEd Schouten 
734808d9805SEd Schouten static struct xlat cloudabi_mprot[] = {
735808d9805SEd Schouten 	X(PROT_EXEC) X(PROT_WRITE) X(PROT_READ)
736808d9805SEd Schouten 	XEND
737808d9805SEd Schouten };
738808d9805SEd Schouten 
739808d9805SEd Schouten static struct xlat cloudabi_msflags[] = {
740808d9805SEd Schouten 	X(MS_ASYNC) X(MS_INVALIDATE) X(MS_SYNC)
741808d9805SEd Schouten 	XEND
742808d9805SEd Schouten };
743808d9805SEd Schouten 
744808d9805SEd Schouten static struct xlat cloudabi_oflags[] = {
745808d9805SEd Schouten 	X(O_CREAT) X(O_DIRECTORY) X(O_EXCL) X(O_TRUNC)
746808d9805SEd Schouten 	XEND
747808d9805SEd Schouten };
748808d9805SEd Schouten 
749808d9805SEd Schouten static struct xlat cloudabi_sdflags[] = {
750808d9805SEd Schouten 	X(SHUT_RD) X(SHUT_WR)
751808d9805SEd Schouten 	XEND
752808d9805SEd Schouten };
753808d9805SEd Schouten 
754808d9805SEd Schouten static struct xlat cloudabi_signal[] = {
755808d9805SEd Schouten 	X(SIGABRT) X(SIGALRM) X(SIGBUS) X(SIGCHLD) X(SIGCONT) X(SIGFPE)
756808d9805SEd Schouten 	X(SIGHUP) X(SIGILL) X(SIGINT) X(SIGKILL) X(SIGPIPE) X(SIGQUIT)
757808d9805SEd Schouten 	X(SIGSEGV) X(SIGSTOP) X(SIGSYS) X(SIGTERM) X(SIGTRAP) X(SIGTSTP)
758808d9805SEd Schouten 	X(SIGTTIN) X(SIGTTOU) X(SIGURG) X(SIGUSR1) X(SIGUSR2)
759808d9805SEd Schouten 	X(SIGVTALRM) X(SIGXCPU) X(SIGXFSZ)
760808d9805SEd Schouten 	XEND
761808d9805SEd Schouten };
762808d9805SEd Schouten 
763808d9805SEd Schouten static struct xlat cloudabi_ulflags[] = {
764808d9805SEd Schouten 	X(UNLINK_REMOVEDIR)
765808d9805SEd Schouten 	XEND
766808d9805SEd Schouten };
767808d9805SEd Schouten 
768808d9805SEd Schouten static struct xlat cloudabi_whence[] = {
769808d9805SEd Schouten 	X(WHENCE_CUR) X(WHENCE_END) X(WHENCE_SET)
770808d9805SEd Schouten 	XEND
771808d9805SEd Schouten };
772808d9805SEd Schouten 
773808d9805SEd Schouten #undef X
774081e5c48SPav Lucistnik #undef XEND
775081e5c48SPav Lucistnik 
776d8984f48SDag-Erling Smørgrav /*
777d8984f48SDag-Erling Smørgrav  * Searches an xlat array for a value, and returns it if found.  Otherwise
778d8984f48SDag-Erling Smørgrav  * return a string representation.
779d8984f48SDag-Erling Smørgrav  */
780d8984f48SDag-Erling Smørgrav static const char *
781d8984f48SDag-Erling Smørgrav lookup(struct xlat *xlat, int val, int base)
782081e5c48SPav Lucistnik {
783081e5c48SPav Lucistnik 	static char tmp[16];
784d8984f48SDag-Erling Smørgrav 
785081e5c48SPav Lucistnik 	for (; xlat->str != NULL; xlat++)
786081e5c48SPav Lucistnik 		if (xlat->val == val)
787d8984f48SDag-Erling Smørgrav 			return (xlat->str);
788081e5c48SPav Lucistnik 	switch (base) {
789081e5c48SPav Lucistnik 		case 8:
790081e5c48SPav Lucistnik 			sprintf(tmp, "0%o", val);
791081e5c48SPav Lucistnik 			break;
792081e5c48SPav Lucistnik 		case 16:
793081e5c48SPav Lucistnik 			sprintf(tmp, "0x%x", val);
794081e5c48SPav Lucistnik 			break;
795081e5c48SPav Lucistnik 		case 10:
796081e5c48SPav Lucistnik 			sprintf(tmp, "%u", val);
797081e5c48SPav Lucistnik 			break;
798081e5c48SPav Lucistnik 		default:
799081e5c48SPav Lucistnik 			errx(1,"Unknown lookup base");
800081e5c48SPav Lucistnik 			break;
801081e5c48SPav Lucistnik 	}
802d8984f48SDag-Erling Smørgrav 	return (tmp);
803081e5c48SPav Lucistnik }
804081e5c48SPav Lucistnik 
8055d2d083cSXin LI static const char *
8065d2d083cSXin LI xlookup(struct xlat *xlat, int val)
807081e5c48SPav Lucistnik {
808d8984f48SDag-Erling Smørgrav 
809d8984f48SDag-Erling Smørgrav 	return (lookup(xlat, val, 16));
810081e5c48SPav Lucistnik }
811081e5c48SPav Lucistnik 
8124e3da534SJohn Baldwin /*
8134e3da534SJohn Baldwin  * Searches an xlat array containing bitfield values.  Remaining bits
8144e3da534SJohn Baldwin  * set after removing the known ones are printed at the end:
8154e3da534SJohn Baldwin  * IN|0x400.
8164e3da534SJohn Baldwin  */
817d8984f48SDag-Erling Smørgrav static char *
818d8984f48SDag-Erling Smørgrav xlookup_bits(struct xlat *xlat, int val)
819081e5c48SPav Lucistnik {
82094355cfdSAndrey Zonov 	int len, rem;
821081e5c48SPav Lucistnik 	static char str[512];
822081e5c48SPav Lucistnik 
82394355cfdSAndrey Zonov 	len = 0;
82494355cfdSAndrey Zonov 	rem = val;
825d8984f48SDag-Erling Smørgrav 	for (; xlat->str != NULL; xlat++) {
826d8984f48SDag-Erling Smørgrav 		if ((xlat->val & rem) == xlat->val) {
8274e3da534SJohn Baldwin 			/*
8284e3da534SJohn Baldwin 			 * Don't print the "all-bits-zero" string unless all
8294e3da534SJohn Baldwin 			 * bits are really zero.
8304e3da534SJohn Baldwin 			 */
831081e5c48SPav Lucistnik 			if (xlat->val == 0 && val != 0)
832081e5c48SPav Lucistnik 				continue;
833081e5c48SPav Lucistnik 			len += sprintf(str + len, "%s|", xlat->str);
834081e5c48SPav Lucistnik 			rem &= ~(xlat->val);
835081e5c48SPav Lucistnik 		}
836081e5c48SPav Lucistnik 	}
8374e3da534SJohn Baldwin 
8384e3da534SJohn Baldwin 	/*
8394e3da534SJohn Baldwin 	 * If we have leftover bits or didn't match anything, print
8404e3da534SJohn Baldwin 	 * the remainder.
8414e3da534SJohn Baldwin 	 */
842081e5c48SPav Lucistnik 	if (rem || len == 0)
843081e5c48SPav Lucistnik 		len += sprintf(str + len, "0x%x", rem);
844081e5c48SPav Lucistnik 	if (len && str[len - 1] == '|')
845081e5c48SPav Lucistnik 		len--;
846081e5c48SPav Lucistnik 	str[len] = 0;
847d8984f48SDag-Erling Smørgrav 	return (str);
848081e5c48SPav Lucistnik }
849081e5c48SPav Lucistnik 
8509289f547SJohn Baldwin static void
8519289f547SJohn Baldwin print_integer_arg(const char *(*decoder)(int), FILE *fp, int value)
8529289f547SJohn Baldwin {
8539289f547SJohn Baldwin 	const char *str;
8549289f547SJohn Baldwin 
8559289f547SJohn Baldwin 	str = decoder(value);
8569289f547SJohn Baldwin 	if (str != NULL)
8579289f547SJohn Baldwin 		fputs(str, fp);
8589289f547SJohn Baldwin 	else
8599289f547SJohn Baldwin 		fprintf(fp, "%d", value);
8609289f547SJohn Baldwin }
8619289f547SJohn Baldwin 
8629289f547SJohn Baldwin static void
8639289f547SJohn Baldwin print_mask_arg(bool (*decoder)(FILE *, int, int *), FILE *fp, int value)
8649289f547SJohn Baldwin {
8659289f547SJohn Baldwin 	int rem;
8669289f547SJohn Baldwin 
8679289f547SJohn Baldwin 	if (!decoder(fp, value, &rem))
8689289f547SJohn Baldwin 		fprintf(fp, "0x%x", rem);
8699289f547SJohn Baldwin 	else if (rem != 0)
8709289f547SJohn Baldwin 		fprintf(fp, "|0x%x", rem);
8719289f547SJohn Baldwin }
8729289f547SJohn Baldwin 
873bed418c8SJohn Baldwin static void
874bed418c8SJohn Baldwin print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *), FILE *fp,
875bed418c8SJohn Baldwin     uint32_t value)
876bed418c8SJohn Baldwin {
877bed418c8SJohn Baldwin 	uint32_t rem;
878bed418c8SJohn Baldwin 
879bed418c8SJohn Baldwin 	if (!decoder(fp, value, &rem))
880bed418c8SJohn Baldwin 		fprintf(fp, "0x%x", rem);
881bed418c8SJohn Baldwin 	else if (rem != 0)
882bed418c8SJohn Baldwin 		fprintf(fp, "|0x%x", rem);
883bed418c8SJohn Baldwin }
884bed418c8SJohn Baldwin 
885c05cc0d6SJohn Baldwin #ifndef __LP64__
886c05cc0d6SJohn Baldwin /*
887c05cc0d6SJohn Baldwin  * Add argument padding to subsequent system calls afater a Quad
888c05cc0d6SJohn Baldwin  * syscall arguments as needed.  This used to be done by hand in the
889c05cc0d6SJohn Baldwin  * decoded_syscalls table which was ugly and error prone.  It is
890c05cc0d6SJohn Baldwin  * simpler to do the fixup of offsets at initalization time than when
891c05cc0d6SJohn Baldwin  * decoding arguments.
892c05cc0d6SJohn Baldwin  */
893c05cc0d6SJohn Baldwin static void
894c05cc0d6SJohn Baldwin quad_fixup(struct syscall *sc)
895c05cc0d6SJohn Baldwin {
896c05cc0d6SJohn Baldwin 	int offset, prev;
897c05cc0d6SJohn Baldwin 	u_int i;
898c05cc0d6SJohn Baldwin 
899c05cc0d6SJohn Baldwin 	offset = 0;
900c05cc0d6SJohn Baldwin 	prev = -1;
901c05cc0d6SJohn Baldwin 	for (i = 0; i < sc->nargs; i++) {
902c05cc0d6SJohn Baldwin 		/* This arg type is a dummy that doesn't use offset. */
903c05cc0d6SJohn Baldwin 		if ((sc->args[i].type & ARG_MASK) == PipeFds)
904c05cc0d6SJohn Baldwin 			continue;
905c05cc0d6SJohn Baldwin 
906c05cc0d6SJohn Baldwin 		assert(prev < sc->args[i].offset);
907c05cc0d6SJohn Baldwin 		prev = sc->args[i].offset;
908c05cc0d6SJohn Baldwin 		sc->args[i].offset += offset;
909c05cc0d6SJohn Baldwin 		switch (sc->args[i].type & ARG_MASK) {
910c05cc0d6SJohn Baldwin 		case Quad:
911c05cc0d6SJohn Baldwin 		case QuadHex:
912c05cc0d6SJohn Baldwin #ifdef __powerpc__
913c05cc0d6SJohn Baldwin 			/*
914c05cc0d6SJohn Baldwin 			 * 64-bit arguments on 32-bit powerpc must be
915c05cc0d6SJohn Baldwin 			 * 64-bit aligned.  If the current offset is
916c05cc0d6SJohn Baldwin 			 * not aligned, the calling convention inserts
917c05cc0d6SJohn Baldwin 			 * a 32-bit pad argument that should be skipped.
918c05cc0d6SJohn Baldwin 			 */
919c05cc0d6SJohn Baldwin 			if (sc->args[i].offset % 2 == 1) {
920c05cc0d6SJohn Baldwin 				sc->args[i].offset++;
921c05cc0d6SJohn Baldwin 				offset++;
922c05cc0d6SJohn Baldwin 			}
923c05cc0d6SJohn Baldwin #endif
924c05cc0d6SJohn Baldwin 			offset++;
925c05cc0d6SJohn Baldwin 		default:
926c05cc0d6SJohn Baldwin 			break;
927c05cc0d6SJohn Baldwin 		}
928c05cc0d6SJohn Baldwin 	}
929c05cc0d6SJohn Baldwin }
930c05cc0d6SJohn Baldwin #endif
931c05cc0d6SJohn Baldwin 
9326c61b0f3SBryan Drewery void
9336c61b0f3SBryan Drewery init_syscalls(void)
9346c61b0f3SBryan Drewery {
9356c61b0f3SBryan Drewery 	struct syscall *sc;
9366c61b0f3SBryan Drewery 
9376c61b0f3SBryan Drewery 	STAILQ_INIT(&syscalls);
938c05cc0d6SJohn Baldwin 	for (sc = decoded_syscalls; sc->name != NULL; sc++) {
939c05cc0d6SJohn Baldwin #ifndef __LP64__
940c05cc0d6SJohn Baldwin 		quad_fixup(sc);
941c05cc0d6SJohn Baldwin #endif
9426c61b0f3SBryan Drewery 		STAILQ_INSERT_HEAD(&syscalls, sc, entries);
9436c61b0f3SBryan Drewery 	}
944c05cc0d6SJohn Baldwin }
9451175b23fSJohn Baldwin 
9461175b23fSJohn Baldwin static struct syscall *
9471175b23fSJohn Baldwin find_syscall(struct procabi *abi, u_int number)
9481175b23fSJohn Baldwin {
9491175b23fSJohn Baldwin 	struct extra_syscall *es;
9501175b23fSJohn Baldwin 
9511175b23fSJohn Baldwin 	if (number < nitems(abi->syscalls))
9521175b23fSJohn Baldwin 		return (abi->syscalls[number]);
9531175b23fSJohn Baldwin 	STAILQ_FOREACH(es, &abi->extra_syscalls, entries) {
9541175b23fSJohn Baldwin 		if (es->number == number)
9551175b23fSJohn Baldwin 			return (es->sc);
9561175b23fSJohn Baldwin 	}
9571175b23fSJohn Baldwin 	return (NULL);
9581175b23fSJohn Baldwin }
9591175b23fSJohn Baldwin 
9601175b23fSJohn Baldwin static void
9611175b23fSJohn Baldwin add_syscall(struct procabi *abi, u_int number, struct syscall *sc)
9621175b23fSJohn Baldwin {
9631175b23fSJohn Baldwin 	struct extra_syscall *es;
9641175b23fSJohn Baldwin 
9651175b23fSJohn Baldwin 	if (number < nitems(abi->syscalls)) {
9661175b23fSJohn Baldwin 		assert(abi->syscalls[number] == NULL);
9671175b23fSJohn Baldwin 		abi->syscalls[number] = sc;
9681175b23fSJohn Baldwin 	} else {
9691175b23fSJohn Baldwin 		es = malloc(sizeof(*es));
9701175b23fSJohn Baldwin 		es->sc = sc;
9711175b23fSJohn Baldwin 		es->number = number;
9721175b23fSJohn Baldwin 		STAILQ_INSERT_TAIL(&abi->extra_syscalls, es, entries);
9731175b23fSJohn Baldwin 	}
9741175b23fSJohn Baldwin }
9751175b23fSJohn Baldwin 
976bbeaf6c0SSean Eric Fagan /*
977bbeaf6c0SSean Eric Fagan  * If/when the list gets big, it might be desirable to do it
978bbeaf6c0SSean Eric Fagan  * as a hash table or binary search.
979bbeaf6c0SSean Eric Fagan  */
980bbeaf6c0SSean Eric Fagan struct syscall *
9811175b23fSJohn Baldwin get_syscall(struct threadinfo *t, u_int number, u_int nargs)
982d8984f48SDag-Erling Smørgrav {
98394355cfdSAndrey Zonov 	struct syscall *sc;
9841175b23fSJohn Baldwin 	const char *name;
9851175b23fSJohn Baldwin 	char *new_name;
9861175b23fSJohn Baldwin 	u_int i;
987bbeaf6c0SSean Eric Fagan 
9881175b23fSJohn Baldwin 	sc = find_syscall(t->proc->abi, number);
9891175b23fSJohn Baldwin 	if (sc != NULL)
990d8984f48SDag-Erling Smørgrav 		return (sc);
9916c61b0f3SBryan Drewery 
9921175b23fSJohn Baldwin 	name = sysdecode_syscallname(t->proc->abi->abi, number);
9931175b23fSJohn Baldwin 	if (name == NULL) {
9941175b23fSJohn Baldwin 		asprintf(&new_name, "#%d", number);
9951175b23fSJohn Baldwin 		name = new_name;
9961175b23fSJohn Baldwin 	} else
9971175b23fSJohn Baldwin 		new_name = NULL;
9981175b23fSJohn Baldwin 	STAILQ_FOREACH(sc, &syscalls, entries) {
9991175b23fSJohn Baldwin 		if (strcmp(name, sc->name) == 0) {
10001175b23fSJohn Baldwin 			add_syscall(t->proc->abi, number, sc);
10011175b23fSJohn Baldwin 			free(new_name);
10021175b23fSJohn Baldwin 			return (sc);
10031175b23fSJohn Baldwin 		}
10041175b23fSJohn Baldwin 	}
10051175b23fSJohn Baldwin 
10066c61b0f3SBryan Drewery 	/* It is unknown.  Add it into the list. */
10076c61b0f3SBryan Drewery #if DEBUG
10086c61b0f3SBryan Drewery 	fprintf(stderr, "unknown syscall %s -- setting args to %d\n", name,
10096c61b0f3SBryan Drewery 	    nargs);
10106c61b0f3SBryan Drewery #endif
10116c61b0f3SBryan Drewery 
10126c61b0f3SBryan Drewery 	sc = calloc(1, sizeof(struct syscall));
10131175b23fSJohn Baldwin 	sc->name = name;
10141175b23fSJohn Baldwin 	if (new_name != NULL)
10151175b23fSJohn Baldwin 		sc->unknown = true;
10166c61b0f3SBryan Drewery 	sc->ret_type = 1;
10176c61b0f3SBryan Drewery 	sc->nargs = nargs;
10186c61b0f3SBryan Drewery 	for (i = 0; i < nargs; i++) {
10196c61b0f3SBryan Drewery 		sc->args[i].offset = i;
10206c61b0f3SBryan Drewery 		/* Treat all unknown arguments as LongHex. */
10216c61b0f3SBryan Drewery 		sc->args[i].type = LongHex;
1022bbeaf6c0SSean Eric Fagan 	}
10236c61b0f3SBryan Drewery 	STAILQ_INSERT_HEAD(&syscalls, sc, entries);
10241175b23fSJohn Baldwin 	add_syscall(t->proc->abi, number, sc);
10256c61b0f3SBryan Drewery 
10266c61b0f3SBryan Drewery 	return (sc);
1027bbeaf6c0SSean Eric Fagan }
1028bbeaf6c0SSean Eric Fagan 
1029bbeaf6c0SSean Eric Fagan /*
10309ddd1412SDag-Erling Smørgrav  * Copy a fixed amount of bytes from the process.
10319ddd1412SDag-Erling Smørgrav  */
10321be5d704SMark Murray static int
1033be305c9cSAndrey Zonov get_struct(pid_t pid, void *offset, void *buf, int len)
1034d8984f48SDag-Erling Smørgrav {
10355d2d083cSXin LI 	struct ptrace_io_desc iorequest;
10369ddd1412SDag-Erling Smørgrav 
10375d2d083cSXin LI 	iorequest.piod_op = PIOD_READ_D;
10385d2d083cSXin LI 	iorequest.piod_offs = offset;
10395d2d083cSXin LI 	iorequest.piod_addr = buf;
10405d2d083cSXin LI 	iorequest.piod_len = len;
10415d2d083cSXin LI 	if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0)
1042d8984f48SDag-Erling Smørgrav 		return (-1);
1043d8984f48SDag-Erling Smørgrav 	return (0);
10449ddd1412SDag-Erling Smørgrav }
10459ddd1412SDag-Erling Smørgrav 
10465d2d083cSXin LI #define	MAXSIZE		4096
1047abb3f965SJohn Baldwin 
10489ddd1412SDag-Erling Smørgrav /*
1049bbeaf6c0SSean Eric Fagan  * Copy a string from the process.  Note that it is
1050bbeaf6c0SSean Eric Fagan  * expected to be a C string, but if max is set, it will
1051bbeaf6c0SSean Eric Fagan  * only get that much.
1052bbeaf6c0SSean Eric Fagan  */
10535d2d083cSXin LI static char *
1054abb3f965SJohn Baldwin get_string(pid_t pid, void *addr, int max)
1055d8984f48SDag-Erling Smørgrav {
10565d2d083cSXin LI 	struct ptrace_io_desc iorequest;
1057abb3f965SJohn Baldwin 	char *buf, *nbuf;
1058abb3f965SJohn Baldwin 	size_t offset, size, totalsize;
1059bbeaf6c0SSean Eric Fagan 
1060abb3f965SJohn Baldwin 	offset = 0;
1061abb3f965SJohn Baldwin 	if (max)
1062abb3f965SJohn Baldwin 		size = max + 1;
1063abb3f965SJohn Baldwin 	else {
1064abb3f965SJohn Baldwin 		/* Read up to the end of the current page. */
1065abb3f965SJohn Baldwin 		size = PAGE_SIZE - ((uintptr_t)addr % PAGE_SIZE);
1066abb3f965SJohn Baldwin 		if (size > MAXSIZE)
1067abb3f965SJohn Baldwin 			size = MAXSIZE;
1068abb3f965SJohn Baldwin 	}
1069abb3f965SJohn Baldwin 	totalsize = size;
10705d2d083cSXin LI 	buf = malloc(totalsize);
10715d2d083cSXin LI 	if (buf == NULL)
1072d8984f48SDag-Erling Smørgrav 		return (NULL);
10735d2d083cSXin LI 	for (;;) {
10745d2d083cSXin LI 		iorequest.piod_op = PIOD_READ_D;
1075abb3f965SJohn Baldwin 		iorequest.piod_offs = (char *)addr + offset;
1076abb3f965SJohn Baldwin 		iorequest.piod_addr = buf + offset;
10775d2d083cSXin LI 		iorequest.piod_len = size;
10785d2d083cSXin LI 		if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) {
10795d2d083cSXin LI 			free(buf);
1080d8984f48SDag-Erling Smørgrav 			return (NULL);
1081bbeaf6c0SSean Eric Fagan 		}
1082abb3f965SJohn Baldwin 		if (memchr(buf + offset, '\0', size) != NULL)
1083abb3f965SJohn Baldwin 			return (buf);
1084abb3f965SJohn Baldwin 		offset += size;
1085abb3f965SJohn Baldwin 		if (totalsize < MAXSIZE && max == 0) {
1086abb3f965SJohn Baldwin 			size = MAXSIZE - totalsize;
1087abb3f965SJohn Baldwin 			if (size > PAGE_SIZE)
1088abb3f965SJohn Baldwin 				size = PAGE_SIZE;
1089abb3f965SJohn Baldwin 			nbuf = realloc(buf, totalsize + size);
1090abb3f965SJohn Baldwin 			if (nbuf == NULL) {
1091abb3f965SJohn Baldwin 				buf[totalsize - 1] = '\0';
10924e92419dSMarcel Moolenaar 				return (buf);
1093bbeaf6c0SSean Eric Fagan 			}
1094abb3f965SJohn Baldwin 			buf = nbuf;
1095abb3f965SJohn Baldwin 			totalsize += size;
1096d8984f48SDag-Erling Smørgrav 		} else {
1097cdfc719cSJaakko Heinonen 			buf[totalsize - 1] = '\0';
1098d8984f48SDag-Erling Smørgrav 			return (buf);
10995d2d083cSXin LI 		}
11005d2d083cSXin LI 	}
11015d2d083cSXin LI }
1102bbeaf6c0SSean Eric Fagan 
11039289f547SJohn Baldwin static const char *
110434763d1cSJohn Baldwin strsig2(int sig)
110534763d1cSJohn Baldwin {
11069289f547SJohn Baldwin 	static char tmp[32];
11079289f547SJohn Baldwin 	const char *signame;
110834763d1cSJohn Baldwin 
11099289f547SJohn Baldwin 	signame = sysdecode_signal(sig);
11109289f547SJohn Baldwin 	if (signame == NULL) {
1111f083f689SJohn Baldwin 		snprintf(tmp, sizeof(tmp), "%d", sig);
11129289f547SJohn Baldwin 		signame = tmp;
1113f083f689SJohn Baldwin 	}
11149289f547SJohn Baldwin 	return (signame);
111534763d1cSJohn Baldwin }
1116bbeaf6c0SSean Eric Fagan 
1117c915ff03SJohn Baldwin static void
1118ffb66079SJohn Baldwin print_kevent(FILE *fp, struct kevent *ke)
1119c915ff03SJohn Baldwin {
1120c915ff03SJohn Baldwin 
1121c915ff03SJohn Baldwin 	switch (ke->filter) {
1122c915ff03SJohn Baldwin 	case EVFILT_READ:
1123c915ff03SJohn Baldwin 	case EVFILT_WRITE:
1124c915ff03SJohn Baldwin 	case EVFILT_VNODE:
1125c915ff03SJohn Baldwin 	case EVFILT_PROC:
1126c915ff03SJohn Baldwin 	case EVFILT_TIMER:
1127c915ff03SJohn Baldwin 	case EVFILT_PROCDESC:
1128ffb66079SJohn Baldwin 	case EVFILT_EMPTY:
1129c915ff03SJohn Baldwin 		fprintf(fp, "%ju", (uintmax_t)ke->ident);
1130c915ff03SJohn Baldwin 		break;
1131c915ff03SJohn Baldwin 	case EVFILT_SIGNAL:
1132c915ff03SJohn Baldwin 		fputs(strsig2(ke->ident), fp);
1133c915ff03SJohn Baldwin 		break;
1134c915ff03SJohn Baldwin 	default:
1135c915ff03SJohn Baldwin 		fprintf(fp, "%p", (void *)ke->ident);
1136c915ff03SJohn Baldwin 	}
1137ffb66079SJohn Baldwin 	fprintf(fp, ",");
1138ffb66079SJohn Baldwin 	print_integer_arg(sysdecode_kevent_filter, fp, ke->filter);
1139ffb66079SJohn Baldwin 	fprintf(fp, ",");
1140ffb66079SJohn Baldwin 	print_mask_arg(sysdecode_kevent_flags, fp, ke->flags);
1141ffb66079SJohn Baldwin 	fprintf(fp, ",");
1142ffb66079SJohn Baldwin 	sysdecode_kevent_fflags(fp, ke->filter, ke->fflags, 16);
11432b34e843SKonstantin Belousov 	fprintf(fp, ",%#jx,%p", (uintmax_t)ke->data, ke->udata);
1144c915ff03SJohn Baldwin }
1145c915ff03SJohn Baldwin 
1146195aef99SBryan Drewery static void
1147195aef99SBryan Drewery print_utrace(FILE *fp, void *utrace_addr, size_t len)
1148195aef99SBryan Drewery {
1149195aef99SBryan Drewery 	unsigned char *utrace_buffer;
1150195aef99SBryan Drewery 
1151195aef99SBryan Drewery 	fprintf(fp, "{ ");
1152d6fb4894SJohn Baldwin 	if (sysdecode_utrace(fp, utrace_addr, len)) {
1153195aef99SBryan Drewery 		fprintf(fp, " }");
1154195aef99SBryan Drewery 		return;
1155195aef99SBryan Drewery 	}
1156195aef99SBryan Drewery 
1157195aef99SBryan Drewery 	utrace_buffer = utrace_addr;
1158195aef99SBryan Drewery 	fprintf(fp, "%zu:", len);
1159195aef99SBryan Drewery 	while (len--)
1160195aef99SBryan Drewery 		fprintf(fp, " %02x", *utrace_buffer++);
1161195aef99SBryan Drewery 	fprintf(fp, " }");
1162195aef99SBryan Drewery }
1163195aef99SBryan Drewery 
1164a2674e03SMichael Tuexen static void
1165a2674e03SMichael Tuexen print_sockaddr(FILE *fp, struct trussinfo *trussinfo, void *arg, socklen_t len)
1166a2674e03SMichael Tuexen {
1167a2674e03SMichael Tuexen 	char addr[64];
1168a2674e03SMichael Tuexen 	struct sockaddr_in *lsin;
1169a2674e03SMichael Tuexen 	struct sockaddr_in6 *lsin6;
1170a2674e03SMichael Tuexen 	struct sockaddr_un *sun;
1171a2674e03SMichael Tuexen 	struct sockaddr *sa;
1172a2674e03SMichael Tuexen 	u_char *q;
1173a2674e03SMichael Tuexen 	pid_t pid = trussinfo->curthread->proc->pid;
1174a2674e03SMichael Tuexen 
1175a2674e03SMichael Tuexen 	if (arg == NULL) {
1176a2674e03SMichael Tuexen 		fputs("NULL", fp);
1177a2674e03SMichael Tuexen 		return;
1178a2674e03SMichael Tuexen 	}
1179a2674e03SMichael Tuexen 	/* If the length is too small, just bail. */
1180a2674e03SMichael Tuexen 	if (len < sizeof(*sa)) {
11813193be24SMichael Tuexen 		fprintf(fp, "%p", arg);
1182a2674e03SMichael Tuexen 		return;
1183a2674e03SMichael Tuexen 	}
1184a2674e03SMichael Tuexen 
1185a2674e03SMichael Tuexen 	sa = calloc(1, len);
1186a2674e03SMichael Tuexen 	if (get_struct(pid, arg, sa, len) == -1) {
1187a2674e03SMichael Tuexen 		free(sa);
11883193be24SMichael Tuexen 		fprintf(fp, "%p", arg);
1189a2674e03SMichael Tuexen 		return;
1190a2674e03SMichael Tuexen 	}
1191a2674e03SMichael Tuexen 
1192a2674e03SMichael Tuexen 	switch (sa->sa_family) {
1193a2674e03SMichael Tuexen 	case AF_INET:
1194a2674e03SMichael Tuexen 		if (len < sizeof(*lsin))
1195a2674e03SMichael Tuexen 			goto sockaddr_short;
1196a2674e03SMichael Tuexen 		lsin = (struct sockaddr_in *)(void *)sa;
1197a2674e03SMichael Tuexen 		inet_ntop(AF_INET, &lsin->sin_addr, addr, sizeof(addr));
1198a2674e03SMichael Tuexen 		fprintf(fp, "{ AF_INET %s:%d }", addr,
1199a2674e03SMichael Tuexen 		    htons(lsin->sin_port));
1200a2674e03SMichael Tuexen 		break;
1201a2674e03SMichael Tuexen 	case AF_INET6:
1202a2674e03SMichael Tuexen 		if (len < sizeof(*lsin6))
1203a2674e03SMichael Tuexen 			goto sockaddr_short;
1204a2674e03SMichael Tuexen 		lsin6 = (struct sockaddr_in6 *)(void *)sa;
1205a2674e03SMichael Tuexen 		inet_ntop(AF_INET6, &lsin6->sin6_addr, addr,
1206a2674e03SMichael Tuexen 		    sizeof(addr));
1207a2674e03SMichael Tuexen 		fprintf(fp, "{ AF_INET6 [%s]:%d }", addr,
1208a2674e03SMichael Tuexen 		    htons(lsin6->sin6_port));
1209a2674e03SMichael Tuexen 		break;
1210a2674e03SMichael Tuexen 	case AF_UNIX:
1211a2674e03SMichael Tuexen 		sun = (struct sockaddr_un *)sa;
1212a2674e03SMichael Tuexen 		fprintf(fp, "{ AF_UNIX \"%.*s\" }",
1213a2674e03SMichael Tuexen 		    (int)(len - offsetof(struct sockaddr_un, sun_path)),
1214a2674e03SMichael Tuexen 		    sun->sun_path);
1215a2674e03SMichael Tuexen 		break;
1216a2674e03SMichael Tuexen 	default:
1217a2674e03SMichael Tuexen 	sockaddr_short:
1218a2674e03SMichael Tuexen 		fprintf(fp,
1219a2674e03SMichael Tuexen 		    "{ sa_len = %d, sa_family = %d, sa_data = {",
1220a2674e03SMichael Tuexen 		    (int)sa->sa_len, (int)sa->sa_family);
1221a2674e03SMichael Tuexen 		for (q = (u_char *)sa->sa_data;
1222a2674e03SMichael Tuexen 		     q < (u_char *)sa + len; q++)
1223a2674e03SMichael Tuexen 			fprintf(fp, "%s 0x%02x",
1224a2674e03SMichael Tuexen 			    q == (u_char *)sa->sa_data ? "" : ",",
1225a2674e03SMichael Tuexen 			    *q);
1226a2674e03SMichael Tuexen 		fputs(" } }", fp);
1227a2674e03SMichael Tuexen 	}
1228a2674e03SMichael Tuexen 	free(sa);
1229a2674e03SMichael Tuexen }
1230a2674e03SMichael Tuexen 
1231a2674e03SMichael Tuexen #define IOV_LIMIT 16
1232a2674e03SMichael Tuexen 
1233a2674e03SMichael Tuexen static void
1234a2674e03SMichael Tuexen print_iovec(FILE *fp, struct trussinfo *trussinfo, void *arg, int iovcnt)
1235a2674e03SMichael Tuexen {
1236a2674e03SMichael Tuexen 	struct iovec iov[IOV_LIMIT];
1237a2674e03SMichael Tuexen 	size_t max_string = trussinfo->strsize;
1238a2674e03SMichael Tuexen 	char tmp2[max_string + 1], *tmp3;
1239a2674e03SMichael Tuexen 	size_t len;
1240a2674e03SMichael Tuexen 	pid_t pid = trussinfo->curthread->proc->pid;
1241a2674e03SMichael Tuexen 	int i;
1242a2674e03SMichael Tuexen 	bool buf_truncated, iov_truncated;
1243a2674e03SMichael Tuexen 
1244a2674e03SMichael Tuexen 	if (iovcnt <= 0) {
12453193be24SMichael Tuexen 		fprintf(fp, "%p", arg);
1246a2674e03SMichael Tuexen 		return;
1247a2674e03SMichael Tuexen 	}
1248a2674e03SMichael Tuexen 	if (iovcnt > IOV_LIMIT) {
1249a2674e03SMichael Tuexen 		iovcnt = IOV_LIMIT;
1250a2674e03SMichael Tuexen 		iov_truncated = true;
1251a2674e03SMichael Tuexen 	} else {
1252a2674e03SMichael Tuexen 		iov_truncated = false;
1253a2674e03SMichael Tuexen 	}
1254a2674e03SMichael Tuexen 	if (get_struct(pid, arg, &iov, iovcnt * sizeof(struct iovec)) == -1) {
12553193be24SMichael Tuexen 		fprintf(fp, "%p", arg);
1256a2674e03SMichael Tuexen 		return;
1257a2674e03SMichael Tuexen 	}
1258a2674e03SMichael Tuexen 
1259a2674e03SMichael Tuexen 	fputs("[", fp);
1260a2674e03SMichael Tuexen 	for (i = 0; i < iovcnt; i++) {
1261a2674e03SMichael Tuexen 		len = iov[i].iov_len;
1262a2674e03SMichael Tuexen 		if (len > max_string) {
1263a2674e03SMichael Tuexen 			len = max_string;
1264a2674e03SMichael Tuexen 			buf_truncated = true;
1265a2674e03SMichael Tuexen 		} else {
1266a2674e03SMichael Tuexen 			buf_truncated = false;
1267a2674e03SMichael Tuexen 		}
1268a2674e03SMichael Tuexen 		fprintf(fp, "%s{", (i > 0) ? "," : "");
1269a2674e03SMichael Tuexen 		if (len && get_struct(pid, iov[i].iov_base, &tmp2, len) != -1) {
1270a2674e03SMichael Tuexen 			tmp3 = malloc(len * 4 + 1);
1271a2674e03SMichael Tuexen 			while (len) {
1272a2674e03SMichael Tuexen 				if (strvisx(tmp3, tmp2, len,
1273a2674e03SMichael Tuexen 				    VIS_CSTYLE|VIS_TAB|VIS_NL) <=
1274a2674e03SMichael Tuexen 				    (int)max_string)
1275a2674e03SMichael Tuexen 					break;
1276a2674e03SMichael Tuexen 				len--;
1277a2674e03SMichael Tuexen 				buf_truncated = true;
1278a2674e03SMichael Tuexen 			}
1279a2674e03SMichael Tuexen 			fprintf(fp, "\"%s\"%s", tmp3,
1280a2674e03SMichael Tuexen 			    buf_truncated ? "..." : "");
1281a2674e03SMichael Tuexen 			free(tmp3);
1282a2674e03SMichael Tuexen 		} else {
12833193be24SMichael Tuexen 			fprintf(fp, "%p", iov[i].iov_base);
1284a2674e03SMichael Tuexen 		}
1285a2674e03SMichael Tuexen 		fprintf(fp, ",%zu}", iov[i].iov_len);
1286a2674e03SMichael Tuexen 	}
1287a2674e03SMichael Tuexen 	fprintf(fp, "%s%s", iov_truncated ? ",..." : "", "]");
1288a2674e03SMichael Tuexen }
1289a2674e03SMichael Tuexen 
1290a2674e03SMichael Tuexen static void
1291a2674e03SMichael Tuexen print_gen_cmsg(FILE *fp, struct cmsghdr *cmsghdr)
1292a2674e03SMichael Tuexen {
1293a2674e03SMichael Tuexen 	u_char *q;
1294a2674e03SMichael Tuexen 
1295a2674e03SMichael Tuexen 	fputs("{", fp);
1296a2674e03SMichael Tuexen 	for (q = CMSG_DATA(cmsghdr);
1297a2674e03SMichael Tuexen 	     q < (u_char *)cmsghdr + cmsghdr->cmsg_len; q++) {
1298a2674e03SMichael Tuexen 		fprintf(fp, "%s0x%02x", q == CMSG_DATA(cmsghdr) ? "" : ",", *q);
1299a2674e03SMichael Tuexen 	}
1300a2674e03SMichael Tuexen 	fputs("}", fp);
1301a2674e03SMichael Tuexen }
1302a2674e03SMichael Tuexen 
1303a2674e03SMichael Tuexen static void
1304a2674e03SMichael Tuexen print_sctp_initmsg(FILE *fp, struct sctp_initmsg *init)
1305a2674e03SMichael Tuexen {
1306a2674e03SMichael Tuexen 	fprintf(fp, "{out=%u,", init->sinit_num_ostreams);
1307a2674e03SMichael Tuexen 	fprintf(fp, "in=%u,", init->sinit_max_instreams);
1308a2674e03SMichael Tuexen 	fprintf(fp, "max_rtx=%u,", init->sinit_max_attempts);
1309a2674e03SMichael Tuexen 	fprintf(fp, "max_rto=%u}", init->sinit_max_init_timeo);
1310a2674e03SMichael Tuexen }
1311a2674e03SMichael Tuexen 
1312a2674e03SMichael Tuexen static void
131376785d6eSJohn Baldwin print_sctp_sndrcvinfo(FILE *fp, bool receive, struct sctp_sndrcvinfo *info)
1314a2674e03SMichael Tuexen {
1315a2674e03SMichael Tuexen 	fprintf(fp, "{sid=%u,", info->sinfo_stream);
131676785d6eSJohn Baldwin 	if (receive) {
1317a2674e03SMichael Tuexen 		fprintf(fp, "ssn=%u,", info->sinfo_ssn);
1318a2674e03SMichael Tuexen 	}
1319a2674e03SMichael Tuexen 	fputs("flgs=", fp);
1320a2674e03SMichael Tuexen 	sysdecode_sctp_sinfo_flags(fp, info->sinfo_flags);
1321a2674e03SMichael Tuexen 	fprintf(fp, ",ppid=%u,", ntohl(info->sinfo_ppid));
132276785d6eSJohn Baldwin 	if (!receive) {
1323a2674e03SMichael Tuexen 		fprintf(fp, "ctx=%u,", info->sinfo_context);
1324a2674e03SMichael Tuexen 		fprintf(fp, "ttl=%u,", info->sinfo_timetolive);
1325a2674e03SMichael Tuexen 	}
132676785d6eSJohn Baldwin 	if (receive) {
1327a2674e03SMichael Tuexen 		fprintf(fp, "tsn=%u,", info->sinfo_tsn);
1328a2674e03SMichael Tuexen 		fprintf(fp, "cumtsn=%u,", info->sinfo_cumtsn);
1329a2674e03SMichael Tuexen 	}
1330a2674e03SMichael Tuexen 	fprintf(fp, "id=%u}", info->sinfo_assoc_id);
1331a2674e03SMichael Tuexen }
1332a2674e03SMichael Tuexen 
1333a2674e03SMichael Tuexen static void
1334a2674e03SMichael Tuexen print_sctp_sndinfo(FILE *fp, struct sctp_sndinfo *info)
1335a2674e03SMichael Tuexen {
1336a2674e03SMichael Tuexen 	fprintf(fp, "{sid=%u,", info->snd_sid);
1337a2674e03SMichael Tuexen 	fputs("flgs=", fp);
1338a2674e03SMichael Tuexen 	print_mask_arg(sysdecode_sctp_snd_flags, fp, info->snd_flags);
1339a2674e03SMichael Tuexen 	fprintf(fp, ",ppid=%u,", ntohl(info->snd_ppid));
1340a2674e03SMichael Tuexen 	fprintf(fp, "ctx=%u,", info->snd_context);
1341a2674e03SMichael Tuexen 	fprintf(fp, "id=%u}", info->snd_assoc_id);
1342a2674e03SMichael Tuexen }
1343a2674e03SMichael Tuexen 
1344a2674e03SMichael Tuexen static void
1345a2674e03SMichael Tuexen print_sctp_rcvinfo(FILE *fp, struct sctp_rcvinfo *info)
1346a2674e03SMichael Tuexen {
1347a2674e03SMichael Tuexen 	fprintf(fp, "{sid=%u,", info->rcv_sid);
1348a2674e03SMichael Tuexen 	fprintf(fp, "ssn=%u,", info->rcv_ssn);
1349a2674e03SMichael Tuexen 	fputs("flgs=", fp);
1350a2674e03SMichael Tuexen 	print_mask_arg(sysdecode_sctp_rcv_flags, fp, info->rcv_flags);
1351a2674e03SMichael Tuexen 	fprintf(fp, ",ppid=%u,", ntohl(info->rcv_ppid));
1352a2674e03SMichael Tuexen 	fprintf(fp, "tsn=%u,", info->rcv_tsn);
1353a2674e03SMichael Tuexen 	fprintf(fp, "cumtsn=%u,", info->rcv_cumtsn);
1354a2674e03SMichael Tuexen 	fprintf(fp, "ctx=%u,", info->rcv_context);
1355a2674e03SMichael Tuexen 	fprintf(fp, "id=%u}", info->rcv_assoc_id);
1356a2674e03SMichael Tuexen }
1357a2674e03SMichael Tuexen 
1358a2674e03SMichael Tuexen static void
1359a2674e03SMichael Tuexen print_sctp_nxtinfo(FILE *fp, struct sctp_nxtinfo *info)
1360a2674e03SMichael Tuexen {
1361a2674e03SMichael Tuexen 	fprintf(fp, "{sid=%u,", info->nxt_sid);
1362a2674e03SMichael Tuexen 	fputs("flgs=", fp);
1363a2674e03SMichael Tuexen 	print_mask_arg(sysdecode_sctp_nxt_flags, fp, info->nxt_flags);
1364a2674e03SMichael Tuexen 	fprintf(fp, ",ppid=%u,", ntohl(info->nxt_ppid));
1365a2674e03SMichael Tuexen 	fprintf(fp, "len=%u,", info->nxt_length);
1366a2674e03SMichael Tuexen 	fprintf(fp, "id=%u}", info->nxt_assoc_id);
1367a2674e03SMichael Tuexen }
1368a2674e03SMichael Tuexen 
1369a2674e03SMichael Tuexen static void
1370a2674e03SMichael Tuexen print_sctp_prinfo(FILE *fp, struct sctp_prinfo *info)
1371a2674e03SMichael Tuexen {
1372a2674e03SMichael Tuexen 	fputs("{pol=", fp);
1373a2674e03SMichael Tuexen 	print_integer_arg(sysdecode_sctp_pr_policy, fp, info->pr_policy);
1374a2674e03SMichael Tuexen 	fprintf(fp, ",val=%u}", info->pr_value);
1375a2674e03SMichael Tuexen }
1376a2674e03SMichael Tuexen 
1377a2674e03SMichael Tuexen static void
1378a2674e03SMichael Tuexen print_sctp_authinfo(FILE *fp, struct sctp_authinfo *info)
1379a2674e03SMichael Tuexen {
1380a2674e03SMichael Tuexen 	fprintf(fp, "{num=%u}", info->auth_keynumber);
1381a2674e03SMichael Tuexen }
1382a2674e03SMichael Tuexen 
1383a2674e03SMichael Tuexen static void
1384a2674e03SMichael Tuexen print_sctp_ipv4_addr(FILE *fp, struct in_addr *addr)
1385a2674e03SMichael Tuexen {
1386a2674e03SMichael Tuexen 	char buf[INET_ADDRSTRLEN];
1387a2674e03SMichael Tuexen 	const char *s;
1388a2674e03SMichael Tuexen 
1389a2674e03SMichael Tuexen 	s = inet_ntop(AF_INET, addr, buf, INET_ADDRSTRLEN);
1390a2674e03SMichael Tuexen 	if (s != NULL)
1391a2674e03SMichael Tuexen 		fprintf(fp, "{addr=%s}", s);
1392a2674e03SMichael Tuexen 	else
1393a2674e03SMichael Tuexen 		fputs("{addr=???}", fp);
1394a2674e03SMichael Tuexen }
1395a2674e03SMichael Tuexen 
1396a2674e03SMichael Tuexen static void
1397a2674e03SMichael Tuexen print_sctp_ipv6_addr(FILE *fp, struct in6_addr *addr)
1398a2674e03SMichael Tuexen {
1399a2674e03SMichael Tuexen 	char buf[INET6_ADDRSTRLEN];
1400a2674e03SMichael Tuexen 	const char *s;
1401a2674e03SMichael Tuexen 
1402a2674e03SMichael Tuexen 	s = inet_ntop(AF_INET6, addr, buf, INET6_ADDRSTRLEN);
1403a2674e03SMichael Tuexen 	if (s != NULL)
1404a2674e03SMichael Tuexen 		fprintf(fp, "{addr=%s}", s);
1405a2674e03SMichael Tuexen 	else
1406a2674e03SMichael Tuexen 		fputs("{addr=???}", fp);
1407a2674e03SMichael Tuexen }
1408a2674e03SMichael Tuexen 
1409a2674e03SMichael Tuexen static void
141076785d6eSJohn Baldwin print_sctp_cmsg(FILE *fp, bool receive, struct cmsghdr *cmsghdr)
1411a2674e03SMichael Tuexen {
1412a2674e03SMichael Tuexen 	void *data;
1413a2674e03SMichael Tuexen 	socklen_t len;
1414a2674e03SMichael Tuexen 
1415a2674e03SMichael Tuexen 	len = cmsghdr->cmsg_len;
1416a2674e03SMichael Tuexen 	data = CMSG_DATA(cmsghdr);
1417a2674e03SMichael Tuexen 	switch (cmsghdr->cmsg_type) {
1418a2674e03SMichael Tuexen 	case SCTP_INIT:
1419a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_initmsg)))
1420a2674e03SMichael Tuexen 			print_sctp_initmsg(fp, (struct sctp_initmsg *)data);
1421a2674e03SMichael Tuexen 		else
1422a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1423a2674e03SMichael Tuexen 		break;
1424a2674e03SMichael Tuexen 	case SCTP_SNDRCV:
1425a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_sndrcvinfo)))
142676785d6eSJohn Baldwin 			print_sctp_sndrcvinfo(fp, receive,
1427a2674e03SMichael Tuexen 			    (struct sctp_sndrcvinfo *)data);
1428a2674e03SMichael Tuexen 		else
1429a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1430a2674e03SMichael Tuexen 		break;
1431a2674e03SMichael Tuexen #if 0
1432a2674e03SMichael Tuexen 	case SCTP_EXTRCV:
1433a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_extrcvinfo)))
1434a2674e03SMichael Tuexen 			print_sctp_extrcvinfo(fp,
1435a2674e03SMichael Tuexen 			    (struct sctp_extrcvinfo *)data);
1436a2674e03SMichael Tuexen 		else
1437a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1438a2674e03SMichael Tuexen 		break;
1439a2674e03SMichael Tuexen #endif
1440a2674e03SMichael Tuexen 	case SCTP_SNDINFO:
1441a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_sndinfo)))
1442a2674e03SMichael Tuexen 			print_sctp_sndinfo(fp, (struct sctp_sndinfo *)data);
1443a2674e03SMichael Tuexen 		else
1444a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1445a2674e03SMichael Tuexen 		break;
1446a2674e03SMichael Tuexen 	case SCTP_RCVINFO:
1447a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_rcvinfo)))
1448a2674e03SMichael Tuexen 			print_sctp_rcvinfo(fp, (struct sctp_rcvinfo *)data);
1449a2674e03SMichael Tuexen 		else
1450a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1451a2674e03SMichael Tuexen 		break;
1452a2674e03SMichael Tuexen 	case SCTP_NXTINFO:
1453a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_nxtinfo)))
1454a2674e03SMichael Tuexen 			print_sctp_nxtinfo(fp, (struct sctp_nxtinfo *)data);
1455a2674e03SMichael Tuexen 		else
1456a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1457a2674e03SMichael Tuexen 		break;
1458a2674e03SMichael Tuexen 	case SCTP_PRINFO:
1459a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_prinfo)))
1460a2674e03SMichael Tuexen 			print_sctp_prinfo(fp, (struct sctp_prinfo *)data);
1461a2674e03SMichael Tuexen 		else
1462a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1463a2674e03SMichael Tuexen 		break;
1464a2674e03SMichael Tuexen 	case SCTP_AUTHINFO:
1465a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct sctp_authinfo)))
1466a2674e03SMichael Tuexen 			print_sctp_authinfo(fp, (struct sctp_authinfo *)data);
1467a2674e03SMichael Tuexen 		else
1468a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1469a2674e03SMichael Tuexen 		break;
1470a2674e03SMichael Tuexen 	case SCTP_DSTADDRV4:
1471a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct in_addr)))
1472a2674e03SMichael Tuexen 			print_sctp_ipv4_addr(fp, (struct in_addr *)data);
1473a2674e03SMichael Tuexen 		else
1474a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1475a2674e03SMichael Tuexen 		break;
1476a2674e03SMichael Tuexen 	case SCTP_DSTADDRV6:
1477a2674e03SMichael Tuexen 		if (len == CMSG_LEN(sizeof(struct in6_addr)))
1478a2674e03SMichael Tuexen 			print_sctp_ipv6_addr(fp, (struct in6_addr *)data);
1479a2674e03SMichael Tuexen 		else
1480a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1481a2674e03SMichael Tuexen 		break;
1482a2674e03SMichael Tuexen 	default:
1483a2674e03SMichael Tuexen 		print_gen_cmsg(fp, cmsghdr);
1484a2674e03SMichael Tuexen 	}
1485a2674e03SMichael Tuexen }
1486a2674e03SMichael Tuexen 
1487a2674e03SMichael Tuexen static void
148876785d6eSJohn Baldwin print_cmsgs(FILE *fp, pid_t pid, bool receive, struct msghdr *msghdr)
1489a2674e03SMichael Tuexen {
1490a2674e03SMichael Tuexen 	struct cmsghdr *cmsghdr;
1491a2674e03SMichael Tuexen 	char *cmsgbuf;
1492a2674e03SMichael Tuexen 	const char *temp;
1493a2674e03SMichael Tuexen 	socklen_t len;
1494a2674e03SMichael Tuexen 	int level, type;
1495a2674e03SMichael Tuexen 	bool first;
1496a2674e03SMichael Tuexen 
1497a2674e03SMichael Tuexen 	len = msghdr->msg_controllen;
14986accaf4aSMichael Tuexen 	if (len == 0) {
14996accaf4aSMichael Tuexen 		fputs("{}", fp);
15006accaf4aSMichael Tuexen 		return;
15016accaf4aSMichael Tuexen 	}
1502a2674e03SMichael Tuexen 	cmsgbuf = calloc(1, len);
1503a2674e03SMichael Tuexen 	if (get_struct(pid, msghdr->msg_control, cmsgbuf, len) == -1) {
15043193be24SMichael Tuexen 		fprintf(fp, "%p", msghdr->msg_control);
1505a2674e03SMichael Tuexen 		free(cmsgbuf);
15066accaf4aSMichael Tuexen 		return;
1507a2674e03SMichael Tuexen 	}
1508a2674e03SMichael Tuexen 	msghdr->msg_control = cmsgbuf;
1509a2674e03SMichael Tuexen 	first = true;
1510a2674e03SMichael Tuexen 	fputs("{", fp);
1511a2674e03SMichael Tuexen 	for (cmsghdr = CMSG_FIRSTHDR(msghdr);
1512a2674e03SMichael Tuexen 	   cmsghdr != NULL;
1513a2674e03SMichael Tuexen 	   cmsghdr = CMSG_NXTHDR(msghdr, cmsghdr)) {
1514a2674e03SMichael Tuexen 		level = cmsghdr->cmsg_level;
1515a2674e03SMichael Tuexen 		type = cmsghdr->cmsg_type;
1516a2674e03SMichael Tuexen 		len = cmsghdr->cmsg_len;
1517a2674e03SMichael Tuexen 		fprintf(fp, "%s{level=", first ? "" : ",");
1518a2674e03SMichael Tuexen 		print_integer_arg(sysdecode_sockopt_level, fp, level);
1519a2674e03SMichael Tuexen 		fputs(",type=", fp);
1520a2674e03SMichael Tuexen 		temp = sysdecode_cmsg_type(level, type);
1521a2674e03SMichael Tuexen 		if (temp) {
1522a2674e03SMichael Tuexen 			fputs(temp, fp);
1523a2674e03SMichael Tuexen 		} else {
1524a2674e03SMichael Tuexen 			fprintf(fp, "%d", type);
1525a2674e03SMichael Tuexen 		}
1526a2674e03SMichael Tuexen 		fputs(",data=", fp);
1527a2674e03SMichael Tuexen 		switch (level) {
1528a2674e03SMichael Tuexen 		case IPPROTO_SCTP:
152976785d6eSJohn Baldwin 			print_sctp_cmsg(fp, receive, cmsghdr);
1530a2674e03SMichael Tuexen 			break;
1531a2674e03SMichael Tuexen 		default:
1532a2674e03SMichael Tuexen 			print_gen_cmsg(fp, cmsghdr);
1533a2674e03SMichael Tuexen 			break;
1534a2674e03SMichael Tuexen 		}
1535a2674e03SMichael Tuexen 		fputs("}", fp);
1536b8ff144eSMichael Tuexen 		first = false;
1537a2674e03SMichael Tuexen 	}
1538a2674e03SMichael Tuexen 	fputs("}", fp);
1539a2674e03SMichael Tuexen 	free(cmsgbuf);
1540a2674e03SMichael Tuexen }
1541a2674e03SMichael Tuexen 
1542bbeaf6c0SSean Eric Fagan /*
1543bbeaf6c0SSean Eric Fagan  * Converts a syscall argument into a string.  Said string is
15444e3da534SJohn Baldwin  * allocated via malloc(), so needs to be free()'d.  sc is
1545bbeaf6c0SSean Eric Fagan  * a pointer to the syscall description (see above); args is
1546bbeaf6c0SSean Eric Fagan  * an array of all of the system call arguments.
1547bbeaf6c0SSean Eric Fagan  */
1548bbeaf6c0SSean Eric Fagan char *
15492b75c8adSJohn Baldwin print_arg(struct syscall_args *sc, unsigned long *args, long *retval,
155094355cfdSAndrey Zonov     struct trussinfo *trussinfo)
1551d8984f48SDag-Erling Smørgrav {
1552f083f689SJohn Baldwin 	FILE *fp;
155394355cfdSAndrey Zonov 	char *tmp;
1554f083f689SJohn Baldwin 	size_t tmplen;
155594355cfdSAndrey Zonov 	pid_t pid;
1556d8984f48SDag-Erling Smørgrav 
1557f083f689SJohn Baldwin 	fp = open_memstream(&tmp, &tmplen);
15582b75c8adSJohn Baldwin 	pid = trussinfo->curthread->proc->pid;
1559bbeaf6c0SSean Eric Fagan 	switch (sc->type & ARG_MASK) {
1560bbeaf6c0SSean Eric Fagan 	case Hex:
1561f083f689SJohn Baldwin 		fprintf(fp, "0x%x", (int)args[sc->offset]);
1562bbeaf6c0SSean Eric Fagan 		break;
1563bbeaf6c0SSean Eric Fagan 	case Octal:
1564f083f689SJohn Baldwin 		fprintf(fp, "0%o", (int)args[sc->offset]);
1565bbeaf6c0SSean Eric Fagan 		break;
1566bbeaf6c0SSean Eric Fagan 	case Int:
1567f083f689SJohn Baldwin 		fprintf(fp, "%d", (int)args[sc->offset]);
1568bbeaf6c0SSean Eric Fagan 		break;
1569808d9805SEd Schouten 	case UInt:
1570808d9805SEd Schouten 		fprintf(fp, "%u", (unsigned int)args[sc->offset]);
1571808d9805SEd Schouten 		break;
1572ebb2cc40SJohn Baldwin 	case PUInt: {
1573ebb2cc40SJohn Baldwin 		unsigned int val;
1574ebb2cc40SJohn Baldwin 
1575ebb2cc40SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &val,
1576ebb2cc40SJohn Baldwin 		    sizeof(val)) == 0)
1577ebb2cc40SJohn Baldwin 			fprintf(fp, "{ %u }", val);
1578ebb2cc40SJohn Baldwin 		else
1579ebb2cc40SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1580ebb2cc40SJohn Baldwin 		break;
1581ebb2cc40SJohn Baldwin 	}
1582fdb5bf37SJohn Baldwin 	case LongHex:
1583f083f689SJohn Baldwin 		fprintf(fp, "0x%lx", args[sc->offset]);
1584fdb5bf37SJohn Baldwin 		break;
1585b289a8d7SJohn Baldwin 	case Long:
1586f083f689SJohn Baldwin 		fprintf(fp, "%ld", args[sc->offset]);
1587b289a8d7SJohn Baldwin 		break;
1588e261fb2aSJohn Baldwin 	case Sizet:
1589e261fb2aSJohn Baldwin 		fprintf(fp, "%zu", (size_t)args[sc->offset]);
1590e261fb2aSJohn Baldwin 		break;
1591d8984f48SDag-Erling Smørgrav 	case Name: {
1592081e5c48SPav Lucistnik 		/* NULL-terminated string. */
1593bbeaf6c0SSean Eric Fagan 		char *tmp2;
15944e3da534SJohn Baldwin 
15955d2d083cSXin LI 		tmp2 = get_string(pid, (void*)args[sc->offset], 0);
1596f083f689SJohn Baldwin 		fprintf(fp, "\"%s\"", tmp2);
1597bbeaf6c0SSean Eric Fagan 		free(tmp2);
1598bbeaf6c0SSean Eric Fagan 		break;
1599d8984f48SDag-Erling Smørgrav 	}
1600d8984f48SDag-Erling Smørgrav 	case BinString: {
16014e3da534SJohn Baldwin 		/*
16024e3da534SJohn Baldwin 		 * Binary block of data that might have printable characters.
16034e3da534SJohn Baldwin 		 * XXX If type|OUT, assume that the length is the syscall's
16044e3da534SJohn Baldwin 		 * return value.  Otherwise, assume that the length of the block
16054e3da534SJohn Baldwin 		 * is in the next syscall argument.
16064e3da534SJohn Baldwin 		 */
1607081e5c48SPav Lucistnik 		int max_string = trussinfo->strsize;
1608081e5c48SPav Lucistnik 		char tmp2[max_string + 1], *tmp3;
1609081e5c48SPav Lucistnik 		int len;
1610081e5c48SPav Lucistnik 		int truncated = 0;
1611081e5c48SPav Lucistnik 
1612081e5c48SPav Lucistnik 		if (sc->type & OUT)
16132b75c8adSJohn Baldwin 			len = retval[0];
1614081e5c48SPav Lucistnik 		else
1615081e5c48SPav Lucistnik 			len = args[sc->offset + 1];
1616081e5c48SPav Lucistnik 
16174e3da534SJohn Baldwin 		/*
16184e3da534SJohn Baldwin 		 * Don't print more than max_string characters, to avoid word
16194e3da534SJohn Baldwin 		 * wrap.  If we have to truncate put some ... after the string.
1620081e5c48SPav Lucistnik 		 */
1621081e5c48SPav Lucistnik 		if (len > max_string) {
1622081e5c48SPav Lucistnik 			len = max_string;
1623081e5c48SPav Lucistnik 			truncated = 1;
1624081e5c48SPav Lucistnik 		}
162594355cfdSAndrey Zonov 		if (len && get_struct(pid, (void*)args[sc->offset], &tmp2, len)
162694355cfdSAndrey Zonov 		    != -1) {
1627081e5c48SPav Lucistnik 			tmp3 = malloc(len * 4 + 1);
1628081e5c48SPav Lucistnik 			while (len) {
162994355cfdSAndrey Zonov 				if (strvisx(tmp3, tmp2, len,
163094355cfdSAndrey Zonov 				    VIS_CSTYLE|VIS_TAB|VIS_NL) <= max_string)
1631081e5c48SPav Lucistnik 					break;
1632081e5c48SPav Lucistnik 				len--;
1633081e5c48SPav Lucistnik 				truncated = 1;
163480c7cc1cSPedro F. Giffuni 			}
1635f083f689SJohn Baldwin 			fprintf(fp, "\"%s\"%s", tmp3, truncated ?
163694355cfdSAndrey Zonov 			    "..." : "");
1637081e5c48SPav Lucistnik 			free(tmp3);
1638d8984f48SDag-Erling Smørgrav 		} else {
1639f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1640081e5c48SPav Lucistnik 		}
1641081e5c48SPav Lucistnik 		break;
1642d8984f48SDag-Erling Smørgrav 	}
164368055893SJohn Baldwin 	case ExecArgs:
164468055893SJohn Baldwin 	case ExecEnv:
1645d8984f48SDag-Erling Smørgrav 	case StringArray: {
1646890843c1SJohn Baldwin 		uintptr_t addr;
1647890843c1SJohn Baldwin 		union {
1648890843c1SJohn Baldwin 			char *strarray[0];
1649890843c1SJohn Baldwin 			char buf[PAGE_SIZE];
1650890843c1SJohn Baldwin 		} u;
16519897b203SMatthew N. Dodd 		char *string;
1652890843c1SJohn Baldwin 		size_t len;
16532b75c8adSJohn Baldwin 		u_int first, i;
16549897b203SMatthew N. Dodd 
1655890843c1SJohn Baldwin 		/*
165668055893SJohn Baldwin 		 * Only parse argv[] and environment arrays from exec calls
165768055893SJohn Baldwin 		 * if requested.
165868055893SJohn Baldwin 		 */
165968055893SJohn Baldwin 		if (((sc->type & ARG_MASK) == ExecArgs &&
166068055893SJohn Baldwin 		    (trussinfo->flags & EXECVEARGS) == 0) ||
166168055893SJohn Baldwin 		    ((sc->type & ARG_MASK) == ExecEnv &&
166268055893SJohn Baldwin 		    (trussinfo->flags & EXECVEENVS) == 0)) {
166368055893SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
166468055893SJohn Baldwin 			break;
166568055893SJohn Baldwin 		}
166668055893SJohn Baldwin 
166768055893SJohn Baldwin 		/*
1668890843c1SJohn Baldwin 		 * Read a page of pointers at a time.  Punt if the top-level
1669890843c1SJohn Baldwin 		 * pointer is not aligned.  Note that the first read is of
1670890843c1SJohn Baldwin 		 * a partial page.
1671890843c1SJohn Baldwin 		 */
1672890843c1SJohn Baldwin 		addr = args[sc->offset];
1673890843c1SJohn Baldwin 		if (addr % sizeof(char *) != 0) {
1674890843c1SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1675890843c1SJohn Baldwin 			break;
16769897b203SMatthew N. Dodd 		}
16779897b203SMatthew N. Dodd 
1678890843c1SJohn Baldwin 		len = PAGE_SIZE - (addr & PAGE_MASK);
1679890843c1SJohn Baldwin 		if (get_struct(pid, (void *)addr, u.buf, len) == -1) {
1680890843c1SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1681890843c1SJohn Baldwin 			break;
16829897b203SMatthew N. Dodd 		}
1683890843c1SJohn Baldwin 
1684890843c1SJohn Baldwin 		fputc('[', fp);
1685890843c1SJohn Baldwin 		first = 1;
1686890843c1SJohn Baldwin 		i = 0;
1687890843c1SJohn Baldwin 		while (u.strarray[i] != NULL) {
1688890843c1SJohn Baldwin 			string = get_string(pid, u.strarray[i], 0);
1689890843c1SJohn Baldwin 			fprintf(fp, "%s \"%s\"", first ? "" : ",", string);
1690890843c1SJohn Baldwin 			free(string);
1691890843c1SJohn Baldwin 			first = 0;
1692890843c1SJohn Baldwin 
1693890843c1SJohn Baldwin 			i++;
1694890843c1SJohn Baldwin 			if (i == len / sizeof(char *)) {
1695890843c1SJohn Baldwin 				addr += len;
1696890843c1SJohn Baldwin 				len = PAGE_SIZE;
1697890843c1SJohn Baldwin 				if (get_struct(pid, (void *)addr, u.buf, len) ==
1698890843c1SJohn Baldwin 				    -1) {
1699890843c1SJohn Baldwin 					fprintf(fp, ", <inval>");
1700890843c1SJohn Baldwin 					break;
1701890843c1SJohn Baldwin 				}
1702890843c1SJohn Baldwin 				i = 0;
1703890843c1SJohn Baldwin 			}
1704890843c1SJohn Baldwin 		}
1705890843c1SJohn Baldwin 		fputs(" ]", fp);
17069897b203SMatthew N. Dodd 		break;
1707d8984f48SDag-Erling Smørgrav 	}
170810aeefc9SMarcel Moolenaar #ifdef __LP64__
170910aeefc9SMarcel Moolenaar 	case Quad:
171072df19e7SJohn Baldwin 		fprintf(fp, "%ld", args[sc->offset]);
171172df19e7SJohn Baldwin 		break;
171272df19e7SJohn Baldwin 	case QuadHex:
1713f083f689SJohn Baldwin 		fprintf(fp, "0x%lx", args[sc->offset]);
171410aeefc9SMarcel Moolenaar 		break;
171510aeefc9SMarcel Moolenaar #else
171672df19e7SJohn Baldwin 	case Quad:
171772df19e7SJohn Baldwin 	case QuadHex: {
171810aeefc9SMarcel Moolenaar 		unsigned long long ll;
17194e3da534SJohn Baldwin 
17202b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN
17212b75c8adSJohn Baldwin 		ll = (unsigned long long)args[sc->offset + 1] << 32 |
17222b75c8adSJohn Baldwin 		    args[sc->offset];
17232b75c8adSJohn Baldwin #else
17242b75c8adSJohn Baldwin 		ll = (unsigned long long)args[sc->offset] << 32 |
17252b75c8adSJohn Baldwin 		    args[sc->offset + 1];
17262b75c8adSJohn Baldwin #endif
172772df19e7SJohn Baldwin 		if ((sc->type & ARG_MASK) == Quad)
172872df19e7SJohn Baldwin 			fprintf(fp, "%lld", ll);
172972df19e7SJohn Baldwin 		else
1730f083f689SJohn Baldwin 			fprintf(fp, "0x%llx", ll);
1731bbeaf6c0SSean Eric Fagan 		break;
1732bbeaf6c0SSean Eric Fagan 	}
173310aeefc9SMarcel Moolenaar #endif
1734b60a095bSJohn Baldwin 	case PQuadHex: {
1735b60a095bSJohn Baldwin 		uint64_t val;
1736b60a095bSJohn Baldwin 
1737b60a095bSJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &val,
1738b60a095bSJohn Baldwin 		    sizeof(val)) == 0)
1739b60a095bSJohn Baldwin 			fprintf(fp, "{ 0x%jx }", (uintmax_t)val);
1740b60a095bSJohn Baldwin 		else
1741b60a095bSJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1742b60a095bSJohn Baldwin 		break;
1743b60a095bSJohn Baldwin 	}
1744bbeaf6c0SSean Eric Fagan 	case Ptr:
1745f083f689SJohn Baldwin 		fprintf(fp, "0x%lx", args[sc->offset]);
1746bbeaf6c0SSean Eric Fagan 		break;
1747d8984f48SDag-Erling Smørgrav 	case Readlinkres: {
17482bae4eb3SAlfred Perlstein 		char *tmp2;
17494e3da534SJohn Baldwin 
17502b75c8adSJohn Baldwin 		if (retval[0] == -1)
17512bae4eb3SAlfred Perlstein 			break;
17522b75c8adSJohn Baldwin 		tmp2 = get_string(pid, (void*)args[sc->offset], retval[0]);
1753f083f689SJohn Baldwin 		fprintf(fp, "\"%s\"", tmp2);
17542bae4eb3SAlfred Perlstein 		free(tmp2);
17552bae4eb3SAlfred Perlstein 		break;
1756d8984f48SDag-Erling Smørgrav 	}
1757d8984f48SDag-Erling Smørgrav 	case Ioctl: {
17584e3da534SJohn Baldwin 		const char *temp;
17594e3da534SJohn Baldwin 		unsigned long cmd;
17604e3da534SJohn Baldwin 
17614e3da534SJohn Baldwin 		cmd = args[sc->offset];
1762265e5898SJohn Baldwin 		temp = sysdecode_ioctlname(cmd);
176394355cfdSAndrey Zonov 		if (temp)
1764f083f689SJohn Baldwin 			fputs(temp, fp);
176594355cfdSAndrey Zonov 		else {
1766f083f689SJohn Baldwin 			fprintf(fp, "0x%lx { IO%s%s 0x%lx('%c'), %lu, %lu }",
17674e3da534SJohn Baldwin 			    cmd, cmd & IOC_OUT ? "R" : "",
17684e3da534SJohn Baldwin 			    cmd & IOC_IN ? "W" : "", IOCGROUP(cmd),
17694e3da534SJohn Baldwin 			    isprint(IOCGROUP(cmd)) ? (char)IOCGROUP(cmd) : '?',
17704e3da534SJohn Baldwin 			    cmd & 0xFF, IOCPARM_LEN(cmd));
1771081e5c48SPav Lucistnik 		}
1772081e5c48SPav Lucistnik 		break;
1773d8984f48SDag-Erling Smørgrav 	}
1774d8984f48SDag-Erling Smørgrav 	case Timespec: {
1775e45a5a0dSDavid Malone 		struct timespec ts;
17764e3da534SJohn Baldwin 
177794355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &ts,
177894355cfdSAndrey Zonov 		    sizeof(ts)) != -1)
1779a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec,
178094355cfdSAndrey Zonov 			    ts.tv_nsec);
1781e45a5a0dSDavid Malone 		else
1782f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1783e45a5a0dSDavid Malone 		break;
1784d8984f48SDag-Erling Smørgrav 	}
17857d897327SJohn Baldwin 	case Timespec2: {
17867d897327SJohn Baldwin 		struct timespec ts[2];
17877d897327SJohn Baldwin 		const char *sep;
17887d897327SJohn Baldwin 		unsigned int i;
17897d897327SJohn Baldwin 
17907d897327SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &ts, sizeof(ts))
17917d897327SJohn Baldwin 		    != -1) {
17921e2ec671SJohn Baldwin 			fputs("{ ", fp);
17937d897327SJohn Baldwin 			sep = "";
17947d897327SJohn Baldwin 			for (i = 0; i < nitems(ts); i++) {
17957d897327SJohn Baldwin 				fputs(sep, fp);
17967d897327SJohn Baldwin 				sep = ", ";
17977d897327SJohn Baldwin 				switch (ts[i].tv_nsec) {
17987d897327SJohn Baldwin 				case UTIME_NOW:
17997d897327SJohn Baldwin 					fprintf(fp, "UTIME_NOW");
18007d897327SJohn Baldwin 					break;
18017d897327SJohn Baldwin 				case UTIME_OMIT:
18027d897327SJohn Baldwin 					fprintf(fp, "UTIME_OMIT");
18037d897327SJohn Baldwin 					break;
18047d897327SJohn Baldwin 				default:
1805a1436773SJohn Baldwin 					fprintf(fp, "%jd.%09ld",
1806a1436773SJohn Baldwin 					    (intmax_t)ts[i].tv_sec,
1807a1436773SJohn Baldwin 					    ts[i].tv_nsec);
18087d897327SJohn Baldwin 					break;
18097d897327SJohn Baldwin 				}
18107d897327SJohn Baldwin 			}
18111e2ec671SJohn Baldwin 			fputs(" }", fp);
18127d897327SJohn Baldwin 		} else
1813f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
18147d897327SJohn Baldwin 		break;
18157d897327SJohn Baldwin 	}
1816d8984f48SDag-Erling Smørgrav 	case Timeval: {
1817e45a5a0dSDavid Malone 		struct timeval tv;
18184e3da534SJohn Baldwin 
181994355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
182094355cfdSAndrey Zonov 		    != -1)
1821a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec,
182294355cfdSAndrey Zonov 			    tv.tv_usec);
1823081e5c48SPav Lucistnik 		else
1824f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1825081e5c48SPav Lucistnik 		break;
1826d8984f48SDag-Erling Smørgrav 	}
1827d8984f48SDag-Erling Smørgrav 	case Timeval2: {
1828081e5c48SPav Lucistnik 		struct timeval tv[2];
18294e3da534SJohn Baldwin 
183094355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
183194355cfdSAndrey Zonov 		    != -1)
1832a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
1833a1436773SJohn Baldwin 			    (intmax_t)tv[0].tv_sec, tv[0].tv_usec,
1834a1436773SJohn Baldwin 			    (intmax_t)tv[1].tv_sec, tv[1].tv_usec);
1835e45a5a0dSDavid Malone 		else
1836f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1837e45a5a0dSDavid Malone 		break;
1838d8984f48SDag-Erling Smørgrav 	}
1839d8984f48SDag-Erling Smørgrav 	case Itimerval: {
1840e45a5a0dSDavid Malone 		struct itimerval itv;
18414e3da534SJohn Baldwin 
184294355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &itv,
184394355cfdSAndrey Zonov 		    sizeof(itv)) != -1)
1844a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
1845a1436773SJohn Baldwin 			    (intmax_t)itv.it_interval.tv_sec,
1846081e5c48SPav Lucistnik 			    itv.it_interval.tv_usec,
1847a1436773SJohn Baldwin 			    (intmax_t)itv.it_value.tv_sec,
1848081e5c48SPav Lucistnik 			    itv.it_value.tv_usec);
1849e45a5a0dSDavid Malone 		else
1850f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1851e45a5a0dSDavid Malone 		break;
1852d8984f48SDag-Erling Smørgrav 	}
18531c99a22aSSteven Hartland 	case LinuxSockArgs:
18541c99a22aSSteven Hartland 	{
18551c99a22aSSteven Hartland 		struct linux_socketcall_args largs;
18564e3da534SJohn Baldwin 
18571c99a22aSSteven Hartland 		if (get_struct(pid, (void *)args[sc->offset], (void *)&largs,
1858fb7eabb0SJohn Baldwin 		    sizeof(largs)) != -1)
1859f083f689SJohn Baldwin 			fprintf(fp, "{ %s, 0x%lx }",
1860fb7eabb0SJohn Baldwin 			    lookup(linux_socketcall_ops, largs.what, 10),
18610a46af44SJohn Baldwin 			    (long unsigned int)largs.args);
1862fb7eabb0SJohn Baldwin 		else
1863f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
18641c99a22aSSteven Hartland 		break;
18651c99a22aSSteven Hartland 	}
1866d8984f48SDag-Erling Smørgrav 	case Pollfd: {
1867e45a5a0dSDavid Malone 		/*
186894355cfdSAndrey Zonov 		 * XXX: A Pollfd argument expects the /next/ syscall argument
186994355cfdSAndrey Zonov 		 * to be the number of fds in the array. This matches the poll
187094355cfdSAndrey Zonov 		 * syscall.
1871e45a5a0dSDavid Malone 		 */
1872e45a5a0dSDavid Malone 		struct pollfd *pfd;
1873e45a5a0dSDavid Malone 		int numfds = args[sc->offset + 1];
1874f083f689SJohn Baldwin 		size_t bytes = sizeof(struct pollfd) * numfds;
1875f083f689SJohn Baldwin 		int i;
1876e45a5a0dSDavid Malone 
1877e45a5a0dSDavid Malone 		if ((pfd = malloc(bytes)) == NULL)
1878f083f689SJohn Baldwin 			err(1, "Cannot malloc %zu bytes for pollfd array",
187994355cfdSAndrey Zonov 			    bytes);
188094355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], pfd, bytes)
188194355cfdSAndrey Zonov 		    != -1) {
1882f083f689SJohn Baldwin 			fputs("{", fp);
1883e45a5a0dSDavid Malone 			for (i = 0; i < numfds; i++) {
1884f083f689SJohn Baldwin 				fprintf(fp, " %d/%s", pfd[i].fd,
1885081e5c48SPav Lucistnik 				    xlookup_bits(poll_flags, pfd[i].events));
1886e45a5a0dSDavid Malone 			}
1887f083f689SJohn Baldwin 			fputs(" }", fp);
1888d8984f48SDag-Erling Smørgrav 		} else {
1889f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1890e45a5a0dSDavid Malone 		}
1891d8984f48SDag-Erling Smørgrav 		free(pfd);
1892e45a5a0dSDavid Malone 		break;
1893d8984f48SDag-Erling Smørgrav 	}
1894d8984f48SDag-Erling Smørgrav 	case Fd_set: {
1895e45a5a0dSDavid Malone 		/*
189694355cfdSAndrey Zonov 		 * XXX: A Fd_set argument expects the /first/ syscall argument
189794355cfdSAndrey Zonov 		 * to be the number of fds in the array.  This matches the
189894355cfdSAndrey Zonov 		 * select syscall.
1899e45a5a0dSDavid Malone 		 */
1900e45a5a0dSDavid Malone 		fd_set *fds;
1901e45a5a0dSDavid Malone 		int numfds = args[0];
1902f083f689SJohn Baldwin 		size_t bytes = _howmany(numfds, _NFDBITS) * _NFDBITS;
1903f083f689SJohn Baldwin 		int i;
1904e45a5a0dSDavid Malone 
1905e45a5a0dSDavid Malone 		if ((fds = malloc(bytes)) == NULL)
1906f083f689SJohn Baldwin 			err(1, "Cannot malloc %zu bytes for fd_set array",
190794355cfdSAndrey Zonov 			    bytes);
190894355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], fds, bytes)
190994355cfdSAndrey Zonov 		    != -1) {
1910f083f689SJohn Baldwin 			fputs("{", fp);
1911e45a5a0dSDavid Malone 			for (i = 0; i < numfds; i++) {
1912f083f689SJohn Baldwin 				if (FD_ISSET(i, fds))
1913f083f689SJohn Baldwin 					fprintf(fp, " %d", i);
1914e45a5a0dSDavid Malone 			}
1915f083f689SJohn Baldwin 			fputs(" }", fp);
191694355cfdSAndrey Zonov 		} else
1917f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1918d8984f48SDag-Erling Smørgrav 		free(fds);
1919e45a5a0dSDavid Malone 		break;
1920d8984f48SDag-Erling Smørgrav 	}
192134763d1cSJohn Baldwin 	case Signal:
1922f083f689SJohn Baldwin 		fputs(strsig2(args[sc->offset]), fp);
1923f0ebbc29SDag-Erling Smørgrav 		break;
1924d8984f48SDag-Erling Smørgrav 	case Sigset: {
1925081e5c48SPav Lucistnik 		long sig;
1926081e5c48SPav Lucistnik 		sigset_t ss;
1927f083f689SJohn Baldwin 		int i, first;
1928081e5c48SPav Lucistnik 
1929081e5c48SPav Lucistnik 		sig = args[sc->offset];
193094355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], (void *)&ss,
193194355cfdSAndrey Zonov 		    sizeof(ss)) == -1) {
1932f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1933081e5c48SPav Lucistnik 			break;
1934081e5c48SPav Lucistnik 		}
1935f083f689SJohn Baldwin 		fputs("{ ", fp);
1936f083f689SJohn Baldwin 		first = 1;
1937d8984f48SDag-Erling Smørgrav 		for (i = 1; i < sys_nsig; i++) {
193834763d1cSJohn Baldwin 			if (sigismember(&ss, i)) {
1939f083f689SJohn Baldwin 				fprintf(fp, "%s%s", !first ? "|" : "",
19409289f547SJohn Baldwin 				    strsig2(i));
1941f083f689SJohn Baldwin 				first = 0;
194234763d1cSJohn Baldwin 			}
1943081e5c48SPav Lucistnik 		}
1944f083f689SJohn Baldwin 		if (!first)
1945f083f689SJohn Baldwin 			fputc(' ', fp);
1946f083f689SJohn Baldwin 		fputc('}', fp);
1947081e5c48SPav Lucistnik 		break;
1948d8984f48SDag-Erling Smørgrav 	}
19499289f547SJohn Baldwin 	case Sigprocmask:
19509289f547SJohn Baldwin 		print_integer_arg(sysdecode_sigprocmask_how, fp,
19519289f547SJohn Baldwin 		    args[sc->offset]);
1952894b8f7aSAlfred Perlstein 		break;
19539289f547SJohn Baldwin 	case Fcntlflag:
19544e3da534SJohn Baldwin 		/* XXX: Output depends on the value of the previous argument. */
19559289f547SJohn Baldwin 		if (sysdecode_fcntl_arg_p(args[sc->offset - 1]))
19569289f547SJohn Baldwin 			sysdecode_fcntl_arg(fp, args[sc->offset - 1],
19579289f547SJohn Baldwin 			    args[sc->offset], 16);
1958081e5c48SPav Lucistnik 		break;
1959081e5c48SPav Lucistnik 	case Open:
19609289f547SJohn Baldwin 		print_mask_arg(sysdecode_open_flags, fp, args[sc->offset]);
1961081e5c48SPav Lucistnik 		break;
1962081e5c48SPav Lucistnik 	case Fcntl:
19639289f547SJohn Baldwin 		print_integer_arg(sysdecode_fcntl_cmd, fp, args[sc->offset]);
1964081e5c48SPav Lucistnik 		break;
1965894b8f7aSAlfred Perlstein 	case Mprot:
19669289f547SJohn Baldwin 		print_mask_arg(sysdecode_mmap_prot, fp, args[sc->offset]);
1967894b8f7aSAlfred Perlstein 		break;
19689289f547SJohn Baldwin 	case Mmapflags:
19699289f547SJohn Baldwin 		print_mask_arg(sysdecode_mmap_flags, fp, args[sc->offset]);
1970894b8f7aSAlfred Perlstein 		break;
1971fde3a7d1SAlfred Perlstein 	case Whence:
19729289f547SJohn Baldwin 		print_integer_arg(sysdecode_whence, fp, args[sc->offset]);
1973081e5c48SPav Lucistnik 		break;
1974081e5c48SPav Lucistnik 	case Sockdomain:
19759289f547SJohn Baldwin 		print_integer_arg(sysdecode_socketdomain, fp, args[sc->offset]);
1976081e5c48SPav Lucistnik 		break;
19779289f547SJohn Baldwin 	case Socktype:
19789289f547SJohn Baldwin 		print_mask_arg(sysdecode_socket_type, fp, args[sc->offset]);
1979081e5c48SPav Lucistnik 		break;
1980081e5c48SPav Lucistnik 	case Shutdown:
19819289f547SJohn Baldwin 		print_integer_arg(sysdecode_shutdown_how, fp, args[sc->offset]);
1982081e5c48SPav Lucistnik 		break;
1983081e5c48SPav Lucistnik 	case Resource:
19849289f547SJohn Baldwin 		print_integer_arg(sysdecode_rlimit, fp, args[sc->offset]);
1985081e5c48SPav Lucistnik 		break;
1986ee8aa41dSJohn Baldwin 	case RusageWho:
1987ee8aa41dSJohn Baldwin 		print_integer_arg(sysdecode_getrusage_who, fp, args[sc->offset]);
1988ee8aa41dSJohn Baldwin 		break;
1989081e5c48SPav Lucistnik 	case Pathconf:
199039a3a438SJohn Baldwin 		print_integer_arg(sysdecode_pathconf_name, fp, args[sc->offset]);
1991fde3a7d1SAlfred Perlstein 		break;
19929e1db66eSMark Johnston 	case Rforkflags:
19939289f547SJohn Baldwin 		print_mask_arg(sysdecode_rfork_flags, fp, args[sc->offset]);
19949e1db66eSMark Johnston 		break;
1995d8984f48SDag-Erling Smørgrav 	case Sockaddr: {
199666917ca9SJohn Baldwin 		socklen_t len;
19979ddd1412SDag-Erling Smørgrav 
1998a7a08c7eSMarcel Moolenaar 		if (args[sc->offset] == 0) {
1999f083f689SJohn Baldwin 			fputs("NULL", fp);
2000a7a08c7eSMarcel Moolenaar 			break;
2001a7a08c7eSMarcel Moolenaar 		}
2002a7a08c7eSMarcel Moolenaar 
20036a656761SAlfred Perlstein 		/*
200466917ca9SJohn Baldwin 		 * Extract the address length from the next argument.  If
200566917ca9SJohn Baldwin 		 * this is an output sockaddr (OUT is set), then the
200666917ca9SJohn Baldwin 		 * next argument is a pointer to a socklen_t.  Otherwise
200766917ca9SJohn Baldwin 		 * the next argument contains a socklen_t by value.
20086a656761SAlfred Perlstein 		 */
200966917ca9SJohn Baldwin 		if (sc->type & OUT) {
201066917ca9SJohn Baldwin 			if (get_struct(pid, (void *)args[sc->offset + 1],
201166917ca9SJohn Baldwin 			    &len, sizeof(len)) == -1) {
201266917ca9SJohn Baldwin 				fprintf(fp, "0x%lx", args[sc->offset]);
20136a656761SAlfred Perlstein 				break;
20146a656761SAlfred Perlstein 			}
201566917ca9SJohn Baldwin 		} else
201666917ca9SJohn Baldwin 			len = args[sc->offset + 1];
201766917ca9SJohn Baldwin 
2018a2674e03SMichael Tuexen 		print_sockaddr(fp, trussinfo, (void *)args[sc->offset], len);
20199ddd1412SDag-Erling Smørgrav 		break;
2020d8984f48SDag-Erling Smørgrav 	}
2021d8984f48SDag-Erling Smørgrav 	case Sigaction: {
2022e45a5a0dSDavid Malone 		struct sigaction sa;
2023e45a5a0dSDavid Malone 
202494355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &sa, sizeof(sa))
202594355cfdSAndrey Zonov 		    != -1) {
2026f083f689SJohn Baldwin 			fputs("{ ", fp);
2027e45a5a0dSDavid Malone 			if (sa.sa_handler == SIG_DFL)
2028f083f689SJohn Baldwin 				fputs("SIG_DFL", fp);
2029e45a5a0dSDavid Malone 			else if (sa.sa_handler == SIG_IGN)
2030f083f689SJohn Baldwin 				fputs("SIG_IGN", fp);
2031e45a5a0dSDavid Malone 			else
2032f083f689SJohn Baldwin 				fprintf(fp, "%p", sa.sa_handler);
2033f083f689SJohn Baldwin 			fprintf(fp, " %s ss_t }",
2034081e5c48SPav Lucistnik 			    xlookup_bits(sigaction_flags, sa.sa_flags));
203594355cfdSAndrey Zonov 		} else
2036f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2037e45a5a0dSDavid Malone 		break;
2038d8984f48SDag-Erling Smørgrav 	}
2039d8984f48SDag-Erling Smørgrav 	case Kevent: {
2040081e5c48SPav Lucistnik 		/*
20414e3da534SJohn Baldwin 		 * XXX XXX: The size of the array is determined by either the
2042081e5c48SPav Lucistnik 		 * next syscall argument, or by the syscall return value,
2043081e5c48SPav Lucistnik 		 * depending on which argument number we are.  This matches the
2044081e5c48SPav Lucistnik 		 * kevent syscall, but luckily that's the only syscall that uses
2045081e5c48SPav Lucistnik 		 * them.
2046081e5c48SPav Lucistnik 		 */
2047081e5c48SPav Lucistnik 		struct kevent *ke;
2048081e5c48SPav Lucistnik 		int numevents = -1;
2049f083f689SJohn Baldwin 		size_t bytes;
2050f083f689SJohn Baldwin 		int i;
2051081e5c48SPav Lucistnik 
2052081e5c48SPav Lucistnik 		if (sc->offset == 1)
2053081e5c48SPav Lucistnik 			numevents = args[sc->offset+1];
20542b75c8adSJohn Baldwin 		else if (sc->offset == 3 && retval[0] != -1)
20552b75c8adSJohn Baldwin 			numevents = retval[0];
2056081e5c48SPav Lucistnik 
2057f083f689SJohn Baldwin 		if (numevents >= 0) {
2058081e5c48SPav Lucistnik 			bytes = sizeof(struct kevent) * numevents;
2059081e5c48SPav Lucistnik 			if ((ke = malloc(bytes)) == NULL)
2060f083f689SJohn Baldwin 				err(1,
2061f083f689SJohn Baldwin 				    "Cannot malloc %zu bytes for kevent array",
206294355cfdSAndrey Zonov 				    bytes);
2063f083f689SJohn Baldwin 		} else
2064f083f689SJohn Baldwin 			ke = NULL;
206594355cfdSAndrey Zonov 		if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset],
206694355cfdSAndrey Zonov 		    ke, bytes) != -1) {
2067f083f689SJohn Baldwin 			fputc('{', fp);
2068c915ff03SJohn Baldwin 			for (i = 0; i < numevents; i++) {
2069c915ff03SJohn Baldwin 				fputc(' ', fp);
2070ffb66079SJohn Baldwin 				print_kevent(fp, &ke[i]);
2071c915ff03SJohn Baldwin 			}
2072f083f689SJohn Baldwin 			fputs(" }", fp);
2073d8984f48SDag-Erling Smørgrav 		} else {
2074f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2075081e5c48SPav Lucistnik 		}
2076d8984f48SDag-Erling Smørgrav 		free(ke);
2077081e5c48SPav Lucistnik 		break;
2078d8984f48SDag-Erling Smørgrav 	}
2079ffb66079SJohn Baldwin 	case Kevent11: {
2080ffb66079SJohn Baldwin 		struct kevent_freebsd11 *ke11;
2081ffb66079SJohn Baldwin 		struct kevent ke;
2082ffb66079SJohn Baldwin 		int numevents = -1;
2083ffb66079SJohn Baldwin 		size_t bytes;
2084ffb66079SJohn Baldwin 		int i;
2085ffb66079SJohn Baldwin 
2086ffb66079SJohn Baldwin 		if (sc->offset == 1)
2087ffb66079SJohn Baldwin 			numevents = args[sc->offset+1];
2088ffb66079SJohn Baldwin 		else if (sc->offset == 3 && retval[0] != -1)
2089ffb66079SJohn Baldwin 			numevents = retval[0];
2090ffb66079SJohn Baldwin 
2091ffb66079SJohn Baldwin 		if (numevents >= 0) {
2092ffb66079SJohn Baldwin 			bytes = sizeof(struct kevent_freebsd11) * numevents;
2093ffb66079SJohn Baldwin 			if ((ke11 = malloc(bytes)) == NULL)
2094ffb66079SJohn Baldwin 				err(1,
2095ffb66079SJohn Baldwin 				    "Cannot malloc %zu bytes for kevent array",
2096ffb66079SJohn Baldwin 				    bytes);
2097ffb66079SJohn Baldwin 		} else
2098ffb66079SJohn Baldwin 			ke11 = NULL;
2099ffb66079SJohn Baldwin 		memset(&ke, 0, sizeof(ke));
2100ffb66079SJohn Baldwin 		if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset],
2101ffb66079SJohn Baldwin 		    ke11, bytes) != -1) {
2102ffb66079SJohn Baldwin 			fputc('{', fp);
2103ffb66079SJohn Baldwin 			for (i = 0; i < numevents; i++) {
2104ffb66079SJohn Baldwin 				fputc(' ', fp);
2105ffb66079SJohn Baldwin 				ke.ident = ke11[i].ident;
2106ffb66079SJohn Baldwin 				ke.filter = ke11[i].filter;
2107ffb66079SJohn Baldwin 				ke.flags = ke11[i].flags;
2108ffb66079SJohn Baldwin 				ke.fflags = ke11[i].fflags;
2109ffb66079SJohn Baldwin 				ke.data = ke11[i].data;
2110ffb66079SJohn Baldwin 				ke.udata = ke11[i].udata;
2111ffb66079SJohn Baldwin 				print_kevent(fp, &ke);
2112ffb66079SJohn Baldwin 			}
2113ffb66079SJohn Baldwin 			fputs(" }", fp);
2114ffb66079SJohn Baldwin 		} else {
2115ffb66079SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2116ffb66079SJohn Baldwin 		}
2117ffb66079SJohn Baldwin 		free(ke11);
2118ffb66079SJohn Baldwin 		break;
2119ffb66079SJohn Baldwin 	}
2120d8984f48SDag-Erling Smørgrav 	case Stat: {
2121081e5c48SPav Lucistnik 		struct stat st;
21224e3da534SJohn Baldwin 
212394355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st))
212494355cfdSAndrey Zonov 		    != -1) {
2125081e5c48SPav Lucistnik 			char mode[12];
21264e3da534SJohn Baldwin 
2127081e5c48SPav Lucistnik 			strmode(st.st_mode, mode);
2128f083f689SJohn Baldwin 			fprintf(fp,
2129b38fbc2eSJohn Baldwin 			    "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode,
2130b38fbc2eSJohn Baldwin 			    (uintmax_t)st.st_ino, (intmax_t)st.st_size,
213194355cfdSAndrey Zonov 			    (long)st.st_blksize);
2132d8984f48SDag-Erling Smørgrav 		} else {
2133f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2134081e5c48SPav Lucistnik 		}
2135081e5c48SPav Lucistnik 		break;
2136d8984f48SDag-Erling Smørgrav 	}
21378207f12dSWarner Losh 	case Stat11: {
21388207f12dSWarner Losh 		struct freebsd11_stat st;
21398207f12dSWarner Losh 
21408207f12dSWarner Losh 		if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st))
21418207f12dSWarner Losh 		    != -1) {
21428207f12dSWarner Losh 			char mode[12];
21438207f12dSWarner Losh 
21448207f12dSWarner Losh 			strmode(st.st_mode, mode);
21458207f12dSWarner Losh 			fprintf(fp,
21468207f12dSWarner Losh 			    "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode,
21478207f12dSWarner Losh 			    (uintmax_t)st.st_ino, (intmax_t)st.st_size,
21488207f12dSWarner Losh 			    (long)st.st_blksize);
21498207f12dSWarner Losh 		} else {
21508207f12dSWarner Losh 			fprintf(fp, "0x%lx", args[sc->offset]);
21518207f12dSWarner Losh 		}
21528207f12dSWarner Losh 		break;
21538207f12dSWarner Losh 	}
2154a776866bSBryan Drewery 	case StatFs: {
2155a776866bSBryan Drewery 		unsigned int i;
2156a776866bSBryan Drewery 		struct statfs buf;
21570a71c082SBryan Drewery 
2158a776866bSBryan Drewery 		if (get_struct(pid, (void *)args[sc->offset], &buf,
2159a776866bSBryan Drewery 		    sizeof(buf)) != -1) {
2160a776866bSBryan Drewery 			char fsid[17];
2161a776866bSBryan Drewery 
2162a776866bSBryan Drewery 			bzero(fsid, sizeof(fsid));
2163a776866bSBryan Drewery 			if (buf.f_fsid.val[0] != 0 || buf.f_fsid.val[1] != 0) {
2164a776866bSBryan Drewery 			        for (i = 0; i < sizeof(buf.f_fsid); i++)
2165a776866bSBryan Drewery 					snprintf(&fsid[i*2],
2166a776866bSBryan Drewery 					    sizeof(fsid) - (i*2), "%02x",
2167a776866bSBryan Drewery 					    ((u_char *)&buf.f_fsid)[i]);
2168a776866bSBryan Drewery 			}
2169a776866bSBryan Drewery 			fprintf(fp,
2170a776866bSBryan Drewery 			    "{ fstypename=%s,mntonname=%s,mntfromname=%s,"
2171a776866bSBryan Drewery 			    "fsid=%s }", buf.f_fstypename, buf.f_mntonname,
2172a776866bSBryan Drewery 			    buf.f_mntfromname, fsid);
2173a776866bSBryan Drewery 		} else
2174a776866bSBryan Drewery 			fprintf(fp, "0x%lx", args[sc->offset]);
2175a776866bSBryan Drewery 		break;
2176a776866bSBryan Drewery 	}
2177a776866bSBryan Drewery 
2178d8984f48SDag-Erling Smørgrav 	case Rusage: {
2179081e5c48SPav Lucistnik 		struct rusage ru;
21804e3da534SJohn Baldwin 
218194355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru))
218294355cfdSAndrey Zonov 		    != -1) {
2183f083f689SJohn Baldwin 			fprintf(fp,
2184a1436773SJohn Baldwin 			    "{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }",
2185a1436773SJohn Baldwin 			    (intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec,
2186a1436773SJohn Baldwin 			    (intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec,
2187081e5c48SPav Lucistnik 			    ru.ru_inblock, ru.ru_oublock);
218894355cfdSAndrey Zonov 		} else
2189f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2190081e5c48SPav Lucistnik 		break;
2191d8984f48SDag-Erling Smørgrav 	}
2192d8984f48SDag-Erling Smørgrav 	case Rlimit: {
2193081e5c48SPav Lucistnik 		struct rlimit rl;
21944e3da534SJohn Baldwin 
219594355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &rl, sizeof(rl))
219694355cfdSAndrey Zonov 		    != -1) {
2197f083f689SJohn Baldwin 			fprintf(fp, "{ cur=%ju,max=%ju }",
2198081e5c48SPav Lucistnik 			    rl.rlim_cur, rl.rlim_max);
219994355cfdSAndrey Zonov 		} else
2200f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2201081e5c48SPav Lucistnik 		break;
2202d8984f48SDag-Erling Smørgrav 	}
220334763d1cSJohn Baldwin 	case ExitStatus: {
220434763d1cSJohn Baldwin 		int status;
2205f083f689SJohn Baldwin 
220634763d1cSJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &status,
220734763d1cSJohn Baldwin 		    sizeof(status)) != -1) {
2208f083f689SJohn Baldwin 			fputs("{ ", fp);
220934763d1cSJohn Baldwin 			if (WIFCONTINUED(status))
2210f083f689SJohn Baldwin 				fputs("CONTINUED", fp);
221134763d1cSJohn Baldwin 			else if (WIFEXITED(status))
2212f083f689SJohn Baldwin 				fprintf(fp, "EXITED,val=%d",
221334763d1cSJohn Baldwin 				    WEXITSTATUS(status));
221434763d1cSJohn Baldwin 			else if (WIFSIGNALED(status))
2215f083f689SJohn Baldwin 				fprintf(fp, "SIGNALED,sig=%s%s",
2216f083f689SJohn Baldwin 				    strsig2(WTERMSIG(status)),
221734763d1cSJohn Baldwin 				    WCOREDUMP(status) ? ",cored" : "");
221834763d1cSJohn Baldwin 			else
2219f083f689SJohn Baldwin 				fprintf(fp, "STOPPED,sig=%s",
2220f083f689SJohn Baldwin 				    strsig2(WTERMSIG(status)));
2221f083f689SJohn Baldwin 			fputs(" }", fp);
222234763d1cSJohn Baldwin 		} else
2223f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
222434763d1cSJohn Baldwin 		break;
222534763d1cSJohn Baldwin 	}
222634763d1cSJohn Baldwin 	case Waitoptions:
22279289f547SJohn Baldwin 		print_mask_arg(sysdecode_wait6_options, fp, args[sc->offset]);
222834763d1cSJohn Baldwin 		break;
222934763d1cSJohn Baldwin 	case Idtype:
22309289f547SJohn Baldwin 		print_integer_arg(sysdecode_idtype, fp, args[sc->offset]);
223134763d1cSJohn Baldwin 		break;
223255648840SJohn Baldwin 	case Procctl:
22339289f547SJohn Baldwin 		print_integer_arg(sysdecode_procctl_cmd, fp, args[sc->offset]);
223455648840SJohn Baldwin 		break;
2235fdb5bf37SJohn Baldwin 	case Umtxop:
22369289f547SJohn Baldwin 		print_integer_arg(sysdecode_umtx_op, fp, args[sc->offset]);
2237fdb5bf37SJohn Baldwin 		break;
22387d897327SJohn Baldwin 	case Atfd:
22399289f547SJohn Baldwin 		print_integer_arg(sysdecode_atfd, fp, args[sc->offset]);
22407d897327SJohn Baldwin 		break;
22417d897327SJohn Baldwin 	case Atflags:
224239a3a438SJohn Baldwin 		print_mask_arg(sysdecode_atflags, fp, args[sc->offset]);
22437d897327SJohn Baldwin 		break;
22447d897327SJohn Baldwin 	case Accessmode:
22459289f547SJohn Baldwin 		print_mask_arg(sysdecode_access_mode, fp, args[sc->offset]);
22467d897327SJohn Baldwin 		break;
2247b289a8d7SJohn Baldwin 	case Sysarch:
224839a3a438SJohn Baldwin 		print_integer_arg(sysdecode_sysarch_number, fp,
224939a3a438SJohn Baldwin 		    args[sc->offset]);
2250b289a8d7SJohn Baldwin 		break;
22512b75c8adSJohn Baldwin 	case PipeFds:
22522b75c8adSJohn Baldwin 		/*
22532b75c8adSJohn Baldwin 		 * The pipe() system call in the kernel returns its
22542b75c8adSJohn Baldwin 		 * two file descriptors via return values.  However,
22552b75c8adSJohn Baldwin 		 * the interface exposed by libc is that pipe()
22562b75c8adSJohn Baldwin 		 * accepts a pointer to an array of descriptors.
22572b75c8adSJohn Baldwin 		 * Format the output to match the libc API by printing
22582b75c8adSJohn Baldwin 		 * the returned file descriptors as a fake argument.
22592b75c8adSJohn Baldwin 		 *
22602b75c8adSJohn Baldwin 		 * Overwrite the first retval to signal a successful
22612b75c8adSJohn Baldwin 		 * return as well.
22622b75c8adSJohn Baldwin 		 */
22632b75c8adSJohn Baldwin 		fprintf(fp, "{ %ld, %ld }", retval[0], retval[1]);
22642b75c8adSJohn Baldwin 		retval[0] = 0;
22652b75c8adSJohn Baldwin 		break;
2266195aef99SBryan Drewery 	case Utrace: {
2267195aef99SBryan Drewery 		size_t len;
2268195aef99SBryan Drewery 		void *utrace_addr;
2269195aef99SBryan Drewery 
2270195aef99SBryan Drewery 		len = args[sc->offset + 1];
2271195aef99SBryan Drewery 		utrace_addr = calloc(1, len);
2272195aef99SBryan Drewery 		if (get_struct(pid, (void *)args[sc->offset],
2273195aef99SBryan Drewery 		    (void *)utrace_addr, len) != -1)
2274195aef99SBryan Drewery 			print_utrace(fp, utrace_addr, len);
2275195aef99SBryan Drewery 		else
2276195aef99SBryan Drewery 			fprintf(fp, "0x%lx", args[sc->offset]);
2277195aef99SBryan Drewery 		free(utrace_addr);
2278195aef99SBryan Drewery 		break;
2279195aef99SBryan Drewery 	}
2280808d9805SEd Schouten 	case IntArray: {
2281808d9805SEd Schouten 		int descriptors[16];
2282808d9805SEd Schouten 		unsigned long i, ndescriptors;
2283808d9805SEd Schouten 		bool truncated;
2284808d9805SEd Schouten 
2285808d9805SEd Schouten 		ndescriptors = args[sc->offset + 1];
2286808d9805SEd Schouten 		truncated = false;
2287808d9805SEd Schouten 		if (ndescriptors > nitems(descriptors)) {
2288808d9805SEd Schouten 			ndescriptors = nitems(descriptors);
2289808d9805SEd Schouten 			truncated = true;
2290808d9805SEd Schouten 		}
2291808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset],
2292808d9805SEd Schouten 		    descriptors, ndescriptors * sizeof(descriptors[0])) != -1) {
2293808d9805SEd Schouten 			fprintf(fp, "{");
2294808d9805SEd Schouten 			for (i = 0; i < ndescriptors; i++)
2295808d9805SEd Schouten 				fprintf(fp, i == 0 ? " %d" : ", %d",
2296808d9805SEd Schouten 				    descriptors[i]);
2297808d9805SEd Schouten 			fprintf(fp, truncated ? ", ... }" : " }");
2298808d9805SEd Schouten 		} else
2299808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
2300808d9805SEd Schouten 		break;
2301808d9805SEd Schouten 	}
23029289f547SJohn Baldwin 	case Pipe2:
23039289f547SJohn Baldwin 		print_mask_arg(sysdecode_pipe2_flags, fp, args[sc->offset]);
23049289f547SJohn Baldwin 		break;
2305bed418c8SJohn Baldwin 	case CapFcntlRights: {
2306bed418c8SJohn Baldwin 		uint32_t rights;
2307bed418c8SJohn Baldwin 
2308bed418c8SJohn Baldwin 		if (sc->type & OUT) {
2309bed418c8SJohn Baldwin 			if (get_struct(pid, (void *)args[sc->offset], &rights,
2310bed418c8SJohn Baldwin 			    sizeof(rights)) == -1) {
2311bed418c8SJohn Baldwin 				fprintf(fp, "0x%lx", args[sc->offset]);
2312bed418c8SJohn Baldwin 				break;
2313bed418c8SJohn Baldwin 			}
2314bed418c8SJohn Baldwin 		} else
2315bed418c8SJohn Baldwin 			rights = args[sc->offset];
2316bed418c8SJohn Baldwin 		print_mask_arg32(sysdecode_cap_fcntlrights, fp, rights);
2317bed418c8SJohn Baldwin 		break;
2318bed418c8SJohn Baldwin 	}
2319d2a97485SJohn Baldwin 	case Fadvice:
2320d2a97485SJohn Baldwin 		print_integer_arg(sysdecode_fadvice, fp, args[sc->offset]);
2321d2a97485SJohn Baldwin 		break;
232227459358SJohn Baldwin 	case FileFlags: {
232327459358SJohn Baldwin 		fflags_t rem;
232427459358SJohn Baldwin 
232527459358SJohn Baldwin 		if (!sysdecode_fileflags(fp, args[sc->offset], &rem))
232627459358SJohn Baldwin 			fprintf(fp, "0x%x", rem);
232727459358SJohn Baldwin 		else if (rem != 0)
232827459358SJohn Baldwin 			fprintf(fp, "|0x%x", rem);
232927459358SJohn Baldwin 		break;
233027459358SJohn Baldwin 	}
2331dd92181fSJohn Baldwin 	case Flockop:
2332dd92181fSJohn Baldwin 		print_mask_arg(sysdecode_flock_operation, fp, args[sc->offset]);
2333dd92181fSJohn Baldwin 		break;
2334ab43bedcSJohn Baldwin 	case Getfsstatmode:
2335ab43bedcSJohn Baldwin 		print_integer_arg(sysdecode_getfsstat_mode, fp,
2336ab43bedcSJohn Baldwin 		    args[sc->offset]);
2337ab43bedcSJohn Baldwin 		break;
233894e854c5SJohn Baldwin 	case Kldsymcmd:
233994e854c5SJohn Baldwin 		print_integer_arg(sysdecode_kldsym_cmd, fp, args[sc->offset]);
234094e854c5SJohn Baldwin 		break;
234194e854c5SJohn Baldwin 	case Kldunloadflags:
234294e854c5SJohn Baldwin 		print_integer_arg(sysdecode_kldunload_flags, fp,
234394e854c5SJohn Baldwin 		    args[sc->offset]);
234494e854c5SJohn Baldwin 		break;
234598fdbeecSJohn Baldwin 	case Madvice:
234698fdbeecSJohn Baldwin 		print_integer_arg(sysdecode_madvice, fp, args[sc->offset]);
234798fdbeecSJohn Baldwin 		break;
234858227c60SMichael Tuexen 	case Socklent:
234958227c60SMichael Tuexen 		fprintf(fp, "%u", (socklen_t)args[sc->offset]);
235058227c60SMichael Tuexen 		break;
2351ecac235bSMichael Tuexen 	case Sockprotocol: {
2352738a93a4SMichael Tuexen 		const char *temp;
2353738a93a4SMichael Tuexen 		int domain, protocol;
2354ecac235bSMichael Tuexen 
2355738a93a4SMichael Tuexen 		domain = args[sc->offset - 2];
2356ecac235bSMichael Tuexen 		protocol = args[sc->offset];
2357ecac235bSMichael Tuexen 		if (protocol == 0) {
2358ecac235bSMichael Tuexen 			fputs("0", fp);
2359ecac235bSMichael Tuexen 		} else {
2360738a93a4SMichael Tuexen 			temp = sysdecode_socket_protocol(domain, protocol);
2361738a93a4SMichael Tuexen 			if (temp) {
2362738a93a4SMichael Tuexen 				fputs(temp, fp);
2363738a93a4SMichael Tuexen 			} else {
2364738a93a4SMichael Tuexen 				fprintf(fp, "%d", protocol);
2365738a93a4SMichael Tuexen 			}
2366ecac235bSMichael Tuexen 		}
2367ecac235bSMichael Tuexen 		break;
2368ecac235bSMichael Tuexen 	}
2369832af457SMichael Tuexen 	case Sockoptlevel:
2370832af457SMichael Tuexen 		print_integer_arg(sysdecode_sockopt_level, fp,
2371832af457SMichael Tuexen 		    args[sc->offset]);
2372832af457SMichael Tuexen 		break;
2373832af457SMichael Tuexen 	case Sockoptname: {
2374832af457SMichael Tuexen 		const char *temp;
2375832af457SMichael Tuexen 		int level, name;
2376832af457SMichael Tuexen 
2377832af457SMichael Tuexen 		level = args[sc->offset - 1];
2378832af457SMichael Tuexen 		name = args[sc->offset];
2379832af457SMichael Tuexen 		temp = sysdecode_sockopt_name(level, name);
2380832af457SMichael Tuexen 		if (temp) {
2381832af457SMichael Tuexen 			fputs(temp, fp);
2382832af457SMichael Tuexen 		} else {
2383832af457SMichael Tuexen 			fprintf(fp, "%d", name);
2384832af457SMichael Tuexen 		}
2385832af457SMichael Tuexen 		break;
2386832af457SMichael Tuexen 	}
23878b429b65SMichael Tuexen 	case Msgflags:
23888b429b65SMichael Tuexen 		print_mask_arg(sysdecode_msg_flags, fp, args[sc->offset]);
23898b429b65SMichael Tuexen 		break;
23907136a1d9SJohn Baldwin 	case CapRights: {
23917136a1d9SJohn Baldwin 		cap_rights_t rights;
23927136a1d9SJohn Baldwin 
23937136a1d9SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &rights,
23947136a1d9SJohn Baldwin 		    sizeof(rights)) != -1) {
23957136a1d9SJohn Baldwin 			fputs("{ ", fp);
23967136a1d9SJohn Baldwin 			sysdecode_cap_rights(fp, &rights);
23977136a1d9SJohn Baldwin 			fputs(" }", fp);
23987136a1d9SJohn Baldwin 		} else
23997136a1d9SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
24007136a1d9SJohn Baldwin 		break;
24017136a1d9SJohn Baldwin 	}
24027ce44f08SJohn Baldwin 	case Acltype:
24037ce44f08SJohn Baldwin 		print_integer_arg(sysdecode_acltype, fp, args[sc->offset]);
24047ce44f08SJohn Baldwin 		break;
240526606dcaSJohn Baldwin 	case Extattrnamespace:
240626606dcaSJohn Baldwin 		print_integer_arg(sysdecode_extattrnamespace, fp,
240726606dcaSJohn Baldwin 		    args[sc->offset]);
240826606dcaSJohn Baldwin 		break;
24092d9c9988SJohn Baldwin 	case Minherit:
24102d9c9988SJohn Baldwin 		print_integer_arg(sysdecode_minherit_inherit, fp,
24112d9c9988SJohn Baldwin 		    args[sc->offset]);
24122d9c9988SJohn Baldwin 		break;
241394bde755SJohn Baldwin 	case Mlockall:
241494bde755SJohn Baldwin 		print_mask_arg(sysdecode_mlockall_flags, fp, args[sc->offset]);
241594bde755SJohn Baldwin 		break;
24168acc8e78SJohn Baldwin 	case Mountflags:
24178acc8e78SJohn Baldwin 		print_mask_arg(sysdecode_mount_flags, fp, args[sc->offset]);
24188acc8e78SJohn Baldwin 		break;
2419114aeee0SJohn Baldwin 	case Msync:
2420114aeee0SJohn Baldwin 		print_mask_arg(sysdecode_msync_flags, fp, args[sc->offset]);
2421114aeee0SJohn Baldwin 		break;
2422ad419d33SJohn Baldwin 	case Priowhich:
2423ad419d33SJohn Baldwin 		print_integer_arg(sysdecode_prio_which, fp, args[sc->offset]);
2424ad419d33SJohn Baldwin 		break;
24255ac1c7acSJohn Baldwin 	case Ptraceop:
24265ac1c7acSJohn Baldwin 		print_integer_arg(sysdecode_ptrace_request, fp,
24275ac1c7acSJohn Baldwin 		    args[sc->offset]);
24285ac1c7acSJohn Baldwin 		break;
2429dd0c462cSJohn Baldwin 	case Quotactlcmd:
2430dd0c462cSJohn Baldwin 		if (!sysdecode_quotactl_cmd(fp, args[sc->offset]))
2431dd0c462cSJohn Baldwin 			fprintf(fp, "%#x", (int)args[sc->offset]);
2432dd0c462cSJohn Baldwin 		break;
24334152441fSJohn Baldwin 	case Reboothowto:
24344152441fSJohn Baldwin 		print_mask_arg(sysdecode_reboot_howto, fp, args[sc->offset]);
24354152441fSJohn Baldwin 		break;
24363cd40bc3SJohn Baldwin 	case Rtpriofunc:
24373cd40bc3SJohn Baldwin 		print_integer_arg(sysdecode_rtprio_function, fp,
24383cd40bc3SJohn Baldwin 		    args[sc->offset]);
24393cd40bc3SJohn Baldwin 		break;
2440a4110f9fSJohn Baldwin 	case Schedpolicy:
2441a4110f9fSJohn Baldwin 		print_integer_arg(sysdecode_scheduler_policy, fp,
2442a4110f9fSJohn Baldwin 		    args[sc->offset]);
2443a4110f9fSJohn Baldwin 		break;
2444a4110f9fSJohn Baldwin 	case Schedparam: {
2445a4110f9fSJohn Baldwin 		struct sched_param sp;
2446a4110f9fSJohn Baldwin 
2447a4110f9fSJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &sp,
2448a4110f9fSJohn Baldwin 		    sizeof(sp)) != -1)
2449a4110f9fSJohn Baldwin 			fprintf(fp, "{ %d }", sp.sched_priority);
2450a4110f9fSJohn Baldwin 		else
2451a4110f9fSJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
2452a4110f9fSJohn Baldwin 		break;
2453a4110f9fSJohn Baldwin 	}
245413e5e6b6SJohn Baldwin 	case PSig: {
245513e5e6b6SJohn Baldwin 		int sig;
245613e5e6b6SJohn Baldwin 
245713e5e6b6SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &sig,
245813e5e6b6SJohn Baldwin 		    sizeof(sig)) == 0)
245913e5e6b6SJohn Baldwin 			fprintf(fp, "{ %s }", strsig2(sig));
246013e5e6b6SJohn Baldwin 		else
246113e5e6b6SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
246213e5e6b6SJohn Baldwin 		break;
246313e5e6b6SJohn Baldwin 	}
246413e5e6b6SJohn Baldwin 	case Siginfo: {
246513e5e6b6SJohn Baldwin 		siginfo_t si;
246613e5e6b6SJohn Baldwin 
246713e5e6b6SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &si,
246813e5e6b6SJohn Baldwin 		    sizeof(si)) != -1) {
246913e5e6b6SJohn Baldwin 			fprintf(fp, "{ signo=%s", strsig2(si.si_signo));
247013e5e6b6SJohn Baldwin 			decode_siginfo(fp, &si);
247113e5e6b6SJohn Baldwin 			fprintf(fp, " }");
247213e5e6b6SJohn Baldwin 		} else
247313e5e6b6SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
247413e5e6b6SJohn Baldwin 		break;
247513e5e6b6SJohn Baldwin 	}
2476a2674e03SMichael Tuexen 	case Iovec:
2477ee6e58b2SMichael Tuexen 		/*
2478ee6e58b2SMichael Tuexen 		 * Print argument as an array of struct iovec, where the next
2479ee6e58b2SMichael Tuexen 		 * syscall argument is the number of elements of the array.
2480ee6e58b2SMichael Tuexen 		 */
2481ee6e58b2SMichael Tuexen 
2482a2674e03SMichael Tuexen 		print_iovec(fp, trussinfo, (void *)args[sc->offset],
2483a2674e03SMichael Tuexen 		    (int)args[sc->offset + 1]);
2484ee6e58b2SMichael Tuexen 		break;
24854d7b9809SMichael Tuexen 	case Sctpsndrcvinfo: {
24864d7b9809SMichael Tuexen 		struct sctp_sndrcvinfo info;
24874d7b9809SMichael Tuexen 
24884d7b9809SMichael Tuexen 		if (get_struct(pid, (void *)args[sc->offset],
24894d7b9809SMichael Tuexen 		    &info, sizeof(struct sctp_sndrcvinfo)) == -1) {
24904d7b9809SMichael Tuexen 			fprintf(fp, "0x%lx", args[sc->offset]);
24914d7b9809SMichael Tuexen 			break;
24924d7b9809SMichael Tuexen 		}
2493a2674e03SMichael Tuexen 		print_sctp_sndrcvinfo(fp, sc->type & OUT, &info);
2494a2674e03SMichael Tuexen 		break;
24954d7b9809SMichael Tuexen 	}
2496a2674e03SMichael Tuexen 	case Msghdr: {
2497a2674e03SMichael Tuexen 		struct msghdr msghdr;
2498a2674e03SMichael Tuexen 
2499a2674e03SMichael Tuexen 		if (get_struct(pid, (void *)args[sc->offset],
2500a2674e03SMichael Tuexen 		    &msghdr, sizeof(struct msghdr)) == -1) {
2501a2674e03SMichael Tuexen 			fprintf(fp, "0x%lx", args[sc->offset]);
2502a2674e03SMichael Tuexen 			break;
25034d7b9809SMichael Tuexen 		}
2504a2674e03SMichael Tuexen 		fputs("{", fp);
2505a2674e03SMichael Tuexen 		print_sockaddr(fp, trussinfo, msghdr.msg_name, msghdr.msg_namelen);
2506a2674e03SMichael Tuexen 		fprintf(fp, ",%d,", msghdr.msg_namelen);
2507a2674e03SMichael Tuexen 		print_iovec(fp, trussinfo, msghdr.msg_iov, msghdr.msg_iovlen);
2508a2674e03SMichael Tuexen 		fprintf(fp, ",%d,", msghdr.msg_iovlen);
2509a2674e03SMichael Tuexen 		print_cmsgs(fp, pid, sc->type & OUT, &msghdr);
2510a2674e03SMichael Tuexen 		fprintf(fp, ",%u,", msghdr.msg_controllen);
2511a2674e03SMichael Tuexen 		print_mask_arg(sysdecode_msg_flags, fp, msghdr.msg_flags);
2512a2674e03SMichael Tuexen 		fputs("}", fp);
25134d7b9809SMichael Tuexen 		break;
25144d7b9809SMichael Tuexen 	}
2515808d9805SEd Schouten 
2516808d9805SEd Schouten 	case CloudABIAdvice:
2517808d9805SEd Schouten 		fputs(xlookup(cloudabi_advice, args[sc->offset]), fp);
2518808d9805SEd Schouten 		break;
2519808d9805SEd Schouten 	case CloudABIClockID:
2520808d9805SEd Schouten 		fputs(xlookup(cloudabi_clockid, args[sc->offset]), fp);
2521808d9805SEd Schouten 		break;
2522808d9805SEd Schouten 	case ClouduABIFDSFlags:
2523808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_fdsflags, args[sc->offset]), fp);
2524808d9805SEd Schouten 		break;
2525808d9805SEd Schouten 	case CloudABIFDStat: {
2526808d9805SEd Schouten 		cloudabi_fdstat_t fds;
2527808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset], &fds, sizeof(fds))
2528808d9805SEd Schouten 		    != -1) {
2529808d9805SEd Schouten 			fprintf(fp, "{ %s, ",
2530808d9805SEd Schouten 			    xlookup(cloudabi_filetype, fds.fs_filetype));
2531808d9805SEd Schouten 			fprintf(fp, "%s, ... }",
2532808d9805SEd Schouten 			    xlookup_bits(cloudabi_fdflags, fds.fs_flags));
2533808d9805SEd Schouten 		} else
2534808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
2535808d9805SEd Schouten 		break;
2536808d9805SEd Schouten 	}
2537808d9805SEd Schouten 	case CloudABIFileStat: {
2538808d9805SEd Schouten 		cloudabi_filestat_t fsb;
2539808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset], &fsb, sizeof(fsb))
2540808d9805SEd Schouten 		    != -1)
25419ba32307SJohn Baldwin 			fprintf(fp, "{ %s, %ju }",
2542808d9805SEd Schouten 			    xlookup(cloudabi_filetype, fsb.st_filetype),
25439ba32307SJohn Baldwin 			    (uintmax_t)fsb.st_size);
2544808d9805SEd Schouten 		else
2545808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
2546808d9805SEd Schouten 		break;
2547808d9805SEd Schouten 	}
2548808d9805SEd Schouten 	case CloudABIFileType:
2549808d9805SEd Schouten 		fputs(xlookup(cloudabi_filetype, args[sc->offset]), fp);
2550808d9805SEd Schouten 		break;
2551808d9805SEd Schouten 	case CloudABIFSFlags:
2552808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_fsflags, args[sc->offset]), fp);
2553808d9805SEd Schouten 		break;
2554808d9805SEd Schouten 	case CloudABILookup:
2555808d9805SEd Schouten 		if ((args[sc->offset] & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0)
2556808d9805SEd Schouten 			fprintf(fp, "%d|LOOKUP_SYMLINK_FOLLOW",
2557808d9805SEd Schouten 			    (int)args[sc->offset]);
2558808d9805SEd Schouten 		else
2559808d9805SEd Schouten 			fprintf(fp, "%d", (int)args[sc->offset]);
2560808d9805SEd Schouten 		break;
2561808d9805SEd Schouten 	case CloudABIMFlags:
2562808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_mflags, args[sc->offset]), fp);
2563808d9805SEd Schouten 		break;
2564808d9805SEd Schouten 	case CloudABIMProt:
2565808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_mprot, args[sc->offset]), fp);
2566808d9805SEd Schouten 		break;
2567808d9805SEd Schouten 	case CloudABIMSFlags:
2568808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_msflags, args[sc->offset]), fp);
2569808d9805SEd Schouten 		break;
2570808d9805SEd Schouten 	case CloudABIOFlags:
2571808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_oflags, args[sc->offset]), fp);
2572808d9805SEd Schouten 		break;
2573808d9805SEd Schouten 	case CloudABISDFlags:
2574808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_sdflags, args[sc->offset]), fp);
2575808d9805SEd Schouten 		break;
2576808d9805SEd Schouten 	case CloudABISignal:
2577808d9805SEd Schouten 		fputs(xlookup(cloudabi_signal, args[sc->offset]), fp);
2578808d9805SEd Schouten 		break;
2579808d9805SEd Schouten 	case CloudABITimestamp:
2580808d9805SEd Schouten 		fprintf(fp, "%lu.%09lus", args[sc->offset] / 1000000000,
2581808d9805SEd Schouten 		    args[sc->offset] % 1000000000);
2582808d9805SEd Schouten 		break;
2583808d9805SEd Schouten 	case CloudABIULFlags:
2584808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_ulflags, args[sc->offset]), fp);
2585808d9805SEd Schouten 		break;
2586808d9805SEd Schouten 	case CloudABIWhence:
2587808d9805SEd Schouten 		fputs(xlookup(cloudabi_whence, args[sc->offset]), fp);
2588808d9805SEd Schouten 		break;
2589808d9805SEd Schouten 
2590081e5c48SPav Lucistnik 	default:
2591081e5c48SPav Lucistnik 		errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK);
2592bbeaf6c0SSean Eric Fagan 	}
2593f083f689SJohn Baldwin 	fclose(fp);
2594d8984f48SDag-Erling Smørgrav 	return (tmp);
2595bbeaf6c0SSean Eric Fagan }
2596bbeaf6c0SSean Eric Fagan 
2597bbeaf6c0SSean Eric Fagan /*
259800ddbdf2SJohn Baldwin  * Print (to outfile) the system call and its arguments.
2599bbeaf6c0SSean Eric Fagan  */
2600bbeaf6c0SSean Eric Fagan void
260100ddbdf2SJohn Baldwin print_syscall(struct trussinfo *trussinfo)
2602d8984f48SDag-Erling Smørgrav {
260300ddbdf2SJohn Baldwin 	struct threadinfo *t;
260400ddbdf2SJohn Baldwin 	const char *name;
260500ddbdf2SJohn Baldwin 	char **s_args;
260600ddbdf2SJohn Baldwin 	int i, len, nargs;
26070d0bd00eSMatthew N. Dodd 
260800ddbdf2SJohn Baldwin 	t = trussinfo->curthread;
2609c03bfcc8SMatthew N. Dodd 
26101175b23fSJohn Baldwin 	name = t->cs.sc->name;
261100ddbdf2SJohn Baldwin 	nargs = t->cs.nargs;
261200ddbdf2SJohn Baldwin 	s_args = t->cs.s_args;
26130d0bd00eSMatthew N. Dodd 
2614d70876fdSJohn Baldwin 	len = print_line_prefix(trussinfo);
2615ec0bed25SMatthew N. Dodd 	len += fprintf(trussinfo->outfile, "%s(", name);
2616c03bfcc8SMatthew N. Dodd 
2617bbeaf6c0SSean Eric Fagan 	for (i = 0; i < nargs; i++) {
261800ddbdf2SJohn Baldwin 		if (s_args[i] != NULL)
2619ec0bed25SMatthew N. Dodd 			len += fprintf(trussinfo->outfile, "%s", s_args[i]);
2620bbeaf6c0SSean Eric Fagan 		else
262194355cfdSAndrey Zonov 			len += fprintf(trussinfo->outfile,
262294355cfdSAndrey Zonov 			    "<missing argument>");
262394355cfdSAndrey Zonov 		len += fprintf(trussinfo->outfile, "%s", i < (nargs - 1) ?
262494355cfdSAndrey Zonov 		    "," : "");
2625bbeaf6c0SSean Eric Fagan 	}
2626ec0bed25SMatthew N. Dodd 	len += fprintf(trussinfo->outfile, ")");
26276cb533feSSean Eric Fagan 	for (i = 0; i < 6 - (len / 8); i++)
2628ec0bed25SMatthew N. Dodd 		fprintf(trussinfo->outfile, "\t");
26296cb533feSSean Eric Fagan }
26306cb533feSSean Eric Fagan 
26316cb533feSSean Eric Fagan void
263200ddbdf2SJohn Baldwin print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval)
26331bcb5f5aSMarcel Moolenaar {
2634ee3b0f6eSDiomidis Spinellis 	struct timespec timediff;
263500ddbdf2SJohn Baldwin 	struct threadinfo *t;
263600ddbdf2SJohn Baldwin 	struct syscall *sc;
2637287b96ddSJohn Baldwin 	int error;
2638ee3b0f6eSDiomidis Spinellis 
263900ddbdf2SJohn Baldwin 	t = trussinfo->curthread;
264000ddbdf2SJohn Baldwin 	sc = t->cs.sc;
2641ee3b0f6eSDiomidis Spinellis 	if (trussinfo->flags & COUNTONLY) {
264200ddbdf2SJohn Baldwin 		timespecsubt(&t->after, &t->before, &timediff);
2643d9dcc463SXin LI 		timespecadd(&sc->time, &timediff, &sc->time);
2644ee3b0f6eSDiomidis Spinellis 		sc->ncalls++;
2645ee3b0f6eSDiomidis Spinellis 		if (errorp)
2646ee3b0f6eSDiomidis Spinellis 			sc->nerror++;
2647ee3b0f6eSDiomidis Spinellis 		return;
2648ee3b0f6eSDiomidis Spinellis 	}
2649d8984f48SDag-Erling Smørgrav 
265000ddbdf2SJohn Baldwin 	print_syscall(trussinfo);
26510cf21b4fSBrian Somers 	fflush(trussinfo->outfile);
2652b9befd33SJohn Baldwin 
2653b9befd33SJohn Baldwin 	if (retval == NULL) {
2654b9befd33SJohn Baldwin 		/*
2655b9befd33SJohn Baldwin 		 * This system call resulted in the current thread's exit,
2656b9befd33SJohn Baldwin 		 * so there is no return value or error to display.
2657b9befd33SJohn Baldwin 		 */
2658b9befd33SJohn Baldwin 		fprintf(trussinfo->outfile, "\n");
2659b9befd33SJohn Baldwin 		return;
2660b9befd33SJohn Baldwin 	}
2661b9befd33SJohn Baldwin 
2662287b96ddSJohn Baldwin 	if (errorp) {
2663287b96ddSJohn Baldwin 		error = sysdecode_abi_to_freebsd_errno(t->proc->abi->abi,
2664287b96ddSJohn Baldwin 		    retval[0]);
26652b75c8adSJohn Baldwin 		fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval[0],
2666287b96ddSJohn Baldwin 		    error == INT_MAX ? "Unknown error" : strerror(error));
2667287b96ddSJohn Baldwin 	}
26682b75c8adSJohn Baldwin #ifndef __LP64__
26696c61b0f3SBryan Drewery 	else if (sc->ret_type == 2) {
26702b75c8adSJohn Baldwin 		off_t off;
26712b75c8adSJohn Baldwin 
26722b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN
26732b75c8adSJohn Baldwin 		off = (off_t)retval[1] << 32 | retval[0];
26742b75c8adSJohn Baldwin #else
26752b75c8adSJohn Baldwin 		off = (off_t)retval[0] << 32 | retval[1];
26762b75c8adSJohn Baldwin #endif
26772b75c8adSJohn Baldwin 		fprintf(trussinfo->outfile, " = %jd (0x%jx)\n", (intmax_t)off,
26782b75c8adSJohn Baldwin 		    (intmax_t)off);
26796cb533feSSean Eric Fagan 	}
26802b75c8adSJohn Baldwin #endif
26812b75c8adSJohn Baldwin 	else
26822b75c8adSJohn Baldwin 		fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval[0],
26832b75c8adSJohn Baldwin 		    retval[0]);
2684bbeaf6c0SSean Eric Fagan }
2685ee3b0f6eSDiomidis Spinellis 
2686ee3b0f6eSDiomidis Spinellis void
2687ee3b0f6eSDiomidis Spinellis print_summary(struct trussinfo *trussinfo)
2688ee3b0f6eSDiomidis Spinellis {
2689ee3b0f6eSDiomidis Spinellis 	struct timespec total = {0, 0};
269094355cfdSAndrey Zonov 	struct syscall *sc;
2691ee3b0f6eSDiomidis Spinellis 	int ncall, nerror;
2692ee3b0f6eSDiomidis Spinellis 
2693ee3b0f6eSDiomidis Spinellis 	fprintf(trussinfo->outfile, "%-20s%15s%8s%8s\n",
2694ee3b0f6eSDiomidis Spinellis 	    "syscall", "seconds", "calls", "errors");
2695ee3b0f6eSDiomidis Spinellis 	ncall = nerror = 0;
26966c61b0f3SBryan Drewery 	STAILQ_FOREACH(sc, &syscalls, entries)
2697ee3b0f6eSDiomidis Spinellis 		if (sc->ncalls) {
269855a8d2bbSJaakko Heinonen 			fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n",
269955a8d2bbSJaakko Heinonen 			    sc->name, (intmax_t)sc->time.tv_sec,
270055a8d2bbSJaakko Heinonen 			    sc->time.tv_nsec, sc->ncalls, sc->nerror);
2701d9dcc463SXin LI 			timespecadd(&total, &sc->time, &total);
2702ee3b0f6eSDiomidis Spinellis 			ncall += sc->ncalls;
2703ee3b0f6eSDiomidis Spinellis 			nerror += sc->nerror;
2704ee3b0f6eSDiomidis Spinellis 		}
2705ee3b0f6eSDiomidis Spinellis 	fprintf(trussinfo->outfile, "%20s%15s%8s%8s\n",
2706ee3b0f6eSDiomidis Spinellis 	    "", "-------------", "-------", "-------");
270755a8d2bbSJaakko Heinonen 	fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n",
270855a8d2bbSJaakko Heinonen 	    "", (intmax_t)total.tv_sec, total.tv_nsec, ncall, nerror);
2709ee3b0f6eSDiomidis Spinellis }
2710