Add stack overflow check

Change-Id: I67fcb5ad4bda304879ce05561b03aa7cd46e9990
diff --git a/src/thread.cc b/src/thread.cc
index e1de92d..45ff6dd 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -136,6 +136,12 @@
      */
 }
 
+// TODO: placeholder
+static void StackOverflowFromCode(Method* method) {
+    //NOTE: to save code space, this handler needs to look up its own Thread*
+    UNIMPLEMENTED(FATAL) << "Stack overflow: " << PrettyMethod(method);
+}
+
 void Thread::InitFunctionPointers() {
 #if defined(__arm__)
   pShlLong = art_shl_long;
@@ -188,6 +194,7 @@
   pUnlockObjectFromCode = UnlockObjectFromCode;
   pFindFieldFromCode = Field::FindFieldFromCode;
   pCheckSuspendFromCode = CheckSuspendFromCode;
+  pStackOverflowFromCode = StackOverflowFromCode;
   pDebugMe = DebugMe;
 }
 
@@ -380,7 +387,6 @@
     PLOG(FATAL) << "pthread_attr_getstack failed";
   }
 
-  const size_t kStackOverflowReservedBytes = 1024; // Space to throw a StackOverflowError in.
   if (stack_size <= kStackOverflowReservedBytes) {
     LOG(FATAL) << "attempt to attach a thread with a too-small stack (" << stack_size << " bytes)";
   }
@@ -388,7 +394,7 @@
   // stack_base is the "lowest addressable byte" of the stack.
   // Our stacks grow down, so we want stack_end_ to be near there, but reserving enough room
   // to throw a StackOverflowError.
-  stack_end_ = reinterpret_cast<byte*>(stack_base) - kStackOverflowReservedBytes;
+  stack_end_ = reinterpret_cast<byte*>(stack_base) + kStackOverflowReservedBytes;
 
   // Sanity check.
   int stack_variable;