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/Timer.h"
177 #include "rts/Stable.h"
179 /* Misc stuff without a home */
180 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
181 DLL_IMPORT_RTS extern int prog_argc;
182 DLL_IMPORT_RTS extern char *prog_name;
184 void stackOverflow(void);
186 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
188 #ifndef mingw32_HOST_OS
189 int stg_sig_install (int, int, void *);
192 /* -----------------------------------------------------------------------------
194 -------------------------------------------------------------------------- */
196 /* 255 is allegedly used by dynamic linkers to report linking failure */
197 #define EXIT_INTERNAL_ERROR 254
198 #define EXIT_DEADLOCK 253
199 #define EXIT_INTERRUPTED 252
200 #define EXIT_HEAPOVERFLOW 251
201 #define EXIT_KILLED 250
203 /* -----------------------------------------------------------------------------
204 Miscellaneous garbage
205 -------------------------------------------------------------------------- */
207 /* declarations for runtime flags/values */
208 #define MAX_RTS_ARGS 32
211 #define TICK_VAR(arity) \
212 extern StgInt SLOW_CALLS_##arity; \
213 extern StgInt RIGHT_ARITY_##arity; \
214 extern StgInt TAGGED_PTR_##arity;
216 extern StgInt TOTAL_CALLS;
222 /* -----------------------------------------------------------------------------
223 Assertions and Debuggery
224 -------------------------------------------------------------------------- */
226 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
230 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
232 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
235 #define IF_DEBUG(c,s) doNothing()
239 #define DEBUG_ONLY(s) s
241 #define DEBUG_ONLY(s) doNothing()
244 /* -----------------------------------------------------------------------------
245 Useful macros and inline functions
246 -------------------------------------------------------------------------- */
248 #if defined(__GNUC__)
249 #define SUPPORTS_TYPEOF
252 #if defined(SUPPORTS_TYPEOF)
253 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
254 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
256 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
257 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
260 /* -------------------------------------------------------------------------- */
267 /* krc: I put this here because I don't think
268 it needs to be visible externally.
269 It used to be in StgTicky.h, but I got rid
272 /* -----------------------------------------------------------------------------
273 The StgEntCounter type - needed regardless of TICKY_TICKY
274 -------------------------------------------------------------------------- */
276 typedef struct _StgEntCounter {
277 /* Using StgWord for everything, becuase both the C and asm code
278 generators make trouble if you try to pack things tighter */
279 StgWord registeredp; /* 0 == no, 1 == yes */
280 StgInt arity; /* arity (static info) */
281 StgInt stk_args; /* # of args off stack */
282 /* (rest of args are in registers) */
283 char *str; /* name of the thing */
284 char *arg_kinds; /* info about the args types */
285 StgInt entry_count; /* Trips to fast entry code */
286 StgInt allocs; /* number of allocations by this fun */
287 struct _StgEntCounter *link;/* link to chain them all together */