clone.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <signal.h>
  6. #include <sched.h>
  7. #include <asm/unistd.h>
  8. #include <sys/time.h>
  9. #include "as-layout.h"
  10. #include "kern_constants.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. err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
  34. (long) &data->timer, 0);
  35. if (err)
  36. goto out;
  37. remap_stack(data->fd, data->offset);
  38. goto done;
  39. out:
  40. /*
  41. * save current result.
  42. * Parent: pid;
  43. * child: retcode of mmap already saved and it jumps around this
  44. * assignment
  45. */
  46. data->err = err;
  47. done:
  48. trap_myself();
  49. }