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