]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/v850/clone.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / v850 / clone.c
1 /*
2  * libc/sysdeps/linux/v850/clone.c -- `clone' syscall for linux/v850
3  *
4  *  Copyright (C) 2002,03  NEC Electronics Corporation
5  *  Copyright (C) 2002,03  Miles Bader <miles@gnu.org>
6  *
7  * This file is subject to the terms and conditions of the GNU Lesser
8  * General Public License.  See the file COPYING.LIB in the main
9  * directory of this archive for more details.
10  *
11  * Written by Miles Bader <miles@gnu.org>
12  */
13
14 #include <errno.h>
15 #include <sys/syscall.h>
16
17 int
18 clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
19 {
20   register unsigned long rval __asm__ (SYSCALL_RET) = -EINVAL;
21
22   if (fn && child_stack)
23     {
24       register unsigned long syscall __asm__ (SYSCALL_NUM);
25       register unsigned long arg0 __asm__ (SYSCALL_ARG0);
26       register unsigned long arg1 __asm__ (SYSCALL_ARG1);
27
28       /* Clone this thread.  */
29       arg0 = flags;
30       arg1 = (unsigned long)child_stack;
31       syscall = __NR_clone;
32       __asm__ __volatile__ ("trap " SYSCALL_SHORT_TRAP
33                     : "=r" (rval), "=r" (syscall)
34                     : "1" (syscall), "r" (arg0), "r" (arg1)
35                     : SYSCALL_SHORT_CLOBBERS);
36
37       if (rval == 0)
38         /* In child thread, call FN and exit.  */
39         {
40           arg0 = (*fn) (arg);
41           syscall = __NR_exit;
42           __asm__ __volatile__ ("trap " SYSCALL_SHORT_TRAP
43                         : "=r" (rval), "=r" (syscall)
44                         : "1" (syscall), "r" (arg0)
45                         : SYSCALL_SHORT_CLOBBERS);
46         }
47     }
48
49   __syscall_return (int, rval);
50 }