10b57cec5SDimitry Andric //===-- sanitizer_stoptheworld.h --------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // Defines the StopTheWorld function which suspends the execution of the current 100b57cec5SDimitry Andric // process and runs the user-supplied callback in the same address space. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric #ifndef SANITIZER_STOPTHEWORLD_H 140b57cec5SDimitry Andric #define SANITIZER_STOPTHEWORLD_H 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #include "sanitizer_internal_defs.h" 170b57cec5SDimitry Andric #include "sanitizer_common.h" 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric namespace __sanitizer { 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric enum PtraceRegistersStatus { 220b57cec5SDimitry Andric REGISTERS_UNAVAILABLE_FATAL = -1, 230b57cec5SDimitry Andric REGISTERS_UNAVAILABLE = 0, 240b57cec5SDimitry Andric REGISTERS_AVAILABLE = 1 250b57cec5SDimitry Andric }; 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric // Holds the list of suspended threads and provides an interface to dump their 280b57cec5SDimitry Andric // register contexts. 290b57cec5SDimitry Andric class SuspendedThreadsList { 300b57cec5SDimitry Andric public: 310b57cec5SDimitry Andric SuspendedThreadsList() = default; 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric // Can't declare pure virtual functions in sanitizer runtimes: 340b57cec5SDimitry Andric // __cxa_pure_virtual might be unavailable. Use UNIMPLEMENTED() instead. GetRegistersAndSP(uptr index,InternalMmapVector<uptr> * buffer,uptr * sp)35*e8d8bef9SDimitry Andric virtual PtraceRegistersStatus GetRegistersAndSP( 36*e8d8bef9SDimitry Andric uptr index, InternalMmapVector<uptr> *buffer, uptr *sp) const { 370b57cec5SDimitry Andric UNIMPLEMENTED(); 380b57cec5SDimitry Andric } 390b57cec5SDimitry Andric ThreadCount()400b57cec5SDimitry Andric virtual uptr ThreadCount() const { UNIMPLEMENTED(); } GetThreadID(uptr index)410b57cec5SDimitry Andric virtual tid_t GetThreadID(uptr index) const { UNIMPLEMENTED(); } 420b57cec5SDimitry Andric 43*e8d8bef9SDimitry Andric protected: ~SuspendedThreadsList()44*e8d8bef9SDimitry Andric ~SuspendedThreadsList() {} 45*e8d8bef9SDimitry Andric 460b57cec5SDimitry Andric private: 470b57cec5SDimitry Andric // Prohibit copy and assign. 48*e8d8bef9SDimitry Andric SuspendedThreadsList(const SuspendedThreadsList &) = delete; 49*e8d8bef9SDimitry Andric void operator=(const SuspendedThreadsList &) = delete; 500b57cec5SDimitry Andric }; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric typedef void (*StopTheWorldCallback)( 530b57cec5SDimitry Andric const SuspendedThreadsList &suspended_threads_list, 540b57cec5SDimitry Andric void *argument); 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric // Suspend all threads in the current process and run the callback on the list 570b57cec5SDimitry Andric // of suspended threads. This function will resume the threads before returning. 580b57cec5SDimitry Andric // The callback should not call any libc functions. The callback must not call 590b57cec5SDimitry Andric // exit() nor _exit() and instead return to the caller. 600b57cec5SDimitry Andric // This function should NOT be called from multiple threads simultaneously. 610b57cec5SDimitry Andric void StopTheWorld(StopTheWorldCallback callback, void *argument); 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric } // namespace __sanitizer 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric #endif // SANITIZER_STOPTHEWORLD_H 66