[CRIU] [PATCH 5/8] compel/x86: Separate functions used to get fpu state
Dmitry Safonov
dima at arista.com
Wed Jan 31 19:58:12 MSK 2018
Mere cleanup. For Skylake workaround I'll call one after another,
so it's better separate it in a small helpers.
Signed-off-by: Dmitry Safonov <dima at arista.com>
---
compel/arch/x86/src/lib/infect.c | 40 ++++++++++++++++++++++++++++------------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/compel/arch/x86/src/lib/infect.c b/compel/arch/x86/src/lib/infect.c
index cdf4683397b0..d95299b3b692 100644
--- a/compel/arch/x86/src/lib/infect.c
+++ b/compel/arch/x86/src/lib/infect.c
@@ -225,12 +225,35 @@ int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe,
((user_regs_native(pregs)) ? (int64_t)((pregs)->native.name) : \
(int32_t)((pregs)->compat.name))
+static int get_task_xsave(pid_t pid, user_fpregs_struct_t *xsave)
+{
+ struct iovec iov;
+
+ iov.iov_base = xsave;
+ iov.iov_len = sizeof(*xsave);
+
+ if (ptrace(PTRACE_GETREGSET, pid, (unsigned int)NT_X86_XSTATE, &iov) < 0) {
+ pr_perror("Can't obtain FPU registers for %d", pid);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int get_task_fpregs(pid_t pid, user_fpregs_struct_t *xsave)
+{
+ if (ptrace(PTRACE_GETFPREGS, pid, NULL, xsave)) {
+ pr_perror("Can't obtain FPU registers for %d", pid);
+ return -1;
+ }
+
+ return 0;
+}
+
int get_task_regs(pid_t pid, user_regs_struct_t *regs, save_regs_t save,
void *arg, __maybe_unused unsigned long flags)
{
- user_fpregs_struct_t xsave = { }, *xs = NULL;
-
- struct iovec iov;
+ user_fpregs_struct_t xsave = { }, *xs = NULL;
int ret = -1;
pr_info("Dumping general registers for %d in %s mode\n", pid,
@@ -264,18 +287,11 @@ int get_task_regs(pid_t pid, user_regs_struct_t *regs, save_regs_t save,
pr_info("Dumping GP/FPU registers for %d\n", pid);
if (compel_cpu_has_feature(X86_FEATURE_OSXSAVE)) {
- iov.iov_base = &xsave;
- iov.iov_len = sizeof(xsave);
-
- if (ptrace(PTRACE_GETREGSET, pid, (unsigned int)NT_X86_XSTATE, &iov) < 0) {
- pr_perror("Can't obtain FPU registers for %d", pid);
+ if (get_task_xsave(pid, &xsave))
goto err;
- }
} else {
- if (ptrace(PTRACE_GETFPREGS, pid, NULL, &xsave)) {
- pr_perror("Can't obtain FPU registers for %d", pid);
+ if (get_task_fpregs(pid, &xsave))
goto err;
- }
}
xs = &xsave;
--
2.13.6
More information about the CRIU
mailing list