clone.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2017 Hangzhou C-SKY Microsystems co.,ltd.
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
  5. * in this tarball.
  6. */
  7. #include <stdarg.h>
  8. #include <sysdep.h>
  9. #include <unistd.h>
  10. extern int __syscall_error(int err_no);
  11. extern int __csky_clone (
  12. int flags,
  13. void *child_stack,
  14. pid_t *ptid,
  15. pid_t *ctid,
  16. void *tls);
  17. int __clone(
  18. int (*fn)(void *),
  19. void *child_stack,
  20. int flags,
  21. void *arg, ...)
  22. {
  23. void *ptid;
  24. void *tls;
  25. void *ctid;
  26. va_list al;
  27. int err;
  28. va_start(al, arg);
  29. ptid = va_arg(al, void *);
  30. tls = va_arg(al, void *);
  31. ctid = va_arg(al, void *);
  32. va_end(al);
  33. err = EINVAL;
  34. if (!fn)
  35. goto err;
  36. if (!child_stack)
  37. goto err;
  38. /* prepare fn&arg in child_stack */
  39. child_stack = (void *)((unsigned int)child_stack - 8);
  40. *(unsigned int *)child_stack = (unsigned int)fn;
  41. *(unsigned int *)(child_stack + 4) = (unsigned int)arg;
  42. return __csky_clone(flags, child_stack, ptid, ctid, tls);
  43. err:
  44. return __syscall_error(-err);
  45. }
  46. weak_alias(__clone, clone)