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"
172 #include "rts/Flags.h"
173 #include "rts/Adjustor.h"
174 #include "rts/FileLock.h"
175 #include "rts/Globals.h"
176 #include "rts/IOManager.h"
177 #include "rts/Linker.h"
178 #include "rts/Threads.h"
179 #include "rts/Ticky.h"
180 #include "rts/Timer.h"
181 #include "rts/Stable.h"
184 /* Misc stuff without a home */
185 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
186 DLL_IMPORT_RTS extern int prog_argc;
187 DLL_IMPORT_RTS extern char *prog_name;
189 void stackOverflow(void);
191 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
193 #ifndef mingw32_HOST_OS
194 int stg_sig_install (int, int, void *);
197 /* -----------------------------------------------------------------------------
199 -------------------------------------------------------------------------- */
201 /* 255 is allegedly used by dynamic linkers to report linking failure */
202 #define EXIT_INTERNAL_ERROR 254
203 #define EXIT_DEADLOCK 253
204 #define EXIT_INTERRUPTED 252
205 #define EXIT_HEAPOVERFLOW 251
206 #define EXIT_KILLED 250
208 /* -----------------------------------------------------------------------------
209 Miscellaneous garbage
210 -------------------------------------------------------------------------- */
212 /* declarations for runtime flags/values */
213 #define MAX_RTS_ARGS 32
216 #define TICK_VAR(arity) \
217 extern StgInt SLOW_CALLS_##arity; \
218 extern StgInt RIGHT_ARITY_##arity; \
219 extern StgInt TAGGED_PTR_##arity;
221 extern StgInt TOTAL_CALLS;
227 /* -----------------------------------------------------------------------------
228 Assertions and Debuggery
229 -------------------------------------------------------------------------- */
231 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
235 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
237 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
240 #define IF_DEBUG(c,s) doNothing()
244 #define DEBUG_ONLY(s) s
246 #define DEBUG_ONLY(s) doNothing()
249 /* -----------------------------------------------------------------------------
250 Useful macros and inline functions
251 -------------------------------------------------------------------------- */
253 #if defined(__GNUC__)
254 #define SUPPORTS_TYPEOF
257 #if defined(SUPPORTS_TYPEOF)
258 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
259 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
261 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
262 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
265 /* -------------------------------------------------------------------------- */