summaryrefslogtreecommitdiff
path: root/src/gtest-death-test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtest-death-test.cc')
-rw-r--r--src/gtest-death-test.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc
index 36a2e3a..de50ba7 100644
--- a/src/gtest-death-test.cc
+++ b/src/gtest-death-test.cc
@@ -1062,8 +1062,19 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0);
GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
+
+ // Maximum stack alignment in bytes: For a downward-growing stack, this
+ // amount is subtracted from size of the stack space to get an address
+ // that is within the stack space and is aligned on all systems we care
+ // about. As far as I know there is no ABI with stack alignment greater
+ // than 64. We assume stack and stack_size already have alignment of
+ // kMaxStackAlignment.
+ const size_t kMaxStackAlignment = 64;
void* const stack_top =
- static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);
+ static_cast<char*>(stack) +
+ (stack_grows_down ? stack_size - kMaxStackAlignment : 0);
+ GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
+ reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);