[PATCH] [LLVM] Asan Linux MIPS32 support

Jyun-Yan You jyyou.tw at gmail.com
Mon Jun 3 02:55:57 PDT 2013


jyyou.tw added you to the CC list for the revision "[LLVM] Asan Linux MIPS32 support".

http://llvm-reviews.chandlerc.com/D908

Files:
  lib/asan/asan_mapping.h
  lib/asan/asan_linux.cc
  lib/asan/asan_thread.cc
  lib/sanitizer_common/sanitizer_stacktrace.h
  lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc

Index: lib/asan/asan_mapping.h
===================================================================
--- lib/asan/asan_mapping.h
+++ lib/asan/asan_mapping.h
@@ -49,6 +49,13 @@
 // || `[0x24000000, 0x27ffffff]` || ShadowGap  ||
 // || `[0x20000000, 0x23ffffff]` || LowShadow  ||
 // || `[0x00000000, 0x1fffffff]` || LowMem     ||
+//
+// Default Linux/MIPS mapping:
+// || `[0x2aaa8000, 0xffffffff]` || HighMem    ||
+// || `[0x0fffd000, 0x2aaa7fff]` || HighShadow ||
+// || `[0x0bffd000, 0x0fffcfff]` || ShadowGap  ||
+// || `[0x0aaa8000, 0x0bffcfff]` || LowShadow  ||
+// || `[0x00000000, 0x0aaa7fff]` || LowMem     ||
 
 #if ASAN_FLEXIBLE_MAPPING_AND_OFFSET == 1
 extern SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_mapping_scale;
@@ -62,7 +69,11 @@
 # else
 #  define SHADOW_SCALE (3)
 #  if SANITIZER_WORDSIZE == 32
-#   define SHADOW_OFFSET (1 << 29)
+#   if defined(__mips__)
+#     define SHADOW_OFFSET 0x0aaa8000
+#   else
+#     define SHADOW_OFFSET (1 << 29)
+#   endif
 #  else
 #   if defined(__powerpc64__)
 #    define SHADOW_OFFSET (1ULL << 41)
Index: lib/asan/asan_linux.cc
===================================================================
--- lib/asan/asan_linux.cc
+++ lib/asan/asan_linux.cc
@@ -89,6 +89,11 @@
   stk_ptr = (uptr *) *sp;
   *bp = stk_ptr[15];
 # endif
+# elif defined(__mips__)
+  ucontext_t *ucontext = (ucontext_t*)context;
+  *pc = ucontext->uc_mcontext.gregs[31];
+  *bp = ucontext->uc_mcontext.gregs[30];
+  *sp = ucontext->uc_mcontext.gregs[29];
 #else
 # error "Unsupported arch"
 #endif
Index: lib/asan/asan_thread.cc
===================================================================
--- lib/asan/asan_thread.cc
+++ lib/asan/asan_thread.cc
@@ -39,7 +39,8 @@
   thread = 0;
 }
 
-static char thread_registry_placeholder[sizeof(ThreadRegistry)];
+// MIPS requires aligned address
+static char thread_registry_placeholder[sizeof(ThreadRegistry)] ALIGNED(16);
 static ThreadRegistry *asan_thread_registry;
 
 static ThreadContextBase *GetAsanThreadContext(u32 tid) {
Index: lib/sanitizer_common/sanitizer_stacktrace.h
===================================================================
--- lib/sanitizer_common/sanitizer_stacktrace.h
+++ lib/sanitizer_common/sanitizer_stacktrace.h
@@ -21,7 +21,8 @@
 
 #if SANITIZER_LINUX && (defined(__arm__) || \
     defined(__powerpc__) || defined(__powerpc64__) || \
-    defined(__sparc__))
+    defined(__sparc__) || \
+    defined(__mips__))
 #define SANITIZER_CAN_FAST_UNWIND 0
 #else
 #define SANITIZER_CAN_FAST_UNWIND 1
Index: lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+++ lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
@@ -373,6 +373,10 @@
 typedef pt_regs regs_struct;
 #define REG_SP gpr[PT_R1]
 
+#elif defined(__mips__)
+typedef struct user regs_struct;
+#define REG_SP regs[EF_REG29]
+
 #else
 #error "Unsupported architecture"
 #endif // SANITIZER_ANDROID && defined(__arm__)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D908.2.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130603/e047e4a9/attachment.bin>


More information about the llvm-commits mailing list