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" #include "sandboxed_api/sandbox2/sanitizer.h"
#if defined(THREAD_SANITIZER) #if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
#include <sanitizer/tsan_interface.h> 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 #endif
#include <dirent.h> #include <dirent.h>
@ -150,9 +153,12 @@ int GetNumberOfThreads(int pid) {
return threads; return threads;
} }
void WaitForTsan() { void WaitForSanitizer() {
#if defined(THREAD_SANITIZER) #if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
static bool ABSL_ATTRIBUTE_UNUSED dummy_tsan_once = []() { 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); __sanitizer_sandbox_on_notify(nullptr);
return true; return true;
}(); }();

View File

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