From 34db99e3c8f8a5fec5d523e24ee35ed30ea5ad57 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 28 Sep 2016 14:07:16 +0300 Subject: [PATCH] infect: Move parasite_unmap() into infect.c Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- criu/cr-restore.c | 2 +- criu/include/infect-priv.h | 2 -- criu/include/infect.h | 2 ++ criu/include/parasite-syscall.h | 1 - criu/infect.c | 31 +++++++++++++++++++++++++++++-- criu/parasite-syscall.c | 26 +------------------------- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/criu/cr-restore.c b/criu/cr-restore.c index 503d32f64..7d74f2e86 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -1658,7 +1658,7 @@ static void finalize_restore(void) if (ctl == NULL) continue; - parasite_unmap(ctl, (unsigned long)rsti(item)->munmap_restorer); + compel_unmap(ctl, (unsigned long)rsti(item)->munmap_restorer); xfree(ctl); diff --git a/criu/include/infect-priv.h b/criu/include/infect-priv.h index 8a1ab610d..a461ffa2c 100644 --- a/criu/include/infect-priv.h +++ b/criu/include/infect-priv.h @@ -32,6 +32,4 @@ struct parasite_ctl { int tsock; /* transport socket for transferring fds */ }; -int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, - user_regs_struct_t *regs, struct thread_ctx *octx); #endif diff --git a/criu/include/infect.h b/criu/include/infect.h index a521fe49c..d528eabf7 100644 --- a/criu/include/infect.h +++ b/criu/include/infect.h @@ -56,4 +56,6 @@ extern int compel_execute_syscall(struct parasite_ctl *ctl, extern int compel_run_in_thread(pid_t pid, unsigned int cmd, struct parasite_ctl *ctl, struct thread_ctx *octx); + +extern int compel_unmap(struct parasite_ctl *ctl, unsigned long addr); #endif diff --git a/criu/include/parasite-syscall.h b/criu/include/parasite-syscall.h index 6d3e5fdfc..d21d0862a 100644 --- a/criu/include/parasite-syscall.h +++ b/criu/include/parasite-syscall.h @@ -116,7 +116,6 @@ enum trace_flags { extern int parasite_stop_on_syscall(int tasks, int sys_nr, int sys_nr_compat, enum trace_flags trace); -extern int parasite_unmap(struct parasite_ctl *ctl, unsigned long addr); extern int ptrace_stop_pie(pid_t pid, void *addr, enum trace_flags *tf); #endif /* __CR_PARASITE_SYSCALL_H__ */ diff --git a/criu/infect.c b/criu/infect.c index 70ebebe3d..548e4acc0 100644 --- a/criu/infect.c +++ b/criu/infect.c @@ -335,7 +335,7 @@ static int restore_child_handler() return 0; } -int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, +static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, user_regs_struct_t *regs, struct thread_ctx *octx) { k_rtsigset_t block; @@ -738,7 +738,7 @@ int compel_cure_remote(struct parasite_ctl *ctl) args = compel_parasite_args(ctl, struct parasite_unmap_args); args->parasite_start = ctl->remote_map; args->parasite_len = ctl->map_length; - if (parasite_unmap(ctl, ctl->parasite_ip)) + if (compel_unmap(ctl, ctl->parasite_ip)) return -1; } else { unsigned long ret; @@ -815,3 +815,30 @@ int compel_run_in_thread(pid_t pid, unsigned int cmd, return ret; } +/* XXX will be removed soon */ + +extern int restore_thread_ctx(int pid, struct thread_ctx *ctx); +/* + * compel_unmap() is used for unmapping parasite and restorer blobs. + * A blob can contain code for unmapping itself, so the porcess is + * trapped on the exit from the munmap syscall. + */ +int compel_unmap(struct parasite_ctl *ctl, unsigned long addr) +{ + user_regs_struct_t regs = ctl->orig.regs; + pid_t pid = ctl->rpid; + int ret = -1; + + ret = parasite_run(pid, PTRACE_SYSCALL, addr, ctl->rstack, ®s, &ctl->orig); + if (ret) + goto err; + + ret = parasite_stop_on_syscall(1, __NR(munmap, 0), + __NR(munmap, 1), TRACE_ENTER); + + if (restore_thread_ctx(pid, &ctl->orig)) + ret = -1; +err: + return ret; +} + diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c index 3d2f44616..8e38126ef 100644 --- a/criu/parasite-syscall.c +++ b/criu/parasite-syscall.c @@ -91,7 +91,7 @@ static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs) } #endif -static int restore_thread_ctx(int pid, struct thread_ctx *ctx) +int restore_thread_ctx(int pid, struct thread_ctx *ctx) { int ret = 0; @@ -796,30 +796,6 @@ goon: return 0; } -/* - * parasite_unmap() is used for unmapping parasite and restorer blobs. - * A blob can contain code for unmapping itself, so the porcess is - * trapped on the exit from the munmap syscall. - */ -int parasite_unmap(struct parasite_ctl *ctl, unsigned long addr) -{ - user_regs_struct_t regs = ctl->orig.regs; - pid_t pid = ctl->rpid; - int ret = -1; - - ret = parasite_run(pid, PTRACE_SYSCALL, addr, ctl->rstack, ®s, &ctl->orig); - if (ret) - goto err; - - ret = parasite_stop_on_syscall(1, __NR(munmap, 0), - __NR(munmap, 1), TRACE_ENTER); - - if (restore_thread_ctx(pid, &ctl->orig)) - ret = -1; -err: - return ret; -} - static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size) { int fd;