1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Top-level include file for the RTS itself
7 * ---------------------------------------------------------------------------*/
21 // Turn off inlining when debugging - it obfuscates things
24 # define STATIC_INLINE static
30 /* Assume that a flexible array member at the end of a struct
31 * can be defined thus: T arr[]; */
32 #define FLEXIBLE_ARRAY
34 /* Assume that it must be defined thus: T arr[0]; */
35 #define FLEXIBLE_ARRAY 0
38 /* Fix for mingw stat problem (done here so it's early enough) */
39 #ifdef mingw32_HOST_OS
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. */
48 * We often want to know the size of something in units of an
49 * StgWord... (rounded up, of course!)
51 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
54 * It's nice to be able to grep for casts
56 #define stgCast(ty,e) ((ty)(e))
58 /* -----------------------------------------------------------------------------
59 Assertions and Debuggery
60 -------------------------------------------------------------------------- */
63 #define ASSERT(predicate) /* nothing */
66 extern void _assertFail (const char *, unsigned int);
68 #define ASSERT(predicate) \
72 _assertFail(__FILE__, __LINE__)
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.
81 #define doNothing() do { } while (0)
85 #define USED_IF_NOT_DEBUG STG_UNUSED
87 #define USED_IF_DEBUG STG_UNUSED
88 #define USED_IF_NOT_DEBUG
92 #define USED_IF_THREADS
93 #define USED_IF_NOT_THREADS STG_UNUSED
95 #define USED_IF_THREADS STG_UNUSED
96 #define USED_IF_NOT_THREADS
100 * Getting printf formats right for platform-dependent typedefs
103 #define FMT_Word64 "lu"
104 #define FMT_Int64 "ld"
106 #define FMT_Word64 "llu"
107 #define FMT_Int64 "lld"
110 /* -----------------------------------------------------------------------------
111 Include everything STG-ish
112 -------------------------------------------------------------------------- */
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
121 /* Global constaints */
122 #include "Constants.h"
124 /* Profiling information */
126 #include "StgLdvProf.h"
128 /* Storage format definitions */
130 #include "Closures.h"
131 #include "Liveness.h"
132 #include "ClosureTypes.h"
133 #include "InfoTables.h"
136 /* Info tables, closures & code fragments defined in the RTS */
137 #include "StgMiscClosures.h"
139 /* Simulated-parallel information */
142 /* Parallel information */
143 #include "Parallel.h"
144 #include "OSThreads.h"
150 /* Macros for STG/C code */
152 #include "ClosureMacros.h"
154 /* Ticky-ticky counters */
155 #include "TickyCounters.h"
157 /* Runtime-system hooks */
159 #include "RtsMessages.h"
161 /* for StablePtr/getStablePtr/deRefStablePtr */
165 #include "ieee-flpt.h"
169 /* Misc stuff without a home */
170 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
171 DLL_IMPORT_RTS extern int prog_argc;
172 DLL_IMPORT_RTS extern char *prog_name;
174 extern void stackOverflow(void);
176 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
177 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
179 #if defined(WANT_DOTNET_SUPPORT)
180 #include "DNInvoke.h"
183 /* Initialising the whole adjustor thunk machinery. */
184 extern void initAdjustor(void);
186 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
188 /* -----------------------------------------------------------------------------
190 -------------------------------------------------------------------------- */
192 /* 255 is allegedly used by dynamic linkers to report linking failure */
193 #define EXIT_INTERNAL_ERROR 254
194 #define EXIT_DEADLOCK 253
195 #define EXIT_INTERRUPTED 252
196 #define EXIT_HEAPOVERFLOW 251
197 #define EXIT_KILLED 250
199 /* -----------------------------------------------------------------------------
200 Miscellaneous garbage
201 -------------------------------------------------------------------------- */
203 /* declarations for runtime flags/values */
204 #define MAX_RTS_ARGS 32
206 /* -----------------------------------------------------------------------------
207 Assertions and Debuggery
208 -------------------------------------------------------------------------- */
210 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
212 /* -----------------------------------------------------------------------------
213 Assertions and Debuggery
214 -------------------------------------------------------------------------- */
217 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
219 #define IF_DEBUG(c,s) doNothing()
223 #define DEBUG_ONLY(s) s
225 #define DEBUG_ONLY(s) doNothing()
228 #if defined(GRAN) && defined(DEBUG)
229 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
231 #define IF_GRAN_DEBUG(c,s) doNothing()
234 #if defined(PAR) && defined(DEBUG)
235 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
237 #define IF_PAR_DEBUG(c,s) doNothing()
240 /* -----------------------------------------------------------------------------
241 Useful macros and inline functions
242 -------------------------------------------------------------------------- */
244 #if defined(__GNUC__)
245 #define SUPPORTS_TYPEOF
248 #if defined(SUPPORTS_TYPEOF)
249 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
250 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
252 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
253 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
256 /* -------------------------------------------------------------------------- */
263 /* krc: I put this here because I don't think
264 it needs to be visible externally.
265 It used to be in StgTicky.h, but I got rid
268 /* -----------------------------------------------------------------------------
269 The StgEntCounter type - needed regardless of TICKY_TICKY
270 -------------------------------------------------------------------------- */
272 typedef struct _StgEntCounter {
273 /* krc: StgWord32, not StgWord16, in order to match the code
274 generator, which doesn't generate anything of that type. */
275 StgWord32 registeredp; /* 0 == no, 1 == yes */
276 StgWord32 arity; /* arity (static info) */
277 StgWord32 stk_args; /* # of args off stack */
278 /* (rest of args are in registers) */
279 char *str; /* name of the thing */
280 char *arg_kinds; /* info about the args types */
281 StgInt entry_count; /* Trips to fast entry code */
282 StgInt allocs; /* number of allocations by this fun */
283 struct _StgEntCounter *link;/* link to chain them all together */