Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.7 KiB

  1. //===- llvm/Support/Valgrind.h - Communication with Valgrind -----*- 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. // Methods for communicating with a valgrind instance this program is running
  11. // under. These are all no-ops unless LLVM was configured on a system with the
  12. // valgrind headers installed and valgrind is controlling this process.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_SYSTEM_VALGRIND_H
  16. #define LLVM_SYSTEM_VALGRIND_H
  17. #include "llvm/Config/llvm-config.h"
  18. #include "llvm/Support/Compiler.h"
  19. #include <stddef.h>
  20. #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
  21. // tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact
  22. // functions by name.
  23. extern "C" {
  24. LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
  25. const volatile void *cv);
  26. LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
  27. const volatile void *cv);
  28. LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
  29. LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
  30. }
  31. #endif
  32. namespace llvm {
  33. namespace sys {
  34. // True if Valgrind is controlling this process.
  35. bool RunningOnValgrind();
  36. // Discard valgrind's translation of code in the range [Addr .. Addr + Len).
  37. // Otherwise valgrind may continue to execute the old version of the code.
  38. void ValgrindDiscardTranslations(const void *Addr, size_t Len);
  39. #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
  40. // Thread Sanitizer is a valgrind tool that finds races in code.
  41. // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
  42. // This marker is used to define a happens-before arc. The race detector will
  43. // infer an arc from the begin to the end when they share the same pointer
  44. // argument.
  45. #define TsanHappensBefore(cv) \
  46. AnnotateHappensBefore(__FILE__, __LINE__, cv)
  47. // This marker defines the destination of a happens-before arc.
  48. #define TsanHappensAfter(cv) \
  49. AnnotateHappensAfter(__FILE__, __LINE__, cv)
  50. // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
  51. #define TsanIgnoreWritesBegin() \
  52. AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
  53. // Resume checking for racy writes.
  54. #define TsanIgnoreWritesEnd() \
  55. AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
  56. #else
  57. #define TsanHappensBefore(cv)
  58. #define TsanHappensAfter(cv)
  59. #define TsanIgnoreWritesBegin()
  60. #define TsanIgnoreWritesEnd()
  61. #endif
  62. }
  63. }
  64. #endif