forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportability.h
More file actions
184 lines (150 loc) · 5.1 KB
/
portability.h
File metadata and controls
184 lines (150 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef incl_HPHP_PORTABILITY_H_
#define incl_HPHP_PORTABILITY_H_
// From folly/Likely.h
#if defined(__GNUC__) && __GNUC__ >= 4
#define LIKELY(x) (__builtin_expect((x), 1))
#define UNLIKELY(x) (__builtin_expect((x), 0))
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#endif
//////////////////////////////////////////////////////////////////////
/*
* Various macros to make certain things conditional on either
* compiler or architecture.
*
* Currently we don't *really* compile on anything other than gcc or
* sometimes clang, and there are some parts of the code using
* __attribute__ stuff directly, but some things go through these
* macros to make it maybe easier to change later.
*/
//////////////////////////////////////////////////////////////////////
// TODO: does clang define __GNUC__ ?
#ifndef __GNUC__
# define __attribute__(x)
#endif
//////////////////////////////////////////////////////////////////////
#ifdef ATTRIBUTE_UNUSED
# undef ATTRIBUTE_UNUSED
#endif
#ifdef ATTRIBUTE_NORETURN
# undef ATTRIBUTE_NORETURN
#endif
#ifdef ATTRIBUTE_PRINTF
# undef ATTRIBUTE_PRINTF
#endif
#ifdef ATTRIBUTE_PRINTF_STRING
# undef ATTRIBUTE_PRINTF_STRING
#endif
#define ATTRIBUTE_PRINTF_STRING FOLLY_PRINTF_FORMAT
#ifdef _MSC_VER
#define ATTRIBUTE_NORETURN __declspec(noreturn)
#define ATTRIBUTE_PRINTF(a1, a2)
#ifndef __thread
# define __thread __declspec(thread)
#endif
#define ATTRIBUTE_UNUSED
#define ALWAYS_INLINE __forceinline
#define EXTERNALLY_VISIBLE
#define FLATTEN
#define NEVER_INLINE __declspec(noinline)
#define UNUSED
#else
#define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
#define ATTRIBUTE_PRINTF(a1, a2) \
__attribute__((__format__ (__printf__, a1, a2)))
#define ATTRIBUTE_UNUSED __attribute__((__unused__))
#define ALWAYS_INLINE inline __attribute__((__always_inline__))
#define EXTERNALLY_VISIBLE __attribute__((__externally_visible__))
#define FLATTEN __attribute__((__flatten__))
#define NEVER_INLINE __attribute__((__noinline__))
#define UNUSED __attribute__((__unused__))
#endif
#ifdef DEBUG
# define DEBUG_ONLY /* nop */
#else
# define DEBUG_ONLY UNUSED
#endif
/*
* We need to keep some unreferenced functions from being removed by
* the linker. There is no compile time mechanism for doing this, but
* by putting them in the same section as some other, referenced function
* in the same file, we can keep them around.
*
* So this macro should be used to mark at least one function that is
* referenced, and other functions that are not referenced in the same
* file.
*
* Note: this may not work properly with LTO. We'll revisit when/if we
* move to it.
*/
#ifndef __APPLE__
# define KEEP_SECTION \
__attribute__((__section__(".text.keep")))
#else
# define KEEP_SECTION \
__attribute__((__section__(".text,.text.keep")))
#endif
#if defined(__APPLE__)
// OS X has a macro "isset" defined in this header. Force the include so we can
// make sure the macro gets undef'd. (I think this also applies to BSD, but we
// can cross that road when we come to it.)
# include <sys/param.h>
# ifdef isset
# undef isset
# endif
#endif
//////////////////////////////////////////////////////////////////////
#if defined(__x86_64__)
# if defined(__clang__)
# define DECLARE_FRAME_POINTER(fp) \
ActRec* fp; \
asm volatile("mov %%rbp, %0" : "=r" (fp) ::)
# else
# define DECLARE_FRAME_POINTER(fp) register ActRec* fp asm("rbp");
# endif
#elif defined(_M_X64)
// TODO: FIXME! Without this implemented properly, the JIT
// will fail "pretty spectacularly".
# define DECLARE_FRAME_POINTER(fp) \
always_assert(false); \
register ActRec* fp = nullptr;
#elif defined(__AARCH64EL__)
# if defined(__clang__)
# error Clang implementation not done for ARM
# endif
# define DECLARE_FRAME_POINTER(fp) register ActRec* fp asm("x29");
#elif defined(__powerpc64__)
# if defined(__clang__)
# error Clang implementation not done for PPC64
# endif
# define DECLARE_FRAME_POINTER(fp) register ActRec* fp = (ActRec*) __builtin_frame_address(0);
#else
# error What are the stack and frame pointers called on your architecture?
#endif
//////////////////////////////////////////////////////////////////////
// We reserve the exit status 127 to signal a failure in the
// interpreter. 127 is a valid exit code on all reasonable
// architectures: POSIX requires at least 8 unsigned bits and
// Windows 32 signed bits.
#define HPHP_EXIT_FAILURE 127
//////////////////////////////////////////////////////////////////////
#if FACEBOOK
// Linking in libbfd is a gigantic PITA. If you want this yourself in a non-FB
// build, feel free to define HAVE_LIBBFD and specify the right options to link
// in libbfd.a in the extra C++ options.
#define HAVE_LIBBFD 1
#endif
#ifndef PACKAGE
// The value doesn't matter, but it must be defined before you include
// bfd.h
#define PACKAGE "hhvm"
#endif
//////////////////////////////////////////////////////////////////////
#endif