]>
git.saurik.com Git - apple/libplatform.git/blob - internal/os/internal.h
4d7a083edf6d887549fc893479237b63c951360d
2 * Copyright (c) 2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
21 #ifndef __OS_INTERNAL_H__
22 #define __OS_INTERNAL_H__
24 #define __OS_ALLOC_INDIRECT__
26 #include <TargetConditionals.h>
27 #include <machine/cpu_capabilities.h>
29 #include "os/base_private.h"
30 #include "os/semaphore_private.h"
39 #include <mach/thread_switch.h>
41 #define likely(x) os_likely(x)
42 #define unlikely(x) os_unlikely(x)
44 #define __OS_CRASH__(rc, msg) ({ \
45 _os_set_crash_log_cause_and_message(rc, msg); \
46 os_prevent_tail_call_optimization(); \
50 #define __LIBPLATFORM_CLIENT_CRASH__(rc, msg) \
51 __OS_CRASH__(rc, "BUG IN CLIENT OF LIBPLATFORM: " msg)
52 #define __LIBPLATFORM_INTERNAL_CRASH__(rc, msg) \
53 __OS_CRASH__(rc, "BUG IN LIBPLATFORM: " msg)
56 #define __OS_EXPOSE_INTERNALS__ 1
57 #include "os/internal/internal_shared.h"
60 #if !VARIANT_NO_RESOLVERS
61 #if defined(_ARM_ARCH_7) && !defined(__ARM_ARCH_7S__)
63 #define OS_VARIANT_SELECTOR up
65 #define OS_VARIANT_SELECTOR mp
68 #if !defined(OS_VARIANT_SELECTOR) && defined(VARIANT_NO_RESOLVERS)
69 // forced up variant for no-barrier OSAtomics
70 #define OS_ATOMIC_NO_BARRIER_ONLY 1
71 #define OS_VARIANT_SELECTOR up
73 #if (defined(_ARM_ARCH_7) || defined(__arm64__)) && \
74 (!defined(OS_ATOMIC_WFE) && !OS_ATOMIC_UP)
75 #define OS_ATOMIC_WFE 0
79 #define OS_LOCK_VARIANT_SELECTOR wfe
81 #define OS_LOCK_VARIANT_SELECTOR mp
84 #endif // !VARIANT_NO_RESOLVERS
86 #define OS_VARIANT(f, v) OS_CONCAT(f, OS_CONCAT($VARIANT$, v))
88 #ifdef OS_VARIANT_SELECTOR
89 #define _OS_ATOMIC_ALIAS_PRIVATE_EXTERN(n) \
90 ".private_extern _" OS_STRINGIFY(n) "\n\t"
91 #define OS_ATOMIC_EXPORT
93 #define _OS_ATOMIC_ALIAS_PRIVATE_EXTERN(n)
94 #define OS_ATOMIC_EXPORT OS_EXPORT
96 #define _OS_ATOMIC_ALIAS_GLOBL(n) \
97 ".globl _" OS_STRINGIFY(n) "\n\t"
99 #define _OS_ATOMIC_ALIAS_THUMB(n) \
100 ".thumb_func _" OS_STRINGIFY(n) "\n\t"
102 #define _OS_ATOMIC_ALIAS_THUMB(n)
104 #define _OS_ATOMIC_ALIAS_SET(n, o) \
105 ".set _" OS_STRINGIFY(n) ", _" OS_STRINGIFY(o)
107 #define OS_ATOMIC_ALIAS(n, o) __asm__( \
108 _OS_ATOMIC_ALIAS_PRIVATE_EXTERN(n) \
109 _OS_ATOMIC_ALIAS_GLOBL(n) \
110 _OS_ATOMIC_ALIAS_THUMB(n) \
111 _OS_ATOMIC_ALIAS_SET(n, o))
113 #define OS_ATOMIC_EXPORT_ALIAS(n, o) __asm__( \
114 _OS_ATOMIC_ALIAS_GLOBL(n) \
115 _OS_ATOMIC_ALIAS_THUMB(n) \
116 _OS_ATOMIC_ALIAS_SET(n, o))
118 #define _OS_VARIANT_RESOLVER(s, v, ...) \
119 __attribute__((visibility(OS_STRINGIFY(v)))) extern void* s(void); \
121 __asm__(".symbol_resolver _" OS_STRINGIFY(s)); \
125 #define _OS_VARIANT_UPMP_RESOLVER(s, v) \
126 _OS_VARIANT_RESOLVER(s, v, \
127 uint32_t *_c = (void*)(uintptr_t)_COMM_PAGE_CPU_CAPABILITIES; \
129 extern void OS_VARIANT(s, up)(void); \
130 return &OS_VARIANT(s, up); \
132 extern void OS_VARIANT(s, mp)(void); \
133 return &OS_VARIANT(s, mp); \
136 #define OS_VARIANT_UPMP_RESOLVER(s) \
137 _OS_VARIANT_UPMP_RESOLVER(s, default)
139 #define OS_VARIANT_UPMP_RESOLVER_INTERNAL(s) \
140 _OS_VARIANT_UPMP_RESOLVER(s, hidden)
142 #endif // __OS_INTERNAL_H__