]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/sys/EfiCdefs.h
Add Socket Libraries.
[mirror_edk2.git] / StdLib / Include / sys / EfiCdefs.h
CommitLineData
2aa62f2b 1/** @file\r
2 Common declarations and definitions for Standard C Library headers.\r
3\r
4 This header consolidates definitions and declarations for compiler specific\r
5 features in one place in order to assist in making the remainder of the\r
6 library as compiler independent as possible.\r
7\r
8 Certain macro and type definitions are required to be provided by several\r
9 different headers. In order to avoid having multiple definitions, and the\r
10 attendant risk of having the definitions get out of sync, they are defined in\r
11 this header.\r
12\r
13 Note that MdePkg/Include/Base.h is automatically included and will bring\r
14 processor architecture specific definitions along with it.\r
15\r
16 Throughout the library, the following macros are used instead of keywords so\r
17 that the library can be easily tuned for different compilers.\r
18 __inline Defined to the appropriate keyword or not defined.\r
19 __func__ Defined to __FUNC__, __FUNCTION__, or NULL as appropriate.\r
d7ce7006 20 __restrict Defined to nothing for VC++ or to restrict for GCC and C99 compliant compilers.\r
2aa62f2b 21\r
22 This file and its contents are inspired by the <sys/cdefs.h> files in Berkeley\r
23 Unix. They have been re-implemented to be specific to the EFI environment.\r
24\r
d7ce7006 25 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
2aa62f2b 26 This program and the accompanying materials are licensed and made available under\r
27 the terms and conditions of the BSD License that accompanies this distribution.\r
28 The full text of the license may be found at\r
d7ce7006 29 http://opensource.org/licenses/bsd-license.\r
2aa62f2b 30\r
31 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
32 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
33\r
34 Portions Copyright (c) 1991, 1993\r
35 The Regents of the University of California. All rights reserved.\r
36\r
37 Portions of this code are derived from software contributed to Berkeley by\r
38 Berkeley Software Design, Inc.\r
39 Redistribution and use in source and binary forms, with or without\r
40 modification, are permitted provided that the following conditions\r
41 are met:\r
42 1. Redistributions of source code must retain the above copyright\r
43 notice, this list of conditions and the following disclaimer.\r
44 2. Redistributions in binary form must reproduce the above copyright\r
45 notice, this list of conditions and the following disclaimer in the\r
46 documentation and/or other materials provided with the distribution.\r
47 3. Neither the name of the University nor the names of its contributors\r
48 may be used to endorse or promote products derived from this software\r
49 without specific prior written permission.\r
50\r
51 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
52 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
53 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
54 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
55 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
56 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
57 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
58 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
59 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
60 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
61 SUCH DAMAGE.\r
62**/\r
63#ifndef _EFI_CDEFS_H\r
64#define _EFI_CDEFS_H\r
65\r
66/*\r
67* Macro to test if we're using a GNU C compiler of a specific vintage\r
68* or later, for e.g. features that appeared in a particular version\r
69* of GNU C. Usage:\r
70*\r
71* #if __GNUC_PREREQ__(major, minor)\r
72* ...cool feature...\r
73* #else\r
74* ...delete feature...\r
75* #endif\r
76*/\r
77#ifdef __GNUC__\r
78#define __GNUC_PREREQ__(x, y) \\r
79((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \\r
80 (__GNUC__ > (x)))\r
81\r
82#define DONT_USE_STRONG_WEAK_ALIAS 1\r
83\r
84#else\r
85#define __GNUC_PREREQ__(x, y) 0\r
86#endif\r
87\r
88#include <sys/featuretest.h>\r
89//#include <machine/_EfiCdefs.h>\r
90#ifdef __PE32__\r
91#include <sys/_EfiCdefs_PE32.h>\r
92#else\r
93#include <sys/cdefs_aout.h>\r
94#endif\r
95\r
96/* NULL is defined by the automatic inclusion of Base.h by the build tools. */\r
97\r
98#ifdef __GNUC__\r
99 #define _EFI_SIZE_T_ __SIZE_TYPE__ /* sizeof() */\r
100 #define _EFI_WCHAR_T __WCHAR_TYPE__\r
101 #define _EFI_WINT_T __WINT_TYPE__\r
102 //#define _EFI_WINT_MIN (0)\r
103 //#define _EFI_WINT_MAX (0xFFFF)\r
104 #define _EFI_PTRDIFF_T_ __PTRDIFF_TYPE__ /* ptr1 - ptr2 --- Must be same size as size_t */\r
105#else\r
106#define _EFI_SIZE_T_ UINTN /* sizeof() */\r
107#define _EFI_WCHAR_T UINT16\r
108#define _EFI_WINT_T INT32\r
109 //#define _EFI_WINT_MIN (-2147483647) /* wint_t */\r
110 //#define _EFI_WINT_MAX ( 2147483647) /* wint_t */\r
111 #define _EFI_PTRDIFF_T_ INTN /* ptr1 - ptr2 --- Must be same size as size_t */\r
112#endif /* __GNUC__ */\r
113\r
114#define _EFI_CLOCK_T UINT64\r
115#define _EFI_TIME_T INT32\r
116\r
117#if defined(__cplusplus)\r
118#define __BEGIN_DECLS extern "C" {\r
119#define __END_DECLS }\r
120#define __static_cast(x,y) static_cast<x>(y)\r
121#else\r
122#define __BEGIN_DECLS\r
123#define __END_DECLS\r
124#define __static_cast(x,y) (x)y\r
125#endif\r
126\r
127 /*\r
128 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.\r
129 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.\r
130 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces\r
131 * in between its arguments. __CONCAT can also concatenate double-quoted\r
132 * strings produced by the __STRING macro, but this only works with ANSI C.\r
133 */\r
134\r
135#define ___STRING(x) __STRING(x)\r
136#define ___CONCAT(x,y) __CONCAT(x,y)\r
137#define __CONCAT(x,y) x ## y\r
138#define __STRING(x) #x\r
139\r
140#define __const CONST\r
141#define __signed signed\r
142#define __volatile volatile\r
143\r
144#if __STDC__ || defined(__cplusplus)\r
145 #if defined(__cplusplus)\r
146 #define __inline inline /* convert to C++ keyword */\r
147 #else\r
148 #if defined(_MSC_VER) || (!defined(__GNUC__) && !defined(__lint__))\r
149 #define __inline /* delete C99 keyword */\r
150 #endif /* !__GNUC__ && !__lint__ */\r
151 #endif /* !__cplusplus */\r
152#endif /* !(__STDC__ || __cplusplus) */\r
153\r
154/* Used in NetBSD for internal auditing of the source tree. */\r
155#define __aconst\r
156\r
157 /*\r
158 * The following macro is used to remove const cast-away warnings\r
159 * from gcc -Wcast-qual; it should be used with caution because it\r
160 * can hide valid errors; in particular most valid uses are in\r
161 * situations where the API requires it, not to cast away string\r
162 * constants. We don't use *intptr_t on purpose here and we are\r
163 * explicit about unsigned long so that we don't have additional\r
164 * dependencies.\r
165 */\r
166#define __UNCONST(a) ((void *)(a))\r
167//#define __UNCONST(a) ((void *)(PHYSICAL_ADDRESS)(const void *)(a))\r
168\r
169 /*\r
170 * The following macro is used to remove the volatile cast-away warnings\r
171 * from gcc -Wcast-qual; as above it should be used with caution\r
172 * because it can hide valid errors or warnings. Valid uses include\r
173 * making it possible to pass a volatile pointer to memset().\r
174 * For the same reasons as above, we use unsigned long and not intptr_t.\r
175 */\r
176#define __UNVOLATILE(a) ((void *)(PHYSICAL_ADDRESS)(volatile void *)(a))\r
177\r
178 /*\r
179 * GCC2 provides __extension__ to suppress warnings for various GNU C\r
180 * language extensions under "-ansi -pedantic".\r
181 */\r
182#if !__GNUC_PREREQ__(2, 0)\r
183#define __extension__ /* delete __extension__ if non-gcc or gcc1 */\r
184#endif\r
185\r
186 /*\r
187 * GCC1 and some versions of GCC2 declare dead (non-returning) and\r
188 * pure (no side effects) functions using "volatile" and "const";\r
189 * unfortunately, these then cause warnings under "-ansi -pedantic".\r
190 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of\r
191 * these work for GNU C++ (modulo a slight glitch in the C++ grammar\r
192 * in the distribution version of 2.5.5).\r
193 */\r
194#if !__GNUC_PREREQ__(2, 5)\r
195#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */\r
196#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\r
197#define __dead __volatile\r
198#define __pure __const\r
199#endif\r
200#endif\r
201\r
202 /* Delete pseudo-keywords wherever they are not available or needed. */\r
203#ifndef __dead\r
204#define __dead\r
205#define __pure\r
206#endif\r
207\r
208#if __GNUC_PREREQ__(2, 7)\r
209#define __unused __attribute__((__unused__))\r
210#define __noreturn __attribute__((__noreturn__))\r
211#else\r
212#define __unused /* delete */\r
213#define __noreturn /* delete */\r
214#endif\r
215\r
216#if __GNUC_PREREQ__(3, 1)\r
217#define __used __attribute__((__used__))\r
218#else\r
219#define __used __unused\r
220#endif\r
221\r
222#if __GNUC_PREREQ__(2, 7)\r
223#define __packed __attribute__((__packed__))\r
224#define __aligned(x) __attribute__((__aligned__(x)))\r
225#define __section(x) __attribute__((__section__(x)))\r
226#elif defined(__lint__)\r
227#define __packed /* delete */\r
228#define __aligned(x) /* delete */\r
229#define __section(x) /* delete */\r
230#else\r
231#define __packed error: no __packed for this compiler\r
232#define __aligned(x) error: no __aligned for this compiler\r
233#define __section(x) error: no __section for this compiler\r
234#endif\r
235\r
236/*\r
237* C99 defines the restrict type qualifier keyword, which was made available\r
238* in GCC 2.92.\r
239*/\r
240#if __STDC_VERSION__ >= 199901L\r
241 #define __restrict restrict\r
242#else\r
243 #if defined(_MSC_VER) || !__GNUC_PREREQ__(2, 92)\r
244 #define __restrict /* delete __restrict when not supported */\r
245 #endif\r
246#endif\r
247\r
248/*\r
249* C99 defines __func__ predefined identifier, which was made available\r
250* in GCC 2.95.\r
251*/\r
252#if !(__STDC_VERSION__ >= 199901L)\r
253 #if defined(_MSC_VER)\r
254 #define __func__ __FUNCTION__ /* Use the MS-specific predefined macro */\r
255 #elif __GNUC_PREREQ__(2, 6)\r
256 #define __func__ __PRETTY_FUNCTION__\r
257 #elif __GNUC_PREREQ__(2, 4)\r
258 #define __func__ __FUNCTION__\r
259 #else\r
260 #define __func__ ""\r
261 #endif\r
262#endif /* !(__STDC_VERSION__ >= 199901L) */\r
263\r
d7ce7006 264#define __RENAME(x)\r
2aa62f2b 265\r
266 /*\r
267 * A barrier to stop the optimizer from moving code or assume live\r
268 * register values. This is gcc specific, the version is more or less\r
269 * arbitrary, might work with older compilers.\r
270 */\r
271#if __GNUC_PREREQ__(2, 95)\r
272#define __insn_barrier() __asm __volatile("":::"memory")\r
273#else\r
274#define __insn_barrier() /* */\r
275#endif\r
276\r
277 /*\r
278 * GNU C version 2.96 adds explicit branch prediction so that\r
279 * the CPU back-end can hint the processor and also so that\r
280 * code blocks can be reordered such that the predicted path\r
281 * sees a more linear flow, thus improving cache behavior, etc.\r
282 *\r
283 * The following two macros provide us with a way to use this\r
284 * compiler feature. Use __predict_true() if you expect the expression\r
285 * to evaluate to true, and __predict_false() if you expect the\r
286 * expression to evaluate to false.\r
287 *\r
288 * A few notes about usage:\r
289 *\r
290 * * Generally, __predict_false() error condition checks (unless\r
291 * you have some _strong_ reason to do otherwise, in which case\r
292 * document it), and/or __predict_true() `no-error' condition\r
293 * checks, assuming you want to optimize for the no-error case.\r
294 *\r
295 * * Other than that, if you don't know the likelihood of a test\r
296 * succeeding from empirical or other `hard' evidence, don't\r
297 * make predictions.\r
298 *\r
299 * * These are meant to be used in places that are run `a lot'.\r
300 * It is wasteful to make predictions in code that is run\r
301 * seldomly (e.g. at subsystem initialization time) as the\r
302 * basic block reordering that this affects can often generate\r
303 * larger code.\r
304 */\r
305#if __GNUC_PREREQ__(2, 96)\r
306#define __predict_true(exp) __builtin_expect((exp) != 0, 1)\r
307#define __predict_false(exp) __builtin_expect((exp) != 0, 0)\r
308#else\r
309#define __predict_true(exp) (exp)\r
310#define __predict_false(exp) (exp)\r
311#endif\r
312\r
313/* find least significant bit that is set */\r
314#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))\r
315\r
316#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))\r
317#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))\r
318#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))\r
319\r
320#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */\r
321\r
322 /* VC++, by default, defines wchar_t as an intrinsic type, equivalent to\r
323 unsigned short. This conflicts which Standard C Library\r
324 implementations which try to define wchar_t.\r
325 Make sure that this behavior has been turned off by using\r
326 /Zc:wchar_t- on the command line.\r
327 */\r
328 #ifdef _NATIVE_WCHAR_T_DEFINED\r
329 #error You must specify /Zc:wchar_t- to the compiler to turn off intrinsic wchar_t.\r
330 #endif\r
331\r
332 // Keep compiler quiet about casting from smaller to larger types\r
333 #pragma warning ( disable : 4306 )\r
334#endif /* defined(_MSC_VER) */\r
335extern int _fltused; // VC++ requires this if you use floating point. KEEP for all compilers.\r
336\r
337#define _Bool BOOLEAN\r
338#define _DIAGASSERT(e)\r
339\r
340// Types used to replace long so that it will have constant length regardless of compiler.\r
341typedef INT32 EFI_LONG_T; // Equivalent to long in VS200?\r
342typedef UINT32 EFI_ULONG_T; // Equivalent to unsigned long in VS200?\r
343typedef INTN LONGN;\r
344typedef UINTN ULONGN;\r
345typedef INT32 LONG32;\r
346typedef UINT32 ULONG32;\r
347typedef INT64 LONG64;\r
348typedef UINT64 ULONG64;\r
349\r
2aa62f2b 350#endif /* _EFI_CDEFS_H */\r