clone.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "as-layout.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. void __attribute__ ((__section__ (".__syscall_stub")))
  20. stub_clone_handler(void)
  21. {
  22. struct stub_data *data = (struct stub_data *) STUB_DATA;
  23. long err;
  24. err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
  25. STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
  26. if(err != 0)
  27. goto out;
  28. err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
  29. if(err)
  30. goto out;
  31. err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
  32. (long) &data->timer, 0);
  33. if(err)
  34. goto out;
  35. remap_stack(data->fd, data->offset);
  36. goto done;
  37. out:
  38. /* save current result.
  39. * Parent: pid;
  40. * child: retcode of mmap already saved and it jumps around this
  41. * assignment
  42. */
  43. data->err = err;
  44. done:
  45. trap_myself();
  46. }