clone.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <sched.h>
  2. #include <signal.h>
  3. #include <sys/mman.h>
  4. #include <sys/time.h>
  5. #include <asm/unistd.h>
  6. #include <asm/page.h>
  7. #include "ptrace_user.h"
  8. #include "skas.h"
  9. #include "stub-data.h"
  10. #include "uml-config.h"
  11. #include "sysdep/stub.h"
  12. /* This is in a separate file because it needs to be compiled with any
  13. * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
  14. */
  15. void __attribute__ ((__section__ (".__syscall_stub")))
  16. stub_clone_handler(void)
  17. {
  18. long err;
  19. struct stub_data *from = (struct stub_data *) UML_CONFIG_STUB_DATA;
  20. err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
  21. UML_CONFIG_STUB_DATA + PAGE_SIZE / 2 -
  22. sizeof(void *));
  23. if(err != 0)
  24. goto out;
  25. err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
  26. if(err)
  27. goto out;
  28. err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
  29. (long) &from->timer, 0);
  30. if(err)
  31. goto out;
  32. err = stub_syscall6(STUB_MMAP_NR, UML_CONFIG_STUB_DATA, PAGE_SIZE,
  33. PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED,
  34. from->fd, from->offset);
  35. out:
  36. /* save current result. Parent: pid; child: retcode of mmap */
  37. from->err = err;
  38. trap_myself();
  39. }