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. */
59 * We often want to know the size of something in units of an
60 * StgWord... (rounded up, of course!)
62 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
64 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
67 * It's nice to be able to grep for casts
69 #define stgCast(ty,e) ((ty)(e))
71 /* -----------------------------------------------------------------------------
72 Assertions and Debuggery
74 CHECK(p) evaluates p and terminates with an error if p is false
75 ASSERT(p) like CHECK(p) if DEBUG is on, otherwise a no-op
76 -------------------------------------------------------------------------- */
78 extern void _assertFail (const char *, unsigned int);
80 #define CHECK(predicate) \
84 _assertFail(__FILE__, __LINE__)
87 #define ASSERT(predicate) /* nothing */
89 #define ASSERT(predicate) CHECK(predicate)
93 * Use this on the RHS of macros which expand to nothing
94 * to make sure that the macro can be used in a context which
95 * demands a non-empty statement.
98 #define doNothing() do { } while (0)
101 #define USED_IF_DEBUG
102 #define USED_IF_NOT_DEBUG STG_UNUSED
104 #define USED_IF_DEBUG STG_UNUSED
105 #define USED_IF_NOT_DEBUG
109 #define USED_IF_THREADS
110 #define USED_IF_NOT_THREADS STG_UNUSED
112 #define USED_IF_THREADS STG_UNUSED
113 #define USED_IF_NOT_THREADS
117 * Getting printf formats right for platform-dependent typedefs
120 #define FMT_Word64 "lu"
121 #define FMT_Int64 "ld"
123 #define FMT_Word64 "llu"
124 #define FMT_Int64 "lld"
128 * Macros for untagging and retagging closure pointers
129 * For more information look at the comments in Cmm.h
132 static inline StgWord
133 GET_CLOSURE_TAG(StgClosure * p)
135 return (StgWord)p & TAG_MASK;
138 static inline StgClosure *
139 UNTAG_CLOSURE(StgClosure * p)
141 return (StgClosure*)((StgWord)p & ~TAG_MASK);
144 static inline StgClosure *
145 TAG_CLOSURE(StgWord tag,StgClosure * p)
147 return (StgClosure*)((StgWord)p | tag);
150 /* -----------------------------------------------------------------------------
151 Include everything STG-ish
152 -------------------------------------------------------------------------- */
154 /* System headers: stdlib.h is eeded so that we can use NULL. It must
155 * come after MachRegs.h, because stdlib.h might define some inline
156 * functions which may only be defined after register variables have
161 /* Global constaints */
162 #include "Constants.h"
164 /* Profiling information */
166 #include "StgLdvProf.h"
168 /* Storage format definitions */
170 #include "Closures.h"
171 #include "Liveness.h"
172 #include "ClosureTypes.h"
173 #include "InfoTables.h"
176 /* Info tables, closures & code fragments defined in the RTS */
177 #include "StgMiscClosures.h"
179 /* Parallel information */
180 #include "OSThreads.h"
181 #include "SMPClosureOps.h"
182 #include "SpinLock.h"
184 /* Macros for STG/C code */
186 #include "ClosureMacros.h"
188 /* Runtime-system hooks */
190 #include "RtsMessages.h"
192 /* for StablePtr/getStablePtr/deRefStablePtr */
196 #include "ieee-flpt.h"
200 /* Misc stuff without a home */
201 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
202 DLL_IMPORT_RTS extern int prog_argc;
203 DLL_IMPORT_RTS extern char *prog_name;
205 extern void stackOverflow(void);
207 extern void __decodeDouble_2Int (I_ *man_sign, W_ *man_high, W_ *man_low, I_ *exp, StgDouble dbl);
208 extern void __decodeFloat_Int (I_ *man, I_ *exp, StgFloat flt);
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 -------------------------------------------------------------------------- */
262 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
264 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
267 #define IF_DEBUG(c,s) doNothing()
271 #define DEBUG_ONLY(s) s
273 #define DEBUG_ONLY(s) doNothing()
276 /* -----------------------------------------------------------------------------
277 Useful macros and inline functions
278 -------------------------------------------------------------------------- */
280 #if defined(__GNUC__)
281 #define SUPPORTS_TYPEOF
284 #if defined(SUPPORTS_TYPEOF)
285 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
286 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
288 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
289 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
292 /* -------------------------------------------------------------------------- */
299 /* krc: I put this here because I don't think
300 it needs to be visible externally.
301 It used to be in StgTicky.h, but I got rid
304 /* -----------------------------------------------------------------------------
305 The StgEntCounter type - needed regardless of TICKY_TICKY
306 -------------------------------------------------------------------------- */
308 typedef struct _StgEntCounter {
309 /* Using StgWord for everything, becuase both the C and asm code
310 generators make trouble if you try to pack things tighter */
311 StgWord registeredp; /* 0 == no, 1 == yes */
312 StgInt arity; /* arity (static info) */
313 StgInt stk_args; /* # of args off stack */
314 /* (rest of args are in registers) */
315 char *str; /* name of the thing */
316 char *arg_kinds; /* info about the args types */
317 StgInt entry_count; /* Trips to fast entry code */
318 StgInt allocs; /* number of allocations by this fun */
319 struct _StgEntCounter *link;/* link to chain them all together */