d: Merge upstream dmd, druntime 2bbf64907c, phobos b64bfbf91
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_mac.h
blob1cf2e298cc91b9bda82b20a0bcd025eabdf59c6d
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
15 #include "sanitizer_common.h"
16 #include "sanitizer_platform.h"
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
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
37 #if SANITIZER_APPLE
38 #include "sanitizer_posix.h"
40 namespace __sanitizer {
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;
53 template <typename VersionType>
54 struct VersionBase {
55 u16 major;
56 u16 minor;
58 VersionBase(u16 major, u16 minor) : major(major), minor(minor) {}
60 bool operator==(const VersionType &other) const {
61 return major == other.major && minor == other.minor;
63 bool operator>=(const VersionType &other) const {
64 return major > other.major ||
65 (major == other.major && minor >= other.minor);
67 bool operator<(const VersionType &other) const { return !(*this >= other); }
70 struct MacosVersion : VersionBase<MacosVersion> {
71 MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
74 struct DarwinKernelVersion : VersionBase<DarwinKernelVersion> {
75 DarwinKernelVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
78 MacosVersion GetMacosAlignedVersion();
79 DarwinKernelVersion GetDarwinKernelVersion();
81 char **GetEnviron();
83 void RestrictMemoryToMaxAddress(uptr max_address);
85 using ThreadEventCallback = void (*)(uptr thread);
86 using ThreadCreateEventCallback = void (*)(uptr thread, bool gcd_worker);
87 struct ThreadEventCallbacks {
88 ThreadCreateEventCallback create;
89 ThreadEventCallback start;
90 ThreadEventCallback terminate;
91 ThreadEventCallback destroy;
94 void InstallPthreadIntrospectionHook(const ThreadEventCallbacks &callbacks);
96 } // namespace __sanitizer
98 #endif // SANITIZER_APPLE
99 #endif // SANITIZER_APPLE_H