1 //===-- sanitizer_stoptheworld.h --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Defines the StopTheWorld function which suspends the execution of the current
11 // process and runs the user-supplied callback in the same address space.
13 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_STOPTHEWORLD_H
15 #define SANITIZER_STOPTHEWORLD_H
17 #include "sanitizer_internal_defs.h"
18 #include "sanitizer_common.h"
20 namespace __sanitizer {
22 enum PtraceRegistersStatus {
23 REGISTERS_UNAVAILABLE_FATAL = -1,
24 REGISTERS_UNAVAILABLE = 0,
25 REGISTERS_AVAILABLE = 1
28 // Holds the list of suspended threads and provides an interface to dump their
30 class SuspendedThreadsList {
32 SuspendedThreadsList() = default;
34 // Can't declare pure virtual functions in sanitizer runtimes:
35 // __cxa_pure_virtual might be unavailable. Use UNIMPLEMENTED() instead.
36 virtual PtraceRegistersStatus GetRegistersAndSP(uptr index, uptr *buffer,
41 // The buffer in GetRegistersAndSP should be at least this big.
42 virtual uptr RegisterCount() const { UNIMPLEMENTED(); }
43 virtual uptr ThreadCount() const { UNIMPLEMENTED(); }
44 virtual tid_t GetThreadID(uptr index) const { UNIMPLEMENTED(); }
47 // Prohibit copy and assign.
48 SuspendedThreadsList(const SuspendedThreadsList&);
49 void operator=(const SuspendedThreadsList&);
52 typedef void (*StopTheWorldCallback)(
53 const SuspendedThreadsList &suspended_threads_list,
56 // Suspend all threads in the current process and run the callback on the list
57 // of suspended threads. This function will resume the threads before returning.
58 // The callback should not call any libc functions. The callback must not call
59 // exit() nor _exit() and instead return to the caller.
60 // This function should NOT be called from multiple threads simultaneously.
61 void StopTheWorld(StopTheWorldCallback callback, void *argument);
63 } // namespace __sanitizer
65 #endif // SANITIZER_STOPTHEWORLD_H