xref: /freebsd/usr.bin/truss/syscalls.c (revision 26606dcaa73c89897de01637aa1e26c41a04b074)
1bbeaf6c0SSean Eric Fagan /*
20a6c71f8SWarner Losh  * Copyright 1997 Sean Eric Fagan
309d64da3SSean Eric Fagan  *
409d64da3SSean Eric Fagan  * Redistribution and use in source and binary forms, with or without
509d64da3SSean Eric Fagan  * modification, are permitted provided that the following conditions
609d64da3SSean Eric Fagan  * are met:
709d64da3SSean Eric Fagan  * 1. Redistributions of source code must retain the above copyright
809d64da3SSean Eric Fagan  *    notice, this list of conditions and the following disclaimer.
909d64da3SSean Eric Fagan  * 2. Redistributions in binary form must reproduce the above copyright
1009d64da3SSean Eric Fagan  *    notice, this list of conditions and the following disclaimer in the
1109d64da3SSean Eric Fagan  *    documentation and/or other materials provided with the distribution.
1209d64da3SSean Eric Fagan  * 3. All advertising materials mentioning features or use of this software
1309d64da3SSean Eric Fagan  *    must display the following acknowledgement:
1409d64da3SSean Eric Fagan  *	This product includes software developed by Sean Eric Fagan
1509d64da3SSean Eric Fagan  * 4. Neither the name of the author may be used to endorse or promote
1609d64da3SSean Eric Fagan  *    products derived from this software without specific prior written
1709d64da3SSean Eric Fagan  *    permission.
1809d64da3SSean Eric Fagan  *
1909d64da3SSean Eric Fagan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2009d64da3SSean Eric Fagan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2109d64da3SSean Eric Fagan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2209d64da3SSean Eric Fagan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2309d64da3SSean Eric Fagan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2409d64da3SSean Eric Fagan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2509d64da3SSean Eric Fagan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2609d64da3SSean Eric Fagan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2709d64da3SSean Eric Fagan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2809d64da3SSean Eric Fagan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2909d64da3SSean Eric Fagan  * SUCH DAMAGE.
3009d64da3SSean Eric Fagan  */
3109d64da3SSean Eric Fagan 
322b75c8adSJohn Baldwin #include <sys/cdefs.h>
332b75c8adSJohn Baldwin __FBSDID("$FreeBSD$");
343cf51049SPhilippe Charnier 
3509d64da3SSean Eric Fagan /*
36bbeaf6c0SSean Eric Fagan  * This file has routines used to print out system calls and their
37bbeaf6c0SSean Eric Fagan  * arguments.
38bbeaf6c0SSean Eric Fagan  */
39bbeaf6c0SSean Eric Fagan 
407136a1d9SJohn Baldwin #include <sys/capsicum.h>
419ddd1412SDag-Erling Smørgrav #include <sys/types.h>
422b75c8adSJohn Baldwin #include <sys/event.h>
432b75c8adSJohn Baldwin #include <sys/ioccom.h>
44a776866bSBryan Drewery #include <sys/mount.h>
455d2d083cSXin LI #include <sys/ptrace.h>
462b75c8adSJohn Baldwin #include <sys/resource.h>
479ddd1412SDag-Erling Smørgrav #include <sys/socket.h>
482b75c8adSJohn Baldwin #include <sys/stat.h>
499ddd1412SDag-Erling Smørgrav #include <sys/un.h>
5034763d1cSJohn Baldwin #include <sys/wait.h>
512b75c8adSJohn Baldwin #include <machine/sysarch.h>
529ddd1412SDag-Erling Smørgrav #include <netinet/in.h>
539ddd1412SDag-Erling Smørgrav #include <arpa/inet.h>
549ddd1412SDag-Erling Smørgrav 
551175b23fSJohn Baldwin #include <assert.h>
56dec17687SBrian Feldman #include <ctype.h>
573cf51049SPhilippe Charnier #include <err.h>
58894b8f7aSAlfred Perlstein #include <fcntl.h>
59e45a5a0dSDavid Malone #include <poll.h>
609ddd1412SDag-Erling Smørgrav #include <signal.h>
61808d9805SEd Schouten #include <stdbool.h>
62bbeaf6c0SSean Eric Fagan #include <stdio.h>
63bbeaf6c0SSean Eric Fagan #include <stdlib.h>
64bbeaf6c0SSean Eric Fagan #include <string.h>
65d6fb4894SJohn Baldwin #include <sysdecode.h>
66bbeaf6c0SSean Eric Fagan #include <unistd.h>
67081e5c48SPav Lucistnik #include <vis.h>
689ddd1412SDag-Erling Smørgrav 
691f3bbfd8SEd Schouten #include <contrib/cloudabi/cloudabi_types_common.h>
70808d9805SEd Schouten 
71ec0bed25SMatthew N. Dodd #include "truss.h"
721be5d704SMark Murray #include "extern.h"
73bbeaf6c0SSean Eric Fagan #include "syscall.h"
74bbeaf6c0SSean Eric Fagan 
75bbeaf6c0SSean Eric Fagan /*
76081e5c48SPav Lucistnik  * This should probably be in its own file, sorted alphabetically.
77bbeaf6c0SSean Eric Fagan  */
786c61b0f3SBryan Drewery static struct syscall decoded_syscalls[] = {
79f44fc79dSJohn Baldwin 	/* Native ABI */
807ce44f08SJohn Baldwin 	{ .name = "__acl_aclcheck_fd", .ret_type = 1, .nargs = 3,
817ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
827ce44f08SJohn Baldwin 	{ .name = "__acl_aclcheck_file", .ret_type = 1, .nargs = 3,
837ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
847ce44f08SJohn Baldwin 	{ .name = "__acl_aclcheck_link", .ret_type = 1, .nargs = 3,
857ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
867ce44f08SJohn Baldwin 	{ .name = "__acl_delete_fd", .ret_type = 1, .nargs = 2,
877ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 } } },
887ce44f08SJohn Baldwin 	{ .name = "__acl_delete_file", .ret_type = 1, .nargs = 2,
897ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 } } },
907ce44f08SJohn Baldwin 	{ .name = "__acl_delete_link", .ret_type = 1, .nargs = 2,
917ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 } } },
927ce44f08SJohn Baldwin 	{ .name = "__acl_get_fd", .ret_type = 1, .nargs = 3,
937ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
947ce44f08SJohn Baldwin 	{ .name = "__acl_get_file", .ret_type = 1, .nargs = 3,
957ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
967ce44f08SJohn Baldwin 	{ .name = "__acl_get_link", .ret_type = 1, .nargs = 3,
977ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
987ce44f08SJohn Baldwin 	{ .name = "__acl_set_fd", .ret_type = 1, .nargs = 3,
997ce44f08SJohn Baldwin 	  .args = { { Int, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1007ce44f08SJohn Baldwin 	{ .name = "__acl_set_file", .ret_type = 1, .nargs = 3,
1017ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1027ce44f08SJohn Baldwin 	{ .name = "__acl_set_link", .ret_type = 1, .nargs = 3,
1037ce44f08SJohn Baldwin 	  .args = { { Name, 0 }, { Acltype, 1 }, { Ptr, 2 } } },
1047136a1d9SJohn Baldwin 	{ .name = "__cap_rights_get", .ret_type = 1, .nargs = 3,
1057136a1d9SJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 }, { CapRights | OUT, 2 } } },
106f44fc79dSJohn Baldwin 	{ .name = "__getcwd", .ret_type = 1, .nargs = 2,
107f44fc79dSJohn Baldwin 	  .args = { { Name | OUT, 0 }, { Int, 1 } } },
108f44fc79dSJohn Baldwin 	{ .name = "_umtx_op", .ret_type = 1, .nargs = 5,
109f44fc79dSJohn Baldwin 	  .args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 },
110f44fc79dSJohn Baldwin 		    { Ptr, 4 } } },
111f44fc79dSJohn Baldwin 	{ .name = "accept", .ret_type = 1, .nargs = 3,
112f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
113f44fc79dSJohn Baldwin 	{ .name = "access", .ret_type = 1, .nargs = 2,
114f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Accessmode, 1 } } },
115f44fc79dSJohn Baldwin 	{ .name = "bind", .ret_type = 1, .nargs = 3,
11658227c60SMichael Tuexen 	  .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Socklent, 2 } } },
117f44fc79dSJohn Baldwin 	{ .name = "bindat", .ret_type = 1, .nargs = 4,
118f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
1197d897327SJohn Baldwin 		    { Int, 3 } } },
120f44fc79dSJohn Baldwin 	{ .name = "break", .ret_type = 1, .nargs = 1,
121f44fc79dSJohn Baldwin 	  .args = { { Ptr, 0 } } },
122bed418c8SJohn Baldwin 	{ .name = "cap_fcntls_get", .ret_type = 1, .nargs = 2,
123bed418c8SJohn Baldwin 	  .args = { { Int, 0 }, { CapFcntlRights | OUT, 1 } } },
124bed418c8SJohn Baldwin 	{ .name = "cap_fcntls_limit", .ret_type = 1, .nargs = 2,
125bed418c8SJohn Baldwin 	  .args = { { Int, 0 }, { CapFcntlRights, 1 } } },
126ebb2cc40SJohn Baldwin 	{ .name = "cap_getmode", .ret_type = 1, .nargs = 1,
127ebb2cc40SJohn Baldwin 	  .args = { { PUInt | OUT, 0 } } },
1287136a1d9SJohn Baldwin 	{ .name = "cap_rights_limit", .ret_type = 1, .nargs = 2,
1297136a1d9SJohn Baldwin 	  .args = { { Int, 0 }, { CapRights, 1 } } },
130f44fc79dSJohn Baldwin 	{ .name = "chdir", .ret_type = 1, .nargs = 1,
131f44fc79dSJohn Baldwin 	  .args = { { Name, 0 } } },
132f44fc79dSJohn Baldwin 	{ .name = "chflags", .ret_type = 1, .nargs = 2,
13327459358SJohn Baldwin 	  .args = { { Name | IN, 0 }, { FileFlags, 1 } } },
13427459358SJohn Baldwin 	{ .name = "chflagsat", .ret_type = 1, .nargs = 4,
13527459358SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { FileFlags, 2 },
13627459358SJohn Baldwin 		    { Atflags, 3 } } },
137f44fc79dSJohn Baldwin 	{ .name = "chmod", .ret_type = 1, .nargs = 2,
138ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Octal, 1 } } },
139f44fc79dSJohn Baldwin 	{ .name = "chown", .ret_type = 1, .nargs = 3,
140f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
141f44fc79dSJohn Baldwin 	{ .name = "chroot", .ret_type = 1, .nargs = 1,
142f44fc79dSJohn Baldwin 	  .args = { { Name, 0 } } },
143f44fc79dSJohn Baldwin 	{ .name = "clock_gettime", .ret_type = 1, .nargs = 2,
144f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Timespec | OUT, 1 } } },
145ee3b0f6eSDiomidis Spinellis 	{ .name = "close", .ret_type = 1, .nargs = 1,
146ee3b0f6eSDiomidis Spinellis 	  .args = { { Int, 0 } } },
147f44fc79dSJohn Baldwin 	{ .name = "connect", .ret_type = 1, .nargs = 3,
14858227c60SMichael Tuexen 	  .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Socklent, 2 } } },
149f44fc79dSJohn Baldwin 	{ .name = "connectat", .ret_type = 1, .nargs = 4,
150f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
151f44fc79dSJohn Baldwin 		    { Int, 3 } } },
152b60a095bSJohn Baldwin 	{ .name = "dup", .ret_type = 1, .nargs = 1,
153b60a095bSJohn Baldwin 	  .args = { { Int, 0 } } },
154b60a095bSJohn Baldwin 	{ .name = "dup2", .ret_type = 1, .nargs = 2,
155b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 } } },
156f44fc79dSJohn Baldwin 	{ .name = "eaccess", .ret_type = 1, .nargs = 2,
157f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Accessmode, 1 } } },
158f44fc79dSJohn Baldwin 	{ .name = "execve", .ret_type = 1, .nargs = 3,
159f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
160f44fc79dSJohn Baldwin 		    { ExecEnv | IN, 2 } } },
161f44fc79dSJohn Baldwin 	{ .name = "exit", .ret_type = 0, .nargs = 1,
162f44fc79dSJohn Baldwin 	  .args = { { Hex, 0 } } },
163*26606dcaSJohn Baldwin 	{ .name = "extattr_delete_fd", .ret_type = 1, .nargs = 3,
164*26606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
165*26606dcaSJohn Baldwin 	{ .name = "extattr_delete_file", .ret_type = 1, .nargs = 3,
166*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
167*26606dcaSJohn Baldwin 	{ .name = "extattr_delete_link", .ret_type = 1, .nargs = 3,
168*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } },
169*26606dcaSJohn Baldwin 	{ .name = "extattr_get_fd", .ret_type = 1, .nargs = 5,
170*26606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
171*26606dcaSJohn Baldwin 		    { BinString | OUT, 3 }, { Sizet, 4 } } },
172*26606dcaSJohn Baldwin 	{ .name = "extattr_get_file", .ret_type = 1, .nargs = 5,
173*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
174*26606dcaSJohn Baldwin 		    { BinString | OUT, 3 }, { Sizet, 4 } } },
175*26606dcaSJohn Baldwin 	{ .name = "extattr_get_link", .ret_type = 1, .nargs = 5,
176*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
177*26606dcaSJohn Baldwin 		    { BinString | OUT, 3 }, { Sizet, 4 } } },
178*26606dcaSJohn Baldwin 	{ .name = "extattr_list_fd", .ret_type = 1, .nargs = 4,
179*26606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
180*26606dcaSJohn Baldwin 		    { Sizet, 3 } } },
181*26606dcaSJohn Baldwin 	{ .name = "extattr_list_file", .ret_type = 1, .nargs = 4,
182*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
183*26606dcaSJohn Baldwin 		    { Sizet, 3 } } },
184*26606dcaSJohn Baldwin 	{ .name = "extattr_list_link", .ret_type = 1, .nargs = 4,
185*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 },
186*26606dcaSJohn Baldwin 		    { Sizet, 3 } } },
187*26606dcaSJohn Baldwin 	{ .name = "extattr_set_fd", .ret_type = 1, .nargs = 5,
188*26606dcaSJohn Baldwin 	  .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
189*26606dcaSJohn Baldwin 		    { BinString | IN, 3 }, { Sizet, 4 } } },
190*26606dcaSJohn Baldwin 	{ .name = "extattr_set_file", .ret_type = 1, .nargs = 5,
191*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
192*26606dcaSJohn Baldwin 		    { BinString | IN, 3 }, { Sizet, 4 } } },
193*26606dcaSJohn Baldwin 	{ .name = "extattr_set_link", .ret_type = 1, .nargs = 5,
194*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 },
195*26606dcaSJohn Baldwin 		    { BinString | IN, 3 }, { Sizet, 4 } } },
196*26606dcaSJohn Baldwin 	{ .name = "extattrctl", .ret_type = 1, .nargs = 5,
197*26606dcaSJohn Baldwin 	  .args = { { Name, 0 }, { Hex, 1 }, { Name, 2 },
198*26606dcaSJohn Baldwin 		    { Extattrnamespace, 3 }, { Name, 4 } } },
199f44fc79dSJohn Baldwin 	{ .name = "faccessat", .ret_type = 1, .nargs = 4,
200f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Accessmode, 2 },
201f44fc79dSJohn Baldwin 		    { Atflags, 3 } } },
20227459358SJohn Baldwin 	{ .name = "fchflags", .ret_type = 1, .nargs = 2,
20327459358SJohn Baldwin 	  .args = { { Int, 0 }, { FileFlags, 1 } } },
204f44fc79dSJohn Baldwin 	{ .name = "fchmod", .ret_type = 1, .nargs = 2,
205f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Octal, 1 } } },
206f44fc79dSJohn Baldwin 	{ .name = "fchmodat", .ret_type = 1, .nargs = 4,
207f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Atflags, 3 } } },
208f44fc79dSJohn Baldwin 	{ .name = "fchown", .ret_type = 1, .nargs = 3,
209f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
210f44fc79dSJohn Baldwin 	{ .name = "fchownat", .ret_type = 1, .nargs = 5,
211f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Int, 2 }, { Int, 3 },
212f44fc79dSJohn Baldwin 		    { Atflags, 4 } } },
213f44fc79dSJohn Baldwin 	{ .name = "fcntl", .ret_type = 1, .nargs = 3,
214f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } },
215dd92181fSJohn Baldwin 	{ .name = "flock", .ret_type = 1, .nargs = 2,
216dd92181fSJohn Baldwin 	  .args = { { Int, 0 }, { Flockop, 1 } } },
217f44fc79dSJohn Baldwin 	{ .name = "fstat", .ret_type = 1, .nargs = 2,
218f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Stat | OUT, 1 } } },
219f44fc79dSJohn Baldwin 	{ .name = "fstatat", .ret_type = 1, .nargs = 4,
220f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat | OUT, 2 },
221f44fc79dSJohn Baldwin 		    { Atflags, 3 } } },
222f44fc79dSJohn Baldwin 	{ .name = "fstatfs", .ret_type = 1, .nargs = 2,
223f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { StatFs | OUT, 1 } } },
224f44fc79dSJohn Baldwin 	{ .name = "ftruncate", .ret_type = 1, .nargs = 2,
225c05cc0d6SJohn Baldwin 	  .args = { { Int | IN, 0 }, { QuadHex | IN, 1 } } },
226f44fc79dSJohn Baldwin 	{ .name = "futimens", .ret_type = 1, .nargs = 2,
227f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Timespec2 | IN, 1 } } },
228f44fc79dSJohn Baldwin 	{ .name = "futimes", .ret_type = 1, .nargs = 2,
229f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Timeval2 | IN, 1 } } },
230f44fc79dSJohn Baldwin 	{ .name = "futimesat", .ret_type = 1, .nargs = 3,
231f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timeval2 | IN, 2 } } },
232b60a095bSJohn Baldwin 	{ .name = "getdirentries", .ret_type = 1, .nargs = 4,
233b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 },
234b60a095bSJohn Baldwin 		    { PQuadHex | OUT, 3 } } },
235ab43bedcSJohn Baldwin 	{ .name = "getfsstat", .ret_type = 1, .nargs = 3,
236ab43bedcSJohn Baldwin 	  .args = { { Ptr, 0 }, { Long, 1 }, { Getfsstatmode, 2 } } },
237f44fc79dSJohn Baldwin 	{ .name = "getitimer", .ret_type = 1, .nargs = 2,
238f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Itimerval | OUT, 2 } } },
239f44fc79dSJohn Baldwin 	{ .name = "getpeername", .ret_type = 1, .nargs = 3,
240f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
241f44fc79dSJohn Baldwin 	{ .name = "getpgid", .ret_type = 1, .nargs = 1,
242f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
243f44fc79dSJohn Baldwin 	{ .name = "getrlimit", .ret_type = 1, .nargs = 2,
244f44fc79dSJohn Baldwin 	  .args = { { Resource, 0 }, { Rlimit | OUT, 1 } } },
245f44fc79dSJohn Baldwin 	{ .name = "getrusage", .ret_type = 1, .nargs = 2,
246ee8aa41dSJohn Baldwin 	  .args = { { RusageWho, 0 }, { Rusage | OUT, 1 } } },
247f44fc79dSJohn Baldwin 	{ .name = "getsid", .ret_type = 1, .nargs = 1,
248f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
249f44fc79dSJohn Baldwin 	{ .name = "getsockname", .ret_type = 1, .nargs = 3,
250f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
251832af457SMichael Tuexen 	{ .name = "getsockopt", .ret_type = 1, .nargs = 5,
252832af457SMichael Tuexen 	  .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 },
253832af457SMichael Tuexen 		    { Ptr | OUT, 3 }, { Ptr | OUT, 4 } } },
254f44fc79dSJohn Baldwin 	{ .name = "gettimeofday", .ret_type = 1, .nargs = 2,
255f44fc79dSJohn Baldwin 	  .args = { { Timeval | OUT, 0 }, { Ptr, 1 } } },
256f44fc79dSJohn Baldwin 	{ .name = "ioctl", .ret_type = 1, .nargs = 3,
257a776eeafSJohn Baldwin 	  .args = { { Int, 0 }, { Ioctl, 1 }, { Ptr, 2 } } },
258f44fc79dSJohn Baldwin 	{ .name = "kevent", .ret_type = 1, .nargs = 6,
259f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 },
260f44fc79dSJohn Baldwin 		    { Int, 4 }, { Timespec, 5 } } },
261f44fc79dSJohn Baldwin 	{ .name = "kill", .ret_type = 1, .nargs = 2,
262f44fc79dSJohn Baldwin 	  .args = { { Int | IN, 0 }, { Signal | IN, 1 } } },
263f44fc79dSJohn Baldwin 	{ .name = "kldfind", .ret_type = 1, .nargs = 1,
264f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 } } },
265f44fc79dSJohn Baldwin 	{ .name = "kldfirstmod", .ret_type = 1, .nargs = 1,
266f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
267f44fc79dSJohn Baldwin 	{ .name = "kldload", .ret_type = 1, .nargs = 1,
268f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 } } },
269f44fc79dSJohn Baldwin 	{ .name = "kldnext", .ret_type = 1, .nargs = 1,
270f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
271f44fc79dSJohn Baldwin 	{ .name = "kldstat", .ret_type = 1, .nargs = 2,
272f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Ptr, 1 } } },
27394e854c5SJohn Baldwin 	{ .name = "kldsym", .ret_type = 1, .nargs = 3,
27494e854c5SJohn Baldwin 	  .args = { { Int, 0 }, { Kldsymcmd, 1 }, { Ptr, 2 } } },
275f44fc79dSJohn Baldwin 	{ .name = "kldunload", .ret_type = 1, .nargs = 1,
276f44fc79dSJohn Baldwin 	  .args = { { Int, 0 } } },
27794e854c5SJohn Baldwin 	{ .name = "kldunloadf", .ret_type = 1, .nargs = 2,
27894e854c5SJohn Baldwin 	  .args = { { Int, 0 }, { Kldunloadflags, 1 } } },
279f44fc79dSJohn Baldwin 	{ .name = "kse_release", .ret_type = 0, .nargs = 1,
280f44fc79dSJohn Baldwin 	  .args = { { Timespec, 0 } } },
281f44fc79dSJohn Baldwin 	{ .name = "lchflags", .ret_type = 1, .nargs = 2,
28227459358SJohn Baldwin 	  .args = { { Name | IN, 0 }, { FileFlags, 1 } } },
283f44fc79dSJohn Baldwin 	{ .name = "lchmod", .ret_type = 1, .nargs = 2,
284f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 } } },
285f44fc79dSJohn Baldwin 	{ .name = "lchown", .ret_type = 1, .nargs = 3,
286f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
2872b75c8adSJohn Baldwin 	{ .name = "link", .ret_type = 1, .nargs = 2,
288ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Name, 1 } } },
2892b75c8adSJohn Baldwin 	{ .name = "linkat", .ret_type = 1, .nargs = 5,
2907d897327SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 },
2917d897327SJohn Baldwin 		    { Atflags, 4 } } },
292e8d2c81dSMichael Tuexen 	{ .name = "listen", .ret_type = 1, .nargs = 2,
293e8d2c81dSMichael Tuexen 	  .args = { { Int, 0 }, { Int, 1 } } },
294f44fc79dSJohn Baldwin  	{ .name = "lseek", .ret_type = 2, .nargs = 3,
295c05cc0d6SJohn Baldwin 	  .args = { { Int, 0 }, { QuadHex, 1 }, { Whence, 2 } } },
296f44fc79dSJohn Baldwin 	{ .name = "lstat", .ret_type = 1, .nargs = 2,
297f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
298f44fc79dSJohn Baldwin 	{ .name = "lutimes", .ret_type = 1, .nargs = 2,
299f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
30098fdbeecSJohn Baldwin 	{ .name = "madvise", .ret_type = 1, .nargs = 3,
30198fdbeecSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Madvice, 2 } } },
302f44fc79dSJohn Baldwin 	{ .name = "mkdir", .ret_type = 1, .nargs = 2,
303f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 } } },
304f44fc79dSJohn Baldwin 	{ .name = "mkdirat", .ret_type = 1, .nargs = 3,
305f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
3062b75c8adSJohn Baldwin 	{ .name = "mkfifo", .ret_type = 1, .nargs = 2,
307e82ce59cSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 } } },
3082b75c8adSJohn Baldwin 	{ .name = "mkfifoat", .ret_type = 1, .nargs = 3,
3097d897327SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
3102b75c8adSJohn Baldwin 	{ .name = "mknod", .ret_type = 1, .nargs = 3,
311e82ce59cSJohn Baldwin 	  .args = { { Name, 0 }, { Octal, 1 }, { Int, 2 } } },
3122b75c8adSJohn Baldwin 	{ .name = "mknodat", .ret_type = 1, .nargs = 4,
3137d897327SJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Int, 3 } } },
314f44fc79dSJohn Baldwin 	{ .name = "mmap", .ret_type = 1, .nargs = 6,
315e261fb2aSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 }, { Mmapflags, 3 },
316c05cc0d6SJohn Baldwin 		    { Int, 4 }, { QuadHex, 5 } } },
317f44fc79dSJohn Baldwin 	{ .name = "modfind", .ret_type = 1, .nargs = 1,
318f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 } } },
3192b75c8adSJohn Baldwin 	{ .name = "mount", .ret_type = 1, .nargs = 4,
320ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Name, 1 }, { Int, 2 }, { Ptr, 3 } } },
321f44fc79dSJohn Baldwin 	{ .name = "mprotect", .ret_type = 1, .nargs = 3,
322e261fb2aSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 } } },
323f44fc79dSJohn Baldwin 	{ .name = "munmap", .ret_type = 1, .nargs = 2,
324e261fb2aSJohn Baldwin 	  .args = { { Ptr, 0 }, { Sizet, 1 } } },
325f44fc79dSJohn Baldwin 	{ .name = "nanosleep", .ret_type = 1, .nargs = 1,
326f44fc79dSJohn Baldwin 	  .args = { { Timespec, 0 } } },
327f44fc79dSJohn Baldwin 	{ .name = "open", .ret_type = 1, .nargs = 3,
328f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
329f44fc79dSJohn Baldwin 	{ .name = "openat", .ret_type = 1, .nargs = 4,
330f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 },
331f44fc79dSJohn Baldwin 		    { Octal, 3 } } },
332f44fc79dSJohn Baldwin 	{ .name = "pathconf", .ret_type = 1, .nargs = 2,
333f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Pathconf, 1 } } },
334f44fc79dSJohn Baldwin 	{ .name = "pipe", .ret_type = 1, .nargs = 1,
335f44fc79dSJohn Baldwin 	  .args = { { PipeFds | OUT, 0 } } },
336f44fc79dSJohn Baldwin 	{ .name = "pipe2", .ret_type = 1, .nargs = 2,
3379289f547SJohn Baldwin 	  .args = { { Ptr, 0 }, { Pipe2, 1 } } },
338f44fc79dSJohn Baldwin 	{ .name = "poll", .ret_type = 1, .nargs = 3,
339f44fc79dSJohn Baldwin 	  .args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } },
340d2a97485SJohn Baldwin 	{ .name = "posix_fadvise", .ret_type = 1, .nargs = 4,
341d2a97485SJohn Baldwin 	  .args = { { Int, 0 }, { QuadHex, 1 }, { QuadHex, 2 },
342d2a97485SJohn Baldwin 		    { Fadvice, 3 } } },
343f44fc79dSJohn Baldwin 	{ .name = "posix_openpt", .ret_type = 1, .nargs = 1,
344f44fc79dSJohn Baldwin 	  .args = { { Open, 0 } } },
345b60a095bSJohn Baldwin 	{ .name = "pread", .ret_type = 1, .nargs = 4,
346b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 },
347b60a095bSJohn Baldwin 		    { QuadHex, 3 } } },
348f44fc79dSJohn Baldwin 	{ .name = "procctl", .ret_type = 1, .nargs = 4,
349c05cc0d6SJohn Baldwin 	  .args = { { Idtype, 0 }, { Quad, 1 }, { Procctl, 2 }, { Ptr, 3 } } },
350b60a095bSJohn Baldwin 	{ .name = "pwrite", .ret_type = 1, .nargs = 4,
351b60a095bSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 },
352b60a095bSJohn Baldwin 		    { QuadHex, 3 } } },
353f44fc79dSJohn Baldwin 	{ .name = "read", .ret_type = 1, .nargs = 3,
354e261fb2aSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 } } },
355f44fc79dSJohn Baldwin 	{ .name = "readlink", .ret_type = 1, .nargs = 3,
356e261fb2aSJohn Baldwin 	  .args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Sizet, 2 } } },
357f44fc79dSJohn Baldwin 	{ .name = "readlinkat", .ret_type = 1, .nargs = 4,
358f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 },
359e261fb2aSJohn Baldwin 		    { Sizet, 3 } } },
360ee3b0f6eSDiomidis Spinellis 	{ .name = "recvfrom", .ret_type = 1, .nargs = 6,
3618b429b65SMichael Tuexen 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 },
3628b429b65SMichael Tuexen 	            { Msgflags, 3 }, { Sockaddr | OUT, 4 },
3638b429b65SMichael Tuexen 	            { Ptr | OUT, 5 } } },
364fca08fe6SMichael Tuexen 	{ .name = "recvmsg", .ret_type = 1, .nargs = 3,
365fca08fe6SMichael Tuexen 	  .args = { { Int, 0 }, { Ptr, 1 }, { Msgflags, 2 } } },
366f44fc79dSJohn Baldwin 	{ .name = "rename", .ret_type = 1, .nargs = 2,
367f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Name, 1 } } },
368f44fc79dSJohn Baldwin 	{ .name = "renameat", .ret_type = 1, .nargs = 4,
369f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } },
370f44fc79dSJohn Baldwin 	{ .name = "rfork", .ret_type = 1, .nargs = 1,
371f44fc79dSJohn Baldwin 	  .args = { { Rforkflags, 0 } } },
372cca89ee3SBryan Drewery 	{ .name = "rmdir", .ret_type = 1, .nargs = 1,
373cca89ee3SBryan Drewery 	  .args = { { Name, 0 } } },
374c0b72375SMichael Tuexen 	{ .name = "sctp_generic_recvmsg", .ret_type = 1, .nargs = 7,
375c0b72375SMichael Tuexen 	  .args = { { Int, 0 }, { Ptr | IN, 1 }, { Int, 2 },
376c0b72375SMichael Tuexen 	            { Sockaddr | OUT, 3 }, { Ptr | OUT, 4 }, { Ptr | OUT, 5 },
377c0b72375SMichael Tuexen 	            { Ptr | OUT, 6 } } },
378c0b72375SMichael Tuexen 	{ .name = "sctp_generic_sendmsg", .ret_type = 1, .nargs = 7,
379c0b72375SMichael Tuexen 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 },
380c0b72375SMichael Tuexen 	            { Sockaddr | IN, 3 }, { Socklent, 4 }, { Ptr | IN, 5 },
381c0b72375SMichael Tuexen 	            { Msgflags, 6 } } },
382ee3b0f6eSDiomidis Spinellis 	{ .name = "select", .ret_type = 1, .nargs = 5,
3830a46af44SJohn Baldwin 	  .args = { { Int, 0 }, { Fd_set, 1 }, { Fd_set, 2 }, { Fd_set, 3 },
3840a46af44SJohn Baldwin 		    { Timeval, 4 } } },
385fca08fe6SMichael Tuexen 	{ .name = "sendmsg", .ret_type = 1, .nargs = 3,
386fca08fe6SMichael Tuexen 	  .args = { { Int, 0 }, { Ptr, 1 }, { Msgflags, 2 } } },
387f44fc79dSJohn Baldwin 	{ .name = "sendto", .ret_type = 1, .nargs = 6,
3888b429b65SMichael Tuexen 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 },
3898b429b65SMichael Tuexen 	            { Msgflags, 3 }, { Sockaddr | IN, 4 },
3908b429b65SMichael Tuexen 	            { Socklent | IN, 5 } } },
391ee3b0f6eSDiomidis Spinellis 	{ .name = "setitimer", .ret_type = 1, .nargs = 3,
392ee3b0f6eSDiomidis Spinellis 	  .args = { { Int, 0 }, { Itimerval, 1 }, { Itimerval | OUT, 2 } } },
393f44fc79dSJohn Baldwin 	{ .name = "setrlimit", .ret_type = 1, .nargs = 2,
394f44fc79dSJohn Baldwin 	  .args = { { Resource, 0 }, { Rlimit | IN, 1 } } },
395832af457SMichael Tuexen 	{ .name = "setsockopt", .ret_type = 1, .nargs = 5,
396832af457SMichael Tuexen 	  .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 },
397832af457SMichael Tuexen 		    { Ptr | IN, 3 }, { Socklent, 4 } } },
398f44fc79dSJohn Baldwin 	{ .name = "shutdown", .ret_type = 1, .nargs = 2,
399f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Shutdown, 1 } } },
400f44fc79dSJohn Baldwin 	{ .name = "sigaction", .ret_type = 1, .nargs = 3,
401f44fc79dSJohn Baldwin 	  .args = { { Signal, 0 }, { Sigaction | IN, 1 },
402f44fc79dSJohn Baldwin 		    { Sigaction | OUT, 2 } } },
4032b75c8adSJohn Baldwin 	{ .name = "sigpending", .ret_type = 1, .nargs = 1,
404b289a8d7SJohn Baldwin 	  .args = { { Sigset | OUT, 0 } } },
4052b75c8adSJohn Baldwin 	{ .name = "sigprocmask", .ret_type = 1, .nargs = 3,
406ee3b0f6eSDiomidis Spinellis 	  .args = { { Sigprocmask, 0 }, { Sigset, 1 }, { Sigset | OUT, 2 } } },
4072b75c8adSJohn Baldwin 	{ .name = "sigqueue", .ret_type = 1, .nargs = 3,
408b289a8d7SJohn Baldwin 	  .args = { { Int, 0 }, { Signal, 1 }, { LongHex, 2 } } },
4092b75c8adSJohn Baldwin 	{ .name = "sigreturn", .ret_type = 1, .nargs = 1,
410b289a8d7SJohn Baldwin 	  .args = { { Ptr, 0 } } },
4112b75c8adSJohn Baldwin 	{ .name = "sigsuspend", .ret_type = 1, .nargs = 1,
412b289a8d7SJohn Baldwin 	  .args = { { Sigset | IN, 0 } } },
413b289a8d7SJohn Baldwin 	{ .name = "sigtimedwait", .ret_type = 1, .nargs = 3,
414b289a8d7SJohn Baldwin 	  .args = { { Sigset | IN, 0 }, { Ptr, 1 }, { Timespec | IN, 2 } } },
415b289a8d7SJohn Baldwin 	{ .name = "sigwait", .ret_type = 1, .nargs = 2,
416b289a8d7SJohn Baldwin 	  .args = { { Sigset | IN, 0 }, { Ptr, 1 } } },
417b289a8d7SJohn Baldwin 	{ .name = "sigwaitinfo", .ret_type = 1, .nargs = 2,
418b289a8d7SJohn Baldwin 	  .args = { { Sigset | IN, 0 }, { Ptr, 1 } } },
419ee3b0f6eSDiomidis Spinellis 	{ .name = "socket", .ret_type = 1, .nargs = 3,
420ecac235bSMichael Tuexen 	  .args = { { Sockdomain, 0 }, { Socktype, 1 }, { Sockprotocol, 2 } } },
421f44fc79dSJohn Baldwin 	{ .name = "stat", .ret_type = 1, .nargs = 2,
422f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
423f44fc79dSJohn Baldwin 	{ .name = "statfs", .ret_type = 1, .nargs = 2,
424f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } },
425ee3b0f6eSDiomidis Spinellis 	{ .name = "symlink", .ret_type = 1, .nargs = 2,
426ee3b0f6eSDiomidis Spinellis 	  .args = { { Name, 0 }, { Name, 1 } } },
4277d897327SJohn Baldwin 	{ .name = "symlinkat", .ret_type = 1, .nargs = 3,
4287d897327SJohn Baldwin 	  .args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } },
429f44fc79dSJohn Baldwin 	{ .name = "sysarch", .ret_type = 1, .nargs = 2,
430f44fc79dSJohn Baldwin 	  .args = { { Sysarch, 0 }, { Ptr, 1 } } },
431f44fc79dSJohn Baldwin 	{ .name = "thr_kill", .ret_type = 1, .nargs = 2,
432f44fc79dSJohn Baldwin 	  .args = { { Long, 0 }, { Signal, 1 } } },
433f44fc79dSJohn Baldwin 	{ .name = "thr_self", .ret_type = 1, .nargs = 1,
434f44fc79dSJohn Baldwin 	  .args = { { Ptr, 0 } } },
435f44fc79dSJohn Baldwin 	{ .name = "truncate", .ret_type = 1, .nargs = 2,
436c05cc0d6SJohn Baldwin 	  .args = { { Name | IN, 0 }, { QuadHex | IN, 1 } } },
437f44fc79dSJohn Baldwin #if 0
438f44fc79dSJohn Baldwin 	/* Does not exist */
439f44fc79dSJohn Baldwin 	{ .name = "umount", .ret_type = 1, .nargs = 2,
440f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 2 } } },
441f44fc79dSJohn Baldwin #endif
442f44fc79dSJohn Baldwin 	{ .name = "unlink", .ret_type = 1, .nargs = 1,
443f44fc79dSJohn Baldwin 	  .args = { { Name, 0 } } },
444f44fc79dSJohn Baldwin 	{ .name = "unlinkat", .ret_type = 1, .nargs = 3,
445f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } },
446f44fc79dSJohn Baldwin 	{ .name = "unmount", .ret_type = 1, .nargs = 2,
447f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Int, 1 } } },
448f44fc79dSJohn Baldwin 	{ .name = "utimensat", .ret_type = 1, .nargs = 4,
449f44fc79dSJohn Baldwin 	  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 },
450f44fc79dSJohn Baldwin 		    { Atflags, 3 } } },
451f44fc79dSJohn Baldwin 	{ .name = "utimes", .ret_type = 1, .nargs = 2,
452f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
453195aef99SBryan Drewery 	{ .name = "utrace", .ret_type = 1, .nargs = 1,
454195aef99SBryan Drewery 	  .args = { { Utrace, 0 } } },
45534763d1cSJohn Baldwin 	{ .name = "wait4", .ret_type = 1, .nargs = 4,
45634763d1cSJohn Baldwin 	  .args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 },
45734763d1cSJohn Baldwin 		    { Rusage | OUT, 3 } } },
45834763d1cSJohn Baldwin 	{ .name = "wait6", .ret_type = 1, .nargs = 6,
459c05cc0d6SJohn Baldwin 	  .args = { { Idtype, 0 }, { Quad, 1 }, { ExitStatus | OUT, 2 },
460c05cc0d6SJohn Baldwin 		    { Waitoptions, 3 }, { Rusage | OUT, 4 }, { Ptr, 5 } } },
461f44fc79dSJohn Baldwin 	{ .name = "write", .ret_type = 1, .nargs = 3,
462e261fb2aSJohn Baldwin 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 } } },
463f44fc79dSJohn Baldwin 
464f44fc79dSJohn Baldwin 	/* Linux ABI */
465f44fc79dSJohn Baldwin 	{ .name = "linux_access", .ret_type = 1, .nargs = 2,
466f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Accessmode, 1 } } },
467f44fc79dSJohn Baldwin 	{ .name = "linux_execve", .ret_type = 1, .nargs = 3,
468f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
469f44fc79dSJohn Baldwin 		    { ExecEnv | IN, 2 } } },
470f44fc79dSJohn Baldwin 	{ .name = "linux_lseek", .ret_type = 2, .nargs = 3,
471f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } },
472f44fc79dSJohn Baldwin 	{ .name = "linux_mkdir", .ret_type = 1, .nargs = 2,
473f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Int, 1 } } },
474f44fc79dSJohn Baldwin 	{ .name = "linux_newfstat", .ret_type = 1, .nargs = 2,
475f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { Ptr | OUT, 1 } } },
476f44fc79dSJohn Baldwin 	{ .name = "linux_newstat", .ret_type = 1, .nargs = 2,
477f44fc79dSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
478f44fc79dSJohn Baldwin 	{ .name = "linux_open", .ret_type = 1, .nargs = 3,
479f44fc79dSJohn Baldwin 	  .args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } },
480f44fc79dSJohn Baldwin 	{ .name = "linux_readlink", .ret_type = 1, .nargs = 3,
481e261fb2aSJohn Baldwin 	  .args = { { Name, 0 }, { Name | OUT, 1 }, { Sizet, 2 } } },
482f44fc79dSJohn Baldwin 	{ .name = "linux_socketcall", .ret_type = 1, .nargs = 2,
483f44fc79dSJohn Baldwin 	  .args = { { Int, 0 }, { LinuxSockArgs, 1 } } },
48464f4703bSJohn Baldwin 	{ .name = "linux_stat64", .ret_type = 1, .nargs = 2,
48564f4703bSJohn Baldwin 	  .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
486f44fc79dSJohn Baldwin 
487808d9805SEd Schouten 	/* CloudABI system calls. */
488808d9805SEd Schouten 	{ .name = "cloudabi_sys_clock_res_get", .ret_type = 1, .nargs = 1,
489808d9805SEd Schouten 	  .args = { { CloudABIClockID, 0 } } },
490808d9805SEd Schouten 	{ .name = "cloudabi_sys_clock_time_get", .ret_type = 1, .nargs = 2,
491808d9805SEd Schouten 	  .args = { { CloudABIClockID, 0 }, { CloudABITimestamp, 1 } } },
492808d9805SEd Schouten 	{ .name = "cloudabi_sys_condvar_signal", .ret_type = 1, .nargs = 3,
493808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { CloudABIMFlags, 1 }, { UInt, 2 } } },
494808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_close", .ret_type = 1, .nargs = 1,
495808d9805SEd Schouten 	  .args = { { Int, 0 } } },
496808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_create1", .ret_type = 1, .nargs = 1,
497808d9805SEd Schouten 	  .args = { { CloudABIFileType, 0 } } },
498808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_create2", .ret_type = 1, .nargs = 2,
499808d9805SEd Schouten 	  .args = { { CloudABIFileType, 0 }, { PipeFds | OUT, 0 } } },
500808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_datasync", .ret_type = 1, .nargs = 1,
501808d9805SEd Schouten 	  .args = { { Int, 0 } } },
502808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_dup", .ret_type = 1, .nargs = 1,
503808d9805SEd Schouten 	  .args = { { Int, 0 } } },
504808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_replace", .ret_type = 1, .nargs = 2,
505808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 } } },
506808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_seek", .ret_type = 1, .nargs = 3,
507808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { CloudABIWhence, 2 } } },
508808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_stat_get", .ret_type = 1, .nargs = 2,
509808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFDStat | OUT, 1 } } },
510808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_stat_put", .ret_type = 1, .nargs = 3,
511808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFDStat | IN, 1 },
512808d9805SEd Schouten 	            { ClouduABIFDSFlags, 2 } } },
513808d9805SEd Schouten 	{ .name = "cloudabi_sys_fd_sync", .ret_type = 1, .nargs = 1,
514808d9805SEd Schouten 	  .args = { { Int, 0 } } },
515808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_advise", .ret_type = 1, .nargs = 4,
516808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { Int, 2 },
517808d9805SEd Schouten 	            { CloudABIAdvice, 3 } } },
518808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_allocate", .ret_type = 1, .nargs = 3,
519808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
520808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_create", .ret_type = 1, .nargs = 3,
521808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
522808d9805SEd Schouten 	            { CloudABIFileType, 3 } } },
523808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_link", .ret_type = 1, .nargs = 4,
524808d9805SEd Schouten 	  .args = { { CloudABILookup, 0 }, { BinString | IN, 1 },
525808d9805SEd Schouten 	            { Int, 3 }, { BinString | IN, 4 } } },
526808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_open", .ret_type = 1, .nargs = 4,
527808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
528808d9805SEd Schouten 	            { CloudABIOFlags, 3 }, { CloudABIFDStat | IN, 4 } } },
529808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_readdir", .ret_type = 1, .nargs = 4,
530808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 },
531808d9805SEd Schouten 	            { Int, 3 } } },
532808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_readlink", .ret_type = 1, .nargs = 4,
533808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
534808d9805SEd Schouten 	            { BinString | OUT, 3 }, { Int, 4 } } },
535808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_rename", .ret_type = 1, .nargs = 4,
536808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
537808d9805SEd Schouten 	            { Int, 3 }, { BinString | IN, 4 } } },
538808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_fget", .ret_type = 1, .nargs = 2,
539808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFileStat | OUT, 1 } } },
540808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_fput", .ret_type = 1, .nargs = 3,
541808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABIFileStat | IN, 1 },
542808d9805SEd Schouten 	            { CloudABIFSFlags, 2 } } },
543808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_get", .ret_type = 1, .nargs = 3,
544808d9805SEd Schouten 	  .args = { { CloudABILookup, 0 }, { BinString | IN, 1 },
545808d9805SEd Schouten 	            { CloudABIFileStat | OUT, 3 } } },
546808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_stat_put", .ret_type = 1, .nargs = 4,
547808d9805SEd Schouten 	  .args = { { CloudABILookup, 0 }, { BinString | IN, 1 },
548808d9805SEd Schouten 	            { CloudABIFileStat | IN, 3 }, { CloudABIFSFlags, 4 } } },
549808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_symlink", .ret_type = 1, .nargs = 3,
550808d9805SEd Schouten 	  .args = { { BinString | IN, 0 },
551808d9805SEd Schouten 	            { Int, 2 }, { BinString | IN, 3 } } },
552808d9805SEd Schouten 	{ .name = "cloudabi_sys_file_unlink", .ret_type = 1, .nargs = 3,
553808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 },
554808d9805SEd Schouten 	            { CloudABIULFlags, 3 } } },
555808d9805SEd Schouten 	{ .name = "cloudabi_sys_lock_unlock", .ret_type = 1, .nargs = 2,
556808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } },
557808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_advise", .ret_type = 1, .nargs = 3,
558808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIAdvice, 2 } } },
559808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_lock", .ret_type = 1, .nargs = 2,
560808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 } } },
561808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_map", .ret_type = 1, .nargs = 6,
562808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 },
563808d9805SEd Schouten 	            { CloudABIMFlags, 3 }, { Int, 4 }, { Int, 5 } } },
564808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_protect", .ret_type = 1, .nargs = 3,
565808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 } } },
566808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_sync", .ret_type = 1, .nargs = 3,
567808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMSFlags, 2 } } },
568808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_unlock", .ret_type = 1, .nargs = 2,
569808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 } } },
570808d9805SEd Schouten 	{ .name = "cloudabi_sys_mem_unmap", .ret_type = 1, .nargs = 2,
571808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { Int, 1 } } },
572808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_exec", .ret_type = 1, .nargs = 5,
573808d9805SEd Schouten 	  .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 },
574808d9805SEd Schouten 	            { IntArray, 3 }, { Int, 4 } } },
575808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_exit", .ret_type = 1, .nargs = 1,
576808d9805SEd Schouten 	  .args = { { Int, 0 } } },
577808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_fork", .ret_type = 1, .nargs = 0 },
578808d9805SEd Schouten 	{ .name = "cloudabi_sys_proc_raise", .ret_type = 1, .nargs = 1,
579808d9805SEd Schouten 	  .args = { { CloudABISignal, 0 } } },
580808d9805SEd Schouten 	{ .name = "cloudabi_sys_random_get", .ret_type = 1, .nargs = 2,
581808d9805SEd Schouten 	  .args = { { BinString | OUT, 0 }, { Int, 1 } } },
582808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_accept", .ret_type = 1, .nargs = 2,
583808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABISockStat | OUT, 1 } } },
584808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_bind", .ret_type = 1, .nargs = 3,
585808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { BinString | IN, 2 } } },
586808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_connect", .ret_type = 1, .nargs = 3,
587808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 }, { BinString | IN, 2 } } },
588808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_listen", .ret_type = 1, .nargs = 2,
589808d9805SEd Schouten 	  .args = { { Int, 0 }, { Int, 1 } } },
590808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_shutdown", .ret_type = 1, .nargs = 2,
591808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABISDFlags, 1 } } },
592808d9805SEd Schouten 	{ .name = "cloudabi_sys_sock_stat_get", .ret_type = 1, .nargs = 3,
593808d9805SEd Schouten 	  .args = { { Int, 0 }, { CloudABISockStat | OUT, 1 },
594808d9805SEd Schouten 	            { CloudABISSFlags, 2 } } },
595808d9805SEd Schouten 	{ .name = "cloudabi_sys_thread_exit", .ret_type = 1, .nargs = 2,
596808d9805SEd Schouten 	  .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } },
597808d9805SEd Schouten 	{ .name = "cloudabi_sys_thread_yield", .ret_type = 1, .nargs = 0 },
598808d9805SEd Schouten 
599ee3b0f6eSDiomidis Spinellis 	{ .name = 0 },
600bbeaf6c0SSean Eric Fagan };
6016c61b0f3SBryan Drewery static STAILQ_HEAD(, syscall) syscalls;
602bbeaf6c0SSean Eric Fagan 
603081e5c48SPav Lucistnik /* Xlat idea taken from strace */
604081e5c48SPav Lucistnik struct xlat {
605081e5c48SPav Lucistnik 	int val;
6065d2d083cSXin LI 	const char *str;
607081e5c48SPav Lucistnik };
608081e5c48SPav Lucistnik 
609081e5c48SPav Lucistnik #define	X(a)	{ a, #a },
610081e5c48SPav Lucistnik #define	XEND	{ 0, NULL }
611081e5c48SPav Lucistnik 
612081e5c48SPav Lucistnik static struct xlat kevent_filters[] = {
613081e5c48SPav Lucistnik 	X(EVFILT_READ) X(EVFILT_WRITE) X(EVFILT_AIO) X(EVFILT_VNODE)
614081e5c48SPav Lucistnik 	X(EVFILT_PROC) X(EVFILT_SIGNAL) X(EVFILT_TIMER)
615d98d7ba0SJohn Baldwin 	X(EVFILT_PROCDESC) X(EVFILT_FS) X(EVFILT_LIO) X(EVFILT_USER)
616d98d7ba0SJohn Baldwin 	X(EVFILT_SENDFILE) XEND
617081e5c48SPav Lucistnik };
618081e5c48SPav Lucistnik 
619081e5c48SPav Lucistnik static struct xlat kevent_flags[] = {
620081e5c48SPav Lucistnik 	X(EV_ADD) X(EV_DELETE) X(EV_ENABLE) X(EV_DISABLE) X(EV_ONESHOT)
621d98d7ba0SJohn Baldwin 	X(EV_CLEAR) X(EV_RECEIPT) X(EV_DISPATCH) X(EV_FORCEONESHOT)
622d98d7ba0SJohn Baldwin 	X(EV_DROP) X(EV_FLAG1) X(EV_ERROR) X(EV_EOF) XEND
623081e5c48SPav Lucistnik };
624081e5c48SPav Lucistnik 
625c915ff03SJohn Baldwin static struct xlat kevent_user_ffctrl[] = {
626c915ff03SJohn Baldwin 	X(NOTE_FFNOP) X(NOTE_FFAND) X(NOTE_FFOR) X(NOTE_FFCOPY)
627c915ff03SJohn Baldwin 	XEND
628c915ff03SJohn Baldwin };
629c915ff03SJohn Baldwin 
630c915ff03SJohn Baldwin static struct xlat kevent_rdwr_fflags[] = {
631c915ff03SJohn Baldwin 	X(NOTE_LOWAT) X(NOTE_FILE_POLL) XEND
632c915ff03SJohn Baldwin };
633c915ff03SJohn Baldwin 
634c915ff03SJohn Baldwin static struct xlat kevent_vnode_fflags[] = {
635c915ff03SJohn Baldwin 	X(NOTE_DELETE) X(NOTE_WRITE) X(NOTE_EXTEND) X(NOTE_ATTRIB)
636c915ff03SJohn Baldwin 	X(NOTE_LINK) X(NOTE_RENAME) X(NOTE_REVOKE) XEND
637c915ff03SJohn Baldwin };
638c915ff03SJohn Baldwin 
639c915ff03SJohn Baldwin static struct xlat kevent_proc_fflags[] = {
640c915ff03SJohn Baldwin 	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR)
641c915ff03SJohn Baldwin 	X(NOTE_CHILD) XEND
642c915ff03SJohn Baldwin };
643c915ff03SJohn Baldwin 
644c915ff03SJohn Baldwin static struct xlat kevent_timer_fflags[] = {
645c915ff03SJohn Baldwin 	X(NOTE_SECONDS) X(NOTE_MSECONDS) X(NOTE_USECONDS) X(NOTE_NSECONDS)
646c915ff03SJohn Baldwin 	XEND
647c915ff03SJohn Baldwin };
648c915ff03SJohn Baldwin 
649a02c83afSEd Schouten static struct xlat poll_flags[] = {
650081e5c48SPav Lucistnik 	X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR)
651081e5c48SPav Lucistnik 	X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND)
652081e5c48SPav Lucistnik 	X(POLLWRBAND) X(POLLINIGNEOF) XEND
653081e5c48SPav Lucistnik };
654081e5c48SPav Lucistnik 
655081e5c48SPav Lucistnik static struct xlat sigaction_flags[] = {
656081e5c48SPav Lucistnik 	X(SA_ONSTACK) X(SA_RESTART) X(SA_RESETHAND) X(SA_NOCLDSTOP)
657081e5c48SPav Lucistnik 	X(SA_NODEFER) X(SA_NOCLDWAIT) X(SA_SIGINFO) XEND
658081e5c48SPav Lucistnik };
659081e5c48SPav Lucistnik 
660081e5c48SPav Lucistnik static struct xlat pathconf_arg[] = {
661081e5c48SPav Lucistnik 	X(_PC_LINK_MAX)  X(_PC_MAX_CANON)  X(_PC_MAX_INPUT)
662081e5c48SPav Lucistnik 	X(_PC_NAME_MAX) X(_PC_PATH_MAX) X(_PC_PIPE_BUF)
663081e5c48SPav Lucistnik 	X(_PC_CHOWN_RESTRICTED) X(_PC_NO_TRUNC) X(_PC_VDISABLE)
664081e5c48SPav Lucistnik 	X(_PC_ASYNC_IO) X(_PC_PRIO_IO) X(_PC_SYNC_IO)
665081e5c48SPav Lucistnik 	X(_PC_ALLOC_SIZE_MIN) X(_PC_FILESIZEBITS)
666081e5c48SPav Lucistnik 	X(_PC_REC_INCR_XFER_SIZE) X(_PC_REC_MAX_XFER_SIZE)
667081e5c48SPav Lucistnik 	X(_PC_REC_MIN_XFER_SIZE) X(_PC_REC_XFER_ALIGN)
668081e5c48SPav Lucistnik 	X(_PC_SYMLINK_MAX) X(_PC_ACL_EXTENDED) X(_PC_ACL_PATH_MAX)
669081e5c48SPav Lucistnik 	X(_PC_CAP_PRESENT) X(_PC_INF_PRESENT) X(_PC_MAC_PRESENT)
670d98d7ba0SJohn Baldwin 	X(_PC_ACL_NFS4) X(_PC_MIN_HOLE_SIZE) XEND
671081e5c48SPav Lucistnik };
672081e5c48SPav Lucistnik 
6737d897327SJohn Baldwin static struct xlat at_flags[] = {
6747d897327SJohn Baldwin 	X(AT_EACCESS) X(AT_SYMLINK_NOFOLLOW) X(AT_SYMLINK_FOLLOW)
6757d897327SJohn Baldwin 	X(AT_REMOVEDIR) XEND
6767d897327SJohn Baldwin };
6777d897327SJohn Baldwin 
678b289a8d7SJohn Baldwin static struct xlat sysarch_ops[] = {
679b289a8d7SJohn Baldwin #if defined(__i386__) || defined(__amd64__)
680b289a8d7SJohn Baldwin 	X(I386_GET_LDT) X(I386_SET_LDT) X(I386_GET_IOPERM) X(I386_SET_IOPERM)
681b289a8d7SJohn Baldwin 	X(I386_VM86) X(I386_GET_FSBASE) X(I386_SET_FSBASE) X(I386_GET_GSBASE)
682b289a8d7SJohn Baldwin 	X(I386_SET_GSBASE) X(I386_GET_XFPUSTATE) X(AMD64_GET_FSBASE)
683b289a8d7SJohn Baldwin 	X(AMD64_SET_FSBASE) X(AMD64_GET_GSBASE) X(AMD64_SET_GSBASE)
684b289a8d7SJohn Baldwin 	X(AMD64_GET_XFPUSTATE)
685b289a8d7SJohn Baldwin #endif
686b289a8d7SJohn Baldwin 	XEND
687b289a8d7SJohn Baldwin };
688fb7eabb0SJohn Baldwin 
689fb7eabb0SJohn Baldwin static struct xlat linux_socketcall_ops[] = {
690fb7eabb0SJohn Baldwin 	X(LINUX_SOCKET) X(LINUX_BIND) X(LINUX_CONNECT) X(LINUX_LISTEN)
691fb7eabb0SJohn Baldwin 	X(LINUX_ACCEPT) X(LINUX_GETSOCKNAME) X(LINUX_GETPEERNAME)
692fb7eabb0SJohn Baldwin 	X(LINUX_SOCKETPAIR) X(LINUX_SEND) X(LINUX_RECV) X(LINUX_SENDTO)
693fb7eabb0SJohn Baldwin 	X(LINUX_RECVFROM) X(LINUX_SHUTDOWN) X(LINUX_SETSOCKOPT)
694fb7eabb0SJohn Baldwin 	X(LINUX_GETSOCKOPT) X(LINUX_SENDMSG) X(LINUX_RECVMSG)
695fb7eabb0SJohn Baldwin 	XEND
696fb7eabb0SJohn Baldwin };
697fb7eabb0SJohn Baldwin 
698081e5c48SPav Lucistnik #undef X
699808d9805SEd Schouten #define	X(a)	{ CLOUDABI_##a, #a },
700808d9805SEd Schouten 
701808d9805SEd Schouten static struct xlat cloudabi_advice[] = {
702808d9805SEd Schouten 	X(ADVICE_DONTNEED) X(ADVICE_NOREUSE) X(ADVICE_NORMAL)
703808d9805SEd Schouten 	X(ADVICE_RANDOM) X(ADVICE_SEQUENTIAL) X(ADVICE_WILLNEED)
704808d9805SEd Schouten 	XEND
705808d9805SEd Schouten };
706808d9805SEd Schouten 
707808d9805SEd Schouten static struct xlat cloudabi_clockid[] = {
708808d9805SEd Schouten 	X(CLOCK_MONOTONIC) X(CLOCK_PROCESS_CPUTIME_ID)
709808d9805SEd Schouten 	X(CLOCK_REALTIME) X(CLOCK_THREAD_CPUTIME_ID)
710808d9805SEd Schouten 	XEND
711808d9805SEd Schouten };
712808d9805SEd Schouten 
713808d9805SEd Schouten static struct xlat cloudabi_errno[] = {
714808d9805SEd Schouten 	X(E2BIG) X(EACCES) X(EADDRINUSE) X(EADDRNOTAVAIL)
715808d9805SEd Schouten 	X(EAFNOSUPPORT) X(EAGAIN) X(EALREADY) X(EBADF) X(EBADMSG)
716808d9805SEd Schouten 	X(EBUSY) X(ECANCELED) X(ECHILD) X(ECONNABORTED) X(ECONNREFUSED)
717808d9805SEd Schouten 	X(ECONNRESET) X(EDEADLK) X(EDESTADDRREQ) X(EDOM) X(EDQUOT)
718808d9805SEd Schouten 	X(EEXIST) X(EFAULT) X(EFBIG) X(EHOSTUNREACH) X(EIDRM) X(EILSEQ)
719808d9805SEd Schouten 	X(EINPROGRESS) X(EINTR) X(EINVAL) X(EIO) X(EISCONN) X(EISDIR)
720808d9805SEd Schouten 	X(ELOOP) X(EMFILE) X(EMLINK) X(EMSGSIZE) X(EMULTIHOP)
721808d9805SEd Schouten 	X(ENAMETOOLONG) X(ENETDOWN) X(ENETRESET) X(ENETUNREACH)
722808d9805SEd Schouten 	X(ENFILE) X(ENOBUFS) X(ENODEV) X(ENOENT) X(ENOEXEC) X(ENOLCK)
723808d9805SEd Schouten 	X(ENOLINK) X(ENOMEM) X(ENOMSG) X(ENOPROTOOPT) X(ENOSPC)
724808d9805SEd Schouten 	X(ENOSYS) X(ENOTCONN) X(ENOTDIR) X(ENOTEMPTY) X(ENOTRECOVERABLE)
725808d9805SEd Schouten 	X(ENOTSOCK) X(ENOTSUP) X(ENOTTY) X(ENXIO) X(EOVERFLOW)
726808d9805SEd Schouten 	X(EOWNERDEAD) X(EPERM) X(EPIPE) X(EPROTO) X(EPROTONOSUPPORT)
727808d9805SEd Schouten 	X(EPROTOTYPE) X(ERANGE) X(EROFS) X(ESPIPE) X(ESRCH) X(ESTALE)
728808d9805SEd Schouten 	X(ETIMEDOUT) X(ETXTBSY) X(EXDEV) X(ENOTCAPABLE)
729808d9805SEd Schouten 	XEND
730808d9805SEd Schouten };
731808d9805SEd Schouten 
732808d9805SEd Schouten static struct xlat cloudabi_fdflags[] = {
733808d9805SEd Schouten 	X(FDFLAG_APPEND) X(FDFLAG_DSYNC) X(FDFLAG_NONBLOCK)
734808d9805SEd Schouten 	X(FDFLAG_RSYNC) X(FDFLAG_SYNC)
735808d9805SEd Schouten 	XEND
736808d9805SEd Schouten };
737808d9805SEd Schouten 
738808d9805SEd Schouten static struct xlat cloudabi_fdsflags[] = {
739808d9805SEd Schouten 	X(FDSTAT_FLAGS) X(FDSTAT_RIGHTS)
740808d9805SEd Schouten 	XEND
741808d9805SEd Schouten };
742808d9805SEd Schouten 
743808d9805SEd Schouten static struct xlat cloudabi_filetype[] = {
744808d9805SEd Schouten 	X(FILETYPE_UNKNOWN) X(FILETYPE_BLOCK_DEVICE)
745808d9805SEd Schouten 	X(FILETYPE_CHARACTER_DEVICE) X(FILETYPE_DIRECTORY)
746808d9805SEd Schouten 	X(FILETYPE_FIFO) X(FILETYPE_POLL) X(FILETYPE_PROCESS)
747808d9805SEd Schouten 	X(FILETYPE_REGULAR_FILE) X(FILETYPE_SHARED_MEMORY)
748808d9805SEd Schouten 	X(FILETYPE_SOCKET_DGRAM) X(FILETYPE_SOCKET_SEQPACKET)
749808d9805SEd Schouten 	X(FILETYPE_SOCKET_STREAM) X(FILETYPE_SYMBOLIC_LINK)
750808d9805SEd Schouten 	XEND
751808d9805SEd Schouten };
752808d9805SEd Schouten 
753808d9805SEd Schouten static struct xlat cloudabi_fsflags[] = {
754808d9805SEd Schouten 	X(FILESTAT_ATIM) X(FILESTAT_ATIM_NOW) X(FILESTAT_MTIM)
755808d9805SEd Schouten 	X(FILESTAT_MTIM_NOW) X(FILESTAT_SIZE)
756808d9805SEd Schouten 	XEND
757808d9805SEd Schouten };
758808d9805SEd Schouten 
759808d9805SEd Schouten static struct xlat cloudabi_mflags[] = {
760808d9805SEd Schouten 	X(MAP_ANON) X(MAP_FIXED) X(MAP_PRIVATE) X(MAP_SHARED)
761808d9805SEd Schouten 	XEND
762808d9805SEd Schouten };
763808d9805SEd Schouten 
764808d9805SEd Schouten static struct xlat cloudabi_mprot[] = {
765808d9805SEd Schouten 	X(PROT_EXEC) X(PROT_WRITE) X(PROT_READ)
766808d9805SEd Schouten 	XEND
767808d9805SEd Schouten };
768808d9805SEd Schouten 
769808d9805SEd Schouten static struct xlat cloudabi_msflags[] = {
770808d9805SEd Schouten 	X(MS_ASYNC) X(MS_INVALIDATE) X(MS_SYNC)
771808d9805SEd Schouten 	XEND
772808d9805SEd Schouten };
773808d9805SEd Schouten 
774808d9805SEd Schouten static struct xlat cloudabi_oflags[] = {
775808d9805SEd Schouten 	X(O_CREAT) X(O_DIRECTORY) X(O_EXCL) X(O_TRUNC)
776808d9805SEd Schouten 	XEND
777808d9805SEd Schouten };
778808d9805SEd Schouten 
779808d9805SEd Schouten static struct xlat cloudabi_sa_family[] = {
780808d9805SEd Schouten 	X(AF_UNSPEC) X(AF_INET) X(AF_INET6) X(AF_UNIX)
781808d9805SEd Schouten 	XEND
782808d9805SEd Schouten };
783808d9805SEd Schouten 
784808d9805SEd Schouten static struct xlat cloudabi_sdflags[] = {
785808d9805SEd Schouten 	X(SHUT_RD) X(SHUT_WR)
786808d9805SEd Schouten 	XEND
787808d9805SEd Schouten };
788808d9805SEd Schouten 
789808d9805SEd Schouten static struct xlat cloudabi_signal[] = {
790808d9805SEd Schouten 	X(SIGABRT) X(SIGALRM) X(SIGBUS) X(SIGCHLD) X(SIGCONT) X(SIGFPE)
791808d9805SEd Schouten 	X(SIGHUP) X(SIGILL) X(SIGINT) X(SIGKILL) X(SIGPIPE) X(SIGQUIT)
792808d9805SEd Schouten 	X(SIGSEGV) X(SIGSTOP) X(SIGSYS) X(SIGTERM) X(SIGTRAP) X(SIGTSTP)
793808d9805SEd Schouten 	X(SIGTTIN) X(SIGTTOU) X(SIGURG) X(SIGUSR1) X(SIGUSR2)
794808d9805SEd Schouten 	X(SIGVTALRM) X(SIGXCPU) X(SIGXFSZ)
795808d9805SEd Schouten 	XEND
796808d9805SEd Schouten };
797808d9805SEd Schouten 
798808d9805SEd Schouten static struct xlat cloudabi_ssflags[] = {
799808d9805SEd Schouten 	X(SOCKSTAT_CLEAR_ERROR)
800808d9805SEd Schouten 	XEND
801808d9805SEd Schouten };
802808d9805SEd Schouten 
803808d9805SEd Schouten static struct xlat cloudabi_ssstate[] = {
8041f3bbfd8SEd Schouten 	X(SOCKSTATE_ACCEPTCONN)
805808d9805SEd Schouten 	XEND
806808d9805SEd Schouten };
807808d9805SEd Schouten 
808808d9805SEd Schouten static struct xlat cloudabi_ulflags[] = {
809808d9805SEd Schouten 	X(UNLINK_REMOVEDIR)
810808d9805SEd Schouten 	XEND
811808d9805SEd Schouten };
812808d9805SEd Schouten 
813808d9805SEd Schouten static struct xlat cloudabi_whence[] = {
814808d9805SEd Schouten 	X(WHENCE_CUR) X(WHENCE_END) X(WHENCE_SET)
815808d9805SEd Schouten 	XEND
816808d9805SEd Schouten };
817808d9805SEd Schouten 
818808d9805SEd Schouten #undef X
819081e5c48SPav Lucistnik #undef XEND
820081e5c48SPav Lucistnik 
821d8984f48SDag-Erling Smørgrav /*
822d8984f48SDag-Erling Smørgrav  * Searches an xlat array for a value, and returns it if found.  Otherwise
823d8984f48SDag-Erling Smørgrav  * return a string representation.
824d8984f48SDag-Erling Smørgrav  */
825d8984f48SDag-Erling Smørgrav static const char *
826d8984f48SDag-Erling Smørgrav lookup(struct xlat *xlat, int val, int base)
827081e5c48SPav Lucistnik {
828081e5c48SPav Lucistnik 	static char tmp[16];
829d8984f48SDag-Erling Smørgrav 
830081e5c48SPav Lucistnik 	for (; xlat->str != NULL; xlat++)
831081e5c48SPav Lucistnik 		if (xlat->val == val)
832d8984f48SDag-Erling Smørgrav 			return (xlat->str);
833081e5c48SPav Lucistnik 	switch (base) {
834081e5c48SPav Lucistnik 		case 8:
835081e5c48SPav Lucistnik 			sprintf(tmp, "0%o", val);
836081e5c48SPav Lucistnik 			break;
837081e5c48SPav Lucistnik 		case 16:
838081e5c48SPav Lucistnik 			sprintf(tmp, "0x%x", val);
839081e5c48SPav Lucistnik 			break;
840081e5c48SPav Lucistnik 		case 10:
841081e5c48SPav Lucistnik 			sprintf(tmp, "%u", val);
842081e5c48SPav Lucistnik 			break;
843081e5c48SPav Lucistnik 		default:
844081e5c48SPav Lucistnik 			errx(1,"Unknown lookup base");
845081e5c48SPav Lucistnik 			break;
846081e5c48SPav Lucistnik 	}
847d8984f48SDag-Erling Smørgrav 	return (tmp);
848081e5c48SPav Lucistnik }
849081e5c48SPav Lucistnik 
8505d2d083cSXin LI static const char *
8515d2d083cSXin LI xlookup(struct xlat *xlat, int val)
852081e5c48SPav Lucistnik {
853d8984f48SDag-Erling Smørgrav 
854d8984f48SDag-Erling Smørgrav 	return (lookup(xlat, val, 16));
855081e5c48SPav Lucistnik }
856081e5c48SPav Lucistnik 
8574e3da534SJohn Baldwin /*
8584e3da534SJohn Baldwin  * Searches an xlat array containing bitfield values.  Remaining bits
8594e3da534SJohn Baldwin  * set after removing the known ones are printed at the end:
8604e3da534SJohn Baldwin  * IN|0x400.
8614e3da534SJohn Baldwin  */
862d8984f48SDag-Erling Smørgrav static char *
863d8984f48SDag-Erling Smørgrav xlookup_bits(struct xlat *xlat, int val)
864081e5c48SPav Lucistnik {
86594355cfdSAndrey Zonov 	int len, rem;
866081e5c48SPav Lucistnik 	static char str[512];
867081e5c48SPav Lucistnik 
86894355cfdSAndrey Zonov 	len = 0;
86994355cfdSAndrey Zonov 	rem = val;
870d8984f48SDag-Erling Smørgrav 	for (; xlat->str != NULL; xlat++) {
871d8984f48SDag-Erling Smørgrav 		if ((xlat->val & rem) == xlat->val) {
8724e3da534SJohn Baldwin 			/*
8734e3da534SJohn Baldwin 			 * Don't print the "all-bits-zero" string unless all
8744e3da534SJohn Baldwin 			 * bits are really zero.
8754e3da534SJohn Baldwin 			 */
876081e5c48SPav Lucistnik 			if (xlat->val == 0 && val != 0)
877081e5c48SPav Lucistnik 				continue;
878081e5c48SPav Lucistnik 			len += sprintf(str + len, "%s|", xlat->str);
879081e5c48SPav Lucistnik 			rem &= ~(xlat->val);
880081e5c48SPav Lucistnik 		}
881081e5c48SPav Lucistnik 	}
8824e3da534SJohn Baldwin 
8834e3da534SJohn Baldwin 	/*
8844e3da534SJohn Baldwin 	 * If we have leftover bits or didn't match anything, print
8854e3da534SJohn Baldwin 	 * the remainder.
8864e3da534SJohn Baldwin 	 */
887081e5c48SPav Lucistnik 	if (rem || len == 0)
888081e5c48SPav Lucistnik 		len += sprintf(str + len, "0x%x", rem);
889081e5c48SPav Lucistnik 	if (len && str[len - 1] == '|')
890081e5c48SPav Lucistnik 		len--;
891081e5c48SPav Lucistnik 	str[len] = 0;
892d8984f48SDag-Erling Smørgrav 	return (str);
893081e5c48SPav Lucistnik }
894081e5c48SPav Lucistnik 
8959289f547SJohn Baldwin static void
8969289f547SJohn Baldwin print_integer_arg(const char *(*decoder)(int), FILE *fp, int value)
8979289f547SJohn Baldwin {
8989289f547SJohn Baldwin 	const char *str;
8999289f547SJohn Baldwin 
9009289f547SJohn Baldwin 	str = decoder(value);
9019289f547SJohn Baldwin 	if (str != NULL)
9029289f547SJohn Baldwin 		fputs(str, fp);
9039289f547SJohn Baldwin 	else
9049289f547SJohn Baldwin 		fprintf(fp, "%d", value);
9059289f547SJohn Baldwin }
9069289f547SJohn Baldwin 
9079289f547SJohn Baldwin static void
9089289f547SJohn Baldwin print_mask_arg(bool (*decoder)(FILE *, int, int *), FILE *fp, int value)
9099289f547SJohn Baldwin {
9109289f547SJohn Baldwin 	int rem;
9119289f547SJohn Baldwin 
9129289f547SJohn Baldwin 	if (!decoder(fp, value, &rem))
9139289f547SJohn Baldwin 		fprintf(fp, "0x%x", rem);
9149289f547SJohn Baldwin 	else if (rem != 0)
9159289f547SJohn Baldwin 		fprintf(fp, "|0x%x", rem);
9169289f547SJohn Baldwin }
9179289f547SJohn Baldwin 
918bed418c8SJohn Baldwin static void
919bed418c8SJohn Baldwin print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *), FILE *fp,
920bed418c8SJohn Baldwin     uint32_t value)
921bed418c8SJohn Baldwin {
922bed418c8SJohn Baldwin 	uint32_t rem;
923bed418c8SJohn Baldwin 
924bed418c8SJohn Baldwin 	if (!decoder(fp, value, &rem))
925bed418c8SJohn Baldwin 		fprintf(fp, "0x%x", rem);
926bed418c8SJohn Baldwin 	else if (rem != 0)
927bed418c8SJohn Baldwin 		fprintf(fp, "|0x%x", rem);
928bed418c8SJohn Baldwin }
929bed418c8SJohn Baldwin 
930c05cc0d6SJohn Baldwin #ifndef __LP64__
931c05cc0d6SJohn Baldwin /*
932c05cc0d6SJohn Baldwin  * Add argument padding to subsequent system calls afater a Quad
933c05cc0d6SJohn Baldwin  * syscall arguments as needed.  This used to be done by hand in the
934c05cc0d6SJohn Baldwin  * decoded_syscalls table which was ugly and error prone.  It is
935c05cc0d6SJohn Baldwin  * simpler to do the fixup of offsets at initalization time than when
936c05cc0d6SJohn Baldwin  * decoding arguments.
937c05cc0d6SJohn Baldwin  */
938c05cc0d6SJohn Baldwin static void
939c05cc0d6SJohn Baldwin quad_fixup(struct syscall *sc)
940c05cc0d6SJohn Baldwin {
941c05cc0d6SJohn Baldwin 	int offset, prev;
942c05cc0d6SJohn Baldwin 	u_int i;
943c05cc0d6SJohn Baldwin 
944c05cc0d6SJohn Baldwin 	offset = 0;
945c05cc0d6SJohn Baldwin 	prev = -1;
946c05cc0d6SJohn Baldwin 	for (i = 0; i < sc->nargs; i++) {
947c05cc0d6SJohn Baldwin 		/* This arg type is a dummy that doesn't use offset. */
948c05cc0d6SJohn Baldwin 		if ((sc->args[i].type & ARG_MASK) == PipeFds)
949c05cc0d6SJohn Baldwin 			continue;
950c05cc0d6SJohn Baldwin 
951c05cc0d6SJohn Baldwin 		assert(prev < sc->args[i].offset);
952c05cc0d6SJohn Baldwin 		prev = sc->args[i].offset;
953c05cc0d6SJohn Baldwin 		sc->args[i].offset += offset;
954c05cc0d6SJohn Baldwin 		switch (sc->args[i].type & ARG_MASK) {
955c05cc0d6SJohn Baldwin 		case Quad:
956c05cc0d6SJohn Baldwin 		case QuadHex:
957c05cc0d6SJohn Baldwin #ifdef __powerpc__
958c05cc0d6SJohn Baldwin 			/*
959c05cc0d6SJohn Baldwin 			 * 64-bit arguments on 32-bit powerpc must be
960c05cc0d6SJohn Baldwin 			 * 64-bit aligned.  If the current offset is
961c05cc0d6SJohn Baldwin 			 * not aligned, the calling convention inserts
962c05cc0d6SJohn Baldwin 			 * a 32-bit pad argument that should be skipped.
963c05cc0d6SJohn Baldwin 			 */
964c05cc0d6SJohn Baldwin 			if (sc->args[i].offset % 2 == 1) {
965c05cc0d6SJohn Baldwin 				sc->args[i].offset++;
966c05cc0d6SJohn Baldwin 				offset++;
967c05cc0d6SJohn Baldwin 			}
968c05cc0d6SJohn Baldwin #endif
969c05cc0d6SJohn Baldwin 			offset++;
970c05cc0d6SJohn Baldwin 		default:
971c05cc0d6SJohn Baldwin 			break;
972c05cc0d6SJohn Baldwin 		}
973c05cc0d6SJohn Baldwin 	}
974c05cc0d6SJohn Baldwin }
975c05cc0d6SJohn Baldwin #endif
976c05cc0d6SJohn Baldwin 
9776c61b0f3SBryan Drewery void
9786c61b0f3SBryan Drewery init_syscalls(void)
9796c61b0f3SBryan Drewery {
9806c61b0f3SBryan Drewery 	struct syscall *sc;
9816c61b0f3SBryan Drewery 
9826c61b0f3SBryan Drewery 	STAILQ_INIT(&syscalls);
983c05cc0d6SJohn Baldwin 	for (sc = decoded_syscalls; sc->name != NULL; sc++) {
984c05cc0d6SJohn Baldwin #ifndef __LP64__
985c05cc0d6SJohn Baldwin 		quad_fixup(sc);
986c05cc0d6SJohn Baldwin #endif
9876c61b0f3SBryan Drewery 		STAILQ_INSERT_HEAD(&syscalls, sc, entries);
9886c61b0f3SBryan Drewery 	}
989c05cc0d6SJohn Baldwin }
9901175b23fSJohn Baldwin 
9911175b23fSJohn Baldwin static struct syscall *
9921175b23fSJohn Baldwin find_syscall(struct procabi *abi, u_int number)
9931175b23fSJohn Baldwin {
9941175b23fSJohn Baldwin 	struct extra_syscall *es;
9951175b23fSJohn Baldwin 
9961175b23fSJohn Baldwin 	if (number < nitems(abi->syscalls))
9971175b23fSJohn Baldwin 		return (abi->syscalls[number]);
9981175b23fSJohn Baldwin 	STAILQ_FOREACH(es, &abi->extra_syscalls, entries) {
9991175b23fSJohn Baldwin 		if (es->number == number)
10001175b23fSJohn Baldwin 			return (es->sc);
10011175b23fSJohn Baldwin 	}
10021175b23fSJohn Baldwin 	return (NULL);
10031175b23fSJohn Baldwin }
10041175b23fSJohn Baldwin 
10051175b23fSJohn Baldwin static void
10061175b23fSJohn Baldwin add_syscall(struct procabi *abi, u_int number, struct syscall *sc)
10071175b23fSJohn Baldwin {
10081175b23fSJohn Baldwin 	struct extra_syscall *es;
10091175b23fSJohn Baldwin 
10101175b23fSJohn Baldwin 	if (number < nitems(abi->syscalls)) {
10111175b23fSJohn Baldwin 		assert(abi->syscalls[number] == NULL);
10121175b23fSJohn Baldwin 		abi->syscalls[number] = sc;
10131175b23fSJohn Baldwin 	} else {
10141175b23fSJohn Baldwin 		es = malloc(sizeof(*es));
10151175b23fSJohn Baldwin 		es->sc = sc;
10161175b23fSJohn Baldwin 		es->number = number;
10171175b23fSJohn Baldwin 		STAILQ_INSERT_TAIL(&abi->extra_syscalls, es, entries);
10181175b23fSJohn Baldwin 	}
10191175b23fSJohn Baldwin }
10201175b23fSJohn Baldwin 
1021bbeaf6c0SSean Eric Fagan /*
1022bbeaf6c0SSean Eric Fagan  * If/when the list gets big, it might be desirable to do it
1023bbeaf6c0SSean Eric Fagan  * as a hash table or binary search.
1024bbeaf6c0SSean Eric Fagan  */
1025bbeaf6c0SSean Eric Fagan struct syscall *
10261175b23fSJohn Baldwin get_syscall(struct threadinfo *t, u_int number, u_int nargs)
1027d8984f48SDag-Erling Smørgrav {
102894355cfdSAndrey Zonov 	struct syscall *sc;
10291175b23fSJohn Baldwin 	const char *name;
10301175b23fSJohn Baldwin 	char *new_name;
10311175b23fSJohn Baldwin 	u_int i;
1032bbeaf6c0SSean Eric Fagan 
10331175b23fSJohn Baldwin 	sc = find_syscall(t->proc->abi, number);
10341175b23fSJohn Baldwin 	if (sc != NULL)
1035d8984f48SDag-Erling Smørgrav 		return (sc);
10366c61b0f3SBryan Drewery 
10371175b23fSJohn Baldwin 	name = sysdecode_syscallname(t->proc->abi->abi, number);
10381175b23fSJohn Baldwin 	if (name == NULL) {
10391175b23fSJohn Baldwin 		asprintf(&new_name, "#%d", number);
10401175b23fSJohn Baldwin 		name = new_name;
10411175b23fSJohn Baldwin 	} else
10421175b23fSJohn Baldwin 		new_name = NULL;
10431175b23fSJohn Baldwin 	STAILQ_FOREACH(sc, &syscalls, entries) {
10441175b23fSJohn Baldwin 		if (strcmp(name, sc->name) == 0) {
10451175b23fSJohn Baldwin 			add_syscall(t->proc->abi, number, sc);
10461175b23fSJohn Baldwin 			free(new_name);
10471175b23fSJohn Baldwin 			return (sc);
10481175b23fSJohn Baldwin 		}
10491175b23fSJohn Baldwin 	}
10501175b23fSJohn Baldwin 
10516c61b0f3SBryan Drewery 	/* It is unknown.  Add it into the list. */
10526c61b0f3SBryan Drewery #if DEBUG
10536c61b0f3SBryan Drewery 	fprintf(stderr, "unknown syscall %s -- setting args to %d\n", name,
10546c61b0f3SBryan Drewery 	    nargs);
10556c61b0f3SBryan Drewery #endif
10566c61b0f3SBryan Drewery 
10576c61b0f3SBryan Drewery 	sc = calloc(1, sizeof(struct syscall));
10581175b23fSJohn Baldwin 	sc->name = name;
10591175b23fSJohn Baldwin 	if (new_name != NULL)
10601175b23fSJohn Baldwin 		sc->unknown = true;
10616c61b0f3SBryan Drewery 	sc->ret_type = 1;
10626c61b0f3SBryan Drewery 	sc->nargs = nargs;
10636c61b0f3SBryan Drewery 	for (i = 0; i < nargs; i++) {
10646c61b0f3SBryan Drewery 		sc->args[i].offset = i;
10656c61b0f3SBryan Drewery 		/* Treat all unknown arguments as LongHex. */
10666c61b0f3SBryan Drewery 		sc->args[i].type = LongHex;
1067bbeaf6c0SSean Eric Fagan 	}
10686c61b0f3SBryan Drewery 	STAILQ_INSERT_HEAD(&syscalls, sc, entries);
10691175b23fSJohn Baldwin 	add_syscall(t->proc->abi, number, sc);
10706c61b0f3SBryan Drewery 
10716c61b0f3SBryan Drewery 	return (sc);
1072bbeaf6c0SSean Eric Fagan }
1073bbeaf6c0SSean Eric Fagan 
1074bbeaf6c0SSean Eric Fagan /*
10759ddd1412SDag-Erling Smørgrav  * Copy a fixed amount of bytes from the process.
10769ddd1412SDag-Erling Smørgrav  */
10771be5d704SMark Murray static int
1078be305c9cSAndrey Zonov get_struct(pid_t pid, void *offset, void *buf, int len)
1079d8984f48SDag-Erling Smørgrav {
10805d2d083cSXin LI 	struct ptrace_io_desc iorequest;
10819ddd1412SDag-Erling Smørgrav 
10825d2d083cSXin LI 	iorequest.piod_op = PIOD_READ_D;
10835d2d083cSXin LI 	iorequest.piod_offs = offset;
10845d2d083cSXin LI 	iorequest.piod_addr = buf;
10855d2d083cSXin LI 	iorequest.piod_len = len;
10865d2d083cSXin LI 	if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0)
1087d8984f48SDag-Erling Smørgrav 		return (-1);
1088d8984f48SDag-Erling Smørgrav 	return (0);
10899ddd1412SDag-Erling Smørgrav }
10909ddd1412SDag-Erling Smørgrav 
10915d2d083cSXin LI #define	MAXSIZE		4096
1092abb3f965SJohn Baldwin 
10939ddd1412SDag-Erling Smørgrav /*
1094bbeaf6c0SSean Eric Fagan  * Copy a string from the process.  Note that it is
1095bbeaf6c0SSean Eric Fagan  * expected to be a C string, but if max is set, it will
1096bbeaf6c0SSean Eric Fagan  * only get that much.
1097bbeaf6c0SSean Eric Fagan  */
10985d2d083cSXin LI static char *
1099abb3f965SJohn Baldwin get_string(pid_t pid, void *addr, int max)
1100d8984f48SDag-Erling Smørgrav {
11015d2d083cSXin LI 	struct ptrace_io_desc iorequest;
1102abb3f965SJohn Baldwin 	char *buf, *nbuf;
1103abb3f965SJohn Baldwin 	size_t offset, size, totalsize;
1104bbeaf6c0SSean Eric Fagan 
1105abb3f965SJohn Baldwin 	offset = 0;
1106abb3f965SJohn Baldwin 	if (max)
1107abb3f965SJohn Baldwin 		size = max + 1;
1108abb3f965SJohn Baldwin 	else {
1109abb3f965SJohn Baldwin 		/* Read up to the end of the current page. */
1110abb3f965SJohn Baldwin 		size = PAGE_SIZE - ((uintptr_t)addr % PAGE_SIZE);
1111abb3f965SJohn Baldwin 		if (size > MAXSIZE)
1112abb3f965SJohn Baldwin 			size = MAXSIZE;
1113abb3f965SJohn Baldwin 	}
1114abb3f965SJohn Baldwin 	totalsize = size;
11155d2d083cSXin LI 	buf = malloc(totalsize);
11165d2d083cSXin LI 	if (buf == NULL)
1117d8984f48SDag-Erling Smørgrav 		return (NULL);
11185d2d083cSXin LI 	for (;;) {
11195d2d083cSXin LI 		iorequest.piod_op = PIOD_READ_D;
1120abb3f965SJohn Baldwin 		iorequest.piod_offs = (char *)addr + offset;
1121abb3f965SJohn Baldwin 		iorequest.piod_addr = buf + offset;
11225d2d083cSXin LI 		iorequest.piod_len = size;
11235d2d083cSXin LI 		if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) {
11245d2d083cSXin LI 			free(buf);
1125d8984f48SDag-Erling Smørgrav 			return (NULL);
1126bbeaf6c0SSean Eric Fagan 		}
1127abb3f965SJohn Baldwin 		if (memchr(buf + offset, '\0', size) != NULL)
1128abb3f965SJohn Baldwin 			return (buf);
1129abb3f965SJohn Baldwin 		offset += size;
1130abb3f965SJohn Baldwin 		if (totalsize < MAXSIZE && max == 0) {
1131abb3f965SJohn Baldwin 			size = MAXSIZE - totalsize;
1132abb3f965SJohn Baldwin 			if (size > PAGE_SIZE)
1133abb3f965SJohn Baldwin 				size = PAGE_SIZE;
1134abb3f965SJohn Baldwin 			nbuf = realloc(buf, totalsize + size);
1135abb3f965SJohn Baldwin 			if (nbuf == NULL) {
1136abb3f965SJohn Baldwin 				buf[totalsize - 1] = '\0';
11374e92419dSMarcel Moolenaar 				return (buf);
1138bbeaf6c0SSean Eric Fagan 			}
1139abb3f965SJohn Baldwin 			buf = nbuf;
1140abb3f965SJohn Baldwin 			totalsize += size;
1141d8984f48SDag-Erling Smørgrav 		} else {
1142cdfc719cSJaakko Heinonen 			buf[totalsize - 1] = '\0';
1143d8984f48SDag-Erling Smørgrav 			return (buf);
11445d2d083cSXin LI 		}
11455d2d083cSXin LI 	}
11465d2d083cSXin LI }
1147bbeaf6c0SSean Eric Fagan 
11489289f547SJohn Baldwin static const char *
114934763d1cSJohn Baldwin strsig2(int sig)
115034763d1cSJohn Baldwin {
11519289f547SJohn Baldwin 	static char tmp[32];
11529289f547SJohn Baldwin 	const char *signame;
115334763d1cSJohn Baldwin 
11549289f547SJohn Baldwin 	signame = sysdecode_signal(sig);
11559289f547SJohn Baldwin 	if (signame == NULL) {
1156f083f689SJohn Baldwin 		snprintf(tmp, sizeof(tmp), "%d", sig);
11579289f547SJohn Baldwin 		signame = tmp;
1158f083f689SJohn Baldwin 	}
11599289f547SJohn Baldwin 	return (signame);
116034763d1cSJohn Baldwin }
1161bbeaf6c0SSean Eric Fagan 
1162c915ff03SJohn Baldwin static void
1163c915ff03SJohn Baldwin print_kevent(FILE *fp, struct kevent *ke, int input)
1164c915ff03SJohn Baldwin {
1165c915ff03SJohn Baldwin 
1166c915ff03SJohn Baldwin 	switch (ke->filter) {
1167c915ff03SJohn Baldwin 	case EVFILT_READ:
1168c915ff03SJohn Baldwin 	case EVFILT_WRITE:
1169c915ff03SJohn Baldwin 	case EVFILT_VNODE:
1170c915ff03SJohn Baldwin 	case EVFILT_PROC:
1171c915ff03SJohn Baldwin 	case EVFILT_TIMER:
1172c915ff03SJohn Baldwin 	case EVFILT_PROCDESC:
1173c915ff03SJohn Baldwin 		fprintf(fp, "%ju", (uintmax_t)ke->ident);
1174c915ff03SJohn Baldwin 		break;
1175c915ff03SJohn Baldwin 	case EVFILT_SIGNAL:
1176c915ff03SJohn Baldwin 		fputs(strsig2(ke->ident), fp);
1177c915ff03SJohn Baldwin 		break;
1178c915ff03SJohn Baldwin 	default:
1179c915ff03SJohn Baldwin 		fprintf(fp, "%p", (void *)ke->ident);
1180c915ff03SJohn Baldwin 	}
1181c915ff03SJohn Baldwin 	fprintf(fp, ",%s,%s,", xlookup(kevent_filters, ke->filter),
1182c915ff03SJohn Baldwin 	    xlookup_bits(kevent_flags, ke->flags));
1183c915ff03SJohn Baldwin 	switch (ke->filter) {
1184c915ff03SJohn Baldwin 	case EVFILT_READ:
1185c915ff03SJohn Baldwin 	case EVFILT_WRITE:
1186c915ff03SJohn Baldwin 		fputs(xlookup_bits(kevent_rdwr_fflags, ke->fflags), fp);
1187c915ff03SJohn Baldwin 		break;
1188c915ff03SJohn Baldwin 	case EVFILT_VNODE:
1189c915ff03SJohn Baldwin 		fputs(xlookup_bits(kevent_vnode_fflags, ke->fflags), fp);
1190c915ff03SJohn Baldwin 		break;
1191c915ff03SJohn Baldwin 	case EVFILT_PROC:
1192c915ff03SJohn Baldwin 	case EVFILT_PROCDESC:
1193c915ff03SJohn Baldwin 		fputs(xlookup_bits(kevent_proc_fflags, ke->fflags), fp);
1194c915ff03SJohn Baldwin 		break;
1195c915ff03SJohn Baldwin 	case EVFILT_TIMER:
1196c915ff03SJohn Baldwin 		fputs(xlookup_bits(kevent_timer_fflags, ke->fflags), fp);
1197c915ff03SJohn Baldwin 		break;
1198c915ff03SJohn Baldwin 	case EVFILT_USER: {
1199c915ff03SJohn Baldwin 		int ctrl, data;
1200c915ff03SJohn Baldwin 
1201c915ff03SJohn Baldwin 		ctrl = ke->fflags & NOTE_FFCTRLMASK;
1202c915ff03SJohn Baldwin 		data = ke->fflags & NOTE_FFLAGSMASK;
1203c915ff03SJohn Baldwin 		if (input) {
1204c915ff03SJohn Baldwin 			fputs(xlookup(kevent_user_ffctrl, ctrl), fp);
1205c915ff03SJohn Baldwin 			if (ke->fflags & NOTE_TRIGGER)
1206c915ff03SJohn Baldwin 				fputs("|NOTE_TRIGGER", fp);
1207c915ff03SJohn Baldwin 			if (data != 0)
1208c915ff03SJohn Baldwin 				fprintf(fp, "|%#x", data);
1209c915ff03SJohn Baldwin 		} else {
1210c915ff03SJohn Baldwin 			fprintf(fp, "%#x", data);
1211c915ff03SJohn Baldwin 		}
1212c915ff03SJohn Baldwin 		break;
1213c915ff03SJohn Baldwin 	}
1214c915ff03SJohn Baldwin 	default:
1215c915ff03SJohn Baldwin 		fprintf(fp, "%#x", ke->fflags);
1216c915ff03SJohn Baldwin 	}
1217c915ff03SJohn Baldwin 	fprintf(fp, ",%p,%p", (void *)ke->data, (void *)ke->udata);
1218c915ff03SJohn Baldwin }
1219c915ff03SJohn Baldwin 
1220195aef99SBryan Drewery static void
1221195aef99SBryan Drewery print_utrace(FILE *fp, void *utrace_addr, size_t len)
1222195aef99SBryan Drewery {
1223195aef99SBryan Drewery 	unsigned char *utrace_buffer;
1224195aef99SBryan Drewery 
1225195aef99SBryan Drewery 	fprintf(fp, "{ ");
1226d6fb4894SJohn Baldwin 	if (sysdecode_utrace(fp, utrace_addr, len)) {
1227195aef99SBryan Drewery 		fprintf(fp, " }");
1228195aef99SBryan Drewery 		return;
1229195aef99SBryan Drewery 	}
1230195aef99SBryan Drewery 
1231195aef99SBryan Drewery 	utrace_buffer = utrace_addr;
1232195aef99SBryan Drewery 	fprintf(fp, "%zu:", len);
1233195aef99SBryan Drewery 	while (len--)
1234195aef99SBryan Drewery 		fprintf(fp, " %02x", *utrace_buffer++);
1235195aef99SBryan Drewery 	fprintf(fp, " }");
1236195aef99SBryan Drewery }
1237195aef99SBryan Drewery 
1238bbeaf6c0SSean Eric Fagan /*
1239bbeaf6c0SSean Eric Fagan  * Converts a syscall argument into a string.  Said string is
12404e3da534SJohn Baldwin  * allocated via malloc(), so needs to be free()'d.  sc is
1241bbeaf6c0SSean Eric Fagan  * a pointer to the syscall description (see above); args is
1242bbeaf6c0SSean Eric Fagan  * an array of all of the system call arguments.
1243bbeaf6c0SSean Eric Fagan  */
1244bbeaf6c0SSean Eric Fagan char *
12452b75c8adSJohn Baldwin print_arg(struct syscall_args *sc, unsigned long *args, long *retval,
124694355cfdSAndrey Zonov     struct trussinfo *trussinfo)
1247d8984f48SDag-Erling Smørgrav {
1248f083f689SJohn Baldwin 	FILE *fp;
124994355cfdSAndrey Zonov 	char *tmp;
1250f083f689SJohn Baldwin 	size_t tmplen;
125194355cfdSAndrey Zonov 	pid_t pid;
1252d8984f48SDag-Erling Smørgrav 
1253f083f689SJohn Baldwin 	fp = open_memstream(&tmp, &tmplen);
12542b75c8adSJohn Baldwin 	pid = trussinfo->curthread->proc->pid;
1255bbeaf6c0SSean Eric Fagan 	switch (sc->type & ARG_MASK) {
1256bbeaf6c0SSean Eric Fagan 	case Hex:
1257f083f689SJohn Baldwin 		fprintf(fp, "0x%x", (int)args[sc->offset]);
1258bbeaf6c0SSean Eric Fagan 		break;
1259bbeaf6c0SSean Eric Fagan 	case Octal:
1260f083f689SJohn Baldwin 		fprintf(fp, "0%o", (int)args[sc->offset]);
1261bbeaf6c0SSean Eric Fagan 		break;
1262bbeaf6c0SSean Eric Fagan 	case Int:
1263f083f689SJohn Baldwin 		fprintf(fp, "%d", (int)args[sc->offset]);
1264bbeaf6c0SSean Eric Fagan 		break;
1265808d9805SEd Schouten 	case UInt:
1266808d9805SEd Schouten 		fprintf(fp, "%u", (unsigned int)args[sc->offset]);
1267808d9805SEd Schouten 		break;
1268ebb2cc40SJohn Baldwin 	case PUInt: {
1269ebb2cc40SJohn Baldwin 		unsigned int val;
1270ebb2cc40SJohn Baldwin 
1271ebb2cc40SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &val,
1272ebb2cc40SJohn Baldwin 		    sizeof(val)) == 0)
1273ebb2cc40SJohn Baldwin 			fprintf(fp, "{ %u }", val);
1274ebb2cc40SJohn Baldwin 		else
1275ebb2cc40SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1276ebb2cc40SJohn Baldwin 		break;
1277ebb2cc40SJohn Baldwin 	}
1278fdb5bf37SJohn Baldwin 	case LongHex:
1279f083f689SJohn Baldwin 		fprintf(fp, "0x%lx", args[sc->offset]);
1280fdb5bf37SJohn Baldwin 		break;
1281b289a8d7SJohn Baldwin 	case Long:
1282f083f689SJohn Baldwin 		fprintf(fp, "%ld", args[sc->offset]);
1283b289a8d7SJohn Baldwin 		break;
1284e261fb2aSJohn Baldwin 	case Sizet:
1285e261fb2aSJohn Baldwin 		fprintf(fp, "%zu", (size_t)args[sc->offset]);
1286e261fb2aSJohn Baldwin 		break;
1287d8984f48SDag-Erling Smørgrav 	case Name: {
1288081e5c48SPav Lucistnik 		/* NULL-terminated string. */
1289bbeaf6c0SSean Eric Fagan 		char *tmp2;
12904e3da534SJohn Baldwin 
12915d2d083cSXin LI 		tmp2 = get_string(pid, (void*)args[sc->offset], 0);
1292f083f689SJohn Baldwin 		fprintf(fp, "\"%s\"", tmp2);
1293bbeaf6c0SSean Eric Fagan 		free(tmp2);
1294bbeaf6c0SSean Eric Fagan 		break;
1295d8984f48SDag-Erling Smørgrav 	}
1296d8984f48SDag-Erling Smørgrav 	case BinString: {
12974e3da534SJohn Baldwin 		/*
12984e3da534SJohn Baldwin 		 * Binary block of data that might have printable characters.
12994e3da534SJohn Baldwin 		 * XXX If type|OUT, assume that the length is the syscall's
13004e3da534SJohn Baldwin 		 * return value.  Otherwise, assume that the length of the block
13014e3da534SJohn Baldwin 		 * is in the next syscall argument.
13024e3da534SJohn Baldwin 		 */
1303081e5c48SPav Lucistnik 		int max_string = trussinfo->strsize;
1304081e5c48SPav Lucistnik 		char tmp2[max_string + 1], *tmp3;
1305081e5c48SPav Lucistnik 		int len;
1306081e5c48SPav Lucistnik 		int truncated = 0;
1307081e5c48SPav Lucistnik 
1308081e5c48SPav Lucistnik 		if (sc->type & OUT)
13092b75c8adSJohn Baldwin 			len = retval[0];
1310081e5c48SPav Lucistnik 		else
1311081e5c48SPav Lucistnik 			len = args[sc->offset + 1];
1312081e5c48SPav Lucistnik 
13134e3da534SJohn Baldwin 		/*
13144e3da534SJohn Baldwin 		 * Don't print more than max_string characters, to avoid word
13154e3da534SJohn Baldwin 		 * wrap.  If we have to truncate put some ... after the string.
1316081e5c48SPav Lucistnik 		 */
1317081e5c48SPav Lucistnik 		if (len > max_string) {
1318081e5c48SPav Lucistnik 			len = max_string;
1319081e5c48SPav Lucistnik 			truncated = 1;
1320081e5c48SPav Lucistnik 		}
132194355cfdSAndrey Zonov 		if (len && get_struct(pid, (void*)args[sc->offset], &tmp2, len)
132294355cfdSAndrey Zonov 		    != -1) {
1323081e5c48SPav Lucistnik 			tmp3 = malloc(len * 4 + 1);
1324081e5c48SPav Lucistnik 			while (len) {
132594355cfdSAndrey Zonov 				if (strvisx(tmp3, tmp2, len,
132694355cfdSAndrey Zonov 				    VIS_CSTYLE|VIS_TAB|VIS_NL) <= max_string)
1327081e5c48SPav Lucistnik 					break;
1328081e5c48SPav Lucistnik 				len--;
1329081e5c48SPav Lucistnik 				truncated = 1;
133080c7cc1cSPedro F. Giffuni 			}
1331f083f689SJohn Baldwin 			fprintf(fp, "\"%s\"%s", tmp3, truncated ?
133294355cfdSAndrey Zonov 			    "..." : "");
1333081e5c48SPav Lucistnik 			free(tmp3);
1334d8984f48SDag-Erling Smørgrav 		} else {
1335f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1336081e5c48SPav Lucistnik 		}
1337081e5c48SPav Lucistnik 		break;
1338d8984f48SDag-Erling Smørgrav 	}
133968055893SJohn Baldwin 	case ExecArgs:
134068055893SJohn Baldwin 	case ExecEnv:
1341d8984f48SDag-Erling Smørgrav 	case StringArray: {
1342890843c1SJohn Baldwin 		uintptr_t addr;
1343890843c1SJohn Baldwin 		union {
1344890843c1SJohn Baldwin 			char *strarray[0];
1345890843c1SJohn Baldwin 			char buf[PAGE_SIZE];
1346890843c1SJohn Baldwin 		} u;
13479897b203SMatthew N. Dodd 		char *string;
1348890843c1SJohn Baldwin 		size_t len;
13492b75c8adSJohn Baldwin 		u_int first, i;
13509897b203SMatthew N. Dodd 
1351890843c1SJohn Baldwin 		/*
135268055893SJohn Baldwin 		 * Only parse argv[] and environment arrays from exec calls
135368055893SJohn Baldwin 		 * if requested.
135468055893SJohn Baldwin 		 */
135568055893SJohn Baldwin 		if (((sc->type & ARG_MASK) == ExecArgs &&
135668055893SJohn Baldwin 		    (trussinfo->flags & EXECVEARGS) == 0) ||
135768055893SJohn Baldwin 		    ((sc->type & ARG_MASK) == ExecEnv &&
135868055893SJohn Baldwin 		    (trussinfo->flags & EXECVEENVS) == 0)) {
135968055893SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
136068055893SJohn Baldwin 			break;
136168055893SJohn Baldwin 		}
136268055893SJohn Baldwin 
136368055893SJohn Baldwin 		/*
1364890843c1SJohn Baldwin 		 * Read a page of pointers at a time.  Punt if the top-level
1365890843c1SJohn Baldwin 		 * pointer is not aligned.  Note that the first read is of
1366890843c1SJohn Baldwin 		 * a partial page.
1367890843c1SJohn Baldwin 		 */
1368890843c1SJohn Baldwin 		addr = args[sc->offset];
1369890843c1SJohn Baldwin 		if (addr % sizeof(char *) != 0) {
1370890843c1SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1371890843c1SJohn Baldwin 			break;
13729897b203SMatthew N. Dodd 		}
13739897b203SMatthew N. Dodd 
1374890843c1SJohn Baldwin 		len = PAGE_SIZE - (addr & PAGE_MASK);
1375890843c1SJohn Baldwin 		if (get_struct(pid, (void *)addr, u.buf, len) == -1) {
1376890843c1SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1377890843c1SJohn Baldwin 			break;
13789897b203SMatthew N. Dodd 		}
1379890843c1SJohn Baldwin 
1380890843c1SJohn Baldwin 		fputc('[', fp);
1381890843c1SJohn Baldwin 		first = 1;
1382890843c1SJohn Baldwin 		i = 0;
1383890843c1SJohn Baldwin 		while (u.strarray[i] != NULL) {
1384890843c1SJohn Baldwin 			string = get_string(pid, u.strarray[i], 0);
1385890843c1SJohn Baldwin 			fprintf(fp, "%s \"%s\"", first ? "" : ",", string);
1386890843c1SJohn Baldwin 			free(string);
1387890843c1SJohn Baldwin 			first = 0;
1388890843c1SJohn Baldwin 
1389890843c1SJohn Baldwin 			i++;
1390890843c1SJohn Baldwin 			if (i == len / sizeof(char *)) {
1391890843c1SJohn Baldwin 				addr += len;
1392890843c1SJohn Baldwin 				len = PAGE_SIZE;
1393890843c1SJohn Baldwin 				if (get_struct(pid, (void *)addr, u.buf, len) ==
1394890843c1SJohn Baldwin 				    -1) {
1395890843c1SJohn Baldwin 					fprintf(fp, ", <inval>");
1396890843c1SJohn Baldwin 					break;
1397890843c1SJohn Baldwin 				}
1398890843c1SJohn Baldwin 				i = 0;
1399890843c1SJohn Baldwin 			}
1400890843c1SJohn Baldwin 		}
1401890843c1SJohn Baldwin 		fputs(" ]", fp);
14029897b203SMatthew N. Dodd 		break;
1403d8984f48SDag-Erling Smørgrav 	}
140410aeefc9SMarcel Moolenaar #ifdef __LP64__
140510aeefc9SMarcel Moolenaar 	case Quad:
140672df19e7SJohn Baldwin 		fprintf(fp, "%ld", args[sc->offset]);
140772df19e7SJohn Baldwin 		break;
140872df19e7SJohn Baldwin 	case QuadHex:
1409f083f689SJohn Baldwin 		fprintf(fp, "0x%lx", args[sc->offset]);
141010aeefc9SMarcel Moolenaar 		break;
141110aeefc9SMarcel Moolenaar #else
141272df19e7SJohn Baldwin 	case Quad:
141372df19e7SJohn Baldwin 	case QuadHex: {
141410aeefc9SMarcel Moolenaar 		unsigned long long ll;
14154e3da534SJohn Baldwin 
14162b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN
14172b75c8adSJohn Baldwin 		ll = (unsigned long long)args[sc->offset + 1] << 32 |
14182b75c8adSJohn Baldwin 		    args[sc->offset];
14192b75c8adSJohn Baldwin #else
14202b75c8adSJohn Baldwin 		ll = (unsigned long long)args[sc->offset] << 32 |
14212b75c8adSJohn Baldwin 		    args[sc->offset + 1];
14222b75c8adSJohn Baldwin #endif
142372df19e7SJohn Baldwin 		if ((sc->type & ARG_MASK) == Quad)
142472df19e7SJohn Baldwin 			fprintf(fp, "%lld", ll);
142572df19e7SJohn Baldwin 		else
1426f083f689SJohn Baldwin 			fprintf(fp, "0x%llx", ll);
1427bbeaf6c0SSean Eric Fagan 		break;
1428bbeaf6c0SSean Eric Fagan 	}
142910aeefc9SMarcel Moolenaar #endif
1430b60a095bSJohn Baldwin 	case PQuadHex: {
1431b60a095bSJohn Baldwin 		uint64_t val;
1432b60a095bSJohn Baldwin 
1433b60a095bSJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &val,
1434b60a095bSJohn Baldwin 		    sizeof(val)) == 0)
1435b60a095bSJohn Baldwin 			fprintf(fp, "{ 0x%jx }", (uintmax_t)val);
1436b60a095bSJohn Baldwin 		else
1437b60a095bSJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1438b60a095bSJohn Baldwin 		break;
1439b60a095bSJohn Baldwin 	}
1440bbeaf6c0SSean Eric Fagan 	case Ptr:
1441f083f689SJohn Baldwin 		fprintf(fp, "0x%lx", args[sc->offset]);
1442bbeaf6c0SSean Eric Fagan 		break;
1443d8984f48SDag-Erling Smørgrav 	case Readlinkres: {
14442bae4eb3SAlfred Perlstein 		char *tmp2;
14454e3da534SJohn Baldwin 
14462b75c8adSJohn Baldwin 		if (retval[0] == -1)
14472bae4eb3SAlfred Perlstein 			break;
14482b75c8adSJohn Baldwin 		tmp2 = get_string(pid, (void*)args[sc->offset], retval[0]);
1449f083f689SJohn Baldwin 		fprintf(fp, "\"%s\"", tmp2);
14502bae4eb3SAlfred Perlstein 		free(tmp2);
14512bae4eb3SAlfred Perlstein 		break;
1452d8984f48SDag-Erling Smørgrav 	}
1453d8984f48SDag-Erling Smørgrav 	case Ioctl: {
14544e3da534SJohn Baldwin 		const char *temp;
14554e3da534SJohn Baldwin 		unsigned long cmd;
14564e3da534SJohn Baldwin 
14574e3da534SJohn Baldwin 		cmd = args[sc->offset];
1458265e5898SJohn Baldwin 		temp = sysdecode_ioctlname(cmd);
145994355cfdSAndrey Zonov 		if (temp)
1460f083f689SJohn Baldwin 			fputs(temp, fp);
146194355cfdSAndrey Zonov 		else {
1462f083f689SJohn Baldwin 			fprintf(fp, "0x%lx { IO%s%s 0x%lx('%c'), %lu, %lu }",
14634e3da534SJohn Baldwin 			    cmd, cmd & IOC_OUT ? "R" : "",
14644e3da534SJohn Baldwin 			    cmd & IOC_IN ? "W" : "", IOCGROUP(cmd),
14654e3da534SJohn Baldwin 			    isprint(IOCGROUP(cmd)) ? (char)IOCGROUP(cmd) : '?',
14664e3da534SJohn Baldwin 			    cmd & 0xFF, IOCPARM_LEN(cmd));
1467081e5c48SPav Lucistnik 		}
1468081e5c48SPav Lucistnik 		break;
1469d8984f48SDag-Erling Smørgrav 	}
1470d8984f48SDag-Erling Smørgrav 	case Timespec: {
1471e45a5a0dSDavid Malone 		struct timespec ts;
14724e3da534SJohn Baldwin 
147394355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &ts,
147494355cfdSAndrey Zonov 		    sizeof(ts)) != -1)
1475a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec,
147694355cfdSAndrey Zonov 			    ts.tv_nsec);
1477e45a5a0dSDavid Malone 		else
1478f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1479e45a5a0dSDavid Malone 		break;
1480d8984f48SDag-Erling Smørgrav 	}
14817d897327SJohn Baldwin 	case Timespec2: {
14827d897327SJohn Baldwin 		struct timespec ts[2];
14837d897327SJohn Baldwin 		const char *sep;
14847d897327SJohn Baldwin 		unsigned int i;
14857d897327SJohn Baldwin 
14867d897327SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &ts, sizeof(ts))
14877d897327SJohn Baldwin 		    != -1) {
14881e2ec671SJohn Baldwin 			fputs("{ ", fp);
14897d897327SJohn Baldwin 			sep = "";
14907d897327SJohn Baldwin 			for (i = 0; i < nitems(ts); i++) {
14917d897327SJohn Baldwin 				fputs(sep, fp);
14927d897327SJohn Baldwin 				sep = ", ";
14937d897327SJohn Baldwin 				switch (ts[i].tv_nsec) {
14947d897327SJohn Baldwin 				case UTIME_NOW:
14957d897327SJohn Baldwin 					fprintf(fp, "UTIME_NOW");
14967d897327SJohn Baldwin 					break;
14977d897327SJohn Baldwin 				case UTIME_OMIT:
14987d897327SJohn Baldwin 					fprintf(fp, "UTIME_OMIT");
14997d897327SJohn Baldwin 					break;
15007d897327SJohn Baldwin 				default:
1501a1436773SJohn Baldwin 					fprintf(fp, "%jd.%09ld",
1502a1436773SJohn Baldwin 					    (intmax_t)ts[i].tv_sec,
1503a1436773SJohn Baldwin 					    ts[i].tv_nsec);
15047d897327SJohn Baldwin 					break;
15057d897327SJohn Baldwin 				}
15067d897327SJohn Baldwin 			}
15071e2ec671SJohn Baldwin 			fputs(" }", fp);
15087d897327SJohn Baldwin 		} else
1509f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
15107d897327SJohn Baldwin 		break;
15117d897327SJohn Baldwin 	}
1512d8984f48SDag-Erling Smørgrav 	case Timeval: {
1513e45a5a0dSDavid Malone 		struct timeval tv;
15144e3da534SJohn Baldwin 
151594355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
151694355cfdSAndrey Zonov 		    != -1)
1517a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec,
151894355cfdSAndrey Zonov 			    tv.tv_usec);
1519081e5c48SPav Lucistnik 		else
1520f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1521081e5c48SPav Lucistnik 		break;
1522d8984f48SDag-Erling Smørgrav 	}
1523d8984f48SDag-Erling Smørgrav 	case Timeval2: {
1524081e5c48SPav Lucistnik 		struct timeval tv[2];
15254e3da534SJohn Baldwin 
152694355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
152794355cfdSAndrey Zonov 		    != -1)
1528a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
1529a1436773SJohn Baldwin 			    (intmax_t)tv[0].tv_sec, tv[0].tv_usec,
1530a1436773SJohn Baldwin 			    (intmax_t)tv[1].tv_sec, tv[1].tv_usec);
1531e45a5a0dSDavid Malone 		else
1532f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1533e45a5a0dSDavid Malone 		break;
1534d8984f48SDag-Erling Smørgrav 	}
1535d8984f48SDag-Erling Smørgrav 	case Itimerval: {
1536e45a5a0dSDavid Malone 		struct itimerval itv;
15374e3da534SJohn Baldwin 
153894355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &itv,
153994355cfdSAndrey Zonov 		    sizeof(itv)) != -1)
1540a1436773SJohn Baldwin 			fprintf(fp, "{ %jd.%06ld, %jd.%06ld }",
1541a1436773SJohn Baldwin 			    (intmax_t)itv.it_interval.tv_sec,
1542081e5c48SPav Lucistnik 			    itv.it_interval.tv_usec,
1543a1436773SJohn Baldwin 			    (intmax_t)itv.it_value.tv_sec,
1544081e5c48SPav Lucistnik 			    itv.it_value.tv_usec);
1545e45a5a0dSDavid Malone 		else
1546f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1547e45a5a0dSDavid Malone 		break;
1548d8984f48SDag-Erling Smørgrav 	}
15491c99a22aSSteven Hartland 	case LinuxSockArgs:
15501c99a22aSSteven Hartland 	{
15511c99a22aSSteven Hartland 		struct linux_socketcall_args largs;
15524e3da534SJohn Baldwin 
15531c99a22aSSteven Hartland 		if (get_struct(pid, (void *)args[sc->offset], (void *)&largs,
1554fb7eabb0SJohn Baldwin 		    sizeof(largs)) != -1)
1555f083f689SJohn Baldwin 			fprintf(fp, "{ %s, 0x%lx }",
1556fb7eabb0SJohn Baldwin 			    lookup(linux_socketcall_ops, largs.what, 10),
15570a46af44SJohn Baldwin 			    (long unsigned int)largs.args);
1558fb7eabb0SJohn Baldwin 		else
1559f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
15601c99a22aSSteven Hartland 		break;
15611c99a22aSSteven Hartland 	}
1562d8984f48SDag-Erling Smørgrav 	case Pollfd: {
1563e45a5a0dSDavid Malone 		/*
156494355cfdSAndrey Zonov 		 * XXX: A Pollfd argument expects the /next/ syscall argument
156594355cfdSAndrey Zonov 		 * to be the number of fds in the array. This matches the poll
156694355cfdSAndrey Zonov 		 * syscall.
1567e45a5a0dSDavid Malone 		 */
1568e45a5a0dSDavid Malone 		struct pollfd *pfd;
1569e45a5a0dSDavid Malone 		int numfds = args[sc->offset + 1];
1570f083f689SJohn Baldwin 		size_t bytes = sizeof(struct pollfd) * numfds;
1571f083f689SJohn Baldwin 		int i;
1572e45a5a0dSDavid Malone 
1573e45a5a0dSDavid Malone 		if ((pfd = malloc(bytes)) == NULL)
1574f083f689SJohn Baldwin 			err(1, "Cannot malloc %zu bytes for pollfd array",
157594355cfdSAndrey Zonov 			    bytes);
157694355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], pfd, bytes)
157794355cfdSAndrey Zonov 		    != -1) {
1578f083f689SJohn Baldwin 			fputs("{", fp);
1579e45a5a0dSDavid Malone 			for (i = 0; i < numfds; i++) {
1580f083f689SJohn Baldwin 				fprintf(fp, " %d/%s", pfd[i].fd,
1581081e5c48SPav Lucistnik 				    xlookup_bits(poll_flags, pfd[i].events));
1582e45a5a0dSDavid Malone 			}
1583f083f689SJohn Baldwin 			fputs(" }", fp);
1584d8984f48SDag-Erling Smørgrav 		} else {
1585f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1586e45a5a0dSDavid Malone 		}
1587d8984f48SDag-Erling Smørgrav 		free(pfd);
1588e45a5a0dSDavid Malone 		break;
1589d8984f48SDag-Erling Smørgrav 	}
1590d8984f48SDag-Erling Smørgrav 	case Fd_set: {
1591e45a5a0dSDavid Malone 		/*
159294355cfdSAndrey Zonov 		 * XXX: A Fd_set argument expects the /first/ syscall argument
159394355cfdSAndrey Zonov 		 * to be the number of fds in the array.  This matches the
159494355cfdSAndrey Zonov 		 * select syscall.
1595e45a5a0dSDavid Malone 		 */
1596e45a5a0dSDavid Malone 		fd_set *fds;
1597e45a5a0dSDavid Malone 		int numfds = args[0];
1598f083f689SJohn Baldwin 		size_t bytes = _howmany(numfds, _NFDBITS) * _NFDBITS;
1599f083f689SJohn Baldwin 		int i;
1600e45a5a0dSDavid Malone 
1601e45a5a0dSDavid Malone 		if ((fds = malloc(bytes)) == NULL)
1602f083f689SJohn Baldwin 			err(1, "Cannot malloc %zu bytes for fd_set array",
160394355cfdSAndrey Zonov 			    bytes);
160494355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], fds, bytes)
160594355cfdSAndrey Zonov 		    != -1) {
1606f083f689SJohn Baldwin 			fputs("{", fp);
1607e45a5a0dSDavid Malone 			for (i = 0; i < numfds; i++) {
1608f083f689SJohn Baldwin 				if (FD_ISSET(i, fds))
1609f083f689SJohn Baldwin 					fprintf(fp, " %d", i);
1610e45a5a0dSDavid Malone 			}
1611f083f689SJohn Baldwin 			fputs(" }", fp);
161294355cfdSAndrey Zonov 		} else
1613f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1614d8984f48SDag-Erling Smørgrav 		free(fds);
1615e45a5a0dSDavid Malone 		break;
1616d8984f48SDag-Erling Smørgrav 	}
161734763d1cSJohn Baldwin 	case Signal:
1618f083f689SJohn Baldwin 		fputs(strsig2(args[sc->offset]), fp);
1619f0ebbc29SDag-Erling Smørgrav 		break;
1620d8984f48SDag-Erling Smørgrav 	case Sigset: {
1621081e5c48SPav Lucistnik 		long sig;
1622081e5c48SPav Lucistnik 		sigset_t ss;
1623f083f689SJohn Baldwin 		int i, first;
1624081e5c48SPav Lucistnik 
1625081e5c48SPav Lucistnik 		sig = args[sc->offset];
162694355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], (void *)&ss,
162794355cfdSAndrey Zonov 		    sizeof(ss)) == -1) {
1628f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1629081e5c48SPav Lucistnik 			break;
1630081e5c48SPav Lucistnik 		}
1631f083f689SJohn Baldwin 		fputs("{ ", fp);
1632f083f689SJohn Baldwin 		first = 1;
1633d8984f48SDag-Erling Smørgrav 		for (i = 1; i < sys_nsig; i++) {
163434763d1cSJohn Baldwin 			if (sigismember(&ss, i)) {
1635f083f689SJohn Baldwin 				fprintf(fp, "%s%s", !first ? "|" : "",
16369289f547SJohn Baldwin 				    strsig2(i));
1637f083f689SJohn Baldwin 				first = 0;
163834763d1cSJohn Baldwin 			}
1639081e5c48SPav Lucistnik 		}
1640f083f689SJohn Baldwin 		if (!first)
1641f083f689SJohn Baldwin 			fputc(' ', fp);
1642f083f689SJohn Baldwin 		fputc('}', fp);
1643081e5c48SPav Lucistnik 		break;
1644d8984f48SDag-Erling Smørgrav 	}
16459289f547SJohn Baldwin 	case Sigprocmask:
16469289f547SJohn Baldwin 		print_integer_arg(sysdecode_sigprocmask_how, fp,
16479289f547SJohn Baldwin 		    args[sc->offset]);
1648894b8f7aSAlfred Perlstein 		break;
16499289f547SJohn Baldwin 	case Fcntlflag:
16504e3da534SJohn Baldwin 		/* XXX: Output depends on the value of the previous argument. */
16519289f547SJohn Baldwin 		if (sysdecode_fcntl_arg_p(args[sc->offset - 1]))
16529289f547SJohn Baldwin 			sysdecode_fcntl_arg(fp, args[sc->offset - 1],
16539289f547SJohn Baldwin 			    args[sc->offset], 16);
1654081e5c48SPav Lucistnik 		break;
1655081e5c48SPav Lucistnik 	case Open:
16569289f547SJohn Baldwin 		print_mask_arg(sysdecode_open_flags, fp, args[sc->offset]);
1657081e5c48SPav Lucistnik 		break;
1658081e5c48SPav Lucistnik 	case Fcntl:
16599289f547SJohn Baldwin 		print_integer_arg(sysdecode_fcntl_cmd, fp, args[sc->offset]);
1660081e5c48SPav Lucistnik 		break;
1661894b8f7aSAlfred Perlstein 	case Mprot:
16629289f547SJohn Baldwin 		print_mask_arg(sysdecode_mmap_prot, fp, args[sc->offset]);
1663894b8f7aSAlfred Perlstein 		break;
16649289f547SJohn Baldwin 	case Mmapflags:
16659289f547SJohn Baldwin 		print_mask_arg(sysdecode_mmap_flags, fp, args[sc->offset]);
1666894b8f7aSAlfred Perlstein 		break;
1667fde3a7d1SAlfred Perlstein 	case Whence:
16689289f547SJohn Baldwin 		print_integer_arg(sysdecode_whence, fp, args[sc->offset]);
1669081e5c48SPav Lucistnik 		break;
1670081e5c48SPav Lucistnik 	case Sockdomain:
16719289f547SJohn Baldwin 		print_integer_arg(sysdecode_socketdomain, fp, args[sc->offset]);
1672081e5c48SPav Lucistnik 		break;
16739289f547SJohn Baldwin 	case Socktype:
16749289f547SJohn Baldwin 		print_mask_arg(sysdecode_socket_type, fp, args[sc->offset]);
1675081e5c48SPav Lucistnik 		break;
1676081e5c48SPav Lucistnik 	case Shutdown:
16779289f547SJohn Baldwin 		print_integer_arg(sysdecode_shutdown_how, fp, args[sc->offset]);
1678081e5c48SPav Lucistnik 		break;
1679081e5c48SPav Lucistnik 	case Resource:
16809289f547SJohn Baldwin 		print_integer_arg(sysdecode_rlimit, fp, args[sc->offset]);
1681081e5c48SPav Lucistnik 		break;
1682ee8aa41dSJohn Baldwin 	case RusageWho:
1683ee8aa41dSJohn Baldwin 		print_integer_arg(sysdecode_getrusage_who, fp, args[sc->offset]);
1684ee8aa41dSJohn Baldwin 		break;
1685081e5c48SPav Lucistnik 	case Pathconf:
1686f083f689SJohn Baldwin 		fputs(xlookup(pathconf_arg, args[sc->offset]), fp);
1687fde3a7d1SAlfred Perlstein 		break;
16889e1db66eSMark Johnston 	case Rforkflags:
16899289f547SJohn Baldwin 		print_mask_arg(sysdecode_rfork_flags, fp, args[sc->offset]);
16909e1db66eSMark Johnston 		break;
1691d8984f48SDag-Erling Smørgrav 	case Sockaddr: {
16929ddd1412SDag-Erling Smørgrav 		char addr[64];
16931be5d704SMark Murray 		struct sockaddr_in *lsin;
16941be5d704SMark Murray 		struct sockaddr_in6 *lsin6;
1695dec17687SBrian Feldman 		struct sockaddr_un *sun;
1696dec17687SBrian Feldman 		struct sockaddr *sa;
169766917ca9SJohn Baldwin 		socklen_t len;
1698dec17687SBrian Feldman 		u_char *q;
16999ddd1412SDag-Erling Smørgrav 
1700a7a08c7eSMarcel Moolenaar 		if (args[sc->offset] == 0) {
1701f083f689SJohn Baldwin 			fputs("NULL", fp);
1702a7a08c7eSMarcel Moolenaar 			break;
1703a7a08c7eSMarcel Moolenaar 		}
1704a7a08c7eSMarcel Moolenaar 
17056a656761SAlfred Perlstein 		/*
170666917ca9SJohn Baldwin 		 * Extract the address length from the next argument.  If
170766917ca9SJohn Baldwin 		 * this is an output sockaddr (OUT is set), then the
170866917ca9SJohn Baldwin 		 * next argument is a pointer to a socklen_t.  Otherwise
170966917ca9SJohn Baldwin 		 * the next argument contains a socklen_t by value.
17106a656761SAlfred Perlstein 		 */
171166917ca9SJohn Baldwin 		if (sc->type & OUT) {
171266917ca9SJohn Baldwin 			if (get_struct(pid, (void *)args[sc->offset + 1],
171366917ca9SJohn Baldwin 			    &len, sizeof(len)) == -1) {
171466917ca9SJohn Baldwin 				fprintf(fp, "0x%lx", args[sc->offset]);
17156a656761SAlfred Perlstein 				break;
17166a656761SAlfred Perlstein 			}
171766917ca9SJohn Baldwin 		} else
171866917ca9SJohn Baldwin 			len = args[sc->offset + 1];
171966917ca9SJohn Baldwin 
172066917ca9SJohn Baldwin 		/* If the length is too small, just bail. */
172166917ca9SJohn Baldwin 		if (len < sizeof(*sa)) {
1722f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1723f083f689SJohn Baldwin 			break;
17249ddd1412SDag-Erling Smørgrav 		}
1725dec17687SBrian Feldman 
172666917ca9SJohn Baldwin 		sa = calloc(1, len);
172766917ca9SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], sa, len) == -1) {
172866917ca9SJohn Baldwin 			free(sa);
172966917ca9SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
173066917ca9SJohn Baldwin 			break;
173166917ca9SJohn Baldwin 		}
173266917ca9SJohn Baldwin 
173366917ca9SJohn Baldwin 		switch (sa->sa_family) {
1734dec17687SBrian Feldman 		case AF_INET:
173566917ca9SJohn Baldwin 			if (len < sizeof(*lsin))
173666917ca9SJohn Baldwin 				goto sockaddr_short;
173766917ca9SJohn Baldwin 			lsin = (struct sockaddr_in *)(void *)sa;
17384e3da534SJohn Baldwin 			inet_ntop(AF_INET, &lsin->sin_addr, addr, sizeof(addr));
1739f083f689SJohn Baldwin 			fprintf(fp, "{ AF_INET %s:%d }", addr,
174094355cfdSAndrey Zonov 			    htons(lsin->sin_port));
1741dec17687SBrian Feldman 			break;
1742dec17687SBrian Feldman 		case AF_INET6:
174366917ca9SJohn Baldwin 			if (len < sizeof(*lsin6))
174466917ca9SJohn Baldwin 				goto sockaddr_short;
174566917ca9SJohn Baldwin 			lsin6 = (struct sockaddr_in6 *)(void *)sa;
174694355cfdSAndrey Zonov 			inet_ntop(AF_INET6, &lsin6->sin6_addr, addr,
17474e3da534SJohn Baldwin 			    sizeof(addr));
1748f083f689SJohn Baldwin 			fprintf(fp, "{ AF_INET6 [%s]:%d }", addr,
174994355cfdSAndrey Zonov 			    htons(lsin6->sin6_port));
1750dec17687SBrian Feldman 			break;
1751dec17687SBrian Feldman 		case AF_UNIX:
175266917ca9SJohn Baldwin 			sun = (struct sockaddr_un *)sa;
175366917ca9SJohn Baldwin 			fprintf(fp, "{ AF_UNIX \"%.*s\" }",
175466917ca9SJohn Baldwin 			    (int)(len - offsetof(struct sockaddr_un, sun_path)),
175566917ca9SJohn Baldwin 			    sun->sun_path);
1756dec17687SBrian Feldman 			break;
1757dec17687SBrian Feldman 		default:
175866917ca9SJohn Baldwin 		sockaddr_short:
1759f083f689SJohn Baldwin 			fprintf(fp,
1760f083f689SJohn Baldwin 			    "{ sa_len = %d, sa_family = %d, sa_data = {",
1761f083f689SJohn Baldwin 			    (int)sa->sa_len, (int)sa->sa_family);
1762f083f689SJohn Baldwin 			for (q = (u_char *)sa->sa_data;
176366917ca9SJohn Baldwin 			     q < (u_char *)sa + len; q++)
1764f083f689SJohn Baldwin 				fprintf(fp, "%s 0x%02x",
1765f083f689SJohn Baldwin 				    q == (u_char *)sa->sa_data ? "" : ",",
1766f083f689SJohn Baldwin 				    *q);
1767f083f689SJohn Baldwin 			fputs(" } }", fp);
1768dec17687SBrian Feldman 		}
176966917ca9SJohn Baldwin 		free(sa);
17709ddd1412SDag-Erling Smørgrav 		break;
1771d8984f48SDag-Erling Smørgrav 	}
1772d8984f48SDag-Erling Smørgrav 	case Sigaction: {
1773e45a5a0dSDavid Malone 		struct sigaction sa;
1774e45a5a0dSDavid Malone 
177594355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &sa, sizeof(sa))
177694355cfdSAndrey Zonov 		    != -1) {
1777f083f689SJohn Baldwin 			fputs("{ ", fp);
1778e45a5a0dSDavid Malone 			if (sa.sa_handler == SIG_DFL)
1779f083f689SJohn Baldwin 				fputs("SIG_DFL", fp);
1780e45a5a0dSDavid Malone 			else if (sa.sa_handler == SIG_IGN)
1781f083f689SJohn Baldwin 				fputs("SIG_IGN", fp);
1782e45a5a0dSDavid Malone 			else
1783f083f689SJohn Baldwin 				fprintf(fp, "%p", sa.sa_handler);
1784f083f689SJohn Baldwin 			fprintf(fp, " %s ss_t }",
1785081e5c48SPav Lucistnik 			    xlookup_bits(sigaction_flags, sa.sa_flags));
178694355cfdSAndrey Zonov 		} else
1787f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1788e45a5a0dSDavid Malone 		break;
1789d8984f48SDag-Erling Smørgrav 	}
1790d8984f48SDag-Erling Smørgrav 	case Kevent: {
1791081e5c48SPav Lucistnik 		/*
17924e3da534SJohn Baldwin 		 * XXX XXX: The size of the array is determined by either the
1793081e5c48SPav Lucistnik 		 * next syscall argument, or by the syscall return value,
1794081e5c48SPav Lucistnik 		 * depending on which argument number we are.  This matches the
1795081e5c48SPav Lucistnik 		 * kevent syscall, but luckily that's the only syscall that uses
1796081e5c48SPav Lucistnik 		 * them.
1797081e5c48SPav Lucistnik 		 */
1798081e5c48SPav Lucistnik 		struct kevent *ke;
1799081e5c48SPav Lucistnik 		int numevents = -1;
1800f083f689SJohn Baldwin 		size_t bytes;
1801f083f689SJohn Baldwin 		int i;
1802081e5c48SPav Lucistnik 
1803081e5c48SPav Lucistnik 		if (sc->offset == 1)
1804081e5c48SPav Lucistnik 			numevents = args[sc->offset+1];
18052b75c8adSJohn Baldwin 		else if (sc->offset == 3 && retval[0] != -1)
18062b75c8adSJohn Baldwin 			numevents = retval[0];
1807081e5c48SPav Lucistnik 
1808f083f689SJohn Baldwin 		if (numevents >= 0) {
1809081e5c48SPav Lucistnik 			bytes = sizeof(struct kevent) * numevents;
1810081e5c48SPav Lucistnik 			if ((ke = malloc(bytes)) == NULL)
1811f083f689SJohn Baldwin 				err(1,
1812f083f689SJohn Baldwin 				    "Cannot malloc %zu bytes for kevent array",
181394355cfdSAndrey Zonov 				    bytes);
1814f083f689SJohn Baldwin 		} else
1815f083f689SJohn Baldwin 			ke = NULL;
181694355cfdSAndrey Zonov 		if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset],
181794355cfdSAndrey Zonov 		    ke, bytes) != -1) {
1818f083f689SJohn Baldwin 			fputc('{', fp);
1819c915ff03SJohn Baldwin 			for (i = 0; i < numevents; i++) {
1820c915ff03SJohn Baldwin 				fputc(' ', fp);
1821c915ff03SJohn Baldwin 				print_kevent(fp, &ke[i], sc->offset == 1);
1822c915ff03SJohn Baldwin 			}
1823f083f689SJohn Baldwin 			fputs(" }", fp);
1824d8984f48SDag-Erling Smørgrav 		} else {
1825f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1826081e5c48SPav Lucistnik 		}
1827d8984f48SDag-Erling Smørgrav 		free(ke);
1828081e5c48SPav Lucistnik 		break;
1829d8984f48SDag-Erling Smørgrav 	}
1830d8984f48SDag-Erling Smørgrav 	case Stat: {
1831081e5c48SPav Lucistnik 		struct stat st;
18324e3da534SJohn Baldwin 
183394355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st))
183494355cfdSAndrey Zonov 		    != -1) {
1835081e5c48SPav Lucistnik 			char mode[12];
18364e3da534SJohn Baldwin 
1837081e5c48SPav Lucistnik 			strmode(st.st_mode, mode);
1838f083f689SJohn Baldwin 			fprintf(fp,
1839b38fbc2eSJohn Baldwin 			    "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode,
1840b38fbc2eSJohn Baldwin 			    (uintmax_t)st.st_ino, (intmax_t)st.st_size,
184194355cfdSAndrey Zonov 			    (long)st.st_blksize);
1842d8984f48SDag-Erling Smørgrav 		} else {
1843f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1844081e5c48SPav Lucistnik 		}
1845081e5c48SPav Lucistnik 		break;
1846d8984f48SDag-Erling Smørgrav 	}
1847a776866bSBryan Drewery 	case StatFs: {
1848a776866bSBryan Drewery 		unsigned int i;
1849a776866bSBryan Drewery 		struct statfs buf;
18500a71c082SBryan Drewery 
1851a776866bSBryan Drewery 		if (get_struct(pid, (void *)args[sc->offset], &buf,
1852a776866bSBryan Drewery 		    sizeof(buf)) != -1) {
1853a776866bSBryan Drewery 			char fsid[17];
1854a776866bSBryan Drewery 
1855a776866bSBryan Drewery 			bzero(fsid, sizeof(fsid));
1856a776866bSBryan Drewery 			if (buf.f_fsid.val[0] != 0 || buf.f_fsid.val[1] != 0) {
1857a776866bSBryan Drewery 			        for (i = 0; i < sizeof(buf.f_fsid); i++)
1858a776866bSBryan Drewery 					snprintf(&fsid[i*2],
1859a776866bSBryan Drewery 					    sizeof(fsid) - (i*2), "%02x",
1860a776866bSBryan Drewery 					    ((u_char *)&buf.f_fsid)[i]);
1861a776866bSBryan Drewery 			}
1862a776866bSBryan Drewery 			fprintf(fp,
1863a776866bSBryan Drewery 			    "{ fstypename=%s,mntonname=%s,mntfromname=%s,"
1864a776866bSBryan Drewery 			    "fsid=%s }", buf.f_fstypename, buf.f_mntonname,
1865a776866bSBryan Drewery 			    buf.f_mntfromname, fsid);
1866a776866bSBryan Drewery 		} else
1867a776866bSBryan Drewery 			fprintf(fp, "0x%lx", args[sc->offset]);
1868a776866bSBryan Drewery 		break;
1869a776866bSBryan Drewery 	}
1870a776866bSBryan Drewery 
1871d8984f48SDag-Erling Smørgrav 	case Rusage: {
1872081e5c48SPav Lucistnik 		struct rusage ru;
18734e3da534SJohn Baldwin 
187494355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru))
187594355cfdSAndrey Zonov 		    != -1) {
1876f083f689SJohn Baldwin 			fprintf(fp,
1877a1436773SJohn Baldwin 			    "{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }",
1878a1436773SJohn Baldwin 			    (intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec,
1879a1436773SJohn Baldwin 			    (intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec,
1880081e5c48SPav Lucistnik 			    ru.ru_inblock, ru.ru_oublock);
188194355cfdSAndrey Zonov 		} else
1882f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1883081e5c48SPav Lucistnik 		break;
1884d8984f48SDag-Erling Smørgrav 	}
1885d8984f48SDag-Erling Smørgrav 	case Rlimit: {
1886081e5c48SPav Lucistnik 		struct rlimit rl;
18874e3da534SJohn Baldwin 
188894355cfdSAndrey Zonov 		if (get_struct(pid, (void *)args[sc->offset], &rl, sizeof(rl))
188994355cfdSAndrey Zonov 		    != -1) {
1890f083f689SJohn Baldwin 			fprintf(fp, "{ cur=%ju,max=%ju }",
1891081e5c48SPav Lucistnik 			    rl.rlim_cur, rl.rlim_max);
189294355cfdSAndrey Zonov 		} else
1893f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
1894081e5c48SPav Lucistnik 		break;
1895d8984f48SDag-Erling Smørgrav 	}
189634763d1cSJohn Baldwin 	case ExitStatus: {
189734763d1cSJohn Baldwin 		int status;
1898f083f689SJohn Baldwin 
189934763d1cSJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &status,
190034763d1cSJohn Baldwin 		    sizeof(status)) != -1) {
1901f083f689SJohn Baldwin 			fputs("{ ", fp);
190234763d1cSJohn Baldwin 			if (WIFCONTINUED(status))
1903f083f689SJohn Baldwin 				fputs("CONTINUED", fp);
190434763d1cSJohn Baldwin 			else if (WIFEXITED(status))
1905f083f689SJohn Baldwin 				fprintf(fp, "EXITED,val=%d",
190634763d1cSJohn Baldwin 				    WEXITSTATUS(status));
190734763d1cSJohn Baldwin 			else if (WIFSIGNALED(status))
1908f083f689SJohn Baldwin 				fprintf(fp, "SIGNALED,sig=%s%s",
1909f083f689SJohn Baldwin 				    strsig2(WTERMSIG(status)),
191034763d1cSJohn Baldwin 				    WCOREDUMP(status) ? ",cored" : "");
191134763d1cSJohn Baldwin 			else
1912f083f689SJohn Baldwin 				fprintf(fp, "STOPPED,sig=%s",
1913f083f689SJohn Baldwin 				    strsig2(WTERMSIG(status)));
1914f083f689SJohn Baldwin 			fputs(" }", fp);
191534763d1cSJohn Baldwin 		} else
1916f083f689SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
191734763d1cSJohn Baldwin 		break;
191834763d1cSJohn Baldwin 	}
191934763d1cSJohn Baldwin 	case Waitoptions:
19209289f547SJohn Baldwin 		print_mask_arg(sysdecode_wait6_options, fp, args[sc->offset]);
192134763d1cSJohn Baldwin 		break;
192234763d1cSJohn Baldwin 	case Idtype:
19239289f547SJohn Baldwin 		print_integer_arg(sysdecode_idtype, fp, args[sc->offset]);
192434763d1cSJohn Baldwin 		break;
192555648840SJohn Baldwin 	case Procctl:
19269289f547SJohn Baldwin 		print_integer_arg(sysdecode_procctl_cmd, fp, args[sc->offset]);
192755648840SJohn Baldwin 		break;
1928fdb5bf37SJohn Baldwin 	case Umtxop:
19299289f547SJohn Baldwin 		print_integer_arg(sysdecode_umtx_op, fp, args[sc->offset]);
1930fdb5bf37SJohn Baldwin 		break;
19317d897327SJohn Baldwin 	case Atfd:
19329289f547SJohn Baldwin 		print_integer_arg(sysdecode_atfd, fp, args[sc->offset]);
19337d897327SJohn Baldwin 		break;
19347d897327SJohn Baldwin 	case Atflags:
1935f083f689SJohn Baldwin 		fputs(xlookup_bits(at_flags, args[sc->offset]), fp);
19367d897327SJohn Baldwin 		break;
19377d897327SJohn Baldwin 	case Accessmode:
19389289f547SJohn Baldwin 		print_mask_arg(sysdecode_access_mode, fp, args[sc->offset]);
19397d897327SJohn Baldwin 		break;
1940b289a8d7SJohn Baldwin 	case Sysarch:
1941f083f689SJohn Baldwin 		fputs(xlookup(sysarch_ops, args[sc->offset]), fp);
1942b289a8d7SJohn Baldwin 		break;
19432b75c8adSJohn Baldwin 	case PipeFds:
19442b75c8adSJohn Baldwin 		/*
19452b75c8adSJohn Baldwin 		 * The pipe() system call in the kernel returns its
19462b75c8adSJohn Baldwin 		 * two file descriptors via return values.  However,
19472b75c8adSJohn Baldwin 		 * the interface exposed by libc is that pipe()
19482b75c8adSJohn Baldwin 		 * accepts a pointer to an array of descriptors.
19492b75c8adSJohn Baldwin 		 * Format the output to match the libc API by printing
19502b75c8adSJohn Baldwin 		 * the returned file descriptors as a fake argument.
19512b75c8adSJohn Baldwin 		 *
19522b75c8adSJohn Baldwin 		 * Overwrite the first retval to signal a successful
19532b75c8adSJohn Baldwin 		 * return as well.
19542b75c8adSJohn Baldwin 		 */
19552b75c8adSJohn Baldwin 		fprintf(fp, "{ %ld, %ld }", retval[0], retval[1]);
19562b75c8adSJohn Baldwin 		retval[0] = 0;
19572b75c8adSJohn Baldwin 		break;
1958195aef99SBryan Drewery 	case Utrace: {
1959195aef99SBryan Drewery 		size_t len;
1960195aef99SBryan Drewery 		void *utrace_addr;
1961195aef99SBryan Drewery 
1962195aef99SBryan Drewery 		len = args[sc->offset + 1];
1963195aef99SBryan Drewery 		utrace_addr = calloc(1, len);
1964195aef99SBryan Drewery 		if (get_struct(pid, (void *)args[sc->offset],
1965195aef99SBryan Drewery 		    (void *)utrace_addr, len) != -1)
1966195aef99SBryan Drewery 			print_utrace(fp, utrace_addr, len);
1967195aef99SBryan Drewery 		else
1968195aef99SBryan Drewery 			fprintf(fp, "0x%lx", args[sc->offset]);
1969195aef99SBryan Drewery 		free(utrace_addr);
1970195aef99SBryan Drewery 		break;
1971195aef99SBryan Drewery 	}
1972808d9805SEd Schouten 	case IntArray: {
1973808d9805SEd Schouten 		int descriptors[16];
1974808d9805SEd Schouten 		unsigned long i, ndescriptors;
1975808d9805SEd Schouten 		bool truncated;
1976808d9805SEd Schouten 
1977808d9805SEd Schouten 		ndescriptors = args[sc->offset + 1];
1978808d9805SEd Schouten 		truncated = false;
1979808d9805SEd Schouten 		if (ndescriptors > nitems(descriptors)) {
1980808d9805SEd Schouten 			ndescriptors = nitems(descriptors);
1981808d9805SEd Schouten 			truncated = true;
1982808d9805SEd Schouten 		}
1983808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset],
1984808d9805SEd Schouten 		    descriptors, ndescriptors * sizeof(descriptors[0])) != -1) {
1985808d9805SEd Schouten 			fprintf(fp, "{");
1986808d9805SEd Schouten 			for (i = 0; i < ndescriptors; i++)
1987808d9805SEd Schouten 				fprintf(fp, i == 0 ? " %d" : ", %d",
1988808d9805SEd Schouten 				    descriptors[i]);
1989808d9805SEd Schouten 			fprintf(fp, truncated ? ", ... }" : " }");
1990808d9805SEd Schouten 		} else
1991808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
1992808d9805SEd Schouten 		break;
1993808d9805SEd Schouten 	}
19949289f547SJohn Baldwin 	case Pipe2:
19959289f547SJohn Baldwin 		print_mask_arg(sysdecode_pipe2_flags, fp, args[sc->offset]);
19969289f547SJohn Baldwin 		break;
1997bed418c8SJohn Baldwin 	case CapFcntlRights: {
1998bed418c8SJohn Baldwin 		uint32_t rights;
1999bed418c8SJohn Baldwin 
2000bed418c8SJohn Baldwin 		if (sc->type & OUT) {
2001bed418c8SJohn Baldwin 			if (get_struct(pid, (void *)args[sc->offset], &rights,
2002bed418c8SJohn Baldwin 			    sizeof(rights)) == -1) {
2003bed418c8SJohn Baldwin 				fprintf(fp, "0x%lx", args[sc->offset]);
2004bed418c8SJohn Baldwin 				break;
2005bed418c8SJohn Baldwin 			}
2006bed418c8SJohn Baldwin 		} else
2007bed418c8SJohn Baldwin 			rights = args[sc->offset];
2008bed418c8SJohn Baldwin 		print_mask_arg32(sysdecode_cap_fcntlrights, fp, rights);
2009bed418c8SJohn Baldwin 		break;
2010bed418c8SJohn Baldwin 	}
2011d2a97485SJohn Baldwin 	case Fadvice:
2012d2a97485SJohn Baldwin 		print_integer_arg(sysdecode_fadvice, fp, args[sc->offset]);
2013d2a97485SJohn Baldwin 		break;
201427459358SJohn Baldwin 	case FileFlags: {
201527459358SJohn Baldwin 		fflags_t rem;
201627459358SJohn Baldwin 
201727459358SJohn Baldwin 		if (!sysdecode_fileflags(fp, args[sc->offset], &rem))
201827459358SJohn Baldwin 			fprintf(fp, "0x%x", rem);
201927459358SJohn Baldwin 		else if (rem != 0)
202027459358SJohn Baldwin 			fprintf(fp, "|0x%x", rem);
202127459358SJohn Baldwin 		break;
202227459358SJohn Baldwin 	}
2023dd92181fSJohn Baldwin 	case Flockop:
2024dd92181fSJohn Baldwin 		print_mask_arg(sysdecode_flock_operation, fp, args[sc->offset]);
2025dd92181fSJohn Baldwin 		break;
2026ab43bedcSJohn Baldwin 	case Getfsstatmode:
2027ab43bedcSJohn Baldwin 		print_integer_arg(sysdecode_getfsstat_mode, fp,
2028ab43bedcSJohn Baldwin 		    args[sc->offset]);
2029ab43bedcSJohn Baldwin 		break;
203094e854c5SJohn Baldwin 	case Kldsymcmd:
203194e854c5SJohn Baldwin 		print_integer_arg(sysdecode_kldsym_cmd, fp, args[sc->offset]);
203294e854c5SJohn Baldwin 		break;
203394e854c5SJohn Baldwin 	case Kldunloadflags:
203494e854c5SJohn Baldwin 		print_integer_arg(sysdecode_kldunload_flags, fp,
203594e854c5SJohn Baldwin 		    args[sc->offset]);
203694e854c5SJohn Baldwin 		break;
203798fdbeecSJohn Baldwin 	case Madvice:
203898fdbeecSJohn Baldwin 		print_integer_arg(sysdecode_madvice, fp, args[sc->offset]);
203998fdbeecSJohn Baldwin 		break;
204058227c60SMichael Tuexen 	case Socklent:
204158227c60SMichael Tuexen 		fprintf(fp, "%u", (socklen_t)args[sc->offset]);
204258227c60SMichael Tuexen 		break;
2043ecac235bSMichael Tuexen 	case Sockprotocol: {
2044738a93a4SMichael Tuexen 		const char *temp;
2045738a93a4SMichael Tuexen 		int domain, protocol;
2046ecac235bSMichael Tuexen 
2047738a93a4SMichael Tuexen 		domain = args[sc->offset - 2];
2048ecac235bSMichael Tuexen 		protocol = args[sc->offset];
2049ecac235bSMichael Tuexen 		if (protocol == 0) {
2050ecac235bSMichael Tuexen 			fputs("0", fp);
2051ecac235bSMichael Tuexen 		} else {
2052738a93a4SMichael Tuexen 			temp = sysdecode_socket_protocol(domain, protocol);
2053738a93a4SMichael Tuexen 			if (temp) {
2054738a93a4SMichael Tuexen 				fputs(temp, fp);
2055738a93a4SMichael Tuexen 			} else {
2056738a93a4SMichael Tuexen 				fprintf(fp, "%d", protocol);
2057738a93a4SMichael Tuexen 			}
2058ecac235bSMichael Tuexen 		}
2059ecac235bSMichael Tuexen 		break;
2060ecac235bSMichael Tuexen 	}
2061832af457SMichael Tuexen 	case Sockoptlevel:
2062832af457SMichael Tuexen 		print_integer_arg(sysdecode_sockopt_level, fp,
2063832af457SMichael Tuexen 		    args[sc->offset]);
2064832af457SMichael Tuexen 		break;
2065832af457SMichael Tuexen 	case Sockoptname: {
2066832af457SMichael Tuexen 		const char *temp;
2067832af457SMichael Tuexen 		int level, name;
2068832af457SMichael Tuexen 
2069832af457SMichael Tuexen 		level = args[sc->offset - 1];
2070832af457SMichael Tuexen 		name = args[sc->offset];
2071832af457SMichael Tuexen 		temp = sysdecode_sockopt_name(level, name);
2072832af457SMichael Tuexen 		if (temp) {
2073832af457SMichael Tuexen 			fputs(temp, fp);
2074832af457SMichael Tuexen 		} else {
2075832af457SMichael Tuexen 			fprintf(fp, "%d", name);
2076832af457SMichael Tuexen 		}
2077832af457SMichael Tuexen 		break;
2078832af457SMichael Tuexen 	}
20798b429b65SMichael Tuexen 	case Msgflags:
20808b429b65SMichael Tuexen 		print_mask_arg(sysdecode_msg_flags, fp, args[sc->offset]);
20818b429b65SMichael Tuexen 		break;
20827136a1d9SJohn Baldwin 	case CapRights: {
20837136a1d9SJohn Baldwin 		cap_rights_t rights;
20847136a1d9SJohn Baldwin 
20857136a1d9SJohn Baldwin 		if (get_struct(pid, (void *)args[sc->offset], &rights,
20867136a1d9SJohn Baldwin 		    sizeof(rights)) != -1) {
20877136a1d9SJohn Baldwin 			fputs("{ ", fp);
20887136a1d9SJohn Baldwin 			sysdecode_cap_rights(fp, &rights);
20897136a1d9SJohn Baldwin 			fputs(" }", fp);
20907136a1d9SJohn Baldwin 		} else
20917136a1d9SJohn Baldwin 			fprintf(fp, "0x%lx", args[sc->offset]);
20927136a1d9SJohn Baldwin 		break;
20937136a1d9SJohn Baldwin 	}
20947ce44f08SJohn Baldwin 	case Acltype:
20957ce44f08SJohn Baldwin 		print_integer_arg(sysdecode_acltype, fp, args[sc->offset]);
20967ce44f08SJohn Baldwin 		break;
2097*26606dcaSJohn Baldwin 	case Extattrnamespace:
2098*26606dcaSJohn Baldwin 		print_integer_arg(sysdecode_extattrnamespace, fp,
2099*26606dcaSJohn Baldwin 		    args[sc->offset]);
2100*26606dcaSJohn Baldwin 		break;
2101808d9805SEd Schouten 
2102808d9805SEd Schouten 	case CloudABIAdvice:
2103808d9805SEd Schouten 		fputs(xlookup(cloudabi_advice, args[sc->offset]), fp);
2104808d9805SEd Schouten 		break;
2105808d9805SEd Schouten 	case CloudABIClockID:
2106808d9805SEd Schouten 		fputs(xlookup(cloudabi_clockid, args[sc->offset]), fp);
2107808d9805SEd Schouten 		break;
2108808d9805SEd Schouten 	case ClouduABIFDSFlags:
2109808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_fdsflags, args[sc->offset]), fp);
2110808d9805SEd Schouten 		break;
2111808d9805SEd Schouten 	case CloudABIFDStat: {
2112808d9805SEd Schouten 		cloudabi_fdstat_t fds;
2113808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset], &fds, sizeof(fds))
2114808d9805SEd Schouten 		    != -1) {
2115808d9805SEd Schouten 			fprintf(fp, "{ %s, ",
2116808d9805SEd Schouten 			    xlookup(cloudabi_filetype, fds.fs_filetype));
2117808d9805SEd Schouten 			fprintf(fp, "%s, ... }",
2118808d9805SEd Schouten 			    xlookup_bits(cloudabi_fdflags, fds.fs_flags));
2119808d9805SEd Schouten 		} else
2120808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
2121808d9805SEd Schouten 		break;
2122808d9805SEd Schouten 	}
2123808d9805SEd Schouten 	case CloudABIFileStat: {
2124808d9805SEd Schouten 		cloudabi_filestat_t fsb;
2125808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset], &fsb, sizeof(fsb))
2126808d9805SEd Schouten 		    != -1)
21279ba32307SJohn Baldwin 			fprintf(fp, "{ %s, %ju }",
2128808d9805SEd Schouten 			    xlookup(cloudabi_filetype, fsb.st_filetype),
21299ba32307SJohn Baldwin 			    (uintmax_t)fsb.st_size);
2130808d9805SEd Schouten 		else
2131808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
2132808d9805SEd Schouten 		break;
2133808d9805SEd Schouten 	}
2134808d9805SEd Schouten 	case CloudABIFileType:
2135808d9805SEd Schouten 		fputs(xlookup(cloudabi_filetype, args[sc->offset]), fp);
2136808d9805SEd Schouten 		break;
2137808d9805SEd Schouten 	case CloudABIFSFlags:
2138808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_fsflags, args[sc->offset]), fp);
2139808d9805SEd Schouten 		break;
2140808d9805SEd Schouten 	case CloudABILookup:
2141808d9805SEd Schouten 		if ((args[sc->offset] & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0)
2142808d9805SEd Schouten 			fprintf(fp, "%d|LOOKUP_SYMLINK_FOLLOW",
2143808d9805SEd Schouten 			    (int)args[sc->offset]);
2144808d9805SEd Schouten 		else
2145808d9805SEd Schouten 			fprintf(fp, "%d", (int)args[sc->offset]);
2146808d9805SEd Schouten 		break;
2147808d9805SEd Schouten 	case CloudABIMFlags:
2148808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_mflags, args[sc->offset]), fp);
2149808d9805SEd Schouten 		break;
2150808d9805SEd Schouten 	case CloudABIMProt:
2151808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_mprot, args[sc->offset]), fp);
2152808d9805SEd Schouten 		break;
2153808d9805SEd Schouten 	case CloudABIMSFlags:
2154808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_msflags, args[sc->offset]), fp);
2155808d9805SEd Schouten 		break;
2156808d9805SEd Schouten 	case CloudABIOFlags:
2157808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_oflags, args[sc->offset]), fp);
2158808d9805SEd Schouten 		break;
2159808d9805SEd Schouten 	case CloudABISDFlags:
2160808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_sdflags, args[sc->offset]), fp);
2161808d9805SEd Schouten 		break;
2162808d9805SEd Schouten 	case CloudABISignal:
2163808d9805SEd Schouten 		fputs(xlookup(cloudabi_signal, args[sc->offset]), fp);
2164808d9805SEd Schouten 		break;
2165808d9805SEd Schouten 	case CloudABISockStat: {
2166808d9805SEd Schouten 		cloudabi_sockstat_t ss;
2167808d9805SEd Schouten 		if (get_struct(pid, (void *)args[sc->offset], &ss, sizeof(ss))
2168808d9805SEd Schouten 		    != -1) {
2169808d9805SEd Schouten 			fprintf(fp, "{ %s, ", xlookup(
2170808d9805SEd Schouten 			    cloudabi_sa_family, ss.ss_sockname.sa_family));
2171808d9805SEd Schouten 			fprintf(fp, "%s, ", xlookup(
2172808d9805SEd Schouten 			    cloudabi_sa_family, ss.ss_peername.sa_family));
2173808d9805SEd Schouten 			fprintf(fp, "%s, ", xlookup(
2174808d9805SEd Schouten 			    cloudabi_errno, ss.ss_error));
2175808d9805SEd Schouten 			fprintf(fp, "%s }", xlookup_bits(
2176808d9805SEd Schouten 			    cloudabi_ssstate, ss.ss_state));
2177808d9805SEd Schouten 		} else
2178808d9805SEd Schouten 			fprintf(fp, "0x%lx", args[sc->offset]);
2179808d9805SEd Schouten 		break;
2180808d9805SEd Schouten 	}
2181808d9805SEd Schouten 	case CloudABISSFlags:
2182808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_ssflags, args[sc->offset]), fp);
2183808d9805SEd Schouten 		break;
2184808d9805SEd Schouten 	case CloudABITimestamp:
2185808d9805SEd Schouten 		fprintf(fp, "%lu.%09lus", args[sc->offset] / 1000000000,
2186808d9805SEd Schouten 		    args[sc->offset] % 1000000000);
2187808d9805SEd Schouten 		break;
2188808d9805SEd Schouten 	case CloudABIULFlags:
2189808d9805SEd Schouten 		fputs(xlookup_bits(cloudabi_ulflags, args[sc->offset]), fp);
2190808d9805SEd Schouten 		break;
2191808d9805SEd Schouten 	case CloudABIWhence:
2192808d9805SEd Schouten 		fputs(xlookup(cloudabi_whence, args[sc->offset]), fp);
2193808d9805SEd Schouten 		break;
2194808d9805SEd Schouten 
2195081e5c48SPav Lucistnik 	default:
2196081e5c48SPav Lucistnik 		errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK);
2197bbeaf6c0SSean Eric Fagan 	}
2198f083f689SJohn Baldwin 	fclose(fp);
2199d8984f48SDag-Erling Smørgrav 	return (tmp);
2200bbeaf6c0SSean Eric Fagan }
2201bbeaf6c0SSean Eric Fagan 
2202bbeaf6c0SSean Eric Fagan /*
220300ddbdf2SJohn Baldwin  * Print (to outfile) the system call and its arguments.
2204bbeaf6c0SSean Eric Fagan  */
2205bbeaf6c0SSean Eric Fagan void
220600ddbdf2SJohn Baldwin print_syscall(struct trussinfo *trussinfo)
2207d8984f48SDag-Erling Smørgrav {
220800ddbdf2SJohn Baldwin 	struct threadinfo *t;
220900ddbdf2SJohn Baldwin 	const char *name;
221000ddbdf2SJohn Baldwin 	char **s_args;
221100ddbdf2SJohn Baldwin 	int i, len, nargs;
22120d0bd00eSMatthew N. Dodd 
221300ddbdf2SJohn Baldwin 	t = trussinfo->curthread;
2214c03bfcc8SMatthew N. Dodd 
22151175b23fSJohn Baldwin 	name = t->cs.sc->name;
221600ddbdf2SJohn Baldwin 	nargs = t->cs.nargs;
221700ddbdf2SJohn Baldwin 	s_args = t->cs.s_args;
22180d0bd00eSMatthew N. Dodd 
2219d70876fdSJohn Baldwin 	len = print_line_prefix(trussinfo);
2220ec0bed25SMatthew N. Dodd 	len += fprintf(trussinfo->outfile, "%s(", name);
2221c03bfcc8SMatthew N. Dodd 
2222bbeaf6c0SSean Eric Fagan 	for (i = 0; i < nargs; i++) {
222300ddbdf2SJohn Baldwin 		if (s_args[i] != NULL)
2224ec0bed25SMatthew N. Dodd 			len += fprintf(trussinfo->outfile, "%s", s_args[i]);
2225bbeaf6c0SSean Eric Fagan 		else
222694355cfdSAndrey Zonov 			len += fprintf(trussinfo->outfile,
222794355cfdSAndrey Zonov 			    "<missing argument>");
222894355cfdSAndrey Zonov 		len += fprintf(trussinfo->outfile, "%s", i < (nargs - 1) ?
222994355cfdSAndrey Zonov 		    "," : "");
2230bbeaf6c0SSean Eric Fagan 	}
2231ec0bed25SMatthew N. Dodd 	len += fprintf(trussinfo->outfile, ")");
22326cb533feSSean Eric Fagan 	for (i = 0; i < 6 - (len / 8); i++)
2233ec0bed25SMatthew N. Dodd 		fprintf(trussinfo->outfile, "\t");
22346cb533feSSean Eric Fagan }
22356cb533feSSean Eric Fagan 
22366cb533feSSean Eric Fagan void
223700ddbdf2SJohn Baldwin print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval)
22381bcb5f5aSMarcel Moolenaar {
2239ee3b0f6eSDiomidis Spinellis 	struct timespec timediff;
224000ddbdf2SJohn Baldwin 	struct threadinfo *t;
224100ddbdf2SJohn Baldwin 	struct syscall *sc;
2242287b96ddSJohn Baldwin 	int error;
2243ee3b0f6eSDiomidis Spinellis 
224400ddbdf2SJohn Baldwin 	t = trussinfo->curthread;
224500ddbdf2SJohn Baldwin 	sc = t->cs.sc;
2246ee3b0f6eSDiomidis Spinellis 	if (trussinfo->flags & COUNTONLY) {
224700ddbdf2SJohn Baldwin 		timespecsubt(&t->after, &t->before, &timediff);
2248d9dcc463SXin LI 		timespecadd(&sc->time, &timediff, &sc->time);
2249ee3b0f6eSDiomidis Spinellis 		sc->ncalls++;
2250ee3b0f6eSDiomidis Spinellis 		if (errorp)
2251ee3b0f6eSDiomidis Spinellis 			sc->nerror++;
2252ee3b0f6eSDiomidis Spinellis 		return;
2253ee3b0f6eSDiomidis Spinellis 	}
2254d8984f48SDag-Erling Smørgrav 
225500ddbdf2SJohn Baldwin 	print_syscall(trussinfo);
22560cf21b4fSBrian Somers 	fflush(trussinfo->outfile);
2257b9befd33SJohn Baldwin 
2258b9befd33SJohn Baldwin 	if (retval == NULL) {
2259b9befd33SJohn Baldwin 		/*
2260b9befd33SJohn Baldwin 		 * This system call resulted in the current thread's exit,
2261b9befd33SJohn Baldwin 		 * so there is no return value or error to display.
2262b9befd33SJohn Baldwin 		 */
2263b9befd33SJohn Baldwin 		fprintf(trussinfo->outfile, "\n");
2264b9befd33SJohn Baldwin 		return;
2265b9befd33SJohn Baldwin 	}
2266b9befd33SJohn Baldwin 
2267287b96ddSJohn Baldwin 	if (errorp) {
2268287b96ddSJohn Baldwin 		error = sysdecode_abi_to_freebsd_errno(t->proc->abi->abi,
2269287b96ddSJohn Baldwin 		    retval[0]);
22702b75c8adSJohn Baldwin 		fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval[0],
2271287b96ddSJohn Baldwin 		    error == INT_MAX ? "Unknown error" : strerror(error));
2272287b96ddSJohn Baldwin 	}
22732b75c8adSJohn Baldwin #ifndef __LP64__
22746c61b0f3SBryan Drewery 	else if (sc->ret_type == 2) {
22752b75c8adSJohn Baldwin 		off_t off;
22762b75c8adSJohn Baldwin 
22772b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN
22782b75c8adSJohn Baldwin 		off = (off_t)retval[1] << 32 | retval[0];
22792b75c8adSJohn Baldwin #else
22802b75c8adSJohn Baldwin 		off = (off_t)retval[0] << 32 | retval[1];
22812b75c8adSJohn Baldwin #endif
22822b75c8adSJohn Baldwin 		fprintf(trussinfo->outfile, " = %jd (0x%jx)\n", (intmax_t)off,
22832b75c8adSJohn Baldwin 		    (intmax_t)off);
22846cb533feSSean Eric Fagan 	}
22852b75c8adSJohn Baldwin #endif
22862b75c8adSJohn Baldwin 	else
22872b75c8adSJohn Baldwin 		fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval[0],
22882b75c8adSJohn Baldwin 		    retval[0]);
2289bbeaf6c0SSean Eric Fagan }
2290ee3b0f6eSDiomidis Spinellis 
2291ee3b0f6eSDiomidis Spinellis void
2292ee3b0f6eSDiomidis Spinellis print_summary(struct trussinfo *trussinfo)
2293ee3b0f6eSDiomidis Spinellis {
2294ee3b0f6eSDiomidis Spinellis 	struct timespec total = {0, 0};
229594355cfdSAndrey Zonov 	struct syscall *sc;
2296ee3b0f6eSDiomidis Spinellis 	int ncall, nerror;
2297ee3b0f6eSDiomidis Spinellis 
2298ee3b0f6eSDiomidis Spinellis 	fprintf(trussinfo->outfile, "%-20s%15s%8s%8s\n",
2299ee3b0f6eSDiomidis Spinellis 	    "syscall", "seconds", "calls", "errors");
2300ee3b0f6eSDiomidis Spinellis 	ncall = nerror = 0;
23016c61b0f3SBryan Drewery 	STAILQ_FOREACH(sc, &syscalls, entries)
2302ee3b0f6eSDiomidis Spinellis 		if (sc->ncalls) {
230355a8d2bbSJaakko Heinonen 			fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n",
230455a8d2bbSJaakko Heinonen 			    sc->name, (intmax_t)sc->time.tv_sec,
230555a8d2bbSJaakko Heinonen 			    sc->time.tv_nsec, sc->ncalls, sc->nerror);
2306d9dcc463SXin LI 			timespecadd(&total, &sc->time, &total);
2307ee3b0f6eSDiomidis Spinellis 			ncall += sc->ncalls;
2308ee3b0f6eSDiomidis Spinellis 			nerror += sc->nerror;
2309ee3b0f6eSDiomidis Spinellis 		}
2310ee3b0f6eSDiomidis Spinellis 	fprintf(trussinfo->outfile, "%20s%15s%8s%8s\n",
2311ee3b0f6eSDiomidis Spinellis 	    "", "-------------", "-------", "-------");
231255a8d2bbSJaakko Heinonen 	fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n",
231355a8d2bbSJaakko Heinonen 	    "", (intmax_t)total.tv_sec, total.tv_nsec, ncall, nerror);
2314ee3b0f6eSDiomidis Spinellis }
2315