10b57cec5SDimitry Andric //===-- sanitizer_mac.h -----------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file is shared between various sanitizers' runtime libraries and 100b57cec5SDimitry Andric // provides definitions for OSX-specific functions. 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 1281ad6265SDimitry Andric #ifndef SANITIZER_APPLE_H 1381ad6265SDimitry Andric #define SANITIZER_APPLE_H 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #include "sanitizer_common.h" 160b57cec5SDimitry Andric #include "sanitizer_platform.h" 1781ad6265SDimitry Andric #if SANITIZER_APPLE 180b57cec5SDimitry Andric #include "sanitizer_posix.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric namespace __sanitizer { 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric struct MemoryMappingLayoutData { 230b57cec5SDimitry Andric int current_image; 240b57cec5SDimitry Andric u32 current_magic; 250b57cec5SDimitry Andric u32 current_filetype; 260b57cec5SDimitry Andric ModuleArch current_arch; 270b57cec5SDimitry Andric u8 current_uuid[kModuleUUIDSize]; 280b57cec5SDimitry Andric int current_load_cmd_count; 290b57cec5SDimitry Andric const char *current_load_cmd_addr; 300b57cec5SDimitry Andric bool current_instrumented; 310b57cec5SDimitry Andric }; 320b57cec5SDimitry Andric 335ffd83dbSDimitry Andric template <typename VersionType> 345ffd83dbSDimitry Andric struct VersionBase { 355ffd83dbSDimitry Andric u16 major; 365ffd83dbSDimitry Andric u16 minor; 375ffd83dbSDimitry Andric VersionBaseVersionBase385ffd83dbSDimitry Andric VersionBase(u16 major, u16 minor) : major(major), minor(minor) {} 395ffd83dbSDimitry Andric 405ffd83dbSDimitry Andric bool operator==(const VersionType &other) const { 415ffd83dbSDimitry Andric return major == other.major && minor == other.minor; 425ffd83dbSDimitry Andric } 435ffd83dbSDimitry Andric bool operator>=(const VersionType &other) const { 445ffd83dbSDimitry Andric return major > other.major || 455ffd83dbSDimitry Andric (major == other.major && minor >= other.minor); 465ffd83dbSDimitry Andric } 47e8d8bef9SDimitry Andric bool operator<(const VersionType &other) const { return !(*this >= other); } 480b57cec5SDimitry Andric }; 490b57cec5SDimitry Andric 505ffd83dbSDimitry Andric struct MacosVersion : VersionBase<MacosVersion> { MacosVersionMacosVersion515ffd83dbSDimitry Andric MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {} 525ffd83dbSDimitry Andric }; 535ffd83dbSDimitry Andric 545ffd83dbSDimitry Andric struct DarwinKernelVersion : VersionBase<DarwinKernelVersion> { DarwinKernelVersionDarwinKernelVersion555ffd83dbSDimitry Andric DarwinKernelVersion(u16 major, u16 minor) : VersionBase(major, minor) {} 565ffd83dbSDimitry Andric }; 575ffd83dbSDimitry Andric 585ffd83dbSDimitry Andric MacosVersion GetMacosAlignedVersion(); 595ffd83dbSDimitry Andric DarwinKernelVersion GetDarwinKernelVersion(); 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric char **GetEnviron(); 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric void RestrictMemoryToMaxAddress(uptr max_address); 640b57cec5SDimitry Andric 65fcaf7f86SDimitry Andric using ThreadEventCallback = void (*)(uptr thread); 66fcaf7f86SDimitry Andric using ThreadCreateEventCallback = void (*)(uptr thread, bool gcd_worker); 67fcaf7f86SDimitry Andric struct ThreadEventCallbacks { 68fcaf7f86SDimitry Andric ThreadCreateEventCallback create; 69fcaf7f86SDimitry Andric ThreadEventCallback start; 70fcaf7f86SDimitry Andric ThreadEventCallback terminate; 71fcaf7f86SDimitry Andric ThreadEventCallback destroy; 72fcaf7f86SDimitry Andric }; 73fcaf7f86SDimitry Andric 74fcaf7f86SDimitry Andric void InstallPthreadIntrospectionHook(const ThreadEventCallbacks &callbacks); 75fcaf7f86SDimitry Andric 760b57cec5SDimitry Andric } // namespace __sanitizer 770b57cec5SDimitry Andric 7881ad6265SDimitry Andric #endif // SANITIZER_APPLE 7981ad6265SDimitry Andric #endif // SANITIZER_APPLE_H 80