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
93 /* -----------------------------------------------------------------------------
94 Include everything STG-ish
95 -------------------------------------------------------------------------- */
97 /* System headers: stdlib.h is eeded so that we can use NULL. It must
98 * come after MachRegs.h, because stdlib.h might define some inline
99 * functions which may only be defined after register variables have
104 /* Global constaints */
105 #include "Constants.h"
107 /* Profiling information */
109 #include "StgLdvProf.h"
111 /* Storage format definitions */
113 #include "Closures.h"
114 #include "Liveness.h"
115 #include "ClosureTypes.h"
116 #include "InfoTables.h"
119 /* Info tables, closures & code fragments defined in the RTS */
120 #include "StgMiscClosures.h"
122 /* Simulated-parallel information */
125 /* Parallel information */
126 #include "Parallel.h"
127 #include "OSThreads.h"
130 /* STG/Optimised-C related stuff */
136 /* Macros for STG/C code */
137 #include "ClosureMacros.h"
138 #include "StgTicky.h"
141 /* Runtime-system hooks */
143 #include "RtsMessages.h"
145 #include "ieee-flpt.h"
149 /* Misc stuff without a home */
150 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
151 DLL_IMPORT_RTS extern int prog_argc;
152 DLL_IMPORT_RTS extern char *prog_name;
154 extern void stackOverflow(void);
156 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
157 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
159 #if defined(WANT_DOTNET_SUPPORT)
160 #include "DNInvoke.h"
163 /* Initialising the whole adjustor thunk machinery. */
164 extern void initAdjustor(void);
166 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
168 /* -----------------------------------------------------------------------------
170 -------------------------------------------------------------------------- */
172 /* 255 is allegedly used by dynamic linkers to report linking failure */
173 #define EXIT_INTERNAL_ERROR 254
174 #define EXIT_DEADLOCK 253
175 #define EXIT_INTERRUPTED 252
176 #define EXIT_HEAPOVERFLOW 251
177 #define EXIT_KILLED 250
179 /* -----------------------------------------------------------------------------
180 Miscellaneous garbage
181 -------------------------------------------------------------------------- */
183 /* declarations for runtime flags/values */
184 #define MAX_RTS_ARGS 32
186 /* -----------------------------------------------------------------------------
187 Assertions and Debuggery
188 -------------------------------------------------------------------------- */
190 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
192 /* -----------------------------------------------------------------------------
193 Assertions and Debuggery
194 -------------------------------------------------------------------------- */
197 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
199 #define IF_DEBUG(c,s) doNothing()
203 #define DEBUG_ONLY(s) s
205 #define DEBUG_ONLY(s) doNothing()
208 #if defined(GRAN) && defined(DEBUG)
209 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
211 #define IF_GRAN_DEBUG(c,s) doNothing()
214 #if defined(PAR) && defined(DEBUG)
215 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
217 #define IF_PAR_DEBUG(c,s) doNothing()
220 /* -----------------------------------------------------------------------------
221 Useful macros and inline functions
222 -------------------------------------------------------------------------- */
224 #if defined(__GNUC__)
225 #define SUPPORTS_TYPEOF
228 #if defined(SUPPORTS_TYPEOF)
229 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
230 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
232 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
233 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
236 /* -------------------------------------------------------------------------- */