sanitizer_stoptheworld.h revision 53c18d7e051c7dfe3cc8a2351e6ee67a264dbb51
17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch//===-- sanitizer_stoptheworld.h --------------------------------*- C++ -*-===// 27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// 37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// The LLVM Compiler Infrastructure 47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// This file is distributed under the University of Illinois Open Source 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// License. See LICENSE.TXT for details. 77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch//===----------------------------------------------------------------------===// 97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Defines the StopTheWorld function which suspends the execution of the current 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// process and runs the user-supplied callback in the same address space. 127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// 137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch//===----------------------------------------------------------------------===// 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#ifndef SANITIZER_STOPTHEWORLD_H 157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#define SANITIZER_STOPTHEWORLD_H 167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "sanitizer_internal_defs.h" 187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "sanitizer_common.h" 197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace __sanitizer { 217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtypedef int SuspendedThreadID; 227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Holds the list of suspended threads and provides an interface to dump their 247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// register contexts. 257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SuspendedThreadsList { 267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public: 277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SuspendedThreadsList() 287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch : thread_ids_(1024) {} 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SuspendedThreadID GetThreadID(uptr index) const { 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch CHECK_LT(index, thread_ids_.size()); 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return thread_ids_[index]; 327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch int GetRegistersAndSP(uptr index, uptr *buffer, uptr *sp) const; 34 // The buffer in GetRegistersAndSP should be at least this big. 35 static uptr RegisterCount(); 36 uptr thread_count() const { return thread_ids_.size(); } 37 bool Contains(SuspendedThreadID thread_id) const { 38 for (uptr i = 0; i < thread_ids_.size(); i++) { 39 if (thread_ids_[i] == thread_id) 40 return true; 41 } 42 return false; 43 } 44 void Append(SuspendedThreadID thread_id) { 45 thread_ids_.push_back(thread_id); 46 } 47 48 private: 49 InternalVector<SuspendedThreadID> thread_ids_; 50 51 // Prohibit copy and assign. 52 SuspendedThreadsList(const SuspendedThreadsList&); 53 void operator=(const SuspendedThreadsList&); 54}; 55 56typedef void (*StopTheWorldCallback)( 57 const SuspendedThreadsList &suspended_threads_list, 58 void *argument); 59 60// Suspend all threads in the current process and run the callback on the list 61// of suspended threads. This function will resume the threads before returning. 62// The callback should not call any libc functions. 63// This function should NOT be called from multiple threads simultaneously. 64void StopTheWorld(StopTheWorldCallback callback, void *argument); 65 66} // namespace __sanitizer 67 68#endif // SANITIZER_STOPTHEWORLD_H 69