Implement setjmp cookies on MIPS and MIPS64

Bug: http://b/23942752
Change-Id: Ie58892a97b5075d30d7607667251007cda99d38c
diff --git a/tests/setjmp_test.cpp b/tests/setjmp_test.cpp
index 944dac8..c75ab51 100644
--- a/tests/setjmp_test.cpp
+++ b/tests/setjmp_test.cpp
@@ -221,15 +221,24 @@
 #define __JB_SIGFLAG 7
 #elif defined(__x86_64)
 #define __JB_SIGFLAG 8
+#elif defined(__mips__) && defined(__LP64__)
+#define __JB_SIGFLAG 1
+#elif defined(__mips__)
+#define __JB_SIGFLAG 2
 #endif
 
 TEST(setjmp, setjmp_cookie) {
-#if !defined(__mips__)
   jmp_buf jb;
   int value = setjmp(jb);
   ASSERT_EQ(0, value);
 
+#if defined(__mips__) && !defined(__LP64__)
+  // round address to 8-byte boundry
+  uintptr_t jb_aligned = reinterpret_cast<uintptr_t>(jb) & ~7L;
+  long* sigflag = reinterpret_cast<long*>(jb_aligned) + __JB_SIGFLAG;
+#else
   long* sigflag = reinterpret_cast<long*>(jb) + __JB_SIGFLAG;
+#endif
 
   // Make sure there's actually a cookie.
   EXPECT_NE(0, *sigflag & ~1);
@@ -237,5 +246,4 @@
   // Wipe it out
   *sigflag &= 1;
   EXPECT_DEATH(longjmp(jb, 0), "");
-#endif
 }