sanitizer_mac.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===-- sanitizer_mac.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. // This file is shared between various sanitizers' runtime libraries and
  10. // provides definitions for OSX-specific functions.
  11. //===----------------------------------------------------------------------===//
  12. #ifndef SANITIZER_APPLE_H
  13. #define SANITIZER_APPLE_H
  14. #include "sanitizer_common.h"
  15. #include "sanitizer_platform.h"
  16. #if SANITIZER_APPLE
  17. #include "sanitizer_posix.h"
  18. namespace __sanitizer {
  19. struct MemoryMappingLayoutData {
  20. int current_image;
  21. u32 current_magic;
  22. u32 current_filetype;
  23. ModuleArch current_arch;
  24. u8 current_uuid[kModuleUUIDSize];
  25. int current_load_cmd_count;
  26. const char *current_load_cmd_addr;
  27. bool current_instrumented;
  28. };
  29. template <typename VersionType>
  30. struct VersionBase {
  31. u16 major;
  32. u16 minor;
  33. VersionBase(u16 major, u16 minor) : major(major), minor(minor) {}
  34. bool operator==(const VersionType &other) const {
  35. return major == other.major && minor == other.minor;
  36. }
  37. bool operator>=(const VersionType &other) const {
  38. return major > other.major ||
  39. (major == other.major && minor >= other.minor);
  40. }
  41. bool operator<(const VersionType &other) const { return !(*this >= other); }
  42. };
  43. struct MacosVersion : VersionBase<MacosVersion> {
  44. MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
  45. };
  46. struct DarwinKernelVersion : VersionBase<DarwinKernelVersion> {
  47. DarwinKernelVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
  48. };
  49. MacosVersion GetMacosAlignedVersion();
  50. DarwinKernelVersion GetDarwinKernelVersion();
  51. char **GetEnviron();
  52. void RestrictMemoryToMaxAddress(uptr max_address);
  53. using ThreadEventCallback = void (*)(uptr thread);
  54. using ThreadCreateEventCallback = void (*)(uptr thread, bool gcd_worker);
  55. struct ThreadEventCallbacks {
  56. ThreadCreateEventCallback create;
  57. ThreadEventCallback start;
  58. ThreadEventCallback terminate;
  59. ThreadEventCallback destroy;
  60. };
  61. void InstallPthreadIntrospectionHook(const ThreadEventCallbacks &callbacks);
  62. } // namespace __sanitizer
  63. #endif // SANITIZER_APPLE
  64. #endif // SANITIZER_APPLE_H