OSDN Git Service

Split up the stack space tests into their own noinline functions.
authorJosh Gao <jmgao@google.com>
Thu, 16 Mar 2017 02:42:05 +0000 (19:42 -0700)
committerJosh Gao <jmgao@google.com>
Thu, 16 Mar 2017 02:53:17 +0000 (19:53 -0700)
Prevent the compiler from being too smart and allocating a stack buffer
at the beginning of a function.

Bug: http://b/36206043
Test: 32/64-bit dynamic tests pass, static ones still don't
Change-Id: I90c575be43a9dd6c4fefc0d8b514f1ae0405b994

tests/pthread_test.cpp

index 4fb15ad..60fe294 100755 (executable)
@@ -1886,25 +1886,34 @@ extern _Unwind_Reason_Code FrameCounter(_Unwind_Context* ctx, void* arg);
 
 static volatile bool signal_handler_on_altstack_done;
 
+__attribute__((__noinline__))
+static void signal_handler_backtrace() {
+  // Check if we have enough stack space for unwinding.
+  int count = 0;
+  _Unwind_Backtrace(FrameCounter, &count);
+  ASSERT_GT(count, 0);
+}
+
+__attribute__((__noinline__))
+static void signal_handler_logging() {
+  // Check if we have enough stack space for logging.
+  std::string s(2048, '*');
+  GTEST_LOG_(INFO) << s;
+  signal_handler_on_altstack_done = true;
+}
+
+__attribute__((__noinline__))
+static void signal_handler_snprintf() {
+  // Check if we have enough stack space for snprintf to a PATH_MAX buffer, plus some extra.
+  char buf[PATH_MAX + 2048];
+  ASSERT_GT(snprintf(buf, sizeof(buf), "/proc/%d/status", getpid()), 0);
+}
+
 static void SignalHandlerOnAltStack(int signo, siginfo_t*, void*) {
   ASSERT_EQ(SIGUSR1, signo);
-  {
-    // Check if we have enough stack space for unwinding.
-    int count = 0;
-    _Unwind_Backtrace(FrameCounter, &count);
-    ASSERT_GT(count, 0);
-  }
-  {
-    // Check if we have enough stack space for logging.
-    std::string s(2048, '*');
-    GTEST_LOG_(INFO) << s;
-    signal_handler_on_altstack_done = true;
-  }
-  {
-    // Check if we have enough stack space for snprintf to a PATH_MAX buffer, plus some extra.
-    char buf[PATH_MAX + 2048];
-    ASSERT_GT(snprintf(buf, sizeof(buf), "/proc/%d/status", getpid()), 0);
-  }
+  signal_handler_backtrace();
+  signal_handler_logging();
+  signal_handler_snprintf();
 }
 
 TEST(pthread, big_enough_signal_stack) {