clone.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
  3. * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  4. * Licensed under the GPL
  5. */
  6. #include <signal.h>
  7. #include <sched.h>
  8. #include <asm/unistd.h>
  9. #include <sys/time.h>
  10. #include <as-layout.h>
  11. #include <ptrace_user.h>
  12. #include <stub-data.h>
  13. #include <sysdep/stub.h>
  14. /*
  15. * This is in a separate file because it needs to be compiled with any
  16. * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
  17. *
  18. * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
  19. * on some systems.
  20. */
  21. void __attribute__ ((__section__ (".__syscall_stub")))
  22. stub_clone_handler(void)
  23. {
  24. struct stub_data *data = (struct stub_data *) STUB_DATA;
  25. long err;
  26. err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
  27. STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
  28. if (err != 0)
  29. goto out;
  30. err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
  31. if (err)
  32. goto out;
  33. remap_stack(data->fd, data->offset);
  34. goto done;
  35. out:
  36. /*
  37. * save current result.
  38. * Parent: pid;
  39. * child: retcode of mmap already saved and it jumps around this
  40. * assignment
  41. */
  42. data->err = err;
  43. done:
  44. trap_myself();
  45. }