Skip to content

Commit 120f8b3

Browse files
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
1 parent 090d8a8 commit 120f8b3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/gtest-death-test.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,19 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
10621062
void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
10631063
MAP_ANON | MAP_PRIVATE, -1, 0);
10641064
GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
1065+
1066+
// Maximum stack alignment in bytes: For a downward-growing stack, this
1067+
// amount is subtracted from size of the stack space to get an address
1068+
// that is within the stack space and is aligned on all systems we care
1069+
// about. As far as I know there is no ABI with stack alignment greater
1070+
// than 64. We assume stack and stack_size already have alignment of
1071+
// kMaxStackAlignment.
1072+
const size_t kMaxStackAlignment = 64;
10651073
void* const stack_top =
1066-
static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);
1074+
static_cast<char*>(stack) +
1075+
(stack_grows_down ? stack_size - kMaxStackAlignment : 0);
1076+
GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
1077+
reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
10671078

10681079
child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
10691080

0 commit comments

Comments
 (0)