Omit visibility pragmas on Windows (fixes warnings/validate failures)
[ghc-hetmet.git] / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2009
4  *
5  * RTS external APIs.  This file declares everything that the GHC RTS
6  * exposes externally.
7  *
8  * To understand the structure of the RTS headers, see the wiki:
9  *   http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
10  *
11  * ---------------------------------------------------------------------------*/
12
13 #ifndef RTS_H
14 #define RTS_H
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #ifndef IN_STG_CODE
21 #define IN_STG_CODE 0
22 #endif
23 #include "Stg.h"
24
25 #include "HsFFI.h"
26 #include "RtsAPI.h"
27
28 // Turn off inlining when debugging - it obfuscates things
29 #ifdef DEBUG
30 # undef  STATIC_INLINE
31 # define STATIC_INLINE static
32 #endif
33
34 #include "rts/Types.h"
35
36 #if __GNUC__ >= 3
37 /* Assume that a flexible array member at the end of a struct
38  * can be defined thus: T arr[]; */
39 #define FLEXIBLE_ARRAY
40 #else
41 /* Assume that it must be defined thus: T arr[0]; */
42 #define FLEXIBLE_ARRAY 0
43 #endif
44
45 #if __GNUC__ >= 3
46 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
47 #else
48 #define ATTRIBUTE_ALIGNED(n) /*nothing*/
49 #endif
50
51 // Symbols that are extern, but private to the RTS, are declared
52 // with visibility "hidden" to hide them outside the RTS shared
53 // library.
54 #if !defined(mingw32_HOST_OS)
55 #define RTS_PRIVATE  GNUC3_ATTRIBUTE(visibility("hidden"))
56 #else
57 #define RTS_PRIVATE  /* disabled: RTS_PRIVATE */
58 #endif
59
60 #if __GNUC__ > 4
61 #define BEGIN_RTS_PRIVATE #pragma GCC visibility push(hidden)
62 #define END_RTS_PRIVATE   #pragma GCC visibility pop
63 #else
64 #define BEGIN_RTS_PRIVATE /* disabled: BEGIN_RTS_PRIVATE */
65 #define END_RTS_PRIVATE   /* disabled: END_RTS_PRIVATE */
66 #endif
67
68 /* Fix for mingw stat problem (done here so it's early enough) */
69 #ifdef mingw32_HOST_OS
70 #define __MSVCRT__ 1
71 #endif
72
73 /* Needed to get the macro version of errno on some OSs, and also to
74    get prototypes for the _r versions of C library functions. */
75 #ifndef _REENTRANT
76 #define _REENTRANT 1
77 #endif
78
79 /*
80  * We often want to know the size of something in units of an
81  * StgWord... (rounded up, of course!)
82  */
83 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
84
85 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
86
87 /* -----------------------------------------------------------------------------
88    Assertions and Debuggery
89
90    CHECK(p)   evaluates p and terminates with an error if p is false
91    ASSERT(p)  like CHECK(p) if DEBUG is on, otherwise a no-op
92    -------------------------------------------------------------------------- */
93
94 void _assertFail(const char *filename, unsigned int linenum)
95    GNUC3_ATTRIBUTE(__noreturn__);
96
97 #define CHECK(predicate)                        \
98         if (predicate)                          \
99             /*null*/;                           \
100         else                                    \
101             _assertFail(__FILE__, __LINE__)
102
103 #ifndef DEBUG
104 #define ASSERT(predicate) /* nothing */
105 #else
106 #define ASSERT(predicate) CHECK(predicate)
107 #endif /* DEBUG */
108
109 /* 
110  * Use this on the RHS of macros which expand to nothing
111  * to make sure that the macro can be used in a context which
112  * demands a non-empty statement.
113  */
114
115 #define doNothing() do { } while (0)
116
117 #ifdef DEBUG
118 #define USED_IF_DEBUG
119 #define USED_IF_NOT_DEBUG STG_UNUSED
120 #else
121 #define USED_IF_DEBUG STG_UNUSED
122 #define USED_IF_NOT_DEBUG
123 #endif
124
125 #ifdef THREADED_RTS
126 #define USED_IF_THREADS
127 #define USED_IF_NOT_THREADS STG_UNUSED
128 #else
129 #define USED_IF_THREADS STG_UNUSED
130 #define USED_IF_NOT_THREADS
131 #endif
132
133 /*
134  * Getting printf formats right for platform-dependent typedefs
135  */
136 #if SIZEOF_LONG == 8
137 #define FMT_Word64 "lu"
138 #define FMT_Int64  "ld"
139 #else
140 #define FMT_Word64 "llu"
141 #define FMT_Int64  "lld"
142 #endif
143
144 /* -----------------------------------------------------------------------------
145    Include everything STG-ish
146    -------------------------------------------------------------------------- */
147
148 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
149  * come after MachRegs.h, because stdlib.h might define some inline
150  * functions which may only be defined after register variables have
151  * been declared.
152  */
153 #include <stdlib.h>
154
155 #include "rts/Config.h"
156
157 /* Global constaints */
158 #include "rts/Constants.h"
159
160 /* Profiling information */
161 #include "rts/prof/CCS.h"
162 #include "rts/prof/LDV.h"
163
164 /* Parallel information */
165 #include "rts/OSThreads.h"
166 #include "rts/SpinLock.h"
167
168 #include "rts/Messages.h"
169
170 /* Storage format definitions */
171 #include "rts/storage/FunTypes.h"
172 #include "rts/storage/InfoTables.h"
173 #include "rts/storage/Closures.h"
174 #include "rts/storage/Liveness.h"
175 #include "rts/storage/ClosureTypes.h"
176 #include "rts/storage/TSO.h"
177 #include "stg/MiscClosures.h" /* InfoTables, closures etc. defined in the RTS */
178 #include "rts/storage/SMPClosureOps.h"
179 #include "rts/storage/Block.h"
180 #include "rts/storage/ClosureMacros.h"
181 #include "rts/storage/MBlock.h"
182 #include "rts/storage/GC.h"
183
184 /* Other RTS external APIs */
185 #include "rts/Parallel.h"
186 #include "rts/Hooks.h"
187 #include "rts/Signals.h"
188 #include "rts/BlockSignals.h"
189 #include "rts/Hpc.h"
190 #include "rts/Flags.h"
191 #include "rts/Adjustor.h"
192 #include "rts/FileLock.h"
193 #include "rts/Globals.h"
194 #include "rts/IOManager.h"
195 #include "rts/Linker.h"
196 #include "rts/Threads.h"
197 #include "rts/Ticky.h"
198 #include "rts/Timer.h"
199 #include "rts/Stable.h"
200 #include "rts/TTY.h"
201 #include "rts/Utils.h"
202 #include "rts/PrimFloat.h"
203
204 /* Misc stuff without a home */
205 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
206 DLL_IMPORT_RTS extern int    prog_argc;
207 DLL_IMPORT_RTS extern char  *prog_name;
208
209 void stackOverflow(void);
210
211 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
212
213 #ifndef mingw32_HOST_OS
214 int stg_sig_install (int, int, void *);
215 #endif
216
217 /* -----------------------------------------------------------------------------
218    RTS Exit codes
219    -------------------------------------------------------------------------- */
220
221 /* 255 is allegedly used by dynamic linkers to report linking failure */
222 #define EXIT_INTERNAL_ERROR 254
223 #define EXIT_DEADLOCK       253
224 #define EXIT_INTERRUPTED    252
225 #define EXIT_HEAPOVERFLOW   251
226 #define EXIT_KILLED         250
227
228 /* -----------------------------------------------------------------------------
229    Miscellaneous garbage
230    -------------------------------------------------------------------------- */
231
232 /* declarations for runtime flags/values */
233 #define MAX_RTS_ARGS 32
234
235 #ifdef DEBUG
236 #define TICK_VAR(arity) \
237   extern StgInt SLOW_CALLS_##arity; \
238   extern StgInt RIGHT_ARITY_##arity; \
239   extern StgInt TAGGED_PTR_##arity;
240
241 extern StgInt TOTAL_CALLS;
242
243 TICK_VAR(1)
244 TICK_VAR(2)
245 #endif
246
247 /* -----------------------------------------------------------------------------
248    Assertions and Debuggery
249    -------------------------------------------------------------------------- */
250
251 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
252
253 #ifdef DEBUG
254 #if IN_STG_CODE
255 #define IF_DEBUG(c,s)  if (RtsFlags[0].DebugFlags.c) { s; }
256 #else
257 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
258 #endif
259 #else
260 #define IF_DEBUG(c,s)  doNothing()
261 #endif
262
263 #ifdef DEBUG
264 #define DEBUG_ONLY(s) s
265 #else
266 #define DEBUG_ONLY(s) doNothing()
267 #endif
268
269 /* -----------------------------------------------------------------------------
270    Useful macros and inline functions
271    -------------------------------------------------------------------------- */
272
273 #if defined(__GNUC__)
274 #define SUPPORTS_TYPEOF
275 #endif
276
277 #if defined(SUPPORTS_TYPEOF)
278 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
279 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
280 #else
281 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
282 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
283 #endif
284
285 /* -------------------------------------------------------------------------- */
286
287 #ifdef __cplusplus
288 }
289 #endif
290
291 #endif /* RTS_H */