clone.c 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (C) 2004 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <sched.h>
  9. #include <errno.h>
  10. #include <sys/syscall.h>
  11. #include <unistd.h>
  12. int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...)
  13. {
  14. int rval = -EINVAL;
  15. if (fn && child_stack)
  16. rval = INTERNAL_SYSCALL(clone, 0, 2, flags, child_stack);
  17. if (rval == 0)
  18. {
  19. int exitCode = fn(arg);
  20. rval = INTERNAL_SYSCALL(exit, 0, 1, exitCode);
  21. }
  22. return rval;
  23. }
  24. #ifdef __NR_clone2
  25. int
  26. __clone2(int (*fn)(void *arg), void *child_stack, size_t stack_size,
  27. int flags, void *arg, ...)
  28. {
  29. int rval = -EINVAL;
  30. if (fn && child_stack)
  31. {
  32. rval = INTERNAL_SYSCALL(clone2, 0, 3, flags, child_stack, stack_size);
  33. }
  34. if (rval == 0)
  35. {
  36. int exitCode = fn(arg);
  37. rval = INTERNAL_SYSCALL(exit, 0, 1, exitCode);
  38. }
  39. return rval;
  40. }
  41. #endif