]> git.saurik.com Git - apple/libplatform.git/blob - internal/os/internal.h
libplatform-177.270.1.tar.gz
[apple/libplatform.git] / internal / os / internal.h
1 /*
2 * Copyright (c) 2013 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20
21 #ifndef __OS_INTERNAL_H__
22 #define __OS_INTERNAL_H__
23
24 #define __OS_ALLOC_INDIRECT__
25
26 #include <TargetConditionals.h>
27 #include <machine/cpu_capabilities.h>
28
29 #include "os/base_private.h"
30 #include "os/semaphore_private.h"
31
32 #include <stddef.h>
33 #include <stdint.h>
34 #include <stdbool.h>
35 #include <limits.h>
36 #if defined(__arm__)
37 #include <arm/arch.h>
38 #endif
39 #include <mach/thread_switch.h>
40
41 #define likely(x) os_likely(x)
42 #define unlikely(x) os_unlikely(x)
43
44 #define __OS_CRASH__(rc, msg) ({ \
45 _os_set_crash_log_cause_and_message(rc, msg); \
46 os_prevent_tail_call_optimization(); \
47 __builtin_trap(); \
48 })
49
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)
54
55 #define __OS_EXPOSE_INTERNALS__ 1
56 #include "os/internal/internal_shared.h"
57 #include "yield.h"
58
59 #define OS_NOEXPORT extern __attribute__((__visibility__("hidden")))
60
61 #define OS_VARIANT(f, v) OS_CONCAT(f, OS_CONCAT($VARIANT$, v))
62
63 #define _OS_ATOMIC_ALIAS_PRIVATE_EXTERN(n)
64 #define OS_ATOMIC_EXPORT OS_EXPORT
65 #define _OS_ATOMIC_ALIAS_GLOBL(n) \
66 ".globl _" OS_STRINGIFY(n) "\n\t"
67 #ifdef __thumb__
68 #define _OS_ATOMIC_ALIAS_THUMB(n) \
69 ".thumb_func _" OS_STRINGIFY(n) "\n\t"
70 #else
71 #define _OS_ATOMIC_ALIAS_THUMB(n)
72 #endif
73 #define _OS_ATOMIC_ALIAS_SET(n, o) \
74 ".set _" OS_STRINGIFY(n) ", _" OS_STRINGIFY(o)
75
76 #define OS_ATOMIC_ALIAS(n, o) __asm__( \
77 _OS_ATOMIC_ALIAS_PRIVATE_EXTERN(n) \
78 _OS_ATOMIC_ALIAS_GLOBL(n) \
79 _OS_ATOMIC_ALIAS_THUMB(n) \
80 _OS_ATOMIC_ALIAS_SET(n, o))
81
82 #define OS_ATOMIC_EXPORT_ALIAS(n, o) __asm__( \
83 _OS_ATOMIC_ALIAS_GLOBL(n) \
84 _OS_ATOMIC_ALIAS_THUMB(n) \
85 _OS_ATOMIC_ALIAS_SET(n, o))
86
87 #define _OS_VARIANT_RESOLVER(s, v, ...) \
88 __attribute__((visibility(OS_STRINGIFY(v)))) extern void* s(void); \
89 void* s(void) { \
90 __asm__(".symbol_resolver _" OS_STRINGIFY(s)); \
91 __VA_ARGS__ \
92 }
93
94 #endif // __OS_INTERNAL_H__