riscv64: fix linking with binutils 2.40
[uclibc-ng.git] / libc / sysdeps / linux / csky / clone.c
blobf0fcc257bf0d2a7f331b9e3c5d865f9c6a151e13
1 /*
2 * Copyright (C) 2017 Hangzhou C-SKY Microsystems co.,ltd.
4 * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
5 * in this tarball.
6 */
8 #include <stdarg.h>
9 #include <sysdep.h>
10 #include <unistd.h>
12 extern long __syscall_error(int err_no);
14 extern int __csky_clone (
15 int flags,
16 void *child_stack,
17 pid_t *ptid,
18 pid_t *ctid,
19 void *tls);
21 int __clone(
22 int (*fn)(void *),
23 void *child_stack,
24 int flags,
25 void *arg, ...)
27 void *ptid;
28 void *tls;
29 void *ctid;
30 va_list al;
31 int err;
33 va_start(al, arg);
34 ptid = va_arg(al, void *);
35 tls = va_arg(al, void *);
36 ctid = va_arg(al, void *);
37 va_end(al);
39 err = EINVAL;
40 if (!fn)
41 goto err;
42 if (!child_stack)
43 goto err;
45 /* prepare fn&arg in child_stack */
46 child_stack = (void *)((unsigned int)child_stack - 8);
47 *(unsigned int *)child_stack = (unsigned int)fn;
48 *(unsigned int *)(child_stack + 4) = (unsigned int)arg;
50 return __csky_clone(flags, child_stack, ptid, ctid, tls);
51 err:
52 return __syscall_error(-err);
54 weak_alias(__clone, clone)