[PATCH] ntdll: Determine write fault based on failed instruction on ARM64

André Hentschel nerv at dawncrow.de
Sun Jan 21 13:22:55 CST 2018


Based on code from Qemu

Reported-by: Stefan Dösinger <stefan at codeweavers.com>
Signed-off-by: André Hentschel <nerv at dawncrow.de>
---
 dlls/ntdll/signal_arm64.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c
index a04fe93..57ec13a 100644
--- a/dlls/ntdll/signal_arm64.c
+++ b/dlls/ntdll/signal_arm64.c
@@ -568,6 +568,23 @@ static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL f
     return STATUS_SUCCESS;
 }
 
+static inline DWORD is_write_fault( ucontext_t *context )
+{
+    DWORD inst = *(DWORD *)PC_sig(context);
+    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;
+}
+
 /**********************************************************************
  *		segv_handler
  *
@@ -604,8 +621,7 @@ static void segv_handler( int signal, siginfo_t *info, void *ucontext )
     case SIGSEGV:  /* Segmentation fault */
         rec->ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
         rec->NumberParameters = 2;
-        /* FIXME: Currently the kernel provides no way to determine if it's read or write */
-        rec->ExceptionInformation[0] = 0;
+        rec->ExceptionInformation[0] = is_write_fault(context);
         rec->ExceptionInformation[1] = (ULONG_PTR)info->si_addr;
         break;
     case SIGBUS:  /* Alignment check exception */
-- 
2.7.4




More information about the wine-devel mailing list