Index: head/lib/libsysdecode/errno.c =================================================================== --- head/lib/libsysdecode/errno.c (revision 297246) +++ head/lib/libsysdecode/errno.c (revision 297247) @@ -1,209 +1,209 @@ /*- * Copyright (c) 2015 John H. Baldwin * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #if defined(__i386__) || defined(__amd64__) /* * Linux syscalls return negative errno's, we do positive and map them * Reference: * FreeBSD: src/sys/sys/errno.h * Linux: linux-2.6.17.8/include/asm-generic/errno-base.h * linux-2.6.17.8/include/asm-generic/errno.h */ static int bsd_to_linux_errno[ELAST + 1] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -35, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -11,-115,-114, -88, -89, -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, -6, -6, -43, -42, -75,-125, -84, -95, -16, -74, -72, -67, -71 }; #endif #if defined(__aarch64__) || defined(__amd64__) -#include +#include static const int cloudabi_errno_table[] = { [CLOUDABI_E2BIG] = E2BIG, [CLOUDABI_EACCES] = EACCES, [CLOUDABI_EADDRINUSE] = EADDRINUSE, [CLOUDABI_EADDRNOTAVAIL] = EADDRNOTAVAIL, [CLOUDABI_EAFNOSUPPORT] = EAFNOSUPPORT, [CLOUDABI_EAGAIN] = EAGAIN, [CLOUDABI_EALREADY] = EALREADY, [CLOUDABI_EBADF] = EBADF, [CLOUDABI_EBADMSG] = EBADMSG, [CLOUDABI_EBUSY] = EBUSY, [CLOUDABI_ECANCELED] = ECANCELED, [CLOUDABI_ECHILD] = ECHILD, [CLOUDABI_ECONNABORTED] = ECONNABORTED, [CLOUDABI_ECONNREFUSED] = ECONNREFUSED, [CLOUDABI_ECONNRESET] = ECONNRESET, [CLOUDABI_EDEADLK] = EDEADLK, [CLOUDABI_EDESTADDRREQ] = EDESTADDRREQ, [CLOUDABI_EDOM] = EDOM, [CLOUDABI_EDQUOT] = EDQUOT, [CLOUDABI_EEXIST] = EEXIST, [CLOUDABI_EFAULT] = EFAULT, [CLOUDABI_EFBIG] = EFBIG, [CLOUDABI_EHOSTUNREACH] = EHOSTUNREACH, [CLOUDABI_EIDRM] = EIDRM, [CLOUDABI_EILSEQ] = EILSEQ, [CLOUDABI_EINPROGRESS] = EINPROGRESS, [CLOUDABI_EINTR] = EINTR, [CLOUDABI_EINVAL] = EINVAL, [CLOUDABI_EIO] = EIO, [CLOUDABI_EISCONN] = EISCONN, [CLOUDABI_EISDIR] = EISDIR, [CLOUDABI_ELOOP] = ELOOP, [CLOUDABI_EMFILE] = EMFILE, [CLOUDABI_EMLINK] = EMLINK, [CLOUDABI_EMSGSIZE] = EMSGSIZE, [CLOUDABI_EMULTIHOP] = EMULTIHOP, [CLOUDABI_ENAMETOOLONG] = ENAMETOOLONG, [CLOUDABI_ENETDOWN] = ENETDOWN, [CLOUDABI_ENETRESET] = ENETRESET, [CLOUDABI_ENETUNREACH] = ENETUNREACH, [CLOUDABI_ENFILE] = ENFILE, [CLOUDABI_ENOBUFS] = ENOBUFS, [CLOUDABI_ENODEV] = ENODEV, [CLOUDABI_ENOENT] = ENOENT, [CLOUDABI_ENOEXEC] = ENOEXEC, [CLOUDABI_ENOLCK] = ENOLCK, [CLOUDABI_ENOLINK] = ENOLINK, [CLOUDABI_ENOMEM] = ENOMEM, [CLOUDABI_ENOMSG] = ENOMSG, [CLOUDABI_ENOPROTOOPT] = ENOPROTOOPT, [CLOUDABI_ENOSPC] = ENOSPC, [CLOUDABI_ENOSYS] = ENOSYS, [CLOUDABI_ENOTCONN] = ENOTCONN, [CLOUDABI_ENOTDIR] = ENOTDIR, [CLOUDABI_ENOTEMPTY] = ENOTEMPTY, [CLOUDABI_ENOTRECOVERABLE] = ENOTRECOVERABLE, [CLOUDABI_ENOTSOCK] = ENOTSOCK, [CLOUDABI_ENOTSUP] = ENOTSUP, [CLOUDABI_ENOTTY] = ENOTTY, [CLOUDABI_ENXIO] = ENXIO, [CLOUDABI_EOVERFLOW] = EOVERFLOW, [CLOUDABI_EOWNERDEAD] = EOWNERDEAD, [CLOUDABI_EPERM] = EPERM, [CLOUDABI_EPIPE] = EPIPE, [CLOUDABI_EPROTO] = EPROTO, [CLOUDABI_EPROTONOSUPPORT] = EPROTONOSUPPORT, [CLOUDABI_EPROTOTYPE] = EPROTOTYPE, [CLOUDABI_ERANGE] = ERANGE, [CLOUDABI_EROFS] = EROFS, [CLOUDABI_ESPIPE] = ESPIPE, [CLOUDABI_ESRCH] = ESRCH, [CLOUDABI_ESTALE] = ESTALE, [CLOUDABI_ETIMEDOUT] = ETIMEDOUT, [CLOUDABI_ETXTBSY] = ETXTBSY, [CLOUDABI_EXDEV] = EXDEV, [CLOUDABI_ENOTCAPABLE] = ENOTCAPABLE, }; #endif int sysdecode_abi_to_freebsd_errno(enum sysdecode_abi abi, int error) { switch (abi) { case SYSDECODE_ABI_FREEBSD: case SYSDECODE_ABI_FREEBSD32: return (error); #if defined(__i386__) || defined(__amd64__) case SYSDECODE_ABI_LINUX: case SYSDECODE_ABI_LINUX32: { unsigned int i; /* * This is imprecise since it returns the first * matching errno. */ for (i = 0; i < nitems(bsd_to_linux_errno); i++) { if (error == bsd_to_linux_errno[i]) return (i); } break; } #endif #if defined(__aarch64__) || defined(__amd64__) case SYSDECODE_ABI_CLOUDABI64: if (error >= 0 && (unsigned int)error < nitems(cloudabi_errno_table)) return (cloudabi_errno_table[error]); break; #endif default: break; } return (INT_MAX); } int sysdecode_freebsd_to_abi_errno(enum sysdecode_abi abi, int error) { switch (abi) { case SYSDECODE_ABI_FREEBSD: case SYSDECODE_ABI_FREEBSD32: return (error); #if defined(__i386__) || defined(__amd64__) case SYSDECODE_ABI_LINUX: case SYSDECODE_ABI_LINUX32: if (error >= 0 && error <= ELAST) return (bsd_to_linux_errno[error]); break; #endif #if defined(__aarch64__) || defined(__amd64__) case SYSDECODE_ABI_CLOUDABI64: { unsigned int i; for (i = 0; i < nitems(cloudabi_errno_table); i++) { if (error == cloudabi_errno_table[i]) return (i); } break; } #endif default: break; } return (INT_MAX); } Index: head/sys/compat/cloudabi/cloudabi_syscalldefs.h =================================================================== --- head/sys/compat/cloudabi/cloudabi_syscalldefs.h (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_syscalldefs.h (nonexistent) @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 2015 Nuxi, https://nuxi.nl/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _CLOUDABI_SYSCALLDEFS_H_ -#define _CLOUDABI_SYSCALLDEFS_H_ - -#ifdef _KERNEL -#include -#include - -#define alignas _Alignas -#define alignof _Alignof -#define static_assert _Static_assert -#else -#include -#include -#include -#include -#endif - -/* Import machine-independent CloudABI definitions. */ -#include - -#endif Property changes on: head/sys/compat/cloudabi/cloudabi_syscalldefs.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/sys/compat/cloudabi/cloudabi_clock.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_clock.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_clock.c (revision 297247) @@ -1,133 +1,134 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include +#include + #include -#include #include /* Converts a CloudABI clock ID to a FreeBSD clock ID. */ static int cloudabi_convert_clockid(cloudabi_clockid_t in, clockid_t *out) { switch (in) { case CLOUDABI_CLOCK_MONOTONIC: *out = CLOCK_MONOTONIC; return (0); case CLOUDABI_CLOCK_PROCESS_CPUTIME_ID: *out = CLOCK_PROCESS_CPUTIME_ID; return (0); case CLOUDABI_CLOCK_REALTIME: *out = CLOCK_REALTIME; return (0); case CLOUDABI_CLOCK_THREAD_CPUTIME_ID: *out = CLOCK_THREAD_CPUTIME_ID; return (0); default: return (EINVAL); } } /* Converts a struct timespec to a CloudABI timestamp. */ int cloudabi_convert_timespec(const struct timespec *in, cloudabi_timestamp_t *out) { cloudabi_timestamp_t s, ns; if (in->tv_sec < 0) { /* Timestamps from before the Epoch cannot be expressed. */ *out = 0; return (EOVERFLOW); } s = in->tv_sec; ns = in->tv_nsec; if (s > UINT64_MAX / 1000000000 || (s == UINT64_MAX / 1000000000 && ns > UINT64_MAX % 1000000000)) { /* Addition of seconds and nanoseconds would overflow. */ *out = UINT64_MAX; return (EOVERFLOW); } *out = s * 1000000000 + ns; return (0); } /* Fetches the time value of a clock. */ int cloudabi_clock_time_get(struct thread *td, cloudabi_clockid_t clock_id, cloudabi_timestamp_t *ret) { struct timespec ts; int error; clockid_t clockid; error = cloudabi_convert_clockid(clock_id, &clockid); if (error != 0) return (error); error = kern_clock_gettime(td, clockid, &ts); if (error != 0) return (error); return (cloudabi_convert_timespec(&ts, ret)); } int cloudabi_sys_clock_res_get(struct thread *td, struct cloudabi_sys_clock_res_get_args *uap) { struct timespec ts; cloudabi_timestamp_t cts; int error; clockid_t clockid; error = cloudabi_convert_clockid(uap->clock_id, &clockid); if (error != 0) return (error); error = kern_clock_getres(td, clockid, &ts); if (error != 0) return (error); error = cloudabi_convert_timespec(&ts, &cts); if (error != 0) return (error); td->td_retval[0] = cts; return (0); } int cloudabi_sys_clock_time_get(struct thread *td, struct cloudabi_sys_clock_time_get_args *uap) { cloudabi_timestamp_t ts; int error; error = cloudabi_clock_time_get(td, uap->clock_id, &ts); td->td_retval[0] = ts; return (error); } Index: head/sys/compat/cloudabi/cloudabi_errno.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_errno.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_errno.c (revision 297247) @@ -1,121 +1,122 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include -#include +#include + #include /* Converts a FreeBSD errno to a CloudABI errno. */ cloudabi_errno_t cloudabi_convert_errno(int error) { static const int table[] = { [E2BIG] = CLOUDABI_E2BIG, [EACCES] = CLOUDABI_EACCES, [EADDRINUSE] = CLOUDABI_EADDRINUSE, [EADDRNOTAVAIL] = CLOUDABI_EADDRNOTAVAIL, [EAFNOSUPPORT] = CLOUDABI_EAFNOSUPPORT, [EAGAIN] = CLOUDABI_EAGAIN, [EALREADY] = CLOUDABI_EALREADY, [EBADF] = CLOUDABI_EBADF, [EBADMSG] = CLOUDABI_EBADMSG, [EBUSY] = CLOUDABI_EBUSY, [ECANCELED] = CLOUDABI_ECANCELED, [ECHILD] = CLOUDABI_ECHILD, [ECONNABORTED] = CLOUDABI_ECONNABORTED, [ECONNREFUSED] = CLOUDABI_ECONNREFUSED, [ECONNRESET] = CLOUDABI_ECONNRESET, [EDEADLK] = CLOUDABI_EDEADLK, [EDESTADDRREQ] = CLOUDABI_EDESTADDRREQ, [EDOM] = CLOUDABI_EDOM, [EDQUOT] = CLOUDABI_EDQUOT, [EEXIST] = CLOUDABI_EEXIST, [EFAULT] = CLOUDABI_EFAULT, [EFBIG] = CLOUDABI_EFBIG, [EHOSTUNREACH] = CLOUDABI_EHOSTUNREACH, [EIDRM] = CLOUDABI_EIDRM, [EILSEQ] = CLOUDABI_EILSEQ, [EINPROGRESS] = CLOUDABI_EINPROGRESS, [EINTR] = CLOUDABI_EINTR, [EINVAL] = CLOUDABI_EINVAL, [EIO] = CLOUDABI_EIO, [EISCONN] = CLOUDABI_EISCONN, [EISDIR] = CLOUDABI_EISDIR, [ELOOP] = CLOUDABI_ELOOP, [EMFILE] = CLOUDABI_EMFILE, [EMLINK] = CLOUDABI_EMLINK, [EMSGSIZE] = CLOUDABI_EMSGSIZE, [EMULTIHOP] = CLOUDABI_EMULTIHOP, [ENAMETOOLONG] = CLOUDABI_ENAMETOOLONG, [ENETDOWN] = CLOUDABI_ENETDOWN, [ENETRESET] = CLOUDABI_ENETRESET, [ENETUNREACH] = CLOUDABI_ENETUNREACH, [ENFILE] = CLOUDABI_ENFILE, [ENOBUFS] = CLOUDABI_ENOBUFS, [ENODEV] = CLOUDABI_ENODEV, [ENOENT] = CLOUDABI_ENOENT, [ENOEXEC] = CLOUDABI_ENOEXEC, [ENOLCK] = CLOUDABI_ENOLCK, [ENOLINK] = CLOUDABI_ENOLINK, [ENOMEM] = CLOUDABI_ENOMEM, [ENOMSG] = CLOUDABI_ENOMSG, [ENOPROTOOPT] = CLOUDABI_ENOPROTOOPT, [ENOSPC] = CLOUDABI_ENOSPC, [ENOSYS] = CLOUDABI_ENOSYS, [ENOTCONN] = CLOUDABI_ENOTCONN, [ENOTDIR] = CLOUDABI_ENOTDIR, [ENOTEMPTY] = CLOUDABI_ENOTEMPTY, [ENOTRECOVERABLE] = CLOUDABI_ENOTRECOVERABLE, [ENOTSOCK] = CLOUDABI_ENOTSOCK, [ENOTSUP] = CLOUDABI_ENOTSUP, [ENOTTY] = CLOUDABI_ENOTTY, [ENXIO] = CLOUDABI_ENXIO, [EOVERFLOW] = CLOUDABI_EOVERFLOW, [EOWNERDEAD] = CLOUDABI_EOWNERDEAD, [EPERM] = CLOUDABI_EPERM, [EPIPE] = CLOUDABI_EPIPE, [EPROTO] = CLOUDABI_EPROTO, [EPROTONOSUPPORT] = CLOUDABI_EPROTONOSUPPORT, [EPROTOTYPE] = CLOUDABI_EPROTOTYPE, [ERANGE] = CLOUDABI_ERANGE, [EROFS] = CLOUDABI_EROFS, [ESPIPE] = CLOUDABI_ESPIPE, [ESRCH] = CLOUDABI_ESRCH, [ESTALE] = CLOUDABI_ESTALE, [ETIMEDOUT] = CLOUDABI_ETIMEDOUT, [ETXTBSY] = CLOUDABI_ETXTBSY, [EXDEV] = CLOUDABI_EXDEV, [ENOTCAPABLE] = CLOUDABI_ENOTCAPABLE, }; /* Unknown error: fall back to returning ENOSYS. */ if (error < 0 || error >= nitems(table) || table[error] == 0) return (error == 0 ? 0 : CLOUDABI_ENOSYS); return (table[error]); } Index: head/sys/compat/cloudabi/cloudabi_fd.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_fd.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_fd.c (revision 297247) @@ -1,564 +1,565 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include +#include + #include -#include #include /* Translation between CloudABI and Capsicum rights. */ #define RIGHTS_MAPPINGS \ MAPPING(CLOUDABI_RIGHT_FD_DATASYNC, CAP_FSYNC) \ MAPPING(CLOUDABI_RIGHT_FD_READ, CAP_READ) \ MAPPING(CLOUDABI_RIGHT_FD_SEEK, CAP_SEEK) \ MAPPING(CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS, CAP_FCNTL) \ MAPPING(CLOUDABI_RIGHT_FD_SYNC, CAP_FSYNC) \ MAPPING(CLOUDABI_RIGHT_FD_TELL, CAP_SEEK_TELL) \ MAPPING(CLOUDABI_RIGHT_FD_WRITE, CAP_WRITE) \ MAPPING(CLOUDABI_RIGHT_FILE_ADVISE) \ MAPPING(CLOUDABI_RIGHT_FILE_ALLOCATE, CAP_WRITE) \ MAPPING(CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY, CAP_MKDIRAT) \ MAPPING(CLOUDABI_RIGHT_FILE_CREATE_FILE, CAP_CREATE) \ MAPPING(CLOUDABI_RIGHT_FILE_CREATE_FIFO, CAP_MKFIFOAT) \ MAPPING(CLOUDABI_RIGHT_FILE_LINK_SOURCE, CAP_LINKAT_SOURCE) \ MAPPING(CLOUDABI_RIGHT_FILE_LINK_TARGET, CAP_LINKAT_TARGET) \ MAPPING(CLOUDABI_RIGHT_FILE_OPEN, CAP_LOOKUP) \ MAPPING(CLOUDABI_RIGHT_FILE_READDIR, CAP_READ) \ MAPPING(CLOUDABI_RIGHT_FILE_READLINK, CAP_LOOKUP) \ MAPPING(CLOUDABI_RIGHT_FILE_RENAME_SOURCE, CAP_RENAMEAT_SOURCE) \ MAPPING(CLOUDABI_RIGHT_FILE_RENAME_TARGET, CAP_RENAMEAT_TARGET) \ MAPPING(CLOUDABI_RIGHT_FILE_STAT_FGET, CAP_FSTAT) \ MAPPING(CLOUDABI_RIGHT_FILE_STAT_FPUT_SIZE, CAP_FTRUNCATE) \ MAPPING(CLOUDABI_RIGHT_FILE_STAT_FPUT_TIMES, CAP_FUTIMES) \ MAPPING(CLOUDABI_RIGHT_FILE_STAT_GET, CAP_FSTATAT) \ MAPPING(CLOUDABI_RIGHT_FILE_STAT_PUT_TIMES, CAP_FUTIMESAT) \ MAPPING(CLOUDABI_RIGHT_FILE_SYMLINK, CAP_SYMLINKAT) \ MAPPING(CLOUDABI_RIGHT_FILE_UNLINK, CAP_UNLINKAT) \ MAPPING(CLOUDABI_RIGHT_MEM_MAP, CAP_MMAP) \ MAPPING(CLOUDABI_RIGHT_MEM_MAP_EXEC, CAP_MMAP_X) \ MAPPING(CLOUDABI_RIGHT_POLL_FD_READWRITE, CAP_EVENT) \ MAPPING(CLOUDABI_RIGHT_POLL_MODIFY, CAP_KQUEUE_CHANGE) \ MAPPING(CLOUDABI_RIGHT_POLL_PROC_TERMINATE, CAP_EVENT) \ MAPPING(CLOUDABI_RIGHT_POLL_WAIT, CAP_KQUEUE_EVENT) \ MAPPING(CLOUDABI_RIGHT_PROC_EXEC, CAP_FEXECVE) \ MAPPING(CLOUDABI_RIGHT_SOCK_ACCEPT, CAP_ACCEPT) \ MAPPING(CLOUDABI_RIGHT_SOCK_BIND_DIRECTORY, CAP_BINDAT) \ MAPPING(CLOUDABI_RIGHT_SOCK_BIND_SOCKET, CAP_BIND) \ MAPPING(CLOUDABI_RIGHT_SOCK_CONNECT_DIRECTORY, CAP_CONNECTAT) \ MAPPING(CLOUDABI_RIGHT_SOCK_CONNECT_SOCKET, CAP_CONNECT) \ MAPPING(CLOUDABI_RIGHT_SOCK_LISTEN, CAP_LISTEN) \ MAPPING(CLOUDABI_RIGHT_SOCK_SHUTDOWN, CAP_SHUTDOWN) \ MAPPING(CLOUDABI_RIGHT_SOCK_STAT_GET, CAP_GETPEERNAME, \ CAP_GETSOCKNAME, CAP_GETSOCKOPT) int cloudabi_sys_fd_close(struct thread *td, struct cloudabi_sys_fd_close_args *uap) { return (kern_close(td, uap->fd)); } int cloudabi_sys_fd_create1(struct thread *td, struct cloudabi_sys_fd_create1_args *uap) { struct filecaps fcaps = {}; struct socket_args socket_args = { .domain = AF_UNIX, }; switch (uap->type) { case CLOUDABI_FILETYPE_POLL: cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_KQUEUE); return (kern_kqueue(td, 0, &fcaps)); case CLOUDABI_FILETYPE_SHARED_MEMORY: cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_FTRUNCATE, CAP_MMAP_RWX); return (kern_shm_open(td, SHM_ANON, O_RDWR, 0, &fcaps)); case CLOUDABI_FILETYPE_SOCKET_DGRAM: socket_args.type = SOCK_DGRAM; return (sys_socket(td, &socket_args)); case CLOUDABI_FILETYPE_SOCKET_SEQPACKET: socket_args.type = SOCK_SEQPACKET; return (sys_socket(td, &socket_args)); case CLOUDABI_FILETYPE_SOCKET_STREAM: socket_args.type = SOCK_STREAM; return (sys_socket(td, &socket_args)); default: return (EINVAL); } } int cloudabi_sys_fd_create2(struct thread *td, struct cloudabi_sys_fd_create2_args *uap) { struct filecaps fcaps1 = {}, fcaps2 = {}; int fds[2]; int error; switch (uap->type) { case CLOUDABI_FILETYPE_FIFO: /* * CloudABI pipes are unidirectional. Restrict rights on * the pipe to simulate this. */ cap_rights_init(&fcaps1.fc_rights, CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_READ); fcaps1.fc_fcntls = CAP_FCNTL_SETFL; cap_rights_init(&fcaps2.fc_rights, CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_WRITE); fcaps2.fc_fcntls = CAP_FCNTL_SETFL; error = kern_pipe(td, fds, 0, &fcaps1, &fcaps2); break; case CLOUDABI_FILETYPE_SOCKET_DGRAM: error = kern_socketpair(td, AF_UNIX, SOCK_DGRAM, 0, fds); break; case CLOUDABI_FILETYPE_SOCKET_SEQPACKET: error = kern_socketpair(td, AF_UNIX, SOCK_SEQPACKET, 0, fds); break; case CLOUDABI_FILETYPE_SOCKET_STREAM: error = kern_socketpair(td, AF_UNIX, SOCK_STREAM, 0, fds); break; default: return (EINVAL); } if (error == 0) { td->td_retval[0] = fds[0]; td->td_retval[1] = fds[1]; } return (0); } int cloudabi_sys_fd_datasync(struct thread *td, struct cloudabi_sys_fd_datasync_args *uap) { struct fsync_args fsync_args = { .fd = uap->fd }; /* Call into fsync(), as FreeBSD lacks fdatasync(). */ return (sys_fsync(td, &fsync_args)); } int cloudabi_sys_fd_dup(struct thread *td, struct cloudabi_sys_fd_dup_args *uap) { return (kern_dup(td, FDDUP_NORMAL, 0, uap->from, 0)); } int cloudabi_sys_fd_replace(struct thread *td, struct cloudabi_sys_fd_replace_args *uap) { int error; /* * CloudABI's equivalent to dup2(). CloudABI processes should * not depend on hardcoded file descriptor layouts, but simply * use the file descriptor numbers that are allocated by the * kernel. Duplicating file descriptors to arbitrary numbers * should not be done. * * Invoke kern_dup() with FDDUP_MUSTREPLACE, so that we return * EBADF when duplicating to a nonexistent file descriptor. Also * clear the return value, as this system call yields no return * value. */ error = kern_dup(td, FDDUP_MUSTREPLACE, 0, uap->from, uap->to); td->td_retval[0] = 0; return (error); } int cloudabi_sys_fd_seek(struct thread *td, struct cloudabi_sys_fd_seek_args *uap) { struct lseek_args lseek_args = { .fd = uap->fd, .offset = uap->offset }; switch (uap->whence) { case CLOUDABI_WHENCE_CUR: lseek_args.whence = SEEK_CUR; break; case CLOUDABI_WHENCE_END: lseek_args.whence = SEEK_END; break; case CLOUDABI_WHENCE_SET: lseek_args.whence = SEEK_SET; break; default: return (EINVAL); } return (sys_lseek(td, &lseek_args)); } /* Converts a file descriptor to a CloudABI file descriptor type. */ cloudabi_filetype_t cloudabi_convert_filetype(const struct file *fp) { struct socket *so; struct vnode *vp; switch (fp->f_type) { case DTYPE_FIFO: return (CLOUDABI_FILETYPE_FIFO); case DTYPE_KQUEUE: return (CLOUDABI_FILETYPE_POLL); case DTYPE_PIPE: return (CLOUDABI_FILETYPE_FIFO); case DTYPE_PROCDESC: return (CLOUDABI_FILETYPE_PROCESS); case DTYPE_SHM: return (CLOUDABI_FILETYPE_SHARED_MEMORY); case DTYPE_SOCKET: so = fp->f_data; switch (so->so_type) { case SOCK_DGRAM: return (CLOUDABI_FILETYPE_SOCKET_DGRAM); case SOCK_SEQPACKET: return (CLOUDABI_FILETYPE_SOCKET_SEQPACKET); case SOCK_STREAM: return (CLOUDABI_FILETYPE_SOCKET_STREAM); default: return (CLOUDABI_FILETYPE_UNKNOWN); } case DTYPE_VNODE: vp = fp->f_vnode; switch (vp->v_type) { case VBLK: return (CLOUDABI_FILETYPE_BLOCK_DEVICE); case VCHR: return (CLOUDABI_FILETYPE_CHARACTER_DEVICE); case VDIR: return (CLOUDABI_FILETYPE_DIRECTORY); case VFIFO: return (CLOUDABI_FILETYPE_FIFO); case VLNK: return (CLOUDABI_FILETYPE_SYMBOLIC_LINK); case VREG: return (CLOUDABI_FILETYPE_REGULAR_FILE); case VSOCK: return (CLOUDABI_FILETYPE_SOCKET_STREAM); default: return (CLOUDABI_FILETYPE_UNKNOWN); } default: return (CLOUDABI_FILETYPE_UNKNOWN); } } /* Removes rights that conflict with the file descriptor type. */ void cloudabi_remove_conflicting_rights(cloudabi_filetype_t filetype, cloudabi_rights_t *base, cloudabi_rights_t *inheriting) { /* * CloudABI has a small number of additional rights bits to * disambiguate between multiple purposes. Remove the bits that * don't apply to the type of the file descriptor. * * As file descriptor access modes (O_ACCMODE) has been fully * replaced by rights bits, CloudABI distinguishes between * rights that apply to the file descriptor itself (base) versus * rights of new file descriptors derived from them * (inheriting). The code below approximates the pair by * decomposing depending on the file descriptor type. * * We need to be somewhat accurate about which actions can * actually be performed on the file descriptor, as functions * like fcntl(fd, F_GETFL) are emulated on top of this. */ switch (filetype) { case CLOUDABI_FILETYPE_DIRECTORY: *base &= CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS | CLOUDABI_RIGHT_FD_SYNC | CLOUDABI_RIGHT_FILE_ADVISE | CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY | CLOUDABI_RIGHT_FILE_CREATE_FILE | CLOUDABI_RIGHT_FILE_CREATE_FIFO | CLOUDABI_RIGHT_FILE_LINK_SOURCE | CLOUDABI_RIGHT_FILE_LINK_TARGET | CLOUDABI_RIGHT_FILE_OPEN | CLOUDABI_RIGHT_FILE_READDIR | CLOUDABI_RIGHT_FILE_READLINK | CLOUDABI_RIGHT_FILE_RENAME_SOURCE | CLOUDABI_RIGHT_FILE_RENAME_TARGET | CLOUDABI_RIGHT_FILE_STAT_FGET | CLOUDABI_RIGHT_FILE_STAT_FPUT_TIMES | CLOUDABI_RIGHT_FILE_STAT_GET | CLOUDABI_RIGHT_FILE_STAT_PUT_TIMES | CLOUDABI_RIGHT_FILE_SYMLINK | CLOUDABI_RIGHT_FILE_UNLINK | CLOUDABI_RIGHT_POLL_FD_READWRITE | CLOUDABI_RIGHT_SOCK_BIND_DIRECTORY | CLOUDABI_RIGHT_SOCK_CONNECT_DIRECTORY; *inheriting &= CLOUDABI_RIGHT_FD_DATASYNC | CLOUDABI_RIGHT_FD_READ | CLOUDABI_RIGHT_FD_SEEK | CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS | CLOUDABI_RIGHT_FD_SYNC | CLOUDABI_RIGHT_FD_TELL | CLOUDABI_RIGHT_FD_WRITE | CLOUDABI_RIGHT_FILE_ADVISE | CLOUDABI_RIGHT_FILE_ALLOCATE | CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY | CLOUDABI_RIGHT_FILE_CREATE_FILE | CLOUDABI_RIGHT_FILE_CREATE_FIFO | CLOUDABI_RIGHT_FILE_LINK_SOURCE | CLOUDABI_RIGHT_FILE_LINK_TARGET | CLOUDABI_RIGHT_FILE_OPEN | CLOUDABI_RIGHT_FILE_READDIR | CLOUDABI_RIGHT_FILE_READLINK | CLOUDABI_RIGHT_FILE_RENAME_SOURCE | CLOUDABI_RIGHT_FILE_RENAME_TARGET | CLOUDABI_RIGHT_FILE_STAT_FGET | CLOUDABI_RIGHT_FILE_STAT_FPUT_SIZE | CLOUDABI_RIGHT_FILE_STAT_FPUT_TIMES | CLOUDABI_RIGHT_FILE_STAT_GET | CLOUDABI_RIGHT_FILE_STAT_PUT_TIMES | CLOUDABI_RIGHT_FILE_SYMLINK | CLOUDABI_RIGHT_FILE_UNLINK | CLOUDABI_RIGHT_MEM_MAP | CLOUDABI_RIGHT_MEM_MAP_EXEC | CLOUDABI_RIGHT_POLL_FD_READWRITE | CLOUDABI_RIGHT_PROC_EXEC | CLOUDABI_RIGHT_SOCK_BIND_DIRECTORY | CLOUDABI_RIGHT_SOCK_CONNECT_DIRECTORY; break; case CLOUDABI_FILETYPE_FIFO: *base &= CLOUDABI_RIGHT_FD_READ | CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS | CLOUDABI_RIGHT_FD_WRITE | CLOUDABI_RIGHT_FILE_STAT_FGET | CLOUDABI_RIGHT_POLL_FD_READWRITE; *inheriting = 0; break; case CLOUDABI_FILETYPE_POLL: *base &= ~CLOUDABI_RIGHT_FILE_ADVISE; *inheriting = 0; break; case CLOUDABI_FILETYPE_PROCESS: *base &= ~(CLOUDABI_RIGHT_FILE_ADVISE | CLOUDABI_RIGHT_POLL_FD_READWRITE); *inheriting = 0; break; case CLOUDABI_FILETYPE_REGULAR_FILE: *base &= CLOUDABI_RIGHT_FD_DATASYNC | CLOUDABI_RIGHT_FD_READ | CLOUDABI_RIGHT_FD_SEEK | CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS | CLOUDABI_RIGHT_FD_SYNC | CLOUDABI_RIGHT_FD_TELL | CLOUDABI_RIGHT_FD_WRITE | CLOUDABI_RIGHT_FILE_ADVISE | CLOUDABI_RIGHT_FILE_ALLOCATE | CLOUDABI_RIGHT_FILE_STAT_FGET | CLOUDABI_RIGHT_FILE_STAT_FPUT_SIZE | CLOUDABI_RIGHT_FILE_STAT_FPUT_TIMES | CLOUDABI_RIGHT_MEM_MAP | CLOUDABI_RIGHT_MEM_MAP_EXEC | CLOUDABI_RIGHT_POLL_FD_READWRITE | CLOUDABI_RIGHT_PROC_EXEC; *inheriting = 0; break; case CLOUDABI_FILETYPE_SHARED_MEMORY: *base &= ~(CLOUDABI_RIGHT_FD_SEEK | CLOUDABI_RIGHT_FD_TELL | CLOUDABI_RIGHT_FILE_ADVISE | CLOUDABI_RIGHT_FILE_ALLOCATE | CLOUDABI_RIGHT_FILE_READDIR); *inheriting = 0; break; case CLOUDABI_FILETYPE_SOCKET_DGRAM: case CLOUDABI_FILETYPE_SOCKET_SEQPACKET: case CLOUDABI_FILETYPE_SOCKET_STREAM: *base &= CLOUDABI_RIGHT_FD_READ | CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS | CLOUDABI_RIGHT_FD_WRITE | CLOUDABI_RIGHT_FILE_STAT_FGET | CLOUDABI_RIGHT_POLL_FD_READWRITE | CLOUDABI_RIGHT_SOCK_ACCEPT | CLOUDABI_RIGHT_SOCK_BIND_SOCKET | CLOUDABI_RIGHT_SOCK_CONNECT_SOCKET | CLOUDABI_RIGHT_SOCK_LISTEN | CLOUDABI_RIGHT_SOCK_SHUTDOWN | CLOUDABI_RIGHT_SOCK_STAT_GET; break; default: *inheriting = 0; break; } } /* Converts FreeBSD's Capsicum rights to CloudABI's set of rights. */ static void convert_capabilities(const cap_rights_t *capabilities, cloudabi_filetype_t filetype, cloudabi_rights_t *base, cloudabi_rights_t *inheriting) { cloudabi_rights_t rights; /* Convert FreeBSD bits to CloudABI bits. */ rights = 0; #define MAPPING(cloudabi, ...) do { \ if (cap_rights_is_set(capabilities, ##__VA_ARGS__)) \ rights |= (cloudabi); \ } while (0); RIGHTS_MAPPINGS #undef MAPPING *base = rights; *inheriting = rights; cloudabi_remove_conflicting_rights(filetype, base, inheriting); } int cloudabi_sys_fd_stat_get(struct thread *td, struct cloudabi_sys_fd_stat_get_args *uap) { cloudabi_fdstat_t fsb = {}; struct filedesc *fdp; struct file *fp; seq_t seq; cap_rights_t rights; int error, oflags; bool modified; /* Obtain file descriptor properties. */ fdp = td->td_proc->p_fd; do { error = fget_unlocked(fdp, uap->fd, cap_rights_init(&rights), &fp, &seq); if (error != 0) return (error); if (fp->f_ops == &badfileops) { fdrop(fp, td); return (EBADF); } rights = *cap_rights(fdp, uap->fd); oflags = OFLAGS(fp->f_flag); fsb.fs_filetype = cloudabi_convert_filetype(fp); modified = fd_modified(fdp, uap->fd, seq); fdrop(fp, td); } while (modified); /* Convert file descriptor flags. */ if (oflags & O_APPEND) fsb.fs_flags |= CLOUDABI_FDFLAG_APPEND; if (oflags & O_NONBLOCK) fsb.fs_flags |= CLOUDABI_FDFLAG_NONBLOCK; if (oflags & O_SYNC) fsb.fs_flags |= CLOUDABI_FDFLAG_SYNC; /* Convert capabilities to CloudABI rights. */ convert_capabilities(&rights, fsb.fs_filetype, &fsb.fs_rights_base, &fsb.fs_rights_inheriting); return (copyout(&fsb, (void *)uap->buf, sizeof(fsb))); } /* Converts CloudABI rights to a set of Capsicum capabilities. */ int cloudabi_convert_rights(cloudabi_rights_t in, cap_rights_t *out) { cap_rights_init(out); #define MAPPING(cloudabi, ...) do { \ if (in & (cloudabi)) { \ cap_rights_set(out, ##__VA_ARGS__); \ in &= ~(cloudabi); \ } \ } while (0); RIGHTS_MAPPINGS #undef MAPPING if (in != 0) return (ENOTCAPABLE); return (0); } int cloudabi_sys_fd_stat_put(struct thread *td, struct cloudabi_sys_fd_stat_put_args *uap) { cloudabi_fdstat_t fsb; cap_rights_t rights; int error, oflags; error = copyin(uap->buf, &fsb, sizeof(fsb)); if (error != 0) return (error); if (uap->flags == CLOUDABI_FDSTAT_FLAGS) { /* Convert flags. */ oflags = 0; if (fsb.fs_flags & CLOUDABI_FDFLAG_APPEND) oflags |= O_APPEND; if (fsb.fs_flags & CLOUDABI_FDFLAG_NONBLOCK) oflags |= O_NONBLOCK; if (fsb.fs_flags & (CLOUDABI_FDFLAG_SYNC | CLOUDABI_FDFLAG_DSYNC | CLOUDABI_FDFLAG_RSYNC)) oflags |= O_SYNC; return (kern_fcntl(td, uap->fd, F_SETFL, oflags)); } else if (uap->flags == CLOUDABI_FDSTAT_RIGHTS) { /* Convert rights. */ error = cloudabi_convert_rights( fsb.fs_rights_base | fsb.fs_rights_inheriting, &rights); if (error != 0) return (error); return (kern_cap_rights_limit(td, uap->fd, &rights)); } return (EINVAL); } int cloudabi_sys_fd_sync(struct thread *td, struct cloudabi_sys_fd_sync_args *uap) { struct fsync_args fsync_args = { .fd = uap->fd }; return (sys_fsync(td, &fsync_args)); } Index: head/sys/compat/cloudabi/cloudabi_file.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_file.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_file.c (revision 297247) @@ -1,760 +1,761 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include +#include + #include -#include #include #include static MALLOC_DEFINE(M_CLOUDABI_PATH, "cloudabipath", "CloudABI pathnames"); /* * Copying pathnames from userspace to kernelspace. * * Unlike most operating systems, CloudABI doesn't use null-terminated * pathname strings. Processes always pass pathnames to the kernel by * providing a base pointer and a length. This has a couple of reasons: * * - It makes it easier to use CloudABI in combination with programming * languages other than C, that may use non-null terminated strings. * - It allows for calling system calls on individual components of the * pathname without modifying the input string. * * The function below copies in pathname strings and null-terminates it. * It also ensure that the string itself does not contain any null * bytes. * * TODO(ed): Add an abstraction to vfs_lookup.c that allows us to pass * in unterminated pathname strings, so we can do away with * the copying. */ static int copyin_path(const char *uaddr, size_t len, char **result) { char *buf; int error; if (len >= PATH_MAX) return (ENAMETOOLONG); buf = malloc(len + 1, M_CLOUDABI_PATH, M_WAITOK); error = copyin(uaddr, buf, len); if (error != 0) { free(buf, M_CLOUDABI_PATH); return (error); } if (memchr(buf, '\0', len) != NULL) { free(buf, M_CLOUDABI_PATH); return (EINVAL); } buf[len] = '\0'; *result = buf; return (0); } static void cloudabi_freestr(char *buf) { free(buf, M_CLOUDABI_PATH); } int cloudabi_sys_file_advise(struct thread *td, struct cloudabi_sys_file_advise_args *uap) { int advice; switch (uap->advice) { case CLOUDABI_ADVICE_DONTNEED: advice = POSIX_FADV_DONTNEED; break; case CLOUDABI_ADVICE_NOREUSE: advice = POSIX_FADV_NOREUSE; break; case CLOUDABI_ADVICE_NORMAL: advice = POSIX_FADV_NORMAL; break; case CLOUDABI_ADVICE_RANDOM: advice = POSIX_FADV_RANDOM; break; case CLOUDABI_ADVICE_SEQUENTIAL: advice = POSIX_FADV_SEQUENTIAL; break; case CLOUDABI_ADVICE_WILLNEED: advice = POSIX_FADV_WILLNEED; break; default: return (EINVAL); } return (kern_posix_fadvise(td, uap->fd, uap->offset, uap->len, advice)); } int cloudabi_sys_file_allocate(struct thread *td, struct cloudabi_sys_file_allocate_args *uap) { return (kern_posix_fallocate(td, uap->fd, uap->offset, uap->len)); } int cloudabi_sys_file_create(struct thread *td, struct cloudabi_sys_file_create_args *uap) { char *path; int error; error = copyin_path(uap->path, uap->pathlen, &path); if (error != 0) return (error); /* * CloudABI processes cannot interact with UNIX credentials and * permissions. Depend on the umask that is set prior to * execution to restrict the file permissions. */ switch (uap->type) { case CLOUDABI_FILETYPE_DIRECTORY: error = kern_mkdirat(td, uap->fd, path, UIO_SYSSPACE, 0777); break; case CLOUDABI_FILETYPE_FIFO: error = kern_mkfifoat(td, uap->fd, path, UIO_SYSSPACE, 0666); break; default: error = EINVAL; break; } cloudabi_freestr(path); return (error); } int cloudabi_sys_file_link(struct thread *td, struct cloudabi_sys_file_link_args *uap) { char *path1, *path2; int error; error = copyin_path(uap->path1, uap->path1len, &path1); if (error != 0) return (error); error = copyin_path(uap->path2, uap->path2len, &path2); if (error != 0) { cloudabi_freestr(path1); return (error); } - error = kern_linkat(td, uap->fd1, uap->fd2, path1, path2, - UIO_SYSSPACE, (uap->fd1 & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0 ? + error = kern_linkat(td, uap->fd1.fd, uap->fd2, path1, path2, + UIO_SYSSPACE, (uap->fd1.flags & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) ? FOLLOW : NOFOLLOW); cloudabi_freestr(path1); cloudabi_freestr(path2); return (error); } int cloudabi_sys_file_open(struct thread *td, struct cloudabi_sys_file_open_args *uap) { cloudabi_fdstat_t fds; cap_rights_t rights; struct filecaps fcaps = {}; struct nameidata nd; struct file *fp; struct vnode *vp; char *path; int error, fd, fflags; bool read, write; error = copyin(uap->fds, &fds, sizeof(fds)); if (error != 0) return (error); /* All the requested rights should be set on the descriptor. */ error = cloudabi_convert_rights( fds.fs_rights_base | fds.fs_rights_inheriting, &rights); if (error != 0) return (error); cap_rights_set(&rights, CAP_LOOKUP); /* Convert rights to corresponding access mode. */ read = (fds.fs_rights_base & (CLOUDABI_RIGHT_FD_READ | CLOUDABI_RIGHT_FILE_READDIR | CLOUDABI_RIGHT_MEM_MAP_EXEC)) != 0; write = (fds.fs_rights_base & (CLOUDABI_RIGHT_FD_DATASYNC | CLOUDABI_RIGHT_FD_WRITE | CLOUDABI_RIGHT_FILE_ALLOCATE | CLOUDABI_RIGHT_FILE_STAT_FPUT_SIZE)) != 0; fflags = write ? read ? FREAD | FWRITE : FWRITE : FREAD; /* Convert open flags. */ if ((uap->oflags & CLOUDABI_O_CREAT) != 0) { fflags |= O_CREAT; cap_rights_set(&rights, CAP_CREATE); } if ((uap->oflags & CLOUDABI_O_DIRECTORY) != 0) fflags |= O_DIRECTORY; if ((uap->oflags & CLOUDABI_O_EXCL) != 0) fflags |= O_EXCL; if ((uap->oflags & CLOUDABI_O_TRUNC) != 0) { fflags |= O_TRUNC; cap_rights_set(&rights, CAP_FTRUNCATE); } if ((fds.fs_flags & CLOUDABI_FDFLAG_APPEND) != 0) fflags |= O_APPEND; if ((fds.fs_flags & CLOUDABI_FDFLAG_NONBLOCK) != 0) fflags |= O_NONBLOCK; if ((fds.fs_flags & (CLOUDABI_FDFLAG_SYNC | CLOUDABI_FDFLAG_DSYNC | CLOUDABI_FDFLAG_RSYNC)) != 0) { fflags |= O_SYNC; cap_rights_set(&rights, CAP_FSYNC); } - if ((uap->fd & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) == 0) + if ((uap->dirfd.flags & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) == 0) fflags |= O_NOFOLLOW; if (write && (fflags & (O_APPEND | O_TRUNC)) == 0) cap_rights_set(&rights, CAP_SEEK); /* Allocate new file descriptor. */ error = falloc_noinstall(td, &fp); if (error != 0) return (error); fp->f_flag = fflags & FMASK; /* Open path. */ error = copyin_path(uap->path, uap->pathlen, &path); if (error != 0) { fdrop(fp, td); return (error); } - NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path, uap->fd, + NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path, uap->dirfd.fd, &rights, td); error = vn_open(&nd, &fflags, 0777 & ~td->td_proc->p_fd->fd_cmask, fp); cloudabi_freestr(path); if (error != 0) { /* Custom operations provided. */ if (error == ENXIO && fp->f_ops != &badfileops) goto success; /* * POSIX compliance: return ELOOP in case openat() is * called on a symbolic link and O_NOFOLLOW is set. */ if (error == EMLINK) error = ELOOP; fdrop(fp, td); return (error); } NDFREE(&nd, NDF_ONLY_PNBUF); filecaps_free(&nd.ni_filecaps); fp->f_vnode = vp = nd.ni_vp; /* Install vnode operations if no custom operations are provided. */ if (fp->f_ops == &badfileops) { fp->f_seqcount = 1; finit(fp, (fflags & FMASK) | (fp->f_flag & FHASLOCK), DTYPE_VNODE, vp, &vnops); } VOP_UNLOCK(vp, 0); /* Truncate file. */ if (fflags & O_TRUNC) { error = fo_truncate(fp, 0, td->td_ucred, td); if (error != 0) { fdrop(fp, td); return (error); } } success: /* Determine which Capsicum rights to set on the file descriptor. */ cloudabi_remove_conflicting_rights(cloudabi_convert_filetype(fp), &fds.fs_rights_base, &fds.fs_rights_inheriting); cloudabi_convert_rights(fds.fs_rights_base | fds.fs_rights_inheriting, &fcaps.fc_rights); if (cap_rights_is_set(&fcaps.fc_rights)) fcaps.fc_fcntls = CAP_FCNTL_SETFL; error = finstall(td, fp, &fd, fflags, &fcaps); fdrop(fp, td); if (error != 0) return (error); td->td_retval[0] = fd; return (0); } /* Converts a FreeBSD directory entry structure and writes it to userspace. */ static int write_dirent(struct dirent *bde, cloudabi_dircookie_t cookie, struct uio *uio) { cloudabi_dirent_t cde = { .d_next = cookie, .d_ino = bde->d_fileno, .d_namlen = bde->d_namlen, }; size_t len; int error; /* Convert file type. */ switch (bde->d_type) { case DT_BLK: cde.d_type = CLOUDABI_FILETYPE_BLOCK_DEVICE; break; case DT_CHR: cde.d_type = CLOUDABI_FILETYPE_CHARACTER_DEVICE; break; case DT_DIR: cde.d_type = CLOUDABI_FILETYPE_DIRECTORY; break; case DT_FIFO: cde.d_type = CLOUDABI_FILETYPE_FIFO; break; case DT_LNK: cde.d_type = CLOUDABI_FILETYPE_SYMBOLIC_LINK; break; case DT_REG: cde.d_type = CLOUDABI_FILETYPE_REGULAR_FILE; break; case DT_SOCK: /* The exact socket type cannot be derived. */ cde.d_type = CLOUDABI_FILETYPE_SOCKET_STREAM; break; default: cde.d_type = CLOUDABI_FILETYPE_UNKNOWN; break; } /* Write directory entry structure. */ len = sizeof(cde) < uio->uio_resid ? sizeof(cde) : uio->uio_resid; error = uiomove(&cde, len, uio); if (error != 0) return (error); /* Write filename. */ len = bde->d_namlen < uio->uio_resid ? bde->d_namlen : uio->uio_resid; return (uiomove(bde->d_name, len, uio)); } int cloudabi_sys_file_readdir(struct thread *td, struct cloudabi_sys_file_readdir_args *uap) { struct iovec iov = { .iov_base = uap->buf, .iov_len = uap->nbyte }; struct uio uio = { .uio_iov = &iov, .uio_iovcnt = 1, .uio_resid = iov.iov_len, .uio_segflg = UIO_USERSPACE, .uio_rw = UIO_READ, .uio_td = td }; struct file *fp; struct vnode *vp; void *readbuf; cap_rights_t rights; cloudabi_dircookie_t offset; int error; /* Obtain directory vnode. */ error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp); if (error != 0) { if (error == EINVAL) return (ENOTDIR); return (error); } if ((fp->f_flag & FREAD) == 0) { fdrop(fp, td); return (EBADF); } /* * Call VOP_READDIR() and convert resulting data until the user * provided buffer is filled. */ readbuf = malloc(MAXBSIZE, M_TEMP, M_WAITOK); offset = uap->cookie; vp = fp->f_vnode; while (uio.uio_resid > 0) { struct iovec readiov = { .iov_base = readbuf, .iov_len = MAXBSIZE }; struct uio readuio = { .uio_iov = &readiov, .uio_iovcnt = 1, .uio_rw = UIO_READ, .uio_segflg = UIO_SYSSPACE, .uio_td = td, .uio_resid = MAXBSIZE, .uio_offset = offset }; struct dirent *bde; unsigned long *cookies, *cookie; size_t readbuflen; int eof, ncookies; /* Validate file type. */ vn_lock(vp, LK_SHARED | LK_RETRY); if (vp->v_type != VDIR) { VOP_UNLOCK(vp, 0); error = ENOTDIR; goto done; } #ifdef MAC error = mac_vnode_check_readdir(td->td_ucred, vp); if (error != 0) { VOP_UNLOCK(vp, 0); goto done; } #endif /* MAC */ /* Read new directory entries. */ cookies = NULL; ncookies = 0; error = VOP_READDIR(vp, &readuio, fp->f_cred, &eof, &ncookies, &cookies); VOP_UNLOCK(vp, 0); if (error != 0) goto done; /* Convert entries to CloudABI's format. */ readbuflen = MAXBSIZE - readuio.uio_resid; bde = readbuf; cookie = cookies; while (readbuflen >= offsetof(struct dirent, d_name) && uio.uio_resid > 0 && ncookies > 0) { /* Ensure that the returned offset always increases. */ if (readbuflen >= bde->d_reclen && bde->d_fileno != 0 && *cookie > offset) { error = write_dirent(bde, *cookie, &uio); if (error != 0) { free(cookies, M_TEMP); goto done; } } if (offset < *cookie) offset = *cookie; ++cookie; --ncookies; readbuflen -= bde->d_reclen; bde = (struct dirent *)((char *)bde + bde->d_reclen); } free(cookies, M_TEMP); if (eof) break; } done: fdrop(fp, td); free(readbuf, M_TEMP); if (error != 0) return (error); /* Return number of bytes copied to userspace. */ td->td_retval[0] = uap->nbyte - uio.uio_resid; return (0); } int cloudabi_sys_file_readlink(struct thread *td, struct cloudabi_sys_file_readlink_args *uap) { char *path; int error; error = copyin_path(uap->path, uap->pathlen, &path); if (error != 0) return (error); error = kern_readlinkat(td, uap->fd, path, UIO_SYSSPACE, uap->buf, UIO_USERSPACE, uap->bufsize); cloudabi_freestr(path); return (error); } int cloudabi_sys_file_rename(struct thread *td, struct cloudabi_sys_file_rename_args *uap) { char *old, *new; int error; error = copyin_path(uap->old, uap->oldlen, &old); if (error != 0) return (error); error = copyin_path(uap->new, uap->newlen, &new); if (error != 0) { cloudabi_freestr(old); return (error); } error = kern_renameat(td, uap->oldfd, old, uap->newfd, new, UIO_SYSSPACE); cloudabi_freestr(old); cloudabi_freestr(new); return (error); } /* Converts a FreeBSD stat structure to a CloudABI stat structure. */ static void convert_stat(const struct stat *sb, cloudabi_filestat_t *csb) { cloudabi_filestat_t res = { .st_dev = sb->st_dev, .st_ino = sb->st_ino, .st_nlink = sb->st_nlink, .st_size = sb->st_size, }; cloudabi_convert_timespec(&sb->st_atim, &res.st_atim); cloudabi_convert_timespec(&sb->st_mtim, &res.st_mtim); cloudabi_convert_timespec(&sb->st_ctim, &res.st_ctim); *csb = res; } int cloudabi_sys_file_stat_fget(struct thread *td, struct cloudabi_sys_file_stat_fget_args *uap) { struct stat sb; cloudabi_filestat_t csb; struct file *fp; cap_rights_t rights; cloudabi_filetype_t filetype; int error; /* Fetch file descriptor attributes. */ error = fget(td, uap->fd, cap_rights_init(&rights, CAP_FSTAT), &fp); if (error != 0) return (error); error = fo_stat(fp, &sb, td->td_ucred, td); if (error != 0) { fdrop(fp, td); return (error); } filetype = cloudabi_convert_filetype(fp); fdrop(fp, td); /* Convert attributes to CloudABI's format. */ convert_stat(&sb, &csb); csb.st_filetype = filetype; return (copyout(&csb, uap->buf, sizeof(csb))); } /* Converts timestamps to arguments to futimens() and utimensat(). */ static void convert_utimens_arguments(const cloudabi_filestat_t *fs, cloudabi_fsflags_t flags, struct timespec *ts) { if ((flags & CLOUDABI_FILESTAT_ATIM_NOW) != 0) { ts[0].tv_nsec = UTIME_NOW; } else if ((flags & CLOUDABI_FILESTAT_ATIM) != 0) { ts[0].tv_sec = fs->st_atim / 1000000000; ts[0].tv_nsec = fs->st_atim % 1000000000; } else { ts[0].tv_nsec = UTIME_OMIT; } if ((flags & CLOUDABI_FILESTAT_MTIM_NOW) != 0) { ts[1].tv_nsec = UTIME_NOW; } else if ((flags & CLOUDABI_FILESTAT_MTIM) != 0) { ts[1].tv_sec = fs->st_mtim / 1000000000; ts[1].tv_nsec = fs->st_mtim % 1000000000; } else { ts[1].tv_nsec = UTIME_OMIT; } } int cloudabi_sys_file_stat_fput(struct thread *td, struct cloudabi_sys_file_stat_fput_args *uap) { cloudabi_filestat_t fs; struct timespec ts[2]; int error; error = copyin(uap->buf, &fs, sizeof(fs)); if (error != 0) return (error); /* * Only support truncation and timestamp modification separately * for now, to prevent unnecessary code duplication. */ if ((uap->flags & CLOUDABI_FILESTAT_SIZE) != 0) { /* Call into kern_ftruncate() for file truncation. */ if ((uap->flags & ~CLOUDABI_FILESTAT_SIZE) != 0) return (EINVAL); return (kern_ftruncate(td, uap->fd, fs.st_size)); } else if ((uap->flags & (CLOUDABI_FILESTAT_ATIM | CLOUDABI_FILESTAT_ATIM_NOW | CLOUDABI_FILESTAT_MTIM | CLOUDABI_FILESTAT_MTIM_NOW)) != 0) { /* Call into kern_futimens() for timestamp modification. */ if ((uap->flags & ~(CLOUDABI_FILESTAT_ATIM | CLOUDABI_FILESTAT_ATIM_NOW | CLOUDABI_FILESTAT_MTIM | CLOUDABI_FILESTAT_MTIM_NOW)) != 0) return (EINVAL); convert_utimens_arguments(&fs, uap->flags, ts); return (kern_futimens(td, uap->fd, ts, UIO_SYSSPACE)); } return (EINVAL); } int cloudabi_sys_file_stat_get(struct thread *td, struct cloudabi_sys_file_stat_get_args *uap) { struct stat sb; cloudabi_filestat_t csb; char *path; int error; error = copyin_path(uap->path, uap->pathlen, &path); if (error != 0) return (error); error = kern_statat(td, - (uap->fd & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0 ? 0 : - AT_SYMLINK_NOFOLLOW, uap->fd, path, UIO_SYSSPACE, &sb, NULL); + (uap->fd.flags & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0 ? 0 : + AT_SYMLINK_NOFOLLOW, uap->fd.fd, path, UIO_SYSSPACE, &sb, NULL); cloudabi_freestr(path); if (error != 0) return (error); /* Convert results and return them. */ convert_stat(&sb, &csb); if (S_ISBLK(sb.st_mode)) csb.st_filetype = CLOUDABI_FILETYPE_BLOCK_DEVICE; else if (S_ISCHR(sb.st_mode)) csb.st_filetype = CLOUDABI_FILETYPE_CHARACTER_DEVICE; else if (S_ISDIR(sb.st_mode)) csb.st_filetype = CLOUDABI_FILETYPE_DIRECTORY; else if (S_ISFIFO(sb.st_mode)) csb.st_filetype = CLOUDABI_FILETYPE_FIFO; else if (S_ISREG(sb.st_mode)) csb.st_filetype = CLOUDABI_FILETYPE_REGULAR_FILE; else if (S_ISSOCK(sb.st_mode)) { /* Inaccurate, but the best that we can do. */ csb.st_filetype = CLOUDABI_FILETYPE_SOCKET_STREAM; } else if (S_ISLNK(sb.st_mode)) csb.st_filetype = CLOUDABI_FILETYPE_SYMBOLIC_LINK; else csb.st_filetype = CLOUDABI_FILETYPE_UNKNOWN; return (copyout(&csb, uap->buf, sizeof(csb))); } int cloudabi_sys_file_stat_put(struct thread *td, struct cloudabi_sys_file_stat_put_args *uap) { cloudabi_filestat_t fs; struct timespec ts[2]; char *path; int error; /* * Only support timestamp modification for now, as there is no * truncateat(). */ if ((uap->flags & ~(CLOUDABI_FILESTAT_ATIM | CLOUDABI_FILESTAT_ATIM_NOW | CLOUDABI_FILESTAT_MTIM | CLOUDABI_FILESTAT_MTIM_NOW)) != 0) return (EINVAL); error = copyin(uap->buf, &fs, sizeof(fs)); if (error != 0) return (error); error = copyin_path(uap->path, uap->pathlen, &path); if (error != 0) return (error); convert_utimens_arguments(&fs, uap->flags, ts); - error = kern_utimensat(td, uap->fd, path, UIO_SYSSPACE, ts, - UIO_SYSSPACE, (uap->fd & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0 ? + error = kern_utimensat(td, uap->fd.fd, path, UIO_SYSSPACE, ts, + UIO_SYSSPACE, (uap->fd.flags & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) ? 0 : AT_SYMLINK_NOFOLLOW); cloudabi_freestr(path); return (error); } int cloudabi_sys_file_symlink(struct thread *td, struct cloudabi_sys_file_symlink_args *uap) { char *path1, *path2; int error; error = copyin_path(uap->path1, uap->path1len, &path1); if (error != 0) return (error); error = copyin_path(uap->path2, uap->path2len, &path2); if (error != 0) { cloudabi_freestr(path1); return (error); } error = kern_symlinkat(td, path1, uap->fd, path2, UIO_SYSSPACE); cloudabi_freestr(path1); cloudabi_freestr(path2); return (error); } int cloudabi_sys_file_unlink(struct thread *td, struct cloudabi_sys_file_unlink_args *uap) { char *path; int error; error = copyin_path(uap->path, uap->pathlen, &path); if (error != 0) return (error); - if (uap->flag & CLOUDABI_UNLINK_REMOVEDIR) + if (uap->flags & CLOUDABI_UNLINK_REMOVEDIR) error = kern_rmdirat(td, uap->fd, path, UIO_SYSSPACE); else error = kern_unlinkat(td, uap->fd, path, UIO_SYSSPACE, 0); cloudabi_freestr(path); return (error); } Index: head/sys/compat/cloudabi/cloudabi_futex.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_futex.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_futex.c (revision 297247) @@ -1,1161 +1,1162 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include +#include + #include -#include #include /* * Futexes for CloudABI. * * On most systems, futexes are implemented as objects of a single type * on which a set of operations can be performed. CloudABI makes a clear * distinction between locks and condition variables. A lock may have * zero or more associated condition variables. A condition variable is * always associated with exactly one lock. There is a strict topology. * This approach has two advantages: * * - This topology is guaranteed to be acyclic. Requeueing of threads * only happens in one direction (from condition variables to locks). * This eases locking. * - It means that a futex object for a lock exists when it is unlocked, * but has threads waiting on associated condition variables. Threads * can be requeued to a lock even if the thread performing the wakeup * does not have the lock mapped in its address space. * * This futex implementation only implements a single lock type, namely * a read-write lock. A regular mutex type would not be necessary, as * the read-write lock is as efficient as a mutex if used as such. * Userspace futex locks are 32 bits in size: * * - 1 bit: has threads waiting in kernel-space. * - 1 bit: is write-locked. * - 30 bits: * - if write-locked: thread ID of owner. * - if not write-locked: number of read locks held. * * Condition variables are also 32 bits in size. Its value is modified * by kernel-space exclusively. Zero indicates that it has no waiting * threads. Non-zero indicates the opposite. * * This implementation is optimal, in the sense that it only wakes up * threads if they can actually continue execution. It does not suffer * from the thundering herd problem. If multiple threads waiting on a * condition variable need to be woken up, only a single thread is * scheduled. All other threads are 'donated' to this thread. After the * thread manages to reacquire the lock, it requeues its donated threads * to the lock. * * TODO(ed): Integrate this functionality into kern_umtx.c instead. * TODO(ed): Store futex objects in a hash table. * TODO(ed): Add actual priority inheritance. * TODO(ed): Let futex_queue also take priorities into account. * TODO(ed): Make locking fine-grained. * TODO(ed): Perform sleeps until an actual absolute point in time, * instead of converting the timestamp to a relative value. */ struct futex_address; struct futex_condvar; struct futex_lock; struct futex_queue; struct futex_waiter; /* Identifier of a location in memory. */ struct futex_address { struct umtx_key fa_key; }; /* A set of waiting threads. */ struct futex_queue { STAILQ_HEAD(, futex_waiter) fq_list; unsigned int fq_count; }; /* Condition variables. */ struct futex_condvar { /* Address of the condition variable. */ struct futex_address fc_address; /* The lock the waiters should be moved to when signalled. */ struct futex_lock * fc_lock; /* Threads waiting on the condition variable. */ struct futex_queue fc_waiters; /* * Number of threads blocked on this condition variable, or * being blocked on the lock after being requeued. */ unsigned int fc_waitcount; /* Global list pointers. */ LIST_ENTRY(futex_condvar) fc_next; }; /* Read-write locks. */ struct futex_lock { /* Address of the lock. */ struct futex_address fl_address; /* * Current owner of the lock. LOCK_UNMANAGED if the lock is * currently not owned by the kernel. LOCK_OWNER_UNKNOWN in case * the owner is not known (e.g., when the lock is read-locked). */ cloudabi_tid_t fl_owner; #define LOCK_UNMANAGED 0x0 #define LOCK_OWNER_UNKNOWN 0x1 /* Writers blocked on the lock. */ struct futex_queue fl_writers; /* Readers blocked on the lock. */ struct futex_queue fl_readers; /* Number of threads blocked on this lock + condition variables. */ unsigned int fl_waitcount; /* Global list pointers. */ LIST_ENTRY(futex_lock) fl_next; }; /* Information associated with a thread blocked on an object. */ struct futex_waiter { /* Thread ID. */ cloudabi_tid_t fw_tid; /* Condition variable used for waiting. */ struct cv fw_wait; /* Queue this waiter is currently placed in. */ struct futex_queue * fw_queue; /* List pointers of fw_queue. */ STAILQ_ENTRY(futex_waiter) fw_next; /* Lock has been acquired. */ bool fw_locked; /* If not locked, threads that should block after acquiring. */ struct futex_queue fw_donated; }; /* Global data structures. */ static MALLOC_DEFINE(M_FUTEX, "futex", "CloudABI futex"); static struct sx futex_global_lock; SX_SYSINIT(futex_global_lock, &futex_global_lock, "CloudABI futex global lock"); static LIST_HEAD(, futex_lock) futex_lock_list = LIST_HEAD_INITIALIZER(&futex_lock_list); static LIST_HEAD(, futex_condvar) futex_condvar_list = LIST_HEAD_INITIALIZER(&futex_condvar_list); /* Utility functions. */ static void futex_lock_assert(const struct futex_lock *); static struct futex_lock *futex_lock_lookup_locked(struct futex_address *); static void futex_lock_release(struct futex_lock *); static int futex_lock_tryrdlock(struct futex_lock *, cloudabi_lock_t *); static int futex_lock_unmanage(struct futex_lock *, cloudabi_lock_t *); static int futex_lock_update_owner(struct futex_lock *, cloudabi_lock_t *); static int futex_lock_wake_up_next(struct futex_lock *, cloudabi_lock_t *); static unsigned int futex_queue_count(const struct futex_queue *); static void futex_queue_init(struct futex_queue *); static void futex_queue_requeue(struct futex_queue *, struct futex_queue *, unsigned int); static int futex_queue_sleep(struct futex_queue *, struct futex_lock *, struct futex_waiter *, struct thread *, cloudabi_clockid_t, cloudabi_timestamp_t, cloudabi_timestamp_t); static cloudabi_tid_t futex_queue_tid_best(const struct futex_queue *); static void futex_queue_wake_up_all(struct futex_queue *); static void futex_queue_wake_up_best(struct futex_queue *); static void futex_queue_wake_up_donate(struct futex_queue *, unsigned int); static int futex_user_load(uint32_t *, uint32_t *); static int futex_user_store(uint32_t *, uint32_t); static int futex_user_cmpxchg(uint32_t *, uint32_t, uint32_t *, uint32_t); /* * futex_address operations. */ static int futex_address_create(struct futex_address *fa, struct thread *td, const void *object, cloudabi_mflags_t scope) { KASSERT(td == curthread, ("Can only create umtx keys for the current thread")); switch (scope) { case CLOUDABI_MAP_PRIVATE: return (umtx_key_get(object, TYPE_FUTEX, THREAD_SHARE, &fa->fa_key)); case CLOUDABI_MAP_SHARED: return (umtx_key_get(object, TYPE_FUTEX, AUTO_SHARE, &fa->fa_key)); default: return (EINVAL); } } static void futex_address_free(struct futex_address *fa) { umtx_key_release(&fa->fa_key); } static bool futex_address_match(const struct futex_address *fa1, const struct futex_address *fa2) { return (umtx_key_match(&fa1->fa_key, &fa2->fa_key)); } /* * futex_condvar operations. */ static void futex_condvar_assert(const struct futex_condvar *fc) { KASSERT(fc->fc_waitcount >= futex_queue_count(&fc->fc_waiters), ("Total number of waiters cannot be smaller than the wait queue")); futex_lock_assert(fc->fc_lock); } static int futex_condvar_lookup(struct thread *td, const cloudabi_condvar_t *address, cloudabi_mflags_t scope, struct futex_condvar **fcret) { struct futex_address fa_condvar; struct futex_condvar *fc; int error; error = futex_address_create(&fa_condvar, td, address, scope); if (error != 0) return (error); sx_xlock(&futex_global_lock); LIST_FOREACH(fc, &futex_condvar_list, fc_next) { if (futex_address_match(&fc->fc_address, &fa_condvar)) { /* Found matching lock object. */ futex_address_free(&fa_condvar); futex_condvar_assert(fc); *fcret = fc; return (0); } } sx_xunlock(&futex_global_lock); futex_address_free(&fa_condvar); return (ENOENT); } static int futex_condvar_lookup_or_create(struct thread *td, const cloudabi_condvar_t *condvar, cloudabi_mflags_t condvar_scope, const cloudabi_lock_t *lock, cloudabi_mflags_t lock_scope, struct futex_condvar **fcret) { struct futex_address fa_condvar, fa_lock; struct futex_condvar *fc; struct futex_lock *fl; int error; error = futex_address_create(&fa_condvar, td, condvar, condvar_scope); if (error != 0) return (error); error = futex_address_create(&fa_lock, td, lock, lock_scope); if (error != 0) { futex_address_free(&fa_condvar); return (error); } sx_xlock(&futex_global_lock); LIST_FOREACH(fc, &futex_condvar_list, fc_next) { if (!futex_address_match(&fc->fc_address, &fa_condvar)) continue; fl = fc->fc_lock; if (!futex_address_match(&fl->fl_address, &fa_lock)) { /* Condition variable is owned by a different lock. */ futex_address_free(&fa_condvar); futex_address_free(&fa_lock); sx_xunlock(&futex_global_lock); return (EINVAL); } /* Found fully matching condition variable. */ futex_address_free(&fa_condvar); futex_address_free(&fa_lock); futex_condvar_assert(fc); *fcret = fc; return (0); } /* None found. Create new condition variable object. */ fc = malloc(sizeof(*fc), M_FUTEX, M_WAITOK); fc->fc_address = fa_condvar; fc->fc_lock = futex_lock_lookup_locked(&fa_lock); futex_queue_init(&fc->fc_waiters); fc->fc_waitcount = 0; LIST_INSERT_HEAD(&futex_condvar_list, fc, fc_next); *fcret = fc; return (0); } static void futex_condvar_release(struct futex_condvar *fc) { struct futex_lock *fl; futex_condvar_assert(fc); fl = fc->fc_lock; if (fc->fc_waitcount == 0) { /* Condition variable has no waiters. Deallocate it. */ futex_address_free(&fc->fc_address); LIST_REMOVE(fc, fc_next); free(fc, M_FUTEX); } futex_lock_release(fl); } static int futex_condvar_unmanage(struct futex_condvar *fc, cloudabi_condvar_t *condvar) { if (futex_queue_count(&fc->fc_waiters) != 0) return (0); return (futex_user_store(condvar, CLOUDABI_CONDVAR_HAS_NO_WAITERS)); } /* * futex_lock operations. */ static void futex_lock_assert(const struct futex_lock *fl) { /* * A futex lock can only be kernel-managed if it has waiters. * Vice versa: if a futex lock has waiters, it must be * kernel-managed. */ KASSERT((fl->fl_owner == LOCK_UNMANAGED) == (futex_queue_count(&fl->fl_readers) == 0 && futex_queue_count(&fl->fl_writers) == 0), ("Managed locks must have waiting threads")); KASSERT(fl->fl_waitcount != 0 || fl->fl_owner == LOCK_UNMANAGED, ("Lock with no waiters must be unmanaged")); } static int futex_lock_lookup(struct thread *td, const cloudabi_lock_t *address, cloudabi_mflags_t scope, struct futex_lock **flret) { struct futex_address fa; int error; error = futex_address_create(&fa, td, address, scope); if (error != 0) return (error); sx_xlock(&futex_global_lock); *flret = futex_lock_lookup_locked(&fa); return (0); } static struct futex_lock * futex_lock_lookup_locked(struct futex_address *fa) { struct futex_lock *fl; LIST_FOREACH(fl, &futex_lock_list, fl_next) { if (futex_address_match(&fl->fl_address, fa)) { /* Found matching lock object. */ futex_address_free(fa); futex_lock_assert(fl); return (fl); } } /* None found. Create new lock object. */ fl = malloc(sizeof(*fl), M_FUTEX, M_WAITOK); fl->fl_address = *fa; fl->fl_owner = LOCK_UNMANAGED; futex_queue_init(&fl->fl_readers); futex_queue_init(&fl->fl_writers); fl->fl_waitcount = 0; LIST_INSERT_HEAD(&futex_lock_list, fl, fl_next); return (fl); } static int futex_lock_rdlock(struct futex_lock *fl, struct thread *td, cloudabi_lock_t *lock, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision) { struct futex_waiter fw; int error; error = futex_lock_tryrdlock(fl, lock); if (error == EBUSY) { /* Suspend execution. */ KASSERT(fl->fl_owner != LOCK_UNMANAGED, ("Attempted to sleep on an unmanaged lock")); error = futex_queue_sleep(&fl->fl_readers, fl, &fw, td, clock_id, timeout, precision); KASSERT((error == 0) == fw.fw_locked, ("Should have locked write lock on success")); KASSERT(futex_queue_count(&fw.fw_donated) == 0, ("Lock functions cannot receive threads")); } if (error != 0) futex_lock_unmanage(fl, lock); return (error); } static void futex_lock_release(struct futex_lock *fl) { futex_lock_assert(fl); if (fl->fl_waitcount == 0) { /* Lock object is unreferenced. Deallocate it. */ KASSERT(fl->fl_owner == LOCK_UNMANAGED, ("Attempted to free a managed lock")); futex_address_free(&fl->fl_address); LIST_REMOVE(fl, fl_next); free(fl, M_FUTEX); } sx_xunlock(&futex_global_lock); } static int futex_lock_unmanage(struct futex_lock *fl, cloudabi_lock_t *lock) { cloudabi_lock_t cmp, old; int error; if (futex_queue_count(&fl->fl_readers) == 0 && futex_queue_count(&fl->fl_writers) == 0) { /* Lock should be unmanaged. */ fl->fl_owner = LOCK_UNMANAGED; /* Clear kernel-managed bit. */ error = futex_user_load(lock, &old); if (error != 0) return (error); for (;;) { cmp = old; error = futex_user_cmpxchg(lock, cmp, &old, cmp & ~CLOUDABI_LOCK_KERNEL_MANAGED); if (error != 0) return (error); if (old == cmp) break; } } return (0); } /* Sets an owner of a lock, based on a userspace lock value. */ static void futex_lock_set_owner(struct futex_lock *fl, cloudabi_lock_t lock) { /* Lock has no explicit owner. */ if ((lock & ~CLOUDABI_LOCK_WRLOCKED) == 0) { fl->fl_owner = LOCK_OWNER_UNKNOWN; return; } lock &= ~(CLOUDABI_LOCK_WRLOCKED | CLOUDABI_LOCK_KERNEL_MANAGED); /* Don't allow userspace to silently unlock. */ if (lock == LOCK_UNMANAGED) { fl->fl_owner = LOCK_OWNER_UNKNOWN; return; } fl->fl_owner = lock; } static int futex_lock_unlock(struct futex_lock *fl, struct thread *td, cloudabi_lock_t *lock) { int error; /* Validate that this thread is allowed to unlock. */ error = futex_lock_update_owner(fl, lock); if (error != 0) return (error); if (fl->fl_owner != LOCK_UNMANAGED && fl->fl_owner != td->td_tid) return (EPERM); return (futex_lock_wake_up_next(fl, lock)); } /* Syncs in the owner of the lock from userspace if needed. */ static int futex_lock_update_owner(struct futex_lock *fl, cloudabi_lock_t *address) { cloudabi_lock_t lock; int error; if (fl->fl_owner == LOCK_OWNER_UNKNOWN) { error = futex_user_load(address, &lock); if (error != 0) return (error); futex_lock_set_owner(fl, lock); } return (0); } static int futex_lock_tryrdlock(struct futex_lock *fl, cloudabi_lock_t *address) { cloudabi_lock_t old, cmp; int error; if (fl->fl_owner != LOCK_UNMANAGED) { /* Lock is already acquired. */ return (EBUSY); } old = CLOUDABI_LOCK_UNLOCKED; for (;;) { if ((old & CLOUDABI_LOCK_KERNEL_MANAGED) != 0) { /* * Userspace lock is kernel-managed, even though * the kernel disagrees. */ return (EINVAL); } if ((old & CLOUDABI_LOCK_WRLOCKED) == 0) { /* * Lock is not write-locked. Attempt to acquire * it by increasing the read count. */ cmp = old; error = futex_user_cmpxchg(address, cmp, &old, cmp + 1); if (error != 0) return (error); if (old == cmp) { /* Success. */ return (0); } } else { /* Lock is write-locked. Make it kernel-managed. */ cmp = old; error = futex_user_cmpxchg(address, cmp, &old, cmp | CLOUDABI_LOCK_KERNEL_MANAGED); if (error != 0) return (error); if (old == cmp) { /* Success. */ futex_lock_set_owner(fl, cmp); return (EBUSY); } } } } static int futex_lock_trywrlock(struct futex_lock *fl, cloudabi_lock_t *address, cloudabi_tid_t tid, bool force_kernel_managed) { cloudabi_lock_t old, new, cmp; int error; if (fl->fl_owner == tid) { /* Attempted to acquire lock recursively. */ return (EDEADLK); } if (fl->fl_owner != LOCK_UNMANAGED) { /* Lock is already acquired. */ return (EBUSY); } old = CLOUDABI_LOCK_UNLOCKED; for (;;) { if ((old & CLOUDABI_LOCK_KERNEL_MANAGED) != 0) { /* * Userspace lock is kernel-managed, even though * the kernel disagrees. */ return (EINVAL); } if (old == (tid | CLOUDABI_LOCK_WRLOCKED)) { /* Attempted to acquire lock recursively. */ return (EDEADLK); } if (old == CLOUDABI_LOCK_UNLOCKED) { /* Lock is unlocked. Attempt to acquire it. */ new = tid | CLOUDABI_LOCK_WRLOCKED; if (force_kernel_managed) new |= CLOUDABI_LOCK_KERNEL_MANAGED; error = futex_user_cmpxchg(address, CLOUDABI_LOCK_UNLOCKED, &old, new); if (error != 0) return (error); if (old == CLOUDABI_LOCK_UNLOCKED) { /* Success. */ if (force_kernel_managed) fl->fl_owner = tid; return (0); } } else { /* Lock is still locked. Make it kernel-managed. */ cmp = old; error = futex_user_cmpxchg(address, cmp, &old, cmp | CLOUDABI_LOCK_KERNEL_MANAGED); if (error != 0) return (error); if (old == cmp) { /* Success. */ futex_lock_set_owner(fl, cmp); return (EBUSY); } } } } static int futex_lock_wake_up_next(struct futex_lock *fl, cloudabi_lock_t *lock) { cloudabi_tid_t tid; int error; /* * Determine which thread(s) to wake up. Prefer waking up * writers over readers to prevent write starvation. */ if (futex_queue_count(&fl->fl_writers) > 0) { /* Transfer ownership to a single write-locker. */ if (futex_queue_count(&fl->fl_writers) > 1 || futex_queue_count(&fl->fl_readers) > 0) { /* Lock should remain managed afterwards. */ tid = futex_queue_tid_best(&fl->fl_writers); error = futex_user_store(lock, tid | CLOUDABI_LOCK_WRLOCKED | CLOUDABI_LOCK_KERNEL_MANAGED); if (error != 0) return (error); futex_queue_wake_up_best(&fl->fl_writers); fl->fl_owner = tid; } else { /* Lock can become unmanaged afterwards. */ error = futex_user_store(lock, futex_queue_tid_best(&fl->fl_writers) | CLOUDABI_LOCK_WRLOCKED); if (error != 0) return (error); futex_queue_wake_up_best(&fl->fl_writers); fl->fl_owner = LOCK_UNMANAGED; } } else { /* Transfer ownership to all read-lockers (if any). */ error = futex_user_store(lock, futex_queue_count(&fl->fl_readers)); if (error != 0) return (error); /* Wake up all threads. */ futex_queue_wake_up_all(&fl->fl_readers); fl->fl_owner = LOCK_UNMANAGED; } return (0); } static int futex_lock_wrlock(struct futex_lock *fl, struct thread *td, cloudabi_lock_t *lock, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision, struct futex_queue *donated) { struct futex_waiter fw; int error; error = futex_lock_trywrlock(fl, lock, td->td_tid, futex_queue_count(donated) > 0); if (error == 0 || error == EBUSY) { /* Put donated threads in queue before suspending. */ KASSERT(futex_queue_count(donated) == 0 || fl->fl_owner != LOCK_UNMANAGED, ("Lock should be managed if we are going to donate")); futex_queue_requeue(donated, &fl->fl_writers, UINT_MAX); } else { /* * This thread cannot deal with the donated threads. * Wake up the next thread and let it try it by itself. */ futex_queue_wake_up_donate(donated, UINT_MAX); } if (error == EBUSY) { /* Suspend execution if the lock was busy. */ KASSERT(fl->fl_owner != LOCK_UNMANAGED, ("Attempted to sleep on an unmanaged lock")); error = futex_queue_sleep(&fl->fl_writers, fl, &fw, td, clock_id, timeout, precision); KASSERT((error == 0) == fw.fw_locked, ("Should have locked write lock on success")); KASSERT(futex_queue_count(&fw.fw_donated) == 0, ("Lock functions cannot receive threads")); } if (error != 0) futex_lock_unmanage(fl, lock); return (error); } /* * futex_queue operations. */ static cloudabi_tid_t futex_queue_tid_best(const struct futex_queue *fq) { return (STAILQ_FIRST(&fq->fq_list)->fw_tid); } static unsigned int futex_queue_count(const struct futex_queue *fq) { return (fq->fq_count); } static void futex_queue_init(struct futex_queue *fq) { STAILQ_INIT(&fq->fq_list); fq->fq_count = 0; } /* Converts a relative timestamp to an sbintime. */ static sbintime_t futex_queue_convert_timestamp_relative(cloudabi_timestamp_t ts) { cloudabi_timestamp_t s, ns; s = ts / 1000000000; ns = ts % 1000000000; if (s > INT32_MAX) return (INT64_MAX); return ((s << 32) + (ns << 32) / 1000000000); } /* Converts an absolute timestamp and precision to a pair of sbintime values. */ static int futex_queue_convert_timestamp(struct thread *td, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision, sbintime_t *sbttimeout, sbintime_t *sbtprecision) { cloudabi_timestamp_t now; int error; /* Make the time relative. */ error = cloudabi_clock_time_get(td, clock_id, &now); if (error != 0) return (error); timeout = timeout < now ? 0 : timeout - now; *sbttimeout = futex_queue_convert_timestamp_relative(timeout); *sbtprecision = futex_queue_convert_timestamp_relative(precision); return (0); } static int futex_queue_sleep(struct futex_queue *fq, struct futex_lock *fl, struct futex_waiter *fw, struct thread *td, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision) { sbintime_t sbttimeout, sbtprecision; int error; /* Initialize futex_waiter object. */ fw->fw_tid = td->td_tid; fw->fw_locked = false; futex_queue_init(&fw->fw_donated); if (timeout != UINT64_MAX) { /* Convert timeout duration. */ error = futex_queue_convert_timestamp(td, clock_id, timeout, precision, &sbttimeout, &sbtprecision); if (error != 0) return (error); } /* Place object in the queue. */ fw->fw_queue = fq; STAILQ_INSERT_TAIL(&fq->fq_list, fw, fw_next); ++fq->fq_count; cv_init(&fw->fw_wait, "futex"); ++fl->fl_waitcount; futex_lock_assert(fl); if (timeout == UINT64_MAX) { /* Wait without a timeout. */ error = cv_wait_sig(&fw->fw_wait, &futex_global_lock); } else { /* Wait respecting the timeout. */ error = cv_timedwait_sig_sbt(&fw->fw_wait, &futex_global_lock, sbttimeout, sbtprecision, 0); futex_lock_assert(fl); if (error == EWOULDBLOCK && fw->fw_queue != NULL && fw->fw_queue != fq) { /* * We got signalled on a condition variable, but * observed a timeout while waiting to reacquire * the lock. In other words, we didn't actually * time out. Go back to sleep and wait for the * lock to be reacquired. */ error = cv_wait_sig(&fw->fw_wait, &futex_global_lock); } } futex_lock_assert(fl); --fl->fl_waitcount; cv_destroy(&fw->fw_wait); fq = fw->fw_queue; if (fq == NULL) { /* Thread got dequeued, so we've slept successfully. */ return (0); } /* Thread is still enqueued. Remove it. */ KASSERT(error != 0, ("Woken up thread is still enqueued")); STAILQ_REMOVE(&fq->fq_list, fw, futex_waiter, fw_next); --fq->fq_count; return (error == EWOULDBLOCK ? ETIMEDOUT : error); } /* Moves up to nwaiters waiters from one queue to another. */ static void futex_queue_requeue(struct futex_queue *fqfrom, struct futex_queue *fqto, unsigned int nwaiters) { struct futex_waiter *fw; /* Move waiters to the target queue. */ while (nwaiters-- > 0 && !STAILQ_EMPTY(&fqfrom->fq_list)) { fw = STAILQ_FIRST(&fqfrom->fq_list); STAILQ_REMOVE_HEAD(&fqfrom->fq_list, fw_next); --fqfrom->fq_count; fw->fw_queue = fqto; STAILQ_INSERT_TAIL(&fqto->fq_list, fw, fw_next); ++fqto->fq_count; } } /* Wakes up all waiters in a queue. */ static void futex_queue_wake_up_all(struct futex_queue *fq) { struct futex_waiter *fw; STAILQ_FOREACH(fw, &fq->fq_list, fw_next) { fw->fw_locked = true; fw->fw_queue = NULL; cv_signal(&fw->fw_wait); } STAILQ_INIT(&fq->fq_list); fq->fq_count = 0; } /* * Wakes up the best waiter (i.e., the waiter having the highest * priority) in a queue. */ static void futex_queue_wake_up_best(struct futex_queue *fq) { struct futex_waiter *fw; fw = STAILQ_FIRST(&fq->fq_list); fw->fw_locked = true; fw->fw_queue = NULL; cv_signal(&fw->fw_wait); STAILQ_REMOVE_HEAD(&fq->fq_list, fw_next); --fq->fq_count; } static void futex_queue_wake_up_donate(struct futex_queue *fq, unsigned int nwaiters) { struct futex_waiter *fw; fw = STAILQ_FIRST(&fq->fq_list); if (fw == NULL) return; fw->fw_locked = false; fw->fw_queue = NULL; cv_signal(&fw->fw_wait); STAILQ_REMOVE_HEAD(&fq->fq_list, fw_next); --fq->fq_count; futex_queue_requeue(fq, &fw->fw_donated, nwaiters); } /* * futex_user operations. Used to adjust values in userspace. */ static int futex_user_load(uint32_t *obj, uint32_t *val) { return (fueword32(obj, val) != 0 ? EFAULT : 0); } static int futex_user_store(uint32_t *obj, uint32_t val) { return (suword32(obj, val) != 0 ? EFAULT : 0); } static int futex_user_cmpxchg(uint32_t *obj, uint32_t cmp, uint32_t *old, uint32_t new) { return (casueword32(obj, cmp, old, new) != 0 ? EFAULT : 0); } /* * Blocking calls: acquiring locks, waiting on condition variables. */ int cloudabi_futex_condvar_wait(struct thread *td, cloudabi_condvar_t *condvar, cloudabi_mflags_t condvar_scope, cloudabi_lock_t *lock, cloudabi_mflags_t lock_scope, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision) { struct futex_condvar *fc; struct futex_lock *fl; struct futex_waiter fw; int error, error2; /* Lookup condition variable object. */ error = futex_condvar_lookup_or_create(td, condvar, condvar_scope, lock, lock_scope, &fc); if (error != 0) return (error); fl = fc->fc_lock; /* * Set the condition variable to something other than * CLOUDABI_CONDVAR_HAS_NO_WAITERS to make userspace threads * call into the kernel to perform wakeups. */ error = futex_user_store(condvar, ~CLOUDABI_CONDVAR_HAS_NO_WAITERS); if (error != 0) { futex_condvar_release(fc); return (error); } /* Drop the lock. */ error = futex_lock_unlock(fl, td, lock); if (error != 0) { futex_condvar_unmanage(fc, condvar); futex_condvar_release(fc); return (error); } /* Go to sleep. */ ++fc->fc_waitcount; error = futex_queue_sleep(&fc->fc_waiters, fc->fc_lock, &fw, td, clock_id, timeout, precision); if (fw.fw_locked) { /* Waited and got the lock assigned to us. */ KASSERT(futex_queue_count(&fw.fw_donated) == 0, ("Received threads while being locked")); } else if (error == 0 || error == ETIMEDOUT) { if (error != 0) futex_condvar_unmanage(fc, condvar); /* * Got woken up without having the lock assigned to us. * This can happen in two cases: * * 1. We observed a timeout on a condition variable. * 2. We got signalled on a condition variable while the * associated lock is unlocked. We are the first * thread that gets woken up. This thread is * responsible for reacquiring the userspace lock. */ error2 = futex_lock_wrlock(fl, td, lock, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0, &fw.fw_donated); if (error2 != 0) error = error2; } else { KASSERT(futex_queue_count(&fw.fw_donated) == 0, ("Received threads on error")); futex_condvar_unmanage(fc, condvar); futex_lock_unmanage(fl, lock); } --fc->fc_waitcount; futex_condvar_release(fc); return (error); } int cloudabi_futex_lock_rdlock(struct thread *td, cloudabi_lock_t *lock, cloudabi_mflags_t scope, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision) { struct futex_lock *fl; int error; /* Look up lock object. */ error = futex_lock_lookup(td, lock, scope, &fl); if (error != 0) return (error); error = futex_lock_rdlock(fl, td, lock, clock_id, timeout, precision); futex_lock_release(fl); return (error); } int cloudabi_futex_lock_wrlock(struct thread *td, cloudabi_lock_t *lock, cloudabi_mflags_t scope, cloudabi_clockid_t clock_id, cloudabi_timestamp_t timeout, cloudabi_timestamp_t precision) { struct futex_lock *fl; struct futex_queue fq; int error; /* Look up lock object. */ error = futex_lock_lookup(td, lock, scope, &fl); if (error != 0) return (error); futex_queue_init(&fq); error = futex_lock_wrlock(fl, td, lock, clock_id, timeout, precision, &fq); futex_lock_release(fl); return (error); } /* * Non-blocking calls: releasing locks, signalling condition variables. */ int cloudabi_sys_condvar_signal(struct thread *td, struct cloudabi_sys_condvar_signal_args *uap) { struct futex_condvar *fc; struct futex_lock *fl; cloudabi_nthreads_t nwaiters; int error; nwaiters = uap->nwaiters; if (nwaiters == 0) { /* No threads to wake up. */ return (0); } /* Look up futex object. */ error = futex_condvar_lookup(td, uap->condvar, uap->scope, &fc); if (error != 0) { /* Race condition: condition variable with no waiters. */ return (error == ENOENT ? 0 : error); } fl = fc->fc_lock; if (fl->fl_owner == LOCK_UNMANAGED) { /* * The lock is currently not managed by the kernel, * meaning we must attempt to acquire the userspace lock * first. We cannot requeue threads to an unmanaged lock, * as these threads will then never be scheduled. * * Unfortunately, the memory address of the lock is * unknown from this context, meaning that we cannot * acquire the lock on behalf of the first thread to be * scheduled. The lock may even not be mapped within the * address space of the current thread. * * To solve this, wake up a single waiter that will * attempt to acquire the lock. Donate all of the other * waiters that need to be woken up to this waiter, so * it can requeue them after acquiring the lock. */ futex_queue_wake_up_donate(&fc->fc_waiters, nwaiters - 1); } else { /* * Lock is already managed by the kernel. This makes it * easy, as we can requeue the threads from the * condition variable directly to the associated lock. */ futex_queue_requeue(&fc->fc_waiters, &fl->fl_writers, nwaiters); } /* Clear userspace condition variable if all waiters are gone. */ error = futex_condvar_unmanage(fc, uap->condvar); futex_condvar_release(fc); return (error); } int cloudabi_sys_lock_unlock(struct thread *td, struct cloudabi_sys_lock_unlock_args *uap) { struct futex_lock *fl; int error; error = futex_lock_lookup(td, uap->lock, uap->scope, &fl); if (error != 0) return (error); error = futex_lock_unlock(fl, td, uap->lock); futex_lock_release(fl); return (error); } Index: head/sys/compat/cloudabi/cloudabi_mem.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_mem.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_mem.c (revision 297247) @@ -1,197 +1,198 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include +#include + #include -#include /* Converts CloudABI's memory protection flags to FreeBSD's. */ static int convert_mprot(cloudabi_mprot_t in, int *out) { /* Unknown protection flags. */ if ((in & ~(CLOUDABI_PROT_EXEC | CLOUDABI_PROT_WRITE | CLOUDABI_PROT_READ)) != 0) return (ENOTSUP); /* W^X: Write and exec cannot be enabled at the same time. */ if ((in & (CLOUDABI_PROT_EXEC | CLOUDABI_PROT_WRITE)) == (CLOUDABI_PROT_EXEC | CLOUDABI_PROT_WRITE)) return (ENOTSUP); *out = 0; if (in & CLOUDABI_PROT_EXEC) *out |= PROT_EXEC; if (in & CLOUDABI_PROT_WRITE) *out |= PROT_WRITE; if (in & CLOUDABI_PROT_READ) *out |= PROT_READ; return (0); } int cloudabi_sys_mem_advise(struct thread *td, struct cloudabi_sys_mem_advise_args *uap) { struct madvise_args madvise_args = { .addr = uap->addr, .len = uap->len }; switch (uap->advice) { case CLOUDABI_ADVICE_DONTNEED: madvise_args.behav = MADV_DONTNEED; break; case CLOUDABI_ADVICE_NORMAL: madvise_args.behav = MADV_NORMAL; break; case CLOUDABI_ADVICE_RANDOM: madvise_args.behav = MADV_RANDOM; break; case CLOUDABI_ADVICE_SEQUENTIAL: madvise_args.behav = MADV_SEQUENTIAL; break; case CLOUDABI_ADVICE_WILLNEED: madvise_args.behav = MADV_WILLNEED; break; default: return (EINVAL); } return (sys_madvise(td, &madvise_args)); } int cloudabi_sys_mem_lock(struct thread *td, struct cloudabi_sys_mem_lock_args *uap) { struct mlock_args mlock_args = { .addr = uap->addr, .len = uap->len }; return (sys_mlock(td, &mlock_args)); } int cloudabi_sys_mem_map(struct thread *td, struct cloudabi_sys_mem_map_args *uap) { struct mmap_args mmap_args = { .addr = uap->addr, .len = uap->len, .fd = uap->fd, .pos = uap->off }; int error; /* Translate flags. */ if (uap->flags & CLOUDABI_MAP_ANON) mmap_args.flags |= MAP_ANON; if (uap->flags & CLOUDABI_MAP_FIXED) mmap_args.flags |= MAP_FIXED; if (uap->flags & CLOUDABI_MAP_PRIVATE) mmap_args.flags |= MAP_PRIVATE; if (uap->flags & CLOUDABI_MAP_SHARED) mmap_args.flags |= MAP_SHARED; /* Translate protection. */ error = convert_mprot(uap->prot, &mmap_args.prot); if (error != 0) return (error); return (sys_mmap(td, &mmap_args)); } int cloudabi_sys_mem_protect(struct thread *td, struct cloudabi_sys_mem_protect_args *uap) { struct mprotect_args mprotect_args = { .addr = uap->addr, .len = uap->len, }; int error; /* Translate protection. */ error = convert_mprot(uap->prot, &mprotect_args.prot); if (error != 0) return (error); return (sys_mprotect(td, &mprotect_args)); } int cloudabi_sys_mem_sync(struct thread *td, struct cloudabi_sys_mem_sync_args *uap) { struct msync_args msync_args = { .addr = uap->addr, .len = uap->len, }; /* Convert flags. */ switch (uap->flags & (CLOUDABI_MS_ASYNC | CLOUDABI_MS_SYNC)) { case CLOUDABI_MS_ASYNC: msync_args.flags |= MS_ASYNC; break; case CLOUDABI_MS_SYNC: msync_args.flags |= MS_SYNC; break; default: return (EINVAL); } if ((uap->flags & CLOUDABI_MS_INVALIDATE) != 0) msync_args.flags |= MS_INVALIDATE; return (sys_msync(td, &msync_args)); } int cloudabi_sys_mem_unlock(struct thread *td, struct cloudabi_sys_mem_unlock_args *uap) { struct munlock_args munlock_args = { .addr = uap->addr, .len = uap->len }; return (sys_munlock(td, &munlock_args)); } int cloudabi_sys_mem_unmap(struct thread *td, struct cloudabi_sys_mem_unmap_args *uap) { struct munmap_args munmap_args = { .addr = uap->addr, .len = uap->len }; return (sys_munmap(td, &munmap_args)); } Index: head/sys/compat/cloudabi/cloudabi_proc.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_proc.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_proc.c (revision 297247) @@ -1,147 +1,148 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include +#include + #include -#include int cloudabi_sys_proc_exec(struct thread *td, struct cloudabi_sys_proc_exec_args *uap) { struct image_args args; struct vmspace *oldvmspace; int error; error = pre_execve(td, &oldvmspace); if (error != 0) return (error); error = exec_copyin_data_fds(td, &args, uap->data, uap->datalen, uap->fds, uap->fdslen); if (error == 0) { args.fd = uap->fd; error = kern_execve(td, &args, NULL); } post_execve(td, error, oldvmspace); return (error); } int cloudabi_sys_proc_exit(struct thread *td, struct cloudabi_sys_proc_exit_args *uap) { exit1(td, uap->rval, 0); /* NOTREACHED */ } int cloudabi_sys_proc_fork(struct thread *td, struct cloudabi_sys_proc_fork_args *uap) { struct fork_req fr; struct filecaps fcaps = {}; int error, fd; cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_EVENT); bzero(&fr, sizeof(fr)); fr.fr_flags = RFFDG | RFPROC | RFPROCDESC; fr.fr_pd_fd = &fd; fr.fr_pd_fcaps = &fcaps; error = fork1(td, &fr); if (error != 0) return (error); /* Return the file descriptor to the parent process. */ td->td_retval[0] = fd; return (0); } int cloudabi_sys_proc_raise(struct thread *td, struct cloudabi_sys_proc_raise_args *uap) { static const int signals[] = { [CLOUDABI_SIGABRT] = SIGABRT, [CLOUDABI_SIGALRM] = SIGALRM, [CLOUDABI_SIGBUS] = SIGBUS, [CLOUDABI_SIGCHLD] = SIGCHLD, [CLOUDABI_SIGCONT] = SIGCONT, [CLOUDABI_SIGFPE] = SIGFPE, [CLOUDABI_SIGHUP] = SIGHUP, [CLOUDABI_SIGILL] = SIGILL, [CLOUDABI_SIGINT] = SIGINT, [CLOUDABI_SIGKILL] = SIGKILL, [CLOUDABI_SIGPIPE] = SIGPIPE, [CLOUDABI_SIGQUIT] = SIGQUIT, [CLOUDABI_SIGSEGV] = SIGSEGV, [CLOUDABI_SIGSTOP] = SIGSTOP, [CLOUDABI_SIGSYS] = SIGSYS, [CLOUDABI_SIGTERM] = SIGTERM, [CLOUDABI_SIGTRAP] = SIGTRAP, [CLOUDABI_SIGTSTP] = SIGTSTP, [CLOUDABI_SIGTTIN] = SIGTTIN, [CLOUDABI_SIGTTOU] = SIGTTOU, [CLOUDABI_SIGURG] = SIGURG, [CLOUDABI_SIGUSR1] = SIGUSR1, [CLOUDABI_SIGUSR2] = SIGUSR2, [CLOUDABI_SIGVTALRM] = SIGVTALRM, [CLOUDABI_SIGXCPU] = SIGXCPU, [CLOUDABI_SIGXFSZ] = SIGXFSZ, }; ksiginfo_t ksi; struct proc *p; if (uap->sig >= nitems(signals) || signals[uap->sig] == 0) { /* Invalid signal, or the null signal. */ return (uap->sig == 0 ? 0 : EINVAL); } p = td->td_proc; ksiginfo_init(&ksi); ksi.ksi_signo = signals[uap->sig]; ksi.ksi_code = SI_USER; ksi.ksi_pid = p->p_pid; ksi.ksi_uid = td->td_ucred->cr_ruid; PROC_LOCK(p); pksignal(p, ksi.ksi_signo, &ksi); PROC_UNLOCK(p); return (0); } MODULE_VERSION(cloudabi, 1); Index: head/sys/compat/cloudabi/cloudabi_proto.h =================================================================== --- head/sys/compat/cloudabi/cloudabi_proto.h (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_proto.h (revision 297247) @@ -1,34 +1,36 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ /* * This should provide all prototypes for the machine-independent system * calls. Unfortunately, we don't have a separate system call table for * those, so rely on the system call table from COMPAT_CLOUDABI64. */ -#include + +#include + #include Index: head/sys/compat/cloudabi/cloudabi_sock.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_sock.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_sock.c (revision 297247) @@ -1,250 +1,252 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include + #include -#include #include /* Converts FreeBSD's struct sockaddr to CloudABI's cloudabi_sockaddr_t. */ void cloudabi_convert_sockaddr(const struct sockaddr *sa, socklen_t sal, cloudabi_sockaddr_t *rsa) { const struct sockaddr_in *sin; const struct sockaddr_in6 *sin6; /* Zero-sized socket address. */ if (sal < offsetof(struct sockaddr, sa_family) + sizeof(sa->sa_family)) return; switch (sa->sa_family) { case AF_INET: if (sal < sizeof(struct sockaddr_in)) return; sin = (const struct sockaddr_in *)sa; rsa->sa_family = CLOUDABI_AF_INET; memcpy(&rsa->sa_inet.addr, &sin->sin_addr, sizeof(rsa->sa_inet.addr)); rsa->sa_inet.port = ntohs(sin->sin_port); return; case AF_INET6: if (sal < sizeof(struct sockaddr_in6)) return; sin6 = (const struct sockaddr_in6 *)sa; rsa->sa_family = CLOUDABI_AF_INET6; memcpy(&rsa->sa_inet6.addr, &sin6->sin6_addr, sizeof(rsa->sa_inet6.addr)); rsa->sa_inet6.port = ntohs(sin6->sin6_port); return; case AF_UNIX: rsa->sa_family = CLOUDABI_AF_UNIX; return; } } /* Copies a pathname into a UNIX socket address structure. */ static int copyin_sockaddr_un(const char *path, size_t pathlen, struct sockaddr_un *sun) { int error; /* Copy in pathname string if there's enough space. */ if (pathlen >= sizeof(sun->sun_path)) return (ENAMETOOLONG); error = copyin(path, &sun->sun_path, pathlen); if (error != 0) return (error); if (memchr(sun->sun_path, '\0', pathlen) != NULL) return (EINVAL); /* Initialize the rest of the socket address. */ sun->sun_path[pathlen] = '\0'; sun->sun_family = AF_UNIX; sun->sun_len = sizeof(*sun); return (0); } int cloudabi_sys_sock_accept(struct thread *td, struct cloudabi_sys_sock_accept_args *uap) { struct sockaddr *sa; cloudabi_sockstat_t ss = {}; socklen_t sal; int error; if (uap->buf == NULL) { /* Only return the new file descriptor number. */ - return (kern_accept(td, uap->s, NULL, NULL, NULL)); + return (kern_accept(td, uap->sock, NULL, NULL, NULL)); } else { /* Also return properties of the new socket descriptor. */ sal = MAX(sizeof(struct sockaddr_in), sizeof(struct sockaddr_in6)); - error = kern_accept(td, uap->s, (void *)&sa, &sal, NULL); + error = kern_accept(td, uap->sock, (void *)&sa, &sal, NULL); if (error != 0) return (error); /* TODO(ed): Fill the other members of cloudabi_sockstat_t. */ cloudabi_convert_sockaddr(sa, sal, &ss.ss_peername); free(sa, M_SONAME); return (copyout(&ss, uap->buf, sizeof(ss))); } } int cloudabi_sys_sock_bind(struct thread *td, struct cloudabi_sys_sock_bind_args *uap) { struct sockaddr_un sun; int error; error = copyin_sockaddr_un(uap->path, uap->pathlen, &sun); if (error != 0) return (error); - return (kern_bindat(td, uap->fd, uap->s, (struct sockaddr *)&sun)); + return (kern_bindat(td, uap->fd, uap->sock, (struct sockaddr *)&sun)); } int cloudabi_sys_sock_connect(struct thread *td, struct cloudabi_sys_sock_connect_args *uap) { struct sockaddr_un sun; int error; error = copyin_sockaddr_un(uap->path, uap->pathlen, &sun); if (error != 0) return (error); - return (kern_connectat(td, uap->fd, uap->s, (struct sockaddr *)&sun)); + return (kern_connectat(td, uap->fd, uap->sock, + (struct sockaddr *)&sun)); } int cloudabi_sys_sock_listen(struct thread *td, struct cloudabi_sys_sock_listen_args *uap) { struct listen_args listen_args = { - .s = uap->s, + .s = uap->sock, .backlog = uap->backlog, }; return (sys_listen(td, &listen_args)); } int cloudabi_sys_sock_shutdown(struct thread *td, struct cloudabi_sys_sock_shutdown_args *uap) { struct shutdown_args shutdown_args = { - .s = uap->fd, + .s = uap->sock, }; switch (uap->how) { case CLOUDABI_SHUT_RD: shutdown_args.how = SHUT_RD; break; case CLOUDABI_SHUT_WR: shutdown_args.how = SHUT_WR; break; case CLOUDABI_SHUT_RD | CLOUDABI_SHUT_WR: shutdown_args.how = SHUT_RDWR; break; default: return (EINVAL); } return (sys_shutdown(td, &shutdown_args)); } int cloudabi_sys_sock_stat_get(struct thread *td, struct cloudabi_sys_sock_stat_get_args *uap) { cloudabi_sockstat_t ss = {}; cap_rights_t rights; struct file *fp; struct sockaddr *sa; struct socket *so; int error; - error = getsock_cap(td, uap->fd, cap_rights_init(&rights, + error = getsock_cap(td, uap->sock, cap_rights_init(&rights, CAP_GETSOCKOPT, CAP_GETPEERNAME, CAP_GETSOCKNAME), &fp, NULL); if (error != 0) return (error); so = fp->f_data; CURVNET_SET(so->so_vnet); /* Set ss_sockname. */ error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa); if (error == 0) { cloudabi_convert_sockaddr(sa, sa->sa_len, &ss.ss_sockname); free(sa, M_SONAME); } /* Set ss_peername. */ if ((so->so_state & (SS_ISCONNECTED | SS_ISCONFIRMING)) != 0) { error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa); if (error == 0) { cloudabi_convert_sockaddr(sa, sa->sa_len, &ss.ss_peername); free(sa, M_SONAME); } } CURVNET_RESTORE(); /* Set ss_error. */ SOCK_LOCK(so); ss.ss_error = cloudabi_convert_errno(so->so_error); if ((uap->flags & CLOUDABI_SOCKSTAT_CLEAR_ERROR) != 0) so->so_error = 0; SOCK_UNLOCK(so); /* Set ss_state. */ if ((so->so_options & SO_ACCEPTCONN) != 0) - ss.ss_state |= CLOUDABI_SOCKSTAT_ACCEPTCONN; + ss.ss_state |= CLOUDABI_SOCKSTATE_ACCEPTCONN; fdrop(fp, td); return (copyout(&ss, uap->buf, sizeof(ss))); } Index: head/sys/compat/cloudabi/cloudabi_thread.c =================================================================== --- head/sys/compat/cloudabi/cloudabi_thread.c (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_thread.c (revision 297247) @@ -1,73 +1,74 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include +#include + #include -#include int cloudabi_sys_thread_exit(struct thread *td, struct cloudabi_sys_thread_exit_args *uap) { struct cloudabi_sys_lock_unlock_args cloudabi_sys_lock_unlock_args = { .lock = uap->lock, .scope = uap->scope, }; /* Wake up joining thread. */ cloudabi_sys_lock_unlock(td, &cloudabi_sys_lock_unlock_args); /* * Attempt to terminate the thread. Terminate the process if * it's the last thread. */ kern_thr_exit(td); exit1(td, 0, 0); /* NOTREACHED */ } int cloudabi_sys_thread_tcb_set(struct thread *td, struct cloudabi_sys_thread_tcb_set_args *uap) { return (cpu_set_user_tls(td, uap->tcb)); } int cloudabi_sys_thread_yield(struct thread *td, struct cloudabi_sys_thread_yield_args *uap) { sched_relinquish(td); return (0); } Index: head/sys/compat/cloudabi/cloudabi_util.h =================================================================== --- head/sys/compat/cloudabi/cloudabi_util.h (revision 297246) +++ head/sys/compat/cloudabi/cloudabi_util.h (revision 297247) @@ -1,79 +1,79 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _CLOUDABI_UTIL_H_ #define _CLOUDABI_UTIL_H_ #include -#include +#include struct file; struct thread; struct timespec; /* Fetches the time value of a clock. */ int cloudabi_clock_time_get(struct thread *, cloudabi_clockid_t, cloudabi_timestamp_t *); /* Converts a FreeBSD errno to a CloudABI errno. */ cloudabi_errno_t cloudabi_convert_errno(int); /* Converts FreeBSD's struct sockaddr to CloudABI's cloudabi_sockaddr_t. */ void cloudabi_convert_sockaddr(const struct sockaddr *, socklen_t, cloudabi_sockaddr_t *); /* Converts a file descriptor to a CloudABI file descriptor type. */ cloudabi_filetype_t cloudabi_convert_filetype(const struct file *); /* Converts CloudABI rights to a set of Capsicum capabilities. */ int cloudabi_convert_rights(cloudabi_rights_t, cap_rights_t *); /* Removes rights that conflict with the file descriptor type. */ void cloudabi_remove_conflicting_rights(cloudabi_filetype_t, cloudabi_rights_t *, cloudabi_rights_t *); /* Converts a struct timespec to a CloudABI timestamp. */ int cloudabi_convert_timespec(const struct timespec *, cloudabi_timestamp_t *); /* * Blocking futex functions. * * These functions are called by CloudABI's polling system calls to * sleep on a lock or condition variable. */ int cloudabi_futex_condvar_wait(struct thread *, cloudabi_condvar_t *, cloudabi_mflags_t, cloudabi_lock_t *, cloudabi_mflags_t, cloudabi_clockid_t, cloudabi_timestamp_t, cloudabi_timestamp_t); int cloudabi_futex_lock_rdlock(struct thread *, cloudabi_lock_t *, cloudabi_mflags_t, cloudabi_clockid_t, cloudabi_timestamp_t, cloudabi_timestamp_t); int cloudabi_futex_lock_wrlock(struct thread *, cloudabi_lock_t *, cloudabi_mflags_t, cloudabi_clockid_t, cloudabi_timestamp_t, cloudabi_timestamp_t); #endif Index: head/sys/compat/cloudabi64/cloudabi64_syscalldefs.h =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_syscalldefs.h (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_syscalldefs.h (nonexistent) @@ -1,45 +0,0 @@ -/*- - * Copyright (c) 2015 Nuxi, https://nuxi.nl/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _CLOUDABI64_SYSCALLDEFS_H_ -#define _CLOUDABI64_SYSCALLDEFS_H_ - -#include - -#include - -typedef uint64_t cloudabi64_size_t; -typedef uint64_t cloudabi64_uintptr_t; - -/* Import machine-dependent CloudABI definitions for 64-bit systems. */ -#define IDENT(ident) cloudabi64_##ident -#define PTR(type) cloudabi64_uintptr_t -#include -#undef IDENT -#undef PTR - -#endif Property changes on: head/sys/compat/cloudabi64/cloudabi64_syscalldefs.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/sys/compat/cloudabi64/syscalls.master =================================================================== --- head/sys/compat/cloudabi64/syscalls.master (revision 297246) +++ head/sys/compat/cloudabi64/syscalls.master (nonexistent) @@ -1,220 +0,0 @@ - $FreeBSD$ - -; System call table for CloudABI. -; -; All system calls that do not use any machine-dependent data types are -; prefixed with cloudabi_sys_. The others are called cloudabi64_sys_. - -#include -#include - -#include -#include - -0 AUE_NULL STD { cloudabi_timestamp_t \ - cloudabi_sys_clock_res_get( \ - cloudabi_clockid_t clock_id); } -1 AUE_NULL STD { cloudabi_timestamp_t \ - cloudabi_sys_clock_time_get( \ - cloudabi_clockid_t clock_id, \ - cloudabi_timestamp_t precision); } - -2 AUE_NULL STD { void cloudabi_sys_condvar_signal( \ - cloudabi_condvar_t *condvar, \ - cloudabi_mflags_t scope, \ - cloudabi_nthreads_t nwaiters); } - -3 AUE_NULL STD { void cloudabi_sys_fd_close( \ - cloudabi_fd_t fd); } -4 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_fd_create1( \ - cloudabi_filetype_t type); } -5 AUE_NULL STD { void cloudabi_sys_fd_create2( \ - cloudabi_filetype_t type); } -6 AUE_NULL STD { void cloudabi_sys_fd_datasync( \ - cloudabi_fd_t fd); } -7 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_fd_dup( \ - cloudabi_fd_t from); } -8 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_fd_pread( \ - cloudabi_fd_t fd, \ - const cloudabi64_iovec_t *iov, \ - cloudabi64_size_t iovcnt, \ - cloudabi_filesize_t offset); } -9 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_fd_pwrite( \ - cloudabi_fd_t fd, \ - const cloudabi64_ciovec_t *iov, \ - cloudabi64_size_t iovcnt, \ - cloudabi_filesize_t offset); } -10 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_fd_read( \ - cloudabi_fd_t fd, \ - const cloudabi64_iovec_t *iov, \ - cloudabi64_size_t iovcnt); } -11 AUE_NULL STD { void cloudabi_sys_fd_replace( \ - cloudabi_fd_t from, \ - cloudabi_fd_t to); } -12 AUE_NULL STD { cloudabi_filesize_t cloudabi_sys_fd_seek( \ - cloudabi_fd_t fd, \ - cloudabi_filedelta_t offset, \ - cloudabi_whence_t whence); } -13 AUE_NULL STD { void cloudabi_sys_fd_stat_get( \ - cloudabi_fd_t fd, \ - cloudabi_fdstat_t *buf); } -14 AUE_NULL STD { void cloudabi_sys_fd_stat_put( \ - cloudabi_fd_t fd, \ - const cloudabi_fdstat_t *buf, \ - cloudabi_fdsflags_t flags); } -15 AUE_NULL STD { void cloudabi_sys_fd_sync( \ - cloudabi_fd_t fd); } -16 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_fd_write( \ - cloudabi_fd_t fd, \ - const cloudabi64_ciovec_t *iov, \ - cloudabi64_size_t iovcnt); } - -17 AUE_NULL STD { void cloudabi_sys_file_advise( \ - cloudabi_fd_t fd, \ - cloudabi_filesize_t offset, \ - cloudabi_filesize_t len, \ - cloudabi_advice_t advice); } -18 AUE_NULL STD { void cloudabi_sys_file_allocate( \ - cloudabi_fd_t fd, \ - cloudabi_filesize_t offset, \ - cloudabi_filesize_t len); } -19 AUE_NULL STD { void cloudabi_sys_file_create( \ - cloudabi_fd_t fd, \ - const char *path, size_t pathlen, \ - cloudabi_filetype_t type); } -20 AUE_NULL STD { void cloudabi_sys_file_link( \ - cloudabi_lookup_t fd1, \ - const char *path1, size_t path1len, \ - cloudabi_fd_t fd2, \ - const char *path2, size_t path2len); } -21 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_file_open( \ - cloudabi_lookup_t fd, \ - const char *path, size_t pathlen, \ - cloudabi_oflags_t oflags, \ - const cloudabi_fdstat_t *fds); } -22 AUE_NULL STD { size_t cloudabi_sys_file_readdir( \ - cloudabi_fd_t fd, \ - void *buf, size_t nbyte, \ - cloudabi_dircookie_t cookie); } -23 AUE_NULL STD { size_t cloudabi_sys_file_readlink( \ - cloudabi_fd_t fd, \ - const char *path, size_t pathlen, \ - void *buf, size_t bufsize); } -24 AUE_NULL STD { void cloudabi_sys_file_rename( \ - cloudabi_fd_t oldfd, \ - const char *old, size_t oldlen, \ - cloudabi_fd_t newfd, \ - const char *new, size_t newlen); } -25 AUE_NULL STD { void cloudabi_sys_file_stat_fget( \ - cloudabi_fd_t fd, \ - cloudabi_filestat_t *buf); } -26 AUE_NULL STD { void cloudabi_sys_file_stat_fput( \ - cloudabi_fd_t fd, \ - const cloudabi_filestat_t *buf, \ - cloudabi_fsflags_t flags); } -27 AUE_NULL STD { void cloudabi_sys_file_stat_get( \ - cloudabi_lookup_t fd, \ - const char *path, size_t pathlen, \ - cloudabi_filestat_t *buf); } -28 AUE_NULL STD { void cloudabi_sys_file_stat_put( \ - cloudabi_lookup_t fd, \ - const char *path, size_t pathlen, \ - const cloudabi_filestat_t *buf, \ - cloudabi_fsflags_t flags); } -29 AUE_NULL STD { void cloudabi_sys_file_symlink( \ - const char *path1, size_t path1len, \ - cloudabi_fd_t fd, \ - const char *path2, size_t path2len); } -30 AUE_NULL STD { void cloudabi_sys_file_unlink( \ - cloudabi_fd_t fd, \ - const char *path, size_t pathlen, \ - cloudabi_ulflags_t flag); } - -31 AUE_NULL STD { void cloudabi_sys_lock_unlock( \ - cloudabi_lock_t *lock, \ - cloudabi_mflags_t scope); } - -32 AUE_NULL STD { void cloudabi_sys_mem_advise( \ - void *addr, size_t len, \ - cloudabi_advice_t advice); } -33 AUE_NULL STD { void cloudabi_sys_mem_lock( \ - const void *addr, size_t len); } -34 AUE_NULL STD { void cloudabi_sys_mem_map( \ - void *addr, size_t len, \ - cloudabi_mprot_t prot, \ - cloudabi_mflags_t flags, \ - cloudabi_fd_t fd, \ - cloudabi_filesize_t off); } -35 AUE_NULL STD { void cloudabi_sys_mem_protect( \ - void *addr, size_t len, \ - cloudabi_mprot_t prot); } -36 AUE_NULL STD { void cloudabi_sys_mem_sync( \ - void *addr, size_t len, \ - cloudabi_msflags_t flags); } -37 AUE_NULL STD { void cloudabi_sys_mem_unlock( \ - const void *addr, size_t len); } -38 AUE_NULL STD { void cloudabi_sys_mem_unmap( \ - void * addr, size_t len); } - -39 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_poll( \ - const cloudabi64_subscription_t *in, \ - cloudabi64_event_t *out, \ - cloudabi64_size_t nevents); } - -40 AUE_NULL STD { void cloudabi_sys_proc_exec( \ - cloudabi_fd_t fd, const void *data, \ - size_t datalen, \ - const cloudabi_fd_t *fds, \ - size_t fdslen); } -41 AUE_NULL STD { void cloudabi_sys_proc_exit( \ - cloudabi_exitcode_t rval); } -42 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_proc_fork(); } -43 AUE_NULL STD { void cloudabi_sys_proc_raise( \ - cloudabi_signal_t sig); } - -44 AUE_NULL STD { void cloudabi_sys_random_get( \ - void *buf, size_t nbyte); } - -45 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_sock_accept( \ - cloudabi_fd_t s, \ - cloudabi_sockstat_t *buf); } -46 AUE_NULL STD { void cloudabi_sys_sock_bind( \ - cloudabi_fd_t s, cloudabi_fd_t fd, \ - const char *path, size_t pathlen); } -47 AUE_NULL STD { void cloudabi_sys_sock_connect( \ - cloudabi_fd_t s, cloudabi_fd_t fd, \ - const char *path, size_t pathlen); } -48 AUE_NULL STD { void cloudabi_sys_sock_listen( \ - cloudabi_fd_t s, \ - cloudabi_backlog_t backlog); } -49 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_sock_recv( \ - cloudabi_fd_t s, \ - const cloudabi64_recv_in_t *in, \ - cloudabi64_recv_out_t *out); } -50 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_sock_send( \ - cloudabi_fd_t s, \ - const cloudabi64_send_in_t *in, \ - cloudabi64_send_out_t *out); } -51 AUE_NULL STD { void cloudabi_sys_sock_shutdown( \ - cloudabi_fd_t fd, \ - cloudabi_sdflags_t how); } -52 AUE_NULL STD { void cloudabi_sys_sock_stat_get( \ - cloudabi_fd_t fd, \ - cloudabi_sockstat_t *buf, \ - cloudabi_ssflags_t flags); } - -53 AUE_NULL STD { cloudabi_tid_t cloudabi64_sys_thread_create( \ - cloudabi64_threadattr_t *attr); } -54 AUE_NULL STD { void cloudabi_sys_thread_exit( \ - cloudabi_lock_t *lock, \ - cloudabi_mflags_t scope); } -55 AUE_NULL STD { void cloudabi_sys_thread_tcb_set(void *tcb); } -56 AUE_NULL STD { void cloudabi_sys_thread_yield(); } - -57 AUE_NULL STD { cloudabi64_size_t cloudabi64_sys_poll_fd( \ - cloudabi_fd_t fd, \ - const cloudabi64_subscription_t *in, \ - cloudabi64_size_t nin, \ - cloudabi64_event_t *out, \ - cloudabi64_size_t nout, \ - const cloudabi64_subscription_t *timeout); } Property changes on: head/sys/compat/cloudabi64/syscalls.master ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: head/sys/compat/cloudabi64/Makefile =================================================================== --- head/sys/compat/cloudabi64/Makefile (revision 297246) +++ head/sys/compat/cloudabi64/Makefile (revision 297247) @@ -1,12 +1,14 @@ # $FreeBSD$ all: @echo "make sysent only" sysent: cloudabi64_sysent.c cloudabi64_syscall.h cloudabi64_proto.h \ cloudabi64_syscalls.c cloudabi64_systrace_args.c cloudabi64_sysent.c cloudabi64_syscall.h cloudabi64_proto.h \ cloudabi64_syscalls.c cloudabi64_systrace_args.c: \ - ../../kern/makesyscalls.sh syscalls.master syscalls.conf - sh ../../kern/makesyscalls.sh syscalls.master syscalls.conf + ../../kern/makesyscalls.sh ../../contrib/cloudabi/syscalls.master \ + syscalls.conf + sh ../../kern/makesyscalls.sh ../../contrib/cloudabi/syscalls.master \ + syscalls.conf Index: head/sys/compat/cloudabi64/cloudabi64_fd.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_fd.c (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_fd.c (revision 297247) @@ -1,145 +1,146 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include -#include +#include + #include /* Copies in 64-bit iovec structures from userspace. */ static int cloudabi64_copyinuio(const cloudabi64_iovec_t *iovp, size_t iovcnt, struct uio **uiop) { cloudabi64_iovec_t iovobj; struct uio *uio; struct iovec *iov; size_t i; int error; /* Allocate uio and iovecs. */ if (iovcnt > UIO_MAXIOV) return (EINVAL); uio = malloc(sizeof(struct uio) + iovcnt * sizeof(struct iovec), M_IOV, M_WAITOK); iov = (struct iovec *)(uio + 1); /* Initialize uio. */ uio->uio_iov = iov; uio->uio_iovcnt = iovcnt; uio->uio_segflg = UIO_USERSPACE; uio->uio_offset = -1; uio->uio_resid = 0; /* Copy in iovecs. */ for (i = 0; i < iovcnt; i++) { error = copyin(&iovp[i], &iovobj, sizeof(iovobj)); if (error != 0) { free(uio, M_IOV); return (error); } iov[i].iov_base = (void *)iovobj.iov_base; iov[i].iov_len = iovobj.iov_len; if (iov[i].iov_len > SSIZE_MAX - uio->uio_resid) { free(uio, M_IOV); return (EINVAL); } uio->uio_resid += iov[i].iov_len; } *uiop = uio; return (0); } int cloudabi64_sys_fd_pread(struct thread *td, struct cloudabi64_sys_fd_pread_args *uap) { struct uio *uio; int error; error = cloudabi64_copyinuio(uap->iov, uap->iovcnt, &uio); if (error != 0) return (error); error = kern_preadv(td, uap->fd, uio, uap->offset); free(uio, M_IOV); return (error); } int cloudabi64_sys_fd_pwrite(struct thread *td, struct cloudabi64_sys_fd_pwrite_args *uap) { struct uio *uio; int error; error = cloudabi64_copyinuio((const cloudabi64_iovec_t *)uap->iov, uap->iovcnt, &uio); if (error != 0) return (error); error = kern_pwritev(td, uap->fd, uio, uap->offset); free(uio, M_IOV); return (error); } int cloudabi64_sys_fd_read(struct thread *td, struct cloudabi64_sys_fd_read_args *uap) { struct uio *uio; int error; error = cloudabi64_copyinuio(uap->iov, uap->iovcnt, &uio); if (error != 0) return (error); error = kern_readv(td, uap->fd, uio); free(uio, M_IOV); return (error); } int cloudabi64_sys_fd_write(struct thread *td, struct cloudabi64_sys_fd_write_args *uap) { struct uio *uio; int error; error = cloudabi64_copyinuio((const cloudabi64_iovec_t *)uap->iov, uap->iovcnt, &uio); if (error != 0) return (error); error = kern_writev(td, uap->fd, uio); free(uio, M_IOV); return (error); } Index: head/sys/compat/cloudabi64/cloudabi64_module.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_module.c (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_module.c (revision 297247) @@ -1,148 +1,149 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include -#include +#include + #include register_t * cloudabi64_copyout_strings(struct image_params *imgp) { struct image_args *args; uintptr_t begin; size_t len; /* Copy out program arguments. */ args = imgp->args; len = args->begin_envv - args->begin_argv; begin = rounddown2(imgp->sysent->sv_usrstack - len, sizeof(register_t)); copyout(args->begin_argv, (void *)begin, len); return ((register_t *)begin); } int cloudabi64_fixup(register_t **stack_base, struct image_params *imgp) { char canarybuf[64]; Elf64_Auxargs *args; struct thread *td; void *argdata, *canary; size_t argdatalen; int error; /* * CloudABI executables do not store the FreeBSD OS release * number in their header. Set the OS release number to the * latest version of FreeBSD, so that system calls behave as if * called natively. */ td = curthread; td->td_proc->p_osrel = __FreeBSD_version; /* Store canary for stack smashing protection. */ argdata = *stack_base; arc4rand(canarybuf, sizeof(canarybuf), 0); *stack_base -= howmany(sizeof(canarybuf), sizeof(register_t)); canary = *stack_base; error = copyout(canarybuf, canary, sizeof(canarybuf)); if (error != 0) return (error); /* * Compute length of program arguments. As the argument data is * binary safe, we had to add a trailing null byte in * exec_copyin_data_fds(). Undo this by reducing the length. */ args = (Elf64_Auxargs *)imgp->auxargs; argdatalen = imgp->args->begin_envv - imgp->args->begin_argv; if (argdatalen > 0) --argdatalen; /* Write out an auxiliary vector. */ cloudabi64_auxv_t auxv[] = { #define VAL(type, val) { .a_type = (type), .a_val = (val) } #define PTR(type, ptr) { .a_type = (type), .a_ptr = (uintptr_t)(ptr) } PTR(CLOUDABI_AT_ARGDATA, argdata), VAL(CLOUDABI_AT_ARGDATALEN, argdatalen), PTR(CLOUDABI_AT_CANARY, canary), VAL(CLOUDABI_AT_CANARYLEN, sizeof(canarybuf)), VAL(CLOUDABI_AT_NCPUS, mp_ncpus), VAL(CLOUDABI_AT_PAGESZ, args->pagesz), PTR(CLOUDABI_AT_PHDR, args->phdr), VAL(CLOUDABI_AT_PHNUM, args->phnum), VAL(CLOUDABI_AT_TID, td->td_tid), #undef VAL #undef PTR { .a_type = CLOUDABI_AT_NULL }, }; *stack_base -= howmany(sizeof(auxv), sizeof(register_t)); return (copyout(auxv, *stack_base, sizeof(auxv))); } static int cloudabi64_modevent(module_t mod, int type, void *data) { switch (type) { case MOD_LOAD: if (elf64_insert_brand_entry(&cloudabi64_brand) < 0) { printf("Failed to add CloudABI ELF brand handler\n"); return (EINVAL); } return (0); case MOD_UNLOAD: if (elf64_brand_inuse(&cloudabi64_brand)) return (EBUSY); if (elf64_remove_brand_entry(&cloudabi64_brand) < 0) { printf("Failed to remove CloudABI ELF brand handler\n"); return (EINVAL); } return (0); default: return (EOPNOTSUPP); } } static moduledata_t cloudabi64_module = { "cloudabi64", cloudabi64_modevent, NULL }; DECLARE_MODULE_TIED(cloudabi64, cloudabi64_module, SI_SUB_EXEC, SI_ORDER_ANY); MODULE_DEPEND(cloudabi64, cloudabi, 1, 1, 1); FEATURE(cloudabi64, "CloudABI 64bit support"); Index: head/sys/compat/cloudabi64/cloudabi64_poll.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_poll.c (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_poll.c (revision 297247) @@ -1,406 +1,407 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include +#include + #include -#include #include /* Converts a FreeBSD signal number to a CloudABI signal number. */ static cloudabi_signal_t convert_signal(int sig) { static const cloudabi_signal_t signals[] = { [SIGABRT] = CLOUDABI_SIGABRT, [SIGALRM] = CLOUDABI_SIGALRM, [SIGBUS] = CLOUDABI_SIGBUS, [SIGCHLD] = CLOUDABI_SIGCHLD, [SIGCONT] = CLOUDABI_SIGCONT, [SIGFPE] = CLOUDABI_SIGFPE, [SIGHUP] = CLOUDABI_SIGHUP, [SIGILL] = CLOUDABI_SIGILL, [SIGINT] = CLOUDABI_SIGINT, [SIGKILL] = CLOUDABI_SIGKILL, [SIGPIPE] = CLOUDABI_SIGPIPE, [SIGQUIT] = CLOUDABI_SIGQUIT, [SIGSEGV] = CLOUDABI_SIGSEGV, [SIGSTOP] = CLOUDABI_SIGSTOP, [SIGSYS] = CLOUDABI_SIGSYS, [SIGTERM] = CLOUDABI_SIGTERM, [SIGTRAP] = CLOUDABI_SIGTRAP, [SIGTSTP] = CLOUDABI_SIGTSTP, [SIGTTIN] = CLOUDABI_SIGTTIN, [SIGTTOU] = CLOUDABI_SIGTTOU, [SIGURG] = CLOUDABI_SIGURG, [SIGUSR1] = CLOUDABI_SIGUSR1, [SIGUSR2] = CLOUDABI_SIGUSR2, [SIGVTALRM] = CLOUDABI_SIGVTALRM, [SIGXCPU] = CLOUDABI_SIGXCPU, [SIGXFSZ] = CLOUDABI_SIGXFSZ, }; /* Convert unknown signals to SIGABRT. */ if (sig < 0 || sig >= nitems(signals) || signals[sig] == 0) return (SIGABRT); return (signals[sig]); } struct cloudabi64_kevent_args { const cloudabi64_subscription_t *in; cloudabi64_event_t *out; bool once; }; /* Converts CloudABI's subscription objects to FreeBSD's struct kevent. */ static int cloudabi64_kevent_copyin(void *arg, struct kevent *kevp, int count) { cloudabi64_subscription_t sub; struct cloudabi64_kevent_args *args; cloudabi_timestamp_t ts; int error; args = arg; while (count-- > 0) { /* TODO(ed): Copy in multiple entries at once. */ error = copyin(args->in++, &sub, sizeof(sub)); if (error != 0) return (error); memset(kevp, 0, sizeof(*kevp)); kevp->udata = (void *)sub.userdata; switch (sub.type) { case CLOUDABI_EVENTTYPE_CLOCK: kevp->filter = EVFILT_TIMER; kevp->ident = sub.clock.identifier; kevp->fflags = NOTE_NSECONDS; if ((sub.clock.flags & CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) != 0 && sub.clock.timeout > 0) { /* Convert absolute timestamp to a relative. */ error = cloudabi_clock_time_get(curthread, sub.clock.clock_id, &ts); if (error != 0) return (error); ts = ts > sub.clock.timeout ? 0 : sub.clock.timeout - ts; } else { /* Relative timestamp. */ ts = sub.clock.timeout; } kevp->data = ts > INTPTR_MAX ? INTPTR_MAX : ts; break; case CLOUDABI_EVENTTYPE_FD_READ: kevp->filter = EVFILT_READ; kevp->ident = sub.fd_readwrite.fd; if ((sub.fd_readwrite.flags & CLOUDABI_SUBSCRIPTION_FD_READWRITE_POLL) != 0) kevp->fflags = NOTE_FILE_POLL; break; case CLOUDABI_EVENTTYPE_FD_WRITE: kevp->filter = EVFILT_WRITE; kevp->ident = sub.fd_readwrite.fd; break; case CLOUDABI_EVENTTYPE_PROC_TERMINATE: kevp->filter = EVFILT_PROCDESC; kevp->ident = sub.proc_terminate.fd; kevp->fflags = NOTE_EXIT; break; } if (args->once) { /* Ignore flags. Simply use oneshot mode. */ kevp->flags = EV_ADD | EV_ONESHOT; } else { /* Translate flags. */ if ((sub.flags & CLOUDABI_SUBSCRIPTION_ADD) != 0) kevp->flags |= EV_ADD; if ((sub.flags & CLOUDABI_SUBSCRIPTION_CLEAR) != 0) kevp->flags |= EV_CLEAR; if ((sub.flags & CLOUDABI_SUBSCRIPTION_DELETE) != 0) kevp->flags |= EV_DELETE; if ((sub.flags & CLOUDABI_SUBSCRIPTION_DISABLE) != 0) kevp->flags |= EV_DISABLE; if ((sub.flags & CLOUDABI_SUBSCRIPTION_ENABLE) != 0) kevp->flags |= EV_ENABLE; if ((sub.flags & CLOUDABI_SUBSCRIPTION_ONESHOT) != 0) kevp->flags |= EV_ONESHOT; } ++kevp; } return (0); } /* Converts FreeBSD's struct kevent to CloudABI's event objects. */ static int cloudabi64_kevent_copyout(void *arg, struct kevent *kevp, int count) { cloudabi64_event_t ev; struct cloudabi64_kevent_args *args; int error; args = arg; while (count-- > 0) { /* Convert fields that should always be present. */ memset(&ev, 0, sizeof(ev)); ev.userdata = (uintptr_t)kevp->udata; switch (kevp->filter) { case EVFILT_TIMER: ev.type = CLOUDABI_EVENTTYPE_CLOCK; ev.clock.identifier = kevp->ident; break; case EVFILT_READ: ev.type = CLOUDABI_EVENTTYPE_FD_READ; ev.fd_readwrite.fd = kevp->ident; break; case EVFILT_WRITE: ev.type = CLOUDABI_EVENTTYPE_FD_WRITE; ev.fd_readwrite.fd = kevp->ident; break; case EVFILT_PROCDESC: ev.type = CLOUDABI_EVENTTYPE_PROC_TERMINATE; ev.proc_terminate.fd = kevp->ident; break; } if ((kevp->flags & EV_ERROR) == 0) { /* Success. */ switch (kevp->filter) { case EVFILT_READ: case EVFILT_WRITE: ev.fd_readwrite.nbytes = kevp->data; if ((kevp->flags & EV_EOF) != 0) { ev.fd_readwrite.flags |= CLOUDABI_EVENT_FD_READWRITE_HANGUP; } break; case EVFILT_PROCDESC: if (WIFSIGNALED(kevp->data)) { /* Process got signalled. */ ev.proc_terminate.signal = convert_signal(WTERMSIG(kevp->data)); ev.proc_terminate.exitcode = 0; } else { /* Process exited. */ ev.proc_terminate.signal = 0; ev.proc_terminate.exitcode = WEXITSTATUS(kevp->data); } break; } } else { /* Error. */ ev.error = cloudabi_convert_errno(kevp->data); } ++kevp; /* TODO(ed): Copy out multiple entries at once. */ error = copyout(&ev, args->out++, sizeof(ev)); if (error != 0) return (error); } return (0); } int cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap) { struct cloudabi64_kevent_args args = { .in = uap->in, .out = uap->out, .once = true, }; struct kevent_copyops copyops = { .k_copyin = cloudabi64_kevent_copyin, .k_copyout = cloudabi64_kevent_copyout, .arg = &args, }; /* * Bandaid to support CloudABI futex constructs that are not * implemented through FreeBSD's kqueue(). */ - if (uap->nevents == 1) { + if (uap->nsubscriptions == 1) { cloudabi64_subscription_t sub; cloudabi64_event_t ev = {}; int error; error = copyin(uap->in, &sub, sizeof(sub)); if (error != 0) return (error); ev.userdata = sub.userdata; ev.type = sub.type; if (sub.type == CLOUDABI_EVENTTYPE_CONDVAR) { /* Wait on a condition variable. */ ev.condvar.condvar = sub.condvar.condvar; ev.error = cloudabi_convert_errno( cloudabi_futex_condvar_wait( td, (cloudabi_condvar_t *)sub.condvar.condvar, sub.condvar.condvar_scope, (cloudabi_lock_t *)sub.condvar.lock, sub.condvar.lock_scope, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0)); td->td_retval[0] = 1; return (copyout(&ev, uap->out, sizeof(ev))); } else if (sub.type == CLOUDABI_EVENTTYPE_LOCK_RDLOCK) { /* Acquire a read lock. */ ev.lock.lock = sub.lock.lock; ev.error = cloudabi_convert_errno( cloudabi_futex_lock_rdlock( td, (cloudabi_lock_t *)sub.lock.lock, sub.lock.lock_scope, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0)); td->td_retval[0] = 1; return (copyout(&ev, uap->out, sizeof(ev))); } else if (sub.type == CLOUDABI_EVENTTYPE_LOCK_WRLOCK) { /* Acquire a write lock. */ ev.lock.lock = sub.lock.lock; ev.error = cloudabi_convert_errno( cloudabi_futex_lock_wrlock( td, (cloudabi_lock_t *)sub.lock.lock, sub.lock.lock_scope, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0)); td->td_retval[0] = 1; return (copyout(&ev, uap->out, sizeof(ev))); } - } else if (uap->nevents == 2) { + } else if (uap->nsubscriptions == 2) { cloudabi64_subscription_t sub[2]; cloudabi64_event_t ev[2] = {}; int error; error = copyin(uap->in, &sub, sizeof(sub)); if (error != 0) return (error); ev[0].userdata = sub[0].userdata; ev[0].type = sub[0].type; ev[1].userdata = sub[1].userdata; ev[1].type = sub[1].type; if (sub[0].type == CLOUDABI_EVENTTYPE_CONDVAR && sub[1].type == CLOUDABI_EVENTTYPE_CLOCK && sub[1].clock.flags == CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) { /* Wait for a condition variable with timeout. */ ev[0].condvar.condvar = sub[0].condvar.condvar; ev[1].clock.identifier = sub[1].clock.identifier; error = cloudabi_futex_condvar_wait( td, (cloudabi_condvar_t *)sub[0].condvar.condvar, sub[0].condvar.condvar_scope, (cloudabi_lock_t *)sub[0].condvar.lock, sub[0].condvar.lock_scope, sub[1].clock.clock_id, sub[1].clock.timeout, sub[1].clock.precision); if (error == ETIMEDOUT) { td->td_retval[0] = 1; return (copyout(&ev[1], uap->out, sizeof(ev[1]))); } ev[0].error = cloudabi_convert_errno(error); td->td_retval[0] = 1; return (copyout(&ev[0], uap->out, sizeof(ev[0]))); } else if (sub[0].type == CLOUDABI_EVENTTYPE_LOCK_RDLOCK && sub[1].type == CLOUDABI_EVENTTYPE_CLOCK && sub[1].clock.flags == CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) { /* Acquire a read lock with a timeout. */ ev[0].lock.lock = sub[0].lock.lock; ev[1].clock.identifier = sub[1].clock.identifier; error = cloudabi_futex_lock_rdlock( td, (cloudabi_lock_t *)sub[0].lock.lock, sub[0].lock.lock_scope, sub[1].clock.clock_id, sub[1].clock.timeout, sub[1].clock.precision); if (error == ETIMEDOUT) { td->td_retval[0] = 1; return (copyout(&ev[1], uap->out, sizeof(ev[1]))); } ev[0].error = cloudabi_convert_errno(error); td->td_retval[0] = 1; return (copyout(&ev[0], uap->out, sizeof(ev[0]))); } else if (sub[0].type == CLOUDABI_EVENTTYPE_LOCK_WRLOCK && sub[1].type == CLOUDABI_EVENTTYPE_CLOCK && sub[1].clock.flags == CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) { /* Acquire a write lock with a timeout. */ ev[0].lock.lock = sub[0].lock.lock; ev[1].clock.identifier = sub[1].clock.identifier; error = cloudabi_futex_lock_wrlock( td, (cloudabi_lock_t *)sub[0].lock.lock, sub[0].lock.lock_scope, sub[1].clock.clock_id, sub[1].clock.timeout, sub[1].clock.precision); if (error == ETIMEDOUT) { td->td_retval[0] = 1; return (copyout(&ev[1], uap->out, sizeof(ev[1]))); } ev[0].error = cloudabi_convert_errno(error); td->td_retval[0] = 1; return (copyout(&ev[0], uap->out, sizeof(ev[0]))); } } - return (kern_kevent_anonymous(td, uap->nevents, ©ops)); + return (kern_kevent_anonymous(td, uap->nsubscriptions, ©ops)); } int cloudabi64_sys_poll_fd(struct thread *td, struct cloudabi64_sys_poll_fd_args *uap) { struct cloudabi64_kevent_args args = { .in = uap->in, .out = uap->out, .once = false, }; struct kevent_copyops copyops = { .k_copyin = cloudabi64_kevent_copyin, .k_copyout = cloudabi64_kevent_copyout, .arg = &args, }; cloudabi64_subscription_t subtimo; struct timespec timeout; int error; if (uap->timeout != NULL) { /* Poll with a timeout. */ error = copyin(uap->timeout, &subtimo, sizeof(subtimo)); if (error != 0) return (error); if (subtimo.type != CLOUDABI_EVENTTYPE_CLOCK || subtimo.clock.flags != 0) return (EINVAL); timeout.tv_sec = subtimo.clock.timeout / 1000000000; timeout.tv_nsec = subtimo.clock.timeout % 1000000000; return (kern_kevent(td, uap->fd, uap->nin, uap->nout, ©ops, &timeout)); } else { /* Poll without a timeout. */ return (kern_kevent(td, uap->fd, uap->nin, uap->nout, ©ops, NULL)); } } Index: head/sys/compat/cloudabi64/cloudabi64_sock.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_sock.c (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_sock.c (revision 297247) @@ -1,144 +1,145 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include +#include + #include -#include #include static MALLOC_DEFINE(M_SOCKET, "socket", "CloudABI socket"); int cloudabi64_sys_sock_recv(struct thread *td, struct cloudabi64_sys_sock_recv_args *uap) { struct sockaddr_storage ss; cloudabi64_recv_in_t ri; cloudabi64_recv_out_t ro = {}; cloudabi64_iovec_t iovobj; struct msghdr msghdr = {}; size_t i; int error; error = copyin(uap->in, &ri, sizeof(ri)); if (error != 0) return (error); /* Convert results in cloudabi_recv_in_t to struct msghdr. */ if (ri.ri_datalen > UIO_MAXIOV) return (EINVAL); msghdr.msg_iovlen = ri.ri_datalen; msghdr.msg_iov = malloc(msghdr.msg_iovlen * sizeof(struct iovec), M_SOCKET, M_WAITOK); for (i = 0; i < msghdr.msg_iovlen; i++) { error = copyin(&((cloudabi64_iovec_t *)ri.ri_data)[i], &iovobj, sizeof(iovobj)); if (error != 0) { free(msghdr.msg_iov, M_SOCKET); return (error); } msghdr.msg_iov[i].iov_base = (void *)iovobj.iov_base; msghdr.msg_iov[i].iov_len = iovobj.iov_len; } msghdr.msg_name = &ss; msghdr.msg_namelen = sizeof(ss); if (ri.ri_flags & CLOUDABI_MSG_PEEK) msghdr.msg_flags |= MSG_PEEK; if (ri.ri_flags & CLOUDABI_MSG_WAITALL) msghdr.msg_flags |= MSG_WAITALL; /* TODO(ed): Add file descriptor passing. */ - error = kern_recvit(td, uap->s, &msghdr, UIO_SYSSPACE, NULL); + error = kern_recvit(td, uap->sock, &msghdr, UIO_SYSSPACE, NULL); free(msghdr.msg_iov, M_SOCKET); if (error != 0) return (error); /* Convert results in msghdr to cloudabi_recv_out_t. */ ro.ro_datalen = td->td_retval[0]; cloudabi_convert_sockaddr((struct sockaddr *)&ss, MIN(msghdr.msg_namelen, sizeof(ss)), &ro.ro_peername); td->td_retval[0] = 0; return (copyout(&ro, uap->out, sizeof(ro))); } int cloudabi64_sys_sock_send(struct thread *td, struct cloudabi64_sys_sock_send_args *uap) { cloudabi64_send_in_t si; cloudabi64_send_out_t so = {}; cloudabi64_ciovec_t iovobj; struct msghdr msghdr = {}; size_t i; int error, flags; error = copyin(uap->in, &si, sizeof(si)); if (error != 0) return (error); /* Convert results in cloudabi_send_in_t to struct msghdr. */ if (si.si_datalen > UIO_MAXIOV) return (EINVAL); msghdr.msg_iovlen = si.si_datalen; msghdr.msg_iov = malloc(msghdr.msg_iovlen * sizeof(struct iovec), M_SOCKET, M_WAITOK); for (i = 0; i < msghdr.msg_iovlen; i++) { error = copyin(&((cloudabi64_ciovec_t *)si.si_data)[i], &iovobj, sizeof(iovobj)); if (error != 0) { free(msghdr.msg_iov, M_SOCKET); return (error); } msghdr.msg_iov[i].iov_base = (void *)iovobj.iov_base; msghdr.msg_iov[i].iov_len = iovobj.iov_len; } flags = MSG_NOSIGNAL; if (si.si_flags & CLOUDABI_MSG_EOR) flags |= MSG_EOR; /* TODO(ed): Add file descriptor passing. */ - error = kern_sendit(td, uap->s, &msghdr, flags, NULL, UIO_USERSPACE); + error = kern_sendit(td, uap->sock, &msghdr, flags, NULL, UIO_USERSPACE); free(msghdr.msg_iov, M_SOCKET); if (error != 0) return (error); /* Convert results in msghdr to cloudabi_send_out_t. */ so.so_datalen = td->td_retval[0]; td->td_retval[0] = 0; return (copyout(&so, uap->out, sizeof(so))); } Index: head/sys/compat/cloudabi64/cloudabi64_systrace_args.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_systrace_args.c (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_systrace_args.c (revision 297247) @@ -1,1724 +1,1724 @@ /* * System call argument to DTrace register array converstion. * * DO NOT EDIT-- this file is automatically generated. * $FreeBSD$ * This file is part of the DTrace syscall provider. */ static void systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args) { int64_t *iarg = (int64_t *) uarg; switch (sysnum) { /* cloudabi_sys_clock_res_get */ case 0: { struct cloudabi_sys_clock_res_get_args *p = params; iarg[0] = p->clock_id; /* cloudabi_clockid_t */ *n_args = 1; break; } /* cloudabi_sys_clock_time_get */ case 1: { struct cloudabi_sys_clock_time_get_args *p = params; iarg[0] = p->clock_id; /* cloudabi_clockid_t */ iarg[1] = p->precision; /* cloudabi_timestamp_t */ *n_args = 2; break; } /* cloudabi_sys_condvar_signal */ case 2: { struct cloudabi_sys_condvar_signal_args *p = params; uarg[0] = (intptr_t) p->condvar; /* cloudabi_condvar_t * */ iarg[1] = p->scope; /* cloudabi_mflags_t */ iarg[2] = p->nwaiters; /* cloudabi_nthreads_t */ *n_args = 3; break; } /* cloudabi_sys_fd_close */ case 3: { struct cloudabi_sys_fd_close_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ *n_args = 1; break; } /* cloudabi_sys_fd_create1 */ case 4: { struct cloudabi_sys_fd_create1_args *p = params; iarg[0] = p->type; /* cloudabi_filetype_t */ *n_args = 1; break; } /* cloudabi_sys_fd_create2 */ case 5: { struct cloudabi_sys_fd_create2_args *p = params; iarg[0] = p->type; /* cloudabi_filetype_t */ *n_args = 1; break; } /* cloudabi_sys_fd_datasync */ case 6: { struct cloudabi_sys_fd_datasync_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ *n_args = 1; break; } /* cloudabi_sys_fd_dup */ case 7: { struct cloudabi_sys_fd_dup_args *p = params; iarg[0] = p->from; /* cloudabi_fd_t */ *n_args = 1; break; } /* cloudabi64_sys_fd_pread */ case 8: { struct cloudabi64_sys_fd_pread_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->iov; /* const cloudabi64_iovec_t * */ - iarg[2] = p->iovcnt; /* cloudabi64_size_t */ + uarg[2] = p->iovcnt; /* size_t */ iarg[3] = p->offset; /* cloudabi_filesize_t */ *n_args = 4; break; } /* cloudabi64_sys_fd_pwrite */ case 9: { struct cloudabi64_sys_fd_pwrite_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->iov; /* const cloudabi64_ciovec_t * */ - iarg[2] = p->iovcnt; /* cloudabi64_size_t */ + uarg[2] = p->iovcnt; /* size_t */ iarg[3] = p->offset; /* cloudabi_filesize_t */ *n_args = 4; break; } /* cloudabi64_sys_fd_read */ case 10: { struct cloudabi64_sys_fd_read_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->iov; /* const cloudabi64_iovec_t * */ - iarg[2] = p->iovcnt; /* cloudabi64_size_t */ + uarg[2] = p->iovcnt; /* size_t */ *n_args = 3; break; } /* cloudabi_sys_fd_replace */ case 11: { struct cloudabi_sys_fd_replace_args *p = params; iarg[0] = p->from; /* cloudabi_fd_t */ iarg[1] = p->to; /* cloudabi_fd_t */ *n_args = 2; break; } /* cloudabi_sys_fd_seek */ case 12: { struct cloudabi_sys_fd_seek_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ iarg[1] = p->offset; /* cloudabi_filedelta_t */ iarg[2] = p->whence; /* cloudabi_whence_t */ *n_args = 3; break; } /* cloudabi_sys_fd_stat_get */ case 13: { struct cloudabi_sys_fd_stat_get_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* cloudabi_fdstat_t * */ *n_args = 2; break; } /* cloudabi_sys_fd_stat_put */ case 14: { struct cloudabi_sys_fd_stat_put_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* const cloudabi_fdstat_t * */ iarg[2] = p->flags; /* cloudabi_fdsflags_t */ *n_args = 3; break; } /* cloudabi_sys_fd_sync */ case 15: { struct cloudabi_sys_fd_sync_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ *n_args = 1; break; } /* cloudabi64_sys_fd_write */ case 16: { struct cloudabi64_sys_fd_write_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->iov; /* const cloudabi64_ciovec_t * */ - iarg[2] = p->iovcnt; /* cloudabi64_size_t */ + uarg[2] = p->iovcnt; /* size_t */ *n_args = 3; break; } /* cloudabi_sys_file_advise */ case 17: { struct cloudabi_sys_file_advise_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ iarg[1] = p->offset; /* cloudabi_filesize_t */ iarg[2] = p->len; /* cloudabi_filesize_t */ iarg[3] = p->advice; /* cloudabi_advice_t */ *n_args = 4; break; } /* cloudabi_sys_file_allocate */ case 18: { struct cloudabi_sys_file_allocate_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ iarg[1] = p->offset; /* cloudabi_filesize_t */ iarg[2] = p->len; /* cloudabi_filesize_t */ *n_args = 3; break; } /* cloudabi_sys_file_create */ case 19: { struct cloudabi_sys_file_create_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->path; /* const char * */ uarg[2] = p->pathlen; /* size_t */ iarg[3] = p->type; /* cloudabi_filetype_t */ *n_args = 4; break; } /* cloudabi_sys_file_link */ case 20: { struct cloudabi_sys_file_link_args *p = params; iarg[0] = p->fd1; /* cloudabi_lookup_t */ uarg[1] = (intptr_t) p->path1; /* const char * */ uarg[2] = p->path1len; /* size_t */ iarg[3] = p->fd2; /* cloudabi_fd_t */ uarg[4] = (intptr_t) p->path2; /* const char * */ uarg[5] = p->path2len; /* size_t */ *n_args = 6; break; } /* cloudabi_sys_file_open */ case 21: { struct cloudabi_sys_file_open_args *p = params; - iarg[0] = p->fd; /* cloudabi_lookup_t */ + iarg[0] = p->dirfd; /* cloudabi_lookup_t */ uarg[1] = (intptr_t) p->path; /* const char * */ uarg[2] = p->pathlen; /* size_t */ iarg[3] = p->oflags; /* cloudabi_oflags_t */ uarg[4] = (intptr_t) p->fds; /* const cloudabi_fdstat_t * */ *n_args = 5; break; } /* cloudabi_sys_file_readdir */ case 22: { struct cloudabi_sys_file_readdir_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* void * */ uarg[2] = p->nbyte; /* size_t */ iarg[3] = p->cookie; /* cloudabi_dircookie_t */ *n_args = 4; break; } /* cloudabi_sys_file_readlink */ case 23: { struct cloudabi_sys_file_readlink_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->path; /* const char * */ uarg[2] = p->pathlen; /* size_t */ - uarg[3] = (intptr_t) p->buf; /* void * */ + uarg[3] = (intptr_t) p->buf; /* char * */ uarg[4] = p->bufsize; /* size_t */ *n_args = 5; break; } /* cloudabi_sys_file_rename */ case 24: { struct cloudabi_sys_file_rename_args *p = params; iarg[0] = p->oldfd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->old; /* const char * */ uarg[2] = p->oldlen; /* size_t */ iarg[3] = p->newfd; /* cloudabi_fd_t */ uarg[4] = (intptr_t) p->new; /* const char * */ uarg[5] = p->newlen; /* size_t */ *n_args = 6; break; } /* cloudabi_sys_file_stat_fget */ case 25: { struct cloudabi_sys_file_stat_fget_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* cloudabi_filestat_t * */ *n_args = 2; break; } /* cloudabi_sys_file_stat_fput */ case 26: { struct cloudabi_sys_file_stat_fput_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* const cloudabi_filestat_t * */ iarg[2] = p->flags; /* cloudabi_fsflags_t */ *n_args = 3; break; } /* cloudabi_sys_file_stat_get */ case 27: { struct cloudabi_sys_file_stat_get_args *p = params; iarg[0] = p->fd; /* cloudabi_lookup_t */ uarg[1] = (intptr_t) p->path; /* const char * */ uarg[2] = p->pathlen; /* size_t */ uarg[3] = (intptr_t) p->buf; /* cloudabi_filestat_t * */ *n_args = 4; break; } /* cloudabi_sys_file_stat_put */ case 28: { struct cloudabi_sys_file_stat_put_args *p = params; iarg[0] = p->fd; /* cloudabi_lookup_t */ uarg[1] = (intptr_t) p->path; /* const char * */ uarg[2] = p->pathlen; /* size_t */ uarg[3] = (intptr_t) p->buf; /* const cloudabi_filestat_t * */ iarg[4] = p->flags; /* cloudabi_fsflags_t */ *n_args = 5; break; } /* cloudabi_sys_file_symlink */ case 29: { struct cloudabi_sys_file_symlink_args *p = params; uarg[0] = (intptr_t) p->path1; /* const char * */ uarg[1] = p->path1len; /* size_t */ iarg[2] = p->fd; /* cloudabi_fd_t */ uarg[3] = (intptr_t) p->path2; /* const char * */ uarg[4] = p->path2len; /* size_t */ *n_args = 5; break; } /* cloudabi_sys_file_unlink */ case 30: { struct cloudabi_sys_file_unlink_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->path; /* const char * */ uarg[2] = p->pathlen; /* size_t */ - iarg[3] = p->flag; /* cloudabi_ulflags_t */ + iarg[3] = p->flags; /* cloudabi_ulflags_t */ *n_args = 4; break; } /* cloudabi_sys_lock_unlock */ case 31: { struct cloudabi_sys_lock_unlock_args *p = params; uarg[0] = (intptr_t) p->lock; /* cloudabi_lock_t * */ iarg[1] = p->scope; /* cloudabi_mflags_t */ *n_args = 2; break; } /* cloudabi_sys_mem_advise */ case 32: { struct cloudabi_sys_mem_advise_args *p = params; uarg[0] = (intptr_t) p->addr; /* void * */ uarg[1] = p->len; /* size_t */ iarg[2] = p->advice; /* cloudabi_advice_t */ *n_args = 3; break; } /* cloudabi_sys_mem_lock */ case 33: { struct cloudabi_sys_mem_lock_args *p = params; uarg[0] = (intptr_t) p->addr; /* const void * */ uarg[1] = p->len; /* size_t */ *n_args = 2; break; } /* cloudabi_sys_mem_map */ case 34: { struct cloudabi_sys_mem_map_args *p = params; uarg[0] = (intptr_t) p->addr; /* void * */ uarg[1] = p->len; /* size_t */ iarg[2] = p->prot; /* cloudabi_mprot_t */ iarg[3] = p->flags; /* cloudabi_mflags_t */ iarg[4] = p->fd; /* cloudabi_fd_t */ iarg[5] = p->off; /* cloudabi_filesize_t */ *n_args = 6; break; } /* cloudabi_sys_mem_protect */ case 35: { struct cloudabi_sys_mem_protect_args *p = params; uarg[0] = (intptr_t) p->addr; /* void * */ uarg[1] = p->len; /* size_t */ iarg[2] = p->prot; /* cloudabi_mprot_t */ *n_args = 3; break; } /* cloudabi_sys_mem_sync */ case 36: { struct cloudabi_sys_mem_sync_args *p = params; uarg[0] = (intptr_t) p->addr; /* void * */ uarg[1] = p->len; /* size_t */ iarg[2] = p->flags; /* cloudabi_msflags_t */ *n_args = 3; break; } /* cloudabi_sys_mem_unlock */ case 37: { struct cloudabi_sys_mem_unlock_args *p = params; uarg[0] = (intptr_t) p->addr; /* const void * */ uarg[1] = p->len; /* size_t */ *n_args = 2; break; } /* cloudabi_sys_mem_unmap */ case 38: { struct cloudabi_sys_mem_unmap_args *p = params; uarg[0] = (intptr_t) p->addr; /* void * */ uarg[1] = p->len; /* size_t */ *n_args = 2; break; } /* cloudabi64_sys_poll */ case 39: { struct cloudabi64_sys_poll_args *p = params; uarg[0] = (intptr_t) p->in; /* const cloudabi64_subscription_t * */ uarg[1] = (intptr_t) p->out; /* cloudabi64_event_t * */ - iarg[2] = p->nevents; /* cloudabi64_size_t */ + uarg[2] = p->nsubscriptions; /* size_t */ *n_args = 3; break; } /* cloudabi_sys_proc_exec */ case 40: { struct cloudabi_sys_proc_exec_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->data; /* const void * */ uarg[2] = p->datalen; /* size_t */ uarg[3] = (intptr_t) p->fds; /* const cloudabi_fd_t * */ uarg[4] = p->fdslen; /* size_t */ *n_args = 5; break; } /* cloudabi_sys_proc_exit */ case 41: { struct cloudabi_sys_proc_exit_args *p = params; iarg[0] = p->rval; /* cloudabi_exitcode_t */ *n_args = 1; break; } /* cloudabi_sys_proc_fork */ case 42: { *n_args = 0; break; } /* cloudabi_sys_proc_raise */ case 43: { struct cloudabi_sys_proc_raise_args *p = params; iarg[0] = p->sig; /* cloudabi_signal_t */ *n_args = 1; break; } /* cloudabi_sys_random_get */ case 44: { struct cloudabi_sys_random_get_args *p = params; uarg[0] = (intptr_t) p->buf; /* void * */ uarg[1] = p->nbyte; /* size_t */ *n_args = 2; break; } /* cloudabi_sys_sock_accept */ case 45: { struct cloudabi_sys_sock_accept_args *p = params; - iarg[0] = p->s; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* cloudabi_sockstat_t * */ *n_args = 2; break; } /* cloudabi_sys_sock_bind */ case 46: { struct cloudabi_sys_sock_bind_args *p = params; - iarg[0] = p->s; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ iarg[1] = p->fd; /* cloudabi_fd_t */ uarg[2] = (intptr_t) p->path; /* const char * */ uarg[3] = p->pathlen; /* size_t */ *n_args = 4; break; } /* cloudabi_sys_sock_connect */ case 47: { struct cloudabi_sys_sock_connect_args *p = params; - iarg[0] = p->s; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ iarg[1] = p->fd; /* cloudabi_fd_t */ uarg[2] = (intptr_t) p->path; /* const char * */ uarg[3] = p->pathlen; /* size_t */ *n_args = 4; break; } /* cloudabi_sys_sock_listen */ case 48: { struct cloudabi_sys_sock_listen_args *p = params; - iarg[0] = p->s; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ iarg[1] = p->backlog; /* cloudabi_backlog_t */ *n_args = 2; break; } /* cloudabi64_sys_sock_recv */ case 49: { struct cloudabi64_sys_sock_recv_args *p = params; - iarg[0] = p->s; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->in; /* const cloudabi64_recv_in_t * */ uarg[2] = (intptr_t) p->out; /* cloudabi64_recv_out_t * */ *n_args = 3; break; } /* cloudabi64_sys_sock_send */ case 50: { struct cloudabi64_sys_sock_send_args *p = params; - iarg[0] = p->s; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->in; /* const cloudabi64_send_in_t * */ uarg[2] = (intptr_t) p->out; /* cloudabi64_send_out_t * */ *n_args = 3; break; } /* cloudabi_sys_sock_shutdown */ case 51: { struct cloudabi_sys_sock_shutdown_args *p = params; - iarg[0] = p->fd; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ iarg[1] = p->how; /* cloudabi_sdflags_t */ *n_args = 2; break; } /* cloudabi_sys_sock_stat_get */ case 52: { struct cloudabi_sys_sock_stat_get_args *p = params; - iarg[0] = p->fd; /* cloudabi_fd_t */ + iarg[0] = p->sock; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->buf; /* cloudabi_sockstat_t * */ iarg[2] = p->flags; /* cloudabi_ssflags_t */ *n_args = 3; break; } /* cloudabi64_sys_thread_create */ case 53: { struct cloudabi64_sys_thread_create_args *p = params; uarg[0] = (intptr_t) p->attr; /* cloudabi64_threadattr_t * */ *n_args = 1; break; } /* cloudabi_sys_thread_exit */ case 54: { struct cloudabi_sys_thread_exit_args *p = params; uarg[0] = (intptr_t) p->lock; /* cloudabi_lock_t * */ iarg[1] = p->scope; /* cloudabi_mflags_t */ *n_args = 2; break; } /* cloudabi_sys_thread_tcb_set */ case 55: { struct cloudabi_sys_thread_tcb_set_args *p = params; uarg[0] = (intptr_t) p->tcb; /* void * */ *n_args = 1; break; } /* cloudabi_sys_thread_yield */ case 56: { *n_args = 0; break; } /* cloudabi64_sys_poll_fd */ case 57: { struct cloudabi64_sys_poll_fd_args *p = params; iarg[0] = p->fd; /* cloudabi_fd_t */ uarg[1] = (intptr_t) p->in; /* const cloudabi64_subscription_t * */ - iarg[2] = p->nin; /* cloudabi64_size_t */ + uarg[2] = p->nin; /* size_t */ uarg[3] = (intptr_t) p->out; /* cloudabi64_event_t * */ - iarg[4] = p->nout; /* cloudabi64_size_t */ + uarg[4] = p->nout; /* size_t */ uarg[5] = (intptr_t) p->timeout; /* const cloudabi64_subscription_t * */ *n_args = 6; break; } default: *n_args = 0; break; }; } static void systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) { const char *p = NULL; switch (sysnum) { /* cloudabi_sys_clock_res_get */ case 0: switch(ndx) { case 0: p = "cloudabi_clockid_t"; break; default: break; }; break; /* cloudabi_sys_clock_time_get */ case 1: switch(ndx) { case 0: p = "cloudabi_clockid_t"; break; case 1: p = "cloudabi_timestamp_t"; break; default: break; }; break; /* cloudabi_sys_condvar_signal */ case 2: switch(ndx) { case 0: p = "cloudabi_condvar_t *"; break; case 1: p = "cloudabi_mflags_t"; break; case 2: p = "cloudabi_nthreads_t"; break; default: break; }; break; /* cloudabi_sys_fd_close */ case 3: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; default: break; }; break; /* cloudabi_sys_fd_create1 */ case 4: switch(ndx) { case 0: p = "cloudabi_filetype_t"; break; default: break; }; break; /* cloudabi_sys_fd_create2 */ case 5: switch(ndx) { case 0: p = "cloudabi_filetype_t"; break; default: break; }; break; /* cloudabi_sys_fd_datasync */ case 6: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; default: break; }; break; /* cloudabi_sys_fd_dup */ case 7: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; default: break; }; break; /* cloudabi64_sys_fd_pread */ case 8: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_iovec_t *"; break; case 2: - p = "cloudabi64_size_t"; + p = "size_t"; break; case 3: p = "cloudabi_filesize_t"; break; default: break; }; break; /* cloudabi64_sys_fd_pwrite */ case 9: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_ciovec_t *"; break; case 2: - p = "cloudabi64_size_t"; + p = "size_t"; break; case 3: p = "cloudabi_filesize_t"; break; default: break; }; break; /* cloudabi64_sys_fd_read */ case 10: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_iovec_t *"; break; case 2: - p = "cloudabi64_size_t"; + p = "size_t"; break; default: break; }; break; /* cloudabi_sys_fd_replace */ case 11: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_fd_t"; break; default: break; }; break; /* cloudabi_sys_fd_seek */ case 12: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_filedelta_t"; break; case 2: p = "cloudabi_whence_t"; break; default: break; }; break; /* cloudabi_sys_fd_stat_get */ case 13: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_fdstat_t *"; break; default: break; }; break; /* cloudabi_sys_fd_stat_put */ case 14: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi_fdstat_t *"; break; case 2: p = "cloudabi_fdsflags_t"; break; default: break; }; break; /* cloudabi_sys_fd_sync */ case 15: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; default: break; }; break; /* cloudabi64_sys_fd_write */ case 16: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_ciovec_t *"; break; case 2: - p = "cloudabi64_size_t"; + p = "size_t"; break; default: break; }; break; /* cloudabi_sys_file_advise */ case 17: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_filesize_t"; break; case 2: p = "cloudabi_filesize_t"; break; case 3: p = "cloudabi_advice_t"; break; default: break; }; break; /* cloudabi_sys_file_allocate */ case 18: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_filesize_t"; break; case 2: p = "cloudabi_filesize_t"; break; default: break; }; break; /* cloudabi_sys_file_create */ case 19: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_filetype_t"; break; default: break; }; break; /* cloudabi_sys_file_link */ case 20: switch(ndx) { case 0: p = "cloudabi_lookup_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_fd_t"; break; case 4: p = "const char *"; break; case 5: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_file_open */ case 21: switch(ndx) { case 0: p = "cloudabi_lookup_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_oflags_t"; break; case 4: p = "const cloudabi_fdstat_t *"; break; default: break; }; break; /* cloudabi_sys_file_readdir */ case 22: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "void *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_dircookie_t"; break; default: break; }; break; /* cloudabi_sys_file_readlink */ case 23: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: - p = "void *"; + p = "char *"; break; case 4: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_file_rename */ case 24: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_fd_t"; break; case 4: p = "const char *"; break; case 5: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_file_stat_fget */ case 25: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_filestat_t *"; break; default: break; }; break; /* cloudabi_sys_file_stat_fput */ case 26: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi_filestat_t *"; break; case 2: p = "cloudabi_fsflags_t"; break; default: break; }; break; /* cloudabi_sys_file_stat_get */ case 27: switch(ndx) { case 0: p = "cloudabi_lookup_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_filestat_t *"; break; default: break; }; break; /* cloudabi_sys_file_stat_put */ case 28: switch(ndx) { case 0: p = "cloudabi_lookup_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "const cloudabi_filestat_t *"; break; case 4: p = "cloudabi_fsflags_t"; break; default: break; }; break; /* cloudabi_sys_file_symlink */ case 29: switch(ndx) { case 0: p = "const char *"; break; case 1: p = "size_t"; break; case 2: p = "cloudabi_fd_t"; break; case 3: p = "const char *"; break; case 4: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_file_unlink */ case 30: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const char *"; break; case 2: p = "size_t"; break; case 3: p = "cloudabi_ulflags_t"; break; default: break; }; break; /* cloudabi_sys_lock_unlock */ case 31: switch(ndx) { case 0: p = "cloudabi_lock_t *"; break; case 1: p = "cloudabi_mflags_t"; break; default: break; }; break; /* cloudabi_sys_mem_advise */ case 32: switch(ndx) { case 0: p = "void *"; break; case 1: p = "size_t"; break; case 2: p = "cloudabi_advice_t"; break; default: break; }; break; /* cloudabi_sys_mem_lock */ case 33: switch(ndx) { case 0: p = "const void *"; break; case 1: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_mem_map */ case 34: switch(ndx) { case 0: p = "void *"; break; case 1: p = "size_t"; break; case 2: p = "cloudabi_mprot_t"; break; case 3: p = "cloudabi_mflags_t"; break; case 4: p = "cloudabi_fd_t"; break; case 5: p = "cloudabi_filesize_t"; break; default: break; }; break; /* cloudabi_sys_mem_protect */ case 35: switch(ndx) { case 0: p = "void *"; break; case 1: p = "size_t"; break; case 2: p = "cloudabi_mprot_t"; break; default: break; }; break; /* cloudabi_sys_mem_sync */ case 36: switch(ndx) { case 0: p = "void *"; break; case 1: p = "size_t"; break; case 2: p = "cloudabi_msflags_t"; break; default: break; }; break; /* cloudabi_sys_mem_unlock */ case 37: switch(ndx) { case 0: p = "const void *"; break; case 1: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_mem_unmap */ case 38: switch(ndx) { case 0: p = "void *"; break; case 1: p = "size_t"; break; default: break; }; break; /* cloudabi64_sys_poll */ case 39: switch(ndx) { case 0: p = "const cloudabi64_subscription_t *"; break; case 1: p = "cloudabi64_event_t *"; break; case 2: - p = "cloudabi64_size_t"; + p = "size_t"; break; default: break; }; break; /* cloudabi_sys_proc_exec */ case 40: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const void *"; break; case 2: p = "size_t"; break; case 3: p = "const cloudabi_fd_t *"; break; case 4: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_proc_exit */ case 41: switch(ndx) { case 0: p = "cloudabi_exitcode_t"; break; default: break; }; break; /* cloudabi_sys_proc_fork */ case 42: break; /* cloudabi_sys_proc_raise */ case 43: switch(ndx) { case 0: p = "cloudabi_signal_t"; break; default: break; }; break; /* cloudabi_sys_random_get */ case 44: switch(ndx) { case 0: p = "void *"; break; case 1: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_sock_accept */ case 45: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_sockstat_t *"; break; default: break; }; break; /* cloudabi_sys_sock_bind */ case 46: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_fd_t"; break; case 2: p = "const char *"; break; case 3: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_sock_connect */ case 47: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_fd_t"; break; case 2: p = "const char *"; break; case 3: p = "size_t"; break; default: break; }; break; /* cloudabi_sys_sock_listen */ case 48: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_backlog_t"; break; default: break; }; break; /* cloudabi64_sys_sock_recv */ case 49: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_recv_in_t *"; break; case 2: p = "cloudabi64_recv_out_t *"; break; default: break; }; break; /* cloudabi64_sys_sock_send */ case 50: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_send_in_t *"; break; case 2: p = "cloudabi64_send_out_t *"; break; default: break; }; break; /* cloudabi_sys_sock_shutdown */ case 51: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_sdflags_t"; break; default: break; }; break; /* cloudabi_sys_sock_stat_get */ case 52: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "cloudabi_sockstat_t *"; break; case 2: p = "cloudabi_ssflags_t"; break; default: break; }; break; /* cloudabi64_sys_thread_create */ case 53: switch(ndx) { case 0: p = "cloudabi64_threadattr_t *"; break; default: break; }; break; /* cloudabi_sys_thread_exit */ case 54: switch(ndx) { case 0: p = "cloudabi_lock_t *"; break; case 1: p = "cloudabi_mflags_t"; break; default: break; }; break; /* cloudabi_sys_thread_tcb_set */ case 55: switch(ndx) { case 0: p = "void *"; break; default: break; }; break; /* cloudabi_sys_thread_yield */ case 56: break; /* cloudabi64_sys_poll_fd */ case 57: switch(ndx) { case 0: p = "cloudabi_fd_t"; break; case 1: p = "const cloudabi64_subscription_t *"; break; case 2: - p = "cloudabi64_size_t"; + p = "size_t"; break; case 3: p = "cloudabi64_event_t *"; break; case 4: - p = "cloudabi64_size_t"; + p = "size_t"; break; case 5: p = "const cloudabi64_subscription_t *"; break; default: break; }; break; default: break; }; if (p != NULL) strlcpy(desc, p, descsz); } static void systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) { const char *p = NULL; switch (sysnum) { /* cloudabi_sys_clock_res_get */ case 0: if (ndx == 0 || ndx == 1) p = "cloudabi_timestamp_t"; break; /* cloudabi_sys_clock_time_get */ case 1: if (ndx == 0 || ndx == 1) p = "cloudabi_timestamp_t"; break; /* cloudabi_sys_condvar_signal */ case 2: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_close */ case 3: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_create1 */ case 4: if (ndx == 0 || ndx == 1) p = "cloudabi_fd_t"; break; /* cloudabi_sys_fd_create2 */ case 5: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_datasync */ case 6: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_dup */ case 7: if (ndx == 0 || ndx == 1) p = "cloudabi_fd_t"; break; /* cloudabi64_sys_fd_pread */ case 8: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "size_t"; break; /* cloudabi64_sys_fd_pwrite */ case 9: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "size_t"; break; /* cloudabi64_sys_fd_read */ case 10: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "size_t"; break; /* cloudabi_sys_fd_replace */ case 11: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_seek */ case 12: if (ndx == 0 || ndx == 1) p = "cloudabi_filesize_t"; break; /* cloudabi_sys_fd_stat_get */ case 13: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_stat_put */ case 14: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_fd_sync */ case 15: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi64_sys_fd_write */ case 16: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "size_t"; break; /* cloudabi_sys_file_advise */ case 17: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_allocate */ case 18: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_create */ case 19: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_link */ case 20: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_open */ case 21: if (ndx == 0 || ndx == 1) p = "cloudabi_fd_t"; break; /* cloudabi_sys_file_readdir */ case 22: if (ndx == 0 || ndx == 1) p = "size_t"; break; /* cloudabi_sys_file_readlink */ case 23: if (ndx == 0 || ndx == 1) p = "size_t"; break; /* cloudabi_sys_file_rename */ case 24: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_stat_fget */ case 25: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_stat_fput */ case 26: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_stat_get */ case 27: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_stat_put */ case 28: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_symlink */ case 29: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_file_unlink */ case 30: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_lock_unlock */ case 31: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_advise */ case 32: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_lock */ case 33: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_map */ case 34: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_protect */ case 35: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_sync */ case 36: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_unlock */ case 37: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_mem_unmap */ case 38: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi64_sys_poll */ case 39: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "size_t"; break; /* cloudabi_sys_proc_exec */ case 40: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_proc_exit */ case 41: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_proc_fork */ case 42: /* cloudabi_sys_proc_raise */ case 43: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_random_get */ case 44: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_sock_accept */ case 45: if (ndx == 0 || ndx == 1) p = "cloudabi_fd_t"; break; /* cloudabi_sys_sock_bind */ case 46: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_sock_connect */ case 47: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_sock_listen */ case 48: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi64_sys_sock_recv */ case 49: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "void"; break; /* cloudabi64_sys_sock_send */ case 50: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "void"; break; /* cloudabi_sys_sock_shutdown */ case 51: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_sock_stat_get */ case 52: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi64_sys_thread_create */ case 53: if (ndx == 0 || ndx == 1) p = "cloudabi_tid_t"; break; /* cloudabi_sys_thread_exit */ case 54: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_thread_tcb_set */ case 55: if (ndx == 0 || ndx == 1) p = "void"; break; /* cloudabi_sys_thread_yield */ case 56: /* cloudabi64_sys_poll_fd */ case 57: if (ndx == 0 || ndx == 1) - p = "cloudabi64_size_t"; + p = "size_t"; break; default: break; }; if (p != NULL) strlcpy(desc, p, descsz); } Index: head/sys/compat/cloudabi64/cloudabi64_thread.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_thread.c (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_thread.c (revision 297247) @@ -1,70 +1,71 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include -#include +#include + #include #include struct thread_create_args { cloudabi64_threadattr_t attr; lwpid_t tid; }; static int initialize_thread(struct thread *td, void *thunk) { struct thread_create_args *args = thunk; /* Save the thread ID, so it can be returned. */ args->tid = td->td_tid; /* Set up initial register contents. */ cloudabi64_thread_setregs(td, &args->attr); return (0); } int cloudabi64_sys_thread_create(struct thread *td, struct cloudabi64_sys_thread_create_args *uap) { struct thread_create_args args; int error; error = copyin(uap->attr, &args.attr, sizeof(args.attr)); if (error != 0) return (error); error = thread_create(td, NULL, initialize_thread, &args); if (error != 0) return (error); td->td_retval[0] = args.tid; return (0); } Index: head/sys/compat/cloudabi64/cloudabi64_util.h =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_util.h (revision 297246) +++ head/sys/compat/cloudabi64/cloudabi64_util.h (revision 297247) @@ -1,48 +1,48 @@ /*- * Copyright (c) 2015 Nuxi, https://nuxi.nl/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _CLOUDABI64_UTIL_H_ #define _CLOUDABI64_UTIL_H_ #include #include -#include +#include struct image_params; struct thread; extern Elf64_Brandinfo cloudabi64_brand; /* Stack initialization during process execution. */ register_t *cloudabi64_copyout_strings(struct image_params *); int cloudabi64_fixup(register_t **, struct image_params *); void cloudabi64_thread_setregs(struct thread *, const cloudabi64_threadattr_t *); #endif Index: head/sys/contrib/cloudabi/syscalldefs_md.h =================================================================== --- head/sys/contrib/cloudabi/syscalldefs_md.h (revision 297246) +++ head/sys/contrib/cloudabi/syscalldefs_md.h (nonexistent) @@ -1,255 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. - -// Machine dependent definitions. - -// Macro to force sane alignment rules. -// -// On x86-32 it is the case that 64-bit integers are 4-byte aligned when -// embedded in structs, even though they are 8-byte aligned when not -// embedded. Force 8-byte alignment explicitly. -#define MEMBER(type) alignas(alignof(type)) type -#define ASSERT_OFFSET(type, field, offset32, offset64) \ - static_assert((sizeof(PTR(void)) == 4 && \ - offsetof(IDENT(type), field) == (offset32)) || \ - (sizeof(PTR(void)) == 8 && \ - offsetof(IDENT(type), field) == (offset64)), \ - "Offset incorrect") -#define ASSERT_SIZE(type, size32, size64) \ - static_assert( \ - (sizeof(PTR(void)) == 4 && sizeof(IDENT(type)) == (size32)) || \ - (sizeof(PTR(void)) == 8 && sizeof(IDENT(type)) == (size64)), \ - "Size incorrect") - -typedef void IDENT(threadentry_t)(cloudabi_tid_t, PTR(void)); - -// Auxiliary vector entry, used to provide paramters on startup. -typedef struct { - uint32_t a_type; - union { - MEMBER(IDENT(size_t)) a_val; - MEMBER(PTR(void)) a_ptr; - }; -} IDENT(auxv_t); -ASSERT_OFFSET(auxv_t, a_type, 0, 0); -ASSERT_OFFSET(auxv_t, a_val, 4, 8); -ASSERT_OFFSET(auxv_t, a_ptr, 4, 8); -ASSERT_SIZE(auxv_t, 8, 16); - -typedef struct { - MEMBER(PTR(const void)) iov_base; - MEMBER(IDENT(size_t)) iov_len; -} IDENT(ciovec_t); -ASSERT_OFFSET(ciovec_t, iov_base, 0, 0); -ASSERT_OFFSET(ciovec_t, iov_len, 4, 8); -ASSERT_SIZE(ciovec_t, 8, 16); - -typedef struct { - MEMBER(cloudabi_userdata_t) userdata; - MEMBER(cloudabi_errno_t) error; - MEMBER(cloudabi_eventtype_t) type; - union { - // CLOUDABI_EVENTTYPE_CLOCK: Wait until the value of a clock - // exceeds a value. - struct { - MEMBER(cloudabi_userdata_t) identifier; - } clock; - - // CLOUDABI_EVENTTYPE_CONDVAR: Release a lock and wait on a - // condition variable. - struct { - MEMBER(PTR(_Atomic(cloudabi_condvar_t))) condvar; - } condvar; - - // CLOUDABI_EVENTTYPE_FD_READ and CLOUDABI_EVENTTYPE_FD_WRITE: - // Wait for a file descriptor to allow read() and write() to be - // called without blocking. - struct { - MEMBER(cloudabi_filesize_t) nbytes; - MEMBER(cloudabi_fd_t) fd; - MEMBER(uint16_t) flags; - } fd_readwrite; - - // CLOUDABI_EVENT_LOCK_RDLOCK and CLOUDABI_EVENT_LOCK_WRLOCK: Wait - // and acquire a read or write lock. - struct { - MEMBER(PTR(_Atomic(cloudabi_lock_t))) lock; - } lock; - - // CLOUDABI_EVENTTYPE_PROC_TERMINATE: Wait for a process to terminate. - struct { - MEMBER(cloudabi_fd_t) fd; - MEMBER(cloudabi_signal_t) signal; // Non-zero if process got killed. - MEMBER(cloudabi_exitcode_t) exitcode; // Exit code. - } proc_terminate; - }; -} IDENT(event_t); -ASSERT_OFFSET(event_t, userdata, 0, 0); -ASSERT_OFFSET(event_t, error, 8, 8); -ASSERT_OFFSET(event_t, type, 10, 10); -ASSERT_OFFSET(event_t, clock.identifier, 16, 16); -ASSERT_OFFSET(event_t, condvar.condvar, 16, 16); -ASSERT_OFFSET(event_t, fd_readwrite.nbytes, 16, 16); -ASSERT_OFFSET(event_t, fd_readwrite.fd, 24, 24); -ASSERT_OFFSET(event_t, fd_readwrite.flags, 28, 28); -ASSERT_OFFSET(event_t, lock.lock, 16, 16); -ASSERT_OFFSET(event_t, proc_terminate.fd, 16, 16); -ASSERT_OFFSET(event_t, proc_terminate.signal, 20, 20); -ASSERT_OFFSET(event_t, proc_terminate.exitcode, 24, 24); -ASSERT_SIZE(event_t, 32, 32); - -typedef struct { - MEMBER(PTR(void)) iov_base; - MEMBER(IDENT(size_t)) iov_len; -} IDENT(iovec_t); -ASSERT_OFFSET(iovec_t, iov_base, 0, 0); -ASSERT_OFFSET(iovec_t, iov_len, 4, 8); -ASSERT_SIZE(iovec_t, 8, 16); - -typedef struct { - MEMBER(PTR(const IDENT(iovec_t))) ri_data; // Data I/O vectors. - MEMBER(IDENT(size_t)) ri_datalen; // Number of data I/O vectors. - MEMBER(PTR(cloudabi_fd_t)) ri_fds; // File descriptors. - MEMBER(IDENT(size_t)) ri_fdslen; // Number of file descriptors. - MEMBER(cloudabi_msgflags_t) ri_flags; // Input flags. -} IDENT(recv_in_t); -ASSERT_OFFSET(recv_in_t, ri_data, 0, 0); -ASSERT_OFFSET(recv_in_t, ri_datalen, 4, 8); -ASSERT_OFFSET(recv_in_t, ri_fds, 8, 16); -ASSERT_OFFSET(recv_in_t, ri_fdslen, 12, 24); -ASSERT_OFFSET(recv_in_t, ri_flags, 16, 32); -ASSERT_SIZE(recv_in_t, 20, 40); - -typedef struct { - MEMBER(IDENT(size_t)) ro_datalen; // Bytes of data received. - MEMBER(IDENT(size_t)) ro_fdslen; // Number of file descriptors received. - MEMBER(cloudabi_sockaddr_t) ro_sockname; // Address of receiver. - MEMBER(cloudabi_sockaddr_t) ro_peername; // Address of sender. - MEMBER(cloudabi_msgflags_t) ro_flags; // Output flags. -} IDENT(recv_out_t); -ASSERT_OFFSET(recv_out_t, ro_datalen, 0, 0); -ASSERT_OFFSET(recv_out_t, ro_fdslen, 4, 8); -ASSERT_OFFSET(recv_out_t, ro_sockname, 8, 16); -ASSERT_OFFSET(recv_out_t, ro_peername, 28, 36); -ASSERT_OFFSET(recv_out_t, ro_flags, 48, 56); -ASSERT_SIZE(recv_out_t, 52, 64); - -typedef struct { - MEMBER(PTR(const IDENT(ciovec_t))) si_data; // Data I/O vectors. - MEMBER(IDENT(size_t)) si_datalen; // Number of data I/O vectors. - MEMBER(PTR(const cloudabi_fd_t)) si_fds; // File descriptors. - MEMBER(IDENT(size_t)) si_fdslen; // Number of file descriptors. - MEMBER(cloudabi_msgflags_t) si_flags; // Input flags. -} IDENT(send_in_t); -ASSERT_OFFSET(send_in_t, si_data, 0, 0); -ASSERT_OFFSET(send_in_t, si_datalen, 4, 8); -ASSERT_OFFSET(send_in_t, si_fds, 8, 16); -ASSERT_OFFSET(send_in_t, si_fdslen, 12, 24); -ASSERT_OFFSET(send_in_t, si_flags, 16, 32); -ASSERT_SIZE(send_in_t, 20, 40); - -typedef struct { - MEMBER(IDENT(size_t)) so_datalen; // Bytes of data sent. -} IDENT(send_out_t); -ASSERT_OFFSET(send_out_t, so_datalen, 0, 0); -ASSERT_SIZE(send_out_t, 4, 8); - -typedef struct { - MEMBER(cloudabi_userdata_t) userdata; - MEMBER(uint16_t) flags; - MEMBER(cloudabi_eventtype_t) type; - union { - // CLOUDABI_EVENTTYPE_CLOCK: Wait until the value of a clock - // exceeds a value. - struct { - MEMBER(cloudabi_userdata_t) identifier; - MEMBER(cloudabi_clockid_t) clock_id; - MEMBER(cloudabi_timestamp_t) timeout; - MEMBER(cloudabi_timestamp_t) precision; - MEMBER(uint16_t) flags; - } clock; - - // CLOUDABI_EVENTTYPE_CONDVAR: Release a lock and wait on a - // condition variable. - struct { - MEMBER(PTR(_Atomic(cloudabi_condvar_t))) condvar; - MEMBER(PTR(_Atomic(cloudabi_lock_t))) lock; - MEMBER(cloudabi_mflags_t) condvar_scope; - MEMBER(cloudabi_mflags_t) lock_scope; - } condvar; - - // CLOUDABI_EVENTTYPE_FD_READ and CLOUDABI_EVENTTYPE_FD_WRITE: - // Wait for a file descriptor to allow read() and write() to be - // called without blocking. - struct { - MEMBER(cloudabi_fd_t) fd; - MEMBER(uint16_t) flags; - } fd_readwrite; - - // CLOUDABI_EVENT_LOCK_RDLOCK and CLOUDABI_EVENT_LOCK_WRLOCK: Wait - // and acquire a read or write lock. - struct { - MEMBER(PTR(_Atomic(cloudabi_lock_t))) lock; - MEMBER(cloudabi_mflags_t) lock_scope; - } lock; - - // CLOUDABI_EVENTTYPE_PROC_TERMINATE: Wait for a process to terminate. - struct { - MEMBER(cloudabi_fd_t) fd; - } proc_terminate; - }; -} IDENT(subscription_t); -ASSERT_OFFSET(subscription_t, userdata, 0, 0); -ASSERT_OFFSET(subscription_t, flags, 8, 8); -ASSERT_OFFSET(subscription_t, type, 10, 10); -ASSERT_OFFSET(subscription_t, clock.identifier, 16, 16); -ASSERT_OFFSET(subscription_t, clock.clock_id, 24, 24); -ASSERT_OFFSET(subscription_t, clock.timeout, 32, 32); -ASSERT_OFFSET(subscription_t, clock.precision, 40, 40); -ASSERT_OFFSET(subscription_t, clock.flags, 48, 48); -ASSERT_OFFSET(subscription_t, condvar.condvar, 16, 16); -ASSERT_OFFSET(subscription_t, condvar.lock, 20, 24); -ASSERT_OFFSET(subscription_t, condvar.condvar_scope, 24, 32); -ASSERT_OFFSET(subscription_t, condvar.lock_scope, 25, 33); -ASSERT_OFFSET(subscription_t, fd_readwrite.fd, 16, 16); -ASSERT_OFFSET(subscription_t, fd_readwrite.flags, 20, 20); -ASSERT_OFFSET(subscription_t, lock.lock, 16, 16); -ASSERT_OFFSET(subscription_t, lock.lock_scope, 20, 24); -ASSERT_OFFSET(subscription_t, proc_terminate.fd, 16, 16); -ASSERT_SIZE(subscription_t, 56, 56); - -typedef struct { - MEMBER(PTR(IDENT(threadentry_t))) entry_point; // Entry point. - MEMBER(PTR(void)) stack; // Pointer to stack buffer. - MEMBER(IDENT(size_t)) stack_size; // Size of stack buffer. - MEMBER(PTR(void)) argument; // Argument to be passed to entry point. -} IDENT(threadattr_t); -ASSERT_OFFSET(threadattr_t, entry_point, 0, 0); -ASSERT_OFFSET(threadattr_t, stack, 4, 8); -ASSERT_OFFSET(threadattr_t, stack_size, 8, 16); -ASSERT_OFFSET(threadattr_t, argument, 12, 24); -ASSERT_SIZE(threadattr_t, 16, 32); - -#undef MEMBER -#undef ASSERT_OFFSET -#undef ASSERT_SIZE Property changes on: head/sys/contrib/cloudabi/syscalldefs_md.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/sys/contrib/cloudabi/syscalldefs_mi.h =================================================================== --- head/sys/contrib/cloudabi/syscalldefs_mi.h (revision 297246) +++ head/sys/contrib/cloudabi/syscalldefs_mi.h (nonexistent) @@ -1,476 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. - -#ifndef COMMON_SYSCALLDEFS_MI_H -#define COMMON_SYSCALLDEFS_MI_H - -// Machine independent definitions. - -// Socket address families. -#define CLOUDABI_AF_UNSPEC 0 -#define CLOUDABI_AF_INET 1 -#define CLOUDABI_AF_INET6 2 -#define CLOUDABI_AF_UNIX 3 - -// File and memory I/O advice. -#define CLOUDABI_ADVICE_DONTNEED 1 -#define CLOUDABI_ADVICE_NOREUSE 2 -#define CLOUDABI_ADVICE_NORMAL 3 -#define CLOUDABI_ADVICE_RANDOM 4 -#define CLOUDABI_ADVICE_SEQUENTIAL 5 -#define CLOUDABI_ADVICE_WILLNEED 6 - -// Auxiliary vector entries. All entries that are also part of the -// x86-64 ABI use the same number. All extensions start at 256. -#define CLOUDABI_AT_ARGDATA 256 -#define CLOUDABI_AT_ARGDATALEN 257 -#define CLOUDABI_AT_CANARY 258 -#define CLOUDABI_AT_CANARYLEN 259 -#define CLOUDABI_AT_NCPUS 260 -#define CLOUDABI_AT_NULL 0 -#define CLOUDABI_AT_PAGESZ 6 -#define CLOUDABI_AT_PHDR 3 -#define CLOUDABI_AT_PHNUM 4 -#define CLOUDABI_AT_TID 261 - -// Clocks. -#define CLOUDABI_CLOCK_MONOTONIC 1 -#define CLOUDABI_CLOCK_PROCESS_CPUTIME_ID 2 -#define CLOUDABI_CLOCK_REALTIME 3 -#define CLOUDABI_CLOCK_THREAD_CPUTIME_ID 4 - -// Condition variables. -#define CLOUDABI_CONDVAR_HAS_NO_WAITERS 0 - -// The start of a directory, to be passed to readdir(). -#define CLOUDABI_DIRCOOKIE_START 0 - -// POSIX standard error numbers. -#define CLOUDABI_E2BIG 1 -#define CLOUDABI_EACCES 2 -#define CLOUDABI_EADDRINUSE 3 -#define CLOUDABI_EADDRNOTAVAIL 4 -#define CLOUDABI_EAFNOSUPPORT 5 -#define CLOUDABI_EAGAIN 6 -#define CLOUDABI_EALREADY 7 -#define CLOUDABI_EBADF 8 -#define CLOUDABI_EBADMSG 9 -#define CLOUDABI_EBUSY 10 -#define CLOUDABI_ECANCELED 11 -#define CLOUDABI_ECHILD 12 -#define CLOUDABI_ECONNABORTED 13 -#define CLOUDABI_ECONNREFUSED 14 -#define CLOUDABI_ECONNRESET 15 -#define CLOUDABI_EDEADLK 16 -#define CLOUDABI_EDESTADDRREQ 17 -#define CLOUDABI_EDOM 18 -#define CLOUDABI_EDQUOT 19 -#define CLOUDABI_EEXIST 20 -#define CLOUDABI_EFAULT 21 -#define CLOUDABI_EFBIG 22 -#define CLOUDABI_EHOSTUNREACH 23 -#define CLOUDABI_EIDRM 24 -#define CLOUDABI_EILSEQ 25 -#define CLOUDABI_EINPROGRESS 26 -#define CLOUDABI_EINTR 27 -#define CLOUDABI_EINVAL 28 -#define CLOUDABI_EIO 29 -#define CLOUDABI_EISCONN 30 -#define CLOUDABI_EISDIR 31 -#define CLOUDABI_ELOOP 32 -#define CLOUDABI_EMFILE 33 -#define CLOUDABI_EMLINK 34 -#define CLOUDABI_EMSGSIZE 35 -#define CLOUDABI_EMULTIHOP 36 -#define CLOUDABI_ENAMETOOLONG 37 -#define CLOUDABI_ENETDOWN 38 -#define CLOUDABI_ENETRESET 39 -#define CLOUDABI_ENETUNREACH 40 -#define CLOUDABI_ENFILE 41 -#define CLOUDABI_ENOBUFS 42 -#define CLOUDABI_ENODEV 43 -#define CLOUDABI_ENOENT 44 -#define CLOUDABI_ENOEXEC 45 -#define CLOUDABI_ENOLCK 46 -#define CLOUDABI_ENOLINK 47 -#define CLOUDABI_ENOMEM 48 -#define CLOUDABI_ENOMSG 49 -#define CLOUDABI_ENOPROTOOPT 50 -#define CLOUDABI_ENOSPC 51 -#define CLOUDABI_ENOSYS 52 -#define CLOUDABI_ENOTCONN 53 -#define CLOUDABI_ENOTDIR 54 -#define CLOUDABI_ENOTEMPTY 55 -#define CLOUDABI_ENOTRECOVERABLE 56 -#define CLOUDABI_ENOTSOCK 57 -#define CLOUDABI_ENOTSUP 58 -#define CLOUDABI_ENOTTY 59 -#define CLOUDABI_ENXIO 60 -#define CLOUDABI_EOVERFLOW 61 -#define CLOUDABI_EOWNERDEAD 62 -#define CLOUDABI_EPERM 63 -#define CLOUDABI_EPIPE 64 -#define CLOUDABI_EPROTO 65 -#define CLOUDABI_EPROTONOSUPPORT 66 -#define CLOUDABI_EPROTOTYPE 67 -#define CLOUDABI_ERANGE 68 -#define CLOUDABI_EROFS 69 -#define CLOUDABI_ESPIPE 70 -#define CLOUDABI_ESRCH 71 -#define CLOUDABI_ESTALE 72 -#define CLOUDABI_ETIMEDOUT 73 -#define CLOUDABI_ETXTBSY 74 -#define CLOUDABI_EXDEV 75 - -// Non-standard error numbers. -#define CLOUDABI_ENOTCAPABLE 76 - -#define CLOUDABI_EVENT_FD_READWRITE_HANGUP 0x1 - -// Filter types for cloudabi_eventtype_t. -#define CLOUDABI_EVENTTYPE_CLOCK 1 -#define CLOUDABI_EVENTTYPE_CONDVAR 2 -#define CLOUDABI_EVENTTYPE_FD_READ 3 -#define CLOUDABI_EVENTTYPE_FD_WRITE 4 -#define CLOUDABI_EVENTTYPE_LOCK_RDLOCK 5 -#define CLOUDABI_EVENTTYPE_LOCK_WRLOCK 6 -#define CLOUDABI_EVENTTYPE_PROC_TERMINATE 7 - -// File descriptor behavior flags. -#define CLOUDABI_FDFLAG_APPEND 0x1 -#define CLOUDABI_FDFLAG_DSYNC 0x2 -#define CLOUDABI_FDFLAG_NONBLOCK 0x4 -#define CLOUDABI_FDFLAG_RSYNC 0x8 -#define CLOUDABI_FDFLAG_SYNC 0x10 - -// fdstat_put() flags. -#define CLOUDABI_FDSTAT_FLAGS 0x1 -#define CLOUDABI_FDSTAT_RIGHTS 0x2 - -// filestat_put() flags. -#define CLOUDABI_FILESTAT_ATIM 0x1 -#define CLOUDABI_FILESTAT_ATIM_NOW 0x2 -#define CLOUDABI_FILESTAT_MTIM 0x4 -#define CLOUDABI_FILESTAT_MTIM_NOW 0x8 -#define CLOUDABI_FILESTAT_SIZE 0x10 - -// File types returned through struct stat::st_mode. -#define CLOUDABI_FILETYPE_UNKNOWN 0 -#define CLOUDABI_FILETYPE_BLOCK_DEVICE 0x10 -#define CLOUDABI_FILETYPE_CHARACTER_DEVICE 0x11 -#define CLOUDABI_FILETYPE_DIRECTORY 0x20 -#define CLOUDABI_FILETYPE_FIFO 0x30 -#define CLOUDABI_FILETYPE_POLL 0x40 -#define CLOUDABI_FILETYPE_PROCESS 0x50 -#define CLOUDABI_FILETYPE_REGULAR_FILE 0x60 -#define CLOUDABI_FILETYPE_SHARED_MEMORY 0x70 -#define CLOUDABI_FILETYPE_SOCKET_DGRAM 0x80 -#define CLOUDABI_FILETYPE_SOCKET_SEQPACKET 0x81 -#define CLOUDABI_FILETYPE_SOCKET_STREAM 0x82 -#define CLOUDABI_FILETYPE_SYMBOLIC_LINK 0x90 - -// Read-write lock related constants. -#define CLOUDABI_LOCK_UNLOCKED 0 // Lock is unlocked. -#define CLOUDABI_LOCK_WRLOCKED 0x40000000 // Lock is write locked. -#define CLOUDABI_LOCK_KERNEL_MANAGED 0x80000000 // Lock has waiters. -#define CLOUDABI_LOCK_BOGUS 0x80000000 // Lock is broken. - -// Lookup properties for *at() functions. -#define CLOUDABI_LOOKUP_SYMLINK_FOLLOW (UINT64_C(0x1) << 32) - -// Open flags for openat(), etc. -#define CLOUDABI_O_CREAT 0x1 -#define CLOUDABI_O_DIRECTORY 0x2 -#define CLOUDABI_O_EXCL 0x4 -#define CLOUDABI_O_TRUNC 0x8 - -// File descriptor returned to pdfork()'s child process. -#define CLOUDABI_PROCESS_CHILD 0xffffffff - -// mmap() map flags. -#define CLOUDABI_MAP_ANON 0x1 -#define CLOUDABI_MAP_FIXED 0x2 -#define CLOUDABI_MAP_PRIVATE 0x4 -#define CLOUDABI_MAP_SHARED 0x8 - -// File descriptor that must be passed in when using CLOUDABI_MAP_ANON. -#define CLOUDABI_MAP_ANON_FD 0xffffffff - -// msync() flags. -#define CLOUDABI_MS_ASYNC 0x1 -#define CLOUDABI_MS_INVALIDATE 0x2 -#define CLOUDABI_MS_SYNC 0x4 - -// send() and recv() flags. -#define CLOUDABI_MSG_CTRUNC 0x1 // Control data truncated. -#define CLOUDABI_MSG_EOR 0x2 // Terminates a record. -#define CLOUDABI_MSG_PEEK 0x4 // Leave received data in queue. -#define CLOUDABI_MSG_TRUNC 0x8 // Normal data truncated. -#define CLOUDABI_MSG_WAITALL 0x10 // Attempt to fill the read buffer. - -// mmap()/mprotect() protection flags. -#define CLOUDABI_PROT_EXEC 0x1 -#define CLOUDABI_PROT_WRITE 0x2 -#define CLOUDABI_PROT_READ 0x4 - -// File descriptor capabilities/rights. -#define CLOUDABI_RIGHT_BIT(bit) (UINT64_C(1) << (bit)) -#define CLOUDABI_RIGHT_FD_DATASYNC CLOUDABI_RIGHT_BIT(0) -#define CLOUDABI_RIGHT_FD_READ CLOUDABI_RIGHT_BIT(1) -#define CLOUDABI_RIGHT_FD_SEEK CLOUDABI_RIGHT_BIT(2) -#define CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS CLOUDABI_RIGHT_BIT(3) -#define CLOUDABI_RIGHT_FD_SYNC CLOUDABI_RIGHT_BIT(4) -#define CLOUDABI_RIGHT_FD_TELL CLOUDABI_RIGHT_BIT(5) -#define CLOUDABI_RIGHT_FD_WRITE CLOUDABI_RIGHT_BIT(6) -#define CLOUDABI_RIGHT_FILE_ADVISE CLOUDABI_RIGHT_BIT(7) -#define CLOUDABI_RIGHT_FILE_ALLOCATE CLOUDABI_RIGHT_BIT(8) -#define CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY CLOUDABI_RIGHT_BIT(9) -#define CLOUDABI_RIGHT_FILE_CREATE_FILE CLOUDABI_RIGHT_BIT(10) -#define CLOUDABI_RIGHT_FILE_CREATE_FIFO CLOUDABI_RIGHT_BIT(11) -#define CLOUDABI_RIGHT_FILE_LINK_SOURCE CLOUDABI_RIGHT_BIT(12) -#define CLOUDABI_RIGHT_FILE_LINK_TARGET CLOUDABI_RIGHT_BIT(13) -#define CLOUDABI_RIGHT_FILE_OPEN CLOUDABI_RIGHT_BIT(14) -#define CLOUDABI_RIGHT_FILE_READDIR CLOUDABI_RIGHT_BIT(15) -#define CLOUDABI_RIGHT_FILE_READLINK CLOUDABI_RIGHT_BIT(16) -#define CLOUDABI_RIGHT_FILE_RENAME_SOURCE CLOUDABI_RIGHT_BIT(17) -#define CLOUDABI_RIGHT_FILE_RENAME_TARGET CLOUDABI_RIGHT_BIT(18) -#define CLOUDABI_RIGHT_FILE_STAT_FGET CLOUDABI_RIGHT_BIT(19) -#define CLOUDABI_RIGHT_FILE_STAT_FPUT_SIZE CLOUDABI_RIGHT_BIT(20) -#define CLOUDABI_RIGHT_FILE_STAT_FPUT_TIMES CLOUDABI_RIGHT_BIT(21) -#define CLOUDABI_RIGHT_FILE_STAT_GET CLOUDABI_RIGHT_BIT(22) -#define CLOUDABI_RIGHT_FILE_STAT_PUT_TIMES CLOUDABI_RIGHT_BIT(23) -#define CLOUDABI_RIGHT_FILE_SYMLINK CLOUDABI_RIGHT_BIT(24) -#define CLOUDABI_RIGHT_FILE_UNLINK CLOUDABI_RIGHT_BIT(25) -#define CLOUDABI_RIGHT_MEM_MAP CLOUDABI_RIGHT_BIT(26) -#define CLOUDABI_RIGHT_MEM_MAP_EXEC CLOUDABI_RIGHT_BIT(27) -#define CLOUDABI_RIGHT_POLL_FD_READWRITE CLOUDABI_RIGHT_BIT(28) -#define CLOUDABI_RIGHT_POLL_MODIFY CLOUDABI_RIGHT_BIT(29) -#define CLOUDABI_RIGHT_POLL_PROC_TERMINATE CLOUDABI_RIGHT_BIT(30) -#define CLOUDABI_RIGHT_POLL_WAIT CLOUDABI_RIGHT_BIT(31) -#define CLOUDABI_RIGHT_PROC_EXEC CLOUDABI_RIGHT_BIT(32) -#define CLOUDABI_RIGHT_SOCK_ACCEPT CLOUDABI_RIGHT_BIT(33) -#define CLOUDABI_RIGHT_SOCK_BIND_DIRECTORY CLOUDABI_RIGHT_BIT(34) -#define CLOUDABI_RIGHT_SOCK_BIND_SOCKET CLOUDABI_RIGHT_BIT(35) -#define CLOUDABI_RIGHT_SOCK_CONNECT_DIRECTORY CLOUDABI_RIGHT_BIT(36) -#define CLOUDABI_RIGHT_SOCK_CONNECT_SOCKET CLOUDABI_RIGHT_BIT(37) -#define CLOUDABI_RIGHT_SOCK_LISTEN CLOUDABI_RIGHT_BIT(38) -#define CLOUDABI_RIGHT_SOCK_SHUTDOWN CLOUDABI_RIGHT_BIT(39) -#define CLOUDABI_RIGHT_SOCK_STAT_GET CLOUDABI_RIGHT_BIT(40) - -// Socket shutdown flags. -#define CLOUDABI_SHUT_RD 0x1 -#define CLOUDABI_SHUT_WR 0x2 - -// Signals. -#define CLOUDABI_SIGABRT 1 -#define CLOUDABI_SIGALRM 2 -#define CLOUDABI_SIGBUS 3 -#define CLOUDABI_SIGCHLD 4 -#define CLOUDABI_SIGCONT 5 -#define CLOUDABI_SIGFPE 6 -#define CLOUDABI_SIGHUP 7 -#define CLOUDABI_SIGILL 8 -#define CLOUDABI_SIGINT 9 -#define CLOUDABI_SIGKILL 10 -#define CLOUDABI_SIGPIPE 11 -#define CLOUDABI_SIGQUIT 12 -#define CLOUDABI_SIGSEGV 13 -#define CLOUDABI_SIGSTOP 14 -#define CLOUDABI_SIGSYS 15 -#define CLOUDABI_SIGTERM 16 -#define CLOUDABI_SIGTRAP 17 -#define CLOUDABI_SIGTSTP 18 -#define CLOUDABI_SIGTTIN 19 -#define CLOUDABI_SIGTTOU 20 -#define CLOUDABI_SIGURG 21 -#define CLOUDABI_SIGUSR1 22 -#define CLOUDABI_SIGUSR2 23 -#define CLOUDABI_SIGVTALRM 24 -#define CLOUDABI_SIGXCPU 25 -#define CLOUDABI_SIGXFSZ 26 - -// sockstat() flags. -#define CLOUDABI_SOCKSTAT_CLEAR_ERROR 0x1 - -// sockstat() state. -#define CLOUDABI_SOCKSTAT_ACCEPTCONN 0x1 - -// cloudabi_subscription_t flags. -#define CLOUDABI_SUBSCRIPTION_ADD 0x1 -#define CLOUDABI_SUBSCRIPTION_CLEAR 0x2 -#define CLOUDABI_SUBSCRIPTION_DELETE 0x4 -#define CLOUDABI_SUBSCRIPTION_DISABLE 0x8 -#define CLOUDABI_SUBSCRIPTION_ENABLE 0x10 -#define CLOUDABI_SUBSCRIPTION_ONESHOT 0x20 - -// cloudabi_subscription_t::clock.flags. -#define CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME 0x1 - -// cloudabi_subscription_t::fd_readwrite.flags. -#define CLOUDABI_SUBSCRIPTION_FD_READWRITE_POLL 0x1 - -// unlinkat(). -#define CLOUDABI_UNLINK_REMOVEDIR 0x1 - -// Seeking. -#define CLOUDABI_WHENCE_CUR 1 -#define CLOUDABI_WHENCE_END 2 -#define CLOUDABI_WHENCE_SET 3 - -typedef uint8_t cloudabi_advice_t; // posix_fadvise() and posix_madvise(). -typedef uint32_t cloudabi_backlog_t; // listen(). -typedef uint32_t cloudabi_clockid_t; // clock_*(). -typedef uint32_t cloudabi_condvar_t; // pthread_cond_*(). -typedef uint64_t cloudabi_device_t; // struct stat::st_dev. -typedef uint64_t cloudabi_dircookie_t; // readdir(). -typedef uint16_t cloudabi_errno_t; // errno. -typedef uint8_t cloudabi_eventtype_t; // poll(). -typedef uint32_t cloudabi_exitcode_t; // _exit() and _Exit(). -typedef uint32_t cloudabi_fd_t; // File descriptors. -typedef uint16_t cloudabi_fdflags_t; // cloudabi_fdstat_t. -typedef uint16_t cloudabi_fdsflags_t; // fd_stat_put(). -typedef int64_t cloudabi_filedelta_t; // lseek(). -typedef uint64_t cloudabi_filesize_t; // ftruncate(), struct stat::st_size. -typedef uint8_t cloudabi_filetype_t; // struct stat::st_mode. -typedef uint16_t cloudabi_fsflags_t; // file_stat_put(). -typedef uint64_t cloudabi_inode_t; // struct stat::st_ino. -typedef uint32_t cloudabi_linkcount_t; // struct stat::st_nlink. -typedef uint32_t cloudabi_lock_t; // pthread_{mutex,rwlock}_*(). -typedef uint64_t cloudabi_lookup_t; // openat(), linkat(), etc. -typedef uint8_t cloudabi_mflags_t; // mmap(). -typedef uint8_t cloudabi_mprot_t; // mmap(). -typedef uint8_t cloudabi_msflags_t; // msync(). -typedef uint16_t cloudabi_msgflags_t; // send() and recv(). -typedef uint32_t cloudabi_nthreads_t; // pthread_cond_*(). -typedef uint16_t cloudabi_oflags_t; // openat(), etc. -typedef uint64_t cloudabi_rights_t; // File descriptor rights. -typedef uint8_t cloudabi_sa_family_t; // Socket address family. -typedef uint8_t cloudabi_sdflags_t; // shutdown(). -typedef uint8_t cloudabi_ssflags_t; // sockstat(). -typedef uint8_t cloudabi_signal_t; // raise(). -typedef uint32_t cloudabi_tid_t; // Thread ID. -typedef uint64_t cloudabi_timestamp_t; // clock_*(), struct stat::st_*tim. -typedef uint8_t cloudabi_ulflags_t; // unlinkat(). -typedef uint64_t cloudabi_userdata_t; // User-supplied data for callbacks. -typedef uint8_t cloudabi_whence_t; // lseek(). - -// Macro to force sane alignment rules. -// -// On x86-32 it is the case that 64-bit integers are 4-byte aligned when -// embedded in structs, even though they are 8-byte aligned when not -// embedded. Force 8-byte alignment explicitly. -#define MEMBER(type) alignas(alignof(type)) type -#define ASSERT_OFFSET(type, field, offset) \ - static_assert(offsetof(cloudabi_##type, field) == (offset), \ - "Offset incorrect") -#define ASSERT_SIZE(type, size) \ - static_assert(sizeof(cloudabi_##type) == (size), "Size incorrect") - -// Directory entries. -typedef struct { - MEMBER(cloudabi_dircookie_t) d_next; // Cookie of the next entry. - MEMBER(cloudabi_inode_t) d_ino; // Inode number of the current entry. - MEMBER(uint32_t) d_namlen; // Length of the name of the current entry. - MEMBER(cloudabi_filetype_t) d_type; // File type of the current entry. -} cloudabi_dirent_t; -ASSERT_OFFSET(dirent_t, d_next, 0); -ASSERT_OFFSET(dirent_t, d_ino, 8); -ASSERT_OFFSET(dirent_t, d_namlen, 16); -ASSERT_OFFSET(dirent_t, d_type, 20); -ASSERT_SIZE(dirent_t, 24); - -// File descriptor status. -typedef struct { - MEMBER(cloudabi_filetype_t) fs_filetype; // File descriptor type. - MEMBER(cloudabi_fdflags_t) fs_flags; // Non-blocking mode, etc. - MEMBER(cloudabi_rights_t) fs_rights_base; // Base rights. - MEMBER(cloudabi_rights_t) fs_rights_inheriting; // Inheriting rights. -} cloudabi_fdstat_t; -ASSERT_OFFSET(fdstat_t, fs_filetype, 0); -ASSERT_OFFSET(fdstat_t, fs_flags, 2); -ASSERT_OFFSET(fdstat_t, fs_rights_base, 8); -ASSERT_OFFSET(fdstat_t, fs_rights_inheriting, 16); -ASSERT_SIZE(fdstat_t, 24); - -// File status. -typedef struct { - MEMBER(cloudabi_device_t) st_dev; // Device storing the file. - MEMBER(cloudabi_inode_t) st_ino; // Inode of the file. - MEMBER(cloudabi_filetype_t) st_filetype; // File type. - MEMBER(cloudabi_linkcount_t) st_nlink; // Number of hardlinks. - MEMBER(cloudabi_filesize_t) st_size; // Size of the file. - MEMBER(cloudabi_timestamp_t) st_atim; // Access time. - MEMBER(cloudabi_timestamp_t) st_mtim; // Modification time. - MEMBER(cloudabi_timestamp_t) st_ctim; // Change time. -} cloudabi_filestat_t; -ASSERT_OFFSET(filestat_t, st_dev, 0); -ASSERT_OFFSET(filestat_t, st_ino, 8); -ASSERT_OFFSET(filestat_t, st_filetype, 16); -ASSERT_OFFSET(filestat_t, st_nlink, 20); -ASSERT_OFFSET(filestat_t, st_size, 24); -ASSERT_OFFSET(filestat_t, st_atim, 32); -ASSERT_OFFSET(filestat_t, st_mtim, 40); -ASSERT_OFFSET(filestat_t, st_ctim, 48); -ASSERT_SIZE(filestat_t, 56); - -typedef struct { - MEMBER(cloudabi_sa_family_t) sa_family; - union { - struct { - // IPv4 address and port number. - MEMBER(uint8_t) addr[4]; - MEMBER(uint16_t) port; - } sa_inet; - struct { - // IPv6 address and port number. - // TODO(ed): What about the flow info and scope ID? - MEMBER(uint8_t) addr[16]; - MEMBER(uint16_t) port; - } sa_inet6; - }; -} cloudabi_sockaddr_t; -ASSERT_OFFSET(sockaddr_t, sa_family, 0); -ASSERT_OFFSET(sockaddr_t, sa_inet.addr, 2); -ASSERT_OFFSET(sockaddr_t, sa_inet.port, 6); -ASSERT_OFFSET(sockaddr_t, sa_inet6.addr, 2); -ASSERT_OFFSET(sockaddr_t, sa_inet6.port, 18); -ASSERT_SIZE(sockaddr_t, 20); - -// Socket status. -typedef struct { - MEMBER(cloudabi_sockaddr_t) ss_sockname; // Socket address. - MEMBER(cloudabi_sockaddr_t) ss_peername; // Peer address. - MEMBER(cloudabi_errno_t) ss_error; // Current error state. - MEMBER(uint32_t) ss_state; // State flags. -} cloudabi_sockstat_t; -ASSERT_OFFSET(sockstat_t, ss_sockname, 0); -ASSERT_OFFSET(sockstat_t, ss_peername, 20); -ASSERT_OFFSET(sockstat_t, ss_error, 40); -ASSERT_OFFSET(sockstat_t, ss_state, 44); -ASSERT_SIZE(sockstat_t, 48); - -#undef MEMBER -#undef ASSERT_OFFSET -#undef ASSERT_SIZE - -#endif Property changes on: head/sys/contrib/cloudabi/syscalldefs_mi.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/sys/contrib/cloudabi/cloudabi64_types.h =================================================================== --- head/sys/contrib/cloudabi/cloudabi64_types.h (nonexistent) +++ head/sys/contrib/cloudabi/cloudabi64_types.h (revision 297247) @@ -0,0 +1,222 @@ +// Copyright (c) 2016 Nuxi, https://nuxi.nl/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// This file is automatically generated. Do not edit. +// Source: https://github.com/NuxiNL/cloudabi + +#ifndef CLOUDABI64_TYPES_H +#define CLOUDABI64_TYPES_H + +#include "cloudabi_types_common.h" + +typedef struct { + _Alignas(4) cloudabi_auxtype_t a_type; + union { + _Alignas(8) uint64_t a_val; + _Alignas(8) uint64_t a_ptr; + }; +} cloudabi64_auxv_t; +_Static_assert(offsetof(cloudabi64_auxv_t, a_type) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_auxv_t, a_val) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_auxv_t, a_ptr) == 8, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_auxv_t) == 16, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_auxv_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) uint64_t iov_base; + _Alignas(8) uint64_t iov_len; +} cloudabi64_ciovec_t; +_Static_assert(offsetof(cloudabi64_ciovec_t, iov_base) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_ciovec_t, iov_len) == 8, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_ciovec_t) == 16, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_ciovec_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) cloudabi_userdata_t userdata; + _Alignas(2) cloudabi_errno_t error; + _Alignas(1) cloudabi_eventtype_t type; + union { + struct { + _Alignas(8) cloudabi_userdata_t identifier; + } clock; + struct { + _Alignas(8) uint64_t condvar; + } condvar; + struct { + _Alignas(8) cloudabi_filesize_t nbytes; + _Alignas(4) cloudabi_fd_t fd; + _Alignas(2) cloudabi_eventrwflags_t flags; + } fd_readwrite; + struct { + _Alignas(8) uint64_t lock; + } lock; + struct { + _Alignas(4) cloudabi_fd_t fd; + _Alignas(1) cloudabi_signal_t signal; + _Alignas(4) cloudabi_exitcode_t exitcode; + } proc_terminate; + }; +} cloudabi64_event_t; +_Static_assert(offsetof(cloudabi64_event_t, userdata) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, error) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, type) == 10, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, clock.identifier) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, condvar.condvar) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, fd_readwrite.nbytes) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, fd_readwrite.fd) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, fd_readwrite.flags) == 28, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, lock.lock) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, proc_terminate.fd) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, proc_terminate.signal) == 20, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_event_t, proc_terminate.exitcode) == 24, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_event_t) == 32, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_event_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) uint64_t iov_base; + _Alignas(8) uint64_t iov_len; +} cloudabi64_iovec_t; +_Static_assert(offsetof(cloudabi64_iovec_t, iov_base) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_iovec_t, iov_len) == 8, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_iovec_t) == 16, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_iovec_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) uint64_t ri_data; + _Alignas(8) uint64_t ri_datalen; + _Alignas(8) uint64_t ri_fds; + _Alignas(8) uint64_t ri_fdslen; + _Alignas(2) cloudabi_msgflags_t ri_flags; +} cloudabi64_recv_in_t; +_Static_assert(offsetof(cloudabi64_recv_in_t, ri_data) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_in_t, ri_datalen) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_in_t, ri_fds) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_in_t, ri_fdslen) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_in_t, ri_flags) == 32, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_recv_in_t) == 40, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_recv_in_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) uint64_t si_data; + _Alignas(8) uint64_t si_datalen; + _Alignas(8) uint64_t si_fds; + _Alignas(8) uint64_t si_fdslen; + _Alignas(2) cloudabi_msgflags_t si_flags; +} cloudabi64_send_in_t; +_Static_assert(offsetof(cloudabi64_send_in_t, si_data) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_send_in_t, si_datalen) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_send_in_t, si_fds) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_send_in_t, si_fdslen) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_send_in_t, si_flags) == 32, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_send_in_t) == 40, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_send_in_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) uint64_t so_datalen; +} cloudabi64_send_out_t; +_Static_assert(offsetof(cloudabi64_send_out_t, so_datalen) == 0, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_send_out_t) == 8, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_send_out_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) cloudabi_userdata_t userdata; + _Alignas(2) cloudabi_subflags_t flags; + _Alignas(1) cloudabi_eventtype_t type; + union { + struct { + _Alignas(8) cloudabi_userdata_t identifier; + _Alignas(4) cloudabi_clockid_t clock_id; + _Alignas(8) cloudabi_timestamp_t timeout; + _Alignas(8) cloudabi_timestamp_t precision; + _Alignas(2) cloudabi_subclockflags_t flags; + } clock; + struct { + _Alignas(8) uint64_t condvar; + _Alignas(8) uint64_t lock; + _Alignas(1) cloudabi_mflags_t condvar_scope; + _Alignas(1) cloudabi_mflags_t lock_scope; + } condvar; + struct { + _Alignas(4) cloudabi_fd_t fd; + _Alignas(2) cloudabi_subrwflags_t flags; + } fd_readwrite; + struct { + _Alignas(8) uint64_t lock; + _Alignas(1) cloudabi_mflags_t lock_scope; + } lock; + struct { + _Alignas(4) cloudabi_fd_t fd; + } proc_terminate; + }; +} cloudabi64_subscription_t; +_Static_assert(offsetof(cloudabi64_subscription_t, userdata) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, flags) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, type) == 10, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, clock.identifier) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, clock.clock_id) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, clock.timeout) == 32, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, clock.precision) == 40, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, clock.flags) == 48, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, condvar.condvar) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, condvar.lock) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, condvar.condvar_scope) == 32, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, condvar.lock_scope) == 33, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, fd_readwrite.fd) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, fd_readwrite.flags) == 20, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, lock.lock) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, lock.lock_scope) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_subscription_t, proc_terminate.fd) == 16, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_subscription_t) == 56, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_subscription_t) == 8, "Incorrect layout"); + +typedef void cloudabi64_threadentry_t(cloudabi_tid_t tid, uint64_t aux); + +typedef struct { + _Alignas(8) uint64_t ro_datalen; + _Alignas(8) uint64_t ro_fdslen; + _Alignas(2) cloudabi_sockaddr_t ro_sockname; + _Alignas(2) cloudabi_sockaddr_t ro_peername; + _Alignas(2) cloudabi_msgflags_t ro_flags; +} cloudabi64_recv_out_t; +_Static_assert(offsetof(cloudabi64_recv_out_t, ro_datalen) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_out_t, ro_fdslen) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_out_t, ro_sockname) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_out_t, ro_peername) == 36, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_recv_out_t, ro_flags) == 56, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_recv_out_t) == 64, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_recv_out_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) uint64_t entry_point; + _Alignas(8) uint64_t stack; + _Alignas(8) uint64_t stack_size; + _Alignas(8) uint64_t argument; +} cloudabi64_threadattr_t; +_Static_assert(offsetof(cloudabi64_threadattr_t, entry_point) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_threadattr_t, stack) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_threadattr_t, stack_size) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi64_threadattr_t, argument) == 24, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_threadattr_t) == 32, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_threadattr_t) == 8, "Incorrect layout"); + +#endif Property changes on: head/sys/contrib/cloudabi/cloudabi64_types.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/sys/contrib/cloudabi/cloudabi_types_common.h =================================================================== --- head/sys/contrib/cloudabi/cloudabi_types_common.h (nonexistent) +++ head/sys/contrib/cloudabi/cloudabi_types_common.h (revision 297247) @@ -0,0 +1,457 @@ +// Copyright (c) 2016 Nuxi, https://nuxi.nl/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. + +// This file is automatically generated. Do not edit. +// Source: https://github.com/NuxiNL/cloudabi + +#ifndef CLOUDABI_TYPES_COMMON_H +#define CLOUDABI_TYPES_COMMON_H + +#if defined(__FreeBSD__) && defined(_KERNEL) +#include +#elif defined(__linux__) && defined(__KERNEL__) +#include +#else +#include +#include +#endif + +typedef uint8_t cloudabi_advice_t; +#define CLOUDABI_ADVICE_DONTNEED 1 +#define CLOUDABI_ADVICE_NOREUSE 2 +#define CLOUDABI_ADVICE_NORMAL 3 +#define CLOUDABI_ADVICE_RANDOM 4 +#define CLOUDABI_ADVICE_SEQUENTIAL 5 +#define CLOUDABI_ADVICE_WILLNEED 6 + +typedef uint32_t cloudabi_auxtype_t; +#define CLOUDABI_AT_ARGDATA 256 +#define CLOUDABI_AT_ARGDATALEN 257 +#define CLOUDABI_AT_CANARY 258 +#define CLOUDABI_AT_CANARYLEN 259 +#define CLOUDABI_AT_NCPUS 260 +#define CLOUDABI_AT_NULL 0 +#define CLOUDABI_AT_PAGESZ 6 +#define CLOUDABI_AT_PHDR 3 +#define CLOUDABI_AT_PHNUM 4 +#define CLOUDABI_AT_TID 261 + +typedef uint32_t cloudabi_backlog_t; + +typedef uint32_t cloudabi_clockid_t; +#define CLOUDABI_CLOCK_MONOTONIC 1 +#define CLOUDABI_CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOUDABI_CLOCK_REALTIME 3 +#define CLOUDABI_CLOCK_THREAD_CPUTIME_ID 4 + +typedef uint32_t cloudabi_condvar_t; +#define CLOUDABI_CONDVAR_HAS_NO_WAITERS 0 + +typedef uint64_t cloudabi_device_t; + +typedef uint64_t cloudabi_dircookie_t; +#define CLOUDABI_DIRCOOKIE_START 0 + +typedef uint16_t cloudabi_errno_t; +#define CLOUDABI_E2BIG 1 +#define CLOUDABI_EACCES 2 +#define CLOUDABI_EADDRINUSE 3 +#define CLOUDABI_EADDRNOTAVAIL 4 +#define CLOUDABI_EAFNOSUPPORT 5 +#define CLOUDABI_EAGAIN 6 +#define CLOUDABI_EALREADY 7 +#define CLOUDABI_EBADF 8 +#define CLOUDABI_EBADMSG 9 +#define CLOUDABI_EBUSY 10 +#define CLOUDABI_ECANCELED 11 +#define CLOUDABI_ECHILD 12 +#define CLOUDABI_ECONNABORTED 13 +#define CLOUDABI_ECONNREFUSED 14 +#define CLOUDABI_ECONNRESET 15 +#define CLOUDABI_EDEADLK 16 +#define CLOUDABI_EDESTADDRREQ 17 +#define CLOUDABI_EDOM 18 +#define CLOUDABI_EDQUOT 19 +#define CLOUDABI_EEXIST 20 +#define CLOUDABI_EFAULT 21 +#define CLOUDABI_EFBIG 22 +#define CLOUDABI_EHOSTUNREACH 23 +#define CLOUDABI_EIDRM 24 +#define CLOUDABI_EILSEQ 25 +#define CLOUDABI_EINPROGRESS 26 +#define CLOUDABI_EINTR 27 +#define CLOUDABI_EINVAL 28 +#define CLOUDABI_EIO 29 +#define CLOUDABI_EISCONN 30 +#define CLOUDABI_EISDIR 31 +#define CLOUDABI_ELOOP 32 +#define CLOUDABI_EMFILE 33 +#define CLOUDABI_EMLINK 34 +#define CLOUDABI_EMSGSIZE 35 +#define CLOUDABI_EMULTIHOP 36 +#define CLOUDABI_ENAMETOOLONG 37 +#define CLOUDABI_ENETDOWN 38 +#define CLOUDABI_ENETRESET 39 +#define CLOUDABI_ENETUNREACH 40 +#define CLOUDABI_ENFILE 41 +#define CLOUDABI_ENOBUFS 42 +#define CLOUDABI_ENODEV 43 +#define CLOUDABI_ENOENT 44 +#define CLOUDABI_ENOEXEC 45 +#define CLOUDABI_ENOLCK 46 +#define CLOUDABI_ENOLINK 47 +#define CLOUDABI_ENOMEM 48 +#define CLOUDABI_ENOMSG 49 +#define CLOUDABI_ENOPROTOOPT 50 +#define CLOUDABI_ENOSPC 51 +#define CLOUDABI_ENOSYS 52 +#define CLOUDABI_ENOTCONN 53 +#define CLOUDABI_ENOTDIR 54 +#define CLOUDABI_ENOTEMPTY 55 +#define CLOUDABI_ENOTRECOVERABLE 56 +#define CLOUDABI_ENOTSOCK 57 +#define CLOUDABI_ENOTSUP 58 +#define CLOUDABI_ENOTTY 59 +#define CLOUDABI_ENXIO 60 +#define CLOUDABI_EOVERFLOW 61 +#define CLOUDABI_EOWNERDEAD 62 +#define CLOUDABI_EPERM 63 +#define CLOUDABI_EPIPE 64 +#define CLOUDABI_EPROTO 65 +#define CLOUDABI_EPROTONOSUPPORT 66 +#define CLOUDABI_EPROTOTYPE 67 +#define CLOUDABI_ERANGE 68 +#define CLOUDABI_EROFS 69 +#define CLOUDABI_ESPIPE 70 +#define CLOUDABI_ESRCH 71 +#define CLOUDABI_ESTALE 72 +#define CLOUDABI_ETIMEDOUT 73 +#define CLOUDABI_ETXTBSY 74 +#define CLOUDABI_EXDEV 75 +#define CLOUDABI_ENOTCAPABLE 76 + +typedef uint16_t cloudabi_eventrwflags_t; +#define CLOUDABI_EVENT_FD_READWRITE_HANGUP 0x0001 + +typedef uint8_t cloudabi_eventtype_t; +#define CLOUDABI_EVENTTYPE_CLOCK 1 +#define CLOUDABI_EVENTTYPE_CONDVAR 2 +#define CLOUDABI_EVENTTYPE_FD_READ 3 +#define CLOUDABI_EVENTTYPE_FD_WRITE 4 +#define CLOUDABI_EVENTTYPE_LOCK_RDLOCK 5 +#define CLOUDABI_EVENTTYPE_LOCK_WRLOCK 6 +#define CLOUDABI_EVENTTYPE_PROC_TERMINATE 7 + +typedef uint32_t cloudabi_exitcode_t; + +typedef uint32_t cloudabi_fd_t; +#define CLOUDABI_PROCESS_CHILD 0xffffffff +#define CLOUDABI_MAP_ANON_FD 0xffffffff + +typedef uint16_t cloudabi_fdflags_t; +#define CLOUDABI_FDFLAG_APPEND 0x0001 +#define CLOUDABI_FDFLAG_DSYNC 0x0002 +#define CLOUDABI_FDFLAG_NONBLOCK 0x0004 +#define CLOUDABI_FDFLAG_RSYNC 0x0008 +#define CLOUDABI_FDFLAG_SYNC 0x0010 + +typedef uint16_t cloudabi_fdsflags_t; +#define CLOUDABI_FDSTAT_FLAGS 0x0001 +#define CLOUDABI_FDSTAT_RIGHTS 0x0002 + +typedef int64_t cloudabi_filedelta_t; + +typedef uint64_t cloudabi_filesize_t; + +typedef uint8_t cloudabi_filetype_t; +#define CLOUDABI_FILETYPE_UNKNOWN 0 +#define CLOUDABI_FILETYPE_BLOCK_DEVICE 16 +#define CLOUDABI_FILETYPE_CHARACTER_DEVICE 17 +#define CLOUDABI_FILETYPE_DIRECTORY 32 +#define CLOUDABI_FILETYPE_FIFO 48 +#define CLOUDABI_FILETYPE_POLL 64 +#define CLOUDABI_FILETYPE_PROCESS 80 +#define CLOUDABI_FILETYPE_REGULAR_FILE 96 +#define CLOUDABI_FILETYPE_SHARED_MEMORY 112 +#define CLOUDABI_FILETYPE_SOCKET_DGRAM 128 +#define CLOUDABI_FILETYPE_SOCKET_SEQPACKET 129 +#define CLOUDABI_FILETYPE_SOCKET_STREAM 130 +#define CLOUDABI_FILETYPE_SYMBOLIC_LINK 144 + +typedef uint16_t cloudabi_fsflags_t; +#define CLOUDABI_FILESTAT_ATIM 0x0001 +#define CLOUDABI_FILESTAT_ATIM_NOW 0x0002 +#define CLOUDABI_FILESTAT_MTIM 0x0004 +#define CLOUDABI_FILESTAT_MTIM_NOW 0x0008 +#define CLOUDABI_FILESTAT_SIZE 0x0010 + +typedef uint64_t cloudabi_inode_t; + +typedef uint32_t cloudabi_linkcount_t; + +typedef uint32_t cloudabi_lock_t; +#define CLOUDABI_LOCK_UNLOCKED 0x00000000 +#define CLOUDABI_LOCK_WRLOCKED 0x40000000 +#define CLOUDABI_LOCK_KERNEL_MANAGED 0x80000000 +#define CLOUDABI_LOCK_BOGUS 0x80000000 + +typedef uint32_t cloudabi_lookupflags_t; +#define CLOUDABI_LOOKUP_SYMLINK_FOLLOW 0x00000001 + +typedef uint8_t cloudabi_mflags_t; +#define CLOUDABI_MAP_ANON 0x01 +#define CLOUDABI_MAP_FIXED 0x02 +#define CLOUDABI_MAP_PRIVATE 0x04 +#define CLOUDABI_MAP_SHARED 0x08 + +typedef uint8_t cloudabi_mprot_t; +#define CLOUDABI_PROT_EXEC 0x01 +#define CLOUDABI_PROT_WRITE 0x02 +#define CLOUDABI_PROT_READ 0x04 + +typedef uint8_t cloudabi_msflags_t; +#define CLOUDABI_MS_ASYNC 0x01 +#define CLOUDABI_MS_INVALIDATE 0x02 +#define CLOUDABI_MS_SYNC 0x04 + +typedef uint16_t cloudabi_msgflags_t; +#define CLOUDABI_MSG_CTRUNC 0x0001 +#define CLOUDABI_MSG_EOR 0x0002 +#define CLOUDABI_MSG_PEEK 0x0004 +#define CLOUDABI_MSG_TRUNC 0x0008 +#define CLOUDABI_MSG_WAITALL 0x0010 + +typedef uint32_t cloudabi_nthreads_t; + +typedef uint16_t cloudabi_oflags_t; +#define CLOUDABI_O_CREAT 0x0001 +#define CLOUDABI_O_DIRECTORY 0x0002 +#define CLOUDABI_O_EXCL 0x0004 +#define CLOUDABI_O_TRUNC 0x0008 + +typedef uint64_t cloudabi_rights_t; +#define CLOUDABI_RIGHT_FD_DATASYNC 0x0000000000000001 +#define CLOUDABI_RIGHT_FD_READ 0x0000000000000002 +#define CLOUDABI_RIGHT_FD_SEEK 0x0000000000000004 +#define CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS 0x0000000000000008 +#define CLOUDABI_RIGHT_FD_SYNC 0x0000000000000010 +#define CLOUDABI_RIGHT_FD_TELL 0x0000000000000020 +#define CLOUDABI_RIGHT_FD_WRITE 0x0000000000000040 +#define CLOUDABI_RIGHT_FILE_ADVISE 0x0000000000000080 +#define CLOUDABI_RIGHT_FILE_ALLOCATE 0x0000000000000100 +#define CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY 0x0000000000000200 +#define CLOUDABI_RIGHT_FILE_CREATE_FILE 0x0000000000000400 +#define CLOUDABI_RIGHT_FILE_CREATE_FIFO 0x0000000000000800 +#define CLOUDABI_RIGHT_FILE_LINK_SOURCE 0x0000000000001000 +#define CLOUDABI_RIGHT_FILE_LINK_TARGET 0x0000000000002000 +#define CLOUDABI_RIGHT_FILE_OPEN 0x0000000000004000 +#define CLOUDABI_RIGHT_FILE_READDIR 0x0000000000008000 +#define CLOUDABI_RIGHT_FILE_READLINK 0x0000000000010000 +#define CLOUDABI_RIGHT_FILE_RENAME_SOURCE 0x0000000000020000 +#define CLOUDABI_RIGHT_FILE_RENAME_TARGET 0x0000000000040000 +#define CLOUDABI_RIGHT_FILE_STAT_FGET 0x0000000000080000 +#define CLOUDABI_RIGHT_FILE_STAT_FPUT_SIZE 0x0000000000100000 +#define CLOUDABI_RIGHT_FILE_STAT_FPUT_TIMES 0x0000000000200000 +#define CLOUDABI_RIGHT_FILE_STAT_GET 0x0000000000400000 +#define CLOUDABI_RIGHT_FILE_STAT_PUT_TIMES 0x0000000000800000 +#define CLOUDABI_RIGHT_FILE_SYMLINK 0x0000000001000000 +#define CLOUDABI_RIGHT_FILE_UNLINK 0x0000000002000000 +#define CLOUDABI_RIGHT_MEM_MAP 0x0000000004000000 +#define CLOUDABI_RIGHT_MEM_MAP_EXEC 0x0000000008000000 +#define CLOUDABI_RIGHT_POLL_FD_READWRITE 0x0000000010000000 +#define CLOUDABI_RIGHT_POLL_MODIFY 0x0000000020000000 +#define CLOUDABI_RIGHT_POLL_PROC_TERMINATE 0x0000000040000000 +#define CLOUDABI_RIGHT_POLL_WAIT 0x0000000080000000 +#define CLOUDABI_RIGHT_PROC_EXEC 0x0000000100000000 +#define CLOUDABI_RIGHT_SOCK_ACCEPT 0x0000000200000000 +#define CLOUDABI_RIGHT_SOCK_BIND_DIRECTORY 0x0000000400000000 +#define CLOUDABI_RIGHT_SOCK_BIND_SOCKET 0x0000000800000000 +#define CLOUDABI_RIGHT_SOCK_CONNECT_DIRECTORY 0x0000001000000000 +#define CLOUDABI_RIGHT_SOCK_CONNECT_SOCKET 0x0000002000000000 +#define CLOUDABI_RIGHT_SOCK_LISTEN 0x0000004000000000 +#define CLOUDABI_RIGHT_SOCK_SHUTDOWN 0x0000008000000000 +#define CLOUDABI_RIGHT_SOCK_STAT_GET 0x0000010000000000 + +typedef uint8_t cloudabi_sa_family_t; +#define CLOUDABI_AF_UNSPEC 0 +#define CLOUDABI_AF_INET 1 +#define CLOUDABI_AF_INET6 2 +#define CLOUDABI_AF_UNIX 3 + +typedef uint8_t cloudabi_sdflags_t; +#define CLOUDABI_SHUT_RD 0x01 +#define CLOUDABI_SHUT_WR 0x02 + +typedef uint8_t cloudabi_signal_t; +#define CLOUDABI_SIGABRT 1 +#define CLOUDABI_SIGALRM 2 +#define CLOUDABI_SIGBUS 3 +#define CLOUDABI_SIGCHLD 4 +#define CLOUDABI_SIGCONT 5 +#define CLOUDABI_SIGFPE 6 +#define CLOUDABI_SIGHUP 7 +#define CLOUDABI_SIGILL 8 +#define CLOUDABI_SIGINT 9 +#define CLOUDABI_SIGKILL 10 +#define CLOUDABI_SIGPIPE 11 +#define CLOUDABI_SIGQUIT 12 +#define CLOUDABI_SIGSEGV 13 +#define CLOUDABI_SIGSTOP 14 +#define CLOUDABI_SIGSYS 15 +#define CLOUDABI_SIGTERM 16 +#define CLOUDABI_SIGTRAP 17 +#define CLOUDABI_SIGTSTP 18 +#define CLOUDABI_SIGTTIN 19 +#define CLOUDABI_SIGTTOU 20 +#define CLOUDABI_SIGURG 21 +#define CLOUDABI_SIGUSR1 22 +#define CLOUDABI_SIGUSR2 23 +#define CLOUDABI_SIGVTALRM 24 +#define CLOUDABI_SIGXCPU 25 +#define CLOUDABI_SIGXFSZ 26 + +typedef uint8_t cloudabi_ssflags_t; +#define CLOUDABI_SOCKSTAT_CLEAR_ERROR 0x01 + +typedef uint32_t cloudabi_sstate_t; +#define CLOUDABI_SOCKSTATE_ACCEPTCONN 0x00000001 + +typedef uint16_t cloudabi_subclockflags_t; +#define CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME 0x0001 + +typedef uint16_t cloudabi_subflags_t; +#define CLOUDABI_SUBSCRIPTION_ADD 0x0001 +#define CLOUDABI_SUBSCRIPTION_CLEAR 0x0002 +#define CLOUDABI_SUBSCRIPTION_DELETE 0x0004 +#define CLOUDABI_SUBSCRIPTION_DISABLE 0x0008 +#define CLOUDABI_SUBSCRIPTION_ENABLE 0x0010 +#define CLOUDABI_SUBSCRIPTION_ONESHOT 0x0020 + +typedef uint16_t cloudabi_subrwflags_t; +#define CLOUDABI_SUBSCRIPTION_FD_READWRITE_POLL 0x0001 + +typedef uint32_t cloudabi_tid_t; + +typedef uint64_t cloudabi_timestamp_t; + +typedef uint8_t cloudabi_ulflags_t; +#define CLOUDABI_UNLINK_REMOVEDIR 0x01 + +typedef uint64_t cloudabi_userdata_t; + +typedef uint8_t cloudabi_whence_t; +#define CLOUDABI_WHENCE_CUR 1 +#define CLOUDABI_WHENCE_END 2 +#define CLOUDABI_WHENCE_SET 3 + +typedef struct { + _Alignas(8) cloudabi_dircookie_t d_next; + _Alignas(8) cloudabi_inode_t d_ino; + _Alignas(4) uint32_t d_namlen; + _Alignas(1) cloudabi_filetype_t d_type; +} cloudabi_dirent_t; +_Static_assert(offsetof(cloudabi_dirent_t, d_next) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_dirent_t, d_ino) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_dirent_t, d_namlen) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_dirent_t, d_type) == 20, "Incorrect layout"); +_Static_assert(sizeof(cloudabi_dirent_t) == 24, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi_dirent_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(1) cloudabi_filetype_t fs_filetype; + _Alignas(2) cloudabi_fdflags_t fs_flags; + _Alignas(8) cloudabi_rights_t fs_rights_base; + _Alignas(8) cloudabi_rights_t fs_rights_inheriting; +} cloudabi_fdstat_t; +_Static_assert(offsetof(cloudabi_fdstat_t, fs_filetype) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_fdstat_t, fs_flags) == 2, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_fdstat_t, fs_rights_base) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_fdstat_t, fs_rights_inheriting) == 16, "Incorrect layout"); +_Static_assert(sizeof(cloudabi_fdstat_t) == 24, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi_fdstat_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(8) cloudabi_device_t st_dev; + _Alignas(8) cloudabi_inode_t st_ino; + _Alignas(1) cloudabi_filetype_t st_filetype; + _Alignas(4) cloudabi_linkcount_t st_nlink; + _Alignas(8) cloudabi_filesize_t st_size; + _Alignas(8) cloudabi_timestamp_t st_atim; + _Alignas(8) cloudabi_timestamp_t st_mtim; + _Alignas(8) cloudabi_timestamp_t st_ctim; +} cloudabi_filestat_t; +_Static_assert(offsetof(cloudabi_filestat_t, st_dev) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_ino) == 8, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_filetype) == 16, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_nlink) == 20, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_size) == 24, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_atim) == 32, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_mtim) == 40, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_filestat_t, st_ctim) == 48, "Incorrect layout"); +_Static_assert(sizeof(cloudabi_filestat_t) == 56, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi_filestat_t) == 8, "Incorrect layout"); + +typedef struct { + _Alignas(4) cloudabi_fd_t fd; + _Alignas(4) cloudabi_lookupflags_t flags; +} cloudabi_lookup_t; +_Static_assert(offsetof(cloudabi_lookup_t, fd) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_lookup_t, flags) == 4, "Incorrect layout"); +_Static_assert(sizeof(cloudabi_lookup_t) == 8, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi_lookup_t) == 4, "Incorrect layout"); + +typedef struct { + _Alignas(1) cloudabi_sa_family_t sa_family; + union { + struct { + _Alignas(1) uint8_t addr[4]; + _Alignas(2) uint16_t port; + } sa_inet; + struct { + _Alignas(1) uint8_t addr[16]; + _Alignas(2) uint16_t port; + } sa_inet6; + }; +} cloudabi_sockaddr_t; +_Static_assert(offsetof(cloudabi_sockaddr_t, sa_family) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockaddr_t, sa_inet.addr) == 2, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockaddr_t, sa_inet.port) == 6, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockaddr_t, sa_inet6.addr) == 2, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockaddr_t, sa_inet6.port) == 18, "Incorrect layout"); +_Static_assert(sizeof(cloudabi_sockaddr_t) == 20, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi_sockaddr_t) == 2, "Incorrect layout"); + +typedef struct { + _Alignas(2) cloudabi_sockaddr_t ss_sockname; + _Alignas(2) cloudabi_sockaddr_t ss_peername; + _Alignas(2) cloudabi_errno_t ss_error; + _Alignas(4) cloudabi_sstate_t ss_state; +} cloudabi_sockstat_t; +_Static_assert(offsetof(cloudabi_sockstat_t, ss_sockname) == 0, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockstat_t, ss_peername) == 20, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockstat_t, ss_error) == 40, "Incorrect layout"); +_Static_assert(offsetof(cloudabi_sockstat_t, ss_state) == 44, "Incorrect layout"); +_Static_assert(sizeof(cloudabi_sockstat_t) == 48, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi_sockstat_t) == 4, "Incorrect layout"); + +#endif Property changes on: head/sys/contrib/cloudabi/cloudabi_types_common.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/sys/contrib/cloudabi/syscalls.master =================================================================== --- head/sys/contrib/cloudabi/syscalls.master (nonexistent) +++ head/sys/contrib/cloudabi/syscalls.master (revision 297247) @@ -0,0 +1,317 @@ + $FreeBSD$ + +; Copyright (c) 2016 Nuxi, https://nuxi.nl/ +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +; This file is automatically generated. Do not edit. +; Source: https://github.com/NuxiNL/cloudabi + +#include +#include + +#include + +#include + +0 AUE_NULL STD { cloudabi_timestamp_t \ + cloudabi_sys_clock_res_get( \ + cloudabi_clockid_t clock_id); } + +1 AUE_NULL STD { cloudabi_timestamp_t \ + cloudabi_sys_clock_time_get( \ + cloudabi_clockid_t clock_id, \ + cloudabi_timestamp_t precision); } + +2 AUE_NULL STD { void cloudabi_sys_condvar_signal( \ + cloudabi_condvar_t *condvar, \ + cloudabi_mflags_t scope, \ + cloudabi_nthreads_t nwaiters); } + +3 AUE_NULL STD { void cloudabi_sys_fd_close( \ + cloudabi_fd_t fd); } + +4 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_fd_create1( \ + cloudabi_filetype_t type); } + +5 AUE_NULL STD { void cloudabi_sys_fd_create2( \ + cloudabi_filetype_t type); } + +6 AUE_NULL STD { void cloudabi_sys_fd_datasync( \ + cloudabi_fd_t fd); } + +7 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_fd_dup( \ + cloudabi_fd_t from); } + +8 AUE_NULL STD { size_t cloudabi64_sys_fd_pread( \ + cloudabi_fd_t fd, \ + const cloudabi64_iovec_t *iov, \ + size_t iovcnt, \ + cloudabi_filesize_t offset); } + +9 AUE_NULL STD { size_t cloudabi64_sys_fd_pwrite( \ + cloudabi_fd_t fd, \ + const cloudabi64_ciovec_t *iov, \ + size_t iovcnt, \ + cloudabi_filesize_t offset); } + +10 AUE_NULL STD { size_t cloudabi64_sys_fd_read( \ + cloudabi_fd_t fd, \ + const cloudabi64_iovec_t *iov, \ + size_t iovcnt); } + +11 AUE_NULL STD { void cloudabi_sys_fd_replace( \ + cloudabi_fd_t from, \ + cloudabi_fd_t to); } + +12 AUE_NULL STD { cloudabi_filesize_t \ + cloudabi_sys_fd_seek( \ + cloudabi_fd_t fd, \ + cloudabi_filedelta_t offset, \ + cloudabi_whence_t whence); } + +13 AUE_NULL STD { void cloudabi_sys_fd_stat_get( \ + cloudabi_fd_t fd, \ + cloudabi_fdstat_t *buf); } + +14 AUE_NULL STD { void cloudabi_sys_fd_stat_put( \ + cloudabi_fd_t fd, \ + const cloudabi_fdstat_t *buf, \ + cloudabi_fdsflags_t flags); } + +15 AUE_NULL STD { void cloudabi_sys_fd_sync( \ + cloudabi_fd_t fd); } + +16 AUE_NULL STD { size_t cloudabi64_sys_fd_write( \ + cloudabi_fd_t fd, \ + const cloudabi64_ciovec_t *iov, \ + size_t iovcnt); } + +17 AUE_NULL STD { void cloudabi_sys_file_advise( \ + cloudabi_fd_t fd, \ + cloudabi_filesize_t offset, \ + cloudabi_filesize_t len, \ + cloudabi_advice_t advice); } + +18 AUE_NULL STD { void cloudabi_sys_file_allocate( \ + cloudabi_fd_t fd, \ + cloudabi_filesize_t offset, \ + cloudabi_filesize_t len); } + +19 AUE_NULL STD { void cloudabi_sys_file_create( \ + cloudabi_fd_t fd, \ + const char *path, \ + size_t pathlen, \ + cloudabi_filetype_t type); } + +20 AUE_NULL STD { void cloudabi_sys_file_link( \ + cloudabi_lookup_t fd1, \ + const char *path1, \ + size_t path1len, \ + cloudabi_fd_t fd2, \ + const char *path2, \ + size_t path2len); } + +21 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_file_open( \ + cloudabi_lookup_t dirfd, \ + const char *path, \ + size_t pathlen, \ + cloudabi_oflags_t oflags, \ + const cloudabi_fdstat_t *fds); } + +22 AUE_NULL STD { size_t cloudabi_sys_file_readdir( \ + cloudabi_fd_t fd, \ + void *buf, \ + size_t nbyte, \ + cloudabi_dircookie_t cookie); } + +23 AUE_NULL STD { size_t cloudabi_sys_file_readlink( \ + cloudabi_fd_t fd, \ + const char *path, \ + size_t pathlen, \ + char *buf, \ + size_t bufsize); } + +24 AUE_NULL STD { void cloudabi_sys_file_rename( \ + cloudabi_fd_t oldfd, \ + const char *old, \ + size_t oldlen, \ + cloudabi_fd_t newfd, \ + const char *new, \ + size_t newlen); } + +25 AUE_NULL STD { void cloudabi_sys_file_stat_fget( \ + cloudabi_fd_t fd, \ + cloudabi_filestat_t *buf); } + +26 AUE_NULL STD { void cloudabi_sys_file_stat_fput( \ + cloudabi_fd_t fd, \ + const cloudabi_filestat_t *buf, \ + cloudabi_fsflags_t flags); } + +27 AUE_NULL STD { void cloudabi_sys_file_stat_get( \ + cloudabi_lookup_t fd, \ + const char *path, \ + size_t pathlen, \ + cloudabi_filestat_t *buf); } + +28 AUE_NULL STD { void cloudabi_sys_file_stat_put( \ + cloudabi_lookup_t fd, \ + const char *path, \ + size_t pathlen, \ + const cloudabi_filestat_t *buf, \ + cloudabi_fsflags_t flags); } + +29 AUE_NULL STD { void cloudabi_sys_file_symlink( \ + const char *path1, \ + size_t path1len, \ + cloudabi_fd_t fd, \ + const char *path2, \ + size_t path2len); } + +30 AUE_NULL STD { void cloudabi_sys_file_unlink( \ + cloudabi_fd_t fd, \ + const char *path, \ + size_t pathlen, \ + cloudabi_ulflags_t flags); } + +31 AUE_NULL STD { void cloudabi_sys_lock_unlock( \ + cloudabi_lock_t *lock, \ + cloudabi_mflags_t scope); } + +32 AUE_NULL STD { void cloudabi_sys_mem_advise( \ + void *addr, \ + size_t len, \ + cloudabi_advice_t advice); } + +33 AUE_NULL STD { void cloudabi_sys_mem_lock( \ + const void *addr, \ + size_t len); } + +34 AUE_NULL STD { void cloudabi_sys_mem_map( \ + void *addr, \ + size_t len, \ + cloudabi_mprot_t prot, \ + cloudabi_mflags_t flags, \ + cloudabi_fd_t fd, \ + cloudabi_filesize_t off); } + +35 AUE_NULL STD { void cloudabi_sys_mem_protect( \ + void *addr, \ + size_t len, \ + cloudabi_mprot_t prot); } + +36 AUE_NULL STD { void cloudabi_sys_mem_sync( \ + void *addr, \ + size_t len, \ + cloudabi_msflags_t flags); } + +37 AUE_NULL STD { void cloudabi_sys_mem_unlock( \ + const void *addr, \ + size_t len); } + +38 AUE_NULL STD { void cloudabi_sys_mem_unmap( \ + void *addr, \ + size_t len); } + +39 AUE_NULL STD { size_t cloudabi64_sys_poll( \ + const cloudabi64_subscription_t *in, \ + cloudabi64_event_t *out, \ + size_t nsubscriptions); } + +40 AUE_NULL STD { void cloudabi_sys_proc_exec( \ + cloudabi_fd_t fd, \ + const void *data, \ + size_t datalen, \ + const cloudabi_fd_t *fds, \ + size_t fdslen); } + +41 AUE_NULL STD { void cloudabi_sys_proc_exit( \ + cloudabi_exitcode_t rval); } + +42 AUE_NULL STD { void cloudabi_sys_proc_fork(); } + +43 AUE_NULL STD { void cloudabi_sys_proc_raise( \ + cloudabi_signal_t sig); } + +44 AUE_NULL STD { void cloudabi_sys_random_get( \ + void *buf, \ + size_t nbyte); } + +45 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_sock_accept( \ + cloudabi_fd_t sock, \ + cloudabi_sockstat_t *buf); } + +46 AUE_NULL STD { void cloudabi_sys_sock_bind( \ + cloudabi_fd_t sock, \ + cloudabi_fd_t fd, \ + const char *path, \ + size_t pathlen); } + +47 AUE_NULL STD { void cloudabi_sys_sock_connect( \ + cloudabi_fd_t sock, \ + cloudabi_fd_t fd, \ + const char *path, \ + size_t pathlen); } + +48 AUE_NULL STD { void cloudabi_sys_sock_listen( \ + cloudabi_fd_t sock, \ + cloudabi_backlog_t backlog); } + +49 AUE_NULL STD { void cloudabi64_sys_sock_recv( \ + cloudabi_fd_t sock, \ + const cloudabi64_recv_in_t *in, \ + cloudabi64_recv_out_t *out); } + +50 AUE_NULL STD { void cloudabi64_sys_sock_send( \ + cloudabi_fd_t sock, \ + const cloudabi64_send_in_t *in, \ + cloudabi64_send_out_t *out); } + +51 AUE_NULL STD { void cloudabi_sys_sock_shutdown( \ + cloudabi_fd_t sock, \ + cloudabi_sdflags_t how); } + +52 AUE_NULL STD { void cloudabi_sys_sock_stat_get( \ + cloudabi_fd_t sock, \ + cloudabi_sockstat_t *buf, \ + cloudabi_ssflags_t flags); } + +53 AUE_NULL STD { cloudabi_tid_t cloudabi64_sys_thread_create( \ + cloudabi64_threadattr_t *attr); } + +54 AUE_NULL STD { void cloudabi_sys_thread_exit( \ + cloudabi_lock_t *lock, \ + cloudabi_mflags_t scope); } + +55 AUE_NULL STD { void cloudabi_sys_thread_tcb_set( \ + void *tcb); } + +56 AUE_NULL STD { void cloudabi_sys_thread_yield(); } + +57 AUE_NULL STD { size_t cloudabi64_sys_poll_fd( \ + cloudabi_fd_t fd, \ + const cloudabi64_subscription_t *in, \ + size_t nin, \ + cloudabi64_event_t *out, \ + size_t nout, \ + const cloudabi64_subscription_t *timeout); } Index: head/usr.bin/truss/syscalls.c =================================================================== --- head/usr.bin/truss/syscalls.c (revision 297246) +++ head/usr.bin/truss/syscalls.c (revision 297247) @@ -1,2114 +1,2114 @@ /* * Copyright 1997 Sean Eric Fagan * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Sean Eric Fagan * 4. Neither the name of the author may be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * This file has routines used to print out system calls and their * arguments. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include +#include #include "truss.h" #include "extern.h" #include "syscall.h" /* 64-bit alignment on 32-bit platforms. */ #if !defined(__LP64__) && defined(__powerpc__) #define QUAD_ALIGN 1 #else #define QUAD_ALIGN 0 #endif /* Number of slots needed for a 64-bit argument. */ #ifdef __LP64__ #define QUAD_SLOTS 1 #else #define QUAD_SLOTS 2 #endif /* * This should probably be in its own file, sorted alphabetically. */ static struct syscall decoded_syscalls[] = { /* Native ABI */ { .name = "__getcwd", .ret_type = 1, .nargs = 2, .args = { { Name | OUT, 0 }, { Int, 1 } } }, { .name = "_umtx_op", .ret_type = 1, .nargs = 5, .args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 }, { Ptr, 4 } } }, { .name = "accept", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } }, { .name = "access", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Accessmode, 1 } } }, { .name = "bind", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Int, 2 } } }, { .name = "bindat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 }, { Int, 3 } } }, { .name = "break", .ret_type = 1, .nargs = 1, .args = { { Ptr, 0 } } }, { .name = "chdir", .ret_type = 1, .nargs = 1, .args = { { Name, 0 } } }, { .name = "chflags", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Hex, 1 } } }, { .name = "chmod", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Octal, 1 } } }, { .name = "chown", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } }, { .name = "chroot", .ret_type = 1, .nargs = 1, .args = { { Name, 0 } } }, { .name = "clock_gettime", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Timespec | OUT, 1 } } }, { .name = "close", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "connect", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Int, 2 } } }, { .name = "connectat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 }, { Int, 3 } } }, { .name = "eaccess", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Accessmode, 1 } } }, { .name = "execve", .ret_type = 1, .nargs = 3, .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 }, { ExecEnv | IN, 2 } } }, { .name = "exit", .ret_type = 0, .nargs = 1, .args = { { Hex, 0 } } }, { .name = "faccessat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name | IN, 1 }, { Accessmode, 2 }, { Atflags, 3 } } }, { .name = "fchmod", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Octal, 1 } } }, { .name = "fchmodat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Atflags, 3 } } }, { .name = "fchown", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } }, { .name = "fchownat", .ret_type = 1, .nargs = 5, .args = { { Atfd, 0 }, { Name, 1 }, { Int, 2 }, { Int, 3 }, { Atflags, 4 } } }, { .name = "fcntl", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } }, { .name = "fstat", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Stat | OUT, 1 } } }, { .name = "fstatat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat | OUT, 2 }, { Atflags, 3 } } }, { .name = "fstatfs", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { StatFs | OUT, 1 } } }, { .name = "ftruncate", .ret_type = 1, .nargs = 2, .args = { { Int | IN, 0 }, { QuadHex | IN, 1 + QUAD_ALIGN } } }, { .name = "futimens", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Timespec2 | IN, 1 } } }, { .name = "futimes", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Timeval2 | IN, 1 } } }, { .name = "futimesat", .ret_type = 1, .nargs = 3, .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timeval2 | IN, 2 } } }, { .name = "getitimer", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Itimerval | OUT, 2 } } }, { .name = "getpeername", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } }, { .name = "getpgid", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "getrlimit", .ret_type = 1, .nargs = 2, .args = { { Resource, 0 }, { Rlimit | OUT, 1 } } }, { .name = "getrusage", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Rusage | OUT, 1 } } }, { .name = "getsid", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "getsockname", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } }, { .name = "gettimeofday", .ret_type = 1, .nargs = 2, .args = { { Timeval | OUT, 0 }, { Ptr, 1 } } }, { .name = "ioctl", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Ioctl, 1 }, { Hex, 2 } } }, { .name = "kevent", .ret_type = 1, .nargs = 6, .args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 }, { Int, 4 }, { Timespec, 5 } } }, { .name = "kill", .ret_type = 1, .nargs = 2, .args = { { Int | IN, 0 }, { Signal | IN, 1 } } }, { .name = "kldfind", .ret_type = 1, .nargs = 1, .args = { { Name | IN, 0 } } }, { .name = "kldfirstmod", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "kldload", .ret_type = 1, .nargs = 1, .args = { { Name | IN, 0 } } }, { .name = "kldnext", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "kldstat", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Ptr, 1 } } }, { .name = "kldunload", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "kse_release", .ret_type = 0, .nargs = 1, .args = { { Timespec, 0 } } }, { .name = "lchflags", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Hex, 1 } } }, { .name = "lchmod", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Octal, 1 } } }, { .name = "lchown", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } }, { .name = "link", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Name, 1 } } }, { .name = "linkat", .ret_type = 1, .nargs = 5, .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 }, { Atflags, 4 } } }, { .name = "lseek", .ret_type = 2, .nargs = 3, .args = { { Int, 0 }, { QuadHex, 1 + QUAD_ALIGN }, { Whence, 1 + QUAD_SLOTS + QUAD_ALIGN } } }, { .name = "lstat", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } }, { .name = "lutimes", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } }, { .name = "mkdir", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Octal, 1 } } }, { .name = "mkdirat", .ret_type = 1, .nargs = 3, .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } }, { .name = "mkfifo", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Octal, 1 } } }, { .name = "mkfifoat", .ret_type = 1, .nargs = 3, .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } }, { .name = "mknod", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Octal, 1 }, { Int, 2 } } }, { .name = "mknodat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Int, 3 } } }, { .name = "mmap", .ret_type = 1, .nargs = 6, .args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 }, { Mmapflags, 3 }, { Int, 4 }, { QuadHex, 5 + QUAD_ALIGN } } }, { .name = "modfind", .ret_type = 1, .nargs = 1, .args = { { Name | IN, 0 } } }, { .name = "mount", .ret_type = 1, .nargs = 4, .args = { { Name, 0 }, { Name, 1 }, { Int, 2 }, { Ptr, 3 } } }, { .name = "mprotect", .ret_type = 1, .nargs = 3, .args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 } } }, { .name = "munmap", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { Int, 1 } } }, { .name = "nanosleep", .ret_type = 1, .nargs = 1, .args = { { Timespec, 0 } } }, { .name = "open", .ret_type = 1, .nargs = 3, .args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } }, { .name = "openat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 }, { Octal, 3 } } }, { .name = "pathconf", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Pathconf, 1 } } }, { .name = "pipe", .ret_type = 1, .nargs = 1, .args = { { PipeFds | OUT, 0 } } }, { .name = "pipe2", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { Open, 1 } } }, { .name = "poll", .ret_type = 1, .nargs = 3, .args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } }, { .name = "posix_openpt", .ret_type = 1, .nargs = 1, .args = { { Open, 0 } } }, { .name = "procctl", .ret_type = 1, .nargs = 4, .args = { { Idtype, 0 }, { Quad, 1 + QUAD_ALIGN }, { Procctl, 1 + QUAD_ALIGN + QUAD_SLOTS }, { Ptr, 2 + QUAD_ALIGN + QUAD_SLOTS } } }, { .name = "read", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 } } }, { .name = "readlink", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Int, 2 } } }, { .name = "readlinkat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 }, { Int, 3 } } }, { .name = "recvfrom", .ret_type = 1, .nargs = 6, .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 }, { Hex, 3 }, { Sockaddr | OUT, 4 }, { Ptr | OUT, 5 } } }, { .name = "rename", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Name, 1 } } }, { .name = "renameat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } }, { .name = "rfork", .ret_type = 1, .nargs = 1, .args = { { Rforkflags, 0 } } }, { .name = "select", .ret_type = 1, .nargs = 5, .args = { { Int, 0 }, { Fd_set, 1 }, { Fd_set, 2 }, { Fd_set, 3 }, { Timeval, 4 } } }, { .name = "sendto", .ret_type = 1, .nargs = 6, .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, { Hex, 3 }, { Sockaddr | IN, 4 }, { Ptr | IN, 5 } } }, { .name = "setitimer", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Itimerval, 1 }, { Itimerval | OUT, 2 } } }, { .name = "setrlimit", .ret_type = 1, .nargs = 2, .args = { { Resource, 0 }, { Rlimit | IN, 1 } } }, { .name = "shutdown", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Shutdown, 1 } } }, { .name = "sigaction", .ret_type = 1, .nargs = 3, .args = { { Signal, 0 }, { Sigaction | IN, 1 }, { Sigaction | OUT, 2 } } }, { .name = "sigpending", .ret_type = 1, .nargs = 1, .args = { { Sigset | OUT, 0 } } }, { .name = "sigprocmask", .ret_type = 1, .nargs = 3, .args = { { Sigprocmask, 0 }, { Sigset, 1 }, { Sigset | OUT, 2 } } }, { .name = "sigqueue", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Signal, 1 }, { LongHex, 2 } } }, { .name = "sigreturn", .ret_type = 1, .nargs = 1, .args = { { Ptr, 0 } } }, { .name = "sigsuspend", .ret_type = 1, .nargs = 1, .args = { { Sigset | IN, 0 } } }, { .name = "sigtimedwait", .ret_type = 1, .nargs = 3, .args = { { Sigset | IN, 0 }, { Ptr, 1 }, { Timespec | IN, 2 } } }, { .name = "sigwait", .ret_type = 1, .nargs = 2, .args = { { Sigset | IN, 0 }, { Ptr, 1 } } }, { .name = "sigwaitinfo", .ret_type = 1, .nargs = 2, .args = { { Sigset | IN, 0 }, { Ptr, 1 } } }, { .name = "socket", .ret_type = 1, .nargs = 3, .args = { { Sockdomain, 0 }, { Socktype, 1 }, { Int, 2 } } }, { .name = "stat", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } }, { .name = "statfs", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } }, { .name = "symlink", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Name, 1 } } }, { .name = "symlinkat", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } }, { .name = "sysarch", .ret_type = 1, .nargs = 2, .args = { { Sysarch, 0 }, { Ptr, 1 } } }, { .name = "thr_kill", .ret_type = 1, .nargs = 2, .args = { { Long, 0 }, { Signal, 1 } } }, { .name = "thr_self", .ret_type = 1, .nargs = 1, .args = { { Ptr, 0 } } }, { .name = "truncate", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { QuadHex | IN, 1 + QUAD_ALIGN } } }, #if 0 /* Does not exist */ { .name = "umount", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Int, 2 } } }, #endif { .name = "unlink", .ret_type = 1, .nargs = 1, .args = { { Name, 0 } } }, { .name = "unlinkat", .ret_type = 1, .nargs = 3, .args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } }, { .name = "unmount", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Int, 1 } } }, { .name = "utimensat", .ret_type = 1, .nargs = 4, .args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 }, { Atflags, 3 } } }, { .name = "utimes", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } }, { .name = "utrace", .ret_type = 1, .nargs = 1, .args = { { Utrace, 0 } } }, { .name = "wait4", .ret_type = 1, .nargs = 4, .args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 }, { Rusage | OUT, 3 } } }, { .name = "wait6", .ret_type = 1, .nargs = 6, .args = { { Idtype, 0 }, { Quad, 1 + QUAD_ALIGN }, { ExitStatus | OUT, 1 + QUAD_ALIGN + QUAD_SLOTS }, { Waitoptions, 2 + QUAD_ALIGN + QUAD_SLOTS }, { Rusage | OUT, 3 + QUAD_ALIGN + QUAD_SLOTS }, { Ptr, 4 + QUAD_ALIGN + QUAD_SLOTS } } }, { .name = "write", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 } } }, /* Linux ABI */ { .name = "linux_access", .ret_type = 1, .nargs = 2, .args = { { Name, 0 }, { Accessmode, 1 } } }, { .name = "linux_execve", .ret_type = 1, .nargs = 3, .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 }, { ExecEnv | IN, 2 } } }, { .name = "linux_lseek", .ret_type = 2, .nargs = 3, .args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } }, { .name = "linux_mkdir", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Int, 1 } } }, { .name = "linux_newfstat", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Ptr | OUT, 1 } } }, { .name = "linux_newstat", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } }, { .name = "linux_open", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } }, { .name = "linux_readlink", .ret_type = 1, .nargs = 3, .args = { { Name, 0 }, { Name | OUT, 1 }, { Int, 2 } } }, { .name = "linux_socketcall", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { LinuxSockArgs, 1 } } }, { .name = "linux_stat64", .ret_type = 1, .nargs = 3, .args = { { Name | IN, 0 }, { Ptr | OUT, 1 }, { Ptr | IN, 1 } } }, /* CloudABI system calls. */ { .name = "cloudabi_sys_clock_res_get", .ret_type = 1, .nargs = 1, .args = { { CloudABIClockID, 0 } } }, { .name = "cloudabi_sys_clock_time_get", .ret_type = 1, .nargs = 2, .args = { { CloudABIClockID, 0 }, { CloudABITimestamp, 1 } } }, { .name = "cloudabi_sys_condvar_signal", .ret_type = 1, .nargs = 3, .args = { { Ptr, 0 }, { CloudABIMFlags, 1 }, { UInt, 2 } } }, { .name = "cloudabi_sys_fd_close", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "cloudabi_sys_fd_create1", .ret_type = 1, .nargs = 1, .args = { { CloudABIFileType, 0 } } }, { .name = "cloudabi_sys_fd_create2", .ret_type = 1, .nargs = 2, .args = { { CloudABIFileType, 0 }, { PipeFds | OUT, 0 } } }, { .name = "cloudabi_sys_fd_datasync", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "cloudabi_sys_fd_dup", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "cloudabi_sys_fd_replace", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Int, 1 } } }, { .name = "cloudabi_sys_fd_seek", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Int, 1 }, { CloudABIWhence, 2 } } }, { .name = "cloudabi_sys_fd_stat_get", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CloudABIFDStat | OUT, 1 } } }, { .name = "cloudabi_sys_fd_stat_put", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { CloudABIFDStat | IN, 1 }, { ClouduABIFDSFlags, 2 } } }, { .name = "cloudabi_sys_fd_sync", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "cloudabi_sys_file_advise", .ret_type = 1, .nargs = 4, .args = { { Int, 0 }, { Int, 1 }, { Int, 2 }, { CloudABIAdvice, 3 } } }, { .name = "cloudabi_sys_file_allocate", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } }, { .name = "cloudabi_sys_file_create", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { BinString | IN, 1 }, { CloudABIFileType, 3 } } }, { .name = "cloudabi_sys_file_link", .ret_type = 1, .nargs = 4, .args = { { CloudABILookup, 0 }, { BinString | IN, 1 }, { Int, 3 }, { BinString | IN, 4 } } }, { .name = "cloudabi_sys_file_open", .ret_type = 1, .nargs = 4, .args = { { Int, 0 }, { BinString | IN, 1 }, { CloudABIOFlags, 3 }, { CloudABIFDStat | IN, 4 } } }, { .name = "cloudabi_sys_file_readdir", .ret_type = 1, .nargs = 4, .args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 }, { Int, 3 } } }, { .name = "cloudabi_sys_file_readlink", .ret_type = 1, .nargs = 4, .args = { { Int, 0 }, { BinString | IN, 1 }, { BinString | OUT, 3 }, { Int, 4 } } }, { .name = "cloudabi_sys_file_rename", .ret_type = 1, .nargs = 4, .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 3 }, { BinString | IN, 4 } } }, { .name = "cloudabi_sys_file_stat_fget", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CloudABIFileStat | OUT, 1 } } }, { .name = "cloudabi_sys_file_stat_fput", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { CloudABIFileStat | IN, 1 }, { CloudABIFSFlags, 2 } } }, { .name = "cloudabi_sys_file_stat_get", .ret_type = 1, .nargs = 3, .args = { { CloudABILookup, 0 }, { BinString | IN, 1 }, { CloudABIFileStat | OUT, 3 } } }, { .name = "cloudabi_sys_file_stat_put", .ret_type = 1, .nargs = 4, .args = { { CloudABILookup, 0 }, { BinString | IN, 1 }, { CloudABIFileStat | IN, 3 }, { CloudABIFSFlags, 4 } } }, { .name = "cloudabi_sys_file_symlink", .ret_type = 1, .nargs = 3, .args = { { BinString | IN, 0 }, { Int, 2 }, { BinString | IN, 3 } } }, { .name = "cloudabi_sys_file_unlink", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { BinString | IN, 1 }, { CloudABIULFlags, 3 } } }, { .name = "cloudabi_sys_lock_unlock", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } }, { .name = "cloudabi_sys_mem_advise", .ret_type = 1, .nargs = 3, .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIAdvice, 2 } } }, { .name = "cloudabi_sys_mem_lock", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { Int, 1 } } }, { .name = "cloudabi_sys_mem_map", .ret_type = 1, .nargs = 6, .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 }, { CloudABIMFlags, 3 }, { Int, 4 }, { Int, 5 } } }, { .name = "cloudabi_sys_mem_protect", .ret_type = 1, .nargs = 3, .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMProt, 2 } } }, { .name = "cloudabi_sys_mem_sync", .ret_type = 1, .nargs = 3, .args = { { Ptr, 0 }, { Int, 1 }, { CloudABIMSFlags, 2 } } }, { .name = "cloudabi_sys_mem_unlock", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { Int, 1 } } }, { .name = "cloudabi_sys_mem_unmap", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { Int, 1 } } }, { .name = "cloudabi_sys_proc_exec", .ret_type = 1, .nargs = 5, .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, { IntArray, 3 }, { Int, 4 } } }, { .name = "cloudabi_sys_proc_exit", .ret_type = 1, .nargs = 1, .args = { { Int, 0 } } }, { .name = "cloudabi_sys_proc_fork", .ret_type = 1, .nargs = 0 }, { .name = "cloudabi_sys_proc_raise", .ret_type = 1, .nargs = 1, .args = { { CloudABISignal, 0 } } }, { .name = "cloudabi_sys_random_get", .ret_type = 1, .nargs = 2, .args = { { BinString | OUT, 0 }, { Int, 1 } } }, { .name = "cloudabi_sys_sock_accept", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CloudABISockStat | OUT, 1 } } }, { .name = "cloudabi_sys_sock_bind", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Int, 1 }, { BinString | IN, 2 } } }, { .name = "cloudabi_sys_sock_connect", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { Int, 1 }, { BinString | IN, 2 } } }, { .name = "cloudabi_sys_sock_listen", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Int, 1 } } }, { .name = "cloudabi_sys_sock_shutdown", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { CloudABISDFlags, 1 } } }, { .name = "cloudabi_sys_sock_stat_get", .ret_type = 1, .nargs = 3, .args = { { Int, 0 }, { CloudABISockStat | OUT, 1 }, { CloudABISSFlags, 2 } } }, { .name = "cloudabi_sys_thread_exit", .ret_type = 1, .nargs = 2, .args = { { Ptr, 0 }, { CloudABIMFlags, 1 } } }, { .name = "cloudabi_sys_thread_tcb_set", .ret_type = 1, .nargs = 1, .args = { { Ptr, 0 } } }, { .name = "cloudabi_sys_thread_yield", .ret_type = 1, .nargs = 0 }, { .name = 0 }, }; static STAILQ_HEAD(, syscall) syscalls; /* Xlat idea taken from strace */ struct xlat { int val; const char *str; }; #define X(a) { a, #a }, #define XEND { 0, NULL } static struct xlat kevent_filters[] = { X(EVFILT_READ) X(EVFILT_WRITE) X(EVFILT_AIO) X(EVFILT_VNODE) X(EVFILT_PROC) X(EVFILT_SIGNAL) X(EVFILT_TIMER) X(EVFILT_PROCDESC) X(EVFILT_FS) X(EVFILT_LIO) X(EVFILT_USER) X(EVFILT_SENDFILE) XEND }; static struct xlat kevent_flags[] = { X(EV_ADD) X(EV_DELETE) X(EV_ENABLE) X(EV_DISABLE) X(EV_ONESHOT) X(EV_CLEAR) X(EV_RECEIPT) X(EV_DISPATCH) X(EV_FORCEONESHOT) X(EV_DROP) X(EV_FLAG1) X(EV_ERROR) X(EV_EOF) XEND }; static struct xlat kevent_user_ffctrl[] = { X(NOTE_FFNOP) X(NOTE_FFAND) X(NOTE_FFOR) X(NOTE_FFCOPY) XEND }; static struct xlat kevent_rdwr_fflags[] = { X(NOTE_LOWAT) X(NOTE_FILE_POLL) XEND }; static struct xlat kevent_vnode_fflags[] = { X(NOTE_DELETE) X(NOTE_WRITE) X(NOTE_EXTEND) X(NOTE_ATTRIB) X(NOTE_LINK) X(NOTE_RENAME) X(NOTE_REVOKE) XEND }; static struct xlat kevent_proc_fflags[] = { X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR) X(NOTE_CHILD) XEND }; static struct xlat kevent_timer_fflags[] = { X(NOTE_SECONDS) X(NOTE_MSECONDS) X(NOTE_USECONDS) X(NOTE_NSECONDS) XEND }; static struct xlat poll_flags[] = { X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR) X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND) X(POLLWRBAND) X(POLLINIGNEOF) XEND }; static struct xlat mmap_flags[] = { X(MAP_SHARED) X(MAP_PRIVATE) X(MAP_FIXED) X(MAP_RESERVED0020) X(MAP_RESERVED0040) X(MAP_RESERVED0080) X(MAP_RESERVED0100) X(MAP_HASSEMAPHORE) X(MAP_STACK) X(MAP_NOSYNC) X(MAP_ANON) X(MAP_EXCL) X(MAP_NOCORE) X(MAP_PREFAULT_READ) #ifdef MAP_32BIT X(MAP_32BIT) #endif XEND }; static struct xlat mprot_flags[] = { X(PROT_NONE) X(PROT_READ) X(PROT_WRITE) X(PROT_EXEC) XEND }; static struct xlat whence_arg[] = { X(SEEK_SET) X(SEEK_CUR) X(SEEK_END) X(SEEK_DATA) X(SEEK_HOLE) XEND }; static struct xlat sigaction_flags[] = { X(SA_ONSTACK) X(SA_RESTART) X(SA_RESETHAND) X(SA_NOCLDSTOP) X(SA_NODEFER) X(SA_NOCLDWAIT) X(SA_SIGINFO) XEND }; static struct xlat fcntl_arg[] = { X(F_DUPFD) X(F_GETFD) X(F_SETFD) X(F_GETFL) X(F_SETFL) X(F_GETOWN) X(F_SETOWN) X(F_OGETLK) X(F_OSETLK) X(F_OSETLKW) X(F_DUP2FD) X(F_GETLK) X(F_SETLK) X(F_SETLKW) X(F_SETLK_REMOTE) X(F_READAHEAD) X(F_RDAHEAD) X(F_DUPFD_CLOEXEC) X(F_DUP2FD_CLOEXEC) XEND }; static struct xlat fcntlfd_arg[] = { X(FD_CLOEXEC) XEND }; static struct xlat fcntlfl_arg[] = { X(O_APPEND) X(O_ASYNC) X(O_FSYNC) X(O_NONBLOCK) X(O_NOFOLLOW) X(FRDAHEAD) X(O_DIRECT) XEND }; static struct xlat sockdomain_arg[] = { X(PF_UNSPEC) X(PF_LOCAL) X(PF_UNIX) X(PF_INET) X(PF_IMPLINK) X(PF_PUP) X(PF_CHAOS) X(PF_NETBIOS) X(PF_ISO) X(PF_OSI) X(PF_ECMA) X(PF_DATAKIT) X(PF_CCITT) X(PF_SNA) X(PF_DECnet) X(PF_DLI) X(PF_LAT) X(PF_HYLINK) X(PF_APPLETALK) X(PF_ROUTE) X(PF_LINK) X(PF_XTP) X(PF_COIP) X(PF_CNT) X(PF_SIP) X(PF_IPX) X(PF_RTIP) X(PF_PIP) X(PF_ISDN) X(PF_KEY) X(PF_INET6) X(PF_NATM) X(PF_ATM) X(PF_NETGRAPH) X(PF_SLOW) X(PF_SCLUSTER) X(PF_ARP) X(PF_BLUETOOTH) X(PF_IEEE80211) X(PF_INET_SDP) X(PF_INET6_SDP) XEND }; static struct xlat socktype_arg[] = { X(SOCK_STREAM) X(SOCK_DGRAM) X(SOCK_RAW) X(SOCK_RDM) X(SOCK_SEQPACKET) XEND }; static struct xlat open_flags[] = { X(O_RDONLY) X(O_WRONLY) X(O_RDWR) X(O_ACCMODE) X(O_NONBLOCK) X(O_APPEND) X(O_SHLOCK) X(O_EXLOCK) X(O_ASYNC) X(O_FSYNC) X(O_NOFOLLOW) X(O_CREAT) X(O_TRUNC) X(O_EXCL) X(O_NOCTTY) X(O_DIRECT) X(O_DIRECTORY) X(O_EXEC) X(O_TTY_INIT) X(O_CLOEXEC) X(O_VERIFY) XEND }; static struct xlat shutdown_arg[] = { X(SHUT_RD) X(SHUT_WR) X(SHUT_RDWR) XEND }; static struct xlat resource_arg[] = { X(RLIMIT_CPU) X(RLIMIT_FSIZE) X(RLIMIT_DATA) X(RLIMIT_STACK) X(RLIMIT_CORE) X(RLIMIT_RSS) X(RLIMIT_MEMLOCK) X(RLIMIT_NPROC) X(RLIMIT_NOFILE) X(RLIMIT_SBSIZE) X(RLIMIT_VMEM) X(RLIMIT_NPTS) X(RLIMIT_SWAP) X(RLIMIT_KQUEUES) XEND }; static struct xlat pathconf_arg[] = { X(_PC_LINK_MAX) X(_PC_MAX_CANON) X(_PC_MAX_INPUT) X(_PC_NAME_MAX) X(_PC_PATH_MAX) X(_PC_PIPE_BUF) X(_PC_CHOWN_RESTRICTED) X(_PC_NO_TRUNC) X(_PC_VDISABLE) X(_PC_ASYNC_IO) X(_PC_PRIO_IO) X(_PC_SYNC_IO) X(_PC_ALLOC_SIZE_MIN) X(_PC_FILESIZEBITS) X(_PC_REC_INCR_XFER_SIZE) X(_PC_REC_MAX_XFER_SIZE) X(_PC_REC_MIN_XFER_SIZE) X(_PC_REC_XFER_ALIGN) X(_PC_SYMLINK_MAX) X(_PC_ACL_EXTENDED) X(_PC_ACL_PATH_MAX) X(_PC_CAP_PRESENT) X(_PC_INF_PRESENT) X(_PC_MAC_PRESENT) X(_PC_ACL_NFS4) X(_PC_MIN_HOLE_SIZE) XEND }; static struct xlat rfork_flags[] = { X(RFFDG) X(RFPROC) X(RFMEM) X(RFNOWAIT) X(RFCFDG) X(RFTHREAD) X(RFSIGSHARE) X(RFLINUXTHPN) X(RFTSIGZMB) X(RFPPWAIT) XEND }; static struct xlat wait_options[] = { X(WNOHANG) X(WUNTRACED) X(WCONTINUED) X(WNOWAIT) X(WEXITED) X(WTRAPPED) XEND }; static struct xlat idtype_arg[] = { X(P_PID) X(P_PPID) X(P_PGID) X(P_SID) X(P_CID) X(P_UID) X(P_GID) X(P_ALL) X(P_LWPID) X(P_TASKID) X(P_PROJID) X(P_POOLID) X(P_JAILID) X(P_CTID) X(P_CPUID) X(P_PSETID) XEND }; static struct xlat procctl_arg[] = { X(PROC_SPROTECT) X(PROC_REAP_ACQUIRE) X(PROC_REAP_RELEASE) X(PROC_REAP_STATUS) X(PROC_REAP_GETPIDS) X(PROC_REAP_KILL) X(PROC_TRACE_CTL) X(PROC_TRACE_STATUS) XEND }; static struct xlat umtx_ops[] = { X(UMTX_OP_RESERVED0) X(UMTX_OP_RESERVED1) X(UMTX_OP_WAIT) X(UMTX_OP_WAKE) X(UMTX_OP_MUTEX_TRYLOCK) X(UMTX_OP_MUTEX_LOCK) X(UMTX_OP_MUTEX_UNLOCK) X(UMTX_OP_SET_CEILING) X(UMTX_OP_CV_WAIT) X(UMTX_OP_CV_SIGNAL) X(UMTX_OP_CV_BROADCAST) X(UMTX_OP_WAIT_UINT) X(UMTX_OP_RW_RDLOCK) X(UMTX_OP_RW_WRLOCK) X(UMTX_OP_RW_UNLOCK) X(UMTX_OP_WAIT_UINT_PRIVATE) X(UMTX_OP_WAKE_PRIVATE) X(UMTX_OP_MUTEX_WAIT) X(UMTX_OP_MUTEX_WAKE) X(UMTX_OP_SEM_WAIT) X(UMTX_OP_SEM_WAKE) X(UMTX_OP_NWAKE_PRIVATE) X(UMTX_OP_MUTEX_WAKE2) X(UMTX_OP_SEM2_WAIT) X(UMTX_OP_SEM2_WAKE) XEND }; static struct xlat at_flags[] = { X(AT_EACCESS) X(AT_SYMLINK_NOFOLLOW) X(AT_SYMLINK_FOLLOW) X(AT_REMOVEDIR) XEND }; static struct xlat access_modes[] = { X(R_OK) X(W_OK) X(X_OK) XEND }; static struct xlat sysarch_ops[] = { #if defined(__i386__) || defined(__amd64__) X(I386_GET_LDT) X(I386_SET_LDT) X(I386_GET_IOPERM) X(I386_SET_IOPERM) X(I386_VM86) X(I386_GET_FSBASE) X(I386_SET_FSBASE) X(I386_GET_GSBASE) X(I386_SET_GSBASE) X(I386_GET_XFPUSTATE) X(AMD64_GET_FSBASE) X(AMD64_SET_FSBASE) X(AMD64_GET_GSBASE) X(AMD64_SET_GSBASE) X(AMD64_GET_XFPUSTATE) #endif XEND }; static struct xlat linux_socketcall_ops[] = { X(LINUX_SOCKET) X(LINUX_BIND) X(LINUX_CONNECT) X(LINUX_LISTEN) X(LINUX_ACCEPT) X(LINUX_GETSOCKNAME) X(LINUX_GETPEERNAME) X(LINUX_SOCKETPAIR) X(LINUX_SEND) X(LINUX_RECV) X(LINUX_SENDTO) X(LINUX_RECVFROM) X(LINUX_SHUTDOWN) X(LINUX_SETSOCKOPT) X(LINUX_GETSOCKOPT) X(LINUX_SENDMSG) X(LINUX_RECVMSG) XEND }; static struct xlat sigprocmask_ops[] = { X(SIG_BLOCK) X(SIG_UNBLOCK) X(SIG_SETMASK) XEND }; #undef X #define X(a) { CLOUDABI_##a, #a }, static struct xlat cloudabi_advice[] = { X(ADVICE_DONTNEED) X(ADVICE_NOREUSE) X(ADVICE_NORMAL) X(ADVICE_RANDOM) X(ADVICE_SEQUENTIAL) X(ADVICE_WILLNEED) XEND }; static struct xlat cloudabi_clockid[] = { X(CLOCK_MONOTONIC) X(CLOCK_PROCESS_CPUTIME_ID) X(CLOCK_REALTIME) X(CLOCK_THREAD_CPUTIME_ID) XEND }; static struct xlat cloudabi_errno[] = { X(E2BIG) X(EACCES) X(EADDRINUSE) X(EADDRNOTAVAIL) X(EAFNOSUPPORT) X(EAGAIN) X(EALREADY) X(EBADF) X(EBADMSG) X(EBUSY) X(ECANCELED) X(ECHILD) X(ECONNABORTED) X(ECONNREFUSED) X(ECONNRESET) X(EDEADLK) X(EDESTADDRREQ) X(EDOM) X(EDQUOT) X(EEXIST) X(EFAULT) X(EFBIG) X(EHOSTUNREACH) X(EIDRM) X(EILSEQ) X(EINPROGRESS) X(EINTR) X(EINVAL) X(EIO) X(EISCONN) X(EISDIR) X(ELOOP) X(EMFILE) X(EMLINK) X(EMSGSIZE) X(EMULTIHOP) X(ENAMETOOLONG) X(ENETDOWN) X(ENETRESET) X(ENETUNREACH) X(ENFILE) X(ENOBUFS) X(ENODEV) X(ENOENT) X(ENOEXEC) X(ENOLCK) X(ENOLINK) X(ENOMEM) X(ENOMSG) X(ENOPROTOOPT) X(ENOSPC) X(ENOSYS) X(ENOTCONN) X(ENOTDIR) X(ENOTEMPTY) X(ENOTRECOVERABLE) X(ENOTSOCK) X(ENOTSUP) X(ENOTTY) X(ENXIO) X(EOVERFLOW) X(EOWNERDEAD) X(EPERM) X(EPIPE) X(EPROTO) X(EPROTONOSUPPORT) X(EPROTOTYPE) X(ERANGE) X(EROFS) X(ESPIPE) X(ESRCH) X(ESTALE) X(ETIMEDOUT) X(ETXTBSY) X(EXDEV) X(ENOTCAPABLE) XEND }; static struct xlat cloudabi_fdflags[] = { X(FDFLAG_APPEND) X(FDFLAG_DSYNC) X(FDFLAG_NONBLOCK) X(FDFLAG_RSYNC) X(FDFLAG_SYNC) XEND }; static struct xlat cloudabi_fdsflags[] = { X(FDSTAT_FLAGS) X(FDSTAT_RIGHTS) XEND }; static struct xlat cloudabi_filetype[] = { X(FILETYPE_UNKNOWN) X(FILETYPE_BLOCK_DEVICE) X(FILETYPE_CHARACTER_DEVICE) X(FILETYPE_DIRECTORY) X(FILETYPE_FIFO) X(FILETYPE_POLL) X(FILETYPE_PROCESS) X(FILETYPE_REGULAR_FILE) X(FILETYPE_SHARED_MEMORY) X(FILETYPE_SOCKET_DGRAM) X(FILETYPE_SOCKET_SEQPACKET) X(FILETYPE_SOCKET_STREAM) X(FILETYPE_SYMBOLIC_LINK) XEND }; static struct xlat cloudabi_fsflags[] = { X(FILESTAT_ATIM) X(FILESTAT_ATIM_NOW) X(FILESTAT_MTIM) X(FILESTAT_MTIM_NOW) X(FILESTAT_SIZE) XEND }; static struct xlat cloudabi_mflags[] = { X(MAP_ANON) X(MAP_FIXED) X(MAP_PRIVATE) X(MAP_SHARED) XEND }; static struct xlat cloudabi_mprot[] = { X(PROT_EXEC) X(PROT_WRITE) X(PROT_READ) XEND }; static struct xlat cloudabi_msflags[] = { X(MS_ASYNC) X(MS_INVALIDATE) X(MS_SYNC) XEND }; static struct xlat cloudabi_oflags[] = { X(O_CREAT) X(O_DIRECTORY) X(O_EXCL) X(O_TRUNC) XEND }; static struct xlat cloudabi_sa_family[] = { X(AF_UNSPEC) X(AF_INET) X(AF_INET6) X(AF_UNIX) XEND }; static struct xlat cloudabi_sdflags[] = { X(SHUT_RD) X(SHUT_WR) XEND }; static struct xlat cloudabi_signal[] = { X(SIGABRT) X(SIGALRM) X(SIGBUS) X(SIGCHLD) X(SIGCONT) X(SIGFPE) X(SIGHUP) X(SIGILL) X(SIGINT) X(SIGKILL) X(SIGPIPE) X(SIGQUIT) X(SIGSEGV) X(SIGSTOP) X(SIGSYS) X(SIGTERM) X(SIGTRAP) X(SIGTSTP) X(SIGTTIN) X(SIGTTOU) X(SIGURG) X(SIGUSR1) X(SIGUSR2) X(SIGVTALRM) X(SIGXCPU) X(SIGXFSZ) XEND }; static struct xlat cloudabi_ssflags[] = { X(SOCKSTAT_CLEAR_ERROR) XEND }; static struct xlat cloudabi_ssstate[] = { - X(SOCKSTAT_ACCEPTCONN) + X(SOCKSTATE_ACCEPTCONN) XEND }; static struct xlat cloudabi_ulflags[] = { X(UNLINK_REMOVEDIR) XEND }; static struct xlat cloudabi_whence[] = { X(WHENCE_CUR) X(WHENCE_END) X(WHENCE_SET) XEND }; #undef X #undef XEND /* * Searches an xlat array for a value, and returns it if found. Otherwise * return a string representation. */ static const char * lookup(struct xlat *xlat, int val, int base) { static char tmp[16]; for (; xlat->str != NULL; xlat++) if (xlat->val == val) return (xlat->str); switch (base) { case 8: sprintf(tmp, "0%o", val); break; case 16: sprintf(tmp, "0x%x", val); break; case 10: sprintf(tmp, "%u", val); break; default: errx(1,"Unknown lookup base"); break; } return (tmp); } static const char * xlookup(struct xlat *xlat, int val) { return (lookup(xlat, val, 16)); } /* * Searches an xlat array containing bitfield values. Remaining bits * set after removing the known ones are printed at the end: * IN|0x400. */ static char * xlookup_bits(struct xlat *xlat, int val) { int len, rem; static char str[512]; len = 0; rem = val; for (; xlat->str != NULL; xlat++) { if ((xlat->val & rem) == xlat->val) { /* * Don't print the "all-bits-zero" string unless all * bits are really zero. */ if (xlat->val == 0 && val != 0) continue; len += sprintf(str + len, "%s|", xlat->str); rem &= ~(xlat->val); } } /* * If we have leftover bits or didn't match anything, print * the remainder. */ if (rem || len == 0) len += sprintf(str + len, "0x%x", rem); if (len && str[len - 1] == '|') len--; str[len] = 0; return (str); } void init_syscalls(void) { struct syscall *sc; STAILQ_INIT(&syscalls); for (sc = decoded_syscalls; sc->name != NULL; sc++) STAILQ_INSERT_HEAD(&syscalls, sc, entries); } /* * If/when the list gets big, it might be desirable to do it * as a hash table or binary search. */ struct syscall * get_syscall(const char *name, int nargs) { struct syscall *sc; int i; if (name == NULL) return (NULL); STAILQ_FOREACH(sc, &syscalls, entries) if (strcmp(name, sc->name) == 0) return (sc); /* It is unknown. Add it into the list. */ #if DEBUG fprintf(stderr, "unknown syscall %s -- setting args to %d\n", name, nargs); #endif sc = calloc(1, sizeof(struct syscall)); sc->name = strdup(name); sc->ret_type = 1; sc->nargs = nargs; for (i = 0; i < nargs; i++) { sc->args[i].offset = i; /* Treat all unknown arguments as LongHex. */ sc->args[i].type = LongHex; } STAILQ_INSERT_HEAD(&syscalls, sc, entries); return (sc); } /* * Copy a fixed amount of bytes from the process. */ static int get_struct(pid_t pid, void *offset, void *buf, int len) { struct ptrace_io_desc iorequest; iorequest.piod_op = PIOD_READ_D; iorequest.piod_offs = offset; iorequest.piod_addr = buf; iorequest.piod_len = len; if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) return (-1); return (0); } #define MAXSIZE 4096 /* * Copy a string from the process. Note that it is * expected to be a C string, but if max is set, it will * only get that much. */ static char * get_string(pid_t pid, void *addr, int max) { struct ptrace_io_desc iorequest; char *buf, *nbuf; size_t offset, size, totalsize; offset = 0; if (max) size = max + 1; else { /* Read up to the end of the current page. */ size = PAGE_SIZE - ((uintptr_t)addr % PAGE_SIZE); if (size > MAXSIZE) size = MAXSIZE; } totalsize = size; buf = malloc(totalsize); if (buf == NULL) return (NULL); for (;;) { iorequest.piod_op = PIOD_READ_D; iorequest.piod_offs = (char *)addr + offset; iorequest.piod_addr = buf + offset; iorequest.piod_len = size; if (ptrace(PT_IO, pid, (caddr_t)&iorequest, 0) < 0) { free(buf); return (NULL); } if (memchr(buf + offset, '\0', size) != NULL) return (buf); offset += size; if (totalsize < MAXSIZE && max == 0) { size = MAXSIZE - totalsize; if (size > PAGE_SIZE) size = PAGE_SIZE; nbuf = realloc(buf, totalsize + size); if (nbuf == NULL) { buf[totalsize - 1] = '\0'; return (buf); } buf = nbuf; totalsize += size; } else { buf[totalsize - 1] = '\0'; return (buf); } } } static char * strsig2(int sig) { static char tmp[sizeof(int) * 3 + 1]; char *ret; ret = strsig(sig); if (ret == NULL) { snprintf(tmp, sizeof(tmp), "%d", sig); ret = tmp; } return (ret); } static void print_kevent(FILE *fp, struct kevent *ke, int input) { switch (ke->filter) { case EVFILT_READ: case EVFILT_WRITE: case EVFILT_VNODE: case EVFILT_PROC: case EVFILT_TIMER: case EVFILT_PROCDESC: fprintf(fp, "%ju", (uintmax_t)ke->ident); break; case EVFILT_SIGNAL: fputs(strsig2(ke->ident), fp); break; default: fprintf(fp, "%p", (void *)ke->ident); } fprintf(fp, ",%s,%s,", xlookup(kevent_filters, ke->filter), xlookup_bits(kevent_flags, ke->flags)); switch (ke->filter) { case EVFILT_READ: case EVFILT_WRITE: fputs(xlookup_bits(kevent_rdwr_fflags, ke->fflags), fp); break; case EVFILT_VNODE: fputs(xlookup_bits(kevent_vnode_fflags, ke->fflags), fp); break; case EVFILT_PROC: case EVFILT_PROCDESC: fputs(xlookup_bits(kevent_proc_fflags, ke->fflags), fp); break; case EVFILT_TIMER: fputs(xlookup_bits(kevent_timer_fflags, ke->fflags), fp); break; case EVFILT_USER: { int ctrl, data; ctrl = ke->fflags & NOTE_FFCTRLMASK; data = ke->fflags & NOTE_FFLAGSMASK; if (input) { fputs(xlookup(kevent_user_ffctrl, ctrl), fp); if (ke->fflags & NOTE_TRIGGER) fputs("|NOTE_TRIGGER", fp); if (data != 0) fprintf(fp, "|%#x", data); } else { fprintf(fp, "%#x", data); } break; } default: fprintf(fp, "%#x", ke->fflags); } fprintf(fp, ",%p,%p", (void *)ke->data, (void *)ke->udata); } static void print_utrace(FILE *fp, void *utrace_addr, size_t len) { unsigned char *utrace_buffer; fprintf(fp, "{ "); if (sysdecode_utrace(fp, utrace_addr, len)) { fprintf(fp, " }"); return; } utrace_buffer = utrace_addr; fprintf(fp, "%zu:", len); while (len--) fprintf(fp, " %02x", *utrace_buffer++); fprintf(fp, " }"); } /* * Converts a syscall argument into a string. Said string is * allocated via malloc(), so needs to be free()'d. sc is * a pointer to the syscall description (see above); args is * an array of all of the system call arguments. */ char * print_arg(struct syscall_args *sc, unsigned long *args, long *retval, struct trussinfo *trussinfo) { FILE *fp; char *tmp; size_t tmplen; pid_t pid; fp = open_memstream(&tmp, &tmplen); pid = trussinfo->curthread->proc->pid; switch (sc->type & ARG_MASK) { case Hex: fprintf(fp, "0x%x", (int)args[sc->offset]); break; case Octal: fprintf(fp, "0%o", (int)args[sc->offset]); break; case Int: fprintf(fp, "%d", (int)args[sc->offset]); break; case UInt: fprintf(fp, "%u", (unsigned int)args[sc->offset]); break; case LongHex: fprintf(fp, "0x%lx", args[sc->offset]); break; case Long: fprintf(fp, "%ld", args[sc->offset]); break; case Name: { /* NULL-terminated string. */ char *tmp2; tmp2 = get_string(pid, (void*)args[sc->offset], 0); fprintf(fp, "\"%s\"", tmp2); free(tmp2); break; } case BinString: { /* * Binary block of data that might have printable characters. * XXX If type|OUT, assume that the length is the syscall's * return value. Otherwise, assume that the length of the block * is in the next syscall argument. */ int max_string = trussinfo->strsize; char tmp2[max_string + 1], *tmp3; int len; int truncated = 0; if (sc->type & OUT) len = retval[0]; else len = args[sc->offset + 1]; /* * Don't print more than max_string characters, to avoid word * wrap. If we have to truncate put some ... after the string. */ if (len > max_string) { len = max_string; truncated = 1; } if (len && get_struct(pid, (void*)args[sc->offset], &tmp2, len) != -1) { tmp3 = malloc(len * 4 + 1); while (len) { if (strvisx(tmp3, tmp2, len, VIS_CSTYLE|VIS_TAB|VIS_NL) <= max_string) break; len--; truncated = 1; }; fprintf(fp, "\"%s\"%s", tmp3, truncated ? "..." : ""); free(tmp3); } else { fprintf(fp, "0x%lx", args[sc->offset]); } break; } case ExecArgs: case ExecEnv: case StringArray: { uintptr_t addr; union { char *strarray[0]; char buf[PAGE_SIZE]; } u; char *string; size_t len; u_int first, i; /* * Only parse argv[] and environment arrays from exec calls * if requested. */ if (((sc->type & ARG_MASK) == ExecArgs && (trussinfo->flags & EXECVEARGS) == 0) || ((sc->type & ARG_MASK) == ExecEnv && (trussinfo->flags & EXECVEENVS) == 0)) { fprintf(fp, "0x%lx", args[sc->offset]); break; } /* * Read a page of pointers at a time. Punt if the top-level * pointer is not aligned. Note that the first read is of * a partial page. */ addr = args[sc->offset]; if (addr % sizeof(char *) != 0) { fprintf(fp, "0x%lx", args[sc->offset]); break; } len = PAGE_SIZE - (addr & PAGE_MASK); if (get_struct(pid, (void *)addr, u.buf, len) == -1) { fprintf(fp, "0x%lx", args[sc->offset]); break; } fputc('[', fp); first = 1; i = 0; while (u.strarray[i] != NULL) { string = get_string(pid, u.strarray[i], 0); fprintf(fp, "%s \"%s\"", first ? "" : ",", string); free(string); first = 0; i++; if (i == len / sizeof(char *)) { addr += len; len = PAGE_SIZE; if (get_struct(pid, (void *)addr, u.buf, len) == -1) { fprintf(fp, ", "); break; } i = 0; } } fputs(" ]", fp); break; } #ifdef __LP64__ case Quad: fprintf(fp, "%ld", args[sc->offset]); break; case QuadHex: fprintf(fp, "0x%lx", args[sc->offset]); break; #else case Quad: case QuadHex: { unsigned long long ll; #if _BYTE_ORDER == _LITTLE_ENDIAN ll = (unsigned long long)args[sc->offset + 1] << 32 | args[sc->offset]; #else ll = (unsigned long long)args[sc->offset] << 32 | args[sc->offset + 1]; #endif if ((sc->type & ARG_MASK) == Quad) fprintf(fp, "%lld", ll); else fprintf(fp, "0x%llx", ll); break; } #endif case Ptr: fprintf(fp, "0x%lx", args[sc->offset]); break; case Readlinkres: { char *tmp2; if (retval[0] == -1) break; tmp2 = get_string(pid, (void*)args[sc->offset], retval[0]); fprintf(fp, "\"%s\"", tmp2); free(tmp2); break; } case Ioctl: { const char *temp; unsigned long cmd; cmd = args[sc->offset]; temp = sysdecode_ioctlname(cmd); if (temp) fputs(temp, fp); else { fprintf(fp, "0x%lx { IO%s%s 0x%lx('%c'), %lu, %lu }", cmd, cmd & IOC_OUT ? "R" : "", cmd & IOC_IN ? "W" : "", IOCGROUP(cmd), isprint(IOCGROUP(cmd)) ? (char)IOCGROUP(cmd) : '?', cmd & 0xFF, IOCPARM_LEN(cmd)); } break; } case Timespec: { struct timespec ts; if (get_struct(pid, (void *)args[sc->offset], &ts, sizeof(ts)) != -1) fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec, ts.tv_nsec); else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Timespec2: { struct timespec ts[2]; const char *sep; unsigned int i; if (get_struct(pid, (void *)args[sc->offset], &ts, sizeof(ts)) != -1) { fputs("{ ", fp); sep = ""; for (i = 0; i < nitems(ts); i++) { fputs(sep, fp); sep = ", "; switch (ts[i].tv_nsec) { case UTIME_NOW: fprintf(fp, "UTIME_NOW"); break; case UTIME_OMIT: fprintf(fp, "UTIME_OMIT"); break; default: fprintf(fp, "%jd.%09ld", (intmax_t)ts[i].tv_sec, ts[i].tv_nsec); break; } } fputs(" }", fp); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Timeval: { struct timeval tv; if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv)) != -1) fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec, tv.tv_usec); else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Timeval2: { struct timeval tv[2]; if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv)) != -1) fprintf(fp, "{ %jd.%06ld, %jd.%06ld }", (intmax_t)tv[0].tv_sec, tv[0].tv_usec, (intmax_t)tv[1].tv_sec, tv[1].tv_usec); else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Itimerval: { struct itimerval itv; if (get_struct(pid, (void *)args[sc->offset], &itv, sizeof(itv)) != -1) fprintf(fp, "{ %jd.%06ld, %jd.%06ld }", (intmax_t)itv.it_interval.tv_sec, itv.it_interval.tv_usec, (intmax_t)itv.it_value.tv_sec, itv.it_value.tv_usec); else fprintf(fp, "0x%lx", args[sc->offset]); break; } case LinuxSockArgs: { struct linux_socketcall_args largs; if (get_struct(pid, (void *)args[sc->offset], (void *)&largs, sizeof(largs)) != -1) fprintf(fp, "{ %s, 0x%lx }", lookup(linux_socketcall_ops, largs.what, 10), (long unsigned int)largs.args); else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Pollfd: { /* * XXX: A Pollfd argument expects the /next/ syscall argument * to be the number of fds in the array. This matches the poll * syscall. */ struct pollfd *pfd; int numfds = args[sc->offset + 1]; size_t bytes = sizeof(struct pollfd) * numfds; int i; if ((pfd = malloc(bytes)) == NULL) err(1, "Cannot malloc %zu bytes for pollfd array", bytes); if (get_struct(pid, (void *)args[sc->offset], pfd, bytes) != -1) { fputs("{", fp); for (i = 0; i < numfds; i++) { fprintf(fp, " %d/%s", pfd[i].fd, xlookup_bits(poll_flags, pfd[i].events)); } fputs(" }", fp); } else { fprintf(fp, "0x%lx", args[sc->offset]); } free(pfd); break; } case Fd_set: { /* * XXX: A Fd_set argument expects the /first/ syscall argument * to be the number of fds in the array. This matches the * select syscall. */ fd_set *fds; int numfds = args[0]; size_t bytes = _howmany(numfds, _NFDBITS) * _NFDBITS; int i; if ((fds = malloc(bytes)) == NULL) err(1, "Cannot malloc %zu bytes for fd_set array", bytes); if (get_struct(pid, (void *)args[sc->offset], fds, bytes) != -1) { fputs("{", fp); for (i = 0; i < numfds; i++) { if (FD_ISSET(i, fds)) fprintf(fp, " %d", i); } fputs(" }", fp); } else fprintf(fp, "0x%lx", args[sc->offset]); free(fds); break; } case Signal: fputs(strsig2(args[sc->offset]), fp); break; case Sigset: { long sig; sigset_t ss; int i, first; sig = args[sc->offset]; if (get_struct(pid, (void *)args[sc->offset], (void *)&ss, sizeof(ss)) == -1) { fprintf(fp, "0x%lx", args[sc->offset]); break; } fputs("{ ", fp); first = 1; for (i = 1; i < sys_nsig; i++) { if (sigismember(&ss, i)) { fprintf(fp, "%s%s", !first ? "|" : "", strsig(i)); first = 0; } } if (!first) fputc(' ', fp); fputc('}', fp); break; } case Sigprocmask: { fputs(xlookup(sigprocmask_ops, args[sc->offset]), fp); break; } case Fcntlflag: { /* XXX: Output depends on the value of the previous argument. */ switch (args[sc->offset - 1]) { case F_SETFD: fputs(xlookup_bits(fcntlfd_arg, args[sc->offset]), fp); break; case F_SETFL: fputs(xlookup_bits(fcntlfl_arg, args[sc->offset]), fp); break; case F_GETFD: case F_GETFL: case F_GETOWN: break; default: fprintf(fp, "0x%lx", args[sc->offset]); break; } break; } case Open: fputs(xlookup_bits(open_flags, args[sc->offset]), fp); break; case Fcntl: fputs(xlookup(fcntl_arg, args[sc->offset]), fp); break; case Mprot: fputs(xlookup_bits(mprot_flags, args[sc->offset]), fp); break; case Mmapflags: { int align, flags; /* * MAP_ALIGNED can't be handled by xlookup_bits(), so * generate that string manually and prepend it to the * string from xlookup_bits(). Have to be careful to * avoid outputting MAP_ALIGNED|0 if MAP_ALIGNED is * the only flag. */ flags = args[sc->offset] & ~MAP_ALIGNMENT_MASK; align = args[sc->offset] & MAP_ALIGNMENT_MASK; if (align != 0) { if (align == MAP_ALIGNED_SUPER) fputs("MAP_ALIGNED_SUPER", fp); else fprintf(fp, "MAP_ALIGNED(%d)", align >> MAP_ALIGNMENT_SHIFT); if (flags == 0) break; fputc('|', fp); } fputs(xlookup_bits(mmap_flags, flags), fp); break; } case Whence: fputs(xlookup(whence_arg, args[sc->offset]), fp); break; case Sockdomain: fputs(xlookup(sockdomain_arg, args[sc->offset]), fp); break; case Socktype: { int type, flags; flags = args[sc->offset] & (SOCK_CLOEXEC | SOCK_NONBLOCK); type = args[sc->offset] & ~flags; fputs(xlookup(socktype_arg, type), fp); if (flags & SOCK_CLOEXEC) fprintf(fp, "|SOCK_CLOEXEC"); if (flags & SOCK_NONBLOCK) fprintf(fp, "|SOCK_NONBLOCK"); break; } case Shutdown: fputs(xlookup(shutdown_arg, args[sc->offset]), fp); break; case Resource: fputs(xlookup(resource_arg, args[sc->offset]), fp); break; case Pathconf: fputs(xlookup(pathconf_arg, args[sc->offset]), fp); break; case Rforkflags: fputs(xlookup_bits(rfork_flags, args[sc->offset]), fp); break; case Sockaddr: { char addr[64]; struct sockaddr_in *lsin; struct sockaddr_in6 *lsin6; struct sockaddr_un *sun; struct sockaddr *sa; socklen_t len; u_char *q; if (args[sc->offset] == 0) { fputs("NULL", fp); break; } /* * Extract the address length from the next argument. If * this is an output sockaddr (OUT is set), then the * next argument is a pointer to a socklen_t. Otherwise * the next argument contains a socklen_t by value. */ if (sc->type & OUT) { if (get_struct(pid, (void *)args[sc->offset + 1], &len, sizeof(len)) == -1) { fprintf(fp, "0x%lx", args[sc->offset]); break; } } else len = args[sc->offset + 1]; /* If the length is too small, just bail. */ if (len < sizeof(*sa)) { fprintf(fp, "0x%lx", args[sc->offset]); break; } sa = calloc(1, len); if (get_struct(pid, (void *)args[sc->offset], sa, len) == -1) { free(sa); fprintf(fp, "0x%lx", args[sc->offset]); break; } switch (sa->sa_family) { case AF_INET: if (len < sizeof(*lsin)) goto sockaddr_short; lsin = (struct sockaddr_in *)(void *)sa; inet_ntop(AF_INET, &lsin->sin_addr, addr, sizeof(addr)); fprintf(fp, "{ AF_INET %s:%d }", addr, htons(lsin->sin_port)); break; case AF_INET6: if (len < sizeof(*lsin6)) goto sockaddr_short; lsin6 = (struct sockaddr_in6 *)(void *)sa; inet_ntop(AF_INET6, &lsin6->sin6_addr, addr, sizeof(addr)); fprintf(fp, "{ AF_INET6 [%s]:%d }", addr, htons(lsin6->sin6_port)); break; case AF_UNIX: sun = (struct sockaddr_un *)sa; fprintf(fp, "{ AF_UNIX \"%.*s\" }", (int)(len - offsetof(struct sockaddr_un, sun_path)), sun->sun_path); break; default: sockaddr_short: fprintf(fp, "{ sa_len = %d, sa_family = %d, sa_data = {", (int)sa->sa_len, (int)sa->sa_family); for (q = (u_char *)sa->sa_data; q < (u_char *)sa + len; q++) fprintf(fp, "%s 0x%02x", q == (u_char *)sa->sa_data ? "" : ",", *q); fputs(" } }", fp); } free(sa); break; } case Sigaction: { struct sigaction sa; if (get_struct(pid, (void *)args[sc->offset], &sa, sizeof(sa)) != -1) { fputs("{ ", fp); if (sa.sa_handler == SIG_DFL) fputs("SIG_DFL", fp); else if (sa.sa_handler == SIG_IGN) fputs("SIG_IGN", fp); else fprintf(fp, "%p", sa.sa_handler); fprintf(fp, " %s ss_t }", xlookup_bits(sigaction_flags, sa.sa_flags)); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Kevent: { /* * XXX XXX: The size of the array is determined by either the * next syscall argument, or by the syscall return value, * depending on which argument number we are. This matches the * kevent syscall, but luckily that's the only syscall that uses * them. */ struct kevent *ke; int numevents = -1; size_t bytes; int i; if (sc->offset == 1) numevents = args[sc->offset+1]; else if (sc->offset == 3 && retval[0] != -1) numevents = retval[0]; if (numevents >= 0) { bytes = sizeof(struct kevent) * numevents; if ((ke = malloc(bytes)) == NULL) err(1, "Cannot malloc %zu bytes for kevent array", bytes); } else ke = NULL; if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset], ke, bytes) != -1) { fputc('{', fp); for (i = 0; i < numevents; i++) { fputc(' ', fp); print_kevent(fp, &ke[i], sc->offset == 1); } fputs(" }", fp); } else { fprintf(fp, "0x%lx", args[sc->offset]); } free(ke); break; } case Stat: { struct stat st; if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st)) != -1) { char mode[12]; strmode(st.st_mode, mode); fprintf(fp, "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode, (uintmax_t)st.st_ino, (intmax_t)st.st_size, (long)st.st_blksize); } else { fprintf(fp, "0x%lx", args[sc->offset]); } break; } case StatFs: { unsigned int i; struct statfs buf; if (get_struct(pid, (void *)args[sc->offset], &buf, sizeof(buf)) != -1) { char fsid[17]; bzero(fsid, sizeof(fsid)); if (buf.f_fsid.val[0] != 0 || buf.f_fsid.val[1] != 0) { for (i = 0; i < sizeof(buf.f_fsid); i++) snprintf(&fsid[i*2], sizeof(fsid) - (i*2), "%02x", ((u_char *)&buf.f_fsid)[i]); } fprintf(fp, "{ fstypename=%s,mntonname=%s,mntfromname=%s," "fsid=%s }", buf.f_fstypename, buf.f_mntonname, buf.f_mntfromname, fsid); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Rusage: { struct rusage ru; if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru)) != -1) { fprintf(fp, "{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }", (intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec, (intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec, ru.ru_inblock, ru.ru_oublock); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Rlimit: { struct rlimit rl; if (get_struct(pid, (void *)args[sc->offset], &rl, sizeof(rl)) != -1) { fprintf(fp, "{ cur=%ju,max=%ju }", rl.rlim_cur, rl.rlim_max); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case ExitStatus: { int status; if (get_struct(pid, (void *)args[sc->offset], &status, sizeof(status)) != -1) { fputs("{ ", fp); if (WIFCONTINUED(status)) fputs("CONTINUED", fp); else if (WIFEXITED(status)) fprintf(fp, "EXITED,val=%d", WEXITSTATUS(status)); else if (WIFSIGNALED(status)) fprintf(fp, "SIGNALED,sig=%s%s", strsig2(WTERMSIG(status)), WCOREDUMP(status) ? ",cored" : ""); else fprintf(fp, "STOPPED,sig=%s", strsig2(WTERMSIG(status))); fputs(" }", fp); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case Waitoptions: fputs(xlookup_bits(wait_options, args[sc->offset]), fp); break; case Idtype: fputs(xlookup(idtype_arg, args[sc->offset]), fp); break; case Procctl: fputs(xlookup(procctl_arg, args[sc->offset]), fp); break; case Umtxop: fputs(xlookup(umtx_ops, args[sc->offset]), fp); break; case Atfd: if ((int)args[sc->offset] == AT_FDCWD) fputs("AT_FDCWD", fp); else fprintf(fp, "%d", (int)args[sc->offset]); break; case Atflags: fputs(xlookup_bits(at_flags, args[sc->offset]), fp); break; case Accessmode: if (args[sc->offset] == F_OK) fputs("F_OK", fp); else fputs(xlookup_bits(access_modes, args[sc->offset]), fp); break; case Sysarch: fputs(xlookup(sysarch_ops, args[sc->offset]), fp); break; case PipeFds: /* * The pipe() system call in the kernel returns its * two file descriptors via return values. However, * the interface exposed by libc is that pipe() * accepts a pointer to an array of descriptors. * Format the output to match the libc API by printing * the returned file descriptors as a fake argument. * * Overwrite the first retval to signal a successful * return as well. */ fprintf(fp, "{ %ld, %ld }", retval[0], retval[1]); retval[0] = 0; break; case Utrace: { size_t len; void *utrace_addr; len = args[sc->offset + 1]; utrace_addr = calloc(1, len); if (get_struct(pid, (void *)args[sc->offset], (void *)utrace_addr, len) != -1) print_utrace(fp, utrace_addr, len); else fprintf(fp, "0x%lx", args[sc->offset]); free(utrace_addr); break; } case IntArray: { int descriptors[16]; unsigned long i, ndescriptors; bool truncated; ndescriptors = args[sc->offset + 1]; truncated = false; if (ndescriptors > nitems(descriptors)) { ndescriptors = nitems(descriptors); truncated = true; } if (get_struct(pid, (void *)args[sc->offset], descriptors, ndescriptors * sizeof(descriptors[0])) != -1) { fprintf(fp, "{"); for (i = 0; i < ndescriptors; i++) fprintf(fp, i == 0 ? " %d" : ", %d", descriptors[i]); fprintf(fp, truncated ? ", ... }" : " }"); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case CloudABIAdvice: fputs(xlookup(cloudabi_advice, args[sc->offset]), fp); break; case CloudABIClockID: fputs(xlookup(cloudabi_clockid, args[sc->offset]), fp); break; case ClouduABIFDSFlags: fputs(xlookup_bits(cloudabi_fdsflags, args[sc->offset]), fp); break; case CloudABIFDStat: { cloudabi_fdstat_t fds; if (get_struct(pid, (void *)args[sc->offset], &fds, sizeof(fds)) != -1) { fprintf(fp, "{ %s, ", xlookup(cloudabi_filetype, fds.fs_filetype)); fprintf(fp, "%s, ... }", xlookup_bits(cloudabi_fdflags, fds.fs_flags)); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case CloudABIFileStat: { cloudabi_filestat_t fsb; if (get_struct(pid, (void *)args[sc->offset], &fsb, sizeof(fsb)) != -1) fprintf(fp, "{ %s, %lu }", xlookup(cloudabi_filetype, fsb.st_filetype), fsb.st_size); else fprintf(fp, "0x%lx", args[sc->offset]); break; } case CloudABIFileType: fputs(xlookup(cloudabi_filetype, args[sc->offset]), fp); break; case CloudABIFSFlags: fputs(xlookup_bits(cloudabi_fsflags, args[sc->offset]), fp); break; case CloudABILookup: if ((args[sc->offset] & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0) fprintf(fp, "%d|LOOKUP_SYMLINK_FOLLOW", (int)args[sc->offset]); else fprintf(fp, "%d", (int)args[sc->offset]); break; case CloudABIMFlags: fputs(xlookup_bits(cloudabi_mflags, args[sc->offset]), fp); break; case CloudABIMProt: fputs(xlookup_bits(cloudabi_mprot, args[sc->offset]), fp); break; case CloudABIMSFlags: fputs(xlookup_bits(cloudabi_msflags, args[sc->offset]), fp); break; case CloudABIOFlags: fputs(xlookup_bits(cloudabi_oflags, args[sc->offset]), fp); break; case CloudABISDFlags: fputs(xlookup_bits(cloudabi_sdflags, args[sc->offset]), fp); break; case CloudABISignal: fputs(xlookup(cloudabi_signal, args[sc->offset]), fp); break; case CloudABISockStat: { cloudabi_sockstat_t ss; if (get_struct(pid, (void *)args[sc->offset], &ss, sizeof(ss)) != -1) { fprintf(fp, "{ %s, ", xlookup( cloudabi_sa_family, ss.ss_sockname.sa_family)); fprintf(fp, "%s, ", xlookup( cloudabi_sa_family, ss.ss_peername.sa_family)); fprintf(fp, "%s, ", xlookup( cloudabi_errno, ss.ss_error)); fprintf(fp, "%s }", xlookup_bits( cloudabi_ssstate, ss.ss_state)); } else fprintf(fp, "0x%lx", args[sc->offset]); break; } case CloudABISSFlags: fputs(xlookup_bits(cloudabi_ssflags, args[sc->offset]), fp); break; case CloudABITimestamp: fprintf(fp, "%lu.%09lus", args[sc->offset] / 1000000000, args[sc->offset] % 1000000000); break; case CloudABIULFlags: fputs(xlookup_bits(cloudabi_ulflags, args[sc->offset]), fp); break; case CloudABIWhence: fputs(xlookup(cloudabi_whence, args[sc->offset]), fp); break; default: errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK); } fclose(fp); return (tmp); } /* * Print (to outfile) the system call and its arguments. */ void print_syscall(struct trussinfo *trussinfo) { struct threadinfo *t; const char *name; char **s_args; int i, len, nargs; t = trussinfo->curthread; name = t->cs.name; nargs = t->cs.nargs; s_args = t->cs.s_args; len = print_line_prefix(trussinfo); len += fprintf(trussinfo->outfile, "%s(", name); for (i = 0; i < nargs; i++) { if (s_args[i] != NULL) len += fprintf(trussinfo->outfile, "%s", s_args[i]); else len += fprintf(trussinfo->outfile, ""); len += fprintf(trussinfo->outfile, "%s", i < (nargs - 1) ? "," : ""); } len += fprintf(trussinfo->outfile, ")"); for (i = 0; i < 6 - (len / 8); i++) fprintf(trussinfo->outfile, "\t"); } void print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval) { struct timespec timediff; struct threadinfo *t; struct syscall *sc; int error; t = trussinfo->curthread; sc = t->cs.sc; if (trussinfo->flags & COUNTONLY) { timespecsubt(&t->after, &t->before, &timediff); timespecadd(&sc->time, &timediff, &sc->time); sc->ncalls++; if (errorp) sc->nerror++; return; } print_syscall(trussinfo); fflush(trussinfo->outfile); if (retval == NULL) { /* * This system call resulted in the current thread's exit, * so there is no return value or error to display. */ fprintf(trussinfo->outfile, "\n"); return; } if (errorp) { error = sysdecode_abi_to_freebsd_errno(t->proc->abi->abi, retval[0]); fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval[0], error == INT_MAX ? "Unknown error" : strerror(error)); } #ifndef __LP64__ else if (sc->ret_type == 2) { off_t off; #if _BYTE_ORDER == _LITTLE_ENDIAN off = (off_t)retval[1] << 32 | retval[0]; #else off = (off_t)retval[0] << 32 | retval[1]; #endif fprintf(trussinfo->outfile, " = %jd (0x%jx)\n", (intmax_t)off, (intmax_t)off); } #endif else fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval[0], retval[0]); } void print_summary(struct trussinfo *trussinfo) { struct timespec total = {0, 0}; struct syscall *sc; int ncall, nerror; fprintf(trussinfo->outfile, "%-20s%15s%8s%8s\n", "syscall", "seconds", "calls", "errors"); ncall = nerror = 0; STAILQ_FOREACH(sc, &syscalls, entries) if (sc->ncalls) { fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n", sc->name, (intmax_t)sc->time.tv_sec, sc->time.tv_nsec, sc->ncalls, sc->nerror); timespecadd(&total, &sc->time, &total); ncall += sc->ncalls; nerror += sc->nerror; } fprintf(trussinfo->outfile, "%20s%15s%8s%8s\n", "", "-------------", "-------", "-------"); fprintf(trussinfo->outfile, "%-20s%5jd.%09ld%8d%8d\n", "", (intmax_t)total.tv_sec, total.tv_nsec, ncall, nerror); }