[CRIU] [PATCH 25/78] infect: Move parasite_unmap() into infect.c

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:36:10 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 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 f8e1b3faa78a..0629da03971c 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1650,7 +1650,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 8a1ab610db5f..a461ffa2ce9f 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 a521fe49c0fb..d528eabf7631 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 6d3e5fdfc4e2..d21d0862a96c 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 e5d0a3049365..c9322b7fef1a 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 = (uintptr_t)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, &regs, &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 88879f376db4..eba407a87451 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, &regs, &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;
-- 
2.7.4



More information about the CRIU mailing list