int __used parasite_service(unsigned long cmd, void *args) { BUILD_BUG_ON(sizeof(struct parasite_dump_pages_args) > PARASITE_ARG_SIZE); BUILD_BUG_ON(sizeof(struct parasite_init_args) > PARASITE_ARG_SIZE); BUILD_BUG_ON(sizeof(struct parasite_dump_misc) > PARASITE_ARG_SIZE); BUILD_BUG_ON(sizeof(struct parasite_dump_tid_info) > PARASITE_ARG_SIZE); BUILD_BUG_ON(sizeof(struct parasite_drain_fd) > PARASITE_ARG_SIZE); switch (cmd) { case PARASITE_CMD_INIT: return init((struct parasite_init_args *) args); case PARASITE_CMD_FINI: return fini(); case PARASITE_CMD_SET_LOGFD: return parasite_set_logfd(); case PARASITE_CMD_DUMPPAGES_INIT: return dump_pages_init(); case PARASITE_CMD_DUMPPAGES_FINI: return dump_pages_fini(); case PARASITE_CMD_DUMPPAGES: return dump_pages((struct parasite_dump_pages_args *)args); case PARASITE_CMD_DUMP_SIGACTS: return dump_sigact((struct parasite_dump_sa_args *)args); case PARASITE_CMD_DUMP_ITIMERS: return dump_itimers((struct parasite_dump_itimers_args *)args); case PARASITE_CMD_DUMP_MISC: return dump_misc((struct parasite_dump_misc *)args); case PARASITE_CMD_DUMP_TID_ADDR: return dump_tid_info((struct parasite_dump_tid_info *)args); case PARASITE_CMD_DRAIN_FDS: return drain_fds((struct parasite_drain_fd *)args); case PARASITE_CMD_GET_PROC_FD: return parasite_get_proc_fd(); #ifdef CONFIG_HAS_TLS case PARASITE_CMD_GET_TLS: parasite_get_tls((struct parasite_get_tls_args*)args); return 0; #endif } sys_write_msg("Unknown command to parasite\n"); return -EINVAL; }
int __used parasite_service(unsigned int cmd, void *args) { pr_info("Parasite cmd %d/%x process\n", cmd, cmd); switch (cmd) { case PARASITE_CMD_INIT: return init(args); case PARASITE_CMD_INIT_THREAD: return init_thread(); case PARASITE_CMD_FINI: return fini(); case PARASITE_CMD_FINI_THREAD: return fini_thread(); case PARASITE_CMD_CFG_LOG: return parasite_cfg_log(args); case PARASITE_CMD_DUMPPAGES: return dump_pages(args); case PARASITE_CMD_MPROTECT_VMAS: return mprotect_vmas(args); case PARASITE_CMD_DUMP_SIGACTS: return dump_sigact(args); case PARASITE_CMD_DUMP_ITIMERS: return dump_itimers(args); case PARASITE_CMD_DUMP_MISC: return dump_misc(args); case PARASITE_CMD_DUMP_CREDS: return dump_creds(args); case PARASITE_CMD_DUMP_THREAD: return dump_thread(args); case PARASITE_CMD_DRAIN_FDS: return drain_fds(args); case PARASITE_CMD_GET_PROC_FD: return parasite_get_proc_fd(); case PARASITE_CMD_DUMP_TTY: return parasite_dump_tty(args); } pr_err("Unknown command to parasite: %d\n", cmd); return -EINVAL; }
static int dump_one_shmem(struct shmem_info_dump *si) { struct iovec *iovs; struct page_pipe *pp; struct page_xfer xfer; int err, ret = -1, fd; unsigned char *map = NULL; void *addr = NULL; unsigned long pfn, nrpages; pr_info("Dumping shared memory %ld\n", si->shmid); nrpages = (si->size + PAGE_SIZE - 1) / PAGE_SIZE; map = xmalloc(nrpages * sizeof(*map)); if (!map) goto err; fd = open_proc(si->pid, "map_files/%lx-%lx", si->start, si->end); if (fd < 0) goto err; addr = mmap(NULL, si->size, PROT_READ, MAP_SHARED, fd, 0); close(fd); if (addr == MAP_FAILED) { pr_err("Can't map shmem 0x%lx (0x%lx-0x%lx)\n", si->shmid, si->start, si->end); goto err; } /* * We can't use pagemap here, because this vma is * not mapped to us at all, but mincore reports the * pagecache status of a file, which is correct in * this case. */ err = mincore(addr, si->size, map); if (err) goto err_unmap; iovs = xmalloc(((nrpages + 1) / 2) * sizeof(struct iovec)); if (!iovs) goto err_unmap; pp = create_page_pipe((nrpages + 1) / 2, iovs, true); if (!pp) goto err_iovs; err = open_page_xfer(&xfer, CR_FD_SHMEM_PAGEMAP, si->shmid); if (err) goto err_pp; for (pfn = 0; pfn < nrpages; pfn++) { if (!(map[pfn] & PAGE_RSS)) continue; again: ret = page_pipe_add_page(pp, (unsigned long)addr + pfn * PAGE_SIZE); if (ret == -EAGAIN) { ret = dump_pages(pp, &xfer, addr); if (ret) goto err_xfer; page_pipe_reinit(pp); goto again; } else if (ret) goto err_xfer; } ret = dump_pages(pp, &xfer, addr); err_xfer: xfer.close(&xfer); err_pp: destroy_page_pipe(pp); err_iovs: xfree(iovs); err_unmap: munmap(addr, si->size); err: xfree(map); return ret; }