[PATCH] configure: Check for "struct esr_context" used on ARM64

Martin Storsjo martin at martin.st
Thu Apr 9 16:42:58 CDT 2020


If not found, use the old codepath from before
85c01202ac70af0c83f894d7a8986adf66983459.

Signed-off-by: Martin Storsjo <martin at martin.st>
---
 configure.ac              |  3 +++
 dlls/ntdll/signal_arm64.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index f30e8b92b0..199139697e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2448,6 +2448,9 @@ AC_CHECK_MEMBERS([scsireq_t.cmd, sg_io_hdr_t.interface_id],,,
 dnl Check for siginfo_t members
 AC_CHECK_MEMBERS([siginfo_t.si_fd],,,[#include <signal.h>])
 
+dnl Check for esr_context members
+AC_CHECK_MEMBERS([struct esr_context.esr],,,[#include <signal.h>])
+
 dnl Check for struct mtget members
 AC_CHECK_MEMBERS([struct mtget.mt_blksiz, struct mtget.mt_gstat, struct mtget.mt_blkno],,,
 [#include <sys/types.h>
diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c
index 5fffd45f7b..f6157ba04f 100644
--- a/dlls/ntdll/signal_arm64.c
+++ b/dlls/ntdll/signal_arm64.c
@@ -101,12 +101,14 @@ static struct fpsimd_context *get_fpsimd_context( ucontext_t *sigcontext )
     return (struct fpsimd_context *)get_extended_sigcontext( sigcontext, FPSIMD_MAGIC );
 }
 
+#ifdef HAVE_STRUCT_ESR_CONTEXT_ESR
 static DWORD64 get_fault_esr( ucontext_t *sigcontext )
 {
     struct esr_context *esr = (struct esr_context *)get_extended_sigcontext( sigcontext, ESR_MAGIC );
     if (esr) return esr->esr;
     return 0;
 }
+#endif
 
 #endif /* linux */
 
@@ -1027,6 +1029,28 @@ static void setup_raise_exception( ucontext_t *sigcontext, struct stack_layout *
     REGn_sig(18, sigcontext) = (ULONG_PTR)NtCurrentTeb();
 }
 
+static inline DWORD is_write_fault( DWORD *pc, ucontext_t *sigcontext )
+{
+#ifdef HAVE_STRUCT_ESR_CONTEXT_ESR
+    return (get_fault_esr( sigcontext ) & 0x40) != 0 ?
+        EXCEPTION_WRITE_FAULT : EXCEPTION_READ_FAULT;
+#else
+    DWORD inst = *pc;
+    if ((inst & 0xbfff0000) == 0x0c000000   /* C3.3.1 */ ||
+        (inst & 0xbfe00000) == 0x0c800000   /* C3.3.2 */ ||
+        (inst & 0xbfdf0000) == 0x0d000000   /* C3.3.3 */ ||
+        (inst & 0xbfc00000) == 0x0d800000   /* C3.3.4 */ ||
+        (inst & 0x3f400000) == 0x08000000   /* C3.3.6 */ ||
+        (inst & 0x3bc00000) == 0x38000000   /* C3.3.8-12 */ ||
+        (inst & 0x3fe00000) == 0x3c800000   /* C3.3.8-12 128bit */ ||
+        (inst & 0x3bc00000) == 0x39000000   /* C3.3.13 */ ||
+        (inst & 0x3fc00000) == 0x3d800000   /* C3.3.13 128bit */ ||
+        (inst & 0x3a400000) == 0x28000000)  /* C3.3.7,14-16 */
+        return EXCEPTION_WRITE_FAULT;
+    return EXCEPTION_READ_FAULT;
+#endif
+}
+
 /**********************************************************************
  *		segv_handler
  *
@@ -1036,6 +1060,7 @@ static void segv_handler( int signal, siginfo_t *info, void *ucontext )
 {
     struct stack_layout *stack;
     ucontext_t *context = ucontext;
+    DWORD *orig_pc = (DWORD *)PC_sig(context);
 
     /* check for page fault inside the thread stack */
     if (signal == SIGSEGV)
@@ -1061,7 +1086,7 @@ static void segv_handler( int signal, siginfo_t *info, void *ucontext )
         break;
     case SIGSEGV:  /* Segmentation fault */
         stack->rec.NumberParameters = 2;
-        stack->rec.ExceptionInformation[0] = (get_fault_esr( context ) & 0x40) != 0;
+        stack->rec.ExceptionInformation[0] = is_write_fault( orig_pc, context );
         stack->rec.ExceptionInformation[1] = (ULONG_PTR)info->si_addr;
         if (!(stack->rec.ExceptionCode = virtual_handle_fault( (void *)stack->rec.ExceptionInformation[1],
                                                          stack->rec.ExceptionInformation[0], FALSE )))
-- 
2.17.1




More information about the wine-devel mailing list