home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3971 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  3.5 KB

  1. Xref: sparky comp.unix.programmer:3971 comp.unix.questions:9507 gnu.misc.discuss:2569 gnu.gcc.help:1802 comp.unix.ultrix:5946
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!drutx!drbug3!ldg
  3. From: ldg@drbug3.dr.att.com (Doug Gibbons)
  4. Newsgroups: comp.unix.programmer,comp.unix.questions,gnu.misc.discuss,gnu.gcc.help,comp.unix.ultrix
  5. Subject: Re: help with unexec
  6. Message-ID: <18740@drutx.ATT.COM>
  7. Date: 28 Jul 92 15:16:05 GMT
  8. References: <1992Jul28.014955.21272@ulowell.ulowell.edu> <1992Jul28.100513.29858@cs.tu-berlin.de>
  9. Sender: news@drutx.ATT.COM
  10. Organization: AT&T Bell Laboratories
  11. Lines: 62
  12.  
  13.  
  14.   41593    Re: help with unexec                          [35] Oliver Laumann      In article <1992Jul28.100513.29858@cs.tu-berlin.de>, net@cs.tu-berlin.de (Oliver Laumann) writes:
  15. |> dnicodem@cs.ulowell.edu (David Nicodemus) writes:
  16. |> > I am looking for a way to force a program out of execution, and save an
  17. |> > image of the program that can be restarted from the same point at a later
  18. |> > time. 
  19. |> > 
  20. |> > It appears that the gnu unexec() function from gnu emacs will do this;
  21. |> > however, the last parameter asks for a "starting address." 
  22. |> > 
  23. |> > How can I find this "starting address" (which I want to be the current
  24. |> > point of execution)?  Is this even possible?
  25. |> 
  26. |> I'm not sure I understand what exactly you want to accomplish.  You
  27. |> certainly cannot *force* a program to dump its image to disk using
  28. |> unexec(); the program must call unexec() voluntarily.
  29.  
  30. But you can. Look at gcore(1) on SunOS and SVR4. This is a ptrace(2) and
  31. /proc -based utility which can generate a snapshot core image of a running
  32. process. But, note that core files usually do not have a copy of the executable
  33. text - this would have to be recovered from the original a.out, and any shared
  34. object libraries that were loaded.
  35.  
  36. Many pieces of the process context are difficult, if not impossible to
  37. either capture and/or reconstruct:
  38.  
  39.     - open file context, including tty
  40.     - STREAMS context
  41.     - mapped-file context (/proc gives you inode #, but not file name)
  42.     - SIGNALS context (try reconstructing a process that was unexeced while it
  43.       was in a signal handler)
  44.     - IPC context
  45. |> 
  46. |> The entry point you can supply to unexec() is the address where the
  47. |> a.out file produced by unexec() will start when it is invoked later.
  48. |> Every a.out file has an entry point; it's part of the a.out header.
  49. |> 
  50. |> Anyway, when using unexec(), you cannot have the newly created a.out
  51. |> file resume execution at the point where the original invocation saved
  52. |> its image.  To be able to do this, unexec() would have to save not only
  53. |> the text and data segment of the running program, but also the entire
  54. |> execution state (stack and registers).
  55. |> 
  56.  
  57. True, unexec would have to restore the execution state. Data, stack and registers
  58. can be recovered from the core file. Text must be recovered from the original
  59. a.out and any associated shared libraries. The entry point for the new 
  60. executable image could be a strip of code which performs
  61.  
  62.     - reloading of the registers, old pc last. Restoring privileged bits
  63.       in whatever your psw is could be tricky or downright impossible.
  64.     - re-establishment of the prior stack context - restoring the sp is
  65.       not nearly enough!
  66.     - resetting the brk value. The initial break value can be determined by
  67.       summing the .data and .bss-like sections of the a.out
  68.  
  69.  
  70. -- 
  71. --------------------------------------------------------------------------------
  72. -- Doug Gibbons            | ldg@druhi.ATT.COM or att!druhi!ldg
  73. -- AT&T Bell Laboratories 
  74. -- Denver CO
  75.