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