Dump stack and heap memory to file, then load it back into RAM?

Issue

As the question states. I am certain that it is possible, but I can’t find information on the subject.

I’m doing this as an experiment right now, the idea is basically to do the following scenario:

  1. boot up linux (just because I don’t like windows)
  2. do some random stuff
  3. dump stack and heap memory to 1 or 2 files
  4. do some other random stuff
  5. load dump(s) back into memory

The effect I am trying to achieve is basically hibernate a system state, but keep the system running, then wake the previous state. Not sure where I would be able to use this, but it sounds like geeky fun.

EDIT: I thought searching for sysctl hibernate sources would help, but I can’t even seem to find those.

Update:
So far I have found the following information:

Continuing the search…

I think this is where I need to dig:
https://github.com/torvalds/linux/search?q=swsusp

Also, as @Useless stated in the comments, here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/power/hibernate.c?h=v5.14-rc6

Solution

EDIT: I thought searching for sysctl hibernate sources would help, but I can’t even seem to find those

It’ll need to be done in the kernel, since there’s a load of kernel & driver state, and it needs access to all running processes.

You can start from power/hibernate.c.

If you just skip the call to swsusp_arch_suspend() increate_image(), you should be most of the way to creating the image and then immediately resuming.

You just need to figure out how to:

  1. keep the hibernation state around that presumably now gets destroyed on resumption
  2. run the restore/thaw half of the code later, when you’re not already suspended

Answered By – Useless

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published