summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjgm@google.com <jgm@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2012-07-12 16:46:50 +0000
committerjgm@google.com <jgm@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2012-07-12 16:46:50 +0000
commit120f8b35d7958abcbb5ccfd26d2a5e562a6a8046 (patch)
tree0f7c18a86e0f003e56dba05cae9b05097b0aaef5
parent090d8a824857f24e5ec780112a3d4b269f9a7d3d (diff)
downloadgtest-120f8b35d7958abcbb5ccfd26d2a5e562a6a8046.tar.gz
gtest-120f8b35d7958abcbb5ccfd26d2a5e562a6a8046.tar.bz2
gtest-120f8b35d7958abcbb5ccfd26d2a5e562a6a8046.tar.xz
fixes a problem in which we pass the address one byte ~/svn/googletest/trunk
after the end of stack space in a call to clone(). According to Linux's man page on clone(), the 'stack' parameter usually points to the topmost address of the memory space set up for the child stack. The existing code points one byte after the end git-svn-id: http://googletest.googlecode.com/svn/trunk@618 861a406c-534a-0410-8894-cb66d6ee9925
-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);