Fix incorrectly hidden RTS symbols
[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 /* Fix for mingw stat problem (done here so it's early enough) */
52 #ifdef mingw32_HOST_OS
53 #define __MSVCRT__ 1
54 #endif
55
56 /* Needed to get the macro version of errno on some OSs, and also to
57    get prototypes for the _r versions of C library functions. */
58 #ifndef _REENTRANT
59 #define _REENTRANT 1
60 #endif
61
62 /*
63  * We often want to know the size of something in units of an
64  * StgWord... (rounded up, of course!)
65  */
66 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
67
68 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
69
70 /* -----------------------------------------------------------------------------
71    Assertions and Debuggery
72
73    CHECK(p)   evaluates p and terminates with an error if p is false
74    ASSERT(p)  like CHECK(p) if DEBUG is on, otherwise a no-op
75    -------------------------------------------------------------------------- */
76
77 void _assertFail(const char *filename, unsigned int linenum)
78    GNUC3_ATTRIBUTE(__noreturn__);
79
80 #define CHECK(predicate)                        \
81         if (predicate)                          \
82             /*null*/;                           \
83         else                                    \
84             _assertFail(__FILE__, __LINE__)
85
86 #ifndef DEBUG
87 #define ASSERT(predicate) /* nothing */
88 #else
89 #define ASSERT(predicate) CHECK(predicate)
90 #endif /* DEBUG */
91
92 /* 
93  * Use this on the RHS of macros which expand to nothing
94  * to make sure that the macro can be used in a context which
95  * demands a non-empty statement.
96  */
97
98 #define doNothing() do { } while (0)
99
100 #ifdef DEBUG
101 #define USED_IF_DEBUG
102 #define USED_IF_NOT_DEBUG STG_UNUSED
103 #else
104 #define USED_IF_DEBUG STG_UNUSED
105 #define USED_IF_NOT_DEBUG
106 #endif
107
108 #ifdef THREADED_RTS
109 #define USED_IF_THREADS
110 #define USED_IF_NOT_THREADS STG_UNUSED
111 #else
112 #define USED_IF_THREADS STG_UNUSED
113 #define USED_IF_NOT_THREADS
114 #endif
115
116 /*
117  * Getting printf formats right for platform-dependent typedefs
118  */
119 #if SIZEOF_LONG == 8
120 #define FMT_Word64 "lu"
121 #define FMT_Int64  "ld"
122 #else
123 #define FMT_Word64 "llu"
124 #define FMT_Int64  "lld"
125 #endif
126
127 /* -----------------------------------------------------------------------------
128    Include everything STG-ish
129    -------------------------------------------------------------------------- */
130
131 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
132  * come after MachRegs.h, because stdlib.h might define some inline
133  * functions which may only be defined after register variables have
134  * been declared.
135  */
136 #include <stdlib.h>
137
138 #include "rts/Config.h"
139
140 /* Global constaints */
141 #include "rts/Constants.h"
142
143 /* Profiling information */
144 #include "rts/prof/CCS.h"
145 #include "rts/prof/LDV.h"
146
147 /* Parallel information */
148 #include "rts/OSThreads.h"
149 #include "rts/SpinLock.h"
150
151 #include "rts/Messages.h"
152
153 /* Storage format definitions */
154 #include "rts/storage/FunTypes.h"
155 #include "rts/storage/InfoTables.h"
156 #include "rts/storage/Closures.h"
157 #include "rts/storage/Liveness.h"
158 #include "rts/storage/ClosureTypes.h"
159 #include "rts/storage/TSO.h"
160 #include "stg/MiscClosures.h" /* InfoTables, closures etc. defined in the RTS */
161 #include "rts/storage/SMPClosureOps.h"
162 #include "rts/storage/Block.h"
163 #include "rts/storage/ClosureMacros.h"
164 #include "rts/storage/MBlock.h"
165 #include "rts/storage/GC.h"
166
167 /* Other RTS external APIs */
168 #include "rts/Parallel.h"
169 #include "rts/Hooks.h"
170 #include "rts/Signals.h"
171 #include "rts/BlockSignals.h"
172 #include "rts/Hpc.h"
173 #include "rts/Flags.h"
174 #include "rts/Adjustor.h"
175 #include "rts/FileLock.h"
176 #include "rts/Globals.h"
177 #include "rts/IOManager.h"
178 #include "rts/Linker.h"
179 #include "rts/Threads.h"
180 #include "rts/Ticky.h"
181 #include "rts/Timer.h"
182 #include "rts/Stable.h"
183 #include "rts/TTY.h"
184 #include "rts/Utils.h"
185 #include "rts/PrimFloat.h"
186
187 /* Misc stuff without a home */
188 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
189 DLL_IMPORT_RTS extern int    prog_argc;
190 DLL_IMPORT_RTS extern char  *prog_name;
191
192 void stackOverflow(void);
193
194 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
195
196 #ifndef mingw32_HOST_OS
197 int stg_sig_install (int, int, void *);
198 #endif
199
200 /* -----------------------------------------------------------------------------
201    RTS Exit codes
202    -------------------------------------------------------------------------- */
203
204 /* 255 is allegedly used by dynamic linkers to report linking failure */
205 #define EXIT_INTERNAL_ERROR 254
206 #define EXIT_DEADLOCK       253
207 #define EXIT_INTERRUPTED    252
208 #define EXIT_HEAPOVERFLOW   251
209 #define EXIT_KILLED         250
210
211 /* -----------------------------------------------------------------------------
212    Miscellaneous garbage
213    -------------------------------------------------------------------------- */
214
215 /* declarations for runtime flags/values */
216 #define MAX_RTS_ARGS 32
217
218 #ifdef DEBUG
219 #define TICK_VAR(arity) \
220   extern StgInt SLOW_CALLS_##arity; \
221   extern StgInt RIGHT_ARITY_##arity; \
222   extern StgInt TAGGED_PTR_##arity;
223
224 extern StgInt TOTAL_CALLS;
225
226 TICK_VAR(1)
227 TICK_VAR(2)
228 #endif
229
230 /* -----------------------------------------------------------------------------
231    Assertions and Debuggery
232    -------------------------------------------------------------------------- */
233
234 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
235
236 #ifdef DEBUG
237 #if IN_STG_CODE
238 #define IF_DEBUG(c,s)  if (RtsFlags[0].DebugFlags.c) { s; }
239 #else
240 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
241 #endif
242 #else
243 #define IF_DEBUG(c,s)  doNothing()
244 #endif
245
246 #ifdef DEBUG
247 #define DEBUG_ONLY(s) s
248 #else
249 #define DEBUG_ONLY(s) doNothing()
250 #endif
251
252 /* -----------------------------------------------------------------------------
253    Useful macros and inline functions
254    -------------------------------------------------------------------------- */
255
256 #if defined(__GNUC__)
257 #define SUPPORTS_TYPEOF
258 #endif
259
260 #if defined(SUPPORTS_TYPEOF)
261 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
262 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
263 #else
264 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
265 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
266 #endif
267
268 /* -------------------------------------------------------------------------- */
269
270 #ifdef __cplusplus
271 }
272 #endif
273
274 #endif /* RTS_H */