| 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 | |
| 15 | #include "sanitizer_common.h" |
| 16 | #include "sanitizer_platform.h" |
| 17 | #if SANITIZER_APPLE |
| 18 | #include "sanitizer_posix.h" |
| 19 | |
| 20 | namespace __sanitizer { |
| 21 | |
| 22 | struct MemoryMappingLayoutData { |
| 23 | int current_image; |
| 24 | u32 current_magic; |
| 25 | u32 current_filetype; |
| 26 | ModuleArch current_arch; |
| 27 | u8 current_uuid[kModuleUUIDSize]; |
| 28 | int current_load_cmd_count; |
| 29 | const char *current_load_cmd_addr; |
| 30 | bool current_instrumented; |
| 31 | }; |
| 32 | |
| 33 | template <typename VersionType> |
| 34 | struct VersionBase { |
| 35 | u16 major; |
| 36 | u16 minor; |
| 37 | |
| 38 | VersionBase(u16 major, u16 minor) : major(major), minor(minor) {} |
| 39 | |
| 40 | bool operator>=(const VersionType &other) const { |
| 41 | return major > other.major || |
| 42 | (major == other.major && minor >= other.minor); |
| 43 | } |
| 44 | bool operator<(const VersionType &other) const { return !(*this >= other); } |
| 45 | }; |
| 46 | |
| 47 | template <typename VersionType> |
| 48 | bool operator==(const VersionBase<VersionType> &self, |
| 49 | const VersionBase<VersionType> &other) { |
| 50 | return self.major == other.major && self.minor == other.minor; |
| 51 | } |
| 52 | |
| 53 | struct MacosVersion : VersionBase<MacosVersion> { |
| 54 | MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {} |
| 55 | }; |
| 56 | |
| 57 | struct DarwinKernelVersion : VersionBase<DarwinKernelVersion> { |
| 58 | DarwinKernelVersion(u16 major, u16 minor) : VersionBase(major, minor) {} |
| 59 | }; |
| 60 | |
| 61 | MacosVersion GetMacosAlignedVersion(); |
| 62 | DarwinKernelVersion GetDarwinKernelVersion(); |
| 63 | |
| 64 | char **GetEnviron(); |
| 65 | |
| 66 | void RestrictMemoryToMaxAddress(uptr max_address); |
| 67 | |
| 68 | using ThreadEventCallback = void (*)(uptr thread); |
| 69 | using ThreadCreateEventCallback = void (*)(uptr thread, bool gcd_worker); |
| 70 | struct ThreadEventCallbacks { |
| 71 | ThreadCreateEventCallback create; |
| 72 | ThreadEventCallback start; |
| 73 | ThreadEventCallback terminate; |
| 74 | ThreadEventCallback destroy; |
| 75 | }; |
| 76 | |
| 77 | void InstallPthreadIntrospectionHook(const ThreadEventCallbacks &callbacks); |
| 78 | |
| 79 | } // namespace __sanitizer |
| 80 | |
| 81 | #endif // SANITIZER_APPLE |
| 82 | #endif // SANITIZER_APPLE_H |
| 83 | |