sanitizer_mac.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_MAC_H
  13. #define SANITIZER_MAC_H
  14. #include "sanitizer_common.h"
  15. #include "sanitizer_platform.h"
  16. /* TARGET_OS_OSX is not present in SDKs before Darwin16 (macOS 10.12) use
  17. TARGET_OS_MAC (we have no support for iOS in any form for these versions,
  18. so there's no ambiguity). */
  19. #if !defined(TARGET_OS_OSX) && TARGET_OS_MAC
  20. # define TARGET_OS_OSX 1
  21. #endif
  22. /* Other TARGET_OS_xxx are not present on earlier versions, define them to
  23. 0 (we have no support for them; they are not valid targets anyway). */
  24. #ifndef TARGET_OS_IOS
  25. #define TARGET_OS_IOS 0
  26. #endif
  27. #ifndef TARGET_OS_TV
  28. #define TARGET_OS_TV 0
  29. #endif
  30. #ifndef TARGET_OS_WATCH
  31. #define TARGET_OS_WATCH 0
  32. #endif
  33. #if SANITIZER_MAC
  34. #include "sanitizer_posix.h"
  35. namespace __sanitizer {
  36. struct MemoryMappingLayoutData {
  37. int current_image;
  38. u32 current_magic;
  39. u32 current_filetype;
  40. ModuleArch current_arch;
  41. u8 current_uuid[kModuleUUIDSize];
  42. int current_load_cmd_count;
  43. const char *current_load_cmd_addr;
  44. bool current_instrumented;
  45. };
  46. template <typename VersionType>
  47. struct VersionBase {
  48. u16 major;
  49. u16 minor;
  50. VersionBase(u16 major, u16 minor) : major(major), minor(minor) {}
  51. bool operator==(const VersionType &other) const {
  52. return major == other.major && minor == other.minor;
  53. }
  54. bool operator>=(const VersionType &other) const {
  55. return major > other.major ||
  56. (major == other.major && minor >= other.minor);
  57. }
  58. bool operator<(const VersionType &other) const { return !(*this >= other); }
  59. };
  60. struct MacosVersion : VersionBase<MacosVersion> {
  61. MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
  62. };
  63. struct DarwinKernelVersion : VersionBase<DarwinKernelVersion> {
  64. DarwinKernelVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
  65. };
  66. MacosVersion GetMacosAlignedVersion();
  67. DarwinKernelVersion GetDarwinKernelVersion();
  68. char **GetEnviron();
  69. void RestrictMemoryToMaxAddress(uptr max_address);
  70. } // namespace __sanitizer
  71. #endif // SANITIZER_MAC
  72. #endif // SANITIZER_MAC_H