mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-20 16:51:37 +00:00
Bring some order in usage of VMA entries helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
bb15450d98
commit
0fd17a08cb
9 changed files with 52 additions and 55 deletions
19
cr-dump.c
19
cr-dump.c
|
|
@ -352,14 +352,14 @@ static int dump_task_mappings(pid_t pid, struct list_head *vma_area_list, struct
|
|||
|
||||
struct vma_entry *vma = &vma_area->vma;
|
||||
|
||||
if (!(vma->status & VMA_AREA_REGULAR))
|
||||
if (!vma_entry_is(vma, VMA_AREA_REGULAR))
|
||||
continue;
|
||||
|
||||
pr_info_vma(vma_area);
|
||||
|
||||
if (vma->flags & (MAP_SHARED | MAP_PRIVATE)) {
|
||||
|
||||
if ((vma->status & VMA_ANON_SHARED)) {
|
||||
if (vma_entry_is(vma, VMA_ANON_SHARED)) {
|
||||
struct shmem_entry e;
|
||||
|
||||
e.start = vma->start;
|
||||
|
|
@ -370,12 +370,13 @@ static int dump_task_mappings(pid_t pid, struct list_head *vma_area_list, struct
|
|||
e.start, e.end, e.shmid);
|
||||
|
||||
write_ptr_safe(cr_fdset->desc[CR_FD_SHMEM].fd, &e, err);
|
||||
} else if ((vma->status & VMA_FILE_PRIVATE) ||
|
||||
(vma->status & VMA_FILE_SHARED)) {
|
||||
} else if (vma_entry_is(vma, VMA_FILE_PRIVATE) ||
|
||||
vma_entry_is(vma, VMA_FILE_SHARED)) {
|
||||
|
||||
unsigned int flags;
|
||||
|
||||
if (vma->prot & PROT_WRITE && (vma->status & VMA_FILE_SHARED))
|
||||
if (vma->prot & PROT_WRITE &&
|
||||
vma_entry_is(vma, VMA_FILE_SHARED))
|
||||
flags = O_RDWR;
|
||||
else
|
||||
flags = O_RDONLY;
|
||||
|
|
@ -985,13 +986,13 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
|
|||
* Just in case if someone broke parasite page
|
||||
* dumper code.
|
||||
*/
|
||||
if (!vma_area_has(vma_area, VMA_AREA_REGULAR)) {
|
||||
if (!vma_area_is(vma_area, VMA_AREA_REGULAR)) {
|
||||
pr_panic("\nA page with address %lx has a wrong status\n", va);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (vma_area_has(vma_area, VMA_ANON_PRIVATE) ||
|
||||
vma_area_has(vma_area, VMA_FILE_PRIVATE)) {
|
||||
if (vma_area_is(vma_area, VMA_ANON_PRIVATE) ||
|
||||
vma_area_is(vma_area, VMA_FILE_PRIVATE)) {
|
||||
ret = write(fd_core, &va, sizeof(va));
|
||||
ret += sendfile(fd_core, fd_pages, NULL, PAGE_SIZE);
|
||||
if (ret != sizeof(va) + PAGE_SIZE) {
|
||||
|
|
@ -1001,7 +1002,7 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
|
|||
goto err;
|
||||
}
|
||||
num++;
|
||||
} else if (vma_area_has(vma_area, VMA_ANON_SHARED)) {
|
||||
} else if (vma_area_is(vma_area, VMA_ANON_SHARED)) {
|
||||
ret = write(fd_pages_shmem, &va, sizeof(va));
|
||||
ret += sendfile(fd_pages_shmem, fd_pages, NULL, PAGE_SIZE);
|
||||
if (ret != sizeof(va) + PAGE_SIZE) {
|
||||
|
|
|
|||
10
cr-restore.c
10
cr-restore.c
|
|
@ -703,15 +703,15 @@ static int fixup_vma_fds(int pid, int fd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (vi.start == 0 && vi.end == 0)
|
||||
if (final_vma_entry(&vi))
|
||||
return 0;
|
||||
|
||||
if (!(vi.status & VMA_AREA_REGULAR))
|
||||
if (!(vma_entry_is(&vi, VMA_AREA_REGULAR)))
|
||||
continue;
|
||||
|
||||
if ((vi.status & VMA_FILE_PRIVATE) ||
|
||||
(vi.status & VMA_FILE_SHARED) ||
|
||||
(vi.status & VMA_ANON_SHARED)) {
|
||||
if (vma_entry_is(&vi, VMA_FILE_PRIVATE) ||
|
||||
vma_entry_is(&vi, VMA_FILE_SHARED) ||
|
||||
vma_entry_is(&vi, VMA_ANON_SHARED)) {
|
||||
|
||||
pr_info("%d: Fixing %016lx-%016lx %016lx vma\n",
|
||||
pid, vi.start, vi.end, vi.pgoff);
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ static void show_core(struct cr_fdset *cr_fdset)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (is_ending_vma(&ve)) {
|
||||
if (final_vma_entry(&ve)) {
|
||||
pr_info("\n\t---[Pages]---\n");
|
||||
while (1) {
|
||||
ret = read(fd_core, &va, sizeof(va));
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ struct vma_area {
|
|||
int vm_file_fd;
|
||||
};
|
||||
|
||||
#define vma_area_has(vma_area, s) vma_entry_has(&vma_area->vma, s)
|
||||
#define vma_entry_len(vma) ((vma)->end - (vma)->start)
|
||||
#define vma_area_is(vma_area, s) vma_entry_is(&((vma_area)->vma), s)
|
||||
#define vma_area_len(vma_area) vma_entry_len(&((vma_area)->vma))
|
||||
|
||||
struct pstree_item {
|
||||
struct list_head list;
|
||||
|
|
@ -97,11 +97,6 @@ struct pstree_item {
|
|||
u32 *children; /* array of children */
|
||||
};
|
||||
|
||||
static inline unsigned long vma_area_size(struct vma_area *vma)
|
||||
{
|
||||
return vma->vma.end - vma->vma.start;
|
||||
}
|
||||
|
||||
static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
|
||||
{
|
||||
return addr >= (unsigned long)vma->vma.start &&
|
||||
|
|
|
|||
|
|
@ -50,22 +50,6 @@ struct pipe_entry {
|
|||
u8 data[0];
|
||||
} __packed;
|
||||
|
||||
#define VMA_AREA_NONE (0 << 0)
|
||||
#define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */
|
||||
#define VMA_AREA_STACK (1 << 1)
|
||||
#define VMA_AREA_VSYSCALL (1 << 2)
|
||||
#define VMA_AREA_VDSO (1 << 3)
|
||||
#define VMA_FORCE_READ (1 << 4) /* VMA changed to be readable */
|
||||
#define VMA_AREA_HEAP (1 << 5)
|
||||
|
||||
#define VMA_FILE_PRIVATE (1 << 6)
|
||||
#define VMA_FILE_SHARED (1 << 7)
|
||||
#define VMA_ANON_SHARED (1 << 8)
|
||||
#define VMA_ANON_PRIVATE (1 << 9)
|
||||
#define VMA_DUMP_ALL (1 << 10) /* Dump the whole VMA area pages */
|
||||
|
||||
#define vma_entry_has(vma, s) (((vma)->status & (s)) == (s))
|
||||
|
||||
struct vma_entry {
|
||||
u64 start;
|
||||
u64 end;
|
||||
|
|
@ -80,11 +64,32 @@ struct vma_entry {
|
|||
u32 dev_min;
|
||||
} __packed;
|
||||
|
||||
#define VMA_AREA_NONE (0 << 0)
|
||||
#define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */
|
||||
#define VMA_AREA_STACK (1 << 1)
|
||||
#define VMA_AREA_VSYSCALL (1 << 2)
|
||||
#define VMA_AREA_VDSO (1 << 3)
|
||||
#define VMA_FORCE_READ (1 << 4) /* VMA changed to be readable */
|
||||
#define VMA_AREA_HEAP (1 << 5)
|
||||
|
||||
#define VMA_FILE_PRIVATE (1 << 6)
|
||||
#define VMA_FILE_SHARED (1 << 7)
|
||||
#define VMA_ANON_SHARED (1 << 8)
|
||||
#define VMA_ANON_PRIVATE (1 << 9)
|
||||
#define VMA_DUMP_ALL (1 << 10) /* Dump the whole VMA area pages */
|
||||
|
||||
#define vma_entry_is(vma, s) (((vma)->status & (s)) == (s))
|
||||
#define vma_entry_len(vma) ((vma)->end - (vma)->start)
|
||||
#define final_vma_entry(vma) ((vma)->start == 0 && (vma)->end == 0)
|
||||
|
||||
struct page_entry {
|
||||
u64 va;
|
||||
u8 data[PAGE_IMAGE_SIZE];
|
||||
} __packed;
|
||||
|
||||
#define final_page_va(va) ((va) == 0)
|
||||
#define final_page_entry(page_entry) (final_page_va((page_entry)->va))
|
||||
|
||||
#define HEADER_VERSION 1
|
||||
#define HEADER_ARCH_X86_64 1
|
||||
|
||||
|
|
|
|||
|
|
@ -125,9 +125,6 @@ struct list_head;
|
|||
|
||||
void printk_vma(struct vma_area *vma_area);
|
||||
|
||||
/* A special marker */
|
||||
#define is_ending_vma(vma) ((vma)->start == 0 && (vma)->end == 0)
|
||||
|
||||
#define pr_info_vma_list(head) \
|
||||
do { \
|
||||
struct vma_area *vma; \
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ static int dump_pages(parasite_args_cmd_dumppages_t *args)
|
|||
}
|
||||
}
|
||||
|
||||
dump_all = !!(args->vma_entry.status & VMA_DUMP_ALL);
|
||||
dump_all = vma_entry_is(&args->vma_entry, VMA_DUMP_ALL);
|
||||
|
||||
/*
|
||||
* Try to change page protection if needed so we would
|
||||
|
|
|
|||
23
restorer.c
23
restorer.c
|
|
@ -238,11 +238,10 @@ self_len_end:
|
|||
goto core_restore_end;
|
||||
}
|
||||
|
||||
if (!(vma_entry.status & VMA_AREA_REGULAR))
|
||||
if (!vma_entry_is(&vma_entry, VMA_AREA_REGULAR))
|
||||
continue;
|
||||
|
||||
if (sys_munmap((void *)vma_entry.start,
|
||||
vma_entry.end - vma_entry.start)) {
|
||||
if (sys_munmap((void *)vma_entry.start, vma_entry_len(&vma_entry))) {
|
||||
write_hex_n(__LINE__);
|
||||
goto core_restore_end;
|
||||
}
|
||||
|
|
@ -265,10 +264,10 @@ self_len_end:
|
|||
goto core_restore_end;
|
||||
}
|
||||
|
||||
if (!vma_entry.start)
|
||||
if (final_vma_entry(&vma_entry))
|
||||
break;
|
||||
|
||||
if (vma_entry.status & VMA_AREA_VDSO) {
|
||||
if (vma_entry_is(&vma_entry, VMA_AREA_VDSO)) {
|
||||
ret = sys_prctl(PR_CKPT_CTL, PR_CKPT_CTL_SETUP_VDSO_AT,
|
||||
vma_entry.start, 0, 0);
|
||||
if (ret) {
|
||||
|
|
@ -279,7 +278,7 @@ self_len_end:
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!(vma_entry.status & VMA_AREA_REGULAR))
|
||||
if (!vma_entry_is(&vma_entry, VMA_AREA_REGULAR))
|
||||
continue;
|
||||
|
||||
/*
|
||||
|
|
@ -288,7 +287,7 @@ self_len_end:
|
|||
* 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_is(&vma_entry, VMA_ANON_SHARED)) {
|
||||
if (vma_entry.fd != -1UL)
|
||||
vma_entry.flags &= ~MAP_ANONYMOUS;
|
||||
}
|
||||
|
|
@ -299,7 +298,7 @@ self_len_end:
|
|||
* contents.
|
||||
*/
|
||||
va = sys_mmap((void *)vma_entry.start,
|
||||
vma_entry.end - vma_entry.start,
|
||||
vma_entry_len(&vma_entry),
|
||||
vma_entry.prot | PROT_WRITE,
|
||||
vma_entry.flags | MAP_FIXED,
|
||||
vma_entry.fd,
|
||||
|
|
@ -333,7 +332,7 @@ self_len_end:
|
|||
write_hex_n(ret);
|
||||
goto core_restore_end;
|
||||
}
|
||||
if (!va)
|
||||
if (final_page_va(va))
|
||||
break;
|
||||
|
||||
ret = sys_read(fd_core, (void *)va, PAGE_SIZE);
|
||||
|
|
@ -359,17 +358,17 @@ self_len_end:
|
|||
goto core_restore_end;
|
||||
}
|
||||
|
||||
if (!vma_entry.start)
|
||||
if (final_vma_entry(&vma_entry))
|
||||
break;
|
||||
|
||||
if (!(vma_entry.status & VMA_AREA_REGULAR))
|
||||
if (!(vma_entry_is(&vma_entry, VMA_AREA_REGULAR)))
|
||||
continue;
|
||||
|
||||
if (vma_entry.prot & PROT_WRITE)
|
||||
continue;
|
||||
|
||||
sys_mprotect(vma_entry.start,
|
||||
vma_entry.end - vma_entry.start,
|
||||
vma_entry_len(&vma_entry),
|
||||
vma_entry.prot);
|
||||
}
|
||||
|
||||
|
|
|
|||
2
util.c
2
util.c
|
|
@ -178,7 +178,7 @@ void printk_vma(struct vma_area *vma_area)
|
|||
printk("s: %16lx e: %16lx l: %4liK p: %4x f: %8x pg: %8lx "
|
||||
"fd: %4d pid: %4d dev:%02x:%02x:%08lx vf: %s st: %s spc: %s\n",
|
||||
vma_area->vma.start, vma_area->vma.end,
|
||||
vma_entry_len(&vma_area->vma) >> 10,
|
||||
vma_area_len(vma_area) >> 10,
|
||||
vma_area->vma.prot,
|
||||
vma_area->vma.flags,
|
||||
vma_area->vma.pgoff,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue