From 976e13a193c8409d92d6c3bbdc5581f4d0fe36fd Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 26 Sep 2016 13:19:41 +0300 Subject: [PATCH] arch: Turn save_task_regs into pointer 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 Signed-off-by: Andrei Vagin --- 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 | 13 ++++++------- criu/arch/x86/include/asm/dump.h | 4 +++- criu/parasite-syscall.c | 4 ++-- 9 files changed, 38 insertions(+), 29 deletions(-) diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c index 0e8a9bd7c..5510da19a 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 671c424da..c53f67c3d 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 edf2bad95..73a82b46a 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 ae1588da8..fa83b8267 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 3914bfda0..9e98190e0 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 1505fd298..0c88b7a56 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 dc3c93b89..a66a8c650 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" @@ -184,13 +185,11 @@ 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 get_signed_user_reg(pregs, name) \ ((user_regs_native(pregs)) ? (int64_t)((pregs)->native.name) : \ (int32_t)((pregs)->compat.name)) -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; @@ -248,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 9c3555236..4b928a8de 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 cdd4e7f2f..f0765fbd8 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; }