4e5947268f194ac46a85b84376f2d283b71c40ac
[ghc-hetmet.git] / ghc / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Top-level include file for the RTS itself
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef RTS_H
10 #define RTS_H
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #ifndef IN_STG_CODE
17 #define IN_STG_CODE 0
18 #endif
19 #include "Stg.h"
20
21 #include "RtsTypes.h"
22
23 #if __GNUC__ >= 3
24 /* Assume that a flexible array member at the end of a struct
25  * can be defined thus: T arr[]; */
26 #define FLEXIBLE_ARRAY
27 #else
28 /* Assume that it must be defined thus: T arr[0]; */
29 #define FLEXIBLE_ARRAY 0
30 #endif
31
32 #if defined(SMP) || defined(THREADED_RTS)
33 #define RTS_SUPPORTS_THREADS 1
34 #endif
35
36 /* Fix for mingw stat problem (done here so it's early enough) */
37 #ifdef mingw32_HOST_OS
38 #define __MSVCRT__ 1
39 #endif
40
41 /*
42  * We often want to know the size of something in units of an
43  * StgWord... (rounded up, of course!)
44  */
45 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
46
47 /* 
48  * It's nice to be able to grep for casts
49  */
50 #define stgCast(ty,e) ((ty)(e))
51
52 /* -----------------------------------------------------------------------------
53    Assertions and Debuggery
54    -------------------------------------------------------------------------- */
55
56 #ifndef DEBUG
57 #define ASSERT(predicate) /* nothing */
58 #else
59
60 void _stgAssert (char *, unsigned int);
61
62 #define ASSERT(predicate)                       \
63         if (predicate)                          \
64             /*null*/;                           \
65         else                                    \
66             _stgAssert(__FILE__, __LINE__)
67 #endif /* DEBUG */
68
69 /* 
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.
73  */
74
75 #define doNothing() do { } while (0)
76
77 /* -----------------------------------------------------------------------------
78    Include everything STG-ish
79    -------------------------------------------------------------------------- */
80
81 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
82  * come after MachRegs.h, because stdlib.h might define some inline
83  * functions which may only be defined after register variables have
84  * been declared.
85  */
86 #include <stdlib.h>
87
88 /* Global constaints */
89 #include "Constants.h"
90
91 /* Profiling information */
92 #include "StgProf.h"
93 #include "StgLdvProf.h"
94
95 /* Storage format definitions */
96 #include "StgFun.h"
97 #include "Closures.h"
98 #include "Liveness.h"
99 #include "ClosureTypes.h"
100 #include "InfoTables.h"
101 #include "TSO.h"
102
103 /* Info tables, closures & code fragments defined in the RTS */
104 #include "StgMiscClosures.h"
105
106 /* Simulated-parallel information */
107 #include "GranSim.h"
108
109 /* Parallel information */
110 #include "Parallel.h"
111
112 /* STG/Optimised-C related stuff */
113 #include "SMP.h"
114 #include "Block.h"
115
116 #ifdef SMP
117 #include <pthread.h>
118 #endif
119
120 /* GNU mp library */
121 #include "gmp.h"
122
123 /* Macros for STG/C code */
124 #include "ClosureMacros.h"
125 #include "StgTicky.h"
126 #include "Stable.h"
127
128 /* Runtime-system hooks */
129 #include "Hooks.h"
130 #include "RtsMessages.h"
131
132 #include "ieee-flpt.h"
133
134 #include "Signals.h"
135
136 /* Misc stuff without a home */
137 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
138 DLL_IMPORT_RTS extern int    prog_argc;
139 DLL_IMPORT_RTS extern char  *prog_name;
140
141 extern void stackOverflow(void);
142
143 extern void      __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
144 extern void      __decodeFloat  (MP_INT *man, I_ *_exp, StgFloat flt);
145
146 #if defined(WANT_DOTNET_SUPPORT)
147 #include "DNInvoke.h"
148 #endif
149
150 /* Initialising the whole adjustor thunk machinery. */
151 extern void initAdjustor(void);
152
153 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
154
155 /* -----------------------------------------------------------------------------
156    RTS Exit codes
157    -------------------------------------------------------------------------- */
158
159 /* 255 is allegedly used by dynamic linkers to report linking failure */
160 #define EXIT_INTERNAL_ERROR 254
161 #define EXIT_DEADLOCK       253
162 #define EXIT_INTERRUPTED    252
163 #define EXIT_HEAPOVERFLOW   251
164 #define EXIT_KILLED         250
165
166 /* -----------------------------------------------------------------------------
167    Miscellaneous garbage
168    -------------------------------------------------------------------------- */
169
170 /* declarations for runtime flags/values */
171 #define MAX_RTS_ARGS 32
172
173 /* -----------------------------------------------------------------------------
174    Assertions and Debuggery
175    -------------------------------------------------------------------------- */
176
177 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
178
179 /* -----------------------------------------------------------------------------
180    Assertions and Debuggery
181    -------------------------------------------------------------------------- */
182
183 #ifdef DEBUG
184 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
185 #else
186 #define IF_DEBUG(c,s)  doNothing()
187 #endif
188
189 #ifdef DEBUG
190 #define DEBUG_ONLY(s) s
191 #else
192 #define DEBUG_ONLY(s) doNothing()
193 #endif
194
195 #if defined(GRAN) && defined(DEBUG)
196 #define IF_GRAN_DEBUG(c,s)  if (RtsFlags.GranFlags.Debug.c) { s; }
197 #else
198 #define IF_GRAN_DEBUG(c,s)  doNothing()
199 #endif
200
201 #if defined(PAR) && defined(DEBUG)
202 #define IF_PAR_DEBUG(c,s)  if (RtsFlags.ParFlags.Debug.c) { s; }
203 #else
204 #define IF_PAR_DEBUG(c,s)  doNothing()
205 #endif
206
207 /* -----------------------------------------------------------------------------
208    Useful macros and inline functions
209    -------------------------------------------------------------------------- */
210
211 #if defined(__GNUC__)
212 #define SUPPORTS_TYPEOF
213 #endif
214
215 #if defined(SUPPORTS_TYPEOF)
216 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
217 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
218 #else
219 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
220 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
221 #endif
222
223 /* -------------------------------------------------------------------------- */
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif /* RTS_H */