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 /* Fix for mingw stat problem (done here so it's early enough) */
52 #ifdef mingw32_HOST_OS
56 /* Needed to get the macro version of errno on some OSs, and also to
57 get prototypes for the _r versions of C library functions. */
63 * We often want to know the size of something in units of an
64 * StgWord... (rounded up, of course!)
66 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
68 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
70 /* -----------------------------------------------------------------------------
71 Assertions and Debuggery
73 CHECK(p) evaluates p and terminates with an error if p is false
74 ASSERT(p) like CHECK(p) if DEBUG is on, otherwise a no-op
75 -------------------------------------------------------------------------- */
77 void _assertFail(const char *filename, unsigned int linenum)
78 GNUC3_ATTRIBUTE(__noreturn__);
80 #define CHECK(predicate) \
84 _assertFail(__FILE__, __LINE__)
87 #define ASSERT(predicate) /* nothing */
89 #define ASSERT(predicate) CHECK(predicate)
93 * Use this on the RHS of macros which expand to nothing
94 * to make sure that the macro can be used in a context which
95 * demands a non-empty statement.
98 #define doNothing() do { } while (0)
101 #define USED_IF_DEBUG
102 #define USED_IF_NOT_DEBUG STG_UNUSED
104 #define USED_IF_DEBUG STG_UNUSED
105 #define USED_IF_NOT_DEBUG
109 #define USED_IF_THREADS
110 #define USED_IF_NOT_THREADS STG_UNUSED
112 #define USED_IF_THREADS STG_UNUSED
113 #define USED_IF_NOT_THREADS
117 * Getting printf formats right for platform-dependent typedefs
120 #define FMT_Word64 "lu"
121 #define FMT_Int64 "ld"
123 #define FMT_Word64 "llu"
124 #define FMT_Int64 "lld"
127 /* -----------------------------------------------------------------------------
128 Include everything STG-ish
129 -------------------------------------------------------------------------- */
131 /* System headers: stdlib.h is eeded so that we can use NULL. It must
132 * come after MachRegs.h, because stdlib.h might define some inline
133 * functions which may only be defined after register variables have
138 #include "rts/Config.h"
140 /* Global constaints */
141 #include "rts/Constants.h"
143 /* Profiling information */
144 #include "rts/prof/CCS.h"
145 #include "rts/prof/LDV.h"
147 /* Parallel information */
148 #include "rts/OSThreads.h"
149 #include "rts/SpinLock.h"
151 #include "rts/Messages.h"
153 /* Storage format definitions */
154 #include "rts/storage/FunTypes.h"
155 #include "rts/storage/InfoTables.h"
156 #include "rts/storage/Closures.h"
157 #include "rts/storage/Liveness.h"
158 #include "rts/storage/ClosureTypes.h"
159 #include "rts/storage/TSO.h"
160 #include "stg/MiscClosures.h" /* InfoTables, closures etc. defined in the RTS */
161 #include "rts/storage/SMPClosureOps.h"
162 #include "rts/storage/Block.h"
163 #include "rts/storage/ClosureMacros.h"
164 #include "rts/storage/MBlock.h"
165 #include "rts/storage/GC.h"
167 /* Other RTS external APIs */
168 #include "rts/Parallel.h"
169 #include "rts/Hooks.h"
170 #include "rts/Signals.h"
171 #include "rts/BlockSignals.h"
173 #include "rts/Flags.h"
174 #include "rts/Adjustor.h"
175 #include "rts/FileLock.h"
176 #include "rts/Globals.h"
177 #include "rts/IOManager.h"
178 #include "rts/Linker.h"
179 #include "rts/Threads.h"
180 #include "rts/Ticky.h"
181 #include "rts/Timer.h"
182 #include "rts/Stable.h"
184 #include "rts/Utils.h"
185 #include "rts/PrimFloat.h"
187 /* Misc stuff without a home */
188 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
189 DLL_IMPORT_RTS extern int prog_argc;
190 DLL_IMPORT_RTS extern char *prog_name;
192 void stackOverflow(void);
194 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
196 #ifndef mingw32_HOST_OS
197 int stg_sig_install (int, int, void *);
200 /* -----------------------------------------------------------------------------
202 -------------------------------------------------------------------------- */
204 /* 255 is allegedly used by dynamic linkers to report linking failure */
205 #define EXIT_INTERNAL_ERROR 254
206 #define EXIT_DEADLOCK 253
207 #define EXIT_INTERRUPTED 252
208 #define EXIT_HEAPOVERFLOW 251
209 #define EXIT_KILLED 250
211 /* -----------------------------------------------------------------------------
212 Miscellaneous garbage
213 -------------------------------------------------------------------------- */
215 /* declarations for runtime flags/values */
216 #define MAX_RTS_ARGS 32
219 #define TICK_VAR(arity) \
220 extern StgInt SLOW_CALLS_##arity; \
221 extern StgInt RIGHT_ARITY_##arity; \
222 extern StgInt TAGGED_PTR_##arity;
224 extern StgInt TOTAL_CALLS;
230 /* -----------------------------------------------------------------------------
231 Assertions and Debuggery
232 -------------------------------------------------------------------------- */
234 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
238 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
240 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
243 #define IF_DEBUG(c,s) doNothing()
247 #define DEBUG_ONLY(s) s
249 #define DEBUG_ONLY(s) doNothing()
252 /* -----------------------------------------------------------------------------
253 Useful macros and inline functions
254 -------------------------------------------------------------------------- */
256 #if defined(__GNUC__)
257 #define SUPPORTS_TYPEOF
260 #if defined(SUPPORTS_TYPEOF)
261 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
262 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
264 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
265 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
268 /* -------------------------------------------------------------------------- */