1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Top-level include file for the RTS itself
7 * ---------------------------------------------------------------------------*/
24 /* Assume that a flexible array member at the end of a struct
25 * can be defined thus: T arr[]; */
26 #define FLEXIBLE_ARRAY
28 /* Assume that it must be defined thus: T arr[0]; */
29 #define FLEXIBLE_ARRAY 0
32 /* Fix for mingw stat problem (done here so it's early enough) */
33 #ifdef mingw32_HOST_OS
37 /* Needed to get the macro version of errno on some OSs, and also to
38 get prototypes for the _r versions of C library functions. */
42 * We often want to know the size of something in units of an
43 * StgWord... (rounded up, of course!)
45 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
48 * It's nice to be able to grep for casts
50 #define stgCast(ty,e) ((ty)(e))
52 /* -----------------------------------------------------------------------------
53 Assertions and Debuggery
54 -------------------------------------------------------------------------- */
57 #define ASSERT(predicate) /* nothing */
60 extern void _assertFail (const char *, unsigned int);
62 #define ASSERT(predicate) \
66 _assertFail(__FILE__, __LINE__)
70 * Use this on the RHS of macros which expand to nothing
71 * to make sure that the macro can be used in a context which
72 * demands a non-empty statement.
75 #define doNothing() do { } while (0)
79 #define USED_IF_NOT_DEBUG STG_UNUSED
81 #define USED_IF_DEBUG STG_UNUSED
82 #define USED_IF_NOT_DEBUG
86 #define USED_IF_THREADS
87 #define USED_IF_NOT_THREADS STG_UNUSED
89 #define USED_IF_THREADS STG_UNUSED
90 #define USED_IF_NOT_THREADS
94 * Getting printf formats right for platform-dependent typedefs
97 #define FMT_Word64 "lu"
98 #define FMT_Int64 "ld"
100 #define FMT_Word64 "llu"
101 #define FMT_Int64 "lld"
104 /* -----------------------------------------------------------------------------
105 Include everything STG-ish
106 -------------------------------------------------------------------------- */
108 /* System headers: stdlib.h is eeded so that we can use NULL. It must
109 * come after MachRegs.h, because stdlib.h might define some inline
110 * functions which may only be defined after register variables have
115 /* Global constaints */
116 #include "Constants.h"
118 /* Profiling information */
120 #include "StgLdvProf.h"
122 /* Storage format definitions */
124 #include "Closures.h"
125 #include "Liveness.h"
126 #include "ClosureTypes.h"
127 #include "InfoTables.h"
130 /* Info tables, closures & code fragments defined in the RTS */
131 #include "StgMiscClosures.h"
133 /* Simulated-parallel information */
136 /* Parallel information */
137 #include "Parallel.h"
138 #include "OSThreads.h"
141 /* STG/Optimised-C related stuff */
147 /* Macros for STG/C code */
148 #include "ClosureMacros.h"
149 #include "StgTicky.h"
152 /* Runtime-system hooks */
154 #include "RtsMessages.h"
156 #include "ieee-flpt.h"
160 /* Misc stuff without a home */
161 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
162 DLL_IMPORT_RTS extern int prog_argc;
163 DLL_IMPORT_RTS extern char *prog_name;
165 extern void stackOverflow(void);
167 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
168 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
170 #if defined(WANT_DOTNET_SUPPORT)
171 #include "DNInvoke.h"
174 /* Initialising the whole adjustor thunk machinery. */
175 extern void initAdjustor(void);
177 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
179 /* -----------------------------------------------------------------------------
181 -------------------------------------------------------------------------- */
183 /* 255 is allegedly used by dynamic linkers to report linking failure */
184 #define EXIT_INTERNAL_ERROR 254
185 #define EXIT_DEADLOCK 253
186 #define EXIT_INTERRUPTED 252
187 #define EXIT_HEAPOVERFLOW 251
188 #define EXIT_KILLED 250
190 /* -----------------------------------------------------------------------------
191 Miscellaneous garbage
192 -------------------------------------------------------------------------- */
194 /* declarations for runtime flags/values */
195 #define MAX_RTS_ARGS 32
197 /* -----------------------------------------------------------------------------
198 Assertions and Debuggery
199 -------------------------------------------------------------------------- */
201 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
203 /* -----------------------------------------------------------------------------
204 Assertions and Debuggery
205 -------------------------------------------------------------------------- */
208 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
210 #define IF_DEBUG(c,s) doNothing()
214 #define DEBUG_ONLY(s) s
216 #define DEBUG_ONLY(s) doNothing()
219 #if defined(GRAN) && defined(DEBUG)
220 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
222 #define IF_GRAN_DEBUG(c,s) doNothing()
225 #if defined(PAR) && defined(DEBUG)
226 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
228 #define IF_PAR_DEBUG(c,s) doNothing()
231 /* -----------------------------------------------------------------------------
232 Useful macros and inline functions
233 -------------------------------------------------------------------------- */
235 #if defined(__GNUC__)
236 #define SUPPORTS_TYPEOF
239 #if defined(SUPPORTS_TYPEOF)
240 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
241 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
243 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
244 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
247 /* -------------------------------------------------------------------------- */