1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2009
5 * RTS external APIs. This file declares everything that the GHC RTS
8 * To understand the structure of the RTS headers, see the wiki:
9 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
11 * ---------------------------------------------------------------------------*/
28 // Turn off inlining when debugging - it obfuscates things
31 # define STATIC_INLINE static
34 #include "rts/Types.h"
37 /* Assume that a flexible array member at the end of a struct
38 * can be defined thus: T arr[]; */
39 #define FLEXIBLE_ARRAY
41 /* Assume that it must be defined thus: T arr[0]; */
42 #define FLEXIBLE_ARRAY 0
46 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
48 #define ATTRIBUTE_ALIGNED(n) /*nothing*/
51 // Symbols that are extern, but private to the RTS, are declared
52 // with visibility "hidden" to hide them outside the RTS shared
54 #if !defined(mingw32_HOST_OS)
55 #define RTS_PRIVATE GNUC3_ATTRIBUTE(visibility("hidden"))
57 #define RTS_PRIVATE /* disabled: RTS_PRIVATE */
61 #define BEGIN_RTS_PRIVATE #pragma GCC visibility push(hidden)
62 #define END_RTS_PRIVATE #pragma GCC visibility pop
64 #define BEGIN_RTS_PRIVATE /* disabled: BEGIN_RTS_PRIVATE */
65 #define END_RTS_PRIVATE /* disabled: END_RTS_PRIVATE */
69 #define RTS_UNLIKELY(p) __builtin_expect((p),0)
71 #define RTS_UNLIKELY(p) p
74 /* Fix for mingw stat problem (done here so it's early enough) */
75 #ifdef mingw32_HOST_OS
79 /* Needed to get the macro version of errno on some OSs, and also to
80 get prototypes for the _r versions of C library functions. */
86 * We often want to know the size of something in units of an
87 * StgWord... (rounded up, of course!)
89 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
91 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
93 /* -----------------------------------------------------------------------------
94 Assertions and Debuggery
96 CHECK(p) evaluates p and terminates with an error if p is false
97 ASSERT(p) like CHECK(p) if DEBUG is on, otherwise a no-op
98 -------------------------------------------------------------------------- */
100 void _assertFail(const char *filename, unsigned int linenum)
101 GNUC3_ATTRIBUTE(__noreturn__);
103 #define CHECK(predicate) \
107 _assertFail(__FILE__, __LINE__)
110 #define ASSERT(predicate) /* nothing */
112 #define ASSERT(predicate) CHECK(predicate)
116 * Use this on the RHS of macros which expand to nothing
117 * to make sure that the macro can be used in a context which
118 * demands a non-empty statement.
121 #define doNothing() do { } while (0)
124 #define USED_IF_DEBUG
125 #define USED_IF_NOT_DEBUG STG_UNUSED
127 #define USED_IF_DEBUG STG_UNUSED
128 #define USED_IF_NOT_DEBUG
132 #define USED_IF_THREADS
133 #define USED_IF_NOT_THREADS STG_UNUSED
135 #define USED_IF_THREADS STG_UNUSED
136 #define USED_IF_NOT_THREADS
140 * Getting printf formats right for platform-dependent typedefs
143 #define FMT_Word64 "lu"
144 #define FMT_Int64 "ld"
146 #define FMT_Word64 "llu"
147 #define FMT_Int64 "lld"
150 /* -----------------------------------------------------------------------------
151 Include everything STG-ish
152 -------------------------------------------------------------------------- */
154 /* System headers: stdlib.h is eeded so that we can use NULL. It must
155 * come after MachRegs.h, because stdlib.h might define some inline
156 * functions which may only be defined after register variables have
161 #include "rts/Config.h"
163 /* Global constaints */
164 #include "rts/Constants.h"
166 /* Profiling information */
167 #include "rts/prof/CCS.h"
168 #include "rts/prof/LDV.h"
170 /* Parallel information */
171 #include "rts/OSThreads.h"
172 #include "rts/SpinLock.h"
174 #include "rts/Messages.h"
176 /* Storage format definitions */
177 #include "rts/storage/FunTypes.h"
178 #include "rts/storage/InfoTables.h"
179 #include "rts/storage/Closures.h"
180 #include "rts/storage/Liveness.h"
181 #include "rts/storage/ClosureTypes.h"
182 #include "rts/storage/TSO.h"
183 #include "stg/MiscClosures.h" /* InfoTables, closures etc. defined in the RTS */
184 #include "rts/storage/SMPClosureOps.h"
185 #include "rts/storage/Block.h"
186 #include "rts/storage/ClosureMacros.h"
187 #include "rts/storage/MBlock.h"
188 #include "rts/storage/GC.h"
190 /* Other RTS external APIs */
191 #include "rts/Parallel.h"
192 #include "rts/Hooks.h"
193 #include "rts/Signals.h"
194 #include "rts/BlockSignals.h"
196 #include "rts/Flags.h"
197 #include "rts/Adjustor.h"
198 #include "rts/FileLock.h"
199 #include "rts/Globals.h"
200 #include "rts/IOManager.h"
201 #include "rts/Linker.h"
202 #include "rts/Threads.h"
203 #include "rts/Ticky.h"
204 #include "rts/Timer.h"
205 #include "rts/Stable.h"
207 #include "rts/Utils.h"
208 #include "rts/PrimFloat.h"
210 /* Misc stuff without a home */
211 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
212 DLL_IMPORT_RTS extern int prog_argc;
213 DLL_IMPORT_RTS extern char *prog_name;
215 void stackOverflow(void);
217 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
219 #ifndef mingw32_HOST_OS
220 int stg_sig_install (int, int, void *);
223 /* -----------------------------------------------------------------------------
225 -------------------------------------------------------------------------- */
227 /* 255 is allegedly used by dynamic linkers to report linking failure */
228 #define EXIT_INTERNAL_ERROR 254
229 #define EXIT_DEADLOCK 253
230 #define EXIT_INTERRUPTED 252
231 #define EXIT_HEAPOVERFLOW 251
232 #define EXIT_KILLED 250
234 /* -----------------------------------------------------------------------------
235 Miscellaneous garbage
236 -------------------------------------------------------------------------- */
238 /* declarations for runtime flags/values */
239 #define MAX_RTS_ARGS 32
242 #define TICK_VAR(arity) \
243 extern StgInt SLOW_CALLS_##arity; \
244 extern StgInt RIGHT_ARITY_##arity; \
245 extern StgInt TAGGED_PTR_##arity;
247 extern StgInt TOTAL_CALLS;
253 /* -----------------------------------------------------------------------------
254 Assertions and Debuggery
255 -------------------------------------------------------------------------- */
257 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
261 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
263 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
266 #define IF_DEBUG(c,s) doNothing()
270 #define DEBUG_ONLY(s) s
272 #define DEBUG_ONLY(s) doNothing()
275 /* -----------------------------------------------------------------------------
276 Useful macros and inline functions
277 -------------------------------------------------------------------------- */
279 #if defined(__GNUC__)
280 #define SUPPORTS_TYPEOF
283 #if defined(SUPPORTS_TYPEOF)
284 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
285 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
287 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
288 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
291 /* -------------------------------------------------------------------------- */