tsan_platform_mac.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //===-- tsan_platform_mac.cc ----------------------------------------------===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file is a part of ThreadSanitizer (TSan), a race detector.
  9. //
  10. // Mac-specific code.
  11. //===----------------------------------------------------------------------===//
  12. #include "sanitizer_common/sanitizer_platform.h"
  13. #if SANITIZER_MAC
  14. #include "sanitizer_common/sanitizer_common.h"
  15. #include "sanitizer_common/sanitizer_libc.h"
  16. #include "sanitizer_common/sanitizer_procmaps.h"
  17. #include "tsan_platform.h"
  18. #include "tsan_rtl.h"
  19. #include "tsan_flags.h"
  20. #include <pthread.h>
  21. #include <signal.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdarg.h>
  26. #include <sys/mman.h>
  27. #include <sys/syscall.h>
  28. #include <sys/time.h>
  29. #include <sys/types.h>
  30. #include <sys/resource.h>
  31. #include <sys/stat.h>
  32. #include <unistd.h>
  33. #include <errno.h>
  34. #include <sched.h>
  35. namespace __tsan {
  36. uptr GetShadowMemoryConsumption() {
  37. return 0;
  38. }
  39. void FlushShadowMemory() {
  40. }
  41. void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive) {
  42. }
  43. uptr GetRSS() {
  44. return 0;
  45. }
  46. #ifndef TSAN_GO
  47. void InitializeShadowMemory() {
  48. uptr shadow = (uptr)MmapFixedNoReserve(kShadowBeg,
  49. kShadowEnd - kShadowBeg);
  50. if (shadow != kShadowBeg) {
  51. Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n");
  52. Printf("FATAL: Make sure to compile with -fPIE and "
  53. "to link with -pie.\n");
  54. Die();
  55. }
  56. DPrintf("kShadow %zx-%zx (%zuGB)\n",
  57. kShadowBeg, kShadowEnd,
  58. (kShadowEnd - kShadowBeg) >> 30);
  59. DPrintf("kAppMem %zx-%zx (%zuGB)\n",
  60. kAppMemBeg, kAppMemEnd,
  61. (kAppMemEnd - kAppMemBeg) >> 30);
  62. }
  63. #endif
  64. void InitializePlatform() {
  65. DisableCoreDumperIfNecessary();
  66. }
  67. #ifndef TSAN_GO
  68. int call_pthread_cancel_with_cleanup(int(*fn)(void *c, void *m,
  69. void *abstime), void *c, void *m, void *abstime,
  70. void(*cleanup)(void *arg), void *arg) {
  71. // pthread_cleanup_push/pop are hardcore macros mess.
  72. // We can't intercept nor call them w/o including pthread.h.
  73. int res;
  74. pthread_cleanup_push(cleanup, arg);
  75. res = fn(c, m, abstime);
  76. pthread_cleanup_pop(0);
  77. return res;
  78. }
  79. #endif
  80. } // namespace __tsan
  81. #endif // SANITIZER_MAC