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
42 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
44 #define ATTRIBUTE_ALIGNED(n) /*nothing*/
47 /* Fix for mingw stat problem (done here so it's early enough) */
48 #ifdef mingw32_HOST_OS
52 /* Needed to get the macro version of errno on some OSs, and also to
53 get prototypes for the _r versions of C library functions. */
57 * We often want to know the size of something in units of an
58 * StgWord... (rounded up, of course!)
60 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
62 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
65 * It's nice to be able to grep for casts
67 #define stgCast(ty,e) ((ty)(e))
69 /* -----------------------------------------------------------------------------
70 Assertions and Debuggery
71 -------------------------------------------------------------------------- */
74 #define ASSERT(predicate) /* nothing */
77 extern void _assertFail (const char *, unsigned int);
79 #define ASSERT(predicate) \
83 _assertFail(__FILE__, __LINE__)
87 * Use this on the RHS of macros which expand to nothing
88 * to make sure that the macro can be used in a context which
89 * demands a non-empty statement.
92 #define doNothing() do { } while (0)
96 #define USED_IF_NOT_DEBUG STG_UNUSED
98 #define USED_IF_DEBUG STG_UNUSED
99 #define USED_IF_NOT_DEBUG
103 #define USED_IF_THREADS
104 #define USED_IF_NOT_THREADS STG_UNUSED
106 #define USED_IF_THREADS STG_UNUSED
107 #define USED_IF_NOT_THREADS
111 * Getting printf formats right for platform-dependent typedefs
114 #define FMT_Word64 "lu"
115 #define FMT_Int64 "ld"
117 #define FMT_Word64 "llu"
118 #define FMT_Int64 "lld"
122 * Macros for untagging and retagging closure pointers
123 * For more information look at the comments in Cmm.h
126 static inline StgWord
127 GET_CLOSURE_TAG(StgClosure * p)
129 return (StgWord)p & TAG_MASK;
132 static inline StgClosure *
133 UNTAG_CLOSURE(StgClosure * p)
135 return (StgClosure*)((StgWord)p & ~TAG_MASK);
138 static inline StgClosure *
139 TAG_CLOSURE(StgWord tag,StgClosure * p)
141 return (StgClosure*)((StgWord)p | tag);
144 /* -----------------------------------------------------------------------------
145 Include everything STG-ish
146 -------------------------------------------------------------------------- */
148 /* System headers: stdlib.h is eeded so that we can use NULL. It must
149 * come after MachRegs.h, because stdlib.h might define some inline
150 * functions which may only be defined after register variables have
155 /* Global constaints */
156 #include "Constants.h"
158 /* Profiling information */
160 #include "StgLdvProf.h"
162 /* Storage format definitions */
164 #include "Closures.h"
165 #include "Liveness.h"
166 #include "ClosureTypes.h"
167 #include "InfoTables.h"
170 /* Info tables, closures & code fragments defined in the RTS */
171 #include "StgMiscClosures.h"
173 /* Simulated-parallel information */
176 /* Parallel information */
177 #include "Parallel.h"
178 #include "OSThreads.h"
179 #include "SMPClosureOps.h"
180 #include "SpinLock.h"
183 #if defined(HAVE_FRAMEWORK_GMP)
189 /* Macros for STG/C code */
191 #include "ClosureMacros.h"
193 /* Ticky-ticky counters */
194 #include "TickyCounters.h"
196 /* Runtime-system hooks */
198 #include "RtsMessages.h"
200 /* for StablePtr/getStablePtr/deRefStablePtr */
204 #include "ieee-flpt.h"
208 /* Misc stuff without a home */
209 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
210 DLL_IMPORT_RTS extern int prog_argc;
211 DLL_IMPORT_RTS extern char *prog_name;
213 extern void stackOverflow(void);
215 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
216 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
217 extern void __decodeDouble_2Int (I_ *man_sign, W_ *man_high, W_ *man_low, I_ *exp, StgDouble dbl);
218 extern void __decodeFloat_Int (I_ *man, I_ *exp, StgFloat flt);
220 #if defined(WANT_DOTNET_SUPPORT)
221 #include "DNInvoke.h"
224 /* Initialising the whole adjustor thunk machinery. */
225 extern void initAdjustor(void);
227 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
229 /* -----------------------------------------------------------------------------
231 -------------------------------------------------------------------------- */
233 /* 255 is allegedly used by dynamic linkers to report linking failure */
234 #define EXIT_INTERNAL_ERROR 254
235 #define EXIT_DEADLOCK 253
236 #define EXIT_INTERRUPTED 252
237 #define EXIT_HEAPOVERFLOW 251
238 #define EXIT_KILLED 250
240 /* -----------------------------------------------------------------------------
241 Miscellaneous garbage
242 -------------------------------------------------------------------------- */
244 /* declarations for runtime flags/values */
245 #define MAX_RTS_ARGS 32
248 #define TICK_VAR(arity) \
249 extern StgInt SLOW_CALLS_##arity; \
250 extern StgInt RIGHT_ARITY_##arity; \
251 extern StgInt TAGGED_PTR_##arity;
253 #define TICK_VAR_INI(arity) \
254 StgInt SLOW_CALLS_##arity = 1; \
255 StgInt RIGHT_ARITY_##arity = 1; \
256 StgInt TAGGED_PTR_##arity = 0;
258 extern StgInt TOTAL_CALLS;
264 /* -----------------------------------------------------------------------------
265 Assertions and Debuggery
266 -------------------------------------------------------------------------- */
268 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
270 /* -----------------------------------------------------------------------------
271 Assertions and Debuggery
272 -------------------------------------------------------------------------- */
276 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
278 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
281 #define IF_DEBUG(c,s) doNothing()
285 #define DEBUG_ONLY(s) s
287 #define DEBUG_ONLY(s) doNothing()
290 #if defined(GRAN) && defined(DEBUG)
291 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
293 #define IF_GRAN_DEBUG(c,s) doNothing()
296 #if defined(PAR) && defined(DEBUG)
297 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
299 #define IF_PAR_DEBUG(c,s) doNothing()
302 /* -----------------------------------------------------------------------------
303 Useful macros and inline functions
304 -------------------------------------------------------------------------- */
306 #if defined(__GNUC__)
307 #define SUPPORTS_TYPEOF
310 #if defined(SUPPORTS_TYPEOF)
311 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
312 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
314 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
315 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
318 /* -------------------------------------------------------------------------- */
325 /* krc: I put this here because I don't think
326 it needs to be visible externally.
327 It used to be in StgTicky.h, but I got rid
330 /* -----------------------------------------------------------------------------
331 The StgEntCounter type - needed regardless of TICKY_TICKY
332 -------------------------------------------------------------------------- */
334 typedef struct _StgEntCounter {
335 /* Using StgWord for everything, becuase both the C and asm code
336 generators make trouble if you try to pack things tighter */
337 StgWord registeredp; /* 0 == no, 1 == yes */
338 StgInt arity; /* arity (static info) */
339 StgInt stk_args; /* # of args off stack */
340 /* (rest of args are in registers) */
341 char *str; /* name of the thing */
342 char *arg_kinds; /* info about the args types */
343 StgInt entry_count; /* Trips to fast entry code */
344 StgInt allocs; /* number of allocations by this fun */
345 struct _StgEntCounter *link;/* link to chain them all together */