allow build settings to be overriden by adding mk/validate.mk
[ghc-hetmet.git] / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Top-level include file for the RTS itself
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef RTS_H
10 #define RTS_H
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #ifndef IN_STG_CODE
17 #define IN_STG_CODE 0
18 #endif
19 #include "Stg.h"
20
21 // Turn off inlining when debugging - it obfuscates things
22 #ifdef DEBUG
23 # undef  STATIC_INLINE
24 # define STATIC_INLINE static
25 #endif
26
27 #include "RtsTypes.h"
28
29 #if __GNUC__ >= 3
30 /* Assume that a flexible array member at the end of a struct
31  * can be defined thus: T arr[]; */
32 #define FLEXIBLE_ARRAY
33 #else
34 /* Assume that it must be defined thus: T arr[0]; */
35 #define FLEXIBLE_ARRAY 0
36 #endif
37
38 /* Fix for mingw stat problem (done here so it's early enough) */
39 #ifdef mingw32_HOST_OS
40 #define __MSVCRT__ 1
41 #endif
42
43 /* Needed to get the macro version of errno on some OSs, and also to
44    get prototypes for the _r versions of C library functions. */
45 #define _REENTRANT 1
46
47 /*
48  * We often want to know the size of something in units of an
49  * StgWord... (rounded up, of course!)
50  */
51 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
52
53 /* 
54  * It's nice to be able to grep for casts
55  */
56 #define stgCast(ty,e) ((ty)(e))
57
58 /* -----------------------------------------------------------------------------
59    Assertions and Debuggery
60    -------------------------------------------------------------------------- */
61
62 #ifndef DEBUG
63 #define ASSERT(predicate) /* nothing */
64 #else
65
66 extern void _assertFail (const char *, unsigned int);
67
68 #define ASSERT(predicate)                       \
69         if (predicate)                          \
70             /*null*/;                           \
71         else                                    \
72             _assertFail(__FILE__, __LINE__)
73 #endif /* DEBUG */
74
75 /* 
76  * Use this on the RHS of macros which expand to nothing
77  * to make sure that the macro can be used in a context which
78  * demands a non-empty statement.
79  */
80
81 #define doNothing() do { } while (0)
82
83 #ifdef DEBUG
84 #define USED_IF_DEBUG
85 #define USED_IF_NOT_DEBUG STG_UNUSED
86 #else
87 #define USED_IF_DEBUG STG_UNUSED
88 #define USED_IF_NOT_DEBUG
89 #endif
90
91 #ifdef THREADED_RTS
92 #define USED_IF_THREADS
93 #define USED_IF_NOT_THREADS STG_UNUSED
94 #else
95 #define USED_IF_THREADS STG_UNUSED
96 #define USED_IF_NOT_THREADS
97 #endif
98
99 /*
100  * Getting printf formats right for platform-dependent typedefs
101  */
102 #if SIZEOF_LONG == 8
103 #define FMT_Word64 "lu"
104 #define FMT_Int64  "ld"
105 #else
106 #define FMT_Word64 "llu"
107 #define FMT_Int64  "lld"
108 #endif
109
110 /* -----------------------------------------------------------------------------
111    Include everything STG-ish
112    -------------------------------------------------------------------------- */
113
114 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
115  * come after MachRegs.h, because stdlib.h might define some inline
116  * functions which may only be defined after register variables have
117  * been declared.
118  */
119 #include <stdlib.h>
120
121 /* Global constaints */
122 #include "Constants.h"
123
124 /* Profiling information */
125 #include "StgProf.h"
126 #include "StgLdvProf.h"
127
128 /* Storage format definitions */
129 #include "StgFun.h"
130 #include "Closures.h"
131 #include "Liveness.h"
132 #include "ClosureTypes.h"
133 #include "InfoTables.h"
134 #include "TSO.h"
135
136 /* Info tables, closures & code fragments defined in the RTS */
137 #include "StgMiscClosures.h"
138
139 /* Simulated-parallel information */
140 #include "GranSim.h"
141
142 /* Parallel information */
143 #include "Parallel.h"
144 #include "OSThreads.h"
145 #include "SMP.h"
146
147 /* GNU mp library */
148 #if defined(HAVE_FRAMEWORK_GMP)
149 #include <GMP/gmp.h>
150 #else
151 #include "gmp.h"
152 #endif
153
154 /* Macros for STG/C code */
155 #include "Block.h"
156 #include "ClosureMacros.h"
157
158   /* Ticky-ticky counters */
159 #include "TickyCounters.h"
160
161 /* Runtime-system hooks */
162 #include "Hooks.h"
163 #include "RtsMessages.h"
164
165 /* for StablePtr/getStablePtr/deRefStablePtr */
166 #include "Storage.h"
167 #include "Stable.h"
168
169 #include "ieee-flpt.h"
170
171 #include "Signals.h"
172
173 /* Misc stuff without a home */
174 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
175 DLL_IMPORT_RTS extern int    prog_argc;
176 DLL_IMPORT_RTS extern char  *prog_name;
177
178 extern void stackOverflow(void);
179
180 extern void      __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
181 extern void      __decodeFloat  (MP_INT *man, I_ *_exp, StgFloat flt);
182
183 #if defined(WANT_DOTNET_SUPPORT)
184 #include "DNInvoke.h"
185 #endif
186
187 /* Initialising the whole adjustor thunk machinery. */
188 extern void initAdjustor(void);
189
190 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
191
192 /* -----------------------------------------------------------------------------
193    RTS Exit codes
194    -------------------------------------------------------------------------- */
195
196 /* 255 is allegedly used by dynamic linkers to report linking failure */
197 #define EXIT_INTERNAL_ERROR 254
198 #define EXIT_DEADLOCK       253
199 #define EXIT_INTERRUPTED    252
200 #define EXIT_HEAPOVERFLOW   251
201 #define EXIT_KILLED         250
202
203 /* -----------------------------------------------------------------------------
204    Miscellaneous garbage
205    -------------------------------------------------------------------------- */
206
207 /* declarations for runtime flags/values */
208 #define MAX_RTS_ARGS 32
209
210 /* -----------------------------------------------------------------------------
211    Assertions and Debuggery
212    -------------------------------------------------------------------------- */
213
214 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
215
216 /* -----------------------------------------------------------------------------
217    Assertions and Debuggery
218    -------------------------------------------------------------------------- */
219
220 #ifdef DEBUG
221 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
222 #else
223 #define IF_DEBUG(c,s)  doNothing()
224 #endif
225
226 #ifdef DEBUG
227 #define DEBUG_ONLY(s) s
228 #else
229 #define DEBUG_ONLY(s) doNothing()
230 #endif
231
232 #if defined(GRAN) && defined(DEBUG)
233 #define IF_GRAN_DEBUG(c,s)  if (RtsFlags.GranFlags.Debug.c) { s; }
234 #else
235 #define IF_GRAN_DEBUG(c,s)  doNothing()
236 #endif
237
238 #if defined(PAR) && defined(DEBUG)
239 #define IF_PAR_DEBUG(c,s)  if (RtsFlags.ParFlags.Debug.c) { s; }
240 #else
241 #define IF_PAR_DEBUG(c,s)  doNothing()
242 #endif
243
244 /* -----------------------------------------------------------------------------
245    Useful macros and inline functions
246    -------------------------------------------------------------------------- */
247
248 #if defined(__GNUC__)
249 #define SUPPORTS_TYPEOF
250 #endif
251
252 #if defined(SUPPORTS_TYPEOF)
253 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
254 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
255 #else
256 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
257 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
258 #endif
259
260 /* -------------------------------------------------------------------------- */
261
262 #ifdef __cplusplus
263 }
264 #endif
265
266
267 /* krc: I put this here because I don't think
268    it needs to be visible externally.
269    It used to be in StgTicky.h, but I got rid
270    of that. */
271
272 /* -----------------------------------------------------------------------------
273    The StgEntCounter type - needed regardless of TICKY_TICKY
274    -------------------------------------------------------------------------- */
275
276 typedef struct _StgEntCounter {
277   /* Using StgWord for everything, becuase both the C and asm code
278      generators make trouble if you try to pack things tighter */
279     StgWord     registeredp;    /* 0 == no, 1 == yes */
280     StgInt      arity;          /* arity (static info) */
281     StgInt      stk_args;       /* # of args off stack */
282                                 /* (rest of args are in registers) */
283     char        *str;           /* name of the thing */
284     char        *arg_kinds;     /* info about the args types */
285     StgInt      entry_count;    /* Trips to fast entry code */
286     StgInt      allocs;         /* number of allocations by this fun */
287     struct _StgEntCounter *link;/* link to chain them all together */
288 } StgEntCounter;
289
290
291 #endif /* RTS_H */