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 #if defined(SMP) || defined(THREADED_RTS)
33 #define RTS_SUPPORTS_THREADS 1
36 /* Fix for mingw stat problem (done here so it's early enough) */
37 #ifdef mingw32_TARGET_OS
42 #define GNU_ATTRIBUTE(at) __attribute__((at))
44 #define GNU_ATTRIBUTE(at)
48 #define GNUC3_ATTRIBUTE(at) __attribute__((at))
50 #define GNUC3_ATTRIBUTE(at)
53 #define STG_UNUSED GNUC3_ATTRIBUTE(__unused__)
56 * Empty structures isn't supported by all, so to define
57 * empty structures, please protect the defn with an
58 * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
59 * employ the macro MAYBE_EMPTY_STRUCT():
61 * MAYBE_EMPTY_STRUCT(structFoo, fieldName);
63 #if SUPPORTS_EMPTY_STRUCTS
64 # define MAYBE_EMPTY_STRUCT(a,b) a b;
66 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
70 * We often want to know the size of something in units of an
71 * StgWord... (rounded up, of course!)
73 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
76 * It's nice to be able to grep for casts
78 #define stgCast(ty,e) ((ty)(e))
80 /* -----------------------------------------------------------------------------
81 Assertions and Debuggery
82 -------------------------------------------------------------------------- */
85 #define ASSERT(predicate) /* nothing */
88 void _stgAssert (char *, unsigned int);
90 #define ASSERT(predicate) \
94 _stgAssert(__FILE__, __LINE__)
98 * Use this on the RHS of macros which expand to nothing
99 * to make sure that the macro can be used in a context which
100 * demands a non-empty statement.
103 #define doNothing() do { } while (0)
105 /* -----------------------------------------------------------------------------
106 Include everything STG-ish
107 -------------------------------------------------------------------------- */
109 /* System headers: stdlib.h is eeded so that we can use NULL. It must
110 * come after MachRegs.h, because stdlib.h might define some inline
111 * functions which may only be defined after register variables have
116 /* Global constaints */
117 #include "Constants.h"
119 /* Profiling information */
121 #include "StgLdvProf.h"
123 /* Storage format definitions */
125 #include "Closures.h"
126 #include "Liveness.h"
127 #include "ClosureTypes.h"
128 #include "InfoTables.h"
131 /* Info tables, closures & code fragments defined in the RTS */
132 #include "StgMiscClosures.h"
134 /* Simulated-parallel information */
137 /* Parallel information */
138 #include "Parallel.h"
140 /* STG/Optimised-C related stuff */
151 /* Macros for STG/C code */
152 #include "ClosureMacros.h"
153 #include "StgTicky.h"
156 /* Runtime-system hooks */
158 #include "RtsMessages.h"
160 #include "ieee-flpt.h"
164 /* Misc stuff without a home */
165 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
166 DLL_IMPORT_RTS extern int prog_argc;
167 DLL_IMPORT_RTS extern char *prog_name;
169 extern void stackOverflow(void);
171 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
172 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
174 #if defined(WANT_DOTNET_SUPPORT)
175 #include "DNInvoke.h"
178 /* Initialising the whole adjustor thunk machinery. */
179 extern void initAdjustor(void);
181 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
183 /* -----------------------------------------------------------------------------
185 -------------------------------------------------------------------------- */
187 /* 255 is allegedly used by dynamic linkers to report linking failure */
188 #define EXIT_INTERNAL_ERROR 254
189 #define EXIT_DEADLOCK 253
190 #define EXIT_INTERRUPTED 252
191 #define EXIT_HEAPOVERFLOW 251
192 #define EXIT_KILLED 250
194 /* -----------------------------------------------------------------------------
195 Miscellaneous garbage
196 -------------------------------------------------------------------------- */
198 /* declarations for runtime flags/values */
199 #define MAX_RTS_ARGS 32
202 /* On the yucky side..suppress -Wmissing-declarations warnings when
203 * including <windows.h>
205 extern void* GetCurrentFiber ( void );
206 extern void* GetFiberData ( void );
209 /* -----------------------------------------------------------------------------
210 Assertions and Debuggery
211 -------------------------------------------------------------------------- */
213 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
215 /* -----------------------------------------------------------------------------
216 Assertions and Debuggery
217 -------------------------------------------------------------------------- */
220 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
222 #define IF_DEBUG(c,s) doNothing()
226 #define DEBUG_ONLY(s) s
228 #define DEBUG_ONLY(s) doNothing()
231 #if defined(GRAN) && defined(DEBUG)
232 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
234 #define IF_GRAN_DEBUG(c,s) doNothing()
237 #if defined(PAR) && defined(DEBUG)
238 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
240 #define IF_PAR_DEBUG(c,s) doNothing()
243 /* -----------------------------------------------------------------------------
244 Useful macros and inline functions
245 -------------------------------------------------------------------------- */
247 #if defined(__GNUC__)
248 #define SUPPORTS_TYPEOF
251 #if defined(SUPPORTS_TYPEOF)
252 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
253 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
255 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
256 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
259 /* -------------------------------------------------------------------------- */