Difference between revisions of "Checkpoint/Restore"
Jump to navigation
Jump to search
(Created page with "== Basic design == === Checkpoint === The checkpoint procedure relies heavily on '''/proc''' file system (it's a general place where crtools takes all the information it needs)...") |
|||
Line 12: | Line 12: | ||
The process dumper (lets call it a dumper further) does the following steps during checkpoint stage | The process dumper (lets call it a dumper further) does the following steps during checkpoint stage | ||
− | # | + | # '''$pid''' of a process group leader is obtained from the command line. |
− | # By using this '''$pid''' the dumper walks though '''/proc/$pid/ | + | # By using this '''$pid''' the dumper walks though '''/proc/$pid/task/$tid/children''' and gathers children '''$pids''' recursively. At the end we will have a process tree. |
− | # Then | + | # Then we take every '''$pid''' from a process tree, seize and them with ptrace ''PTRACE_SEIZE'' call (which put tasks into seized state, where tasks do not know that they are actually stopped and someone does nasty things with them :), and performs the following steps on each '''$pid'''. |
− | # | + | # Collect VMA areas by parsing '''/proc/$pid/maps'''. |
− | # | + | # Collect file descriptor numbers the task has via '''/proc/$pid/fd'''. |
− | # | + | # Core parameters of a task (such as registers and friends) are being dumped via ptrace interface and parsing '''/proc/$pid/stat''' entry. |
− | # | + | # The dumper injects a parasite code into a task via ptrace interface. This is done in two steps - at first we inject only a few bytes for ''mmap'' syscall at CS:IP the task has at moment of seizing. Then ptrace allow us to run an injected syscall and we allocate enough memory for a parasite code chunk we need for dumping. After that the parasite code is copied into new place inside dumpee address space and CS:IP set respectively to point to our parasite code. |
− | + | # After everything dumped (such as memory pages, which can be written out only from inside dumpee address space) we use ptrace facility again and cure dumpee by dropping out all our parasite code and restoring original code. | |
− | |||
− | # | ||
− | |||
− | |||
# The procedure continues for every '''$pid'''. | # The procedure continues for every '''$pid'''. | ||
Revision as of 15:07, 29 August 2012
Basic design
Checkpoint
The checkpoint procedure relies heavily on /proc file system (it's a general place where crtools takes all the information it needs). Which includes
- Files descriptors information (via /proc/$pid/fd and /proc/$pid/fdinfo).
- Pipes parameters.
- Memory maps (via /proc/$pid/maps).
The process dumper (lets call it a dumper further) does the following steps during checkpoint stage
- $pid of a process group leader is obtained from the command line.
- By using this $pid the dumper walks though /proc/$pid/task/$tid/children and gathers children $pids recursively. At the end we will have a process tree.
- Then we take every $pid from a process tree, seize and them with ptrace PTRACE_SEIZE call (which put tasks into seized state, where tasks do not know that they are actually stopped and someone does nasty things with them :), and performs the following steps on each $pid.
- Collect VMA areas by parsing /proc/$pid/maps.
- Collect file descriptor numbers the task has via /proc/$pid/fd.
- Core parameters of a task (such as registers and friends) are being dumped via ptrace interface and parsing /proc/$pid/stat entry.
- The dumper injects a parasite code into a task via ptrace interface. This is done in two steps - at first we inject only a few bytes for mmap syscall at CS:IP the task has at moment of seizing. Then ptrace allow us to run an injected syscall and we allocate enough memory for a parasite code chunk we need for dumping. After that the parasite code is copied into new place inside dumpee address space and CS:IP set respectively to point to our parasite code.
- After everything dumped (such as memory pages, which can be written out only from inside dumpee address space) we use ptrace facility again and cure dumpee by dropping out all our parasite code and restoring original code.
- The procedure continues for every $pid.
Restore
The restore procedure (aka restorer) proceed in the following steps
- A process tree has been read from a file.
- Every process started with saved (i.e. original) $pid via
clone()
call. - Files and pipes are restored (by restored it's meant - they are opened and positioned).
- A new memory map is created, filled with data the program had at checkpoint time.
- Finally the program is kicked to start with rt_sigreturn system call.