clone.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "ptrace_user.h"
  11. #include "stub-data.h"
  12. #include "sysdep/stub.h"
  13. /*
  14. * This is in a separate file because it needs to be compiled with any
  15. * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
  16. *
  17. * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
  18. * on some systems.
  19. */
  20. void __attribute__ ((__section__ (".__syscall_stub")))
  21. stub_clone_handler(void)
  22. {
  23. struct stub_data *data = (struct stub_data *) STUB_DATA;
  24. long err;
  25. err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
  26. STUB_DATA + UM_KERN_PAGE_SIZE / 2 - 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) &data->timer, 0);
  34. if (err)
  35. goto out;
  36. remap_stack(data->fd, data->offset);
  37. goto done;
  38. out:
  39. /*
  40. * save current result.
  41. * Parent: pid;
  42. * child: retcode of mmap already saved and it jumps around this
  43. * assignment
  44. */
  45. data->err = err;
  46. done:
  47. trap_myself();
  48. }