aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2016-08-24 10:51:33 +0000
committerEd Schouten <ed@FreeBSD.org>2016-08-24 10:51:33 +0000
commit22f2f875ad5dc8e2a0474a3713022df478577603 (patch)
treed8c827c222046d8ff6591f23b555b6d1ad3df6a1
parent3b36d1e469d42a25c74051e00940408c8b905a93 (diff)
downloadsrc-22f2f875ad5dc8e2a0474a3713022df478577603.tar.gz
src-22f2f875ad5dc8e2a0474a3713022df478577603.zip
Make execution of 32-bit CloudABI executables work on amd64.
A nice thing about requiring a vDSO is that it makes it incredibly easy to provide full support for running 32-bit processes on 64-bit systems. Instead of letting the kernel be responsible for composing/decomposing 64-bit arguments across multiple registers/stack slots, all of this can now be done in the vDSO. This means that there is no need to provide duplicate copies of certain system calls, like the sys_lseek() and freebsd32_lseek() we have for COMPAT_FREEBSD32. This change imports a new vDSO from the CloudABI repository that has automatically generated code in it that copies system call arguments into a buffer, padding them to eight bytes and zero-extending any pointers/size_t arguments. After returning from the kernel, it does the inverse: extracting return values, in the process truncating pointers/size_t values to 32 bits. Obtained from: https://github.com/NuxiNL/cloudabi
Notes
Notes: svn path=/head/; revision=304744
-rw-r--r--sys/amd64/cloudabi32/cloudabi32_sysvec.c231
-rw-r--r--sys/amd64/conf/NOTES3
-rw-r--r--sys/conf/files.amd6413
-rw-r--r--sys/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S1223
4 files changed, 1470 insertions, 0 deletions
diff --git a/sys/amd64/cloudabi32/cloudabi32_sysvec.c b/sys/amd64/cloudabi32/cloudabi32_sysvec.c
new file mode 100644
index 000000000000..5cf73ab5bfe3
--- /dev/null
+++ b/sys/amd64/cloudabi32/cloudabi32_sysvec.c
@@ -0,0 +1,231 @@
+/*-
+ * Copyright (c) 2015-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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/imgact.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/sysent.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <machine/frame.h>
+#include <machine/pcb.h>
+#include <machine/vmparam.h>
+
+#include <compat/cloudabi/cloudabi_util.h>
+
+#include <compat/cloudabi32/cloudabi32_syscall.h>
+#include <compat/cloudabi32/cloudabi32_util.h>
+
+#include <compat/ia32/ia32_signal.h>
+#include <compat/ia32/ia32_util.h>
+
+extern const char *cloudabi32_syscallnames[];
+extern struct sysent cloudabi32_sysent[];
+
+extern unsigned long ia32_maxssiz;
+
+static int
+cloudabi32_fixup_tcb(register_t **stack_base, struct image_params *imgp)
+{
+ int error;
+ uint32_t args[2];
+
+ /* Place auxiliary vector and TCB on the stack. */
+ error = cloudabi32_fixup(stack_base, imgp);
+ if (error != 0)
+ return (error);
+
+ /*
+ * On i386, the TCB is referred to by %gs:0. Reuse the empty
+ * space normally used by the return address (args[0]) to store
+ * a single element array, containing a pointer to the TCB. %gs
+ * base will point to this.
+ *
+ * Also let the first argument of the entry point (args[1])
+ * refer to the auxiliary vector, which is stored right after
+ * the TCB.
+ */
+ args[0] = (uintptr_t)*stack_base;
+ args[1] = (uintptr_t)*stack_base +
+ roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t));
+ *stack_base -= howmany(sizeof(args), sizeof(register_t));
+ return (copyout(args, *stack_base, sizeof(args)));
+}
+
+static void
+cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp,
+ unsigned long stack)
+{
+
+ ia32_setregs(td, imgp, stack);
+ (void)cpu_set_user_tls(td, (void *)stack);
+}
+
+static int
+cloudabi32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
+{
+ struct trapframe *frame = td->td_frame;
+ int error;
+
+ /* Obtain system call number. */
+ sa->code = frame->tf_rax;
+ if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL)
+ return (ENOSYS);
+ sa->callp = &cloudabi32_sysent[sa->code];
+ sa->narg = sa->callp->sy_narg;
+
+ /*
+ * Fetch system call arguments.
+ *
+ * The vDSO has already made sure that the arguments are
+ * eight-byte aligned. Pointers and size_t parameters are
+ * zero-extended. This makes it possible to copy in the
+ * arguments directly. As long as the call doesn't use 32-bit
+ * data structures, we can just invoke the same system call
+ * implementation used by 64-bit processes.
+ */
+ error = copyin((void *)frame->tf_rcx, sa->args,
+ sa->narg * sizeof(sa->args[0]));
+ if (error != 0)
+ return (error);
+
+ /* Default system call return values. */
+ td->td_retval[0] = 0;
+ td->td_retval[1] = 0;
+ return (0);
+}
+
+static void
+cloudabi32_set_syscall_retval(struct thread *td, int error)
+{
+ struct trapframe *frame = td->td_frame;
+
+ switch (error) {
+ case 0:
+ /*
+ * System call succeeded.
+ *
+ * Simply copy out the 64-bit return values into the
+ * same buffer provided for system call arguments. The
+ * vDSO will copy them to the right spot, truncating
+ * pointers and size_t values to 32 bits.
+ */
+ frame->tf_rax = copyout(td->td_retval, (void *)frame->tf_rcx,
+ sizeof(td->td_retval)) == 0 ? 0 : CLOUDABI_EFAULT;
+ 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);
+ break;
+ }
+}
+
+static void
+cloudabi32_schedtail(struct thread *td)
+{
+ struct trapframe *frame = td->td_frame;
+ register_t retval[2];
+
+ /* Return values for processes returning from fork. */
+ if ((td->td_pflags & TDP_FORKING) != 0) {
+ retval[0] = CLOUDABI_PROCESS_CHILD;
+ retval[1] = td->td_tid;
+ copyout(retval, (void *)frame->tf_rcx, sizeof(retval));
+ }
+}
+
+int
+cloudabi32_thread_setregs(struct thread *td,
+ const cloudabi32_threadattr_t *attr, uint32_t tcb)
+{
+ stack_t stack;
+ uint32_t args[3];
+ void *frameptr;
+ int error;
+
+ /* Perform standard register initialization. */
+ stack.ss_sp = TO_PTR(attr->stack);
+ stack.ss_size = attr->stack_size - sizeof(args);
+ cpu_set_upcall(td, TO_PTR(attr->entry_point), NULL, &stack);
+
+ /*
+ * Copy the arguments for the thread entry point onto the stack
+ * (args[1] and args[2]). Similar to process startup, use the
+ * otherwise unused return address (args[0]) for TLS.
+ */
+ args[0] = tcb;
+ args[1] = td->td_tid;
+ args[2] = attr->argument;
+ frameptr = (void *)td->td_frame->tf_rsp;
+ error = copyout(args, frameptr, sizeof(args));
+ if (error != 0)
+ return (error);
+
+ return (cpu_set_user_tls(td, frameptr));
+}
+
+static struct sysentvec cloudabi32_elf_sysvec = {
+ .sv_size = CLOUDABI32_SYS_MAXSYSCALL,
+ .sv_table = cloudabi32_sysent,
+ .sv_fixup = cloudabi32_fixup_tcb,
+ .sv_name = "CloudABI ELF32",
+ .sv_coredump = elf32_coredump,
+ .sv_pagesize = IA32_PAGE_SIZE,
+ .sv_minuser = FREEBSD32_MINUSER,
+ .sv_maxuser = FREEBSD32_MAXUSER,
+ .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
+ .sv_copyout_strings = cloudabi32_copyout_strings,
+ .sv_setregs = cloudabi32_proc_setregs,
+ .sv_fixlimit = ia32_fixlimit,
+ .sv_maxssiz = &ia32_maxssiz,
+ .sv_flags = SV_ABI_CLOUDABI | SV_CAPSICUM | SV_IA32 | SV_ILP32,
+ .sv_set_syscall_retval = cloudabi32_set_syscall_retval,
+ .sv_fetch_syscall_args = cloudabi32_fetch_syscall_args,
+ .sv_syscallnames = cloudabi32_syscallnames,
+ .sv_schedtail = cloudabi32_schedtail,
+};
+
+INIT_SYSENTVEC(elf_sysvec, &cloudabi32_elf_sysvec);
+
+Elf32_Brandinfo cloudabi32_brand = {
+ .brand = ELFOSABI_CLOUDABI,
+ .machine = EM_386,
+ .sysvec = &cloudabi32_elf_sysvec,
+ .compat_3_brand = "CloudABI",
+};
diff --git a/sys/amd64/conf/NOTES b/sys/amd64/conf/NOTES
index 387d6da1245a..61a5953cb3d9 100644
--- a/sys/amd64/conf/NOTES
+++ b/sys/amd64/conf/NOTES
@@ -614,6 +614,9 @@ options COMPAT_FREEBSD32
# Emulate spx device for client side of SVR3 local X interface
#XXX#options SPX_HACK
+# Enable 32-bit runtime support for CloudABI binaries.
+options COMPAT_CLOUDABI32
+
# Enable 64-bit runtime support for CloudABI binaries.
options COMPAT_CLOUDABI64
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index f32ebf62d9b0..f4c2bb7724b2 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -8,6 +8,18 @@
# dependency lines other than the first are silently ignored.
#
#
+cloudabi32_vdso.o optional compat_cloudabi32 \
+ dependency "$S/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S" \
+ compile-with "${CC} -x assembler-with-cpp -m32 -shared -nostdinc -nostdlib -Wl,-T$S/compat/cloudabi/cloudabi_vdso.lds $S/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S -o ${.TARGET}" \
+ no-obj no-implicit-rule \
+ clean "cloudabi32_vdso.o"
+#
+cloudabi32_vdso_blob.o optional compat_cloudabi32 \
+ dependency "cloudabi32_vdso.o" \
+ compile-with "${OBJCOPY} --input-target binary --output-target elf64-x86-64-freebsd --binary-architecture i386 cloudabi32_vdso.o ${.TARGET}" \
+ no-implicit-rule \
+ clean "cloudabi32_vdso_blob.o"
+#
cloudabi64_vdso.o optional compat_cloudabi64 \
dependency "$S/contrib/cloudabi/cloudabi_vdso_x86_64.S" \
compile-with "${CC} -x assembler-with-cpp -shared -nostdinc -nostdlib -Wl,-T$S/compat/cloudabi/cloudabi_vdso.lds $S/contrib/cloudabi/cloudabi_vdso_x86_64.S -o ${.TARGET}" \
@@ -146,6 +158,7 @@ amd64/amd64/trap.c standard
amd64/amd64/uio_machdep.c standard
amd64/amd64/uma_machdep.c standard
amd64/amd64/vm_machdep.c standard
+amd64/cloudabi32/cloudabi32_sysvec.c optional compat_cloudabi32
amd64/cloudabi64/cloudabi64_sysvec.c optional compat_cloudabi64
amd64/pci/pci_cfgreg.c optional pci
cddl/contrib/opensolaris/common/atomic/amd64/opensolaris_atomic.S optional zfs | dtrace compile-with "${ZFS_S}"
diff --git a/sys/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S b/sys/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S
new file mode 100644
index 000000000000..74f59dbdc6b3
--- /dev/null
+++ b/sys/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S
@@ -0,0 +1,1223 @@
+// 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
+
+#define ENTRY(name) \
+ .text; \
+ .p2align 2, 0x90; \
+ .global name; \
+ .type name, @function; \
+name:
+
+#define END(name) .size name, . - name
+
+ENTRY(cloudabi_sys_clock_res_get)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $0, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 12(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+ mov -12(%ebp), %edx
+ mov %edx, 4(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_clock_res_get)
+
+ENTRY(cloudabi_sys_clock_time_get)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -4(%ebp)
+ mov $1, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 20(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+ mov -12(%ebp), %edx
+ mov %edx, 4(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_clock_time_get)
+
+ENTRY(cloudabi_sys_condvar_signal)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $2, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_condvar_signal)
+
+ENTRY(cloudabi_sys_fd_close)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $3, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_close)
+
+ENTRY(cloudabi_sys_fd_create1)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $4, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 12(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_create1)
+
+ENTRY(cloudabi_sys_fd_create2)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $5, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 12(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+ mov 16(%ebp), %ecx
+ mov -8(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_create2)
+
+ENTRY(cloudabi_sys_fd_datasync)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $6, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_datasync)
+
+ENTRY(cloudabi_sys_fd_dup)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $7, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 12(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_dup)
+
+ENTRY(cloudabi_sys_fd_pread)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -4(%ebp)
+ mov $8, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 28(%ebp), %ecx
+ mov -32(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_pread)
+
+ENTRY(cloudabi_sys_fd_pwrite)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -4(%ebp)
+ mov $9, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 28(%ebp), %ecx
+ mov -32(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_pwrite)
+
+ENTRY(cloudabi_sys_fd_read)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $10, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 20(%ebp), %ecx
+ mov -24(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_read)
+
+ENTRY(cloudabi_sys_fd_replace)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $11, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_replace)
+
+ENTRY(cloudabi_sys_fd_seek)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $12, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 24(%ebp), %ecx
+ mov -24(%ebp), %edx
+ mov %edx, 0(%ecx)
+ mov -20(%ebp), %edx
+ mov %edx, 4(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_seek)
+
+ENTRY(cloudabi_sys_fd_stat_get)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $13, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_stat_get)
+
+ENTRY(cloudabi_sys_fd_stat_put)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $14, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_stat_put)
+
+ENTRY(cloudabi_sys_fd_sync)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $15, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_sync)
+
+ENTRY(cloudabi_sys_fd_write)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $16, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 20(%ebp), %ecx
+ mov -24(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_fd_write)
+
+ENTRY(cloudabi_sys_file_advise)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -20(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -12(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $17, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_advise)
+
+ENTRY(cloudabi_sys_file_allocate)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -4(%ebp)
+ mov $18, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_allocate)
+
+ENTRY(cloudabi_sys_file_create)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $19, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_create)
+
+ENTRY(cloudabi_sys_file_link)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -48(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -44(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ movl $0, -36(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 32(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $20, %eax
+ mov %ebp, %ecx
+ sub $48, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_link)
+
+ENTRY(cloudabi_sys_file_open)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -36(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $21, %eax
+ mov %ebp, %ecx
+ sub $40, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 32(%ebp), %ecx
+ mov -40(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_file_open)
+
+ENTRY(cloudabi_sys_file_readdir)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -4(%ebp)
+ mov $22, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 28(%ebp), %ecx
+ mov -32(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_file_readdir)
+
+ENTRY(cloudabi_sys_file_readlink)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $23, %eax
+ mov %ebp, %ecx
+ sub $40, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 28(%ebp), %ecx
+ mov -40(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_file_readlink)
+
+ENTRY(cloudabi_sys_file_rename)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -48(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ movl $0, -36(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $24, %eax
+ mov %ebp, %ecx
+ sub $48, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_rename)
+
+ENTRY(cloudabi_sys_file_stat_fget)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $25, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_stat_fget)
+
+ENTRY(cloudabi_sys_file_stat_fput)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $26, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_stat_fput)
+
+ENTRY(cloudabi_sys_file_stat_get)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -28(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $27, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_stat_get)
+
+ENTRY(cloudabi_sys_file_stat_put)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -36(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $28, %eax
+ mov %ebp, %ecx
+ sub $40, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_stat_put)
+
+ENTRY(cloudabi_sys_file_symlink)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ movl $0, -36(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $29, %eax
+ mov %ebp, %ecx
+ sub $40, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_symlink)
+
+ENTRY(cloudabi_sys_file_unlink)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $30, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_file_unlink)
+
+ENTRY(cloudabi_sys_lock_unlock)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $31, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_lock_unlock)
+
+ENTRY(cloudabi_sys_mem_advise)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $32, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_advise)
+
+ENTRY(cloudabi_sys_mem_lock)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $33, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_lock)
+
+ENTRY(cloudabi_sys_mem_map)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -48(%ebp)
+ movl $0, -44(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ movl $0, -36(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov 32(%ebp), %ecx
+ mov %ecx, -4(%ebp)
+ mov $34, %eax
+ mov %ebp, %ecx
+ sub $48, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 36(%ebp), %ecx
+ mov -48(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_map)
+
+ENTRY(cloudabi_sys_mem_protect)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $35, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_protect)
+
+ENTRY(cloudabi_sys_mem_sync)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $36, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_sync)
+
+ENTRY(cloudabi_sys_mem_unlock)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $37, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_unlock)
+
+ENTRY(cloudabi_sys_mem_unmap)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $38, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_mem_unmap)
+
+ENTRY(cloudabi_sys_poll)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $39, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 20(%ebp), %ecx
+ mov -24(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_poll)
+
+ENTRY(cloudabi_sys_poll_fd)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -48(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ movl $0, -36(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 28(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $40, %eax
+ mov %ebp, %ecx
+ sub $48, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 32(%ebp), %ecx
+ mov -48(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_poll_fd)
+
+ENTRY(cloudabi_sys_proc_exec)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -40(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ movl $0, -28(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ movl $0, -20(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 24(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $41, %eax
+ mov %ebp, %ecx
+ sub $40, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_proc_exec)
+
+ENTRY(cloudabi_sys_proc_exit)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $42, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+END(cloudabi_sys_proc_exit)
+
+ENTRY(cloudabi_sys_proc_fork)
+ push %ebp
+ mov %esp, %ebp
+ mov $43, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 8(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+ mov 12(%ebp), %ecx
+ mov -8(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_proc_fork)
+
+ENTRY(cloudabi_sys_proc_raise)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov $44, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_proc_raise)
+
+ENTRY(cloudabi_sys_random_get)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $45, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_random_get)
+
+ENTRY(cloudabi_sys_sock_accept)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $46, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 16(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_accept)
+
+ENTRY(cloudabi_sys_sock_bind)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $47, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_bind)
+
+ENTRY(cloudabi_sys_sock_connect)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -32(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 20(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $48, %eax
+ mov %ebp, %ecx
+ sub $32, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_connect)
+
+ENTRY(cloudabi_sys_sock_listen)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $49, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_listen)
+
+ENTRY(cloudabi_sys_sock_recv)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $50, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_recv)
+
+ENTRY(cloudabi_sys_sock_send)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ movl $0, -4(%ebp)
+ mov $51, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_send)
+
+ENTRY(cloudabi_sys_sock_shutdown)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $52, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_shutdown)
+
+ENTRY(cloudabi_sys_sock_stat_get)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -24(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 16(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $53, %eax
+ mov %ebp, %ecx
+ sub $24, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_sock_stat_get)
+
+ENTRY(cloudabi_sys_thread_create)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov $54, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ test %eax, %eax
+ jnz 1f
+ mov 12(%ebp), %ecx
+ mov -16(%ebp), %edx
+ mov %edx, 0(%ecx)
+1:
+ pop %ebp
+ ret
+END(cloudabi_sys_thread_create)
+
+ENTRY(cloudabi_sys_thread_exit)
+ push %ebp
+ mov %esp, %ebp
+ mov 8(%ebp), %ecx
+ mov %ecx, -16(%ebp)
+ movl $0, -12(%ebp)
+ mov 12(%ebp), %ecx
+ mov %ecx, -8(%ebp)
+ mov $55, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+END(cloudabi_sys_thread_exit)
+
+ENTRY(cloudabi_sys_thread_yield)
+ push %ebp
+ mov %esp, %ebp
+ mov $56, %eax
+ mov %ebp, %ecx
+ sub $16, %ecx
+ int $0x80
+ pop %ebp
+ ret
+END(cloudabi_sys_thread_yield)