mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Gather more coverage data
Switch to ForkWithFlags for InitProcess (it will not reset coverage). Explicitly dump coverage after initial namespace setup. Return instead of exiting from libunwind sandbox. PiperOrigin-RevId: 563368599 Change-Id: I3b764db015a71bd091ee7b4b5b614281cbb84832
This commit is contained in:
parent
f6ec787902
commit
b350a41a10
@ -37,8 +37,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/base/attributes.h"
|
#include "absl/base/attributes.h"
|
||||||
#include "absl/container/flat_hash_map.h"
|
#include "absl/container/flat_hash_map.h"
|
||||||
@ -300,7 +300,7 @@ void ForkServer::LaunchChild(const ForkRequest& request, int execve_fd,
|
|||||||
// A custom init process is only needed if a new PID NS is created.
|
// A custom init process is only needed if a new PID NS is created.
|
||||||
if (request.clone_flags() & CLONE_NEWPID) {
|
if (request.clone_flags() & CLONE_NEWPID) {
|
||||||
// Spawn a child process
|
// Spawn a child process
|
||||||
pid_t child = fork();
|
pid_t child = util::ForkWithFlags(SIGCHLD);
|
||||||
if (child < 0) {
|
if (child < 0) {
|
||||||
SAPI_RAW_PLOG(FATAL, "Could not spawn init process");
|
SAPI_RAW_PLOG(FATAL, "Could not spawn init process");
|
||||||
}
|
}
|
||||||
@ -587,6 +587,9 @@ void ForkServer::CreateInitialNamespaces() {
|
|||||||
SAPI_RAW_PCHECK(TEMP_FAILURE_RETRY(read(open_efd.get(), &value,
|
SAPI_RAW_PCHECK(TEMP_FAILURE_RETRY(read(open_efd.get(), &value,
|
||||||
sizeof(value))) == sizeof(value),
|
sizeof(value))) == sizeof(value),
|
||||||
"synchronizing initial namespaces creation");
|
"synchronizing initial namespaces creation");
|
||||||
|
SAPI_RAW_PCHECK(chroot("/realroot") == 0,
|
||||||
|
"chrooting prior to dumping coverage");
|
||||||
|
util::DumpCoverageData();
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
SAPI_RAW_PCHECK(TEMP_FAILURE_RETRY(read(create_efd.get(), &value,
|
SAPI_RAW_PCHECK(TEMP_FAILURE_RETRY(read(create_efd.get(), &value,
|
||||||
|
@ -68,7 +68,8 @@ int main() {
|
|||||||
if (child_pid == 0) {
|
if (child_pid == 0) {
|
||||||
sandbox2::Client client(&comms);
|
sandbox2::Client client(&comms);
|
||||||
client.SandboxMeHere();
|
client.SandboxMeHere();
|
||||||
exit(sandbox2::RunLibUnwindAndSymbolizer(&comms));
|
return sandbox2::RunLibUnwindAndSymbolizer(&comms) ? EXIT_SUCCESS
|
||||||
|
: EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SAPI_RAW_VLOG(1, "ForkServer Comms closed. Exiting");
|
SAPI_RAW_VLOG(1, "ForkServer Comms closed. Exiting");
|
||||||
|
@ -74,6 +74,16 @@ extern "C" void __gcov_flush() ABSL_ATTRIBUTE_WEAK;
|
|||||||
extern "C" void __gcov_reset() ABSL_ATTRIBUTE_WEAK;
|
extern "C" void __gcov_reset() ABSL_ATTRIBUTE_WEAK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void ResetCoverageData() {
|
||||||
|
#ifdef __ELF__
|
||||||
|
if (&__gcov_reset != nullptr) {
|
||||||
|
__gcov_reset();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void DumpCoverageData() {
|
void DumpCoverageData() {
|
||||||
#ifdef __ELF__
|
#ifdef __ELF__
|
||||||
if (&__gcov_dump != nullptr) {
|
if (&__gcov_dump != nullptr) {
|
||||||
@ -86,16 +96,6 @@ void DumpCoverageData() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetCoverageData() {
|
|
||||||
#ifdef __ELF__
|
|
||||||
if (&__gcov_reset != nullptr) {
|
|
||||||
__gcov_reset();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void CharPtrArrToVecString(char* const* arr, std::vector<std::string>* vec) {
|
void CharPtrArrToVecString(char* const* arr, std::vector<std::string>* vec) {
|
||||||
*vec = CharPtrArray(arr).ToStringVector();
|
*vec = CharPtrArray(arr).ToStringVector();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
namespace sandbox2::util {
|
namespace sandbox2::util {
|
||||||
|
|
||||||
|
void DumpCoverageData();
|
||||||
|
|
||||||
// Converts an array of char* (terminated by a nullptr, like argv, or environ
|
// Converts an array of char* (terminated by a nullptr, like argv, or environ
|
||||||
// arrays), to an std::vector<std::string>.
|
// arrays), to an std::vector<std::string>.
|
||||||
ABSL_DEPRECATED("Use CharPtrArray(arr).ToStringVector() instead")
|
ABSL_DEPRECATED("Use CharPtrArray(arr).ToStringVector() instead")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user