[CRIU] [PATCH 02/78] arch: Turn save_task_regs into pointer
Cyrill Gorcunov
gorcunov at openvz.org
Mon Nov 7 08:35:47 PST 2016
From: Pavel Emelyanov <xemul at virtuozzo.com>
The get_task_regs() call now accepts a pointer on a function that
is to keep obtained registers somwehere.
In CRIU case this "somewhere" is 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 | 9 +++++++--
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, 37 insertions(+), 29 deletions(-)
diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c
index cc2421da0720..5510da19a7d0 100644
--- a/criu/arch/aarch64/crtools.c
+++ b/criu/arch/aarch64/crtools.c
@@ -8,6 +8,7 @@
#include "common/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"
@@ -77,12 +78,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;
@@ -104,15 +102,15 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
goto err;
}
- ret = save_task_regs(core, ®s, &fpsimd);
+ ret = save(arg, ®s, &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 671c424da9d7..c53f67c3d487 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 42a8b8d1b282..73a82b46aa76 100644
--- a/criu/arch/arm/crtools.c
+++ b/criu/arch/arm/crtools.c
@@ -4,6 +4,7 @@
#include "types.h"
#include "asm/restorer.h"
#include "common/compiler.h"
+#include "asm/dump.h"
#include "ptrace.h"
#include "asm/processor-flags.h"
#include "protobuf.h"
@@ -79,13 +80,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;
@@ -114,14 +112,15 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
}
}
- ret = save_task_regs(core, ®s, &vfp);
+ ret = save(arg, ®s, &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 ae1588da8792..fa83b8267710 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 3914bfda0e03..9e98190e0562 100644
--- a/criu/arch/ppc64/crtools.c
+++ b/criu/arch/ppc64/crtools.c
@@ -8,6 +8,7 @@
#include "types.h"
#include "asm/fpu.h"
#include "asm/restorer.h"
+#include "asm/dump.h"
#include "cr_options.h"
#include "common/compiler.h"
@@ -692,9 +693,13 @@ static int __copy_task_regs(user_regs_struct_t *regs,
return 0;
}
+int save_task_regs(void *arg, user_regs_struct_t *u, user_fpregs_struct_t *f)
+{
+ return __copy_task_regs(u, f, (CoreEntry *)arg);
+}
/****************************************************************************/
-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;
@@ -703,7 +708,7 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
if (ret)
return ret;
- return __copy_task_regs(®s, &fpregs, core);
+ return save(arg, ®s, &fpregs);
}
int arch_alloc_thread_info(CoreEntry *core)
diff --git a/criu/arch/ppc64/include/asm/dump.h b/criu/arch/ppc64/include/asm/dump.h
index 1505fd2983b0..0c88b7a56235 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 55fb150f807b..e0eec9ec5642 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -11,6 +11,7 @@
#include "asm/parasite-syscall.h"
#include "asm/restorer.h"
#include "asm/fpu.h"
+#include "asm/dump.h"
#include "cr_options.h"
#include "common/compiler.h"
@@ -188,10 +189,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;
@@ -249,14 +247,14 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, CoreEntry *core)
xs = &xsave;
out:
- ret = save_task_regs(core, ®s, xs);
+ ret = save(arg, ®s, 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 9c3555236ce6..4b928a8de662 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 cbc393518836..81ddff712e89 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -667,7 +667,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;
@@ -1427,7 +1427,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.7.4
More information about the CRIU
mailing list