From 4c97512141023985ea849887101d046edb590300 Mon Sep 17 00:00:00 2001 From: jgm Date: Thu, 12 Jul 2012 16:46:50 +0000 Subject: 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 --- src/gtest-death-test.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') 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(stack) + (stack_grows_down ? stack_size : 0); + static_cast(stack) + + (stack_grows_down ? stack_size - kMaxStackAlignment : 0); + GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment && + reinterpret_cast(stack_top) % kMaxStackAlignment == 0); child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args); -- cgit v1.2.3