Home | History | Annotate | Line # | Download | only in sanitizer_common
      1 //===-- sanitizer_stoptheworld.h --------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     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.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 #ifndef SANITIZER_STOPTHEWORLD_H
     15 #define SANITIZER_STOPTHEWORLD_H
     16 
     17 #include "sanitizer_internal_defs.h"
     18 #include "sanitizer_common.h"
     19 
     20 namespace __sanitizer {
     21 
     22 enum PtraceRegistersStatus {
     23   REGISTERS_UNAVAILABLE_FATAL = -1,
     24   REGISTERS_UNAVAILABLE = 0,
     25   REGISTERS_AVAILABLE = 1
     26 };
     27 
     28 // Holds the list of suspended threads and provides an interface to dump their
     29 // register contexts.
     30 class SuspendedThreadsList {
     31  public:
     32   SuspendedThreadsList() = default;
     33 
     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,
     37                                                   uptr *sp) const {
     38     UNIMPLEMENTED();
     39   }
     40 
     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(); }
     45 
     46  private:
     47   // Prohibit copy and assign.
     48   SuspendedThreadsList(const SuspendedThreadsList&);
     49   void operator=(const SuspendedThreadsList&);
     50 };
     51 
     52 typedef void (*StopTheWorldCallback)(
     53     const SuspendedThreadsList &suspended_threads_list,
     54     void *argument);
     55 
     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);
     62 
     63 }  // namespace __sanitizer
     64 
     65 #endif  // SANITIZER_STOPTHEWORLD_H
     66