[CRIU] [PATCH 23/78] infect: Move parasite_execute_syscall() into infect.c

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


From: Pavel Emelyanov <xemul at virtuozzo.com>

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/arch/aarch64/crtools.c     |  3 ++-
 criu/arch/arm/crtools.c         |  3 ++-
 criu/arch/ppc64/crtools.c       |  3 ++-
 criu/arch/x86/crtools.c         |  5 +++--
 criu/include/infect.h           |  6 ++++++
 criu/include/parasite-syscall.h |  2 --
 criu/infect.c                   | 36 ++++++++++++++++++++++++++++++++++++
 criu/parasite-syscall.c         | 33 +--------------------------------
 8 files changed, 52 insertions(+), 39 deletions(-)

diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c
index 5263dd0087ef..a02b63ac0a0e 100644
--- a/criu/arch/aarch64/crtools.c
+++ b/criu/arch/aarch64/crtools.c
@@ -17,6 +17,7 @@
 #include "util.h"
 #include "cpu.h"
 #include "restorer.h"
+#include "infect.h"
 #include "infect-priv.h"
 
 /*
@@ -72,7 +73,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 	regs.regs[6] = 0;
 	regs.regs[7] = 0;
 
-	err = __parasite_execute_syscall(ctl, &regs, code_syscall);
+	err = compel_execute_syscall(ctl, &regs, code_syscall);
 
 	*ret = regs.regs[0];
 	return err;
diff --git a/criu/arch/arm/crtools.c b/criu/arch/arm/crtools.c
index 6ca2fe3869f0..66a42cada9b9 100644
--- a/criu/arch/arm/crtools.c
+++ b/criu/arch/arm/crtools.c
@@ -18,6 +18,7 @@
 #include "restorer.h"
 #include "errno.h"
 #include "kerndat.h"
+#include "infect.h"
 #include "infect-priv.h"
 
 /*
@@ -74,7 +75,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 	regs.ARM_r4 = arg5;
 	regs.ARM_r5 = arg6;
 
-	err = __parasite_execute_syscall(ctl, &regs, code_syscall);
+	err = compel_execute_syscall(ctl, &regs, code_syscall);
 
 	*ret = regs.ARM_r0;
 	return err;
diff --git a/criu/arch/ppc64/crtools.c b/criu/arch/ppc64/crtools.c
index e4a27350c4eb..14d2dc70ccd2 100644
--- a/criu/arch/ppc64/crtools.c
+++ b/criu/arch/ppc64/crtools.c
@@ -18,6 +18,7 @@
 #include "util.h"
 #include "cpu.h"
 #include "errno.h"
+#include "infect.h"
 #include "infect-priv.h"
 
 #include "protobuf.h"
@@ -87,7 +88,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 	regs.gpr[7] = arg5;
 	regs.gpr[8] = arg6;
 
-	err = __parasite_execute_syscall(ctl, &regs, (char*)code_syscall);
+	err = compel_execute_syscall(ctl, &regs, (char*)code_syscall);
 
 	*ret = regs.gpr[3];
 	return err;
diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index 39e3f5d8f24a..686b62914a58 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -25,6 +25,7 @@
 #include "uapi/std/syscall-codes.h"
 #include "kerndat.h"
 #include "infect-priv.h"
+#include "infect.h"
 
 #include "protobuf.h"
 #include "images/core.pb-c.h"
@@ -167,7 +168,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 		r->r8  = arg5;
 		r->r9  = arg6;
 
-		err = __parasite_execute_syscall(ctl, &regs, code_syscall);
+		err = compel_execute_syscall(ctl, &regs, code_syscall);
 	} else {
 		user_regs_struct32 *r = &regs.compat;
 
@@ -179,7 +180,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 		r->di  = arg5;
 		r->bp  = arg6;
 
-		err = __parasite_execute_syscall(ctl, &regs, code_int_80);
+		err = compel_execute_syscall(ctl, &regs, code_int_80);
 	}
 
 	*ret = get_user_reg(&regs, ax);
diff --git a/criu/include/infect.h b/criu/include/infect.h
index 5ab38425fba5..38e22465ab34 100644
--- a/criu/include/infect.h
+++ b/criu/include/infect.h
@@ -1,5 +1,8 @@
 #ifndef __COMPEL_INFECT_H__
 #define __COMPEL_INFECT_H__
+
+#include "types.h"
+
 extern int compel_stop_task(int pid);
 
 struct seize_task_status {
@@ -47,4 +50,7 @@ extern int compel_cure(struct parasite_ctl *ctl);
 
 extern void *compel_parasite_args_p(struct parasite_ctl *ctl);
 extern void *compel_parasite_args_s(struct parasite_ctl *ctl, int args_size);
+
+extern int compel_execute_syscall(struct parasite_ctl *ctl,
+		user_regs_struct_t *regs, const char *code_syscall);
 #endif
diff --git a/criu/include/parasite-syscall.h b/criu/include/parasite-syscall.h
index ec4bef4d61a7..6d3e5fdfc4e2 100644
--- a/criu/include/parasite-syscall.h
+++ b/criu/include/parasite-syscall.h
@@ -99,8 +99,6 @@ extern int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 			  unsigned long arg3, unsigned long arg4,
 			  unsigned long arg5, unsigned long arg6);
 
-extern int __parasite_execute_syscall(struct parasite_ctl *ctl,
-		user_regs_struct_t *regs, const char *code_syscall);
 extern bool arch_can_dump_task(struct parasite_ctl *ctl);
 extern bool seized_native(struct parasite_ctl *ctl);
 
diff --git a/criu/infect.c b/criu/infect.c
index bef2c9ff0a24..042344130de1 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -369,6 +369,42 @@ err_sig:
 	return -1;
 }
 
+/* XXX will be removed soon */
+extern int parasite_trap(struct parasite_ctl *ctl, pid_t pid,
+				user_regs_struct_t *regs,
+				struct thread_ctx *octx);
+
+int compel_execute_syscall(struct parasite_ctl *ctl,
+		user_regs_struct_t *regs, const char *code_syscall)
+{
+	pid_t pid = ctl->rpid;
+	int err;
+	u8 code_orig[BUILTIN_SYSCALL_SIZE];
+
+	/*
+	 * Inject syscall instruction and remember original code,
+	 * we will need it to restore original program content.
+	 */
+	memcpy(code_orig, code_syscall, sizeof(code_orig));
+	if (ptrace_swap_area(pid, (void *)ctl->ictx.syscall_ip,
+			     (void *)code_orig, sizeof(code_orig))) {
+		pr_err("Can't inject syscall blob (pid: %d)\n", pid);
+		return -1;
+	}
+
+	err = parasite_run(pid, PTRACE_CONT, ctl->ictx.syscall_ip, 0, regs, &ctl->orig);
+	if (!err)
+		err = parasite_trap(ctl, pid, regs, &ctl->orig);
+
+	if (ptrace_poke_area(pid, (void *)code_orig,
+			     (void *)ctl->ictx.syscall_ip, sizeof(code_orig))) {
+		pr_err("Can't restore syscall blob (pid: %d)\n", ctl->rpid);
+		err = -1;
+	}
+
+	return err;
+}
+
 static int accept_tsock(struct parasite_ctl *ctl)
 {
 	int sock;
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 487b65ba5142..e95f24d0b524 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -113,7 +113,7 @@ bool seized_native(struct parasite_ctl *ctl)
 }
 
 /* we run at @regs->ip */
-static int parasite_trap(struct parasite_ctl *ctl, pid_t pid,
+int parasite_trap(struct parasite_ctl *ctl, pid_t pid,
 				user_regs_struct_t *regs,
 				struct thread_ctx *octx)
 {
@@ -166,37 +166,6 @@ err:
 	return ret;
 }
 
-int __parasite_execute_syscall(struct parasite_ctl *ctl,
-		user_regs_struct_t *regs, const char *code_syscall)
-{
-	pid_t pid = ctl->rpid;
-	int err;
-	u8 code_orig[BUILTIN_SYSCALL_SIZE];
-
-	/*
-	 * Inject syscall instruction and remember original code,
-	 * we will need it to restore original program content.
-	 */
-	memcpy(code_orig, code_syscall, sizeof(code_orig));
-	if (ptrace_swap_area(pid, (void *)ctl->ictx.syscall_ip,
-			     (void *)code_orig, sizeof(code_orig))) {
-		pr_err("Can't inject syscall blob (pid: %d)\n", pid);
-		return -1;
-	}
-
-	err = parasite_run(pid, PTRACE_CONT, ctl->ictx.syscall_ip, 0, regs, &ctl->orig);
-	if (!err)
-		err = parasite_trap(ctl, pid, regs, &ctl->orig);
-
-	if (ptrace_poke_area(pid, (void *)code_orig,
-			     (void *)ctl->ictx.syscall_ip, sizeof(code_orig))) {
-		pr_err("Can't restore syscall blob (pid: %d)\n", ctl->rpid);
-		err = -1;
-	}
-
-	return err;
-}
-
 static int parasite_run_in_thread(pid_t pid, unsigned int cmd,
 					struct parasite_ctl *ctl,
 					struct thread_ctx *octx)
-- 
2.7.4



More information about the CRIU mailing list