#define _REENTRANT 1 (needed to get the right errno on some OSs)
[ghc-hetmet.git] / 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 /* Fix for mingw stat problem (done here so it's early enough) */
33 #ifdef mingw32_HOST_OS
34 #define __MSVCRT__ 1
35 #endif
36
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. */
39 #define _REENTRANT 1
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 extern void _assertFail (char *, unsigned int);
61
62 #define ASSERT(predicate)                       \
63         if (predicate)                          \
64             /*null*/;                           \
65         else                                    \
66             _assertFail(__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 #ifdef DEBUG
78 #define USED_IF_DEBUG
79 #define USED_IF_NOT_DEBUG STG_UNUSED
80 #else
81 #define USED_IF_DEBUG STG_UNUSED
82 #define USED_IF_NOT_DEBUG
83 #endif
84
85 #ifdef THREADED_RTS
86 #define USED_IF_THREADS
87 #define USED_IF_NOT_THREADS STG_UNUSED
88 #else
89 #define USED_IF_THREADS STG_UNUSED
90 #define USED_IF_NOT_THREADS
91 #endif
92
93 /* -----------------------------------------------------------------------------
94    Include everything STG-ish
95    -------------------------------------------------------------------------- */
96
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
100  * been declared.
101  */
102 #include <stdlib.h>
103
104 /* Global constaints */
105 #include "Constants.h"
106
107 /* Profiling information */
108 #include "StgProf.h"
109 #include "StgLdvProf.h"
110
111 /* Storage format definitions */
112 #include "StgFun.h"
113 #include "Closures.h"
114 #include "Liveness.h"
115 #include "ClosureTypes.h"
116 #include "InfoTables.h"
117 #include "TSO.h"
118
119 /* Info tables, closures & code fragments defined in the RTS */
120 #include "StgMiscClosures.h"
121
122 /* Simulated-parallel information */
123 #include "GranSim.h"
124
125 /* Parallel information */
126 #include "Parallel.h"
127 #include "OSThreads.h"
128 #include "SMP.h"
129
130 /* STG/Optimised-C related stuff */
131 #include "Block.h"
132
133 /* GNU mp library */
134 #include "gmp.h"
135
136 /* Macros for STG/C code */
137 #include "ClosureMacros.h"
138 #include "StgTicky.h"
139 #include "Stable.h"
140
141 /* Runtime-system hooks */
142 #include "Hooks.h"
143 #include "RtsMessages.h"
144
145 #include "ieee-flpt.h"
146
147 #include "Signals.h"
148
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;
153
154 extern void stackOverflow(void);
155
156 extern void      __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
157 extern void      __decodeFloat  (MP_INT *man, I_ *_exp, StgFloat flt);
158
159 #if defined(WANT_DOTNET_SUPPORT)
160 #include "DNInvoke.h"
161 #endif
162
163 /* Initialising the whole adjustor thunk machinery. */
164 extern void initAdjustor(void);
165
166 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
167
168 /* -----------------------------------------------------------------------------
169    RTS Exit codes
170    -------------------------------------------------------------------------- */
171
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
178
179 /* -----------------------------------------------------------------------------
180    Miscellaneous garbage
181    -------------------------------------------------------------------------- */
182
183 /* declarations for runtime flags/values */
184 #define MAX_RTS_ARGS 32
185
186 /* -----------------------------------------------------------------------------
187    Assertions and Debuggery
188    -------------------------------------------------------------------------- */
189
190 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
191
192 /* -----------------------------------------------------------------------------
193    Assertions and Debuggery
194    -------------------------------------------------------------------------- */
195
196 #ifdef DEBUG
197 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
198 #else
199 #define IF_DEBUG(c,s)  doNothing()
200 #endif
201
202 #ifdef DEBUG
203 #define DEBUG_ONLY(s) s
204 #else
205 #define DEBUG_ONLY(s) doNothing()
206 #endif
207
208 #if defined(GRAN) && defined(DEBUG)
209 #define IF_GRAN_DEBUG(c,s)  if (RtsFlags.GranFlags.Debug.c) { s; }
210 #else
211 #define IF_GRAN_DEBUG(c,s)  doNothing()
212 #endif
213
214 #if defined(PAR) && defined(DEBUG)
215 #define IF_PAR_DEBUG(c,s)  if (RtsFlags.ParFlags.Debug.c) { s; }
216 #else
217 #define IF_PAR_DEBUG(c,s)  doNothing()
218 #endif
219
220 /* -----------------------------------------------------------------------------
221    Useful macros and inline functions
222    -------------------------------------------------------------------------- */
223
224 #if defined(__GNUC__)
225 #define SUPPORTS_TYPEOF
226 #endif
227
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; })
231 #else
232 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
233 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
234 #endif
235
236 /* -------------------------------------------------------------------------- */
237
238 #ifdef __cplusplus
239 }
240 #endif
241
242 #endif /* RTS_H */