Commit ce40f5d9 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Fix restoration of anonymous shared vmas

And rename prepare_and_execute_image to
prepare_and_sigreturn which is more appropriate
name here.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent ba634963
...@@ -171,7 +171,7 @@ static int shmem_wait_and_open(struct shmem_info *si) ...@@ -171,7 +171,7 @@ static int shmem_wait_and_open(struct shmem_info *si)
while (1) { while (1) {
int ret = open(path, O_RDWR); int ret = open(path, O_RDWR);
if (ret > 0) if (ret >= 0)
return ret; return ret;
if (ret < 0 && errno != ENOENT) { if (ret < 0 && errno != ENOENT) {
...@@ -201,7 +201,7 @@ static int collect_shmem(int pid, struct shmem_entry *e) ...@@ -201,7 +201,7 @@ static int collect_shmem(int pid, struct shmem_entry *e)
} }
/* /*
* Only the shared mapping with highest * Only the shared mapping with a lowest
* pid will be created in real, other processes * pid will be created in real, other processes
* will wait until the kernel propagate this mapping * will wait until the kernel propagate this mapping
* into /proc * into /proc
...@@ -671,13 +671,15 @@ static int try_fixup_shared_map(int pid, struct vma_entry *vi, int fd) ...@@ -671,13 +671,15 @@ static int try_fixup_shared_map(int pid, struct vma_entry *vi, int fd)
sh_fd = shmem_wait_and_open(si); sh_fd = shmem_wait_and_open(si);
pr_info("%d: Fixing %lx vma to %lx/%d shmem -> %d\n", pr_info("%d: Fixing %lx vma to %lx/%d shmem -> %d\n",
pid, vi->start, si->shmid, si->pid, sh_fd); pid, vi->start, si->shmid, si->pid, sh_fd);
if (fd < 0) { if (sh_fd < 0) {
perror("Can't open shmem"); perror("Can't open shmem");
return 1; return 1;
} }
lseek(fd, -sizeof(*vi), SEEK_CUR); lseek(fd, -sizeof(*vi), SEEK_CUR);
vi->fd = sh_fd; vi->fd = sh_fd;
pr_info("%d: Fixed %lx vma %lx/%d shmem -> %d\n",
pid, vi->start, si->shmid, si->pid, sh_fd);
if (write(fd, vi, sizeof(*vi)) != sizeof(*vi)) { if (write(fd, vi, sizeof(*vi)) != sizeof(*vi)) {
perror("Can't write img"); perror("Can't write img");
return 1; return 1;
...@@ -825,7 +827,7 @@ static int prepare_image_maps(int fd, int pid) ...@@ -825,7 +827,7 @@ static int prepare_image_maps(int fd, int pid)
return 0; return 0;
} }
static int prepare_and_execute_image(int pid) static int prepare_and_sigreturn(int pid)
{ {
char path[128]; char path[128];
int fd, fd_new; int fd, fd_new;
...@@ -1080,7 +1082,7 @@ static int restore_one_task(int pid) ...@@ -1080,7 +1082,7 @@ static int restore_one_task(int pid)
if (prepare_shmem(pid)) if (prepare_shmem(pid))
return 1; return 1;
return prepare_and_execute_image(pid); return prepare_and_sigreturn(pid);
} }
static int do_child(void *arg) static int do_child(void *arg)
......
...@@ -282,6 +282,17 @@ self_len_end: ...@@ -282,6 +282,17 @@ self_len_end:
if (!(vma_entry.status & VMA_AREA_REGULAR)) if (!(vma_entry.status & VMA_AREA_REGULAR))
continue; continue;
/*
* Restore or shared mappings are tricky, since
* we open anonymous mapping via map_files/
* MAP_ANONYMOUS should be eliminated so fd would
* be taken into account by a kernel.
*/
if (vma_entry.status & VMA_ANON_SHARED) {
if (vma_entry.fd != -1UL)
vma_entry.flags &= ~MAP_ANONYMOUS;
}
/* /*
* Should map memory here. Note we map them as * Should map memory here. Note we map them as
* writable since we're going to restore page * writable since we're going to restore page
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment