Small ChangeLog tweak.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_stoptheworld.h
blobc3245266fb90bd13da2966e18a791dc4ef189235
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.
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_STOPTHEWORLD_H
13 #define SANITIZER_STOPTHEWORLD_H
15 #include "sanitizer_internal_defs.h"
16 #include "sanitizer_common.h"
18 namespace __sanitizer {
19 typedef int SuspendedThreadID;
21 // Holds the list of suspended threads and provides an interface to dump their
22 // register contexts.
23 class SuspendedThreadsList {
24 public:
25 SuspendedThreadsList()
26 : thread_ids_(1024) {}
27 SuspendedThreadID GetThreadID(uptr index) const {
28 CHECK_LT(index, thread_ids_.size());
29 return thread_ids_[index];
31 int GetRegistersAndSP(uptr index, uptr *buffer, uptr *sp) const;
32 // The buffer in GetRegistersAndSP should be at least this big.
33 static uptr RegisterCount();
34 uptr thread_count() const { return thread_ids_.size(); }
35 bool Contains(SuspendedThreadID thread_id) const {
36 for (uptr i = 0; i < thread_ids_.size(); i++) {
37 if (thread_ids_[i] == thread_id)
38 return true;
40 return false;
42 void Append(SuspendedThreadID thread_id) {
43 thread_ids_.push_back(thread_id);
46 private:
47 InternalMmapVector<SuspendedThreadID> thread_ids_;
49 // Prohibit copy and assign.
50 SuspendedThreadsList(const SuspendedThreadsList&);
51 void operator=(const SuspendedThreadsList&);
54 typedef void (*StopTheWorldCallback)(
55 const SuspendedThreadsList &suspended_threads_list,
56 void *argument);
58 // Suspend all threads in the current process and run the callback on the list
59 // of suspended threads. This function will resume the threads before returning.
60 // The callback should not call any libc functions. The callback must not call
61 // exit() nor _exit() and instead return to the caller.
62 // This function should NOT be called from multiple threads simultaneously.
63 void StopTheWorld(StopTheWorldCallback callback, void *argument);
65 } // namespace __sanitizer
67 #endif // SANITIZER_STOPTHEWORLD_H