001-um-Allow-building-and-running-on-older-hosts.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 0a987645672ebde7844a9c0732a5a25f3d4bb6c6 Mon Sep 17 00:00:00 2001
  2. From: Florian Fainelli <[email protected]>
  3. Date: Thu, 25 May 2017 11:36:26 -0700
  4. Subject: [PATCH] um: Allow building and running on older hosts
  5. [ Upstream commit 0a987645672ebde7844a9c0732a5a25f3d4bb6c6 ]
  6. Commit a78ff1112263 ("um: add extended processor state save/restore
  7. support") and b6024b21fec8 ("um: extend fpstate to _xstate to support
  8. YMM registers") forced the use of the x86 FP _xstate and
  9. PTRACE_GETREGSET/SETREGSET. On older hosts, we would neither be able to
  10. build UML nor run it anymore with these two commits applied because we
  11. don't have definitions for struct _xstate nor these two ptrace requests.
  12. We can determine at build time which fp context structure to check
  13. against, just like we can keep using the old i387 fp save/restore if
  14. PTRACE_GETRESET/SETREGSET are not defined.
  15. Fixes: a78ff1112263 ("um: add extended processor state save/restore support")
  16. Fixes: b6024b21fec8 ("um: extend fpstate to _xstate to support YMM registers")
  17. Signed-off-by: Florian Fainelli <[email protected]>
  18. Signed-off-by: Richard Weinberger <[email protected]>
  19. ---
  20. arch/x86/um/os-Linux/registers.c | 12 ++++++++----
  21. arch/x86/um/user-offsets.c | 4 ++++
  22. 2 files changed, 12 insertions(+), 4 deletions(-)
  23. --- a/arch/x86/um/os-Linux/registers.c
  24. +++ b/arch/x86/um/os-Linux/registers.c
  25. @@ -26,6 +26,7 @@ int save_i387_registers(int pid, unsigne
  26. int save_fp_registers(int pid, unsigned long *fp_regs)
  27. {
  28. +#ifdef PTRACE_GETREGSET
  29. struct iovec iov;
  30. if (have_xstate_support) {
  31. @@ -34,9 +35,9 @@ int save_fp_registers(int pid, unsigned
  32. if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
  33. return -errno;
  34. return 0;
  35. - } else {
  36. + } else
  37. +#endif
  38. return save_i387_registers(pid, fp_regs);
  39. - }
  40. }
  41. int restore_i387_registers(int pid, unsigned long *fp_regs)
  42. @@ -48,6 +49,7 @@ int restore_i387_registers(int pid, unsi
  43. int restore_fp_registers(int pid, unsigned long *fp_regs)
  44. {
  45. +#ifdef PTRACE_SETREGSET
  46. struct iovec iov;
  47. if (have_xstate_support) {
  48. @@ -56,9 +58,9 @@ int restore_fp_registers(int pid, unsign
  49. if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
  50. return -errno;
  51. return 0;
  52. - } else {
  53. + } else
  54. +#endif
  55. return restore_i387_registers(pid, fp_regs);
  56. - }
  57. }
  58. #ifdef __i386__
  59. @@ -122,6 +124,7 @@ int put_fp_registers(int pid, unsigned l
  60. void arch_init_registers(int pid)
  61. {
  62. +#ifdef PTRACE_GETREGSET
  63. struct _xstate fp_regs;
  64. struct iovec iov;
  65. @@ -129,6 +132,7 @@ void arch_init_registers(int pid)
  66. iov.iov_len = sizeof(struct _xstate);
  67. if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
  68. have_xstate_support = 1;
  69. +#endif
  70. }
  71. #endif
  72. --- a/arch/x86/um/user-offsets.c
  73. +++ b/arch/x86/um/user-offsets.c
  74. @@ -50,7 +50,11 @@ void foo(void)
  75. DEFINE(HOST_GS, GS);
  76. DEFINE(HOST_ORIG_AX, ORIG_EAX);
  77. #else
  78. +#if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET)
  79. DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
  80. +#else
  81. + DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
  82. +#endif
  83. DEFINE_LONGS(HOST_BX, RBX);
  84. DEFINE_LONGS(HOST_CX, RCX);
  85. DEFINE_LONGS(HOST_DI, RDI);