tt.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <signal.h>
  8. #include <sched.h>
  9. #include <errno.h>
  10. #include <stdarg.h>
  11. #include <stdlib.h>
  12. #include <setjmp.h>
  13. #include <sys/time.h>
  14. #include <sys/ptrace.h>
  15. #include <linux/ptrace.h>
  16. #include <sys/wait.h>
  17. #include <sys/mman.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/unistd.h>
  20. #include <asm/page.h>
  21. #include "user_util.h"
  22. #include "kern_util.h"
  23. #include "user.h"
  24. #include "signal_kern.h"
  25. #include "signal_user.h"
  26. #include "sysdep/ptrace.h"
  27. #include "sysdep/sigcontext.h"
  28. #include "irq_user.h"
  29. #include "ptrace_user.h"
  30. #include "time_user.h"
  31. #include "init.h"
  32. #include "os.h"
  33. #include "uml-config.h"
  34. #include "choose-mode.h"
  35. #include "mode.h"
  36. #include "tempfile.h"
  37. /*
  38. *-------------------------
  39. * only for tt mode (will be deleted in future...)
  40. *-------------------------
  41. */
  42. struct tramp {
  43. int (*tramp)(void *);
  44. void *tramp_data;
  45. unsigned long temp_stack;
  46. int flags;
  47. int pid;
  48. };
  49. /* See above for why sigkill is here */
  50. int sigkill = SIGKILL;
  51. int outer_tramp(void *arg)
  52. {
  53. struct tramp *t;
  54. int sig = sigkill;
  55. t = arg;
  56. t->pid = clone(t->tramp, (void *) t->temp_stack + page_size()/2,
  57. t->flags, t->tramp_data);
  58. if(t->pid > 0) wait_for_stop(t->pid, SIGSTOP, PTRACE_CONT, NULL);
  59. kill(os_getpid(), sig);
  60. _exit(0);
  61. }
  62. int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
  63. int clone_flags, int (*tramp)(void *))
  64. {
  65. struct tramp arg;
  66. unsigned long sp;
  67. int new_pid, status, err;
  68. /* The trampoline will run on the temporary stack */
  69. sp = stack_sp(temp_stack);
  70. clone_flags |= CLONE_FILES | SIGCHLD;
  71. arg.tramp = tramp;
  72. arg.tramp_data = thread_arg;
  73. arg.temp_stack = temp_stack;
  74. arg.flags = clone_flags;
  75. /* Start the process and wait for it to kill itself */
  76. new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg);
  77. if(new_pid < 0)
  78. return(new_pid);
  79. CATCH_EINTR(err = waitpid(new_pid, &status, 0));
  80. if(err < 0)
  81. panic("Waiting for outer trampoline failed - errno = %d",
  82. errno);
  83. if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL))
  84. panic("outer trampoline didn't exit with SIGKILL, "
  85. "status = %d", status);
  86. return(arg.pid);
  87. }
  88. void forward_pending_sigio(int target)
  89. {
  90. sigset_t sigs;
  91. if(sigpending(&sigs))
  92. panic("forward_pending_sigio : sigpending failed");
  93. if(sigismember(&sigs, SIGIO))
  94. kill(target, SIGIO);
  95. }