[compiler-rt] 14cd113 - [sanitizer] Add the settings of Read and Write flags in SignalContext for LoongArch

Weining Lu via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 21:35:03 PST 2022


Author: Youling Tang
Date: 2022-11-10T13:34:22+08:00
New Revision: 14cd113e69935e2de9c4d300c3ab01cf83c5d4db

URL: https://github.com/llvm/llvm-project/commit/14cd113e69935e2de9c4d300c3ab01cf83c5d4db
DIFF: https://github.com/llvm/llvm-project/commit/14cd113e69935e2de9c4d300c3ab01cf83c5d4db.diff

LOG: [sanitizer] Add the settings of Read and Write flags in SignalContext for LoongArch

The bit-30 in this `__flags` means the address error is due to memory load, and the
bit-31 means the address error is due to memory store. (see SC_ADDRERR_RD
and SC_ADDRERR_WR in kernel arch/loongarch/include/uapi/asm/sigcontext.h).

`illegal_write_test.cpp` and `illegal_read_test.cpp` have been tested and passed.

Reviewed By: SixWeining, xen0n, XiaodongLoong

Differential Revision: https://reviews.llvm.org/D137231

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 5d1bf9539603..f23ea9da3714 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1956,6 +1956,13 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
   u64 esr;
   if (!Aarch64GetESR(ucontext, &esr)) return Unknown;
   return esr & ESR_ELx_WNR ? Write : Read;
+#elif defined(__loongarch__)
+  u32 flags = ucontext->uc_mcontext.__flags;
+  if (flags & SC_ADDRERR_RD)
+    return SignalContext::Read;
+  if (flags & SC_ADDRERR_WR)
+    return SignalContext::Write;
+  return SignalContext::Unknown;
 #elif defined(__sparc__)
   // Decode the instruction to determine the access type.
   // From OpenSolaris $SRC/uts/sun4/os/trap.c (get_accesstype).


        


More information about the llvm-commits mailing list