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