exec_user.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <stdlib.h>
  8. #include <sched.h>
  9. #include <errno.h>
  10. #include <sys/wait.h>
  11. #include <signal.h>
  12. #include "user_util.h"
  13. #include "kern_util.h"
  14. #include "user.h"
  15. #include "ptrace_user.h"
  16. #include "os.h"
  17. void do_exec(int old_pid, int new_pid)
  18. {
  19. unsigned long regs[FRAME_SIZE];
  20. int err;
  21. if((ptrace(PTRACE_ATTACH, new_pid, 0, 0) < 0) ||
  22. (ptrace(PTRACE_CONT, new_pid, 0, 0) < 0))
  23. tracer_panic("do_exec failed to attach proc - errno = %d",
  24. errno);
  25. CATCH_EINTR(err = waitpid(new_pid, 0, WUNTRACED));
  26. if (err < 0)
  27. tracer_panic("do_exec failed to attach proc in waitpid - errno = %d",
  28. errno);
  29. if(ptrace_getregs(old_pid, regs) < 0)
  30. tracer_panic("do_exec failed to get registers - errno = %d",
  31. errno);
  32. os_kill_ptraced_process(old_pid, 0);
  33. if (ptrace(PTRACE_OLDSETOPTIONS, new_pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
  34. tracer_panic("do_exec: PTRACE_SETOPTIONS failed, errno = %d", errno);
  35. if(ptrace_setregs(new_pid, regs) < 0)
  36. tracer_panic("do_exec failed to start new proc - errno = %d",
  37. errno);
  38. }
  39. /*
  40. * Overrides for Emacs so that we follow Linus's tabbing style.
  41. * Emacs will notice this stuff at the end of the file and automatically
  42. * adjust the settings for this buffer only. This must remain at the end
  43. * of the file.
  44. * ---------------------------------------------------------------------------
  45. * Local variables:
  46. * c-file-style: "linux"
  47. * End:
  48. */