diff --git a/cr-dump.c b/cr-dump.c index 90d828a67..4bc1883bf 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -544,23 +544,21 @@ static int add_shmem_area(pid_t pid, struct vma_entry *vma) static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd, const struct cr_fdset *fdset) { - struct fd_parms p = { - .fd_name = vma->start, - .id = FD_ID_INVALID, - .pid = pid, - .type = FDINFO_MAP, - }; + struct fd_parms p; + if (fstat(file_fd, &p.stat) < 0) { + pr_perror("Can't stat file for vma"); + return -1; + } + + p.type = FDINFO_REG; if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED)) p.flags = O_RDWR; else p.flags = O_RDONLY; + vma->shmid = fd_id_generate_special(); - /* - * XXX Strictly speaking, no need in full fdinfo here. - * This can be relaxed down to calling dump_one_reg_file. - */ - return do_dump_one_fdinfo(&p, file_fd, fdset); + return dump_one_reg_file(file_fd, vma->shmid, &p); } static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, @@ -578,18 +576,12 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, list_for_each_entry(vma_area, vma_area_list, list) { struct vma_entry *vma = &vma_area->vma; - ret = write_img(fd, vma); - if (ret < 0) - goto err; - - if (!vma_entry_is(vma, VMA_AREA_REGULAR)) - continue; - if (vma_entry_is(vma, VMA_AREA_SYSVIPC)) - continue; - pr_info_vma(vma_area); - if (vma_entry_is(vma, VMA_ANON_SHARED)) + if (!vma_entry_is(vma, VMA_AREA_REGULAR) || + vma_entry_is(vma, VMA_AREA_SYSVIPC)) + ret = 0; + else if (vma_entry_is(vma, VMA_ANON_SHARED)) ret = add_shmem_area(pid, vma); else if (vma_entry_is(vma, VMA_FILE_PRIVATE) || vma_entry_is(vma, VMA_FILE_SHARED)) @@ -597,6 +589,8 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, else ret = 0; + if (!ret) + ret = write_img(fd, vma); if (ret) goto err; } diff --git a/cr-show.c b/cr-show.c index 4616e0ec7..d12b96286 100644 --- a/cr-show.c +++ b/cr-show.c @@ -59,7 +59,6 @@ static char *fdtype2s(u8 type) static char und[4]; static char *fdtypes[] = { [FDINFO_REG] = "reg", - [FDINFO_MAP] = "map", [FDINFO_CWD] = "cwd", [FDINFO_EXE] = "exe", [FDINFO_INETSK] = "isk", diff --git a/file-ids.c b/file-ids.c index 3f7f1794f..6ff9c6064 100644 --- a/file-ids.c +++ b/file-ids.c @@ -217,13 +217,18 @@ static struct fd_id_entry *fd_id_generate_gen(pid_t pid, } +u32 fd_id_generate_special(void) +{ + return fd_id_entries_subid++; +} + int fd_id_generate(pid_t pid, struct fdinfo_entry *fe) { struct fd_id_entry *fid; int new_id = 0; if (fd_is_special(fe)) { - fe->id = fd_id_entries_subid++; + fe->id = fd_id_generate_special(); return 1; } diff --git a/files.c b/files.c index 53ab11585..cdd304e45 100644 --- a/files.c +++ b/files.c @@ -24,8 +24,6 @@ static struct fdinfo_list_entry *fdinfo_list; static int nr_fdinfo_list; -static struct fmap_fd *fmap_fds; - #define FDESC_HASH_SIZE 64 static struct list_head file_descs[FDESC_HASH_SIZE]; @@ -460,33 +458,6 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d) return reopen_fd_as((int)fe->addr, tmp); } -static int open_fmap(int pid, struct fdinfo_entry *fe, int fd) -{ - struct fmap_fd *new; - int tmp; - - tmp = find_open_fe_fd(fe); - if (tmp < 0) - return -1; - - pr_info("%d:\t\tWill map %lx to %d\n", pid, (unsigned long)fe->addr, tmp); - - new = xmalloc(sizeof(*new)); - if (!new) { - close_safe(&tmp); - return -1; - } - - new->start = fe->addr; - new->fd = tmp; - new->next = fmap_fds; - new->pid = pid; - - fmap_fds = new; - - return 0; -} - static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state) { u32 mag; @@ -522,8 +493,6 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe, if (state != FD_STATE_RECV) return 0; - if (fe->type == FDINFO_MAP) - return open_fmap(pid, fe, fdinfo_fd); if (fe->type == FDINFO_CWD) return restore_cwd(fe, fdinfo_fd); if (fe->type == FDINFO_EXE) @@ -581,31 +550,16 @@ int prepare_fds(int pid) return run_unix_connections(); } -static struct fmap_fd *pull_fmap_fd(int pid, unsigned long start) -{ - struct fmap_fd **p, *r; - - pr_info("%d: Looking for %lx : ", pid, start); - - for (p = &fmap_fds; *p != NULL; p = &(*p)->next) { - if ((*p)->start != start || (*p)->pid != pid) - continue; - - r = *p; - *p = r->next; - pr_info("found\n"); - - return r; - } - - pr_info("not found\n"); - return NULL; -} - int get_filemap_fd(int pid, struct vma_entry *vma_entry) { - struct fmap_fd *fmap_fd; - - fmap_fd = pull_fmap_fd(pid, vma_entry->start); - return fmap_fd ? fmap_fd->fd : -1; + struct file_desc *fd; + + fd = find_file_desc_raw(FDINFO_REG, vma_entry->shmid); + if (fd == NULL) { + pr_err("Can't find file for mapping %lx-%lx\n", + vma_entry->start, vma_entry->end); + return -1; + } + + return open_fe_fd(fd); } diff --git a/include/file-ids.h b/include/file-ids.h index 50361d513..8af786370 100644 --- a/include/file-ids.h +++ b/include/file-ids.h @@ -13,6 +13,7 @@ struct fdinfo_entry; extern int fd_id_generate(pid_t pid, struct fdinfo_entry *fe); +extern u32 fd_id_generate_special(void); extern void fd_id_show_tree(void); #endif /* FILE_IDS_H__ */ diff --git a/include/image.h b/include/image.h index b169eeec5..9760f6e52 100644 --- a/include/image.h +++ b/include/image.h @@ -35,7 +35,6 @@ enum fd_types { FDINFO_UND, FDINFO_REG, FDINFO_PIPE, - FDINFO_MAP, FDINFO_INETSK, FDINFO_UNIXSK, FDINFO_CWD, @@ -62,8 +61,7 @@ struct fdinfo_entry { u32 id; } __packed; -#define fd_is_special(fe) \ - (((fe)->type == FDINFO_MAP) || \ +#define fd_is_special(fe) ( \ ((fe)->type == FDINFO_CWD) || \ ((fe)->type == FDINFO_EXE))