12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #include <errno.h>
- #include <sys/syscall.h>
- #include <sched.h>
- #include <unistd.h>
- int
- clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...)
- {
- int err;
-
-
- __asm__ __volatile__ (
- "l.sw -4(%0),%1;"
- "l.sw -8(%0),%2;"
- :
- : "r" (child_stack), "r" (fn), "r" (arg)
- );
-
- err = -EINVAL;
- if (!fn)
- goto syscall_error;
- if (!child_stack)
- goto syscall_error;
- err = INLINE_SYSCALL(clone, 2, flags, child_stack);
-
- if (err < 0)
- goto syscall_error;
- else if (err != 0) {
- return err;
- }
-
-
- __asm__ __volatile__ (
- "l.lwz %0,-4(%2);"
- "l.lwz %1,-8(%2);"
- : "=&r" (fn), "=r" (arg)
- : "r" (child_stack)
- : "0", "1"
- );
- _exit(fn(arg));
- syscall_error:
- __set_errno (-err);
- return -1;
- }
|