Move serialize functions to variable-serializer.cpp
[hiphop-php.git] / hphp / util / portability.h
blob0df8ffbbaa33824787f41b0a16f6a23f9efbafb9
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_PORTABILITY_H_
17 #define incl_HPHP_PORTABILITY_H_
19 #include <folly/Likely.h> // defining LIKELY/UNLIKELY is part of this header
20 #include <folly/CPortability.h> // defining FOLLY_DISABLE_ADDRESS_SANITIZER
22 //////////////////////////////////////////////////////////////////////
25 * Various macros to make certain things conditional on either
26 * compiler or architecture.
28 * Currently we don't *really* compile on anything other than gcc or
29 * sometimes clang, and there are some parts of the code using
30 * __attribute__ stuff directly, but some things go through these
31 * macros to make it maybe easier to change later.
34 //////////////////////////////////////////////////////////////////////
36 // TODO: does clang define __GNUC__ ?
37 #ifndef __GNUC__
38 # define __attribute__(x)
39 #endif
41 //////////////////////////////////////////////////////////////////////
43 #ifdef ATTRIBUTE_UNUSED
44 # undef ATTRIBUTE_UNUSED
45 #endif
46 #ifdef ATTRIBUTE_NORETURN
47 # undef ATTRIBUTE_NORETURN
48 #endif
49 #ifdef ATTRIBUTE_PRINTF
50 # undef ATTRIBUTE_PRINTF
51 #endif
53 #ifdef _MSC_VER
54 #define ATTRIBUTE_NORETURN __declspec(noreturn)
55 #define ATTRIBUTE_PRINTF(a1, a2)
56 #ifndef __thread
57 # define __thread __declspec(thread)
58 #endif
59 #define ATTRIBUTE_UNUSED
61 #define ALWAYS_INLINE __forceinline
62 #define EXTERNALLY_VISIBLE
63 #define FLATTEN
64 #define NEVER_INLINE __declspec(noinline)
65 #define UNUSED
66 #else
67 #define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
68 #define ATTRIBUTE_PRINTF(a1, a2) \
69 __attribute__((__format__ (__printf__, a1, a2)))
70 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
72 #define ALWAYS_INLINE inline __attribute__((__always_inline__))
73 #define EXTERNALLY_VISIBLE __attribute__((__externally_visible__))
74 #define FLATTEN __attribute__((__flatten__))
75 #define NEVER_INLINE __attribute__((__noinline__))
76 #define UNUSED __attribute__((__unused__))
77 #endif
79 #ifdef DEBUG
80 # define DEBUG_ONLY /* nop */
81 #else
82 # define DEBUG_ONLY UNUSED
83 #endif
86 * We need to keep some unreferenced functions from being removed by
87 * the linker. There is no compile time mechanism for doing this, but
88 * by putting them in the same section as some other, referenced function
89 * in the same file, we can keep them around.
91 * So this macro should be used to mark at least one function that is
92 * referenced, and other functions that are not referenced in the same
93 * file.
95 * Note: this may not work properly with LTO. We'll revisit when/if we
96 * move to it.
98 #ifndef __APPLE__
99 # define KEEP_SECTION \
100 __attribute__((__section__(".text.keep")))
101 #else
102 # define KEEP_SECTION \
103 __attribute__((__section__(".text,.text.keep")))
104 #endif
106 #if defined(__APPLE__)
107 // OS X has a macro "isset" defined in this header. Force the include so we can
108 // make sure the macro gets undef'd. (I think this also applies to BSD, but we
109 // can cross that road when we come to it.)
110 # include <sys/param.h>
111 # ifdef isset
112 # undef isset
113 # endif
114 #endif
116 //////////////////////////////////////////////////////////////////////
118 #if defined(__x86_64__)
120 # if defined(__clang__)
121 # define DECLARE_FRAME_POINTER(fp) \
122 ActRec* fp; \
123 asm volatile("mov %%rbp, %0" : "=r" (fp) ::)
124 # else
125 # define DECLARE_FRAME_POINTER(fp) register ActRec* fp asm("rbp");
126 # endif
128 #elif defined(__AARCH64EL__)
130 # if defined(__clang__)
131 # error Clang implementation not done for ARM
132 # endif
133 # define DECLARE_FRAME_POINTER(fp) register ActRec* fp asm("x29");
135 #elif defined(__powerpc64__)
137 # if defined(__clang__)
138 # error Clang implementation not done for PPC64
139 # endif
140 # define DECLARE_FRAME_POINTER(fp) register ActRec* fp = (ActRec*) __builtin_frame_address(0);
142 #else
144 # error What are the stack and frame pointers called on your architecture?
146 #endif
148 //////////////////////////////////////////////////////////////////////
150 // We reserve the exit status 127 to signal a failure in the
151 // interpreter. 127 is a valid exit code on all reasonable
152 // architectures: POSIX requires at least 8 unsigned bits and
153 // Windows 32 signed bits.
154 #define HPHP_EXIT_FAILURE 127
156 //////////////////////////////////////////////////////////////////////
158 #if FACEBOOK
159 // Linking in libbfd is a gigantic PITA. If you want this yourself in a non-FB
160 // build, feel free to define HAVE_LIBBFD and specify the right options to link
161 // in libbfd.a in the extra C++ options.
162 #define HAVE_LIBBFD 1
163 #endif
165 #ifndef PACKAGE
166 // The value doesn't matter, but it must be defined before you include
167 // bfd.h
168 #define PACKAGE "hhvm"
169 #endif
171 //////////////////////////////////////////////////////////////////////
173 #endif