1 //===-- sanitizer_mac.h -----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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
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). */
28 #define TARGET_OS_IOS 0
31 #define TARGET_OS_TV 0
33 #ifndef TARGET_OS_WATCH
34 #define TARGET_OS_WATCH 0
38 #include "sanitizer_posix.h"
40 namespace __sanitizer
{
42 struct MemoryMappingLayoutData
{
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
>
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();
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