MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / ExecDeathTestFork

Function ExecDeathTestFork

rtpose_wrapper/src/gtest/gtest-all.cpp:7149–7181  ·  view source on GitHub ↗

A threadsafe implementation of fork(2) for threadsafe-style death tests that uses clone(2). It dies with an error message if anything goes wrong.

Source from the content-addressed store, hash-verified

7147// that uses clone(2). It dies with an error message if anything goes
7148// wrong.
7149static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
7150 ExecDeathTestArgs args = { argv, close_fd };
7151 pid_t child_pid = -1;
7152
7153# if GTEST_HAS_CLONE
7154 const bool use_fork = GTEST_FLAG(death_test_use_fork);
7155
7156 if (!use_fork) {
7157 static const bool stack_grows_down = StackGrowsDown();
7158 const size_t stack_size = getpagesize();
7159 // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.
7160 void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
7161 MAP_ANON | MAP_PRIVATE, -1, 0);
7162 GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
7163 void* const stack_top =
7164 static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);
7165
7166 child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
7167
7168 GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
7169 }
7170# else
7171 const bool use_fork = true;
7172# endif // GTEST_HAS_CLONE
7173
7174 if (use_fork && (child_pid = fork()) == 0) {
7175 ExecDeathTestChildMain(&args);
7176 _exit(0);
7177 }
7178
7179 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
7180 return child_pid;
7181}
7182
7183// The AssumeRole process for a fork-and-exec death test. It re-executes the
7184// main program from the beginning, setting the --gtest_filter

Callers 1

AssumeRoleMethod · 0.85

Calls 2

StackGrowsDownFunction · 0.85
ExecDeathTestChildMainFunction · 0.85

Tested by

no test coverage detected