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 } } }, 16326606dcaSJohn Baldwin { .name = "extattr_delete_fd", .ret_type = 1, .nargs = 3, 16426606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } }, 16526606dcaSJohn Baldwin { .name = "extattr_delete_file", .ret_type = 1, .nargs = 3, 16626606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } }, 16726606dcaSJohn Baldwin { .name = "extattr_delete_link", .ret_type = 1, .nargs = 3, 16826606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 } } }, 16926606dcaSJohn Baldwin { .name = "extattr_get_fd", .ret_type = 1, .nargs = 5, 17026606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 }, 17126606dcaSJohn Baldwin { BinString | OUT, 3 }, { Sizet, 4 } } }, 17226606dcaSJohn Baldwin { .name = "extattr_get_file", .ret_type = 1, .nargs = 5, 17326606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 }, 17426606dcaSJohn Baldwin { BinString | OUT, 3 }, { Sizet, 4 } } }, 17526606dcaSJohn Baldwin { .name = "extattr_get_link", .ret_type = 1, .nargs = 5, 17626606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 }, 17726606dcaSJohn Baldwin { BinString | OUT, 3 }, { Sizet, 4 } } }, 17826606dcaSJohn Baldwin { .name = "extattr_list_fd", .ret_type = 1, .nargs = 4, 17926606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 }, 18026606dcaSJohn Baldwin { Sizet, 3 } } }, 18126606dcaSJohn Baldwin { .name = "extattr_list_file", .ret_type = 1, .nargs = 4, 18226606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 }, 18326606dcaSJohn Baldwin { Sizet, 3 } } }, 18426606dcaSJohn Baldwin { .name = "extattr_list_link", .ret_type = 1, .nargs = 4, 18526606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { BinString | OUT, 2 }, 18626606dcaSJohn Baldwin { Sizet, 3 } } }, 18726606dcaSJohn Baldwin { .name = "extattr_set_fd", .ret_type = 1, .nargs = 5, 18826606dcaSJohn Baldwin .args = { { Int, 0 }, { Extattrnamespace, 1 }, { Name, 2 }, 18926606dcaSJohn Baldwin { BinString | IN, 3 }, { Sizet, 4 } } }, 19026606dcaSJohn Baldwin { .name = "extattr_set_file", .ret_type = 1, .nargs = 5, 19126606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 }, 19226606dcaSJohn Baldwin { BinString | IN, 3 }, { Sizet, 4 } } }, 19326606dcaSJohn Baldwin { .name = "extattr_set_link", .ret_type = 1, .nargs = 5, 19426606dcaSJohn Baldwin .args = { { Name, 0 }, { Extattrnamespace, 1 }, { Name, 2 }, 19526606dcaSJohn Baldwin { BinString | IN, 3 }, { Sizet, 4 } } }, 19626606dcaSJohn Baldwin { .name = "extattrctl", .ret_type = 1, .nargs = 5, 19726606dcaSJohn Baldwin .args = { { Name, 0 }, { Hex, 1 }, { Name, 2 }, 19826606dcaSJohn 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 } } }, 243ad419d33SJohn Baldwin { .name = "getpriority", .ret_type = 1, .nargs = 2, 244ad419d33SJohn Baldwin .args = { { Priowhich, 0 }, { Int, 1 } } }, 245f44fc79dSJohn Baldwin { .name = "getrlimit", .ret_type = 1, .nargs = 2, 246f44fc79dSJohn Baldwin .args = { { Resource, 0 }, { Rlimit | OUT, 1 } } }, 247f44fc79dSJohn Baldwin { .name = "getrusage", .ret_type = 1, .nargs = 2, 248ee8aa41dSJohn Baldwin .args = { { RusageWho, 0 }, { Rusage | OUT, 1 } } }, 249f44fc79dSJohn Baldwin { .name = "getsid", .ret_type = 1, .nargs = 1, 250f44fc79dSJohn Baldwin .args = { { Int, 0 } } }, 251f44fc79dSJohn Baldwin { .name = "getsockname", .ret_type = 1, .nargs = 3, 252f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } }, 253832af457SMichael Tuexen { .name = "getsockopt", .ret_type = 1, .nargs = 5, 254832af457SMichael Tuexen .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 }, 255832af457SMichael Tuexen { Ptr | OUT, 3 }, { Ptr | OUT, 4 } } }, 256f44fc79dSJohn Baldwin { .name = "gettimeofday", .ret_type = 1, .nargs = 2, 257f44fc79dSJohn Baldwin .args = { { Timeval | OUT, 0 }, { Ptr, 1 } } }, 258f44fc79dSJohn Baldwin { .name = "ioctl", .ret_type = 1, .nargs = 3, 259a776eeafSJohn Baldwin .args = { { Int, 0 }, { Ioctl, 1 }, { Ptr, 2 } } }, 260f44fc79dSJohn Baldwin { .name = "kevent", .ret_type = 1, .nargs = 6, 261f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 }, 262f44fc79dSJohn Baldwin { Int, 4 }, { Timespec, 5 } } }, 263f44fc79dSJohn Baldwin { .name = "kill", .ret_type = 1, .nargs = 2, 264f44fc79dSJohn Baldwin .args = { { Int | IN, 0 }, { Signal | IN, 1 } } }, 265f44fc79dSJohn Baldwin { .name = "kldfind", .ret_type = 1, .nargs = 1, 266f44fc79dSJohn Baldwin .args = { { Name | IN, 0 } } }, 267f44fc79dSJohn Baldwin { .name = "kldfirstmod", .ret_type = 1, .nargs = 1, 268f44fc79dSJohn Baldwin .args = { { Int, 0 } } }, 269f44fc79dSJohn Baldwin { .name = "kldload", .ret_type = 1, .nargs = 1, 270f44fc79dSJohn Baldwin .args = { { Name | IN, 0 } } }, 271f44fc79dSJohn Baldwin { .name = "kldnext", .ret_type = 1, .nargs = 1, 272f44fc79dSJohn Baldwin .args = { { Int, 0 } } }, 273f44fc79dSJohn Baldwin { .name = "kldstat", .ret_type = 1, .nargs = 2, 274f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Ptr, 1 } } }, 27594e854c5SJohn Baldwin { .name = "kldsym", .ret_type = 1, .nargs = 3, 27694e854c5SJohn Baldwin .args = { { Int, 0 }, { Kldsymcmd, 1 }, { Ptr, 2 } } }, 277f44fc79dSJohn Baldwin { .name = "kldunload", .ret_type = 1, .nargs = 1, 278f44fc79dSJohn Baldwin .args = { { Int, 0 } } }, 27994e854c5SJohn Baldwin { .name = "kldunloadf", .ret_type = 1, .nargs = 2, 28094e854c5SJohn Baldwin .args = { { Int, 0 }, { Kldunloadflags, 1 } } }, 281f44fc79dSJohn Baldwin { .name = "kse_release", .ret_type = 0, .nargs = 1, 282f44fc79dSJohn Baldwin .args = { { Timespec, 0 } } }, 283f44fc79dSJohn Baldwin { .name = "lchflags", .ret_type = 1, .nargs = 2, 28427459358SJohn Baldwin .args = { { Name | IN, 0 }, { FileFlags, 1 } } }, 285f44fc79dSJohn Baldwin { .name = "lchmod", .ret_type = 1, .nargs = 2, 286f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 } } }, 287f44fc79dSJohn Baldwin { .name = "lchown", .ret_type = 1, .nargs = 3, 288f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } }, 2892b75c8adSJohn Baldwin { .name = "link", .ret_type = 1, .nargs = 2, 290ee3b0f6eSDiomidis Spinellis .args = { { Name, 0 }, { Name, 1 } } }, 2912b75c8adSJohn Baldwin { .name = "linkat", .ret_type = 1, .nargs = 5, 2927d897327SJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 }, 2937d897327SJohn Baldwin { Atflags, 4 } } }, 294e8d2c81dSMichael Tuexen { .name = "listen", .ret_type = 1, .nargs = 2, 295e8d2c81dSMichael Tuexen .args = { { Int, 0 }, { Int, 1 } } }, 296f44fc79dSJohn Baldwin { .name = "lseek", .ret_type = 2, .nargs = 3, 297c05cc0d6SJohn Baldwin .args = { { Int, 0 }, { QuadHex, 1 }, { Whence, 2 } } }, 298f44fc79dSJohn Baldwin { .name = "lstat", .ret_type = 1, .nargs = 2, 299f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } }, 300f44fc79dSJohn Baldwin { .name = "lutimes", .ret_type = 1, .nargs = 2, 301f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } }, 30298fdbeecSJohn Baldwin { .name = "madvise", .ret_type = 1, .nargs = 3, 30398fdbeecSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Madvice, 2 } } }, 3042d9c9988SJohn Baldwin { .name = "minherit", .ret_type = 1, .nargs = 3, 3052d9c9988SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Minherit, 2 } } }, 306f44fc79dSJohn Baldwin { .name = "mkdir", .ret_type = 1, .nargs = 2, 307f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 } } }, 308f44fc79dSJohn Baldwin { .name = "mkdirat", .ret_type = 1, .nargs = 3, 309f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } }, 3102b75c8adSJohn Baldwin { .name = "mkfifo", .ret_type = 1, .nargs = 2, 311e82ce59cSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 } } }, 3122b75c8adSJohn Baldwin { .name = "mkfifoat", .ret_type = 1, .nargs = 3, 3137d897327SJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } }, 3142b75c8adSJohn Baldwin { .name = "mknod", .ret_type = 1, .nargs = 3, 315e82ce59cSJohn Baldwin .args = { { Name, 0 }, { Octal, 1 }, { Int, 2 } } }, 3162b75c8adSJohn Baldwin { .name = "mknodat", .ret_type = 1, .nargs = 4, 3177d897327SJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Int, 3 } } }, 31894bde755SJohn Baldwin { .name = "mlock", .ret_type = 1, .nargs = 2, 31994bde755SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 } } }, 32094bde755SJohn Baldwin { .name = "mlockall", .ret_type = 1, .nargs = 1, 32194bde755SJohn Baldwin .args = { { Mlockall, 0 } } }, 322f44fc79dSJohn Baldwin { .name = "mmap", .ret_type = 1, .nargs = 6, 323e261fb2aSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 }, { Mmapflags, 3 }, 324c05cc0d6SJohn Baldwin { Int, 4 }, { QuadHex, 5 } } }, 325f44fc79dSJohn Baldwin { .name = "modfind", .ret_type = 1, .nargs = 1, 326f44fc79dSJohn Baldwin .args = { { Name | IN, 0 } } }, 3272b75c8adSJohn Baldwin { .name = "mount", .ret_type = 1, .nargs = 4, 3288acc8e78SJohn Baldwin .args = { { Name, 0 }, { Name, 1 }, { Mountflags, 2 }, { Ptr, 3 } } }, 329f44fc79dSJohn Baldwin { .name = "mprotect", .ret_type = 1, .nargs = 3, 330e261fb2aSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Mprot, 2 } } }, 331114aeee0SJohn Baldwin { .name = "msync", .ret_type = 1, .nargs = 3, 332114aeee0SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 }, { Msync, 2 } } }, 33394bde755SJohn Baldwin { .name = "munlock", .ret_type = 1, .nargs = 2, 33494bde755SJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 } } }, 335f44fc79dSJohn Baldwin { .name = "munmap", .ret_type = 1, .nargs = 2, 336e261fb2aSJohn Baldwin .args = { { Ptr, 0 }, { Sizet, 1 } } }, 337f44fc79dSJohn Baldwin { .name = "nanosleep", .ret_type = 1, .nargs = 1, 338f44fc79dSJohn Baldwin .args = { { Timespec, 0 } } }, 3398acc8e78SJohn Baldwin { .name = "nmount", .ret_type = 1, .nargs = 3, 3408acc8e78SJohn Baldwin .args = { { Ptr, 0 }, { UInt, 1 }, { Mountflags, 2 } } }, 341f44fc79dSJohn Baldwin { .name = "open", .ret_type = 1, .nargs = 3, 342f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } }, 343f44fc79dSJohn Baldwin { .name = "openat", .ret_type = 1, .nargs = 4, 344f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 }, 345f44fc79dSJohn Baldwin { Octal, 3 } } }, 346f44fc79dSJohn Baldwin { .name = "pathconf", .ret_type = 1, .nargs = 2, 347f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Pathconf, 1 } } }, 348f44fc79dSJohn Baldwin { .name = "pipe", .ret_type = 1, .nargs = 1, 349f44fc79dSJohn Baldwin .args = { { PipeFds | OUT, 0 } } }, 350f44fc79dSJohn Baldwin { .name = "pipe2", .ret_type = 1, .nargs = 2, 3519289f547SJohn Baldwin .args = { { Ptr, 0 }, { Pipe2, 1 } } }, 352f44fc79dSJohn Baldwin { .name = "poll", .ret_type = 1, .nargs = 3, 353f44fc79dSJohn Baldwin .args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } }, 354d2a97485SJohn Baldwin { .name = "posix_fadvise", .ret_type = 1, .nargs = 4, 355d2a97485SJohn Baldwin .args = { { Int, 0 }, { QuadHex, 1 }, { QuadHex, 2 }, 356d2a97485SJohn Baldwin { Fadvice, 3 } } }, 357f44fc79dSJohn Baldwin { .name = "posix_openpt", .ret_type = 1, .nargs = 1, 358f44fc79dSJohn Baldwin .args = { { Open, 0 } } }, 359b60a095bSJohn Baldwin { .name = "pread", .ret_type = 1, .nargs = 4, 360b60a095bSJohn Baldwin .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 }, 361b60a095bSJohn Baldwin { QuadHex, 3 } } }, 362f44fc79dSJohn Baldwin { .name = "procctl", .ret_type = 1, .nargs = 4, 363c05cc0d6SJohn Baldwin .args = { { Idtype, 0 }, { Quad, 1 }, { Procctl, 2 }, { Ptr, 3 } } }, 3645ac1c7acSJohn Baldwin { .name = "ptrace", .ret_type = 1, .nargs = 4, 3655ac1c7acSJohn Baldwin .args = { { Ptraceop, 0 }, { Int, 1 }, { Ptr, 2 }, { Int, 3 } } }, 366b60a095bSJohn Baldwin { .name = "pwrite", .ret_type = 1, .nargs = 4, 367b60a095bSJohn Baldwin .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 }, 368b60a095bSJohn Baldwin { QuadHex, 3 } } }, 369*dd0c462cSJohn Baldwin { .name = "quotactl", .ret_type = 1, .nargs = 4, 370*dd0c462cSJohn Baldwin .args = { { Name, 0 }, { Quotactlcmd, 1 }, { Int, 2 }, { Ptr, 3 } } }, 371f44fc79dSJohn Baldwin { .name = "read", .ret_type = 1, .nargs = 3, 372e261fb2aSJohn Baldwin .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 } } }, 373f44fc79dSJohn Baldwin { .name = "readlink", .ret_type = 1, .nargs = 3, 374e261fb2aSJohn Baldwin .args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Sizet, 2 } } }, 375f44fc79dSJohn Baldwin { .name = "readlinkat", .ret_type = 1, .nargs = 4, 376f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 }, 377e261fb2aSJohn Baldwin { Sizet, 3 } } }, 378ee3b0f6eSDiomidis Spinellis { .name = "recvfrom", .ret_type = 1, .nargs = 6, 3798b429b65SMichael Tuexen .args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 }, 3808b429b65SMichael Tuexen { Msgflags, 3 }, { Sockaddr | OUT, 4 }, 3818b429b65SMichael Tuexen { Ptr | OUT, 5 } } }, 382fca08fe6SMichael Tuexen { .name = "recvmsg", .ret_type = 1, .nargs = 3, 383fca08fe6SMichael Tuexen .args = { { Int, 0 }, { Ptr, 1 }, { Msgflags, 2 } } }, 384f44fc79dSJohn Baldwin { .name = "rename", .ret_type = 1, .nargs = 2, 385f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Name, 1 } } }, 386f44fc79dSJohn Baldwin { .name = "renameat", .ret_type = 1, .nargs = 4, 387f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } }, 388f44fc79dSJohn Baldwin { .name = "rfork", .ret_type = 1, .nargs = 1, 389f44fc79dSJohn Baldwin .args = { { Rforkflags, 0 } } }, 390cca89ee3SBryan Drewery { .name = "rmdir", .ret_type = 1, .nargs = 1, 391cca89ee3SBryan Drewery .args = { { Name, 0 } } }, 392c0b72375SMichael Tuexen { .name = "sctp_generic_recvmsg", .ret_type = 1, .nargs = 7, 393c0b72375SMichael Tuexen .args = { { Int, 0 }, { Ptr | IN, 1 }, { Int, 2 }, 394c0b72375SMichael Tuexen { Sockaddr | OUT, 3 }, { Ptr | OUT, 4 }, { Ptr | OUT, 5 }, 395c0b72375SMichael Tuexen { Ptr | OUT, 6 } } }, 396c0b72375SMichael Tuexen { .name = "sctp_generic_sendmsg", .ret_type = 1, .nargs = 7, 397c0b72375SMichael Tuexen .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, 398c0b72375SMichael Tuexen { Sockaddr | IN, 3 }, { Socklent, 4 }, { Ptr | IN, 5 }, 399c0b72375SMichael Tuexen { Msgflags, 6 } } }, 400ee3b0f6eSDiomidis Spinellis { .name = "select", .ret_type = 1, .nargs = 5, 4010a46af44SJohn Baldwin .args = { { Int, 0 }, { Fd_set, 1 }, { Fd_set, 2 }, { Fd_set, 3 }, 4020a46af44SJohn Baldwin { Timeval, 4 } } }, 403fca08fe6SMichael Tuexen { .name = "sendmsg", .ret_type = 1, .nargs = 3, 404fca08fe6SMichael Tuexen .args = { { Int, 0 }, { Ptr, 1 }, { Msgflags, 2 } } }, 405f44fc79dSJohn Baldwin { .name = "sendto", .ret_type = 1, .nargs = 6, 4068b429b65SMichael Tuexen .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 }, 4078b429b65SMichael Tuexen { Msgflags, 3 }, { Sockaddr | IN, 4 }, 4088b429b65SMichael Tuexen { Socklent | IN, 5 } } }, 409ee3b0f6eSDiomidis Spinellis { .name = "setitimer", .ret_type = 1, .nargs = 3, 410ee3b0f6eSDiomidis Spinellis .args = { { Int, 0 }, { Itimerval, 1 }, { Itimerval | OUT, 2 } } }, 411ad419d33SJohn Baldwin { .name = "setpriority", .ret_type = 1, .nargs = 3, 412ad419d33SJohn Baldwin .args = { { Priowhich, 0 }, { Int, 1 }, { Int, 2 } } }, 413f44fc79dSJohn Baldwin { .name = "setrlimit", .ret_type = 1, .nargs = 2, 414f44fc79dSJohn Baldwin .args = { { Resource, 0 }, { Rlimit | IN, 1 } } }, 415832af457SMichael Tuexen { .name = "setsockopt", .ret_type = 1, .nargs = 5, 416832af457SMichael Tuexen .args = { { Int, 0 }, { Sockoptlevel, 1 }, { Sockoptname, 2 }, 417832af457SMichael Tuexen { Ptr | IN, 3 }, { Socklent, 4 } } }, 418f44fc79dSJohn Baldwin { .name = "shutdown", .ret_type = 1, .nargs = 2, 419f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Shutdown, 1 } } }, 420f44fc79dSJohn Baldwin { .name = "sigaction", .ret_type = 1, .nargs = 3, 421f44fc79dSJohn Baldwin .args = { { Signal, 0 }, { Sigaction | IN, 1 }, 422f44fc79dSJohn Baldwin { Sigaction | OUT, 2 } } }, 4232b75c8adSJohn Baldwin { .name = "sigpending", .ret_type = 1, .nargs = 1, 424b289a8d7SJohn Baldwin .args = { { Sigset | OUT, 0 } } }, 4252b75c8adSJohn Baldwin { .name = "sigprocmask", .ret_type = 1, .nargs = 3, 426ee3b0f6eSDiomidis Spinellis .args = { { Sigprocmask, 0 }, { Sigset, 1 }, { Sigset | OUT, 2 } } }, 4272b75c8adSJohn Baldwin { .name = "sigqueue", .ret_type = 1, .nargs = 3, 428b289a8d7SJohn Baldwin .args = { { Int, 0 }, { Signal, 1 }, { LongHex, 2 } } }, 4292b75c8adSJohn Baldwin { .name = "sigreturn", .ret_type = 1, .nargs = 1, 430b289a8d7SJohn Baldwin .args = { { Ptr, 0 } } }, 4312b75c8adSJohn Baldwin { .name = "sigsuspend", .ret_type = 1, .nargs = 1, 432b289a8d7SJohn Baldwin .args = { { Sigset | IN, 0 } } }, 433b289a8d7SJohn Baldwin { .name = "sigtimedwait", .ret_type = 1, .nargs = 3, 434b289a8d7SJohn Baldwin .args = { { Sigset | IN, 0 }, { Ptr, 1 }, { Timespec | IN, 2 } } }, 435b289a8d7SJohn Baldwin { .name = "sigwait", .ret_type = 1, .nargs = 2, 436b289a8d7SJohn Baldwin .args = { { Sigset | IN, 0 }, { Ptr, 1 } } }, 437b289a8d7SJohn Baldwin { .name = "sigwaitinfo", .ret_type = 1, .nargs = 2, 438b289a8d7SJohn Baldwin .args = { { Sigset | IN, 0 }, { Ptr, 1 } } }, 439ee3b0f6eSDiomidis Spinellis { .name = "socket", .ret_type = 1, .nargs = 3, 440ecac235bSMichael Tuexen .args = { { Sockdomain, 0 }, { Socktype, 1 }, { Sockprotocol, 2 } } }, 441f44fc79dSJohn Baldwin { .name = "stat", .ret_type = 1, .nargs = 2, 442f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } }, 443f44fc79dSJohn Baldwin { .name = "statfs", .ret_type = 1, .nargs = 2, 444f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } }, 445ee3b0f6eSDiomidis Spinellis { .name = "symlink", .ret_type = 1, .nargs = 2, 446ee3b0f6eSDiomidis Spinellis .args = { { Name, 0 }, { Name, 1 } } }, 4477d897327SJohn Baldwin { .name = "symlinkat", .ret_type = 1, .nargs = 3, 4487d897327SJohn Baldwin .args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } }, 449f44fc79dSJohn Baldwin { .name = "sysarch", .ret_type = 1, .nargs = 2, 450f44fc79dSJohn Baldwin .args = { { Sysarch, 0 }, { Ptr, 1 } } }, 451f44fc79dSJohn Baldwin { .name = "thr_kill", .ret_type = 1, .nargs = 2, 452f44fc79dSJohn Baldwin .args = { { Long, 0 }, { Signal, 1 } } }, 453f44fc79dSJohn Baldwin { .name = "thr_self", .ret_type = 1, .nargs = 1, 454f44fc79dSJohn Baldwin .args = { { Ptr, 0 } } }, 455f44fc79dSJohn Baldwin { .name = "truncate", .ret_type = 1, .nargs = 2, 456c05cc0d6SJohn Baldwin .args = { { Name | IN, 0 }, { QuadHex | IN, 1 } } }, 457f44fc79dSJohn Baldwin #if 0 458f44fc79dSJohn Baldwin /* Does not exist */ 459f44fc79dSJohn Baldwin { .name = "umount", .ret_type = 1, .nargs = 2, 460f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Int, 2 } } }, 461f44fc79dSJohn Baldwin #endif 462f44fc79dSJohn Baldwin { .name = "unlink", .ret_type = 1, .nargs = 1, 463f44fc79dSJohn Baldwin .args = { { Name, 0 } } }, 464f44fc79dSJohn Baldwin { .name = "unlinkat", .ret_type = 1, .nargs = 3, 465f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } }, 466f44fc79dSJohn Baldwin { .name = "unmount", .ret_type = 1, .nargs = 2, 4678acc8e78SJohn Baldwin .args = { { Name, 0 }, { Mountflags, 1 } } }, 468f44fc79dSJohn Baldwin { .name = "utimensat", .ret_type = 1, .nargs = 4, 469f44fc79dSJohn Baldwin .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 }, 470f44fc79dSJohn Baldwin { Atflags, 3 } } }, 471f44fc79dSJohn Baldwin { .name = "utimes", .ret_type = 1, .nargs = 2, 472f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } }, 473195aef99SBryan Drewery { .name = "utrace", .ret_type = 1, .nargs = 1, 474195aef99SBryan Drewery .args = { { Utrace, 0 } } }, 47534763d1cSJohn Baldwin { .name = "wait4", .ret_type = 1, .nargs = 4, 47634763d1cSJohn Baldwin .args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 }, 47734763d1cSJohn Baldwin { Rusage | OUT, 3 } } }, 47834763d1cSJohn Baldwin { .name = "wait6", .ret_type = 1, .nargs = 6, 479c05cc0d6SJohn Baldwin .args = { { Idtype, 0 }, { Quad, 1 }, { ExitStatus | OUT, 2 }, 480c05cc0d6SJohn Baldwin { Waitoptions, 3 }, { Rusage | OUT, 4 }, { Ptr, 5 } } }, 481f44fc79dSJohn Baldwin { .name = "write", .ret_type = 1, .nargs = 3, 482e261fb2aSJohn Baldwin .args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 } } }, 483f44fc79dSJohn Baldwin 484f44fc79dSJohn Baldwin /* Linux ABI */ 485f44fc79dSJohn Baldwin { .name = "linux_access", .ret_type = 1, .nargs = 2, 486f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Accessmode, 1 } } }, 487f44fc79dSJohn Baldwin { .name = "linux_execve", .ret_type = 1, .nargs = 3, 488f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 }, 489f44fc79dSJohn Baldwin { ExecEnv | IN, 2 } } }, 490f44fc79dSJohn Baldwin { .name = "linux_lseek", .ret_type = 2, .nargs = 3, 491f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } }, 492f44fc79dSJohn Baldwin { .name = "linux_mkdir", .ret_type = 1, .nargs = 2, 493f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Int, 1 } } }, 494f44fc79dSJohn Baldwin { .name = "linux_newfstat", .ret_type = 1, .nargs = 2, 495f44fc79dSJohn Baldwin .args = { { Int, 0 }, { Ptr | OUT, 1 } } }, 496f44fc79dSJohn Baldwin { .name = "linux_newstat", .ret_type = 1, .nargs = 2, 497f44fc79dSJohn Baldwin .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } }, 498f44fc79dSJohn Baldwin { .name = "linux_open", .ret_type = 1, .nargs = 3, 499f44fc79dSJohn Baldwin .args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } }, 500f44fc79dSJohn Baldwin { .name = "linux_readlink", .ret_type = 1, .nargs = 3, 501e261fb2aSJohn Baldwin .args = { { Name, 0 }, { Name | OUT, 1 }, { Sizet, 2 } } }, 502f44fc79dSJohn Baldwin { .name = "linux_socketcall", .ret_type = 1, .nargs = 2, 503f44fc79dSJohn Baldwin .args = { { Int, 0 }, { LinuxSockArgs, 1 } } }, 50464f4703bSJohn Baldwin { .name = "linux_stat64", .ret_type = 1, .nargs = 2, 50564f4703bSJohn Baldwin .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } }, 506f44fc79dSJohn Baldwin 507808d9805SEd Schouten /* CloudABI system calls. */ 508808d9805SEd Schouten { .name = "cloudabi_sys_clock_res_get", .ret_type = 1, .nargs = 1, 509808d9805SEd Schouten .args = { { CloudABIClockID, 0 } } }, 510808d9805SEd Schouten { .name = "cloudabi_sys_clock_time_get", .ret_type = 1, .nargs = 2, 511808d9805SEd Schouten .args = { { CloudABIClockID, 0 }, { CloudABITimestamp, 1 } } }, 512808d9805SEd Schouten { .name = "cloudabi_sys_condvar_signal", .ret_type = 1, .nargs = 3, 513808d9805SEd Schouten .args = { { Ptr, 0 }, { CloudABIMFlags, 1 }, { UInt, 2 } } }, 514808d9805SEd Schouten { .name = "cloudabi_sys_fd_close", .ret_type = 1, .nargs = 1, 515808d9805SEd Schouten .args = { { Int, 0 } } }, 516808d9805SEd Schouten { .name = "cloudabi_sys_fd_create1", .ret_type = 1, .nargs = 1, 517808d9805SEd Schouten .args = { { CloudABIFileType, 0 } } }, 518808d9805SEd Schouten { .name = "cloudabi_sys_fd_create2", .ret_type = 1, .nargs = 2, 519808d9805SEd Schouten .args = { { CloudABIFileType, 0 }, { PipeFds | OUT, 0 } } }, 520808d9805SEd Schouten { .name = "cloudabi_sys_fd_datasync", .ret_type = 1, .nargs = 1, 521808d9805SEd Schouten .args = { { Int, 0 } } }, 522808d9805SEd Schouten { .name = "cloudabi_sys_fd_dup", .ret_type = 1, .nargs = 1, 523808d9805SEd Schouten .args = { { Int, 0 } } }, 524808d9805SEd Schouten { .name = "cloudabi_sys_fd_replace", .ret_type = 1, .nargs = 2, 525808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 } } }, 526808d9805SEd Schouten { .name = "cloudabi_sys_fd_seek", .ret_type = 1, .nargs = 3, 527808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 }, { CloudABIWhence, 2 } } }, 528808d9805SEd Schouten { .name = "cloudabi_sys_fd_stat_get", .ret_type = 1, .nargs = 2, 529808d9805SEd Schouten .args = { { Int, 0 }, { CloudABIFDStat | OUT, 1 } } }, 530808d9805SEd Schouten { .name = "cloudabi_sys_fd_stat_put", .ret_type = 1, .nargs = 3, 531808d9805SEd Schouten .args = { { Int, 0 }, { CloudABIFDStat | IN, 1 }, 532808d9805SEd Schouten { ClouduABIFDSFlags, 2 } } }, 533808d9805SEd Schouten { .name = "cloudabi_sys_fd_sync", .ret_type = 1, .nargs = 1, 534808d9805SEd Schouten .args = { { Int, 0 } } }, 535808d9805SEd Schouten { .name = "cloudabi_sys_file_advise", .ret_type = 1, .nargs = 4, 536808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 }, { Int, 2 }, 537808d9805SEd Schouten { CloudABIAdvice, 3 } } }, 538808d9805SEd Schouten { .name = "cloudabi_sys_file_allocate", .ret_type = 1, .nargs = 3, 539808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } }, 540808d9805SEd Schouten { .name = "cloudabi_sys_file_create", .ret_type = 1, .nargs = 3, 541808d9805SEd Schouten .args = { { Int, 0 }, { BinString | IN, 1 }, 542808d9805SEd Schouten { CloudABIFileType, 3 } } }, 543808d9805SEd Schouten { .name = "cloudabi_sys_file_link", .ret_type = 1, .nargs = 4, 544808d9805SEd Schouten .args = { { CloudABILookup, 0 }, { BinString | IN, 1 }, 545808d9805SEd Schouten { Int, 3 }, { BinString | IN, 4 } } }, 546808d9805SEd Schouten { .name = "cloudabi_sys_file_open", .ret_type = 1, .nargs = 4, 547808d9805SEd Schouten .args = { { Int, 0 }, { BinString | IN, 1 }, 548808d9805SEd Schouten { CloudABIOFlags, 3 }, { CloudABIFDStat | IN, 4 } } }, 549808d9805SEd Schouten { .name = "cloudabi_sys_file_readdir", .ret_type = 1, .nargs = 4, 550808d9805SEd Schouten .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 }, 551808d9805SEd Schouten { Int, 3 } } }, 552808d9805SEd Schouten { .name = "cloudabi_sys_file_readlink", .ret_type = 1, .nargs = 4, 553808d9805SEd Schouten .args = { { Int, 0 }, { BinString | IN, 1 }, 554808d9805SEd Schouten { BinString | OUT, 3 }, { Int, 4 } } }, 555808d9805SEd Schouten { .name = "cloudabi_sys_file_rename", .ret_type = 1, .nargs = 4, 556808d9805SEd Schouten .args = { { Int, 0 }, { BinString | IN, 1 }, 557808d9805SEd Schouten { Int, 3 }, { BinString | IN, 4 } } }, 558808d9805SEd Schouten { .name = "cloudabi_sys_file_stat_fget", .ret_type = 1, .nargs = 2, 559808d9805SEd Schouten .args = { { Int, 0 }, { CloudABIFileStat | OUT, 1 } } }, 560808d9805SEd Schouten { .name = "cloudabi_sys_file_stat_fput", .ret_type = 1, .nargs = 3, 561808d9805SEd Schouten .args = { { Int, 0 }, { CloudABIFileStat | IN, 1 }, 562808d9805SEd Schouten { CloudABIFSFlags, 2 } } }, 563808d9805SEd Schouten { .name = "cloudabi_sys_file_stat_get", .ret_type = 1, .nargs = 3, 564808d9805SEd Schouten .args = { { CloudABILookup, 0 }, { BinString | IN, 1 }, 565808d9805SEd Schouten { CloudABIFileStat | OUT, 3 } } }, 566808d9805SEd Schouten { .name = "cloudabi_sys_file_stat_put", .ret_type = 1, .nargs = 4, 567808d9805SEd Schouten .args = { { CloudABILookup, 0 }, { BinString | IN, 1 }, 568808d9805SEd Schouten { CloudABIFileStat | IN, 3 }, { CloudABIFSFlags, 4 } } }, 569808d9805SEd Schouten { .name = "cloudabi_sys_file_symlink", .ret_type = 1, .nargs = 3, 570808d9805SEd Schouten .args = { { BinString | IN, 0 }, 571808d9805SEd Schouten { Int, 2 }, { BinString | IN, 3 } } }, 572808d9805SEd Schouten { .name = "cloudabi_sys_file_unlink", .ret_type = 1, .nargs = 3, 573808d9805SEd Schouten .args = { { Int, 0 }, { BinString | IN, 1 }, 574808d9805SEd Schouten { CloudABIULFlags, 3 } } }, 575808d9805SEd Schouten { .name = "cloudabi_sys_lock_unlock", .ret_type = 1, .nargs = 2, 576808d9805SEd Schouten .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } }, 577808d9805SEd Schouten { .name = "cloudabi_sys_mem_advise", .ret_type = 1, .nargs = 3, 578808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIAdvice, 2 } } }, 579808d9805SEd Schouten { .name = "cloudabi_sys_mem_lock", .ret_type = 1, .nargs = 2, 580808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 } } }, 581808d9805SEd Schouten { .name = "cloudabi_sys_mem_map", .ret_type = 1, .nargs = 6, 582808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 }, 583808d9805SEd Schouten { CloudABIMFlags, 3 }, { Int, 4 }, { Int, 5 } } }, 584808d9805SEd Schouten { .name = "cloudabi_sys_mem_protect", .ret_type = 1, .nargs = 3, 585808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 } } }, 586808d9805SEd Schouten { .name = "cloudabi_sys_mem_sync", .ret_type = 1, .nargs = 3, 587808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMSFlags, 2 } } }, 588808d9805SEd Schouten { .name = "cloudabi_sys_mem_unlock", .ret_type = 1, .nargs = 2, 589808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 } } }, 590808d9805SEd Schouten { .name = "cloudabi_sys_mem_unmap", .ret_type = 1, .nargs = 2, 591808d9805SEd Schouten .args = { { Ptr, 0 }, { Int, 1 } } }, 592808d9805SEd Schouten { .name = "cloudabi_sys_proc_exec", .ret_type = 1, .nargs = 5, 593808d9805SEd Schouten .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, 594808d9805SEd Schouten { IntArray, 3 }, { Int, 4 } } }, 595808d9805SEd Schouten { .name = "cloudabi_sys_proc_exit", .ret_type = 1, .nargs = 1, 596808d9805SEd Schouten .args = { { Int, 0 } } }, 597808d9805SEd Schouten { .name = "cloudabi_sys_proc_fork", .ret_type = 1, .nargs = 0 }, 598808d9805SEd Schouten { .name = "cloudabi_sys_proc_raise", .ret_type = 1, .nargs = 1, 599808d9805SEd Schouten .args = { { CloudABISignal, 0 } } }, 600808d9805SEd Schouten { .name = "cloudabi_sys_random_get", .ret_type = 1, .nargs = 2, 601808d9805SEd Schouten .args = { { BinString | OUT, 0 }, { Int, 1 } } }, 602808d9805SEd Schouten { .name = "cloudabi_sys_sock_accept", .ret_type = 1, .nargs = 2, 603808d9805SEd Schouten .args = { { Int, 0 }, { CloudABISockStat | OUT, 1 } } }, 604808d9805SEd Schouten { .name = "cloudabi_sys_sock_bind", .ret_type = 1, .nargs = 3, 605808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 }, { BinString | IN, 2 } } }, 606808d9805SEd Schouten { .name = "cloudabi_sys_sock_connect", .ret_type = 1, .nargs = 3, 607808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 }, { BinString | IN, 2 } } }, 608808d9805SEd Schouten { .name = "cloudabi_sys_sock_listen", .ret_type = 1, .nargs = 2, 609808d9805SEd Schouten .args = { { Int, 0 }, { Int, 1 } } }, 610808d9805SEd Schouten { .name = "cloudabi_sys_sock_shutdown", .ret_type = 1, .nargs = 2, 611808d9805SEd Schouten .args = { { Int, 0 }, { CloudABISDFlags, 1 } } }, 612808d9805SEd Schouten { .name = "cloudabi_sys_sock_stat_get", .ret_type = 1, .nargs = 3, 613808d9805SEd Schouten .args = { { Int, 0 }, { CloudABISockStat | OUT, 1 }, 614808d9805SEd Schouten { CloudABISSFlags, 2 } } }, 615808d9805SEd Schouten { .name = "cloudabi_sys_thread_exit", .ret_type = 1, .nargs = 2, 616808d9805SEd Schouten .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } }, 617808d9805SEd Schouten { .name = "cloudabi_sys_thread_yield", .ret_type = 1, .nargs = 0 }, 618808d9805SEd Schouten 619ee3b0f6eSDiomidis Spinellis { .name = 0 }, 620bbeaf6c0SSean Eric Fagan }; 6216c61b0f3SBryan Drewery static STAILQ_HEAD(, syscall) syscalls; 622bbeaf6c0SSean Eric Fagan 623081e5c48SPav Lucistnik /* Xlat idea taken from strace */ 624081e5c48SPav Lucistnik struct xlat { 625081e5c48SPav Lucistnik int val; 6265d2d083cSXin LI const char *str; 627081e5c48SPav Lucistnik }; 628081e5c48SPav Lucistnik 629081e5c48SPav Lucistnik #define X(a) { a, #a }, 630081e5c48SPav Lucistnik #define XEND { 0, NULL } 631081e5c48SPav Lucistnik 632081e5c48SPav Lucistnik static struct xlat kevent_filters[] = { 633081e5c48SPav Lucistnik X(EVFILT_READ) X(EVFILT_WRITE) X(EVFILT_AIO) X(EVFILT_VNODE) 634081e5c48SPav Lucistnik X(EVFILT_PROC) X(EVFILT_SIGNAL) X(EVFILT_TIMER) 635d98d7ba0SJohn Baldwin X(EVFILT_PROCDESC) X(EVFILT_FS) X(EVFILT_LIO) X(EVFILT_USER) 636d98d7ba0SJohn Baldwin X(EVFILT_SENDFILE) XEND 637081e5c48SPav Lucistnik }; 638081e5c48SPav Lucistnik 639081e5c48SPav Lucistnik static struct xlat kevent_flags[] = { 640081e5c48SPav Lucistnik X(EV_ADD) X(EV_DELETE) X(EV_ENABLE) X(EV_DISABLE) X(EV_ONESHOT) 641d98d7ba0SJohn Baldwin X(EV_CLEAR) X(EV_RECEIPT) X(EV_DISPATCH) X(EV_FORCEONESHOT) 642d98d7ba0SJohn Baldwin X(EV_DROP) X(EV_FLAG1) X(EV_ERROR) X(EV_EOF) XEND 643081e5c48SPav Lucistnik }; 644081e5c48SPav Lucistnik 645c915ff03SJohn Baldwin static struct xlat kevent_user_ffctrl[] = { 646c915ff03SJohn Baldwin X(NOTE_FFNOP) X(NOTE_FFAND) X(NOTE_FFOR) X(NOTE_FFCOPY) 647c915ff03SJohn Baldwin XEND 648c915ff03SJohn Baldwin }; 649c915ff03SJohn Baldwin 650c915ff03SJohn Baldwin static struct xlat kevent_rdwr_fflags[] = { 651c915ff03SJohn Baldwin X(NOTE_LOWAT) X(NOTE_FILE_POLL) XEND 652c915ff03SJohn Baldwin }; 653c915ff03SJohn Baldwin 654c915ff03SJohn Baldwin static struct xlat kevent_vnode_fflags[] = { 655c915ff03SJohn Baldwin X(NOTE_DELETE) X(NOTE_WRITE) X(NOTE_EXTEND) X(NOTE_ATTRIB) 656c915ff03SJohn Baldwin X(NOTE_LINK) X(NOTE_RENAME) X(NOTE_REVOKE) XEND 657c915ff03SJohn Baldwin }; 658c915ff03SJohn Baldwin 659c915ff03SJohn Baldwin static struct xlat kevent_proc_fflags[] = { 660c915ff03SJohn Baldwin X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR) 661c915ff03SJohn Baldwin X(NOTE_CHILD) XEND 662c915ff03SJohn Baldwin }; 663c915ff03SJohn Baldwin 664c915ff03SJohn Baldwin static struct xlat kevent_timer_fflags[] = { 665c915ff03SJohn Baldwin X(NOTE_SECONDS) X(NOTE_MSECONDS) X(NOTE_USECONDS) X(NOTE_NSECONDS) 666c915ff03SJohn Baldwin XEND 667c915ff03SJohn Baldwin }; 668c915ff03SJohn Baldwin 669a02c83afSEd Schouten static struct xlat poll_flags[] = { 670081e5c48SPav Lucistnik X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR) 671081e5c48SPav Lucistnik X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND) 672081e5c48SPav Lucistnik X(POLLWRBAND) X(POLLINIGNEOF) XEND 673081e5c48SPav Lucistnik }; 674081e5c48SPav Lucistnik 675081e5c48SPav Lucistnik static struct xlat sigaction_flags[] = { 676081e5c48SPav Lucistnik X(SA_ONSTACK) X(SA_RESTART) X(SA_RESETHAND) X(SA_NOCLDSTOP) 677081e5c48SPav Lucistnik X(SA_NODEFER) X(SA_NOCLDWAIT) X(SA_SIGINFO) XEND 678081e5c48SPav Lucistnik }; 679081e5c48SPav Lucistnik 680081e5c48SPav Lucistnik static struct xlat pathconf_arg[] = { 681081e5c48SPav Lucistnik X(_PC_LINK_MAX) X(_PC_MAX_CANON) X(_PC_MAX_INPUT) 682081e5c48SPav Lucistnik X(_PC_NAME_MAX) X(_PC_PATH_MAX) X(_PC_PIPE_BUF) 683081e5c48SPav Lucistnik X(_PC_CHOWN_RESTRICTED) X(_PC_NO_TRUNC) X(_PC_VDISABLE) 684081e5c48SPav Lucistnik X(_PC_ASYNC_IO) X(_PC_PRIO_IO) X(_PC_SYNC_IO) 685081e5c48SPav Lucistnik X(_PC_ALLOC_SIZE_MIN) X(_PC_FILESIZEBITS) 686081e5c48SPav Lucistnik X(_PC_REC_INCR_XFER_SIZE) X(_PC_REC_MAX_XFER_SIZE) 687081e5c48SPav Lucistnik X(_PC_REC_MIN_XFER_SIZE) X(_PC_REC_XFER_ALIGN) 688081e5c48SPav Lucistnik X(_PC_SYMLINK_MAX) X(_PC_ACL_EXTENDED) X(_PC_ACL_PATH_MAX) 689081e5c48SPav Lucistnik X(_PC_CAP_PRESENT) X(_PC_INF_PRESENT) X(_PC_MAC_PRESENT) 690d98d7ba0SJohn Baldwin X(_PC_ACL_NFS4) X(_PC_MIN_HOLE_SIZE) XEND 691081e5c48SPav Lucistnik }; 692081e5c48SPav Lucistnik 6937d897327SJohn Baldwin static struct xlat at_flags[] = { 6947d897327SJohn Baldwin X(AT_EACCESS) X(AT_SYMLINK_NOFOLLOW) X(AT_SYMLINK_FOLLOW) 6957d897327SJohn Baldwin X(AT_REMOVEDIR) XEND 6967d897327SJohn Baldwin }; 6977d897327SJohn Baldwin 698b289a8d7SJohn Baldwin static struct xlat sysarch_ops[] = { 699b289a8d7SJohn Baldwin #if defined(__i386__) || defined(__amd64__) 700b289a8d7SJohn Baldwin X(I386_GET_LDT) X(I386_SET_LDT) X(I386_GET_IOPERM) X(I386_SET_IOPERM) 701b289a8d7SJohn Baldwin X(I386_VM86) X(I386_GET_FSBASE) X(I386_SET_FSBASE) X(I386_GET_GSBASE) 702b289a8d7SJohn Baldwin X(I386_SET_GSBASE) X(I386_GET_XFPUSTATE) X(AMD64_GET_FSBASE) 703b289a8d7SJohn Baldwin X(AMD64_SET_FSBASE) X(AMD64_GET_GSBASE) X(AMD64_SET_GSBASE) 704b289a8d7SJohn Baldwin X(AMD64_GET_XFPUSTATE) 705b289a8d7SJohn Baldwin #endif 706b289a8d7SJohn Baldwin XEND 707b289a8d7SJohn Baldwin }; 708fb7eabb0SJohn Baldwin 709fb7eabb0SJohn Baldwin static struct xlat linux_socketcall_ops[] = { 710fb7eabb0SJohn Baldwin X(LINUX_SOCKET) X(LINUX_BIND) X(LINUX_CONNECT) X(LINUX_LISTEN) 711fb7eabb0SJohn Baldwin X(LINUX_ACCEPT) X(LINUX_GETSOCKNAME) X(LINUX_GETPEERNAME) 712fb7eabb0SJohn Baldwin X(LINUX_SOCKETPAIR) X(LINUX_SEND) X(LINUX_RECV) X(LINUX_SENDTO) 713fb7eabb0SJohn Baldwin X(LINUX_RECVFROM) X(LINUX_SHUTDOWN) X(LINUX_SETSOCKOPT) 714fb7eabb0SJohn Baldwin X(LINUX_GETSOCKOPT) X(LINUX_SENDMSG) X(LINUX_RECVMSG) 715fb7eabb0SJohn Baldwin XEND 716fb7eabb0SJohn Baldwin }; 717fb7eabb0SJohn Baldwin 718081e5c48SPav Lucistnik #undef X 719808d9805SEd Schouten #define X(a) { CLOUDABI_##a, #a }, 720808d9805SEd Schouten 721808d9805SEd Schouten static struct xlat cloudabi_advice[] = { 722808d9805SEd Schouten X(ADVICE_DONTNEED) X(ADVICE_NOREUSE) X(ADVICE_NORMAL) 723808d9805SEd Schouten X(ADVICE_RANDOM) X(ADVICE_SEQUENTIAL) X(ADVICE_WILLNEED) 724808d9805SEd Schouten XEND 725808d9805SEd Schouten }; 726808d9805SEd Schouten 727808d9805SEd Schouten static struct xlat cloudabi_clockid[] = { 728808d9805SEd Schouten X(CLOCK_MONOTONIC) X(CLOCK_PROCESS_CPUTIME_ID) 729808d9805SEd Schouten X(CLOCK_REALTIME) X(CLOCK_THREAD_CPUTIME_ID) 730808d9805SEd Schouten XEND 731808d9805SEd Schouten }; 732808d9805SEd Schouten 733808d9805SEd Schouten static struct xlat cloudabi_errno[] = { 734808d9805SEd Schouten X(E2BIG) X(EACCES) X(EADDRINUSE) X(EADDRNOTAVAIL) 735808d9805SEd Schouten X(EAFNOSUPPORT) X(EAGAIN) X(EALREADY) X(EBADF) X(EBADMSG) 736808d9805SEd Schouten X(EBUSY) X(ECANCELED) X(ECHILD) X(ECONNABORTED) X(ECONNREFUSED) 737808d9805SEd Schouten X(ECONNRESET) X(EDEADLK) X(EDESTADDRREQ) X(EDOM) X(EDQUOT) 738808d9805SEd Schouten X(EEXIST) X(EFAULT) X(EFBIG) X(EHOSTUNREACH) X(EIDRM) X(EILSEQ) 739808d9805SEd Schouten X(EINPROGRESS) X(EINTR) X(EINVAL) X(EIO) X(EISCONN) X(EISDIR) 740808d9805SEd Schouten X(ELOOP) X(EMFILE) X(EMLINK) X(EMSGSIZE) X(EMULTIHOP) 741808d9805SEd Schouten X(ENAMETOOLONG) X(ENETDOWN) X(ENETRESET) X(ENETUNREACH) 742808d9805SEd Schouten X(ENFILE) X(ENOBUFS) X(ENODEV) X(ENOENT) X(ENOEXEC) X(ENOLCK) 743808d9805SEd Schouten X(ENOLINK) X(ENOMEM) X(ENOMSG) X(ENOPROTOOPT) X(ENOSPC) 744808d9805SEd Schouten X(ENOSYS) X(ENOTCONN) X(ENOTDIR) X(ENOTEMPTY) X(ENOTRECOVERABLE) 745808d9805SEd Schouten X(ENOTSOCK) X(ENOTSUP) X(ENOTTY) X(ENXIO) X(EOVERFLOW) 746808d9805SEd Schouten X(EOWNERDEAD) X(EPERM) X(EPIPE) X(EPROTO) X(EPROTONOSUPPORT) 747808d9805SEd Schouten X(EPROTOTYPE) X(ERANGE) X(EROFS) X(ESPIPE) X(ESRCH) X(ESTALE) 748808d9805SEd Schouten X(ETIMEDOUT) X(ETXTBSY) X(EXDEV) X(ENOTCAPABLE) 749808d9805SEd Schouten XEND 750808d9805SEd Schouten }; 751808d9805SEd Schouten 752808d9805SEd Schouten static struct xlat cloudabi_fdflags[] = { 753808d9805SEd Schouten X(FDFLAG_APPEND) X(FDFLAG_DSYNC) X(FDFLAG_NONBLOCK) 754808d9805SEd Schouten X(FDFLAG_RSYNC) X(FDFLAG_SYNC) 755808d9805SEd Schouten XEND 756808d9805SEd Schouten }; 757808d9805SEd Schouten 758808d9805SEd Schouten static struct xlat cloudabi_fdsflags[] = { 759808d9805SEd Schouten X(FDSTAT_FLAGS) X(FDSTAT_RIGHTS) 760808d9805SEd Schouten XEND 761808d9805SEd Schouten }; 762808d9805SEd Schouten 763808d9805SEd Schouten static struct xlat cloudabi_filetype[] = { 764808d9805SEd Schouten X(FILETYPE_UNKNOWN) X(FILETYPE_BLOCK_DEVICE) 765808d9805SEd Schouten X(FILETYPE_CHARACTER_DEVICE) X(FILETYPE_DIRECTORY) 766808d9805SEd Schouten X(FILETYPE_FIFO) X(FILETYPE_POLL) X(FILETYPE_PROCESS) 767808d9805SEd Schouten X(FILETYPE_REGULAR_FILE) X(FILETYPE_SHARED_MEMORY) 768808d9805SEd Schouten X(FILETYPE_SOCKET_DGRAM) X(FILETYPE_SOCKET_SEQPACKET) 769808d9805SEd Schouten X(FILETYPE_SOCKET_STREAM) X(FILETYPE_SYMBOLIC_LINK) 770808d9805SEd Schouten XEND 771808d9805SEd Schouten }; 772808d9805SEd Schouten 773808d9805SEd Schouten static struct xlat cloudabi_fsflags[] = { 774808d9805SEd Schouten X(FILESTAT_ATIM) X(FILESTAT_ATIM_NOW) X(FILESTAT_MTIM) 775808d9805SEd Schouten X(FILESTAT_MTIM_NOW) X(FILESTAT_SIZE) 776808d9805SEd Schouten XEND 777808d9805SEd Schouten }; 778808d9805SEd Schouten 779808d9805SEd Schouten static struct xlat cloudabi_mflags[] = { 780808d9805SEd Schouten X(MAP_ANON) X(MAP_FIXED) X(MAP_PRIVATE) X(MAP_SHARED) 781808d9805SEd Schouten XEND 782808d9805SEd Schouten }; 783808d9805SEd Schouten 784808d9805SEd Schouten static struct xlat cloudabi_mprot[] = { 785808d9805SEd Schouten X(PROT_EXEC) X(PROT_WRITE) X(PROT_READ) 786808d9805SEd Schouten XEND 787808d9805SEd Schouten }; 788808d9805SEd Schouten 789808d9805SEd Schouten static struct xlat cloudabi_msflags[] = { 790808d9805SEd Schouten X(MS_ASYNC) X(MS_INVALIDATE) X(MS_SYNC) 791808d9805SEd Schouten XEND 792808d9805SEd Schouten }; 793808d9805SEd Schouten 794808d9805SEd Schouten static struct xlat cloudabi_oflags[] = { 795808d9805SEd Schouten X(O_CREAT) X(O_DIRECTORY) X(O_EXCL) X(O_TRUNC) 796808d9805SEd Schouten XEND 797808d9805SEd Schouten }; 798808d9805SEd Schouten 799808d9805SEd Schouten static struct xlat cloudabi_sa_family[] = { 800808d9805SEd Schouten X(AF_UNSPEC) X(AF_INET) X(AF_INET6) X(AF_UNIX) 801808d9805SEd Schouten XEND 802808d9805SEd Schouten }; 803808d9805SEd Schouten 804808d9805SEd Schouten static struct xlat cloudabi_sdflags[] = { 805808d9805SEd Schouten X(SHUT_RD) X(SHUT_WR) 806808d9805SEd Schouten XEND 807808d9805SEd Schouten }; 808808d9805SEd Schouten 809808d9805SEd Schouten static struct xlat cloudabi_signal[] = { 810808d9805SEd Schouten X(SIGABRT) X(SIGALRM) X(SIGBUS) X(SIGCHLD) X(SIGCONT) X(SIGFPE) 811808d9805SEd Schouten X(SIGHUP) X(SIGILL) X(SIGINT) X(SIGKILL) X(SIGPIPE) X(SIGQUIT) 812808d9805SEd Schouten X(SIGSEGV) X(SIGSTOP) X(SIGSYS) X(SIGTERM) X(SIGTRAP) X(SIGTSTP) 813808d9805SEd Schouten X(SIGTTIN) X(SIGTTOU) X(SIGURG) X(SIGUSR1) X(SIGUSR2) 814808d9805SEd Schouten X(SIGVTALRM) X(SIGXCPU) X(SIGXFSZ) 815808d9805SEd Schouten XEND 816808d9805SEd Schouten }; 817808d9805SEd Schouten 818808d9805SEd Schouten static struct xlat cloudabi_ssflags[] = { 819808d9805SEd Schouten X(SOCKSTAT_CLEAR_ERROR) 820808d9805SEd Schouten XEND 821808d9805SEd Schouten }; 822808d9805SEd Schouten 823808d9805SEd Schouten static struct xlat cloudabi_ssstate[] = { 8241f3bbfd8SEd Schouten X(SOCKSTATE_ACCEPTCONN) 825808d9805SEd Schouten XEND 826808d9805SEd Schouten }; 827808d9805SEd Schouten 828808d9805SEd Schouten static struct xlat cloudabi_ulflags[] = { 829808d9805SEd Schouten X(UNLINK_REMOVEDIR) 830808d9805SEd Schouten XEND 831808d9805SEd Schouten }; 832808d9805SEd Schouten 833808d9805SEd Schouten static struct xlat cloudabi_whence[] = { 834808d9805SEd Schouten X(WHENCE_CUR) X(WHENCE_END) X(WHENCE_SET) 835808d9805SEd Schouten XEND 836808d9805SEd Schouten }; 837808d9805SEd Schouten 838808d9805SEd Schouten #undef X 839081e5c48SPav Lucistnik #undef XEND 840081e5c48SPav Lucistnik 841d8984f48SDag-Erling Smørgrav /* 842d8984f48SDag-Erling Smørgrav * Searches an xlat array for a value, and returns it if found. Otherwise 843d8984f48SDag-Erling Smørgrav * return a string representation. 844d8984f48SDag-Erling Smørgrav */ 845d8984f48SDag-Erling Smørgrav static const char * 846d8984f48SDag-Erling Smørgrav lookup(struct xlat *xlat, int val, int base) 847081e5c48SPav Lucistnik { 848081e5c48SPav Lucistnik static char tmp[16]; 849d8984f48SDag-Erling Smørgrav 850081e5c48SPav Lucistnik for (; xlat->str != NULL; xlat++) 851081e5c48SPav Lucistnik if (xlat->val == val) 852d8984f48SDag-Erling Smørgrav return (xlat->str); 853081e5c48SPav Lucistnik switch (base) { 854081e5c48SPav Lucistnik case 8: 855081e5c48SPav Lucistnik sprintf(tmp, "0%o", val); 856081e5c48SPav Lucistnik break; 857081e5c48SPav Lucistnik case 16: 858081e5c48SPav Lucistnik sprintf(tmp, "0x%x", val); 859081e5c48SPav Lucistnik break; 860081e5c48SPav Lucistnik case 10: 861081e5c48SPav Lucistnik sprintf(tmp, "%u", val); 862081e5c48SPav Lucistnik break; 863081e5c48SPav Lucistnik default: 864081e5c48SPav Lucistnik errx(1,"Unknown lookup base"); 865081e5c48SPav Lucistnik break; 866081e5c48SPav Lucistnik } 867d8984f48SDag-Erling Smørgrav return (tmp); 868081e5c48SPav Lucistnik } 869081e5c48SPav Lucistnik 8705d2d083cSXin LI static const char * 8715d2d083cSXin LI xlookup(struct xlat *xlat, int val) 872081e5c48SPav Lucistnik { 873d8984f48SDag-Erling Smørgrav 874d8984f48SDag-Erling Smørgrav return (lookup(xlat, val, 16)); 875081e5c48SPav Lucistnik } 876081e5c48SPav Lucistnik 8774e3da534SJohn Baldwin /* 8784e3da534SJohn Baldwin * Searches an xlat array containing bitfield values. Remaining bits 8794e3da534SJohn Baldwin * set after removing the known ones are printed at the end: 8804e3da534SJohn Baldwin * IN|0x400. 8814e3da534SJohn Baldwin */ 882d8984f48SDag-Erling Smørgrav static char * 883d8984f48SDag-Erling Smørgrav xlookup_bits(struct xlat *xlat, int val) 884081e5c48SPav Lucistnik { 88594355cfdSAndrey Zonov int len, rem; 886081e5c48SPav Lucistnik static char str[512]; 887081e5c48SPav Lucistnik 88894355cfdSAndrey Zonov len = 0; 88994355cfdSAndrey Zonov rem = val; 890d8984f48SDag-Erling Smørgrav for (; xlat->str != NULL; xlat++) { 891d8984f48SDag-Erling Smørgrav if ((xlat->val & rem) == xlat->val) { 8924e3da534SJohn Baldwin /* 8934e3da534SJohn Baldwin * Don't print the "all-bits-zero" string unless all 8944e3da534SJohn Baldwin * bits are really zero. 8954e3da534SJohn Baldwin */ 896081e5c48SPav Lucistnik if (xlat->val == 0 && val != 0) 897081e5c48SPav Lucistnik continue; 898081e5c48SPav Lucistnik len += sprintf(str + len, "%s|", xlat->str); 899081e5c48SPav Lucistnik rem &= ~(xlat->val); 900081e5c48SPav Lucistnik } 901081e5c48SPav Lucistnik } 9024e3da534SJohn Baldwin 9034e3da534SJohn Baldwin /* 9044e3da534SJohn Baldwin * If we have leftover bits or didn't match anything, print 9054e3da534SJohn Baldwin * the remainder. 9064e3da534SJohn Baldwin */ 907081e5c48SPav Lucistnik if (rem || len == 0) 908081e5c48SPav Lucistnik len += sprintf(str + len, "0x%x", rem); 909081e5c48SPav Lucistnik if (len && str[len - 1] == '|') 910081e5c48SPav Lucistnik len--; 911081e5c48SPav Lucistnik str[len] = 0; 912d8984f48SDag-Erling Smørgrav return (str); 913081e5c48SPav Lucistnik } 914081e5c48SPav Lucistnik 9159289f547SJohn Baldwin static void 9169289f547SJohn Baldwin print_integer_arg(const char *(*decoder)(int), FILE *fp, int value) 9179289f547SJohn Baldwin { 9189289f547SJohn Baldwin const char *str; 9199289f547SJohn Baldwin 9209289f547SJohn Baldwin str = decoder(value); 9219289f547SJohn Baldwin if (str != NULL) 9229289f547SJohn Baldwin fputs(str, fp); 9239289f547SJohn Baldwin else 9249289f547SJohn Baldwin fprintf(fp, "%d", value); 9259289f547SJohn Baldwin } 9269289f547SJohn Baldwin 9279289f547SJohn Baldwin static void 9289289f547SJohn Baldwin print_mask_arg(bool (*decoder)(FILE *, int, int *), FILE *fp, int value) 9299289f547SJohn Baldwin { 9309289f547SJohn Baldwin int rem; 9319289f547SJohn Baldwin 9329289f547SJohn Baldwin if (!decoder(fp, value, &rem)) 9339289f547SJohn Baldwin fprintf(fp, "0x%x", rem); 9349289f547SJohn Baldwin else if (rem != 0) 9359289f547SJohn Baldwin fprintf(fp, "|0x%x", rem); 9369289f547SJohn Baldwin } 9379289f547SJohn Baldwin 938bed418c8SJohn Baldwin static void 939bed418c8SJohn Baldwin print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *), FILE *fp, 940bed418c8SJohn Baldwin uint32_t value) 941bed418c8SJohn Baldwin { 942bed418c8SJohn Baldwin uint32_t rem; 943bed418c8SJohn Baldwin 944bed418c8SJohn Baldwin if (!decoder(fp, value, &rem)) 945bed418c8SJohn Baldwin fprintf(fp, "0x%x", rem); 946bed418c8SJohn Baldwin else if (rem != 0) 947bed418c8SJohn Baldwin fprintf(fp, "|0x%x", rem); 948bed418c8SJohn Baldwin } 949bed418c8SJohn Baldwin 950c05cc0d6SJohn Baldwin #ifndef __LP64__ 951c05cc0d6SJohn Baldwin /* 952c05cc0d6SJohn Baldwin * Add argument padding to subsequent system calls afater a Quad 953c05cc0d6SJohn Baldwin * syscall arguments as needed. This used to be done by hand in the 954c05cc0d6SJohn Baldwin * decoded_syscalls table which was ugly and error prone. It is 955c05cc0d6SJohn Baldwin * simpler to do the fixup of offsets at initalization time than when 956c05cc0d6SJohn Baldwin * decoding arguments. 957c05cc0d6SJohn Baldwin */ 958c05cc0d6SJohn Baldwin static void 959c05cc0d6SJohn Baldwin quad_fixup(struct syscall *sc) 960c05cc0d6SJohn Baldwin { 961c05cc0d6SJohn Baldwin int offset, prev; 962c05cc0d6SJohn Baldwin u_int i; 963c05cc0d6SJohn Baldwin 964c05cc0d6SJohn Baldwin offset = 0; 965c05cc0d6SJohn Baldwin prev = -1; 966c05cc0d6SJohn Baldwin for (i = 0; i < sc->nargs; i++) { 967c05cc0d6SJohn Baldwin /* This arg type is a dummy that doesn't use offset. */ 968c05cc0d6SJohn Baldwin if ((sc->args[i].type & ARG_MASK) == PipeFds) 969c05cc0d6SJohn Baldwin continue; 970c05cc0d6SJohn Baldwin 971c05cc0d6SJohn Baldwin assert(prev < sc->args[i].offset); 972c05cc0d6SJohn Baldwin prev = sc->args[i].offset; 973c05cc0d6SJohn Baldwin sc->args[i].offset += offset; 974c05cc0d6SJohn Baldwin switch (sc->args[i].type & ARG_MASK) { 975c05cc0d6SJohn Baldwin case Quad: 976c05cc0d6SJohn Baldwin case QuadHex: 977c05cc0d6SJohn Baldwin #ifdef __powerpc__ 978c05cc0d6SJohn Baldwin /* 979c05cc0d6SJohn Baldwin * 64-bit arguments on 32-bit powerpc must be 980c05cc0d6SJohn Baldwin * 64-bit aligned. If the current offset is 981c05cc0d6SJohn Baldwin * not aligned, the calling convention inserts 982c05cc0d6SJohn Baldwin * a 32-bit pad argument that should be skipped. 983c05cc0d6SJohn Baldwin */ 984c05cc0d6SJohn Baldwin if (sc->args[i].offset % 2 == 1) { 985c05cc0d6SJohn Baldwin sc->args[i].offset++; 986c05cc0d6SJohn Baldwin offset++; 987c05cc0d6SJohn Baldwin } 988c05cc0d6SJohn Baldwin #endif 989c05cc0d6SJohn Baldwin offset++; 990c05cc0d6SJohn Baldwin default: 991c05cc0d6SJohn Baldwin break; 992c05cc0d6SJohn Baldwin } 993c05cc0d6SJohn Baldwin } 994c05cc0d6SJohn Baldwin } 995c05cc0d6SJohn Baldwin #endif 996c05cc0d6SJohn Baldwin 9976c61b0f3SBryan Drewery void 9986c61b0f3SBryan Drewery init_syscalls(void) 9996c61b0f3SBryan Drewery { 10006c61b0f3SBryan Drewery struct syscall *sc; 10016c61b0f3SBryan Drewery 10026c61b0f3SBryan Drewery STAILQ_INIT(&syscalls); 1003c05cc0d6SJohn Baldwin for (sc = decoded_syscalls; sc->name != NULL; sc++) { 1004c05cc0d6SJohn Baldwin #ifndef __LP64__ 1005c05cc0d6SJohn Baldwin quad_fixup(sc); 1006c05cc0d6SJohn Baldwin #endif 10076c61b0f3SBryan Drewery STAILQ_INSERT_HEAD(&syscalls, sc, entries); 10086c61b0f3SBryan Drewery } 1009c05cc0d6SJohn Baldwin } 10101175b23fSJohn Baldwin 10111175b23fSJohn Baldwin static struct syscall * 10121175b23fSJohn Baldwin find_syscall(struct procabi *abi, u_int number) 10131175b23fSJohn Baldwin { 10141175b23fSJohn Baldwin struct extra_syscall *es; 10151175b23fSJohn Baldwin 10161175b23fSJohn Baldwin if (number < nitems(abi->syscalls)) 10171175b23fSJohn Baldwin return (abi->syscalls[number]); 10181175b23fSJohn Baldwin STAILQ_FOREACH(es, &abi->extra_syscalls, entries) { 10191175b23fSJohn Baldwin if (es->number == number) 10201175b23fSJohn Baldwin return (es->sc); 10211175b23fSJohn Baldwin } 10221175b23fSJohn Baldwin return (NULL); 10231175b23fSJohn Baldwin } 10241175b23fSJohn Baldwin 10251175b23fSJohn Baldwin static void 10261175b23fSJohn Baldwin add_syscall(struct procabi *abi, u_int number, struct syscall *sc) 10271175b23fSJohn Baldwin { 10281175b23fSJohn Baldwin struct extra_syscall *es; 10291175b23fSJohn Baldwin 10301175b23fSJohn Baldwin if (number < nitems(abi->syscalls)) { 10311175b23fSJohn Baldwin assert(abi->syscalls[number] == NULL); 10321175b23fSJohn Baldwin abi->syscalls[number] = sc; 10331175b23fSJohn Baldwin } else { 10341175b23fSJohn Baldwin es = malloc(sizeof(*es)); 10351175b23fSJohn Baldwin es->sc = sc; 10361175b23fSJohn Baldwin es->number = number; 10371175b23fSJohn Baldwin STAILQ_INSERT_TAIL(&abi->extra_syscalls, es, entries); 10381175b23fSJohn Baldwin } 10391175b23fSJohn Baldwin } 10401175b23fSJohn Baldwin 1041bbeaf6c0SSean Eric Fagan /* 1042bbeaf6c0SSean Eric Fagan * If/when the list gets big, it might be desirable to do it 1043bbeaf6c0SSean Eric Fagan * as a hash table or binary search. 1044bbeaf6c0SSean Eric Fagan */ 1045bbeaf6c0SSean Eric Fagan struct syscall * 10461175b23fSJohn Baldwin get_syscall(struct threadinfo *t, u_int number, u_int nargs) 1047d8984f48SDag-Erling Smørgrav { 104894355cfdSAndrey Zonov struct syscall *sc; 10491175b23fSJohn Baldwin const char *name; 10501175b23fSJohn Baldwin char *new_name; 10511175b23fSJohn Baldwin u_int i; 1052bbeaf6c0SSean Eric Fagan 10531175b23fSJohn Baldwin sc = find_syscall(t->proc->abi, number); 10541175b23fSJohn Baldwin if (sc != NULL) 1055d8984f48SDag-Erling Smørgrav return (sc); 10566c61b0f3SBryan Drewery 10571175b23fSJohn Baldwin name = sysdecode_syscallname(t->proc->abi->abi, number); 10581175b23fSJohn Baldwin if (name == NULL) { 10591175b23fSJohn Baldwin asprintf(&new_name, "#%d", number); 10601175b23fSJohn Baldwin name = new_name; 10611175b23fSJohn Baldwin } else 10621175b23fSJohn Baldwin new_name = NULL; 10631175b23fSJohn Baldwin STAILQ_FOREACH(sc, &syscalls, entries) { 10641175b23fSJohn Baldwin if (strcmp(name, sc->name) == 0) { 10651175b23fSJohn Baldwin add_syscall(t->proc->abi, number, sc); 10661175b23fSJohn Baldwin free(new_name); 10671175b23fSJohn Baldwin return (sc); 10681175b23fSJohn Baldwin } 10691175b23fSJohn Baldwin } 10701175b23fSJohn Baldwin 10716c61b0f3SBryan Drewery /* It is unknown. Add it into the list. */ 10726c61b0f3SBryan Drewery #if DEBUG 10736c61b0f3SBryan Drewery fprintf(stderr, "unknown syscall %s -- setting args to %d\n", name, 10746c61b0f3SBryan Drewery nargs); 10756c61b0f3SBryan Drewery #endif 10766c61b0f3SBryan Drewery 10776c61b0f3SBryan Drewery sc = calloc(1, sizeof(struct syscall)); 10781175b23fSJohn Baldwin sc->name = name; 10791175b23fSJohn Baldwin if (new_name != NULL) 10801175b23fSJohn Baldwin sc->unknown = true; 10816c61b0f3SBryan Drewery sc->ret_type = 1; 10826c61b0f3SBryan Drewery sc->nargs = nargs; 10836c61b0f3SBryan Drewery for (i = 0; i < nargs; i++) { 10846c61b0f3SBryan Drewery sc->args[i].offset = i; 10856c61b0f3SBryan Drewery /* Treat all unknown arguments as LongHex. */ 10866c61b0f3SBryan Drewery sc->args[i].type = LongHex; 1087bbeaf6c0SSean Eric Fagan } 10886c61b0f3SBryan Drewery STAILQ_INSERT_HEAD(&syscalls, sc, entries); 10891175b23fSJohn Baldwin add_syscall(t->proc->abi, number, sc); 10906c61b0f3SBryan Drewery 10916c61b0f3SBryan Drewery return (sc); 1092bbeaf6c0SSean Eric Fagan } 1093bbeaf6c0SSean Eric Fagan 1094bbeaf6c0SSean Eric Fagan /* 10959ddd1412SDag-Erling Smørgrav * Copy a fixed amount of bytes from the process. 10969ddd1412SDag-Erling Smørgrav */ 10971be5d704SMark Murray static int 1098be305c9cSAndrey Zonov get_struct(pid_t pid, void *offset, void *buf, int len) 1099d8984f48SDag-Erling Smørgrav { 11005d2d083cSXin LI struct ptrace_io_desc iorequest; 11019ddd1412SDag-Erling Smørgrav 11025d2d083cSXin LI iorequest.piod_op = PIOD_READ_D; 11035d2d083cSXin LI iorequest.piod_offs = offset; 11045d2d083cSXin LI iorequest.piod_addr = buf; 11055d2d083cSXin LI iorequest.piod_len = len; 11065d2d083cSXin LI if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) 1107d8984f48SDag-Erling Smørgrav return (-1); 1108d8984f48SDag-Erling Smørgrav return (0); 11099ddd1412SDag-Erling Smørgrav } 11109ddd1412SDag-Erling Smørgrav 11115d2d083cSXin LI #define MAXSIZE 4096 1112abb3f965SJohn Baldwin 11139ddd1412SDag-Erling Smørgrav /* 1114bbeaf6c0SSean Eric Fagan * Copy a string from the process. Note that it is 1115bbeaf6c0SSean Eric Fagan * expected to be a C string, but if max is set, it will 1116bbeaf6c0SSean Eric Fagan * only get that much. 1117bbeaf6c0SSean Eric Fagan */ 11185d2d083cSXin LI static char * 1119abb3f965SJohn Baldwin get_string(pid_t pid, void *addr, int max) 1120d8984f48SDag-Erling Smørgrav { 11215d2d083cSXin LI struct ptrace_io_desc iorequest; 1122abb3f965SJohn Baldwin char *buf, *nbuf; 1123abb3f965SJohn Baldwin size_t offset, size, totalsize; 1124bbeaf6c0SSean Eric Fagan 1125abb3f965SJohn Baldwin offset = 0; 1126abb3f965SJohn Baldwin if (max) 1127abb3f965SJohn Baldwin size = max + 1; 1128abb3f965SJohn Baldwin else { 1129abb3f965SJohn Baldwin /* Read up to the end of the current page. */ 1130abb3f965SJohn Baldwin size = PAGE_SIZE - ((uintptr_t)addr % PAGE_SIZE); 1131abb3f965SJohn Baldwin if (size > MAXSIZE) 1132abb3f965SJohn Baldwin size = MAXSIZE; 1133abb3f965SJohn Baldwin } 1134abb3f965SJohn Baldwin totalsize = size; 11355d2d083cSXin LI buf = malloc(totalsize); 11365d2d083cSXin LI if (buf == NULL) 1137d8984f48SDag-Erling Smørgrav return (NULL); 11385d2d083cSXin LI for (;;) { 11395d2d083cSXin LI iorequest.piod_op = PIOD_READ_D; 1140abb3f965SJohn Baldwin iorequest.piod_offs = (char *)addr + offset; 1141abb3f965SJohn Baldwin iorequest.piod_addr = buf + offset; 11425d2d083cSXin LI iorequest.piod_len = size; 11435d2d083cSXin LI if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) { 11445d2d083cSXin LI free(buf); 1145d8984f48SDag-Erling Smørgrav return (NULL); 1146bbeaf6c0SSean Eric Fagan } 1147abb3f965SJohn Baldwin if (memchr(buf + offset, '\0', size) != NULL) 1148abb3f965SJohn Baldwin return (buf); 1149abb3f965SJohn Baldwin offset += size; 1150abb3f965SJohn Baldwin if (totalsize < MAXSIZE && max == 0) { 1151abb3f965SJohn Baldwin size = MAXSIZE - totalsize; 1152abb3f965SJohn Baldwin if (size > PAGE_SIZE) 1153abb3f965SJohn Baldwin size = PAGE_SIZE; 1154abb3f965SJohn Baldwin nbuf = realloc(buf, totalsize + size); 1155abb3f965SJohn Baldwin if (nbuf == NULL) { 1156abb3f965SJohn Baldwin buf[totalsize - 1] = '\0'; 11574e92419dSMarcel Moolenaar return (buf); 1158bbeaf6c0SSean Eric Fagan } 1159abb3f965SJohn Baldwin buf = nbuf; 1160abb3f965SJohn Baldwin totalsize += size; 1161d8984f48SDag-Erling Smørgrav } else { 1162cdfc719cSJaakko Heinonen buf[totalsize - 1] = '\0'; 1163d8984f48SDag-Erling Smørgrav return (buf); 11645d2d083cSXin LI } 11655d2d083cSXin LI } 11665d2d083cSXin LI } 1167bbeaf6c0SSean Eric Fagan 11689289f547SJohn Baldwin static const char * 116934763d1cSJohn Baldwin strsig2(int sig) 117034763d1cSJohn Baldwin { 11719289f547SJohn Baldwin static char tmp[32]; 11729289f547SJohn Baldwin const char *signame; 117334763d1cSJohn Baldwin 11749289f547SJohn Baldwin signame = sysdecode_signal(sig); 11759289f547SJohn Baldwin if (signame == NULL) { 1176f083f689SJohn Baldwin snprintf(tmp, sizeof(tmp), "%d", sig); 11779289f547SJohn Baldwin signame = tmp; 1178f083f689SJohn Baldwin } 11799289f547SJohn Baldwin return (signame); 118034763d1cSJohn Baldwin } 1181bbeaf6c0SSean Eric Fagan 1182c915ff03SJohn Baldwin static void 1183c915ff03SJohn Baldwin print_kevent(FILE *fp, struct kevent *ke, int input) 1184c915ff03SJohn Baldwin { 1185c915ff03SJohn Baldwin 1186c915ff03SJohn Baldwin switch (ke->filter) { 1187c915ff03SJohn Baldwin case EVFILT_READ: 1188c915ff03SJohn Baldwin case EVFILT_WRITE: 1189c915ff03SJohn Baldwin case EVFILT_VNODE: 1190c915ff03SJohn Baldwin case EVFILT_PROC: 1191c915ff03SJohn Baldwin case EVFILT_TIMER: 1192c915ff03SJohn Baldwin case EVFILT_PROCDESC: 1193c915ff03SJohn Baldwin fprintf(fp, "%ju", (uintmax_t)ke->ident); 1194c915ff03SJohn Baldwin break; 1195c915ff03SJohn Baldwin case EVFILT_SIGNAL: 1196c915ff03SJohn Baldwin fputs(strsig2(ke->ident), fp); 1197c915ff03SJohn Baldwin break; 1198c915ff03SJohn Baldwin default: 1199c915ff03SJohn Baldwin fprintf(fp, "%p", (void *)ke->ident); 1200c915ff03SJohn Baldwin } 1201c915ff03SJohn Baldwin fprintf(fp, ",%s,%s,", xlookup(kevent_filters, ke->filter), 1202c915ff03SJohn Baldwin xlookup_bits(kevent_flags, ke->flags)); 1203c915ff03SJohn Baldwin switch (ke->filter) { 1204c915ff03SJohn Baldwin case EVFILT_READ: 1205c915ff03SJohn Baldwin case EVFILT_WRITE: 1206c915ff03SJohn Baldwin fputs(xlookup_bits(kevent_rdwr_fflags, ke->fflags), fp); 1207c915ff03SJohn Baldwin break; 1208c915ff03SJohn Baldwin case EVFILT_VNODE: 1209c915ff03SJohn Baldwin fputs(xlookup_bits(kevent_vnode_fflags, ke->fflags), fp); 1210c915ff03SJohn Baldwin break; 1211c915ff03SJohn Baldwin case EVFILT_PROC: 1212c915ff03SJohn Baldwin case EVFILT_PROCDESC: 1213c915ff03SJohn Baldwin fputs(xlookup_bits(kevent_proc_fflags, ke->fflags), fp); 1214c915ff03SJohn Baldwin break; 1215c915ff03SJohn Baldwin case EVFILT_TIMER: 1216c915ff03SJohn Baldwin fputs(xlookup_bits(kevent_timer_fflags, ke->fflags), fp); 1217c915ff03SJohn Baldwin break; 1218c915ff03SJohn Baldwin case EVFILT_USER: { 1219c915ff03SJohn Baldwin int ctrl, data; 1220c915ff03SJohn Baldwin 1221c915ff03SJohn Baldwin ctrl = ke->fflags & NOTE_FFCTRLMASK; 1222c915ff03SJohn Baldwin data = ke->fflags & NOTE_FFLAGSMASK; 1223c915ff03SJohn Baldwin if (input) { 1224c915ff03SJohn Baldwin fputs(xlookup(kevent_user_ffctrl, ctrl), fp); 1225c915ff03SJohn Baldwin if (ke->fflags & NOTE_TRIGGER) 1226c915ff03SJohn Baldwin fputs("|NOTE_TRIGGER", fp); 1227c915ff03SJohn Baldwin if (data != 0) 1228c915ff03SJohn Baldwin fprintf(fp, "|%#x", data); 1229c915ff03SJohn Baldwin } else { 1230c915ff03SJohn Baldwin fprintf(fp, "%#x", data); 1231c915ff03SJohn Baldwin } 1232c915ff03SJohn Baldwin break; 1233c915ff03SJohn Baldwin } 1234c915ff03SJohn Baldwin default: 1235c915ff03SJohn Baldwin fprintf(fp, "%#x", ke->fflags); 1236c915ff03SJohn Baldwin } 1237c915ff03SJohn Baldwin fprintf(fp, ",%p,%p", (void *)ke->data, (void *)ke->udata); 1238c915ff03SJohn Baldwin } 1239c915ff03SJohn Baldwin 1240195aef99SBryan Drewery static void 1241195aef99SBryan Drewery print_utrace(FILE *fp, void *utrace_addr, size_t len) 1242195aef99SBryan Drewery { 1243195aef99SBryan Drewery unsigned char *utrace_buffer; 1244195aef99SBryan Drewery 1245195aef99SBryan Drewery fprintf(fp, "{ "); 1246d6fb4894SJohn Baldwin if (sysdecode_utrace(fp, utrace_addr, len)) { 1247195aef99SBryan Drewery fprintf(fp, " }"); 1248195aef99SBryan Drewery return; 1249195aef99SBryan Drewery } 1250195aef99SBryan Drewery 1251195aef99SBryan Drewery utrace_buffer = utrace_addr; 1252195aef99SBryan Drewery fprintf(fp, "%zu:", len); 1253195aef99SBryan Drewery while (len--) 1254195aef99SBryan Drewery fprintf(fp, " %02x", *utrace_buffer++); 1255195aef99SBryan Drewery fprintf(fp, " }"); 1256195aef99SBryan Drewery } 1257195aef99SBryan Drewery 1258bbeaf6c0SSean Eric Fagan /* 1259bbeaf6c0SSean Eric Fagan * Converts a syscall argument into a string. Said string is 12604e3da534SJohn Baldwin * allocated via malloc(), so needs to be free()'d. sc is 1261bbeaf6c0SSean Eric Fagan * a pointer to the syscall description (see above); args is 1262bbeaf6c0SSean Eric Fagan * an array of all of the system call arguments. 1263bbeaf6c0SSean Eric Fagan */ 1264bbeaf6c0SSean Eric Fagan char * 12652b75c8adSJohn Baldwin print_arg(struct syscall_args *sc, unsigned long *args, long *retval, 126694355cfdSAndrey Zonov struct trussinfo *trussinfo) 1267d8984f48SDag-Erling Smørgrav { 1268f083f689SJohn Baldwin FILE *fp; 126994355cfdSAndrey Zonov char *tmp; 1270f083f689SJohn Baldwin size_t tmplen; 127194355cfdSAndrey Zonov pid_t pid; 1272d8984f48SDag-Erling Smørgrav 1273f083f689SJohn Baldwin fp = open_memstream(&tmp, &tmplen); 12742b75c8adSJohn Baldwin pid = trussinfo->curthread->proc->pid; 1275bbeaf6c0SSean Eric Fagan switch (sc->type & ARG_MASK) { 1276bbeaf6c0SSean Eric Fagan case Hex: 1277f083f689SJohn Baldwin fprintf(fp, "0x%x", (int)args[sc->offset]); 1278bbeaf6c0SSean Eric Fagan break; 1279bbeaf6c0SSean Eric Fagan case Octal: 1280f083f689SJohn Baldwin fprintf(fp, "0%o", (int)args[sc->offset]); 1281bbeaf6c0SSean Eric Fagan break; 1282bbeaf6c0SSean Eric Fagan case Int: 1283f083f689SJohn Baldwin fprintf(fp, "%d", (int)args[sc->offset]); 1284bbeaf6c0SSean Eric Fagan break; 1285808d9805SEd Schouten case UInt: 1286808d9805SEd Schouten fprintf(fp, "%u", (unsigned int)args[sc->offset]); 1287808d9805SEd Schouten break; 1288ebb2cc40SJohn Baldwin case PUInt: { 1289ebb2cc40SJohn Baldwin unsigned int val; 1290ebb2cc40SJohn Baldwin 1291ebb2cc40SJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], &val, 1292ebb2cc40SJohn Baldwin sizeof(val)) == 0) 1293ebb2cc40SJohn Baldwin fprintf(fp, "{ %u }", val); 1294ebb2cc40SJohn Baldwin else 1295ebb2cc40SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1296ebb2cc40SJohn Baldwin break; 1297ebb2cc40SJohn Baldwin } 1298fdb5bf37SJohn Baldwin case LongHex: 1299f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1300fdb5bf37SJohn Baldwin break; 1301b289a8d7SJohn Baldwin case Long: 1302f083f689SJohn Baldwin fprintf(fp, "%ld", args[sc->offset]); 1303b289a8d7SJohn Baldwin break; 1304e261fb2aSJohn Baldwin case Sizet: 1305e261fb2aSJohn Baldwin fprintf(fp, "%zu", (size_t)args[sc->offset]); 1306e261fb2aSJohn Baldwin break; 1307d8984f48SDag-Erling Smørgrav case Name: { 1308081e5c48SPav Lucistnik /* NULL-terminated string. */ 1309bbeaf6c0SSean Eric Fagan char *tmp2; 13104e3da534SJohn Baldwin 13115d2d083cSXin LI tmp2 = get_string(pid, (void*)args[sc->offset], 0); 1312f083f689SJohn Baldwin fprintf(fp, "\"%s\"", tmp2); 1313bbeaf6c0SSean Eric Fagan free(tmp2); 1314bbeaf6c0SSean Eric Fagan break; 1315d8984f48SDag-Erling Smørgrav } 1316d8984f48SDag-Erling Smørgrav case BinString: { 13174e3da534SJohn Baldwin /* 13184e3da534SJohn Baldwin * Binary block of data that might have printable characters. 13194e3da534SJohn Baldwin * XXX If type|OUT, assume that the length is the syscall's 13204e3da534SJohn Baldwin * return value. Otherwise, assume that the length of the block 13214e3da534SJohn Baldwin * is in the next syscall argument. 13224e3da534SJohn Baldwin */ 1323081e5c48SPav Lucistnik int max_string = trussinfo->strsize; 1324081e5c48SPav Lucistnik char tmp2[max_string + 1], *tmp3; 1325081e5c48SPav Lucistnik int len; 1326081e5c48SPav Lucistnik int truncated = 0; 1327081e5c48SPav Lucistnik 1328081e5c48SPav Lucistnik if (sc->type & OUT) 13292b75c8adSJohn Baldwin len = retval[0]; 1330081e5c48SPav Lucistnik else 1331081e5c48SPav Lucistnik len = args[sc->offset + 1]; 1332081e5c48SPav Lucistnik 13334e3da534SJohn Baldwin /* 13344e3da534SJohn Baldwin * Don't print more than max_string characters, to avoid word 13354e3da534SJohn Baldwin * wrap. If we have to truncate put some ... after the string. 1336081e5c48SPav Lucistnik */ 1337081e5c48SPav Lucistnik if (len > max_string) { 1338081e5c48SPav Lucistnik len = max_string; 1339081e5c48SPav Lucistnik truncated = 1; 1340081e5c48SPav Lucistnik } 134194355cfdSAndrey Zonov if (len && get_struct(pid, (void*)args[sc->offset], &tmp2, len) 134294355cfdSAndrey Zonov != -1) { 1343081e5c48SPav Lucistnik tmp3 = malloc(len * 4 + 1); 1344081e5c48SPav Lucistnik while (len) { 134594355cfdSAndrey Zonov if (strvisx(tmp3, tmp2, len, 134694355cfdSAndrey Zonov VIS_CSTYLE|VIS_TAB|VIS_NL) <= max_string) 1347081e5c48SPav Lucistnik break; 1348081e5c48SPav Lucistnik len--; 1349081e5c48SPav Lucistnik truncated = 1; 135080c7cc1cSPedro F. Giffuni } 1351f083f689SJohn Baldwin fprintf(fp, "\"%s\"%s", tmp3, truncated ? 135294355cfdSAndrey Zonov "..." : ""); 1353081e5c48SPav Lucistnik free(tmp3); 1354d8984f48SDag-Erling Smørgrav } else { 1355f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1356081e5c48SPav Lucistnik } 1357081e5c48SPav Lucistnik break; 1358d8984f48SDag-Erling Smørgrav } 135968055893SJohn Baldwin case ExecArgs: 136068055893SJohn Baldwin case ExecEnv: 1361d8984f48SDag-Erling Smørgrav case StringArray: { 1362890843c1SJohn Baldwin uintptr_t addr; 1363890843c1SJohn Baldwin union { 1364890843c1SJohn Baldwin char *strarray[0]; 1365890843c1SJohn Baldwin char buf[PAGE_SIZE]; 1366890843c1SJohn Baldwin } u; 13679897b203SMatthew N. Dodd char *string; 1368890843c1SJohn Baldwin size_t len; 13692b75c8adSJohn Baldwin u_int first, i; 13709897b203SMatthew N. Dodd 1371890843c1SJohn Baldwin /* 137268055893SJohn Baldwin * Only parse argv[] and environment arrays from exec calls 137368055893SJohn Baldwin * if requested. 137468055893SJohn Baldwin */ 137568055893SJohn Baldwin if (((sc->type & ARG_MASK) == ExecArgs && 137668055893SJohn Baldwin (trussinfo->flags & EXECVEARGS) == 0) || 137768055893SJohn Baldwin ((sc->type & ARG_MASK) == ExecEnv && 137868055893SJohn Baldwin (trussinfo->flags & EXECVEENVS) == 0)) { 137968055893SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 138068055893SJohn Baldwin break; 138168055893SJohn Baldwin } 138268055893SJohn Baldwin 138368055893SJohn Baldwin /* 1384890843c1SJohn Baldwin * Read a page of pointers at a time. Punt if the top-level 1385890843c1SJohn Baldwin * pointer is not aligned. Note that the first read is of 1386890843c1SJohn Baldwin * a partial page. 1387890843c1SJohn Baldwin */ 1388890843c1SJohn Baldwin addr = args[sc->offset]; 1389890843c1SJohn Baldwin if (addr % sizeof(char *) != 0) { 1390890843c1SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1391890843c1SJohn Baldwin break; 13929897b203SMatthew N. Dodd } 13939897b203SMatthew N. Dodd 1394890843c1SJohn Baldwin len = PAGE_SIZE - (addr & PAGE_MASK); 1395890843c1SJohn Baldwin if (get_struct(pid, (void *)addr, u.buf, len) == -1) { 1396890843c1SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1397890843c1SJohn Baldwin break; 13989897b203SMatthew N. Dodd } 1399890843c1SJohn Baldwin 1400890843c1SJohn Baldwin fputc('[', fp); 1401890843c1SJohn Baldwin first = 1; 1402890843c1SJohn Baldwin i = 0; 1403890843c1SJohn Baldwin while (u.strarray[i] != NULL) { 1404890843c1SJohn Baldwin string = get_string(pid, u.strarray[i], 0); 1405890843c1SJohn Baldwin fprintf(fp, "%s \"%s\"", first ? "" : ",", string); 1406890843c1SJohn Baldwin free(string); 1407890843c1SJohn Baldwin first = 0; 1408890843c1SJohn Baldwin 1409890843c1SJohn Baldwin i++; 1410890843c1SJohn Baldwin if (i == len / sizeof(char *)) { 1411890843c1SJohn Baldwin addr += len; 1412890843c1SJohn Baldwin len = PAGE_SIZE; 1413890843c1SJohn Baldwin if (get_struct(pid, (void *)addr, u.buf, len) == 1414890843c1SJohn Baldwin -1) { 1415890843c1SJohn Baldwin fprintf(fp, ", <inval>"); 1416890843c1SJohn Baldwin break; 1417890843c1SJohn Baldwin } 1418890843c1SJohn Baldwin i = 0; 1419890843c1SJohn Baldwin } 1420890843c1SJohn Baldwin } 1421890843c1SJohn Baldwin fputs(" ]", fp); 14229897b203SMatthew N. Dodd break; 1423d8984f48SDag-Erling Smørgrav } 142410aeefc9SMarcel Moolenaar #ifdef __LP64__ 142510aeefc9SMarcel Moolenaar case Quad: 142672df19e7SJohn Baldwin fprintf(fp, "%ld", args[sc->offset]); 142772df19e7SJohn Baldwin break; 142872df19e7SJohn Baldwin case QuadHex: 1429f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 143010aeefc9SMarcel Moolenaar break; 143110aeefc9SMarcel Moolenaar #else 143272df19e7SJohn Baldwin case Quad: 143372df19e7SJohn Baldwin case QuadHex: { 143410aeefc9SMarcel Moolenaar unsigned long long ll; 14354e3da534SJohn Baldwin 14362b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN 14372b75c8adSJohn Baldwin ll = (unsigned long long)args[sc->offset + 1] << 32 | 14382b75c8adSJohn Baldwin args[sc->offset]; 14392b75c8adSJohn Baldwin #else 14402b75c8adSJohn Baldwin ll = (unsigned long long)args[sc->offset] << 32 | 14412b75c8adSJohn Baldwin args[sc->offset + 1]; 14422b75c8adSJohn Baldwin #endif 144372df19e7SJohn Baldwin if ((sc->type & ARG_MASK) == Quad) 144472df19e7SJohn Baldwin fprintf(fp, "%lld", ll); 144572df19e7SJohn Baldwin else 1446f083f689SJohn Baldwin fprintf(fp, "0x%llx", ll); 1447bbeaf6c0SSean Eric Fagan break; 1448bbeaf6c0SSean Eric Fagan } 144910aeefc9SMarcel Moolenaar #endif 1450b60a095bSJohn Baldwin case PQuadHex: { 1451b60a095bSJohn Baldwin uint64_t val; 1452b60a095bSJohn Baldwin 1453b60a095bSJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], &val, 1454b60a095bSJohn Baldwin sizeof(val)) == 0) 1455b60a095bSJohn Baldwin fprintf(fp, "{ 0x%jx }", (uintmax_t)val); 1456b60a095bSJohn Baldwin else 1457b60a095bSJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1458b60a095bSJohn Baldwin break; 1459b60a095bSJohn Baldwin } 1460bbeaf6c0SSean Eric Fagan case Ptr: 1461f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1462bbeaf6c0SSean Eric Fagan break; 1463d8984f48SDag-Erling Smørgrav case Readlinkres: { 14642bae4eb3SAlfred Perlstein char *tmp2; 14654e3da534SJohn Baldwin 14662b75c8adSJohn Baldwin if (retval[0] == -1) 14672bae4eb3SAlfred Perlstein break; 14682b75c8adSJohn Baldwin tmp2 = get_string(pid, (void*)args[sc->offset], retval[0]); 1469f083f689SJohn Baldwin fprintf(fp, "\"%s\"", tmp2); 14702bae4eb3SAlfred Perlstein free(tmp2); 14712bae4eb3SAlfred Perlstein break; 1472d8984f48SDag-Erling Smørgrav } 1473d8984f48SDag-Erling Smørgrav case Ioctl: { 14744e3da534SJohn Baldwin const char *temp; 14754e3da534SJohn Baldwin unsigned long cmd; 14764e3da534SJohn Baldwin 14774e3da534SJohn Baldwin cmd = args[sc->offset]; 1478265e5898SJohn Baldwin temp = sysdecode_ioctlname(cmd); 147994355cfdSAndrey Zonov if (temp) 1480f083f689SJohn Baldwin fputs(temp, fp); 148194355cfdSAndrey Zonov else { 1482f083f689SJohn Baldwin fprintf(fp, "0x%lx { IO%s%s 0x%lx('%c'), %lu, %lu }", 14834e3da534SJohn Baldwin cmd, cmd & IOC_OUT ? "R" : "", 14844e3da534SJohn Baldwin cmd & IOC_IN ? "W" : "", IOCGROUP(cmd), 14854e3da534SJohn Baldwin isprint(IOCGROUP(cmd)) ? (char)IOCGROUP(cmd) : '?', 14864e3da534SJohn Baldwin cmd & 0xFF, IOCPARM_LEN(cmd)); 1487081e5c48SPav Lucistnik } 1488081e5c48SPav Lucistnik break; 1489d8984f48SDag-Erling Smørgrav } 1490d8984f48SDag-Erling Smørgrav case Timespec: { 1491e45a5a0dSDavid Malone struct timespec ts; 14924e3da534SJohn Baldwin 149394355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &ts, 149494355cfdSAndrey Zonov sizeof(ts)) != -1) 1495a1436773SJohn Baldwin fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec, 149694355cfdSAndrey Zonov ts.tv_nsec); 1497e45a5a0dSDavid Malone else 1498f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1499e45a5a0dSDavid Malone break; 1500d8984f48SDag-Erling Smørgrav } 15017d897327SJohn Baldwin case Timespec2: { 15027d897327SJohn Baldwin struct timespec ts[2]; 15037d897327SJohn Baldwin const char *sep; 15047d897327SJohn Baldwin unsigned int i; 15057d897327SJohn Baldwin 15067d897327SJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], &ts, sizeof(ts)) 15077d897327SJohn Baldwin != -1) { 15081e2ec671SJohn Baldwin fputs("{ ", fp); 15097d897327SJohn Baldwin sep = ""; 15107d897327SJohn Baldwin for (i = 0; i < nitems(ts); i++) { 15117d897327SJohn Baldwin fputs(sep, fp); 15127d897327SJohn Baldwin sep = ", "; 15137d897327SJohn Baldwin switch (ts[i].tv_nsec) { 15147d897327SJohn Baldwin case UTIME_NOW: 15157d897327SJohn Baldwin fprintf(fp, "UTIME_NOW"); 15167d897327SJohn Baldwin break; 15177d897327SJohn Baldwin case UTIME_OMIT: 15187d897327SJohn Baldwin fprintf(fp, "UTIME_OMIT"); 15197d897327SJohn Baldwin break; 15207d897327SJohn Baldwin default: 1521a1436773SJohn Baldwin fprintf(fp, "%jd.%09ld", 1522a1436773SJohn Baldwin (intmax_t)ts[i].tv_sec, 1523a1436773SJohn Baldwin ts[i].tv_nsec); 15247d897327SJohn Baldwin break; 15257d897327SJohn Baldwin } 15267d897327SJohn Baldwin } 15271e2ec671SJohn Baldwin fputs(" }", fp); 15287d897327SJohn Baldwin } else 1529f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 15307d897327SJohn Baldwin break; 15317d897327SJohn Baldwin } 1532d8984f48SDag-Erling Smørgrav case Timeval: { 1533e45a5a0dSDavid Malone struct timeval tv; 15344e3da534SJohn Baldwin 153594355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv)) 153694355cfdSAndrey Zonov != -1) 1537a1436773SJohn Baldwin fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec, 153894355cfdSAndrey Zonov tv.tv_usec); 1539081e5c48SPav Lucistnik else 1540f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1541081e5c48SPav Lucistnik break; 1542d8984f48SDag-Erling Smørgrav } 1543d8984f48SDag-Erling Smørgrav case Timeval2: { 1544081e5c48SPav Lucistnik struct timeval tv[2]; 15454e3da534SJohn Baldwin 154694355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv)) 154794355cfdSAndrey Zonov != -1) 1548a1436773SJohn Baldwin fprintf(fp, "{ %jd.%06ld, %jd.%06ld }", 1549a1436773SJohn Baldwin (intmax_t)tv[0].tv_sec, tv[0].tv_usec, 1550a1436773SJohn Baldwin (intmax_t)tv[1].tv_sec, tv[1].tv_usec); 1551e45a5a0dSDavid Malone else 1552f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1553e45a5a0dSDavid Malone break; 1554d8984f48SDag-Erling Smørgrav } 1555d8984f48SDag-Erling Smørgrav case Itimerval: { 1556e45a5a0dSDavid Malone struct itimerval itv; 15574e3da534SJohn Baldwin 155894355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &itv, 155994355cfdSAndrey Zonov sizeof(itv)) != -1) 1560a1436773SJohn Baldwin fprintf(fp, "{ %jd.%06ld, %jd.%06ld }", 1561a1436773SJohn Baldwin (intmax_t)itv.it_interval.tv_sec, 1562081e5c48SPav Lucistnik itv.it_interval.tv_usec, 1563a1436773SJohn Baldwin (intmax_t)itv.it_value.tv_sec, 1564081e5c48SPav Lucistnik itv.it_value.tv_usec); 1565e45a5a0dSDavid Malone else 1566f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1567e45a5a0dSDavid Malone break; 1568d8984f48SDag-Erling Smørgrav } 15691c99a22aSSteven Hartland case LinuxSockArgs: 15701c99a22aSSteven Hartland { 15711c99a22aSSteven Hartland struct linux_socketcall_args largs; 15724e3da534SJohn Baldwin 15731c99a22aSSteven Hartland if (get_struct(pid, (void *)args[sc->offset], (void *)&largs, 1574fb7eabb0SJohn Baldwin sizeof(largs)) != -1) 1575f083f689SJohn Baldwin fprintf(fp, "{ %s, 0x%lx }", 1576fb7eabb0SJohn Baldwin lookup(linux_socketcall_ops, largs.what, 10), 15770a46af44SJohn Baldwin (long unsigned int)largs.args); 1578fb7eabb0SJohn Baldwin else 1579f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 15801c99a22aSSteven Hartland break; 15811c99a22aSSteven Hartland } 1582d8984f48SDag-Erling Smørgrav case Pollfd: { 1583e45a5a0dSDavid Malone /* 158494355cfdSAndrey Zonov * XXX: A Pollfd argument expects the /next/ syscall argument 158594355cfdSAndrey Zonov * to be the number of fds in the array. This matches the poll 158694355cfdSAndrey Zonov * syscall. 1587e45a5a0dSDavid Malone */ 1588e45a5a0dSDavid Malone struct pollfd *pfd; 1589e45a5a0dSDavid Malone int numfds = args[sc->offset + 1]; 1590f083f689SJohn Baldwin size_t bytes = sizeof(struct pollfd) * numfds; 1591f083f689SJohn Baldwin int i; 1592e45a5a0dSDavid Malone 1593e45a5a0dSDavid Malone if ((pfd = malloc(bytes)) == NULL) 1594f083f689SJohn Baldwin err(1, "Cannot malloc %zu bytes for pollfd array", 159594355cfdSAndrey Zonov bytes); 159694355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], pfd, bytes) 159794355cfdSAndrey Zonov != -1) { 1598f083f689SJohn Baldwin fputs("{", fp); 1599e45a5a0dSDavid Malone for (i = 0; i < numfds; i++) { 1600f083f689SJohn Baldwin fprintf(fp, " %d/%s", pfd[i].fd, 1601081e5c48SPav Lucistnik xlookup_bits(poll_flags, pfd[i].events)); 1602e45a5a0dSDavid Malone } 1603f083f689SJohn Baldwin fputs(" }", fp); 1604d8984f48SDag-Erling Smørgrav } else { 1605f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1606e45a5a0dSDavid Malone } 1607d8984f48SDag-Erling Smørgrav free(pfd); 1608e45a5a0dSDavid Malone break; 1609d8984f48SDag-Erling Smørgrav } 1610d8984f48SDag-Erling Smørgrav case Fd_set: { 1611e45a5a0dSDavid Malone /* 161294355cfdSAndrey Zonov * XXX: A Fd_set argument expects the /first/ syscall argument 161394355cfdSAndrey Zonov * to be the number of fds in the array. This matches the 161494355cfdSAndrey Zonov * select syscall. 1615e45a5a0dSDavid Malone */ 1616e45a5a0dSDavid Malone fd_set *fds; 1617e45a5a0dSDavid Malone int numfds = args[0]; 1618f083f689SJohn Baldwin size_t bytes = _howmany(numfds, _NFDBITS) * _NFDBITS; 1619f083f689SJohn Baldwin int i; 1620e45a5a0dSDavid Malone 1621e45a5a0dSDavid Malone if ((fds = malloc(bytes)) == NULL) 1622f083f689SJohn Baldwin err(1, "Cannot malloc %zu bytes for fd_set array", 162394355cfdSAndrey Zonov bytes); 162494355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], fds, bytes) 162594355cfdSAndrey Zonov != -1) { 1626f083f689SJohn Baldwin fputs("{", fp); 1627e45a5a0dSDavid Malone for (i = 0; i < numfds; i++) { 1628f083f689SJohn Baldwin if (FD_ISSET(i, fds)) 1629f083f689SJohn Baldwin fprintf(fp, " %d", i); 1630e45a5a0dSDavid Malone } 1631f083f689SJohn Baldwin fputs(" }", fp); 163294355cfdSAndrey Zonov } else 1633f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1634d8984f48SDag-Erling Smørgrav free(fds); 1635e45a5a0dSDavid Malone break; 1636d8984f48SDag-Erling Smørgrav } 163734763d1cSJohn Baldwin case Signal: 1638f083f689SJohn Baldwin fputs(strsig2(args[sc->offset]), fp); 1639f0ebbc29SDag-Erling Smørgrav break; 1640d8984f48SDag-Erling Smørgrav case Sigset: { 1641081e5c48SPav Lucistnik long sig; 1642081e5c48SPav Lucistnik sigset_t ss; 1643f083f689SJohn Baldwin int i, first; 1644081e5c48SPav Lucistnik 1645081e5c48SPav Lucistnik sig = args[sc->offset]; 164694355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], (void *)&ss, 164794355cfdSAndrey Zonov sizeof(ss)) == -1) { 1648f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1649081e5c48SPav Lucistnik break; 1650081e5c48SPav Lucistnik } 1651f083f689SJohn Baldwin fputs("{ ", fp); 1652f083f689SJohn Baldwin first = 1; 1653d8984f48SDag-Erling Smørgrav for (i = 1; i < sys_nsig; i++) { 165434763d1cSJohn Baldwin if (sigismember(&ss, i)) { 1655f083f689SJohn Baldwin fprintf(fp, "%s%s", !first ? "|" : "", 16569289f547SJohn Baldwin strsig2(i)); 1657f083f689SJohn Baldwin first = 0; 165834763d1cSJohn Baldwin } 1659081e5c48SPav Lucistnik } 1660f083f689SJohn Baldwin if (!first) 1661f083f689SJohn Baldwin fputc(' ', fp); 1662f083f689SJohn Baldwin fputc('}', fp); 1663081e5c48SPav Lucistnik break; 1664d8984f48SDag-Erling Smørgrav } 16659289f547SJohn Baldwin case Sigprocmask: 16669289f547SJohn Baldwin print_integer_arg(sysdecode_sigprocmask_how, fp, 16679289f547SJohn Baldwin args[sc->offset]); 1668894b8f7aSAlfred Perlstein break; 16699289f547SJohn Baldwin case Fcntlflag: 16704e3da534SJohn Baldwin /* XXX: Output depends on the value of the previous argument. */ 16719289f547SJohn Baldwin if (sysdecode_fcntl_arg_p(args[sc->offset - 1])) 16729289f547SJohn Baldwin sysdecode_fcntl_arg(fp, args[sc->offset - 1], 16739289f547SJohn Baldwin args[sc->offset], 16); 1674081e5c48SPav Lucistnik break; 1675081e5c48SPav Lucistnik case Open: 16769289f547SJohn Baldwin print_mask_arg(sysdecode_open_flags, fp, args[sc->offset]); 1677081e5c48SPav Lucistnik break; 1678081e5c48SPav Lucistnik case Fcntl: 16799289f547SJohn Baldwin print_integer_arg(sysdecode_fcntl_cmd, fp, args[sc->offset]); 1680081e5c48SPav Lucistnik break; 1681894b8f7aSAlfred Perlstein case Mprot: 16829289f547SJohn Baldwin print_mask_arg(sysdecode_mmap_prot, fp, args[sc->offset]); 1683894b8f7aSAlfred Perlstein break; 16849289f547SJohn Baldwin case Mmapflags: 16859289f547SJohn Baldwin print_mask_arg(sysdecode_mmap_flags, fp, args[sc->offset]); 1686894b8f7aSAlfred Perlstein break; 1687fde3a7d1SAlfred Perlstein case Whence: 16889289f547SJohn Baldwin print_integer_arg(sysdecode_whence, fp, args[sc->offset]); 1689081e5c48SPav Lucistnik break; 1690081e5c48SPav Lucistnik case Sockdomain: 16919289f547SJohn Baldwin print_integer_arg(sysdecode_socketdomain, fp, args[sc->offset]); 1692081e5c48SPav Lucistnik break; 16939289f547SJohn Baldwin case Socktype: 16949289f547SJohn Baldwin print_mask_arg(sysdecode_socket_type, fp, args[sc->offset]); 1695081e5c48SPav Lucistnik break; 1696081e5c48SPav Lucistnik case Shutdown: 16979289f547SJohn Baldwin print_integer_arg(sysdecode_shutdown_how, fp, args[sc->offset]); 1698081e5c48SPav Lucistnik break; 1699081e5c48SPav Lucistnik case Resource: 17009289f547SJohn Baldwin print_integer_arg(sysdecode_rlimit, fp, args[sc->offset]); 1701081e5c48SPav Lucistnik break; 1702ee8aa41dSJohn Baldwin case RusageWho: 1703ee8aa41dSJohn Baldwin print_integer_arg(sysdecode_getrusage_who, fp, args[sc->offset]); 1704ee8aa41dSJohn Baldwin break; 1705081e5c48SPav Lucistnik case Pathconf: 1706f083f689SJohn Baldwin fputs(xlookup(pathconf_arg, args[sc->offset]), fp); 1707fde3a7d1SAlfred Perlstein break; 17089e1db66eSMark Johnston case Rforkflags: 17099289f547SJohn Baldwin print_mask_arg(sysdecode_rfork_flags, fp, args[sc->offset]); 17109e1db66eSMark Johnston break; 1711d8984f48SDag-Erling Smørgrav case Sockaddr: { 17129ddd1412SDag-Erling Smørgrav char addr[64]; 17131be5d704SMark Murray struct sockaddr_in *lsin; 17141be5d704SMark Murray struct sockaddr_in6 *lsin6; 1715dec17687SBrian Feldman struct sockaddr_un *sun; 1716dec17687SBrian Feldman struct sockaddr *sa; 171766917ca9SJohn Baldwin socklen_t len; 1718dec17687SBrian Feldman u_char *q; 17199ddd1412SDag-Erling Smørgrav 1720a7a08c7eSMarcel Moolenaar if (args[sc->offset] == 0) { 1721f083f689SJohn Baldwin fputs("NULL", fp); 1722a7a08c7eSMarcel Moolenaar break; 1723a7a08c7eSMarcel Moolenaar } 1724a7a08c7eSMarcel Moolenaar 17256a656761SAlfred Perlstein /* 172666917ca9SJohn Baldwin * Extract the address length from the next argument. If 172766917ca9SJohn Baldwin * this is an output sockaddr (OUT is set), then the 172866917ca9SJohn Baldwin * next argument is a pointer to a socklen_t. Otherwise 172966917ca9SJohn Baldwin * the next argument contains a socklen_t by value. 17306a656761SAlfred Perlstein */ 173166917ca9SJohn Baldwin if (sc->type & OUT) { 173266917ca9SJohn Baldwin if (get_struct(pid, (void *)args[sc->offset + 1], 173366917ca9SJohn Baldwin &len, sizeof(len)) == -1) { 173466917ca9SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 17356a656761SAlfred Perlstein break; 17366a656761SAlfred Perlstein } 173766917ca9SJohn Baldwin } else 173866917ca9SJohn Baldwin len = args[sc->offset + 1]; 173966917ca9SJohn Baldwin 174066917ca9SJohn Baldwin /* If the length is too small, just bail. */ 174166917ca9SJohn Baldwin if (len < sizeof(*sa)) { 1742f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1743f083f689SJohn Baldwin break; 17449ddd1412SDag-Erling Smørgrav } 1745dec17687SBrian Feldman 174666917ca9SJohn Baldwin sa = calloc(1, len); 174766917ca9SJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], sa, len) == -1) { 174866917ca9SJohn Baldwin free(sa); 174966917ca9SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 175066917ca9SJohn Baldwin break; 175166917ca9SJohn Baldwin } 175266917ca9SJohn Baldwin 175366917ca9SJohn Baldwin switch (sa->sa_family) { 1754dec17687SBrian Feldman case AF_INET: 175566917ca9SJohn Baldwin if (len < sizeof(*lsin)) 175666917ca9SJohn Baldwin goto sockaddr_short; 175766917ca9SJohn Baldwin lsin = (struct sockaddr_in *)(void *)sa; 17584e3da534SJohn Baldwin inet_ntop(AF_INET, &lsin->sin_addr, addr, sizeof(addr)); 1759f083f689SJohn Baldwin fprintf(fp, "{ AF_INET %s:%d }", addr, 176094355cfdSAndrey Zonov htons(lsin->sin_port)); 1761dec17687SBrian Feldman break; 1762dec17687SBrian Feldman case AF_INET6: 176366917ca9SJohn Baldwin if (len < sizeof(*lsin6)) 176466917ca9SJohn Baldwin goto sockaddr_short; 176566917ca9SJohn Baldwin lsin6 = (struct sockaddr_in6 *)(void *)sa; 176694355cfdSAndrey Zonov inet_ntop(AF_INET6, &lsin6->sin6_addr, addr, 17674e3da534SJohn Baldwin sizeof(addr)); 1768f083f689SJohn Baldwin fprintf(fp, "{ AF_INET6 [%s]:%d }", addr, 176994355cfdSAndrey Zonov htons(lsin6->sin6_port)); 1770dec17687SBrian Feldman break; 1771dec17687SBrian Feldman case AF_UNIX: 177266917ca9SJohn Baldwin sun = (struct sockaddr_un *)sa; 177366917ca9SJohn Baldwin fprintf(fp, "{ AF_UNIX \"%.*s\" }", 177466917ca9SJohn Baldwin (int)(len - offsetof(struct sockaddr_un, sun_path)), 177566917ca9SJohn Baldwin sun->sun_path); 1776dec17687SBrian Feldman break; 1777dec17687SBrian Feldman default: 177866917ca9SJohn Baldwin sockaddr_short: 1779f083f689SJohn Baldwin fprintf(fp, 1780f083f689SJohn Baldwin "{ sa_len = %d, sa_family = %d, sa_data = {", 1781f083f689SJohn Baldwin (int)sa->sa_len, (int)sa->sa_family); 1782f083f689SJohn Baldwin for (q = (u_char *)sa->sa_data; 178366917ca9SJohn Baldwin q < (u_char *)sa + len; q++) 1784f083f689SJohn Baldwin fprintf(fp, "%s 0x%02x", 1785f083f689SJohn Baldwin q == (u_char *)sa->sa_data ? "" : ",", 1786f083f689SJohn Baldwin *q); 1787f083f689SJohn Baldwin fputs(" } }", fp); 1788dec17687SBrian Feldman } 178966917ca9SJohn Baldwin free(sa); 17909ddd1412SDag-Erling Smørgrav break; 1791d8984f48SDag-Erling Smørgrav } 1792d8984f48SDag-Erling Smørgrav case Sigaction: { 1793e45a5a0dSDavid Malone struct sigaction sa; 1794e45a5a0dSDavid Malone 179594355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &sa, sizeof(sa)) 179694355cfdSAndrey Zonov != -1) { 1797f083f689SJohn Baldwin fputs("{ ", fp); 1798e45a5a0dSDavid Malone if (sa.sa_handler == SIG_DFL) 1799f083f689SJohn Baldwin fputs("SIG_DFL", fp); 1800e45a5a0dSDavid Malone else if (sa.sa_handler == SIG_IGN) 1801f083f689SJohn Baldwin fputs("SIG_IGN", fp); 1802e45a5a0dSDavid Malone else 1803f083f689SJohn Baldwin fprintf(fp, "%p", sa.sa_handler); 1804f083f689SJohn Baldwin fprintf(fp, " %s ss_t }", 1805081e5c48SPav Lucistnik xlookup_bits(sigaction_flags, sa.sa_flags)); 180694355cfdSAndrey Zonov } else 1807f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1808e45a5a0dSDavid Malone break; 1809d8984f48SDag-Erling Smørgrav } 1810d8984f48SDag-Erling Smørgrav case Kevent: { 1811081e5c48SPav Lucistnik /* 18124e3da534SJohn Baldwin * XXX XXX: The size of the array is determined by either the 1813081e5c48SPav Lucistnik * next syscall argument, or by the syscall return value, 1814081e5c48SPav Lucistnik * depending on which argument number we are. This matches the 1815081e5c48SPav Lucistnik * kevent syscall, but luckily that's the only syscall that uses 1816081e5c48SPav Lucistnik * them. 1817081e5c48SPav Lucistnik */ 1818081e5c48SPav Lucistnik struct kevent *ke; 1819081e5c48SPav Lucistnik int numevents = -1; 1820f083f689SJohn Baldwin size_t bytes; 1821f083f689SJohn Baldwin int i; 1822081e5c48SPav Lucistnik 1823081e5c48SPav Lucistnik if (sc->offset == 1) 1824081e5c48SPav Lucistnik numevents = args[sc->offset+1]; 18252b75c8adSJohn Baldwin else if (sc->offset == 3 && retval[0] != -1) 18262b75c8adSJohn Baldwin numevents = retval[0]; 1827081e5c48SPav Lucistnik 1828f083f689SJohn Baldwin if (numevents >= 0) { 1829081e5c48SPav Lucistnik bytes = sizeof(struct kevent) * numevents; 1830081e5c48SPav Lucistnik if ((ke = malloc(bytes)) == NULL) 1831f083f689SJohn Baldwin err(1, 1832f083f689SJohn Baldwin "Cannot malloc %zu bytes for kevent array", 183394355cfdSAndrey Zonov bytes); 1834f083f689SJohn Baldwin } else 1835f083f689SJohn Baldwin ke = NULL; 183694355cfdSAndrey Zonov if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset], 183794355cfdSAndrey Zonov ke, bytes) != -1) { 1838f083f689SJohn Baldwin fputc('{', fp); 1839c915ff03SJohn Baldwin for (i = 0; i < numevents; i++) { 1840c915ff03SJohn Baldwin fputc(' ', fp); 1841c915ff03SJohn Baldwin print_kevent(fp, &ke[i], sc->offset == 1); 1842c915ff03SJohn Baldwin } 1843f083f689SJohn Baldwin fputs(" }", fp); 1844d8984f48SDag-Erling Smørgrav } else { 1845f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1846081e5c48SPav Lucistnik } 1847d8984f48SDag-Erling Smørgrav free(ke); 1848081e5c48SPav Lucistnik break; 1849d8984f48SDag-Erling Smørgrav } 1850d8984f48SDag-Erling Smørgrav case Stat: { 1851081e5c48SPav Lucistnik struct stat st; 18524e3da534SJohn Baldwin 185394355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st)) 185494355cfdSAndrey Zonov != -1) { 1855081e5c48SPav Lucistnik char mode[12]; 18564e3da534SJohn Baldwin 1857081e5c48SPav Lucistnik strmode(st.st_mode, mode); 1858f083f689SJohn Baldwin fprintf(fp, 1859b38fbc2eSJohn Baldwin "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode, 1860b38fbc2eSJohn Baldwin (uintmax_t)st.st_ino, (intmax_t)st.st_size, 186194355cfdSAndrey Zonov (long)st.st_blksize); 1862d8984f48SDag-Erling Smørgrav } else { 1863f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1864081e5c48SPav Lucistnik } 1865081e5c48SPav Lucistnik break; 1866d8984f48SDag-Erling Smørgrav } 1867a776866bSBryan Drewery case StatFs: { 1868a776866bSBryan Drewery unsigned int i; 1869a776866bSBryan Drewery struct statfs buf; 18700a71c082SBryan Drewery 1871a776866bSBryan Drewery if (get_struct(pid, (void *)args[sc->offset], &buf, 1872a776866bSBryan Drewery sizeof(buf)) != -1) { 1873a776866bSBryan Drewery char fsid[17]; 1874a776866bSBryan Drewery 1875a776866bSBryan Drewery bzero(fsid, sizeof(fsid)); 1876a776866bSBryan Drewery if (buf.f_fsid.val[0] != 0 || buf.f_fsid.val[1] != 0) { 1877a776866bSBryan Drewery for (i = 0; i < sizeof(buf.f_fsid); i++) 1878a776866bSBryan Drewery snprintf(&fsid[i*2], 1879a776866bSBryan Drewery sizeof(fsid) - (i*2), "%02x", 1880a776866bSBryan Drewery ((u_char *)&buf.f_fsid)[i]); 1881a776866bSBryan Drewery } 1882a776866bSBryan Drewery fprintf(fp, 1883a776866bSBryan Drewery "{ fstypename=%s,mntonname=%s,mntfromname=%s," 1884a776866bSBryan Drewery "fsid=%s }", buf.f_fstypename, buf.f_mntonname, 1885a776866bSBryan Drewery buf.f_mntfromname, fsid); 1886a776866bSBryan Drewery } else 1887a776866bSBryan Drewery fprintf(fp, "0x%lx", args[sc->offset]); 1888a776866bSBryan Drewery break; 1889a776866bSBryan Drewery } 1890a776866bSBryan Drewery 1891d8984f48SDag-Erling Smørgrav case Rusage: { 1892081e5c48SPav Lucistnik struct rusage ru; 18934e3da534SJohn Baldwin 189494355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru)) 189594355cfdSAndrey Zonov != -1) { 1896f083f689SJohn Baldwin fprintf(fp, 1897a1436773SJohn Baldwin "{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }", 1898a1436773SJohn Baldwin (intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec, 1899a1436773SJohn Baldwin (intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec, 1900081e5c48SPav Lucistnik ru.ru_inblock, ru.ru_oublock); 190194355cfdSAndrey Zonov } else 1902f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1903081e5c48SPav Lucistnik break; 1904d8984f48SDag-Erling Smørgrav } 1905d8984f48SDag-Erling Smørgrav case Rlimit: { 1906081e5c48SPav Lucistnik struct rlimit rl; 19074e3da534SJohn Baldwin 190894355cfdSAndrey Zonov if (get_struct(pid, (void *)args[sc->offset], &rl, sizeof(rl)) 190994355cfdSAndrey Zonov != -1) { 1910f083f689SJohn Baldwin fprintf(fp, "{ cur=%ju,max=%ju }", 1911081e5c48SPav Lucistnik rl.rlim_cur, rl.rlim_max); 191294355cfdSAndrey Zonov } else 1913f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 1914081e5c48SPav Lucistnik break; 1915d8984f48SDag-Erling Smørgrav } 191634763d1cSJohn Baldwin case ExitStatus: { 191734763d1cSJohn Baldwin int status; 1918f083f689SJohn Baldwin 191934763d1cSJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], &status, 192034763d1cSJohn Baldwin sizeof(status)) != -1) { 1921f083f689SJohn Baldwin fputs("{ ", fp); 192234763d1cSJohn Baldwin if (WIFCONTINUED(status)) 1923f083f689SJohn Baldwin fputs("CONTINUED", fp); 192434763d1cSJohn Baldwin else if (WIFEXITED(status)) 1925f083f689SJohn Baldwin fprintf(fp, "EXITED,val=%d", 192634763d1cSJohn Baldwin WEXITSTATUS(status)); 192734763d1cSJohn Baldwin else if (WIFSIGNALED(status)) 1928f083f689SJohn Baldwin fprintf(fp, "SIGNALED,sig=%s%s", 1929f083f689SJohn Baldwin strsig2(WTERMSIG(status)), 193034763d1cSJohn Baldwin WCOREDUMP(status) ? ",cored" : ""); 193134763d1cSJohn Baldwin else 1932f083f689SJohn Baldwin fprintf(fp, "STOPPED,sig=%s", 1933f083f689SJohn Baldwin strsig2(WTERMSIG(status))); 1934f083f689SJohn Baldwin fputs(" }", fp); 193534763d1cSJohn Baldwin } else 1936f083f689SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 193734763d1cSJohn Baldwin break; 193834763d1cSJohn Baldwin } 193934763d1cSJohn Baldwin case Waitoptions: 19409289f547SJohn Baldwin print_mask_arg(sysdecode_wait6_options, fp, args[sc->offset]); 194134763d1cSJohn Baldwin break; 194234763d1cSJohn Baldwin case Idtype: 19439289f547SJohn Baldwin print_integer_arg(sysdecode_idtype, fp, args[sc->offset]); 194434763d1cSJohn Baldwin break; 194555648840SJohn Baldwin case Procctl: 19469289f547SJohn Baldwin print_integer_arg(sysdecode_procctl_cmd, fp, args[sc->offset]); 194755648840SJohn Baldwin break; 1948fdb5bf37SJohn Baldwin case Umtxop: 19499289f547SJohn Baldwin print_integer_arg(sysdecode_umtx_op, fp, args[sc->offset]); 1950fdb5bf37SJohn Baldwin break; 19517d897327SJohn Baldwin case Atfd: 19529289f547SJohn Baldwin print_integer_arg(sysdecode_atfd, fp, args[sc->offset]); 19537d897327SJohn Baldwin break; 19547d897327SJohn Baldwin case Atflags: 1955f083f689SJohn Baldwin fputs(xlookup_bits(at_flags, args[sc->offset]), fp); 19567d897327SJohn Baldwin break; 19577d897327SJohn Baldwin case Accessmode: 19589289f547SJohn Baldwin print_mask_arg(sysdecode_access_mode, fp, args[sc->offset]); 19597d897327SJohn Baldwin break; 1960b289a8d7SJohn Baldwin case Sysarch: 1961f083f689SJohn Baldwin fputs(xlookup(sysarch_ops, args[sc->offset]), fp); 1962b289a8d7SJohn Baldwin break; 19632b75c8adSJohn Baldwin case PipeFds: 19642b75c8adSJohn Baldwin /* 19652b75c8adSJohn Baldwin * The pipe() system call in the kernel returns its 19662b75c8adSJohn Baldwin * two file descriptors via return values. However, 19672b75c8adSJohn Baldwin * the interface exposed by libc is that pipe() 19682b75c8adSJohn Baldwin * accepts a pointer to an array of descriptors. 19692b75c8adSJohn Baldwin * Format the output to match the libc API by printing 19702b75c8adSJohn Baldwin * the returned file descriptors as a fake argument. 19712b75c8adSJohn Baldwin * 19722b75c8adSJohn Baldwin * Overwrite the first retval to signal a successful 19732b75c8adSJohn Baldwin * return as well. 19742b75c8adSJohn Baldwin */ 19752b75c8adSJohn Baldwin fprintf(fp, "{ %ld, %ld }", retval[0], retval[1]); 19762b75c8adSJohn Baldwin retval[0] = 0; 19772b75c8adSJohn Baldwin break; 1978195aef99SBryan Drewery case Utrace: { 1979195aef99SBryan Drewery size_t len; 1980195aef99SBryan Drewery void *utrace_addr; 1981195aef99SBryan Drewery 1982195aef99SBryan Drewery len = args[sc->offset + 1]; 1983195aef99SBryan Drewery utrace_addr = calloc(1, len); 1984195aef99SBryan Drewery if (get_struct(pid, (void *)args[sc->offset], 1985195aef99SBryan Drewery (void *)utrace_addr, len) != -1) 1986195aef99SBryan Drewery print_utrace(fp, utrace_addr, len); 1987195aef99SBryan Drewery else 1988195aef99SBryan Drewery fprintf(fp, "0x%lx", args[sc->offset]); 1989195aef99SBryan Drewery free(utrace_addr); 1990195aef99SBryan Drewery break; 1991195aef99SBryan Drewery } 1992808d9805SEd Schouten case IntArray: { 1993808d9805SEd Schouten int descriptors[16]; 1994808d9805SEd Schouten unsigned long i, ndescriptors; 1995808d9805SEd Schouten bool truncated; 1996808d9805SEd Schouten 1997808d9805SEd Schouten ndescriptors = args[sc->offset + 1]; 1998808d9805SEd Schouten truncated = false; 1999808d9805SEd Schouten if (ndescriptors > nitems(descriptors)) { 2000808d9805SEd Schouten ndescriptors = nitems(descriptors); 2001808d9805SEd Schouten truncated = true; 2002808d9805SEd Schouten } 2003808d9805SEd Schouten if (get_struct(pid, (void *)args[sc->offset], 2004808d9805SEd Schouten descriptors, ndescriptors * sizeof(descriptors[0])) != -1) { 2005808d9805SEd Schouten fprintf(fp, "{"); 2006808d9805SEd Schouten for (i = 0; i < ndescriptors; i++) 2007808d9805SEd Schouten fprintf(fp, i == 0 ? " %d" : ", %d", 2008808d9805SEd Schouten descriptors[i]); 2009808d9805SEd Schouten fprintf(fp, truncated ? ", ... }" : " }"); 2010808d9805SEd Schouten } else 2011808d9805SEd Schouten fprintf(fp, "0x%lx", args[sc->offset]); 2012808d9805SEd Schouten break; 2013808d9805SEd Schouten } 20149289f547SJohn Baldwin case Pipe2: 20159289f547SJohn Baldwin print_mask_arg(sysdecode_pipe2_flags, fp, args[sc->offset]); 20169289f547SJohn Baldwin break; 2017bed418c8SJohn Baldwin case CapFcntlRights: { 2018bed418c8SJohn Baldwin uint32_t rights; 2019bed418c8SJohn Baldwin 2020bed418c8SJohn Baldwin if (sc->type & OUT) { 2021bed418c8SJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], &rights, 2022bed418c8SJohn Baldwin sizeof(rights)) == -1) { 2023bed418c8SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 2024bed418c8SJohn Baldwin break; 2025bed418c8SJohn Baldwin } 2026bed418c8SJohn Baldwin } else 2027bed418c8SJohn Baldwin rights = args[sc->offset]; 2028bed418c8SJohn Baldwin print_mask_arg32(sysdecode_cap_fcntlrights, fp, rights); 2029bed418c8SJohn Baldwin break; 2030bed418c8SJohn Baldwin } 2031d2a97485SJohn Baldwin case Fadvice: 2032d2a97485SJohn Baldwin print_integer_arg(sysdecode_fadvice, fp, args[sc->offset]); 2033d2a97485SJohn Baldwin break; 203427459358SJohn Baldwin case FileFlags: { 203527459358SJohn Baldwin fflags_t rem; 203627459358SJohn Baldwin 203727459358SJohn Baldwin if (!sysdecode_fileflags(fp, args[sc->offset], &rem)) 203827459358SJohn Baldwin fprintf(fp, "0x%x", rem); 203927459358SJohn Baldwin else if (rem != 0) 204027459358SJohn Baldwin fprintf(fp, "|0x%x", rem); 204127459358SJohn Baldwin break; 204227459358SJohn Baldwin } 2043dd92181fSJohn Baldwin case Flockop: 2044dd92181fSJohn Baldwin print_mask_arg(sysdecode_flock_operation, fp, args[sc->offset]); 2045dd92181fSJohn Baldwin break; 2046ab43bedcSJohn Baldwin case Getfsstatmode: 2047ab43bedcSJohn Baldwin print_integer_arg(sysdecode_getfsstat_mode, fp, 2048ab43bedcSJohn Baldwin args[sc->offset]); 2049ab43bedcSJohn Baldwin break; 205094e854c5SJohn Baldwin case Kldsymcmd: 205194e854c5SJohn Baldwin print_integer_arg(sysdecode_kldsym_cmd, fp, args[sc->offset]); 205294e854c5SJohn Baldwin break; 205394e854c5SJohn Baldwin case Kldunloadflags: 205494e854c5SJohn Baldwin print_integer_arg(sysdecode_kldunload_flags, fp, 205594e854c5SJohn Baldwin args[sc->offset]); 205694e854c5SJohn Baldwin break; 205798fdbeecSJohn Baldwin case Madvice: 205898fdbeecSJohn Baldwin print_integer_arg(sysdecode_madvice, fp, args[sc->offset]); 205998fdbeecSJohn Baldwin break; 206058227c60SMichael Tuexen case Socklent: 206158227c60SMichael Tuexen fprintf(fp, "%u", (socklen_t)args[sc->offset]); 206258227c60SMichael Tuexen break; 2063ecac235bSMichael Tuexen case Sockprotocol: { 2064738a93a4SMichael Tuexen const char *temp; 2065738a93a4SMichael Tuexen int domain, protocol; 2066ecac235bSMichael Tuexen 2067738a93a4SMichael Tuexen domain = args[sc->offset - 2]; 2068ecac235bSMichael Tuexen protocol = args[sc->offset]; 2069ecac235bSMichael Tuexen if (protocol == 0) { 2070ecac235bSMichael Tuexen fputs("0", fp); 2071ecac235bSMichael Tuexen } else { 2072738a93a4SMichael Tuexen temp = sysdecode_socket_protocol(domain, protocol); 2073738a93a4SMichael Tuexen if (temp) { 2074738a93a4SMichael Tuexen fputs(temp, fp); 2075738a93a4SMichael Tuexen } else { 2076738a93a4SMichael Tuexen fprintf(fp, "%d", protocol); 2077738a93a4SMichael Tuexen } 2078ecac235bSMichael Tuexen } 2079ecac235bSMichael Tuexen break; 2080ecac235bSMichael Tuexen } 2081832af457SMichael Tuexen case Sockoptlevel: 2082832af457SMichael Tuexen print_integer_arg(sysdecode_sockopt_level, fp, 2083832af457SMichael Tuexen args[sc->offset]); 2084832af457SMichael Tuexen break; 2085832af457SMichael Tuexen case Sockoptname: { 2086832af457SMichael Tuexen const char *temp; 2087832af457SMichael Tuexen int level, name; 2088832af457SMichael Tuexen 2089832af457SMichael Tuexen level = args[sc->offset - 1]; 2090832af457SMichael Tuexen name = args[sc->offset]; 2091832af457SMichael Tuexen temp = sysdecode_sockopt_name(level, name); 2092832af457SMichael Tuexen if (temp) { 2093832af457SMichael Tuexen fputs(temp, fp); 2094832af457SMichael Tuexen } else { 2095832af457SMichael Tuexen fprintf(fp, "%d", name); 2096832af457SMichael Tuexen } 2097832af457SMichael Tuexen break; 2098832af457SMichael Tuexen } 20998b429b65SMichael Tuexen case Msgflags: 21008b429b65SMichael Tuexen print_mask_arg(sysdecode_msg_flags, fp, args[sc->offset]); 21018b429b65SMichael Tuexen break; 21027136a1d9SJohn Baldwin case CapRights: { 21037136a1d9SJohn Baldwin cap_rights_t rights; 21047136a1d9SJohn Baldwin 21057136a1d9SJohn Baldwin if (get_struct(pid, (void *)args[sc->offset], &rights, 21067136a1d9SJohn Baldwin sizeof(rights)) != -1) { 21077136a1d9SJohn Baldwin fputs("{ ", fp); 21087136a1d9SJohn Baldwin sysdecode_cap_rights(fp, &rights); 21097136a1d9SJohn Baldwin fputs(" }", fp); 21107136a1d9SJohn Baldwin } else 21117136a1d9SJohn Baldwin fprintf(fp, "0x%lx", args[sc->offset]); 21127136a1d9SJohn Baldwin break; 21137136a1d9SJohn Baldwin } 21147ce44f08SJohn Baldwin case Acltype: 21157ce44f08SJohn Baldwin print_integer_arg(sysdecode_acltype, fp, args[sc->offset]); 21167ce44f08SJohn Baldwin break; 211726606dcaSJohn Baldwin case Extattrnamespace: 211826606dcaSJohn Baldwin print_integer_arg(sysdecode_extattrnamespace, fp, 211926606dcaSJohn Baldwin args[sc->offset]); 212026606dcaSJohn Baldwin break; 21212d9c9988SJohn Baldwin case Minherit: 21222d9c9988SJohn Baldwin print_integer_arg(sysdecode_minherit_inherit, fp, 21232d9c9988SJohn Baldwin args[sc->offset]); 21242d9c9988SJohn Baldwin break; 212594bde755SJohn Baldwin case Mlockall: 212694bde755SJohn Baldwin print_mask_arg(sysdecode_mlockall_flags, fp, args[sc->offset]); 212794bde755SJohn Baldwin break; 21288acc8e78SJohn Baldwin case Mountflags: 21298acc8e78SJohn Baldwin print_mask_arg(sysdecode_mount_flags, fp, args[sc->offset]); 21308acc8e78SJohn Baldwin break; 2131114aeee0SJohn Baldwin case Msync: 2132114aeee0SJohn Baldwin print_mask_arg(sysdecode_msync_flags, fp, args[sc->offset]); 2133114aeee0SJohn Baldwin break; 2134ad419d33SJohn Baldwin case Priowhich: 2135ad419d33SJohn Baldwin print_integer_arg(sysdecode_prio_which, fp, args[sc->offset]); 2136ad419d33SJohn Baldwin break; 21375ac1c7acSJohn Baldwin case Ptraceop: 21385ac1c7acSJohn Baldwin print_integer_arg(sysdecode_ptrace_request, fp, 21395ac1c7acSJohn Baldwin args[sc->offset]); 21405ac1c7acSJohn Baldwin break; 2141*dd0c462cSJohn Baldwin case Quotactlcmd: 2142*dd0c462cSJohn Baldwin if (!sysdecode_quotactl_cmd(fp, args[sc->offset])) 2143*dd0c462cSJohn Baldwin fprintf(fp, "%#x", (int)args[sc->offset]); 2144*dd0c462cSJohn Baldwin break; 2145808d9805SEd Schouten 2146808d9805SEd Schouten case CloudABIAdvice: 2147808d9805SEd Schouten fputs(xlookup(cloudabi_advice, args[sc->offset]), fp); 2148808d9805SEd Schouten break; 2149808d9805SEd Schouten case CloudABIClockID: 2150808d9805SEd Schouten fputs(xlookup(cloudabi_clockid, args[sc->offset]), fp); 2151808d9805SEd Schouten break; 2152808d9805SEd Schouten case ClouduABIFDSFlags: 2153808d9805SEd Schouten fputs(xlookup_bits(cloudabi_fdsflags, args[sc->offset]), fp); 2154808d9805SEd Schouten break; 2155808d9805SEd Schouten case CloudABIFDStat: { 2156808d9805SEd Schouten cloudabi_fdstat_t fds; 2157808d9805SEd Schouten if (get_struct(pid, (void *)args[sc->offset], &fds, sizeof(fds)) 2158808d9805SEd Schouten != -1) { 2159808d9805SEd Schouten fprintf(fp, "{ %s, ", 2160808d9805SEd Schouten xlookup(cloudabi_filetype, fds.fs_filetype)); 2161808d9805SEd Schouten fprintf(fp, "%s, ... }", 2162808d9805SEd Schouten xlookup_bits(cloudabi_fdflags, fds.fs_flags)); 2163808d9805SEd Schouten } else 2164808d9805SEd Schouten fprintf(fp, "0x%lx", args[sc->offset]); 2165808d9805SEd Schouten break; 2166808d9805SEd Schouten } 2167808d9805SEd Schouten case CloudABIFileStat: { 2168808d9805SEd Schouten cloudabi_filestat_t fsb; 2169808d9805SEd Schouten if (get_struct(pid, (void *)args[sc->offset], &fsb, sizeof(fsb)) 2170808d9805SEd Schouten != -1) 21719ba32307SJohn Baldwin fprintf(fp, "{ %s, %ju }", 2172808d9805SEd Schouten xlookup(cloudabi_filetype, fsb.st_filetype), 21739ba32307SJohn Baldwin (uintmax_t)fsb.st_size); 2174808d9805SEd Schouten else 2175808d9805SEd Schouten fprintf(fp, "0x%lx", args[sc->offset]); 2176808d9805SEd Schouten break; 2177808d9805SEd Schouten } 2178808d9805SEd Schouten case CloudABIFileType: 2179808d9805SEd Schouten fputs(xlookup(cloudabi_filetype, args[sc->offset]), fp); 2180808d9805SEd Schouten break; 2181808d9805SEd Schouten case CloudABIFSFlags: 2182808d9805SEd Schouten fputs(xlookup_bits(cloudabi_fsflags, args[sc->offset]), fp); 2183808d9805SEd Schouten break; 2184808d9805SEd Schouten case CloudABILookup: 2185808d9805SEd Schouten if ((args[sc->offset] & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0) 2186808d9805SEd Schouten fprintf(fp, "%d|LOOKUP_SYMLINK_FOLLOW", 2187808d9805SEd Schouten (int)args[sc->offset]); 2188808d9805SEd Schouten else 2189808d9805SEd Schouten fprintf(fp, "%d", (int)args[sc->offset]); 2190808d9805SEd Schouten break; 2191808d9805SEd Schouten case CloudABIMFlags: 2192808d9805SEd Schouten fputs(xlookup_bits(cloudabi_mflags, args[sc->offset]), fp); 2193808d9805SEd Schouten break; 2194808d9805SEd Schouten case CloudABIMProt: 2195808d9805SEd Schouten fputs(xlookup_bits(cloudabi_mprot, args[sc->offset]), fp); 2196808d9805SEd Schouten break; 2197808d9805SEd Schouten case CloudABIMSFlags: 2198808d9805SEd Schouten fputs(xlookup_bits(cloudabi_msflags, args[sc->offset]), fp); 2199808d9805SEd Schouten break; 2200808d9805SEd Schouten case CloudABIOFlags: 2201808d9805SEd Schouten fputs(xlookup_bits(cloudabi_oflags, args[sc->offset]), fp); 2202808d9805SEd Schouten break; 2203808d9805SEd Schouten case CloudABISDFlags: 2204808d9805SEd Schouten fputs(xlookup_bits(cloudabi_sdflags, args[sc->offset]), fp); 2205808d9805SEd Schouten break; 2206808d9805SEd Schouten case CloudABISignal: 2207808d9805SEd Schouten fputs(xlookup(cloudabi_signal, args[sc->offset]), fp); 2208808d9805SEd Schouten break; 2209808d9805SEd Schouten case CloudABISockStat: { 2210808d9805SEd Schouten cloudabi_sockstat_t ss; 2211808d9805SEd Schouten if (get_struct(pid, (void *)args[sc->offset], &ss, sizeof(ss)) 2212808d9805SEd Schouten != -1) { 2213808d9805SEd Schouten fprintf(fp, "{ %s, ", xlookup( 2214808d9805SEd Schouten cloudabi_sa_family, ss.ss_sockname.sa_family)); 2215808d9805SEd Schouten fprintf(fp, "%s, ", xlookup( 2216808d9805SEd Schouten cloudabi_sa_family, ss.ss_peername.sa_family)); 2217808d9805SEd Schouten fprintf(fp, "%s, ", xlookup( 2218808d9805SEd Schouten cloudabi_errno, ss.ss_error)); 2219808d9805SEd Schouten fprintf(fp, "%s }", xlookup_bits( 2220808d9805SEd Schouten cloudabi_ssstate, ss.ss_state)); 2221808d9805SEd Schouten } else 2222808d9805SEd Schouten fprintf(fp, "0x%lx", args[sc->offset]); 2223808d9805SEd Schouten break; 2224808d9805SEd Schouten } 2225808d9805SEd Schouten case CloudABISSFlags: 2226808d9805SEd Schouten fputs(xlookup_bits(cloudabi_ssflags, args[sc->offset]), fp); 2227808d9805SEd Schouten break; 2228808d9805SEd Schouten case CloudABITimestamp: 2229808d9805SEd Schouten fprintf(fp, "%lu.%09lus", args[sc->offset] / 1000000000, 2230808d9805SEd Schouten args[sc->offset] % 1000000000); 2231808d9805SEd Schouten break; 2232808d9805SEd Schouten case CloudABIULFlags: 2233808d9805SEd Schouten fputs(xlookup_bits(cloudabi_ulflags, args[sc->offset]), fp); 2234808d9805SEd Schouten break; 2235808d9805SEd Schouten case CloudABIWhence: 2236808d9805SEd Schouten fputs(xlookup(cloudabi_whence, args[sc->offset]), fp); 2237808d9805SEd Schouten break; 2238808d9805SEd Schouten 2239081e5c48SPav Lucistnik default: 2240081e5c48SPav Lucistnik errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK); 2241bbeaf6c0SSean Eric Fagan } 2242f083f689SJohn Baldwin fclose(fp); 2243d8984f48SDag-Erling Smørgrav return (tmp); 2244bbeaf6c0SSean Eric Fagan } 2245bbeaf6c0SSean Eric Fagan 2246bbeaf6c0SSean Eric Fagan /* 224700ddbdf2SJohn Baldwin * Print (to outfile) the system call and its arguments. 2248bbeaf6c0SSean Eric Fagan */ 2249bbeaf6c0SSean Eric Fagan void 225000ddbdf2SJohn Baldwin print_syscall(struct trussinfo *trussinfo) 2251d8984f48SDag-Erling Smørgrav { 225200ddbdf2SJohn Baldwin struct threadinfo *t; 225300ddbdf2SJohn Baldwin const char *name; 225400ddbdf2SJohn Baldwin char **s_args; 225500ddbdf2SJohn Baldwin int i, len, nargs; 22560d0bd00eSMatthew N. Dodd 225700ddbdf2SJohn Baldwin t = trussinfo->curthread; 2258c03bfcc8SMatthew N. Dodd 22591175b23fSJohn Baldwin name = t->cs.sc->name; 226000ddbdf2SJohn Baldwin nargs = t->cs.nargs; 226100ddbdf2SJohn Baldwin s_args = t->cs.s_args; 22620d0bd00eSMatthew N. Dodd 2263d70876fdSJohn Baldwin len = print_line_prefix(trussinfo); 2264ec0bed25SMatthew N. Dodd len += fprintf(trussinfo->outfile, "%s(", name); 2265c03bfcc8SMatthew N. Dodd 2266bbeaf6c0SSean Eric Fagan for (i = 0; i < nargs; i++) { 226700ddbdf2SJohn Baldwin if (s_args[i] != NULL) 2268ec0bed25SMatthew N. Dodd len += fprintf(trussinfo->outfile, "%s", s_args[i]); 2269bbeaf6c0SSean Eric Fagan else 227094355cfdSAndrey Zonov len += fprintf(trussinfo->outfile, 227194355cfdSAndrey Zonov "<missing argument>"); 227294355cfdSAndrey Zonov len += fprintf(trussinfo->outfile, "%s", i < (nargs - 1) ? 227394355cfdSAndrey Zonov "," : ""); 2274bbeaf6c0SSean Eric Fagan } 2275ec0bed25SMatthew N. Dodd len += fprintf(trussinfo->outfile, ")"); 22766cb533feSSean Eric Fagan for (i = 0; i < 6 - (len / 8); i++) 2277ec0bed25SMatthew N. Dodd fprintf(trussinfo->outfile, "\t"); 22786cb533feSSean Eric Fagan } 22796cb533feSSean Eric Fagan 22806cb533feSSean Eric Fagan void 228100ddbdf2SJohn Baldwin print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval) 22821bcb5f5aSMarcel Moolenaar { 2283ee3b0f6eSDiomidis Spinellis struct timespec timediff; 228400ddbdf2SJohn Baldwin struct threadinfo *t; 228500ddbdf2SJohn Baldwin struct syscall *sc; 2286287b96ddSJohn Baldwin int error; 2287ee3b0f6eSDiomidis Spinellis 228800ddbdf2SJohn Baldwin t = trussinfo->curthread; 228900ddbdf2SJohn Baldwin sc = t->cs.sc; 2290ee3b0f6eSDiomidis Spinellis if (trussinfo->flags & COUNTONLY) { 229100ddbdf2SJohn Baldwin timespecsubt(&t->after, &t->before, &timediff); 2292d9dcc463SXin LI timespecadd(&sc->time, &timediff, &sc->time); 2293ee3b0f6eSDiomidis Spinellis sc->ncalls++; 2294ee3b0f6eSDiomidis Spinellis if (errorp) 2295ee3b0f6eSDiomidis Spinellis sc->nerror++; 2296ee3b0f6eSDiomidis Spinellis return; 2297ee3b0f6eSDiomidis Spinellis } 2298d8984f48SDag-Erling Smørgrav 229900ddbdf2SJohn Baldwin print_syscall(trussinfo); 23000cf21b4fSBrian Somers fflush(trussinfo->outfile); 2301b9befd33SJohn Baldwin 2302b9befd33SJohn Baldwin if (retval == NULL) { 2303b9befd33SJohn Baldwin /* 2304b9befd33SJohn Baldwin * This system call resulted in the current thread's exit, 2305b9befd33SJohn Baldwin * so there is no return value or error to display. 2306b9befd33SJohn Baldwin */ 2307b9befd33SJohn Baldwin fprintf(trussinfo->outfile, "\n"); 2308b9befd33SJohn Baldwin return; 2309b9befd33SJohn Baldwin } 2310b9befd33SJohn Baldwin 2311287b96ddSJohn Baldwin if (errorp) { 2312287b96ddSJohn Baldwin error = sysdecode_abi_to_freebsd_errno(t->proc->abi->abi, 2313287b96ddSJohn Baldwin retval[0]); 23142b75c8adSJohn Baldwin fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval[0], 2315287b96ddSJohn Baldwin error == INT_MAX ? "Unknown error" : strerror(error)); 2316287b96ddSJohn Baldwin } 23172b75c8adSJohn Baldwin #ifndef __LP64__ 23186c61b0f3SBryan Drewery else if (sc->ret_type == 2) { 23192b75c8adSJohn Baldwin off_t off; 23202b75c8adSJohn Baldwin 23212b75c8adSJohn Baldwin #if _BYTE_ORDER == _LITTLE_ENDIAN 23222b75c8adSJohn Baldwin off = (off_t)retval[1] << 32 | retval[0]; 23232b75c8adSJohn Baldwin #else 23242b75c8adSJohn Baldwin off = (off_t)retval[0] << 32 | retval[1]; 23252b75c8adSJohn Baldwin #endif 23262b75c8adSJohn Baldwin fprintf(trussinfo->outfile, " = %jd (0x%jx)\n", (intmax_t)off, 23272b75c8adSJohn Baldwin (intmax_t)off); 23286cb533feSSean Eric Fagan } 23292b75c8adSJohn Baldwin #endif 23302b75c8adSJohn Baldwin else 23312b75c8adSJohn Baldwin fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval[0], 23322b75c8adSJohn Baldwin retval[0]); 2333bbeaf6c0SSean Eric Fagan } 2334ee3b0f6eSDiomidis Spinellis 2335ee3b0f6eSDiomidis Spinellis void 2336ee3b0f6eSDiomidis Spinellis print_summary(struct trussinfo *trussinfo) 2337ee3b0f6eSDiomidis Spinellis { 2338ee3b0f6eSDiomidis Spinellis struct timespec total = {0, 0}; 233994355cfdSAndrey Zonov struct syscall *sc; 2340ee3b0f6eSDiomidis Spinellis int ncall, nerror; 2341ee3b0f6eSDiomidis Spinellis 2342ee3b0f6eSDiomidis Spinellis fprintf(trussinfo->outfile, "%-20s%15s%8s%8s\n", 2343ee3b0f6eSDiomidis Spinellis "syscall", "seconds", "calls", "errors"); 2344ee3b0f6eSDiomidis Spinellis ncall = nerror = 0; 23456c61b0f3SBryan Drewery STAILQ_FOREACH(sc, &syscalls, entries) 2346ee3b0f6eSDiomidis Spinellis if (sc->ncalls) { 234755a8d2bbSJaakko Heinonen fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n", 234855a8d2bbSJaakko Heinonen sc->name, (intmax_t)sc->time.tv_sec, 234955a8d2bbSJaakko Heinonen sc->time.tv_nsec, sc->ncalls, sc->nerror); 2350d9dcc463SXin LI timespecadd(&total, &sc->time, &total); 2351ee3b0f6eSDiomidis Spinellis ncall += sc->ncalls; 2352ee3b0f6eSDiomidis Spinellis nerror += sc->nerror; 2353ee3b0f6eSDiomidis Spinellis } 2354ee3b0f6eSDiomidis Spinellis fprintf(trussinfo->outfile, "%20s%15s%8s%8s\n", 2355ee3b0f6eSDiomidis Spinellis "", "-------------", "-------", "-------"); 235655a8d2bbSJaakko Heinonen fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n", 235755a8d2bbSJaakko Heinonen "", (intmax_t)total.tv_sec, total.tv_nsec, ncall, nerror); 2358ee3b0f6eSDiomidis Spinellis } 2359