1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2009
5 * RTS external APIs. This file declares everything that the GHC RTS
8 * ---------------------------------------------------------------------------*/
25 // Turn off inlining when debugging - it obfuscates things
28 # define STATIC_INLINE static
31 #include "rts/Types.h"
34 /* Assume that a flexible array member at the end of a struct
35 * can be defined thus: T arr[]; */
36 #define FLEXIBLE_ARRAY
38 /* Assume that it must be defined thus: T arr[0]; */
39 #define FLEXIBLE_ARRAY 0
43 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
45 #define ATTRIBUTE_ALIGNED(n) /*nothing*/
48 /* Fix for mingw stat problem (done here so it's early enough) */
49 #ifdef mingw32_HOST_OS
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. */
60 * We often want to know the size of something in units of an
61 * StgWord... (rounded up, of course!)
63 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
65 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
67 /* -----------------------------------------------------------------------------
68 Assertions and Debuggery
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 -------------------------------------------------------------------------- */
74 void _assertFail(const char *filename, unsigned int linenum)
75 GNUC3_ATTRIBUTE(__noreturn__);
77 #define CHECK(predicate) \
81 _assertFail(__FILE__, __LINE__)
84 #define ASSERT(predicate) /* nothing */
86 #define ASSERT(predicate) CHECK(predicate)
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.
95 #define doNothing() do { } while (0)
99 #define USED_IF_NOT_DEBUG STG_UNUSED
101 #define USED_IF_DEBUG STG_UNUSED
102 #define USED_IF_NOT_DEBUG
106 #define USED_IF_THREADS
107 #define USED_IF_NOT_THREADS STG_UNUSED
109 #define USED_IF_THREADS STG_UNUSED
110 #define USED_IF_NOT_THREADS
114 * Getting printf formats right for platform-dependent typedefs
117 #define FMT_Word64 "lu"
118 #define FMT_Int64 "ld"
120 #define FMT_Word64 "llu"
121 #define FMT_Int64 "lld"
124 /* -----------------------------------------------------------------------------
125 Include everything STG-ish
126 -------------------------------------------------------------------------- */
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
135 #include "rts/Config.h"
137 /* Global constaints */
138 #include "rts/Constants.h"
140 /* Profiling information */
141 #include "rts/prof/CCS.h"
142 #include "rts/prof/LDV.h"
144 /* Parallel information */
145 #include "rts/OSThreads.h"
146 #include "rts/SpinLock.h"
148 #include "rts/Messages.h"
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"
164 /* Other RTS external APIs */
165 #include "rts/Parallel.h"
166 #include "rts/Hooks.h"
167 #include "rts/Signals.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"
181 /* Misc stuff without a home */
182 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
183 DLL_IMPORT_RTS extern int prog_argc;
184 DLL_IMPORT_RTS extern char *prog_name;
186 void stackOverflow(void);
188 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
190 #ifndef mingw32_HOST_OS
191 int stg_sig_install (int, int, void *);
194 /* -----------------------------------------------------------------------------
196 -------------------------------------------------------------------------- */
198 /* 255 is allegedly used by dynamic linkers to report linking failure */
199 #define EXIT_INTERNAL_ERROR 254
200 #define EXIT_DEADLOCK 253
201 #define EXIT_INTERRUPTED 252
202 #define EXIT_HEAPOVERFLOW 251
203 #define EXIT_KILLED 250
205 /* -----------------------------------------------------------------------------
206 Miscellaneous garbage
207 -------------------------------------------------------------------------- */
209 /* declarations for runtime flags/values */
210 #define MAX_RTS_ARGS 32
213 #define TICK_VAR(arity) \
214 extern StgInt SLOW_CALLS_##arity; \
215 extern StgInt RIGHT_ARITY_##arity; \
216 extern StgInt TAGGED_PTR_##arity;
218 extern StgInt TOTAL_CALLS;
224 /* -----------------------------------------------------------------------------
225 Assertions and Debuggery
226 -------------------------------------------------------------------------- */
228 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
232 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
234 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
237 #define IF_DEBUG(c,s) doNothing()
241 #define DEBUG_ONLY(s) s
243 #define DEBUG_ONLY(s) doNothing()
246 /* -----------------------------------------------------------------------------
247 Useful macros and inline functions
248 -------------------------------------------------------------------------- */
250 #if defined(__GNUC__)
251 #define SUPPORTS_TYPEOF
254 #if defined(SUPPORTS_TYPEOF)
255 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
256 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
258 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
259 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
262 /* -------------------------------------------------------------------------- */