diff --git a/cr-dump.c b/cr-dump.c index 5581d5ae8..2ce3c762e 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -391,7 +391,7 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset) return pb_write(fdset_fd(fdset, CR_FD_FS), &fe, fs_entry); } -static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd, +static int dump_filemap(pid_t pid, VmaEntry *vma, int file_fd, const struct cr_fdset *fdset) { struct fd_parms p = FD_PARMS_INIT; @@ -423,7 +423,7 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, fd = fdset_fd(cr_fdset, CR_FD_VMAS); list_for_each_entry(vma_area, vma_area_list, list) { - struct vma_entry *vma = &vma_area->vma; + VmaEntry *vma = &vma_area->vma; pr_info_vma(vma_area); @@ -439,7 +439,7 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, ret = 0; if (!ret) - ret = write_img(fd, vma); + ret = pb_write(fd, vma, vma_entry); if (ret) goto err; } diff --git a/cr-restore.c b/cr-restore.c index 11e7e411a..2559b2139 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -52,6 +52,7 @@ #include "protobuf.h" #include "protobuf/sa.pb-c.h" #include "protobuf/itimer.pb-c.h" +#include "protobuf/vma.pb-c.h" static struct pstree_item *me; @@ -141,6 +142,7 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas) *nr_vmas = 0; while (1) { struct vma_area *vma; + VmaEntry *e; ret = -1; vma = alloc_vma_area(); @@ -149,10 +151,13 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas) (*nr_vmas)++; list_add_tail(&vma->list, vmas); - ret = read_img_eof(fd, &vma->vma); + ret = pb_read_eof(fd, &e, vma_entry); if (ret <= 0) break; + vma->vma = *e; + vma_entry__free_unpacked(e, NULL); + if (!(vma_entry_is(&vma->vma, VMA_AREA_REGULAR))) continue; @@ -1055,9 +1060,9 @@ static int prepare_creds(int pid, struct task_restore_core_args *args) return 0; } -static struct vma_entry *vma_list_remap(void *addr, unsigned long len, struct list_head *vmas) +static VmaEntry *vma_list_remap(void *addr, unsigned long len, struct list_head *vmas) { - struct vma_entry *vma, *ret; + VmaEntry *vma, *ret; struct vma_area *vma_area; ret = vma = mmap(addr, len, PROT_READ | PROT_WRITE, @@ -1146,8 +1151,8 @@ static int sigreturn_restore(pid_t pid, struct list_head *tgt_vmas, int nr_vmas) if (ret < 0) goto err; - self_vmas_len = round_up((ret + 1) * sizeof(struct vma_entry), PAGE_SIZE); - vmas_len = round_up((nr_vmas + 1) * sizeof(struct vma_entry), PAGE_SIZE); + self_vmas_len = round_up((ret + 1) * sizeof(VmaEntry), PAGE_SIZE); + vmas_len = round_up((nr_vmas + 1) * sizeof(VmaEntry), PAGE_SIZE); /* pr_info_vma_list(&self_vma_list); */ diff --git a/cr-show.c b/cr-show.c index ad034e9db..b3b87df72 100644 --- a/cr-show.c +++ b/cr-show.c @@ -38,6 +38,7 @@ #include "protobuf/sa.pb-c.h" #include "protobuf/itimer.pb-c.h" #include "protobuf/mm.pb-c.h" +#include "protobuf/vma.pb-c.h" #include "protobuf/creds.pb-c.h" #define DEF_PAGES_PER_LINE 6 @@ -166,24 +167,7 @@ void show_fs(int fd_fs, struct cr_options *o) void show_vmas(int fd_vma, struct cr_options *o) { - struct vma_area vma_area = {}; - struct vma_entry ve; - - pr_img_head(CR_FD_VMAS); - - while (1) { - int ret; - - ret = read_img_eof(fd_vma, &ve); - if (ret <= 0) - break; - - /* Simply in a sake of fancy printing */ - vma_area.vma = ve; - pr_msg_vma(&vma_area); - } - - pr_img_tail(CR_FD_VMAS); + pb_show_plain(fd_vma, vma_entry); } static int nice_width_for(unsigned long addr) diff --git a/files.c b/files.c index 2270127b8..f5b6d6bd3 100644 --- a/files.c +++ b/files.c @@ -531,7 +531,7 @@ err: return ret; } -int get_filemap_fd(int pid, struct vma_entry *vma_entry) +int get_filemap_fd(int pid, VmaEntry *vma_entry) { return open_reg_by_id(vma_entry->shmid); } diff --git a/include/crtools.h b/include/crtools.h index ed79df6ab..c7fe75b8e 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -9,6 +9,8 @@ #include "util.h" #include "image.h" +#include "../protobuf/vma.pb-c.h" + #define CR_FD_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) #define CR_FD_PERM_DUMP (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) @@ -168,7 +170,7 @@ void free_mappings(struct list_head *vma_area_list); struct vma_area { struct list_head list; - struct vma_entry vma; + VmaEntry vma; int vm_file_fd; }; diff --git a/include/files.h b/include/files.h index 3598a0b10..5178da3f7 100644 --- a/include/files.h +++ b/include/files.h @@ -9,6 +9,7 @@ #include "../protobuf/fdinfo.pb-c.h" #include "../protobuf/fown.pb-c.h" +#include "../protobuf/vma.pb-c.h" struct pstree_item; struct file_desc; @@ -87,7 +88,7 @@ extern void show_saved_files(void); extern int prepare_fds(struct pstree_item *me); extern int prepare_fd_pid(int pid, struct rst_info *rst_info); extern int prepare_shared_fdinfo(void); -extern int get_filemap_fd(int pid, struct vma_entry *vma_entry); +extern int get_filemap_fd(int pid, VmaEntry *vma_entry); extern int prepare_fs(int pid); extern int set_fd_flags(int fd, int flags); diff --git a/include/image.h b/include/image.h index f92369cc4..d8d57e62c 100644 --- a/include/image.h +++ b/include/image.h @@ -55,17 +55,6 @@ #define USK_EXTERN (1 << 0) -struct vma_entry { - u64 start; - u64 end; - u64 pgoff; - u64 shmid; - u32 prot; - u32 flags; - u32 status; - s64 fd; -} __packed; - #define VMA_AREA_NONE (0 << 0) #define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */ #define VMA_AREA_STACK (1 << 1) diff --git a/include/parasite.h b/include/parasite.h index 0e0c87cfc..35d3406ef 100644 --- a/include/parasite.h +++ b/include/parasite.h @@ -15,6 +15,8 @@ #include "util-net.h" +#include "../protobuf/vma.pb-c.h" + #define __head __used __section(.head.text) enum { @@ -42,7 +44,7 @@ struct parasite_init_args { }; struct parasite_dump_pages_args { - struct vma_entry vma_entry; + VmaEntry vma_entry; unsigned long nrpages_dumped; /* how many pages are dumped */ unsigned long nrpages_skipped; unsigned long nrpages_total; diff --git a/include/restorer.h b/include/restorer.h index c6777a3dd..1be2168a2 100644 --- a/include/restorer.h +++ b/include/restorer.h @@ -12,6 +12,7 @@ #include "crtools.h" #include "../protobuf/mm.pb-c.h" +#include "../protobuf/vma.pb-c.h" #include "../protobuf/creds.pb-c.h" #ifndef CONFIG_X86_64 @@ -80,8 +81,8 @@ struct task_restore_core_args { struct thread_restore_args *thread_args; /* array of thread arguments */ struct shmems *shmems; struct task_entries *task_entries; - struct vma_entry *self_vmas; - struct vma_entry *tgt_vmas; + VmaEntry *self_vmas; + VmaEntry *tgt_vmas; rt_sigaction_t sigchld_act; struct itimerval itimers[3]; diff --git a/include/shmem.h b/include/shmem.h index f8907c8e7..f109d462b 100644 --- a/include/shmem.h +++ b/include/shmem.h @@ -1,16 +1,18 @@ #ifndef __CR_SHMEM_H__ #define __CR_SHMEM_H__ + +#include "../protobuf/vma.pb-c.h" + int prepare_shmem_pid(int pid); int prepare_shmem_restore(void); void show_saved_shmems(void); -struct vma_entry; -int get_shmem_fd(int pid, struct vma_entry *vi); +int get_shmem_fd(int pid, VmaEntry *vi); struct shmems; extern struct shmems *rst_shmems; int cr_dump_shmem(void); -int add_shmem_area(pid_t pid, struct vma_entry *vma); +int add_shmem_area(pid_t pid, VmaEntry *vma); int init_shmem_dump(void); void fini_shmem_dump(void); #endif diff --git a/include/util.h b/include/util.h index a8b9cc9dd..18c821f4c 100644 --- a/include/util.h +++ b/include/util.h @@ -16,6 +16,8 @@ #include "types.h" #include "log.h" +#include "../protobuf/vma.pb-c.h" + #define PREF_SHIFT_OP(pref, op, size) ((size) op (pref ##BYTES_SHIFT)) #define KBYTES_SHIFT 10 #define MBYTES_SHIFT 20 @@ -155,6 +157,7 @@ extern void pr_vma(unsigned int loglevel, const struct vma_area *vma_area); ({ \ struct vma_area *p__ = xzalloc(sizeof(*p__)); \ if (p__) { \ + vma_entry__init(&p__->vma); \ p__->vm_file_fd = -1; \ p__->vma.fd = -1; \ } \ diff --git a/parasite.c b/parasite.c index b70110af2..29a3e8581 100644 --- a/parasite.c +++ b/parasite.c @@ -102,7 +102,7 @@ static void sys_write_msg(const char *msg) #define PME_SWAP (1ULL << 62) #define PME_FILE (1ULL << 61) -static inline int should_dump_page(struct vma_entry *vmae, u64 pme) +static inline int should_dump_page(VmaEntry *vmae, u64 pme) { return (pme & (PME_PRESENT | PME_SWAP)) && /* diff --git a/protobuf/Makefile b/protobuf/Makefile index 341fc99de..c61d87568 100644 --- a/protobuf/Makefile +++ b/protobuf/Makefile @@ -48,6 +48,7 @@ PROTO_FILES += ipc-shm.proto PROTO_FILES += ipc-msg.proto PROTO_FILES += ipc-sem.proto PROTO_FILES += creds.proto +PROTO_FILES += vma.proto HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES)) SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES)) diff --git a/protobuf/vma.proto b/protobuf/vma.proto new file mode 100644 index 000000000..5535c36dd --- /dev/null +++ b/protobuf/vma.proto @@ -0,0 +1,10 @@ +message vma_entry { + required uint64 start = 1; + required uint64 end = 2; + required uint64 pgoff = 3; + required uint64 shmid = 4; + required uint32 prot = 5; + required uint32 flags = 6; + required uint32 status = 7; + required sint64 fd = 8; +} diff --git a/restorer.c b/restorer.c index 2cb8c5466..e20a2abed 100644 --- a/restorer.c +++ b/restorer.c @@ -244,7 +244,7 @@ static long restore_self_exe_late(struct task_restore_core_args *args) return 0; } -static u64 restore_mapping(const struct vma_entry *vma_entry) +static u64 restore_mapping(const VmaEntry *vma_entry) { int prot = vma_entry->prot; int flags = vma_entry->flags | MAP_FIXED; @@ -295,7 +295,7 @@ long __export_restore_task(struct task_restore_core_args *args) { long ret = -1; struct core_entry *core_entry; - struct vma_entry *vma_entry; + VmaEntry *vma_entry; u64 va; struct rt_sigframe *rt_sigframe; diff --git a/shmem.c b/shmem.c index 38f04b55b..cc1dcdb7a 100644 --- a/shmem.c +++ b/shmem.c @@ -7,6 +7,8 @@ #include "crtools.h" #include "restorer.h" +#include "protobuf.h" + struct shmems *rst_shmems; void show_saved_shmems(void) @@ -22,7 +24,7 @@ void show_saved_shmems(void) rst_shmems->entries[i].pid); } -static int collect_shmem(int pid, struct vma_entry *vi) +static int collect_shmem(int pid, VmaEntry *vi) { int nr_shmems = rst_shmems->nr_shmems; unsigned long size = vi->pgoff + vi->end - vi->start; @@ -77,7 +79,7 @@ static int collect_shmem(int pid, struct vma_entry *vi) int prepare_shmem_pid(int pid) { int fd, ret = -1; - struct vma_entry vi; + VmaEntry *vi; fd = open_image_ro(CR_FD_VMAS, pid); if (fd < 0) { @@ -88,19 +90,21 @@ int prepare_shmem_pid(int pid) } while (1) { - ret = read_img_eof(fd, &vi); + ret = pb_read_eof(fd, &vi, vma_entry); if (ret <= 0) break; - pr_info("vma 0x%lx 0x%lx\n", vi.start, vi.end); + pr_info("vma 0x%lx 0x%lx\n", vi->start, vi->end); - if (!vma_entry_is(&vi, VMA_ANON_SHARED)) + if (!vma_entry_is(vi, VMA_ANON_SHARED) || + vma_entry_is(vi, VMA_AREA_SYSVIPC)) { + vma_entry__free_unpacked(vi, NULL); continue; + } - if (vma_entry_is(&vi, VMA_AREA_SYSVIPC)) - continue; + ret = collect_shmem(pid, vi); + vma_entry__free_unpacked(vi, NULL); - ret = collect_shmem(pid, &vi); if (ret) break; } @@ -156,7 +160,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si) return ret; } -int get_shmem_fd(int pid, struct vma_entry *vi) +int get_shmem_fd(int pid, VmaEntry *vi) { struct shmem_info *si; void *addr; @@ -241,7 +245,7 @@ static struct shmem_info_dump* shmem_find(unsigned long shmid) return NULL; } -int add_shmem_area(pid_t pid, struct vma_entry *vma) +int add_shmem_area(pid_t pid, VmaEntry *vma) { struct shmem_info_dump *si; unsigned long size = vma->pgoff + (vma->end - vma->start);