Validator: print message for unsafe indirects
[nativeclient.git] / include / portability.h
blob265d21bd5447534a595755c0ef4c45473c57c036
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _PORTABILITY_H
33 #define _PORTABILITY_H
35 #include <stdlib.h>
37 #if NACL_WINDOWS
38 # include <malloc.h>
39 # include "win/port_win.h"
40 #else
41 # include <sys/types.h>
42 # include <stdint.h>
43 #endif /*NACL_WINDOWS*/
45 #if NACL_OSX
46 #include "osx/port_osx.h"
47 #endif
49 // MSVC supports "inline" only in C++
50 #if NACL_WINDOWS
51 # define INLINE __inline
52 #else
53 # define INLINE inline
54 #endif
57 #if NACL_WINDOWS
58 # define DLLEXPORT __declspec(dllexport)
59 #elif NACL_OSX
60 # define DLLEXPORT
61 #elif NACL_LINUX
62 # define DLLEXPORT __attribute__ ((visibility("default")))
63 #else
64 # error "what platform?"
65 #endif
68 #if NACL_WINDOWS
69 # define UNREFERENCED_PARAMETER(P) (P)
70 #else
71 # define UNREFERENCED_PARAMETER(P) do { ; } while (0)
72 #endif
74 #if NACL_WINDOWS
75 # define NORETURN __declspec(noreturn)
76 #else
77 # define NORETURN __attribute__((noreturn)) /* assumes gcc */
78 # define _cdecl /* empty */
79 #endif
81 #if NACL_WINDOWS
82 # define THREAD __declspec(thread)
83 #else
84 # define THREAD __thread
85 # define WINAPI
86 #endif
89 Per C99 7.8.14, define __STDC_CONSTANT_MACROS before including <stdint.h>
90 to get the INTn_C and UINTn_C macros for integer constants. It's difficult
91 to guarantee any specific ordering of header includes, so it's difficult to
92 guarantee that the INTn_C macros can be defined by including <stdint.h> at
93 any specific point. Provide GG_INTn_C macros instead.
96 #define GG_INT8_C(x) (x)
97 #define GG_INT16_C(x) (x)
98 #define GG_INT32_C(x) (x)
99 #define GG_INT64_C(x) GG_LONGLONG(x)
101 #define GG_UINT8_C(x) (x ## U)
102 #define GG_UINT16_C(x) (x ## U)
103 #define GG_UINT32_C(x) (x ## U)
104 #define GG_UINT64_C(x) GG_ULONGLONG(x)
106 #if NACL_WINDOWS
107 #define SNPRINTF _snprintf
108 #else
109 #define SNPRINTF snprintf
110 #endif
113 * printf macros for size_t, in the style of inttypes.h. this is
114 * needed since the windows compiler does not understand %zd etc.
116 #if NACL_WINDOWS
117 # define __PRIS_PREFIX
118 #else
119 # define __PRIS_PREFIX "z"
120 #endif
122 #define PRIdS __PRIS_PREFIX "d"
123 #define PRIxS __PRIS_PREFIX "x"
124 #define PRIuS __PRIS_PREFIX "u"
125 #define PRIXS __PRIS_PREFIX "X"
126 #define PRIoS __PRIS_PREFIX "o"
128 #endif // _PORTABILITY_H