Skip to content

Commit 0a98764

Browse files
ffainellirichardweinberger
authored andcommitted
um: Allow building and running on older hosts
Commit a78ff11 ("um: add extended processor state save/restore support") and b6024b2 ("um: extend fpstate to _xstate to support YMM registers") forced the use of the x86 FP _xstate and PTRACE_GETREGSET/SETREGSET. On older hosts, we would neither be able to build UML nor run it anymore with these two commits applied because we don't have definitions for struct _xstate nor these two ptrace requests. We can determine at build time which fp context structure to check against, just like we can keep using the old i387 fp save/restore if PTRACE_GETRESET/SETREGSET are not defined. Fixes: a78ff11 ("um: add extended processor state save/restore support") Fixes: b6024b2 ("um: extend fpstate to _xstate to support YMM registers") Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent f44f1e7 commit 0a98764

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

arch/x86/um/os-Linux/registers.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ int save_i387_registers(int pid, unsigned long *fp_regs)
2626

2727
int save_fp_registers(int pid, unsigned long *fp_regs)
2828
{
29+
#ifdef PTRACE_GETREGSET
2930
struct iovec iov;
3031

3132
if (have_xstate_support) {
@@ -34,9 +35,9 @@ int save_fp_registers(int pid, unsigned long *fp_regs)
3435
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
3536
return -errno;
3637
return 0;
37-
} else {
38+
} else
39+
#endif
3840
return save_i387_registers(pid, fp_regs);
39-
}
4041
}
4142

4243
int restore_i387_registers(int pid, unsigned long *fp_regs)
@@ -48,6 +49,7 @@ int restore_i387_registers(int pid, unsigned long *fp_regs)
4849

4950
int restore_fp_registers(int pid, unsigned long *fp_regs)
5051
{
52+
#ifdef PTRACE_SETREGSET
5153
struct iovec iov;
5254

5355
if (have_xstate_support) {
@@ -56,9 +58,9 @@ int restore_fp_registers(int pid, unsigned long *fp_regs)
5658
if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
5759
return -errno;
5860
return 0;
59-
} else {
61+
} else
62+
#endif
6063
return restore_i387_registers(pid, fp_regs);
61-
}
6264
}
6365

6466
#ifdef __i386__
@@ -122,13 +124,15 @@ int put_fp_registers(int pid, unsigned long *regs)
122124

123125
void arch_init_registers(int pid)
124126
{
127+
#ifdef PTRACE_GETREGSET
125128
struct _xstate fp_regs;
126129
struct iovec iov;
127130

128131
iov.iov_base = &fp_regs;
129132
iov.iov_len = sizeof(struct _xstate);
130133
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
131134
have_xstate_support = 1;
135+
#endif
132136
}
133137
#endif
134138

arch/x86/um/user-offsets.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ void foo(void)
5050
DEFINE(HOST_GS, GS);
5151
DEFINE(HOST_ORIG_AX, ORIG_EAX);
5252
#else
53+
#if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET)
5354
DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
55+
#else
56+
DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
57+
#endif
5458
DEFINE_LONGS(HOST_BX, RBX);
5559
DEFINE_LONGS(HOST_CX, RCX);
5660
DEFINE_LONGS(HOST_DI, RDI);

0 commit comments

Comments
 (0)