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 18namespace __sanitizer { 19typedef int SuspendedThreadID; 20 21// Holds the list of suspended threads and provides an interface to dump their 22// register contexts. 23class 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]; 30 } 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; 39 } 40 return false; 41 } 42 void Append(SuspendedThreadID thread_id) { 43 thread_ids_.push_back(thread_id); 44 } 45 46 private: 47 InternalMmapVector<SuspendedThreadID> thread_ids_; 48 49 // Prohibit copy and assign. 50 SuspendedThreadsList(const SuspendedThreadsList&); 51 void operator=(const SuspendedThreadsList&); 52}; 53 54typedef void (*StopTheWorldCallback)( 55 const SuspendedThreadsList &suspended_threads_list, 56 void *argument); 57 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. 61// This function should NOT be called from multiple threads simultaneously. 62void StopTheWorld(StopTheWorldCallback callback, void *argument); 63 64} // namespace __sanitizer 65 66#endif // SANITIZER_STOPTHEWORLD_H 67