sanitizer_stoptheworld.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===-- sanitizer_stoptheworld.h --------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Defines the StopTheWorld function which suspends the execution of the current
  10. // process and runs the user-supplied callback in the same address space.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef SANITIZER_STOPTHEWORLD_H
  14. #define SANITIZER_STOPTHEWORLD_H
  15. #include "sanitizer_internal_defs.h"
  16. #include "sanitizer_common.h"
  17. namespace __sanitizer {
  18. enum PtraceRegistersStatus {
  19. REGISTERS_UNAVAILABLE_FATAL = -1,
  20. REGISTERS_UNAVAILABLE = 0,
  21. REGISTERS_AVAILABLE = 1
  22. };
  23. // Holds the list of suspended threads and provides an interface to dump their
  24. // register contexts.
  25. class SuspendedThreadsList {
  26. public:
  27. SuspendedThreadsList() = default;
  28. // Can't declare pure virtual functions in sanitizer runtimes:
  29. // __cxa_pure_virtual might be unavailable. Use UNIMPLEMENTED() instead.
  30. virtual PtraceRegistersStatus GetRegistersAndSP(
  31. uptr index, InternalMmapVector<uptr> *buffer, uptr *sp) const {
  32. UNIMPLEMENTED();
  33. }
  34. virtual uptr ThreadCount() const { UNIMPLEMENTED(); }
  35. virtual tid_t GetThreadID(uptr index) const { UNIMPLEMENTED(); }
  36. protected:
  37. ~SuspendedThreadsList() {}
  38. private:
  39. // Prohibit copy and assign.
  40. SuspendedThreadsList(const SuspendedThreadsList &) = delete;
  41. void operator=(const SuspendedThreadsList &) = delete;
  42. };
  43. typedef void (*StopTheWorldCallback)(
  44. const SuspendedThreadsList &suspended_threads_list,
  45. void *argument);
  46. // Suspend all threads in the current process and run the callback on the list
  47. // of suspended threads. This function will resume the threads before returning.
  48. // The callback should not call any libc functions. The callback must not call
  49. // exit() nor _exit() and instead return to the caller.
  50. // This function should NOT be called from multiple threads simultaneously.
  51. void StopTheWorld(StopTheWorldCallback callback, void *argument);
  52. } // namespace __sanitizer
  53. #endif // SANITIZER_STOPTHEWORLD_H