diff --git a/cr-restore.c b/cr-restore.c index 9a113797a..1a13ab245 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -144,33 +144,27 @@ static void shmem_update_real_pid(int vpid, int rpid) static int shmem_wait_and_open(struct shmem_info *si) { - unsigned long time = 1000; + unsigned long time = 1; char path[128]; + int ret; - sleep(1); - - while (si->real_pid == 0) - usleep(time); + cr_wait_until(&si->lock, 1); sprintf(path, "/proc/%d/map_files/%lx-%lx", si->real_pid, si->start, si->end); - while (1) { - int ret = open(path, O_RDWR); - if (ret >= 0) - return ret; + pr_info("Waiting for [%s] to appear\n", path); - if (ret < 0 && errno != ENOENT) { - pr_perror(" %d: Can't stat shmem at %s\n", - si->real_pid, path); - return -1; - } + ret = open(path, O_RDWR); + if (ret >= 0) + return ret; - pr_info("Waiting for [%s] to appear\n", path); - if (time < 20000000) - time <<= 1; - usleep(time); + if (ret < 0) { + pr_perror(" %d: Can't stat shmem at %s\n", + si->real_pid, path); + return -1; } + return 0; } static int collect_shmem(int pid, struct shmem_entry *e) diff --git a/include/restorer.h b/include/restorer.h index 58a79a722..5d0936d11 100644 --- a/include/restorer.h +++ b/include/restorer.h @@ -296,6 +296,7 @@ struct shmem_info { unsigned long shmid; int pid; int real_pid; + u32 lock; /* futex */ }; struct shmems { diff --git a/restorer.c b/restorer.c index e02990a78..f5135fc42 100644 --- a/restorer.c +++ b/restorer.c @@ -277,6 +277,23 @@ self_len_end: if (vma_entry->fd != -1UL) sys_close(vma_entry->fd); + + if (vma_entry_is(vma_entry, VMA_ANON_SHARED) && + vma_entry->fd == -1UL) { + struct shmem_info *entry; + + entry = find_shmem_by_pid(args->shmems, + vma_entry->start, + sys_getpid()); + if (!entry) { + write_num_n(__LINE__); + write_hex_n(vma_entry->start); + goto core_restore_end; + } + + cr_wait_set(&entry->lock, 1); + } + } /*