Implement WaitForTsan on other sanitizers

__sanitizer_sandbox_on_notify is not tsan specific.
It's empty for other sanitizers now, but we are going to need it soon.

PiperOrigin-RevId: 414873197
Change-Id: I251ac38e5c886980b4baa7f05306643599a25090
This commit is contained in:
Sandboxed API Team 2021-12-07 17:58:34 -08:00 committed by Copybara-Service
parent 8979b47d7f
commit 46c09e0024
2 changed files with 21 additions and 12 deletions

View File

@ -16,8 +16,11 @@
#include "sandboxed_api/sandbox2/sanitizer.h"
#if defined(THREAD_SANITIZER)
#include <sanitizer/tsan_interface.h>
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
defined(ABSL_HAVE_HWADDRESS_SANITIZER) || \
defined(ABSL_HAVE_LEAK_SANITIZER) || \
defined(ABSL_HAVE_MEMORY_SANITIZER) || defined(ABSL_HAVE_THREAD_SANITIZER)
#include <sanitizer/common_interface_defs.h>
#endif
#include <dirent.h>
@ -150,9 +153,12 @@ int GetNumberOfThreads(int pid) {
return threads;
}
void WaitForTsan() {
#if defined(THREAD_SANITIZER)
static bool ABSL_ATTRIBUTE_UNUSED dummy_tsan_once = []() {
void WaitForSanitizer() {
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
defined(ABSL_HAVE_HWADDRESS_SANITIZER) || \
defined(ABSL_HAVE_LEAK_SANITIZER) || \
defined(ABSL_HAVE_MEMORY_SANITIZER) || defined(ABSL_HAVE_THREAD_SANITIZER)
static bool ABSL_ATTRIBUTE_UNUSED dummy_once = []() {
__sanitizer_sandbox_on_notify(nullptr);
return true;
}();

View File

@ -42,13 +42,16 @@ absl::Status MarkAllFDsAsCOEExcept(
// errors.
int GetNumberOfThreads(int pid);
// When running under TSAN, it will spawn a background thread. This is not
// desirable for sandboxing purposes. We will notify its background thread
// that we wish for it to finish and then wait for it to be done. It is safe
// to call this function more than once, since it keeps track of whether it
// has already notified TSAN.
// This function does nothing if not running under TSAN.
void WaitForTsan();
// When running under a sanitizer, it may spawn a background threads. This is
// not desirable for sandboxing purposes. We will notify its background thread
// that we wish for it to finish and then wait for it to be done. It is safe to
// call this function more than once, since it keeps track of whether it has
// already notified the sanitizer. This function does nothing if not running
// under a sanitizer.
void WaitForSanitizer();
ABSL_DEPRECATED("Use `sandbox2::sanitizer::WaitForSanitizer()`.")
inline void WaitForTsan() { WaitForSanitizer(); }
// Sanitizes current process (which will not execve a sandboxed binary).
// File-descriptors in fd_exceptions will be either closed