1 /* -----------------------------------------------------------------------------
2 * $Id: Rts.h,v 1.27 2004/09/06 11:10:34 simonmar Exp $
4 * (c) The GHC Team, 1998-1999
6 * Top-level include file for the RTS itself
8 * ---------------------------------------------------------------------------*/
25 /* Assume that a flexible array member at the end of a struct
26 * can be defined thus: T arr[]; */
27 #define FLEXIBLE_ARRAY
29 /* Assume that it must be defined thus: T arr[0]; */
30 #define FLEXIBLE_ARRAY 0
33 #if defined(SMP) || defined(THREADED_RTS)
34 #define RTS_SUPPORTS_THREADS 1
37 /* Fix for mingw stat problem (done here so it's early enough) */
38 #ifdef mingw32_TARGET_OS
43 #define GNU_ATTRIBUTE(at) __attribute__((at))
45 #define GNU_ATTRIBUTE(at)
49 #define GNUC3_ATTRIBUTE(at) __attribute__((at))
51 #define GNUC3_ATTRIBUTE(at)
55 * Empty structures isn't supported by all, so to define
56 * empty structures, please protect the defn with an
57 * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
58 * employ the macro MAYBE_EMPTY_STRUCT():
60 * MAYBE_EMPTY_STRUCT(structFoo, fieldName);
62 #if SUPPORTS_EMPTY_STRUCTS
63 # define MAYBE_EMPTY_STRUCT(a,b) a b;
65 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
69 * We often want to know the size of something in units of an
70 * StgWord... (rounded up, of course!)
72 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
75 * It's nice to be able to grep for casts
77 #define stgCast(ty,e) ((ty)(e))
79 /* -----------------------------------------------------------------------------
80 Assertions and Debuggery
81 -------------------------------------------------------------------------- */
84 #define ASSERT(predicate) /* nothing */
87 void _stgAssert (char *, unsigned int);
89 #define ASSERT(predicate) \
93 _stgAssert(__FILE__, __LINE__)
97 * Use this on the RHS of macros which expand to nothing
98 * to make sure that the macro can be used in a context which
99 * demands a non-empty statement.
102 #define doNothing() do { } while (0)
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"
139 /* STG/Optimised-C related stuff */
150 /* Macros for STG/C code */
151 #include "ClosureMacros.h"
152 #include "StgTicky.h"
155 /* Runtime-system hooks */
157 #include "RtsMessages.h"
159 #include "ieee-flpt.h"
163 /* Misc stuff without a home */
164 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
165 DLL_IMPORT_RTS extern int prog_argc;
166 DLL_IMPORT_RTS extern char *prog_name;
168 extern void stackOverflow(void);
170 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
171 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
173 #if defined(WANT_DOTNET_SUPPORT)
174 #include "DNInvoke.h"
177 /* Initialising the whole adjustor thunk machinery. */
178 extern void initAdjustor(void);
180 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
182 /* -----------------------------------------------------------------------------
184 -------------------------------------------------------------------------- */
186 /* 255 is allegedly used by dynamic linkers to report linking failure */
187 #define EXIT_INTERNAL_ERROR 254
188 #define EXIT_DEADLOCK 253
189 #define EXIT_INTERRUPTED 252
190 #define EXIT_HEAPOVERFLOW 251
191 #define EXIT_KILLED 250
193 /* -----------------------------------------------------------------------------
194 Miscellaneous garbage
195 -------------------------------------------------------------------------- */
197 /* declarations for runtime flags/values */
198 #define MAX_RTS_ARGS 32
201 /* On the yucky side..suppress -Wmissing-declarations warnings when
202 * including <windows.h>
204 extern void* GetCurrentFiber ( void );
205 extern void* GetFiberData ( void );
208 /* -----------------------------------------------------------------------------
209 Assertions and Debuggery
210 -------------------------------------------------------------------------- */
212 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
214 /* -----------------------------------------------------------------------------
215 Assertions and Debuggery
216 -------------------------------------------------------------------------- */
219 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
221 #define IF_DEBUG(c,s) doNothing()
225 #define DEBUG_ONLY(s) s
227 #define DEBUG_ONLY(s) doNothing()
230 #if defined(GRAN) && defined(DEBUG)
231 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
233 #define IF_GRAN_DEBUG(c,s) doNothing()
236 #if defined(PAR) && defined(DEBUG)
237 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
239 #define IF_PAR_DEBUG(c,s) doNothing()
242 /* -----------------------------------------------------------------------------
244 -------------------------------------------------------------------------- */
246 #ifdef __GNUC__ /* Avoid spurious warnings */
247 #if (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || __GNUC__ >= 3
248 #define STG_NORETURN __attribute__ ((noreturn))
249 #define STG_UNUSED __attribute__ ((unused))
259 #if defined(__GNUC__)
260 #define SUPPORTS_TYPEOF
263 /* -----------------------------------------------------------------------------
264 Useful macros and inline functions
265 -------------------------------------------------------------------------- */
267 #if defined(SUPPORTS_TYPEOF)
268 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
269 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
271 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
272 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
275 /* -------------------------------------------------------------------------- */