summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/v850/clone.c
diff options
context:
space:
mode:
authorMiles Bader <miles@lsi.nec.co.jp>2002-12-18 02:16:29 +0000
committerMiles Bader <miles@lsi.nec.co.jp>2002-12-18 02:16:29 +0000
commitad9be0e47c4228fa4f73511c4c22abe6734b4dbe (patch)
treee90ed569b918e180f265a5d2de8c2b05f5b7cd9d /libc/sysdeps/linux/v850/clone.c
parent04fb23f5b3ebb7f34241fe472858183368a44fd6 (diff)
Initial checkin
Diffstat (limited to 'libc/sysdeps/linux/v850/clone.c')
-rw-r--r--libc/sysdeps/linux/v850/clone.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/v850/clone.c b/libc/sysdeps/linux/v850/clone.c
new file mode 100644
index 000000000..33e96b449
--- /dev/null
+++ b/libc/sysdeps/linux/v850/clone.c
@@ -0,0 +1,48 @@
+/*
+ * libc/sysdeps/linux/v850/clone.c -- `clone' syscall for linux/v850
+ *
+ * Copyright (C) 2002 NEC Electronics Corporation
+ * Copyright (C) 2002 Miles Bader <miles@gnu.org>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file COPYING in the main directory of this
+ * archive for more details.
+ *
+ * Written by Miles Bader <miles@gnu.org>
+ */
+
+#include <errno.h>
+#include <sys/syscall.h>
+
+int
+clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
+{
+ register unsigned long rval asm (SYSCALL_RET) = -EINVAL;
+
+ if (fn && child_stack)
+ {
+ register unsigned long syscall asm (SYSCALL_NUM);
+ register unsigned long arg0 asm (SYSCALL_ARG0);
+
+ /* Clone this thread. */
+ arg0 = flags;
+ syscall = __NR_clone;
+ asm volatile ("trap " SYSCALL_SHORT_TRAP
+ : "=r" (rval), "=r" (syscall)
+ : "1" (syscall), "r" (arg0)
+ : SYSCALL_SHORT_CLOBBERS);
+
+ if (rval == 0)
+ /* In child thread, call FN and exit. */
+ {
+ arg0 = (*fn) (arg);
+ syscall = __NR_exit;
+ asm volatile ("trap " SYSCALL_SHORT_TRAP
+ : "=r" (rval), "=r" (syscall)
+ : "1" (syscall), "r" (arg0)
+ : SYSCALL_SHORT_CLOBBERS);
+ }
+ }
+
+ __syscall_return (int, rval);
+}