1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Top-level include file for the RTS itself
7 * ---------------------------------------------------------------------------*/
21 // ToDo: move RtsExternal stuff elsewhere
22 #include "RtsExternal.h"
24 // Turn off inlining when debugging - it obfuscates things
27 # define STATIC_INLINE static
33 /* Assume that a flexible array member at the end of a struct
34 * can be defined thus: T arr[]; */
35 #define FLEXIBLE_ARRAY
37 /* Assume that it must be defined thus: T arr[0]; */
38 #define FLEXIBLE_ARRAY 0
41 /* Fix for mingw stat problem (done here so it's early enough) */
42 #ifdef mingw32_HOST_OS
46 /* Needed to get the macro version of errno on some OSs, and also to
47 get prototypes for the _r versions of C library functions. */
51 * We often want to know the size of something in units of an
52 * StgWord... (rounded up, of course!)
54 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
56 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
59 * It's nice to be able to grep for casts
61 #define stgCast(ty,e) ((ty)(e))
63 /* -----------------------------------------------------------------------------
64 Assertions and Debuggery
65 -------------------------------------------------------------------------- */
68 #define ASSERT(predicate) /* nothing */
71 extern void _assertFail (const char *, unsigned int);
73 #define ASSERT(predicate) \
77 _assertFail(__FILE__, __LINE__)
81 * Use this on the RHS of macros which expand to nothing
82 * to make sure that the macro can be used in a context which
83 * demands a non-empty statement.
86 #define doNothing() do { } while (0)
90 #define USED_IF_NOT_DEBUG STG_UNUSED
92 #define USED_IF_DEBUG STG_UNUSED
93 #define USED_IF_NOT_DEBUG
97 #define USED_IF_THREADS
98 #define USED_IF_NOT_THREADS STG_UNUSED
100 #define USED_IF_THREADS STG_UNUSED
101 #define USED_IF_NOT_THREADS
105 * Getting printf formats right for platform-dependent typedefs
108 #define FMT_Word64 "lu"
109 #define FMT_Int64 "ld"
111 #define FMT_Word64 "llu"
112 #define FMT_Int64 "lld"
116 * Macros for untagging and retagging closure pointers
117 * For more information look at the comments in Cmm.h
120 static inline StgWord
121 GET_CLOSURE_TAG(StgClosure * p)
123 return (StgWord)p & TAG_MASK;
126 static inline StgClosure *
127 UNTAG_CLOSURE(StgClosure * p)
129 return (StgClosure*)((StgWord)p & ~TAG_MASK);
132 static inline StgClosure *
133 TAG_CLOSURE(StgWord tag,StgClosure * p)
135 return (StgClosure*)((StgWord)p | tag);
138 /* -----------------------------------------------------------------------------
139 Include everything STG-ish
140 -------------------------------------------------------------------------- */
142 /* System headers: stdlib.h is eeded so that we can use NULL. It must
143 * come after MachRegs.h, because stdlib.h might define some inline
144 * functions which may only be defined after register variables have
149 /* Global constaints */
150 #include "Constants.h"
152 /* Profiling information */
154 #include "StgLdvProf.h"
156 /* Storage format definitions */
158 #include "Closures.h"
159 #include "Liveness.h"
160 #include "ClosureTypes.h"
161 #include "InfoTables.h"
164 /* Info tables, closures & code fragments defined in the RTS */
165 #include "StgMiscClosures.h"
167 /* Simulated-parallel information */
170 /* Parallel information */
171 #include "Parallel.h"
172 #include "OSThreads.h"
173 #include "SMPClosureOps.h"
174 #include "SpinLock.h"
177 #if defined(HAVE_FRAMEWORK_GMP)
183 /* Macros for STG/C code */
185 #include "ClosureMacros.h"
187 /* Ticky-ticky counters */
188 #include "TickyCounters.h"
190 /* Runtime-system hooks */
192 #include "RtsMessages.h"
194 /* for StablePtr/getStablePtr/deRefStablePtr */
198 #include "ieee-flpt.h"
202 /* Misc stuff without a home */
203 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
204 DLL_IMPORT_RTS extern int prog_argc;
205 DLL_IMPORT_RTS extern char *prog_name;
207 extern void stackOverflow(void);
209 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
210 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
211 extern void __decodeDouble_2Int (I_ *man_sign, W_ *man_high, W_ *man_low, I_ *exp, StgDouble dbl);
212 extern void __decodeFloat_Int (I_ *man, I_ *exp, StgFloat flt);
214 #if defined(WANT_DOTNET_SUPPORT)
215 #include "DNInvoke.h"
218 /* Initialising the whole adjustor thunk machinery. */
219 extern void initAdjustor(void);
221 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
223 /* -----------------------------------------------------------------------------
225 -------------------------------------------------------------------------- */
227 /* 255 is allegedly used by dynamic linkers to report linking failure */
228 #define EXIT_INTERNAL_ERROR 254
229 #define EXIT_DEADLOCK 253
230 #define EXIT_INTERRUPTED 252
231 #define EXIT_HEAPOVERFLOW 251
232 #define EXIT_KILLED 250
234 /* -----------------------------------------------------------------------------
235 Miscellaneous garbage
236 -------------------------------------------------------------------------- */
238 /* declarations for runtime flags/values */
239 #define MAX_RTS_ARGS 32
242 #define TICK_VAR(arity) \
243 extern StgInt SLOW_CALLS_##arity; \
244 extern StgInt RIGHT_ARITY_##arity; \
245 extern StgInt TAGGED_PTR_##arity;
247 #define TICK_VAR_INI(arity) \
248 StgInt SLOW_CALLS_##arity = 1; \
249 StgInt RIGHT_ARITY_##arity = 1; \
250 StgInt TAGGED_PTR_##arity = 0;
252 extern StgInt TOTAL_CALLS;
258 /* -----------------------------------------------------------------------------
259 Assertions and Debuggery
260 -------------------------------------------------------------------------- */
262 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
264 /* -----------------------------------------------------------------------------
265 Assertions and Debuggery
266 -------------------------------------------------------------------------- */
270 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
272 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
275 #define IF_DEBUG(c,s) doNothing()
279 #define DEBUG_ONLY(s) s
281 #define DEBUG_ONLY(s) doNothing()
284 #if defined(GRAN) && defined(DEBUG)
285 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
287 #define IF_GRAN_DEBUG(c,s) doNothing()
290 #if defined(PAR) && defined(DEBUG)
291 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
293 #define IF_PAR_DEBUG(c,s) doNothing()
296 /* -----------------------------------------------------------------------------
297 Useful macros and inline functions
298 -------------------------------------------------------------------------- */
300 #if defined(__GNUC__)
301 #define SUPPORTS_TYPEOF
304 #if defined(SUPPORTS_TYPEOF)
305 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
306 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
308 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
309 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
312 /* -------------------------------------------------------------------------- */
319 /* krc: I put this here because I don't think
320 it needs to be visible externally.
321 It used to be in StgTicky.h, but I got rid
324 /* -----------------------------------------------------------------------------
325 The StgEntCounter type - needed regardless of TICKY_TICKY
326 -------------------------------------------------------------------------- */
328 typedef struct _StgEntCounter {
329 /* Using StgWord for everything, becuase both the C and asm code
330 generators make trouble if you try to pack things tighter */
331 StgWord registeredp; /* 0 == no, 1 == yes */
332 StgInt arity; /* arity (static info) */
333 StgInt stk_args; /* # of args off stack */
334 /* (rest of args are in registers) */
335 char *str; /* name of the thing */
336 char *arg_kinds; /* info about the args types */
337 StgInt entry_count; /* Trips to fast entry code */
338 StgInt allocs; /* number of allocations by this fun */
339 struct _StgEntCounter *link;/* link to chain them all together */