Index: head/sys/amd64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- head/sys/amd64/cloudabi64/cloudabi64_sysvec.c (revision 297612) +++ head/sys/amd64/cloudabi64/cloudabi64_sysvec.c (revision 297613) @@ -1,161 +1,217 @@ /*- * 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 extern const char *cloudabi64_syscallnames[]; extern struct sysent cloudabi64_sysent[]; static int +cloudabi64_fixup_tcb(register_t **stack_base, struct image_params *imgp) +{ + int error; + register_t tcbptr; + + /* Place auxiliary vector and TCB on the stack. */ + error = cloudabi64_fixup(stack_base, imgp); + if (error != 0) + return (error); + + /* + * On x86-64, the TCB is referred to by %fs:0. Take some space + * from the top of the stack to store a single element array, + * containing a pointer to the TCB. %fs base will point to this. + */ + tcbptr = (register_t)*stack_base; + return (copyout(&tcbptr, --*stack_base, sizeof(tcbptr))); +} + +static void +cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp, + unsigned long stack) +{ + struct trapframe *regs; + + exec_setregs(td, imgp, stack); + + /* + * The stack now contains a pointer to the TCB, the TCB itself, + * and the auxiliary vector. Let %rdx point to the auxiliary + * vector, and set %fs base to the address of the TCB. + */ + regs = td->td_frame; + regs->tf_rdi = stack + sizeof(register_t) + + roundup(sizeof(cloudabi64_tcb_t), sizeof(register_t)); + (void)cpu_set_user_tls(td, (void *)stack); +} + +static int cloudabi64_fetch_syscall_args(struct thread *td, struct syscall_args *sa) { struct trapframe *frame = td->td_frame; /* Obtain system call number. */ sa->code = frame->tf_rax; if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL) return (ENOSYS); sa->callp = &cloudabi64_sysent[sa->code]; /* Fetch system call arguments. */ sa->args[0] = frame->tf_rdi; sa->args[1] = frame->tf_rsi; sa->args[2] = frame->tf_rdx; sa->args[3] = frame->tf_rcx; /* Actually %r10. */ sa->args[4] = frame->tf_r8; sa->args[5] = frame->tf_r9; /* Default system call return values. */ td->td_retval[0] = 0; td->td_retval[1] = frame->tf_rdx; return (0); } static void cloudabi64_set_syscall_retval(struct thread *td, int error) { struct trapframe *frame = td->td_frame; switch (error) { case 0: /* System call succeeded. */ frame->tf_rax = td->td_retval[0]; frame->tf_rdx = td->td_retval[1]; frame->tf_rflags &= ~PSL_C; break; case ERESTART: /* Restart system call. */ frame->tf_rip -= frame->tf_err; frame->tf_r10 = frame->tf_rcx; set_pcb_flags(td->td_pcb, PCB_FULL_IRET); break; case EJUSTRETURN: break; default: /* System call returned an error. */ frame->tf_rax = cloudabi_convert_errno(error); frame->tf_rflags |= PSL_C; break; } } static void cloudabi64_schedtail(struct thread *td) { struct trapframe *frame = td->td_frame; /* Initial register values for processes returning from fork. */ frame->tf_rax = CLOUDABI_PROCESS_CHILD; frame->tf_rdx = td->td_tid; } -void +int cloudabi64_thread_setregs(struct thread *td, - const cloudabi64_threadattr_t *attr) + const cloudabi64_threadattr_t *attr, uint64_t tcb) { struct trapframe *frame; stack_t stack; + uint64_t tcbptr; + int error; + /* + * On x86-64, the TCB is referred to by %fs:0. Take some space + * from the top of the stack to store a single element array, + * containing a pointer to the TCB. %fs base will point to this. + */ + tcbptr = rounddown(attr->stack + attr->stack_size - sizeof(tcbptr), + _Alignof(tcbptr)); + error = copyout(&tcb, (void *)tcbptr, sizeof(tcb)); + if (error != 0) + return (error); + /* Perform standard register initialization. */ stack.ss_sp = (void *)attr->stack; - stack.ss_size = attr->stack_size; + stack.ss_size = tcbptr - attr->stack; cpu_set_upcall_kse(td, (void *)attr->entry_point, NULL, &stack); /* * Pass in the thread ID of the new thread and the argument * pointer provided by the parent thread in as arguments to the * entry point. */ frame = td->td_frame; frame->tf_rdi = td->td_tid; frame->tf_rsi = attr->argument; + + return (cpu_set_user_tls(td, (void *)tcbptr)); } static struct sysentvec cloudabi64_elf_sysvec = { .sv_size = CLOUDABI64_SYS_MAXSYSCALL, .sv_table = cloudabi64_sysent, - .sv_fixup = cloudabi64_fixup, + .sv_fixup = cloudabi64_fixup_tcb, .sv_name = "CloudABI ELF64", .sv_coredump = elf64_coredump, .sv_pagesize = PAGE_SIZE, .sv_minuser = VM_MIN_ADDRESS, .sv_maxuser = VM_MAXUSER_ADDRESS, .sv_usrstack = USRSTACK, .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, .sv_copyout_strings = cloudabi64_copyout_strings, + .sv_setregs = cloudabi64_proc_setregs, .sv_flags = SV_ABI_CLOUDABI | SV_CAPSICUM | SV_LP64, .sv_set_syscall_retval = cloudabi64_set_syscall_retval, .sv_fetch_syscall_args = cloudabi64_fetch_syscall_args, .sv_syscallnames = cloudabi64_syscallnames, .sv_schedtail = cloudabi64_schedtail, }; INIT_SYSENTVEC(elf_sysvec, &cloudabi64_elf_sysvec); Elf64_Brandinfo cloudabi64_brand = { .brand = ELFOSABI_CLOUDABI, .machine = EM_X86_64, .sysvec = &cloudabi64_elf_sysvec, .flags = BI_CAN_EXEC_DYN, .compat_3_brand = "CloudABI", }; Index: head/sys/arm64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- head/sys/arm64/cloudabi64/cloudabi64_sysvec.c (revision 297612) +++ head/sys/arm64/cloudabi64/cloudabi64_sysvec.c (revision 297613) @@ -1,162 +1,186 @@ /*- * 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 extern const char *cloudabi64_syscallnames[]; extern struct sysent cloudabi64_sysent[]; +static void +cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp, + unsigned long stack) +{ + struct trapframe *regs; + + exec_setregs(td, imgp, stack); + + /* + * The stack now contains a pointer to the TCB and the auxiliary + * vector. Let x0 point to the auxiliary vector, and set + * tpidr_el0 to the TCB. + */ + regs = td->td_frame; + regs->tf_x[0] = td->td_retval[0] = + stack + roundup(sizeof(cloudabi64_tcb_t), sizeof(register_t)); + (void)cpu_set_user_tls(td, (void *)stack); +} + static int cloudabi64_fetch_syscall_args(struct thread *td, struct syscall_args *sa) { struct trapframe *frame = td->td_frame; int i; /* Obtain system call number. */ sa->code = frame->tf_x[8]; if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL) return (ENOSYS); sa->callp = &cloudabi64_sysent[sa->code]; /* Fetch system call arguments. */ for (i = 0; i < MAXARGS; i++) sa->args[i] = frame->tf_x[i]; /* Default system call return values. */ td->td_retval[0] = 0; td->td_retval[1] = frame->tf_x[1]; return (0); } static void cloudabi64_set_syscall_retval(struct thread *td, int error) { struct trapframe *frame = td->td_frame; switch (error) { case 0: /* System call succeeded. */ frame->tf_x[0] = td->td_retval[0]; frame->tf_x[1] = td->td_retval[1]; frame->tf_spsr &= ~PSR_C; break; case ERESTART: /* Restart system call. */ frame->tf_elr -= 4; break; case EJUSTRETURN: break; default: /* System call returned an error. */ frame->tf_x[0] = cloudabi_convert_errno(error); frame->tf_spsr |= PSR_C; break; } } static void cloudabi64_schedtail(struct thread *td) { struct trapframe *frame = td->td_frame; /* * Initial register values for processes returning from fork. * Make sure that we only set these values when forking, not * when creating a new thread. */ if ((td->td_pflags & TDP_FORKING) != 0) { frame->tf_x[0] = CLOUDABI_PROCESS_CHILD; frame->tf_x[1] = td->td_tid; } } -void +int cloudabi64_thread_setregs(struct thread *td, - const cloudabi64_threadattr_t *attr) + const cloudabi64_threadattr_t *attr, uint64_t tcb) { struct trapframe *frame; stack_t stack; /* Perform standard register initialization. */ stack.ss_sp = (void *)attr->stack; stack.ss_size = attr->stack_size; cpu_set_upcall_kse(td, (void *)attr->entry_point, NULL, &stack); /* * Pass in the thread ID of the new thread and the argument * pointer provided by the parent thread in as arguments to the * entry point. */ frame = td->td_frame; frame->tf_x[0] = td->td_tid; frame->tf_x[1] = attr->argument; + + /* Set up TLS. */ + return (cpu_set_user_tls(td, (void *)tcb)); } static struct sysentvec cloudabi64_elf_sysvec = { .sv_size = CLOUDABI64_SYS_MAXSYSCALL, .sv_table = cloudabi64_sysent, .sv_fixup = cloudabi64_fixup, .sv_name = "CloudABI ELF64", .sv_coredump = elf64_coredump, .sv_pagesize = PAGE_SIZE, .sv_minuser = VM_MIN_ADDRESS, .sv_maxuser = VM_MAXUSER_ADDRESS, .sv_usrstack = USRSTACK, .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, .sv_copyout_strings = cloudabi64_copyout_strings, + .sv_setregs = cloudabi64_proc_setregs, .sv_flags = SV_ABI_CLOUDABI | SV_CAPSICUM | SV_LP64, .sv_set_syscall_retval = cloudabi64_set_syscall_retval, .sv_fetch_syscall_args = cloudabi64_fetch_syscall_args, .sv_syscallnames = cloudabi64_syscallnames, .sv_schedtail = cloudabi64_schedtail, }; INIT_SYSENTVEC(elf_sysvec, &cloudabi64_elf_sysvec); Elf64_Brandinfo cloudabi64_brand = { .brand = ELFOSABI_CLOUDABI, .machine = EM_AARCH64, .sysvec = &cloudabi64_elf_sysvec, .flags = BI_CAN_EXEC_DYN, .compat_3_brand = "CloudABI", }; Index: head/sys/compat/cloudabi64/cloudabi64_module.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_module.c (revision 297612) +++ head/sys/compat/cloudabi64/cloudabi64_module.c (revision 297613) @@ -1,150 +1,156 @@ /*- * 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 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), VAL(CLOUDABI_AT_BASE, args->base), 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))); + error = copyout(auxv, *stack_base, sizeof(auxv)); + if (error != 0) + return (error); + + /* Reserve space for storing the TCB. */ + *stack_base -= howmany(sizeof(cloudabi64_tcb_t), sizeof(register_t)); + return (0); } 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_thread.c =================================================================== --- head/sys/compat/cloudabi64/cloudabi64_thread.c (revision 297612) +++ head/sys/compat/cloudabi64/cloudabi64_thread.c (revision 297613) @@ -1,71 +1,77 @@ /*- * 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 struct thread_create_args { cloudabi64_threadattr_t attr; + uint64_t tcb; 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); + return (cloudabi64_thread_setregs(td, &args->attr, args->tcb)); } 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); + + /* Remove some space on the top of the stack for the TCB. */ + args.tcb = rounddown(args.attr.stack + args.attr.stack_size - + sizeof(cloudabi64_tcb_t), _Alignof(cloudabi64_tcb_t)); + args.attr.stack_size = args.tcb - args.attr.stack; + 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 297612) +++ head/sys/compat/cloudabi64/cloudabi64_util.h (revision 297613) @@ -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 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 *); +int cloudabi64_thread_setregs(struct thread *, + const cloudabi64_threadattr_t *, uint64_t); #endif Index: head/sys/contrib/cloudabi/cloudabi64_types.h =================================================================== --- head/sys/contrib/cloudabi/cloudabi64_types.h (revision 297612) +++ head/sys/contrib/cloudabi/cloudabi64_types.h (revision 297613) @@ -1,225 +1,232 @@ // Copyright (c) 2016 Nuxi (https://nuxi.nl/) and contributors. // // 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 void cloudabi64_processentry_t(uint64_t auxv); 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_scope_t condvar_scope; _Alignas(1) cloudabi_scope_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_scope_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 struct { + _Alignas(8) uint64_t parent; +} cloudabi64_tcb_t; +_Static_assert(offsetof(cloudabi64_tcb_t, parent) == 0, "Incorrect layout"); +_Static_assert(sizeof(cloudabi64_tcb_t) == 8, "Incorrect layout"); +_Static_assert(_Alignof(cloudabi64_tcb_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