clone.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "kern_constants.h"
  13. /* This is in a separate file because it needs to be compiled with any
  14. * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
  15. *
  16. * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
  17. * on some systems.
  18. */
  19. #define STUB_DATA(field) (((struct stub_data *) UML_CONFIG_STUB_DATA)->field)
  20. void __attribute__ ((__section__ (".__syscall_stub")))
  21. stub_clone_handler(void)
  22. {
  23. long err;
  24. err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
  25. UML_CONFIG_STUB_DATA + UM_KERN_PAGE_SIZE / 2 -
  26. sizeof(void *));
  27. if(err != 0)
  28. goto out;
  29. err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
  30. if(err)
  31. goto out;
  32. err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
  33. (long) &STUB_DATA(timer), 0);
  34. if(err)
  35. goto out;
  36. err = stub_syscall6(STUB_MMAP_NR, UML_CONFIG_STUB_DATA,
  37. UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
  38. MAP_FIXED | MAP_SHARED, STUB_DATA(fd),
  39. STUB_DATA(offset));
  40. out:
  41. /* save current result. Parent: pid; child: retcode of mmap */
  42. STUB_DATA(err) = err;
  43. trap_myself();
  44. }