mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-22 17:49:13 +00:00
infect: Move parasite_prep_ctl into infect.c
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
bb33a7742a
commit
e156ab5a62
6 changed files with 54 additions and 50 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue