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"
111 * Macros for untagging and retagging closure pointers
112 * For more information look at the comments in Cmm.h
115 static inline StgWord
116 GET_CLOSURE_TAG(StgClosure * p)
118 return (StgWord)p & TAG_MASK;
121 static inline StgClosure *
122 UNTAG_CLOSURE(StgClosure * p)
124 return (StgClosure*)((StgWord)p & ~TAG_MASK);
127 static inline StgClosure *
128 TAG_CLOSURE(StgWord tag,StgClosure * p)
130 return (StgClosure*)((StgWord)p | tag);
133 /* -----------------------------------------------------------------------------
134 Include everything STG-ish
135 -------------------------------------------------------------------------- */
137 /* System headers: stdlib.h is eeded so that we can use NULL. It must
138 * come after MachRegs.h, because stdlib.h might define some inline
139 * functions which may only be defined after register variables have
144 /* Global constaints */
145 #include "Constants.h"
147 /* Profiling information */
149 #include "StgLdvProf.h"
151 /* Storage format definitions */
153 #include "Closures.h"
154 #include "Liveness.h"
155 #include "ClosureTypes.h"
156 #include "InfoTables.h"
159 /* Info tables, closures & code fragments defined in the RTS */
160 #include "StgMiscClosures.h"
162 /* Simulated-parallel information */
165 /* Parallel information */
166 #include "Parallel.h"
167 #include "OSThreads.h"
171 #if defined(HAVE_FRAMEWORK_GMP)
177 /* Macros for STG/C code */
179 #include "ClosureMacros.h"
181 /* Ticky-ticky counters */
182 #include "TickyCounters.h"
184 /* Runtime-system hooks */
186 #include "RtsMessages.h"
188 /* for StablePtr/getStablePtr/deRefStablePtr */
192 #include "ieee-flpt.h"
196 /* Misc stuff without a home */
197 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
198 DLL_IMPORT_RTS extern int prog_argc;
199 DLL_IMPORT_RTS extern char *prog_name;
201 extern void stackOverflow(void);
203 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
204 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
206 #if defined(WANT_DOTNET_SUPPORT)
207 #include "DNInvoke.h"
210 /* Initialising the whole adjustor thunk machinery. */
211 extern void initAdjustor(void);
213 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
215 /* -----------------------------------------------------------------------------
217 -------------------------------------------------------------------------- */
219 /* 255 is allegedly used by dynamic linkers to report linking failure */
220 #define EXIT_INTERNAL_ERROR 254
221 #define EXIT_DEADLOCK 253
222 #define EXIT_INTERRUPTED 252
223 #define EXIT_HEAPOVERFLOW 251
224 #define EXIT_KILLED 250
226 /* -----------------------------------------------------------------------------
227 Miscellaneous garbage
228 -------------------------------------------------------------------------- */
230 /* declarations for runtime flags/values */
231 #define MAX_RTS_ARGS 32
234 #define TICK_VAR(arity) \
235 extern StgInt SLOW_CALLS_##arity; \
236 extern StgInt RIGHT_ARITY_##arity; \
237 extern StgInt TAGGED_PTR_##arity;
239 #define TICK_VAR_INI(arity) \
240 StgInt SLOW_CALLS_##arity = 1; \
241 StgInt RIGHT_ARITY_##arity = 1; \
242 StgInt TAGGED_PTR_##arity = 0;
244 extern StgInt TOTAL_CALLS;
250 /* -----------------------------------------------------------------------------
251 Assertions and Debuggery
252 -------------------------------------------------------------------------- */
254 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
256 /* -----------------------------------------------------------------------------
257 Assertions and Debuggery
258 -------------------------------------------------------------------------- */
261 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
263 #define IF_DEBUG(c,s) doNothing()
267 #define DEBUG_ONLY(s) s
269 #define DEBUG_ONLY(s) doNothing()
272 #if defined(GRAN) && defined(DEBUG)
273 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
275 #define IF_GRAN_DEBUG(c,s) doNothing()
278 #if defined(PAR) && defined(DEBUG)
279 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
281 #define IF_PAR_DEBUG(c,s) doNothing()
284 /* -----------------------------------------------------------------------------
285 Useful macros and inline functions
286 -------------------------------------------------------------------------- */
288 #if defined(__GNUC__)
289 #define SUPPORTS_TYPEOF
292 #if defined(SUPPORTS_TYPEOF)
293 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
294 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
296 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
297 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
300 /* -------------------------------------------------------------------------- */
307 /* krc: I put this here because I don't think
308 it needs to be visible externally.
309 It used to be in StgTicky.h, but I got rid
312 /* -----------------------------------------------------------------------------
313 The StgEntCounter type - needed regardless of TICKY_TICKY
314 -------------------------------------------------------------------------- */
316 typedef struct _StgEntCounter {
317 /* Using StgWord for everything, becuase both the C and asm code
318 generators make trouble if you try to pack things tighter */
319 StgWord registeredp; /* 0 == no, 1 == yes */
320 StgInt arity; /* arity (static info) */
321 StgInt stk_args; /* # of args off stack */
322 /* (rest of args are in registers) */
323 char *str; /* name of the thing */
324 char *arg_kinds; /* info about the args types */
325 StgInt entry_count; /* Trips to fast entry code */
326 StgInt allocs; /* number of allocations by this fun */
327 struct _StgEntCounter *link;/* link to chain them all together */