1*0fca6ea1SDimitry Andric //===--- rtsan.cpp - Realtime Sanitizer -------------------------*- C++ -*-===// 2*0fca6ea1SDimitry Andric // 3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0fca6ea1SDimitry Andric // 7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 8*0fca6ea1SDimitry Andric // 9*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 10*0fca6ea1SDimitry Andric 11*0fca6ea1SDimitry Andric #include <rtsan/rtsan.h> 12*0fca6ea1SDimitry Andric #include <rtsan/rtsan_context.h> 13*0fca6ea1SDimitry Andric #include <rtsan/rtsan_interceptors.h> 14*0fca6ea1SDimitry Andric 15*0fca6ea1SDimitry Andric using namespace __rtsan; 16*0fca6ea1SDimitry Andric 17*0fca6ea1SDimitry Andric bool __rtsan::rtsan_initialized; 18*0fca6ea1SDimitry Andric bool __rtsan::rtsan_init_is_running; 19*0fca6ea1SDimitry Andric 20*0fca6ea1SDimitry Andric extern "C" { 21*0fca6ea1SDimitry Andric __rtsan_init()22*0fca6ea1SDimitry AndricSANITIZER_INTERFACE_ATTRIBUTE void __rtsan_init() { 23*0fca6ea1SDimitry Andric CHECK(!rtsan_init_is_running); 24*0fca6ea1SDimitry Andric if (rtsan_initialized) 25*0fca6ea1SDimitry Andric return; 26*0fca6ea1SDimitry Andric rtsan_init_is_running = true; 27*0fca6ea1SDimitry Andric 28*0fca6ea1SDimitry Andric InitializeInterceptors(); 29*0fca6ea1SDimitry Andric 30*0fca6ea1SDimitry Andric rtsan_init_is_running = false; 31*0fca6ea1SDimitry Andric rtsan_initialized = true; 32*0fca6ea1SDimitry Andric } 33*0fca6ea1SDimitry Andric __rtsan_realtime_enter()34*0fca6ea1SDimitry AndricSANITIZER_INTERFACE_ATTRIBUTE void __rtsan_realtime_enter() { 35*0fca6ea1SDimitry Andric __rtsan::GetContextForThisThread().RealtimePush(); 36*0fca6ea1SDimitry Andric } 37*0fca6ea1SDimitry Andric __rtsan_realtime_exit()38*0fca6ea1SDimitry AndricSANITIZER_INTERFACE_ATTRIBUTE void __rtsan_realtime_exit() { 39*0fca6ea1SDimitry Andric __rtsan::GetContextForThisThread().RealtimePop(); 40*0fca6ea1SDimitry Andric } 41*0fca6ea1SDimitry Andric __rtsan_off()42*0fca6ea1SDimitry AndricSANITIZER_INTERFACE_ATTRIBUTE void __rtsan_off() { 43*0fca6ea1SDimitry Andric __rtsan::GetContextForThisThread().BypassPush(); 44*0fca6ea1SDimitry Andric } 45*0fca6ea1SDimitry Andric __rtsan_on()46*0fca6ea1SDimitry AndricSANITIZER_INTERFACE_ATTRIBUTE void __rtsan_on() { 47*0fca6ea1SDimitry Andric __rtsan::GetContextForThisThread().BypassPop(); 48*0fca6ea1SDimitry Andric } 49*0fca6ea1SDimitry Andric 50*0fca6ea1SDimitry Andric } // extern "C" 51