[CRIU] [PATCH 1/7] arch: Turn save_task_regs into pointer

Pavel Emelyanov xemul at virtuozzo.com
Mon Sep 26 03:19:41 PDT 2016


The get_task_regs() call now accepts a pointer on a function
that is to keep obtainer registers somwehere. In CRIU case
this "somewhere" will be CoreEntry, for generic compel user
we'll need to add simple memcpy()-s to the library itself.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/arch/aarch64/crtools.c          | 12 +++++-------
 criu/arch/aarch64/include/asm/dump.h |  4 +++-
 criu/arch/arm/crtools.c              | 13 ++++++-------
 criu/arch/arm/include/asm/dump.h     |  4 +++-
 criu/arch/ppc64/crtools.c            | 13 ++++++-------
 criu/arch/ppc64/include/asm/dump.h   |  4 +++-
 criu/arch/x86/crtools.c              | 12 +++++-------
 criu/arch/x86/include/asm/dump.h     |  4 +++-
 criu/parasite-syscall.c              |  4 ++--
 9 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c
index b8c6893..bd5b1ed 100644
--- a/criu/arch/aarch64/crtools.c
+++ b/criu/arch/aarch64/crtools.c
@@ -8,6 +8,7 @@
 #include "compiler.h"
 #include "ptrace.h"
 #include "asm/processor-flags.h"
+#include "asm/dump.h"
 #include "protobuf.h"
 #include "images/core.pb-c.h"
 #include "images/creds.pb-c.h"
@@ -78,12 +79,9 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 	return err;
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpsimd)
-
 #define assign_reg(dst, src, e)		dst->e = (__typeof__(dst->e))(src)->e
 
-int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
+int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *arg)
 {
 	struct iovec iov;
 	user_fpregs_struct_t fpsimd;
@@ -105,15 +103,15 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
 		goto err;
 	}
 
-	ret = save_task_regs(core, &regs, &fpsimd);
+	ret = save(arg, &regs, &fpsimd);
 err:
 	return ret;
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpsimd)
+int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpsimd)
 {
 	int i;
+	CoreEntry *core = x;
 
 	// Save the Aarch64 CPU state
 	for (i = 0; i < 31; ++i)
diff --git a/criu/arch/aarch64/include/asm/dump.h b/criu/arch/aarch64/include/asm/dump.h
index 671c424..c53f67c 100644
--- a/criu/arch/aarch64/include/asm/dump.h
+++ b/criu/arch/aarch64/include/asm/dump.h
@@ -1,7 +1,9 @@
 #ifndef __CR_ASM_DUMP_H__
 #define __CR_ASM_DUMP_H__
 
-extern int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core);
+typedef int (*save_regs_t)(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int save_task_regs(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t, void *);
 extern int arch_alloc_thread_info(CoreEntry *core);
 extern void arch_free_thread_info(CoreEntry *core);
 
diff --git a/criu/arch/arm/crtools.c b/criu/arch/arm/crtools.c
index c3421b9..c46cd7a 100644
--- a/criu/arch/arm/crtools.c
+++ b/criu/arch/arm/crtools.c
@@ -3,6 +3,7 @@
 
 #include "asm/types.h"
 #include "asm/restorer.h"
+#include "asm/dump.h"
 #include "compiler.h"
 #include "ptrace.h"
 #include "asm/processor-flags.h"
@@ -80,13 +81,10 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 	return err;
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
-
 #define assign_reg(dst, src, e)		dst->e = (__typeof__(dst->e))((src)->ARM_##e)
 
 #define PTRACE_GETVFPREGS 27
-int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
+int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *arg)
 {
 	user_fpregs_struct_t vfp;
 	int ret = -1;
@@ -115,14 +113,15 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
 		}
 	}
 
-	ret = save_task_regs(core, &regs, &vfp);
+	ret = save(arg, &regs, &vfp);
 err:
 	return ret;
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
+int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
 {
+	CoreEntry *core = x;
+
 	// Save the ARM CPU state
 
 	assign_reg(core->ti_arm->gpregs, regs, r0);
diff --git a/criu/arch/arm/include/asm/dump.h b/criu/arch/arm/include/asm/dump.h
index ae1588d..fa83b82 100644
--- a/criu/arch/arm/include/asm/dump.h
+++ b/criu/arch/arm/include/asm/dump.h
@@ -1,7 +1,9 @@
 #ifndef __CR_ASM_DUMP_H__
 #define __CR_ASM_DUMP_H__
 
-extern int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core);
+typedef int (*save_regs_t)(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int save_task_regs(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t, void *);
 extern int arch_alloc_thread_info(CoreEntry *core);
 extern void arch_free_thread_info(CoreEntry *core);
 
diff --git a/criu/arch/ppc64/crtools.c b/criu/arch/ppc64/crtools.c
index 5ae8657..01d6061 100644
--- a/criu/arch/ppc64/crtools.c
+++ b/criu/arch/ppc64/crtools.c
@@ -8,6 +8,7 @@
 #include "asm/types.h"
 #include "asm/fpu.h"
 #include "asm/restorer.h"
+#include "asm/dump.h"
 
 #include "cr_options.h"
 #include "compiler.h"
@@ -501,11 +502,8 @@ static int put_tm_regs(struct rt_sigframe *f, UserPpc64TmRegsEntry *tme)
 	return 0;
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpregs);
-
 /****************************************************************************/
-int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
+int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *arg)
 {
 	user_fpregs_struct_t fpregs;
 	int ret;
@@ -588,12 +586,13 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
 		}
 	}
 
-	return save_task_regs(core, &regs, &fpregs);
+	return save(arg, &regs, &fpregs);
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
+int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
 {
+	CoreEntry *core = x;
+
 	UserPpc64RegsEntry *gpregs;
 	UserPpc64FpstateEntry **fpstate;
 	UserPpc64VrstateEntry **vrstate;
diff --git a/criu/arch/ppc64/include/asm/dump.h b/criu/arch/ppc64/include/asm/dump.h
index 1505fd2..0c88b7a 100644
--- a/criu/arch/ppc64/include/asm/dump.h
+++ b/criu/arch/ppc64/include/asm/dump.h
@@ -1,7 +1,9 @@
 #ifndef __CR_ASM_DUMP_H__
 #define __CR_ASM_DUMP_H__
 
-extern int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core);
+typedef int (*save_regs_t)(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int save_task_regs(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t, void *);
 extern int arch_alloc_thread_info(CoreEntry *core);
 extern void arch_free_thread_info(CoreEntry *core);
 
diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index 9fee84a..e54cc5a 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -11,6 +11,7 @@
 #include "asm/restorer.h"
 #include "asm/types.h"
 #include "asm/fpu.h"
+#include "asm/dump.h"
 
 #include "cr_options.h"
 #include "compiler.h"
@@ -193,10 +194,7 @@ int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
 	((user_regs_native(pregs)) ? (int64_t)((pregs)->native.name) :	\
 				(int32_t)((pregs)->compat.name))
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpregs);
-
-int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
+int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *arg)
 {
 	user_fpregs_struct_t xsave	= {  }, *xs = NULL;
 
@@ -254,14 +252,14 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
 
 	xs = &xsave;
 out:
-	ret = save_task_regs(core, &regs, xs);
+	ret = save(arg, &regs, xs);
 err:
 	return ret;
 }
 
-static int save_task_regs(CoreEntry *core,
-		user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
+int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
 {
+	CoreEntry *core = x;
 	UserX86RegsEntry *gpregs	= core->thread_info->gpregs;
 
 #define assign_reg(dst, src, e)		do { dst->e = (__typeof__(dst->e))src.e; } while (0)
diff --git a/criu/arch/x86/include/asm/dump.h b/criu/arch/x86/include/asm/dump.h
index 9c35552..4b928a8 100644
--- a/criu/arch/x86/include/asm/dump.h
+++ b/criu/arch/x86/include/asm/dump.h
@@ -1,7 +1,9 @@
 #ifndef __CR_ASM_DUMP_H__
 #define __CR_ASM_DUMP_H__
 
-extern int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core);
+typedef int (*save_regs_t)(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int save_task_regs(void *, user_regs_struct_t *, user_fpregs_struct_t *);
+extern int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t, void *);
 extern int arch_alloc_thread_info(CoreEntry *core);
 extern void arch_free_thread_info(CoreEntry *core);
 
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index ad33098..46b70d8 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -675,7 +675,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
 		return -1;
 	}
 
-	ret = get_task_regs(pid, octx.regs, core);
+	ret = get_task_regs(pid, octx.regs, save_task_regs, core);
 	if (ret) {
 		pr_err("Can't obtain regs for thread %d\n", pid);
 		return -1;
@@ -1450,7 +1450,7 @@ static int parasite_start_daemon(struct parasite_ctl *ctl, struct pstree_item *i
 	 * while in daemon it is not such.
 	 */
 
-	if (get_task_regs(pid, ctl->orig.regs, item->core[0])) {
+	if (get_task_regs(pid, ctl->orig.regs, save_task_regs, item->core[0])) {
 		pr_err("Can't obtain regs for thread %d\n", pid);
 		return -1;
 	}
-- 
2.5.0



More information about the CRIU mailing list