aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjgm <jgm@google.com>2012-07-12 16:46:50 +0000
committerjgm <jgm@google.com>2012-07-12 16:46:50 +0000
commit4c97512141023985ea849887101d046edb590300 (patch)
tree0f7c18a86e0f003e56dba05cae9b05097b0aaef5 /src
parenta1c4b46bc2c12ea7c61108f001a5b5eb4a8ccad0 (diff)
downloadgoogletest-4c97512141023985ea849887101d046edb590300.tar.gz
googletest-4c97512141023985ea849887101d046edb590300.tar.bz2
googletest-4c97512141023985ea849887101d046edb590300.zip
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
Diffstat (limited to 'src')
-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 36a2e3a7..de50ba74 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);