diff --git a/criu/cr-exec.c b/criu/cr-exec.c index 4762a8b90..e5609abb0 100644 --- a/criu/cr-exec.c +++ b/criu/cr-exec.c @@ -169,7 +169,7 @@ int cr_exec(int pid, char **opt) goto out_unseize; } - ctl = parasite_prep_ctl(pid); + ctl = compel_prepare(pid); if (!ctl) { pr_err("Can't prep ctl %d\n", pid); goto out_unseize; diff --git a/criu/cr-restore.c b/criu/cr-restore.c index 88ca34e57..503d32f64 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -1654,7 +1654,7 @@ static void finalize_restore(void) continue; /* Unmap the restorer blob */ - ctl = parasite_prep_ctl(pid); + ctl = compel_prepare(pid); if (ctl == NULL) continue; diff --git a/criu/include/infect.h b/criu/include/infect.h index 9cfbfe084..fa6dac88c 100644 --- a/criu/include/infect.h +++ b/criu/include/infect.h @@ -24,7 +24,10 @@ extern int compel_wait_task(int pid, int ppid, #define TASK_ZOMBIE 0x6 struct parasite_ctl; +struct thread_ctx; +extern struct parasite_ctl *compel_prepare(int pid); extern int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned long args_size); +extern int compel_prepare_thread(int pid, struct thread_ctx *ctx); #endif diff --git a/criu/include/parasite-syscall.h b/criu/include/parasite-syscall.h index 65d4217c2..9e151df87 100644 --- a/criu/include/parasite-syscall.h +++ b/criu/include/parasite-syscall.h @@ -98,7 +98,6 @@ extern struct parasite_ctl *parasite_infect_seized(pid_t pid, struct vm_area_list *vma_area_list); extern void parasite_ensure_args_size(unsigned long sz); extern unsigned long get_exec_start(struct vm_area_list *); -extern struct parasite_ctl *parasite_prep_ctl(pid_t pid); extern int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size); extern int parasite_dump_cgroup(struct parasite_ctl *ctl, struct parasite_dump_cgroup_args *cgroup); diff --git a/criu/infect.c b/criu/infect.c index 3fc89df5d..4668884de 100644 --- a/criu/infect.c +++ b/criu/infect.c @@ -20,6 +20,9 @@ #include "infect.h" #include "infect-priv.h" +#define MEMFD_FNAME "CRIUMFD" +#define MEMFD_FNAME_SZ sizeof(MEMFD_FNAME) + /* XXX will be removed soon */ extern int parasite_wait_ack(int sockfd, unsigned int cmd, struct ctl_msg *m); @@ -527,3 +530,47 @@ err: return -1; } +int compel_prepare_thread(int pid, struct thread_ctx *ctx) +{ + if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(k_rtsigset_t), &ctx->sigmask)) { + pr_perror("can't get signal blocking mask for %d", pid); + return -1; + } + + if (ptrace_get_regs(pid, &ctx->regs)) { + pr_perror("Can't obtain registers (pid: %d)", pid); + return -1; + } + + return 0; +} + +struct parasite_ctl *compel_prepare(int pid) +{ + struct parasite_ctl *ctl = NULL; + + /* + * Control block early setup. + */ + ctl = xzalloc(sizeof(*ctl)); + if (!ctl) { + pr_err("Parasite control block allocation failed (pid: %d)\n", pid); + goto err; + } + + ctl->tsock = -1; + + if (compel_prepare_thread(pid, &ctl->orig)) + goto err; + + ctl->rpid = pid; + + BUILD_BUG_ON(PARASITE_START_AREA_MIN < BUILTIN_SYSCALL_SIZE + MEMFD_FNAME_SZ); + + return ctl; + +err: + xfree(ctl); + return NULL; +} + diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c index 62841a2aa..b1458ec24 100644 --- a/criu/parasite-syscall.c +++ b/criu/parasite-syscall.c @@ -91,21 +91,6 @@ static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs) } #endif -static int get_thread_ctx(int pid, struct thread_ctx *ctx) -{ - if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(k_rtsigset_t), &ctx->sigmask)) { - pr_perror("can't get signal blocking mask for %d", pid); - return -1; - } - - if (ptrace_get_regs(pid, &ctx->regs)) { - pr_perror("Can't obtain registers (pid: %d)", pid); - return -1; - } - - return 0; -} - static int restore_thread_ctx(int pid, struct thread_ctx *ctx) { int ret = 0; @@ -481,7 +466,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id, pc->cap_last_cap = kdat.last_cap; - ret = get_thread_ctx(pid, &octx); + ret = compel_prepare_thread(pid, &octx); if (ret) return -1; @@ -1071,36 +1056,6 @@ err: return ret; } -/* If vma_area_list is NULL, a place for injecting syscall will not be set. */ -struct parasite_ctl *parasite_prep_ctl(pid_t pid) -{ - struct parasite_ctl *ctl = NULL; - - /* - * Control block early setup. - */ - ctl = xzalloc(sizeof(*ctl)); - if (!ctl) { - pr_err("Parasite control block allocation failed (pid: %d)\n", pid); - goto err; - } - - ctl->tsock = -1; - - if (get_thread_ctx(pid, &ctl->orig)) - goto err; - - ctl->rpid = pid; - - BUILD_BUG_ON(PARASITE_START_AREA_MIN < BUILTIN_SYSCALL_SIZE + MEMFD_FNAME_SZ); - - return ctl; - -err: - xfree(ctl); - return NULL; -} - static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size) { int fd; @@ -1266,7 +1221,7 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item, return NULL; } - ctl = parasite_prep_ctl(pid); + ctl = compel_prepare(pid); if (!ctl) return NULL;