mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
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 <xemul@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
da17b223f1
commit
976e13a193
@@ -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)
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user