move StgEntCounter type into its own header
[ghc-hetmet.git] / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2009
4  *
5  * RTS external APIs.  This file declares everything that the GHC RTS
6  * exposes externally.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef RTS_H
11 #define RTS_H
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #ifndef IN_STG_CODE
18 #define IN_STG_CODE 0
19 #endif
20 #include "Stg.h"
21
22 #include "HsFFI.h"
23 #include "RtsAPI.h"
24
25 // Turn off inlining when debugging - it obfuscates things
26 #ifdef DEBUG
27 # undef  STATIC_INLINE
28 # define STATIC_INLINE static
29 #endif
30
31 #include "rts/Types.h"
32
33 #if __GNUC__ >= 3
34 /* Assume that a flexible array member at the end of a struct
35  * can be defined thus: T arr[]; */
36 #define FLEXIBLE_ARRAY
37 #else
38 /* Assume that it must be defined thus: T arr[0]; */
39 #define FLEXIBLE_ARRAY 0
40 #endif
41
42 #if __GNUC__ >= 3
43 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
44 #else
45 #define ATTRIBUTE_ALIGNED(n) /*nothing*/
46 #endif
47
48 /* Fix for mingw stat problem (done here so it's early enough) */
49 #ifdef mingw32_HOST_OS
50 #define __MSVCRT__ 1
51 #endif
52
53 /* Needed to get the macro version of errno on some OSs, and also to
54    get prototypes for the _r versions of C library functions. */
55 #ifndef _REENTRANT
56 #define _REENTRANT 1
57 #endif
58
59 /*
60  * We often want to know the size of something in units of an
61  * StgWord... (rounded up, of course!)
62  */
63 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
64
65 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
66
67 /* -----------------------------------------------------------------------------
68    Assertions and Debuggery
69
70    CHECK(p)   evaluates p and terminates with an error if p is false
71    ASSERT(p)  like CHECK(p) if DEBUG is on, otherwise a no-op
72    -------------------------------------------------------------------------- */
73
74 void _assertFail(const char *filename, unsigned int linenum)
75    GNUC3_ATTRIBUTE(__noreturn__);
76
77 #define CHECK(predicate)                        \
78         if (predicate)                          \
79             /*null*/;                           \
80         else                                    \
81             _assertFail(__FILE__, __LINE__)
82
83 #ifndef DEBUG
84 #define ASSERT(predicate) /* nothing */
85 #else
86 #define ASSERT(predicate) CHECK(predicate)
87 #endif /* DEBUG */
88
89 /* 
90  * Use this on the RHS of macros which expand to nothing
91  * to make sure that the macro can be used in a context which
92  * demands a non-empty statement.
93  */
94
95 #define doNothing() do { } while (0)
96
97 #ifdef DEBUG
98 #define USED_IF_DEBUG
99 #define USED_IF_NOT_DEBUG STG_UNUSED
100 #else
101 #define USED_IF_DEBUG STG_UNUSED
102 #define USED_IF_NOT_DEBUG
103 #endif
104
105 #ifdef THREADED_RTS
106 #define USED_IF_THREADS
107 #define USED_IF_NOT_THREADS STG_UNUSED
108 #else
109 #define USED_IF_THREADS STG_UNUSED
110 #define USED_IF_NOT_THREADS
111 #endif
112
113 /*
114  * Getting printf formats right for platform-dependent typedefs
115  */
116 #if SIZEOF_LONG == 8
117 #define FMT_Word64 "lu"
118 #define FMT_Int64  "ld"
119 #else
120 #define FMT_Word64 "llu"
121 #define FMT_Int64  "lld"
122 #endif
123
124 /* -----------------------------------------------------------------------------
125    Include everything STG-ish
126    -------------------------------------------------------------------------- */
127
128 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
129  * come after MachRegs.h, because stdlib.h might define some inline
130  * functions which may only be defined after register variables have
131  * been declared.
132  */
133 #include <stdlib.h>
134
135 #include "rts/Config.h"
136
137 /* Global constaints */
138 #include "rts/Constants.h"
139
140 /* Profiling information */
141 #include "rts/prof/CCS.h"
142 #include "rts/prof/LDV.h"
143
144 /* Parallel information */
145 #include "rts/OSThreads.h"
146 #include "rts/SpinLock.h"
147
148 #include "rts/Messages.h"
149
150 /* Storage format definitions */
151 #include "rts/storage/FunTypes.h"
152 #include "rts/storage/InfoTables.h"
153 #include "rts/storage/Closures.h"
154 #include "rts/storage/Liveness.h"
155 #include "rts/storage/ClosureTypes.h"
156 #include "rts/storage/TSO.h"
157 #include "stg/MiscClosures.h" /* InfoTables, closures etc. defined in the RTS */
158 #include "rts/storage/SMPClosureOps.h"
159 #include "rts/storage/Block.h"
160 #include "rts/storage/ClosureMacros.h"
161 #include "rts/storage/MBlock.h"
162 #include "rts/storage/GC.h"
163
164 /* Other RTS external APIs */
165 #include "rts/Parallel.h"
166 #include "rts/Hooks.h"
167 #include "rts/Signals.h"
168 #include "rts/Hpc.h"
169 #include "rts/Flags.h"
170 #include "rts/Adjustor.h"
171 #include "rts/FileLock.h"
172 #include "rts/Globals.h"
173 #include "rts/IOManager.h"
174 #include "rts/Linker.h"
175 #include "rts/Threads.h"
176 #include "rts/Ticky.h"
177 #include "rts/Timer.h"
178 #include "rts/Stable.h"
179
180 /* Misc stuff without a home */
181 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
182 DLL_IMPORT_RTS extern int    prog_argc;
183 DLL_IMPORT_RTS extern char  *prog_name;
184
185 void stackOverflow(void);
186
187 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
188
189 #ifndef mingw32_HOST_OS
190 int stg_sig_install (int, int, void *);
191 #endif
192
193 /* -----------------------------------------------------------------------------
194    RTS Exit codes
195    -------------------------------------------------------------------------- */
196
197 /* 255 is allegedly used by dynamic linkers to report linking failure */
198 #define EXIT_INTERNAL_ERROR 254
199 #define EXIT_DEADLOCK       253
200 #define EXIT_INTERRUPTED    252
201 #define EXIT_HEAPOVERFLOW   251
202 #define EXIT_KILLED         250
203
204 /* -----------------------------------------------------------------------------
205    Miscellaneous garbage
206    -------------------------------------------------------------------------- */
207
208 /* declarations for runtime flags/values */
209 #define MAX_RTS_ARGS 32
210
211 #ifdef DEBUG
212 #define TICK_VAR(arity) \
213   extern StgInt SLOW_CALLS_##arity; \
214   extern StgInt RIGHT_ARITY_##arity; \
215   extern StgInt TAGGED_PTR_##arity;
216
217 extern StgInt TOTAL_CALLS;
218
219 TICK_VAR(1)
220 TICK_VAR(2)
221 #endif
222
223 /* -----------------------------------------------------------------------------
224    Assertions and Debuggery
225    -------------------------------------------------------------------------- */
226
227 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
228
229 #ifdef DEBUG
230 #if IN_STG_CODE
231 #define IF_DEBUG(c,s)  if (RtsFlags[0].DebugFlags.c) { s; }
232 #else
233 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
234 #endif
235 #else
236 #define IF_DEBUG(c,s)  doNothing()
237 #endif
238
239 #ifdef DEBUG
240 #define DEBUG_ONLY(s) s
241 #else
242 #define DEBUG_ONLY(s) doNothing()
243 #endif
244
245 /* -----------------------------------------------------------------------------
246    Useful macros and inline functions
247    -------------------------------------------------------------------------- */
248
249 #if defined(__GNUC__)
250 #define SUPPORTS_TYPEOF
251 #endif
252
253 #if defined(SUPPORTS_TYPEOF)
254 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
255 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
256 #else
257 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
258 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
259 #endif
260
261 /* -------------------------------------------------------------------------- */
262
263 #ifdef __cplusplus
264 }
265 #endif
266
267 #endif /* RTS_H */