Fix memory leak from #12664
[ghc.git] / rts / StgMiscClosures.cmm
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Entry code for various built-in closure types.
6  *
7  * This file is written in a subset of C--, extended with various
8  * features specific to GHC.  It is compiled by GHC directly.  For the
9  * syntax of .cmm files, see the parser in ghc/compiler/cmm/CmmParse.y.
10  *
11  * --------------------------------------------------------------------------*/
12
13 #include "Cmm.h"
14
15 import pthread_mutex_lock;
16 import ghczmprim_GHCziTypes_Czh_static_info;
17 import ghczmprim_GHCziTypes_Izh_static_info;
18 import EnterCriticalSection;
19 import LeaveCriticalSection;
20
21 /* ----------------------------------------------------------------------------
22    Stack underflow
23    ------------------------------------------------------------------------- */
24
25 INFO_TABLE_RET (stg_stack_underflow_frame, UNDERFLOW_FRAME,
26                 W_ info_ptr, P_ unused)
27     /* no args => explicit stack */
28 {
29     W_ new_tso;
30     W_ ret_off;
31
32     SAVE_STGREGS
33
34     SAVE_THREAD_STATE();
35     (ret_off) = foreign "C" threadStackUnderflow(MyCapability() "ptr",
36                                                  CurrentTSO);
37     LOAD_THREAD_STATE();
38
39     RESTORE_STGREGS
40
41     jump %ENTRY_CODE(Sp(ret_off)) [*]; // NB. all registers live!
42 }
43
44 /* ----------------------------------------------------------------------------
45    Restore a saved cost centre
46    ------------------------------------------------------------------------- */
47
48 INFO_TABLE_RET (stg_restore_cccs, RET_SMALL, W_ info_ptr, W_ cccs)
49 {
50     unwind Sp = Sp + WDS(2);
51 #if defined(PROFILING)
52     CCCS = Sp(1);
53 #endif
54     Sp_adj(2);
55     jump %ENTRY_CODE(Sp(0)) [*]; // NB. all registers live!
56 }
57
58 /* ----------------------------------------------------------------------------
59    Support for the bytecode interpreter.
60    ------------------------------------------------------------------------- */
61
62 /* 7 bits of return code for constructors created by the interpreter. */
63 stg_interp_constr1_entry (P_ ret) { return (ret + 1); }
64 stg_interp_constr2_entry (P_ ret) { return (ret + 2); }
65 stg_interp_constr3_entry (P_ ret) { return (ret + 3); }
66 stg_interp_constr4_entry (P_ ret) { return (ret + 4); }
67 stg_interp_constr5_entry (P_ ret) { return (ret + 5); }
68 stg_interp_constr6_entry (P_ ret) { return (ret + 6); }
69 stg_interp_constr7_entry (P_ ret) { return (ret + 7); }
70
71 /* Some info tables to be used when compiled code returns a value to
72    the interpreter, i.e. the interpreter pushes one of these onto the
73    stack before entering a value.  What the code does is to
74    impedance-match the compiled return convention (in R1p/R1n/F1/D1 etc) to
75    the interpreter's convention (returned value is on top of stack),
76    and then cause the scheduler to enter the interpreter.
77
78    On entry, the stack (growing down) looks like this:
79
80       ptr to BCO holding return continuation
81       ptr to one of these info tables.
82
83    The info table code, both direct and vectored, must:
84       * push R1/F1/D1 on the stack, and its tag if necessary
85       * push the BCO (so it's now on the stack twice)
86       * Yield, ie, go to the scheduler.
87
88    Scheduler examines the t.o.s, discovers it is a BCO, and proceeds
89    directly to the bytecode interpreter.  That pops the top element
90    (the BCO, containing the return continuation), and interprets it.
91    Net result: return continuation gets interpreted, with the
92    following stack:
93
94       ptr to this BCO
95       ptr to the info table just jumped thru
96       return value
97
98    which is just what we want -- the "standard" return layout for the
99    interpreter.  Hurrah!
100
101    Don't ask me how unboxed tuple returns are supposed to work.  We
102    haven't got a good story about that yet.
103 */
104
105 INFO_TABLE_RET( stg_ctoi_R1p, RET_BCO)
106     /* explicit stack */
107 {
108     Sp_adj(-2);
109     Sp(1) = R1;
110     Sp(0) = stg_enter_info;
111     jump stg_yield_to_interpreter [];
112 }
113
114 /*
115  * When the returned value is a pointer, but unlifted, in R1 ...
116  */
117 INFO_TABLE_RET( stg_ctoi_R1unpt, RET_BCO )
118     /* explicit stack */
119 {
120     Sp_adj(-2);
121     Sp(1) = R1;
122     Sp(0) = stg_ret_p_info;
123     jump stg_yield_to_interpreter [];
124 }
125
126 /*
127  * When the returned value is a non-pointer in R1 ...
128  */
129 INFO_TABLE_RET( stg_ctoi_R1n, RET_BCO )
130     /* explicit stack */
131 {
132     Sp_adj(-2);
133     Sp(1) = R1;
134     Sp(0) = stg_ret_n_info;
135     jump stg_yield_to_interpreter [];
136 }
137
138 /*
139  * When the returned value is in F1
140  */
141 INFO_TABLE_RET( stg_ctoi_F1, RET_BCO )
142     /* explicit stack */
143 {
144     Sp_adj(-2);
145     F_[Sp + WDS(1)] = F1;
146     Sp(0) = stg_ret_f_info;
147     jump stg_yield_to_interpreter [];
148 }
149
150 /*
151  * When the returned value is in D1
152  */
153 INFO_TABLE_RET( stg_ctoi_D1, RET_BCO )
154     /* explicit stack */
155 {
156     Sp_adj(-1) - SIZEOF_DOUBLE;
157     D_[Sp + WDS(1)] = D1;
158     Sp(0) = stg_ret_d_info;
159     jump stg_yield_to_interpreter [];
160 }
161
162 /*
163  * When the returned value is in L1
164  */
165 INFO_TABLE_RET( stg_ctoi_L1, RET_BCO )
166     /* explicit stack */
167 {
168     Sp_adj(-1) - 8;
169     L_[Sp + WDS(1)] = L1;
170     Sp(0) = stg_ret_l_info;
171     jump stg_yield_to_interpreter [];
172 }
173
174 /*
175  * When the returned value is a void
176  */
177 INFO_TABLE_RET( stg_ctoi_V, RET_BCO )
178     /* explicit stack */
179 {
180     Sp_adj(-1);
181     Sp(0) = stg_ret_v_info;
182     jump stg_yield_to_interpreter [];
183 }
184
185 /*
186  * Dummy info table pushed on the top of the stack when the interpreter
187  * should apply the BCO on the stack to its arguments, also on the
188  * stack.
189  */
190 INFO_TABLE_RET( stg_apply_interp, RET_BCO )
191     /* explicit stack */
192 {
193     /* Just in case we end up in here... (we shouldn't) */
194     jump stg_yield_to_interpreter [];
195 }
196
197 /* ----------------------------------------------------------------------------
198    Entry code for a BCO
199    ------------------------------------------------------------------------- */
200
201 INFO_TABLE_FUN( stg_BCO, 4, 0, BCO, "BCO", "BCO", ARG_BCO )
202     /* explicit stack */
203 {
204   /* entering a BCO means "apply it", same as a function */
205   Sp_adj(-2);
206   // Skip the stack check; the interpreter will do one before using
207   // the stack anyway.
208   Sp(1) = R1;
209   Sp(0) = stg_apply_interp_info;
210   jump stg_yield_to_interpreter [];
211 }
212
213 /* ----------------------------------------------------------------------------
214    Info tables for indirections.
215
216    SPECIALISED INDIRECTIONS: we have a specialised indirection for direct returns,
217    so that we can avoid entering
218    the object when we know it points directly to a value.  The update
219    code (Updates.cmm) updates objects with the appropriate kind of
220    indirection.  We only do this for young-gen indirections.
221    ------------------------------------------------------------------------- */
222
223 INFO_TABLE(stg_IND,1,0,IND,"IND","IND")
224 #if 0
225 /*
226   This version in high-level cmm generates slightly less good code
227   than the low-level version below it. (ToDo)
228 */
229     (P_ node)
230 {
231     TICK_ENT_DYN_IND(); /* tick */
232     node = UNTAG(StgInd_indirectee(node));
233     TICK_ENT_VIA_NODE();
234     jump %GET_ENTRY(node) (node);
235 }
236 #else
237     /* explicit stack */
238 {
239     TICK_ENT_DYN_IND(); /* tick */
240     R1 = UNTAG(StgInd_indirectee(R1));
241     TICK_ENT_VIA_NODE();
242     jump %GET_ENTRY(R1) [R1];
243 }
244 #endif
245
246 INFO_TABLE(stg_IND_direct,1,0,IND,"IND","IND")
247     (P_ node)
248 {
249     TICK_ENT_DYN_IND(); /* tick */
250     node = StgInd_indirectee(node);
251     TICK_ENT_VIA_NODE();
252     jump %ENTRY_CODE(Sp(0)) (node);
253 }
254
255 INFO_TABLE(stg_IND_STATIC,1,0,IND_STATIC,"IND_STATIC","IND_STATIC")
256     /* explicit stack */
257 {
258     TICK_ENT_STATIC_IND(); /* tick */
259     R1 = UNTAG(StgInd_indirectee(R1));
260     TICK_ENT_VIA_NODE();
261     jump %GET_ENTRY(R1) [R1];
262 }
263
264 /* ----------------------------------------------------------------------------
265    Black holes.
266
267    Entering a black hole normally causes a cyclic data dependency, but
268    in the concurrent world, black holes are synchronization points,
269    and they are turned into blocking queues when there are threads
270    waiting for the evaluation of the closure to finish.
271    ------------------------------------------------------------------------- */
272
273 INFO_TABLE(stg_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
274     (P_ node)
275 {
276     W_ r, info, owner, bd;
277     P_ p, bq, msg;
278
279     TICK_ENT_DYN_IND(); /* tick */
280
281 retry:
282     p = StgInd_indirectee(node);
283     if (GETTAG(p) != 0) {
284         return (p);
285     }
286
287     info = StgHeader_info(p);
288     if (info == stg_IND_info) {
289         // This could happen, if e.g. we got a BLOCKING_QUEUE that has
290         // just been replaced with an IND by another thread in
291         // wakeBlockingQueue().
292         goto retry;
293     }
294
295     if (info == stg_TSO_info ||
296         info == stg_BLOCKING_QUEUE_CLEAN_info ||
297         info == stg_BLOCKING_QUEUE_DIRTY_info)
298     {
299         ("ptr" msg) = ccall allocate(MyCapability() "ptr",
300                                      BYTES_TO_WDS(SIZEOF_MessageBlackHole));
301
302         SET_HDR(msg, stg_MSG_BLACKHOLE_info, CCS_SYSTEM);
303         MessageBlackHole_tso(msg) = CurrentTSO;
304         MessageBlackHole_bh(msg) = node;
305
306         (r) = ccall messageBlackHole(MyCapability() "ptr", msg "ptr");
307
308         if (r == 0) {
309             goto retry;
310         } else {
311             StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16;
312             StgTSO_block_info(CurrentTSO) = msg;
313             jump stg_block_blackhole(node);
314         }
315     }
316     else
317     {
318         ENTER(p);
319     }
320 }
321
322 // CAF_BLACKHOLE is allocated when entering a CAF.  The reason it is
323 // distinct from BLACKHOLE is so that we can tell the difference
324 // between an update frame on the stack that points to a CAF under
325 // evaluation, and one that points to a closure that is under
326 // evaluation by another thread (a BLACKHOLE).  see Note [suspend
327 // duplicate work] in ThreadPaused.c
328 //
329 INFO_TABLE(stg_CAF_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
330     (P_ node)
331 {
332     jump ENTRY_LBL(stg_BLACKHOLE) (node);
333 }
334
335 // EAGER_BLACKHOLE exists for the same reason as CAF_BLACKHOLE (see above).
336 INFO_TABLE(__stg_EAGER_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
337     (P_ node)
338 {
339     jump ENTRY_LBL(stg_BLACKHOLE) (node);
340 }
341
342 INFO_TABLE(stg_BLOCKING_QUEUE_CLEAN,4,0,BLOCKING_QUEUE,"BLOCKING_QUEUE","BLOCKING_QUEUE")
343 { foreign "C" barf("BLOCKING_QUEUE_CLEAN object entered!") never returns; }
344
345
346 INFO_TABLE(stg_BLOCKING_QUEUE_DIRTY,4,0,BLOCKING_QUEUE,"BLOCKING_QUEUE","BLOCKING_QUEUE")
347 { foreign "C" barf("BLOCKING_QUEUE_DIRTY object entered!") never returns; }
348
349
350 /* ----------------------------------------------------------------------------
351    Whiteholes are used for the "locked" state of a closure (see lockClosure())
352    ------------------------------------------------------------------------- */
353
354 INFO_TABLE(stg_WHITEHOLE, 0,0, WHITEHOLE, "WHITEHOLE", "WHITEHOLE")
355     (P_ node)
356 {
357 #if defined(THREADED_RTS)
358     W_ info, i;
359
360     i = 0;
361 loop:
362     // spin until the WHITEHOLE is updated
363     info = StgHeader_info(node);
364     if (info == stg_WHITEHOLE_info) {
365         i = i + 1;
366         if (i == SPIN_COUNT) {
367             i = 0;
368             ccall yieldThread();
369         }
370         goto loop;
371     }
372     jump %ENTRY_CODE(info) (node);
373 #else
374     ccall barf("WHITEHOLE object entered!") never returns;
375 #endif
376 }
377
378 /* ----------------------------------------------------------------------------
379    Some static info tables for things that don't get entered, and
380    therefore don't need entry code (i.e. boxed but unpointed objects)
381    NON_ENTERABLE_ENTRY_CODE now defined at the beginning of the file
382    ------------------------------------------------------------------------- */
383
384 INFO_TABLE(stg_TSO, 0,0,TSO, "TSO", "TSO")
385 { foreign "C" barf("TSO object entered!") never returns; }
386
387 INFO_TABLE(stg_STACK, 0,0, STACK, "STACK", "STACK")
388 { foreign "C" barf("STACK object entered!") never returns; }
389
390 /* ----------------------------------------------------------------------------
391    Weak pointers
392
393    Live weak pointers have a special closure type.  Dead ones are just
394    nullary constructors (although they live on the heap - we overwrite
395    live weak pointers with dead ones).
396    ------------------------------------------------------------------------- */
397
398 INFO_TABLE(stg_WEAK,1,4,WEAK,"WEAK","WEAK")
399 { foreign "C" barf("WEAK object entered!") never returns; }
400
401 /*
402  * It's important when turning an existing WEAK into a DEAD_WEAK
403  * (which is what finalizeWeak# does) that we don't lose the link
404  * field and break the linked list of weak pointers.  Hence, we give
405  * DEAD_WEAK 5 non-pointer fields.
406  */
407 INFO_TABLE_CONSTR(stg_DEAD_WEAK,0,5,0,CONSTR,"DEAD_WEAK","DEAD_WEAK")
408 { foreign "C" barf("DEAD_WEAK object entered!") never returns; }
409
410 /* ----------------------------------------------------------------------------
411    C finalizer lists
412
413    Singly linked lists that chain multiple C finalizers on a weak pointer.
414    ------------------------------------------------------------------------- */
415
416 INFO_TABLE_CONSTR(stg_C_FINALIZER_LIST,1,4,0,CONSTR,"C_FINALIZER_LIST","C_FINALIZER_LIST")
417 { foreign "C" barf("C_FINALIZER_LIST object entered!") never returns; }
418
419 /* ----------------------------------------------------------------------------
420    NO_FINALIZER
421
422    This is a static nullary constructor (like []) that we use to mark an empty
423    finalizer in a weak pointer object.
424    ------------------------------------------------------------------------- */
425
426 INFO_TABLE_CONSTR(stg_NO_FINALIZER,0,0,0,CONSTR_NOCAF_STATIC,"NO_FINALIZER","NO_FINALIZER")
427 { foreign "C" barf("NO_FINALIZER object entered!") never returns; }
428
429 CLOSURE(stg_NO_FINALIZER_closure,stg_NO_FINALIZER);
430
431 /* ----------------------------------------------------------------------------
432    Stable Names are unlifted too.
433    ------------------------------------------------------------------------- */
434
435 INFO_TABLE(stg_STABLE_NAME,0,1,PRIM,"STABLE_NAME","STABLE_NAME")
436 { foreign "C" barf("STABLE_NAME object entered!") never returns; }
437
438 /* ----------------------------------------------------------------------------
439    MVars
440
441    There are two kinds of these: full and empty.  We need an info table
442    and entry code for each type.
443    ------------------------------------------------------------------------- */
444
445 INFO_TABLE(stg_MVAR_CLEAN,3,0,MVAR_CLEAN,"MVAR","MVAR")
446 { foreign "C" barf("MVAR object entered!") never returns; }
447
448 INFO_TABLE(stg_MVAR_DIRTY,3,0,MVAR_DIRTY,"MVAR","MVAR")
449 { foreign "C" barf("MVAR object entered!") never returns; }
450
451 /* -----------------------------------------------------------------------------
452    STM
453    -------------------------------------------------------------------------- */
454
455 INFO_TABLE(stg_TVAR_CLEAN, 2, 1, TVAR, "TVAR", "TVAR")
456 { foreign "C" barf("TVAR_CLEAN object entered!") never returns; }
457
458 INFO_TABLE(stg_TVAR_DIRTY, 2, 1, TVAR, "TVAR", "TVAR")
459 { foreign "C" barf("TVAR_DIRTY object entered!") never returns; }
460
461 INFO_TABLE(stg_TVAR_WATCH_QUEUE, 3, 0, MUT_PRIM, "TVAR_WATCH_QUEUE", "TVAR_WATCH_QUEUE")
462 { foreign "C" barf("TVAR_WATCH_QUEUE object entered!") never returns; }
463
464 INFO_TABLE(stg_ATOMIC_INVARIANT, 2, 1, MUT_PRIM, "ATOMIC_INVARIANT", "ATOMIC_INVARIANT")
465 { foreign "C" barf("ATOMIC_INVARIANT object entered!") never returns; }
466
467 INFO_TABLE(stg_INVARIANT_CHECK_QUEUE, 3, 0, MUT_PRIM, "INVARIANT_CHECK_QUEUE", "INVARIANT_CHECK_QUEUE")
468 { foreign "C" barf("INVARIANT_CHECK_QUEUE object entered!") never returns; }
469
470 INFO_TABLE(stg_TREC_CHUNK, 0, 0, TREC_CHUNK, "TREC_CHUNK", "TREC_CHUNK")
471 { foreign "C" barf("TREC_CHUNK object entered!") never returns; }
472
473 INFO_TABLE(stg_TREC_HEADER, 3, 1, MUT_PRIM, "TREC_HEADER", "TREC_HEADER")
474 { foreign "C" barf("TREC_HEADER object entered!") never returns; }
475
476 INFO_TABLE_CONSTR(stg_END_STM_WATCH_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_WATCH_QUEUE","END_STM_WATCH_QUEUE")
477 { foreign "C" barf("END_STM_WATCH_QUEUE object entered!") never returns; }
478
479 INFO_TABLE_CONSTR(stg_END_INVARIANT_CHECK_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_INVARIANT_CHECK_QUEUE","END_INVARIANT_CHECK_QUEUE")
480 { foreign "C" barf("END_INVARIANT_CHECK_QUEUE object entered!") never returns; }
481
482 INFO_TABLE_CONSTR(stg_END_STM_CHUNK_LIST,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_CHUNK_LIST","END_STM_CHUNK_LIST")
483 { foreign "C" barf("END_STM_CHUNK_LIST object entered!") never returns; }
484
485 INFO_TABLE_CONSTR(stg_NO_TREC,0,0,0,CONSTR_NOCAF_STATIC,"NO_TREC","NO_TREC")
486 { foreign "C" barf("NO_TREC object entered!") never returns; }
487
488 CLOSURE(stg_END_STM_WATCH_QUEUE_closure,stg_END_STM_WATCH_QUEUE);
489
490 CLOSURE(stg_END_INVARIANT_CHECK_QUEUE_closure,stg_END_INVARIANT_CHECK_QUEUE);
491
492 CLOSURE(stg_END_STM_CHUNK_LIST_closure,stg_END_STM_CHUNK_LIST);
493
494 CLOSURE(stg_NO_TREC_closure,stg_NO_TREC);
495
496 /* ----------------------------------------------------------------------------
497    Messages
498    ------------------------------------------------------------------------- */
499
500 // PRIM rather than CONSTR, because PRIM objects cannot be duplicated by the GC.
501
502 INFO_TABLE_CONSTR(stg_MSG_TRY_WAKEUP,2,0,0,PRIM,"MSG_TRY_WAKEUP","MSG_TRY_WAKEUP")
503 { foreign "C" barf("MSG_TRY_WAKEUP object entered!") never returns; }
504
505 INFO_TABLE_CONSTR(stg_MSG_THROWTO,4,0,0,PRIM,"MSG_THROWTO","MSG_THROWTO")
506 { foreign "C" barf("MSG_THROWTO object entered!") never returns; }
507
508 INFO_TABLE_CONSTR(stg_MSG_BLACKHOLE,3,0,0,PRIM,"MSG_BLACKHOLE","MSG_BLACKHOLE")
509 { foreign "C" barf("MSG_BLACKHOLE object entered!") never returns; }
510
511 // used to overwrite a MSG_THROWTO when the message has been used/revoked
512 INFO_TABLE_CONSTR(stg_MSG_NULL,1,0,0,PRIM,"MSG_NULL","MSG_NULL")
513 { foreign "C" barf("MSG_NULL object entered!") never returns; }
514
515 /* ----------------------------------------------------------------------------
516    END_TSO_QUEUE
517
518    This is a static nullary constructor (like []) that we use to mark the
519    end of a linked TSO queue.
520    ------------------------------------------------------------------------- */
521
522 INFO_TABLE_CONSTR(stg_END_TSO_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_TSO_QUEUE","END_TSO_QUEUE")
523 { foreign "C" barf("END_TSO_QUEUE object entered!") never returns; }
524
525 CLOSURE(stg_END_TSO_QUEUE_closure,stg_END_TSO_QUEUE);
526
527 /* ----------------------------------------------------------------------------
528    GCD_CAF
529    ------------------------------------------------------------------------- */
530
531 INFO_TABLE_CONSTR(stg_GCD_CAF,0,0,0,CONSTR_NOCAF_STATIC,"GCD_CAF","GCD_CAF")
532 { foreign "C" barf("Evaluated a CAF that was GC'd!") never returns; }
533
534 /* ----------------------------------------------------------------------------
535    STM_AWOKEN
536
537    This is a static nullary constructor (like []) that we use to mark a
538    thread waiting on an STM wakeup
539    ------------------------------------------------------------------------- */
540
541 INFO_TABLE_CONSTR(stg_STM_AWOKEN,0,0,0,CONSTR_NOCAF_STATIC,"STM_AWOKEN","STM_AWOKEN")
542 { foreign "C" barf("STM_AWOKEN object entered!") never returns; }
543
544 CLOSURE(stg_STM_AWOKEN_closure,stg_STM_AWOKEN);
545
546 /* ----------------------------------------------------------------------------
547    Arrays
548
549    These come in two basic flavours: arrays of data (StgArrWords) and arrays of
550    pointers (StgArrPtrs).  They all have a similar layout:
551
552    ___________________________
553    | Info | No. of | data....
554    |  Ptr | Words  |
555    ---------------------------
556
557    These are *unpointed* objects: i.e. they cannot be entered.
558
559    ------------------------------------------------------------------------- */
560
561 INFO_TABLE(stg_ARR_WORDS, 0, 0, ARR_WORDS, "ARR_WORDS", "ARR_WORDS")
562 { foreign "C" barf("ARR_WORDS object entered!") never returns; }
563
564 INFO_TABLE(stg_MUT_ARR_PTRS_CLEAN, 0, 0, MUT_ARR_PTRS_CLEAN, "MUT_ARR_PTRS_CLEAN", "MUT_ARR_PTRS_CLEAN")
565 { foreign "C" barf("MUT_ARR_PTRS_CLEAN object entered!") never returns; }
566
567 INFO_TABLE(stg_MUT_ARR_PTRS_DIRTY, 0, 0, MUT_ARR_PTRS_DIRTY, "MUT_ARR_PTRS_DIRTY", "MUT_ARR_PTRS_DIRTY")
568 { foreign "C" barf("MUT_ARR_PTRS_DIRTY object entered!") never returns; }
569
570 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN, 0, 0, MUT_ARR_PTRS_FROZEN, "MUT_ARR_PTRS_FROZEN", "MUT_ARR_PTRS_FROZEN")
571 { foreign "C" barf("MUT_ARR_PTRS_FROZEN object entered!") never returns; }
572
573 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN0, 0, 0, MUT_ARR_PTRS_FROZEN0, "MUT_ARR_PTRS_FROZEN0", "MUT_ARR_PTRS_FROZEN0")
574 { foreign "C" barf("MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
575
576 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_CLEAN, 0, 0, SMALL_MUT_ARR_PTRS_CLEAN, "SMALL_MUT_ARR_PTRS_CLEAN", "SMALL_MUT_ARR_PTRS_CLEAN")
577 { foreign "C" barf("SMALL_MUT_ARR_PTRS_CLEAN object entered!") never returns; }
578
579 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_DIRTY, 0, 0, SMALL_MUT_ARR_PTRS_DIRTY, "SMALL_MUT_ARR_PTRS_DIRTY", "SMALL_MUT_ARR_PTRS_DIRTY")
580 { foreign "C" barf("SMALL_MUT_ARR_PTRS_DIRTY object entered!") never returns; }
581
582 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_FROZEN, 0, 0, SMALL_MUT_ARR_PTRS_FROZEN, "SMALL_MUT_ARR_PTRS_FROZEN", "SMALL_MUT_ARR_PTRS_FROZEN")
583 { foreign "C" barf("SMALL_MUT_ARR_PTRS_FROZEN object entered!") never returns; }
584
585 INFO_TABLE(stg_SMALL_MUT_ARR_PTRS_FROZEN0, 0, 0, SMALL_MUT_ARR_PTRS_FROZEN0, "SMALL_MUT_ARR_PTRS_FROZEN0", "SMALL_MUT_ARR_PTRS_FROZEN0")
586 { foreign "C" barf("SMALL_MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
587
588 /* ----------------------------------------------------------------------------
589    Mutable Variables
590    ------------------------------------------------------------------------- */
591
592 INFO_TABLE(stg_MUT_VAR_CLEAN, 1, 0, MUT_VAR_CLEAN, "MUT_VAR_CLEAN", "MUT_VAR_CLEAN")
593 { foreign "C" barf("MUT_VAR_CLEAN object entered!") never returns; }
594 INFO_TABLE(stg_MUT_VAR_DIRTY, 1, 0, MUT_VAR_DIRTY, "MUT_VAR_DIRTY", "MUT_VAR_DIRTY")
595 { foreign "C" barf("MUT_VAR_DIRTY object entered!") never returns; }
596
597 /* ----------------------------------------------------------------------------
598    Dummy return closure
599
600    Entering this closure will just return to the address on the top of the
601    stack.  Useful for getting a thread in a canonical form where we can
602    just enter the top stack word to start the thread.  (see deleteThread)
603  * ------------------------------------------------------------------------- */
604
605 INFO_TABLE( stg_dummy_ret, 0, 0, CONSTR_NOCAF_STATIC, "DUMMY_RET", "DUMMY_RET")
606     ()
607 {
608     return ();
609 }
610 CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
611
612 /* ----------------------------------------------------------------------------
613    MVAR_TSO_QUEUE
614    ------------------------------------------------------------------------- */
615
616 INFO_TABLE_CONSTR(stg_MVAR_TSO_QUEUE,2,0,0,PRIM,"MVAR_TSO_QUEUE","MVAR_TSO_QUEUE")
617 { foreign "C" barf("MVAR_TSO_QUEUE object entered!") never returns; }
618
619 /* ----------------------------------------------------------------------------
620    COMPACT_NFDATA (a blob of data in NF with no outgoing pointers)
621
622    Just return immediately because the structure is in NF already
623    ------------------------------------------------------------------------- */
624
625 INFO_TABLE( stg_COMPACT_NFDATA, 0, 0, COMPACT_NFDATA, "COMPACT_NFDATA", "COMPACT_NFDATA")
626     ()
627 {
628     return ();
629 }
630
631 /* ----------------------------------------------------------------------------
632    CHARLIKE and INTLIKE closures.
633
634    These are static representations of Chars and small Ints, so that
635    we can remove dynamic Chars and Ints during garbage collection and
636    replace them with references to the static objects.
637    ------------------------------------------------------------------------- */
638
639 #if defined(COMPILING_WINDOWS_DLL)
640 /*
641  * When sticking the RTS in a Windows DLL, we delay populating the
642  * Charlike and Intlike tables until load-time, which is only
643  * when we've got the real addresses to the C# and I# closures.
644  *
645  * -- this is currently broken BL 2009/11/14.
646  *    we don't rewrite to static closures at all with Windows DLLs.
647  */
648 // #warning Is this correct? _imp is a pointer!
649 #define Char_hash_static_info _imp__ghczmprim_GHCziTypes_Czh_static_info
650 #define Int_hash_static_info _imp__ghczmprim_GHCziTypes_Izh_static_info
651 #else
652 #define Char_hash_static_info ghczmprim_GHCziTypes_Czh_static_info
653 #define Int_hash_static_info ghczmprim_GHCziTypes_Izh_static_info
654 #endif
655
656
657 #define CHARLIKE_HDR(n)  CLOSURE(Char_hash_static_info, n)
658 #define INTLIKE_HDR(n)   CLOSURE(Int_hash_static_info, n)
659
660 /* put these in the *data* section, since the garbage collector relies
661  * on the fact that static closures live in the data section.
662  */
663
664 #if !(defined(COMPILING_WINDOWS_DLL))
665 section "data" {
666  stg_CHARLIKE_closure:
667     CHARLIKE_HDR(0)
668     CHARLIKE_HDR(1)
669     CHARLIKE_HDR(2)
670     CHARLIKE_HDR(3)
671     CHARLIKE_HDR(4)
672     CHARLIKE_HDR(5)
673     CHARLIKE_HDR(6)
674     CHARLIKE_HDR(7)
675     CHARLIKE_HDR(8)
676     CHARLIKE_HDR(9)
677     CHARLIKE_HDR(10)
678     CHARLIKE_HDR(11)
679     CHARLIKE_HDR(12)
680     CHARLIKE_HDR(13)
681     CHARLIKE_HDR(14)
682     CHARLIKE_HDR(15)
683     CHARLIKE_HDR(16)
684     CHARLIKE_HDR(17)
685     CHARLIKE_HDR(18)
686     CHARLIKE_HDR(19)
687     CHARLIKE_HDR(20)
688     CHARLIKE_HDR(21)
689     CHARLIKE_HDR(22)
690     CHARLIKE_HDR(23)
691     CHARLIKE_HDR(24)
692     CHARLIKE_HDR(25)
693     CHARLIKE_HDR(26)
694     CHARLIKE_HDR(27)
695     CHARLIKE_HDR(28)
696     CHARLIKE_HDR(29)
697     CHARLIKE_HDR(30)
698     CHARLIKE_HDR(31)
699     CHARLIKE_HDR(32)
700     CHARLIKE_HDR(33)
701     CHARLIKE_HDR(34)
702     CHARLIKE_HDR(35)
703     CHARLIKE_HDR(36)
704     CHARLIKE_HDR(37)
705     CHARLIKE_HDR(38)
706     CHARLIKE_HDR(39)
707     CHARLIKE_HDR(40)
708     CHARLIKE_HDR(41)
709     CHARLIKE_HDR(42)
710     CHARLIKE_HDR(43)
711     CHARLIKE_HDR(44)
712     CHARLIKE_HDR(45)
713     CHARLIKE_HDR(46)
714     CHARLIKE_HDR(47)
715     CHARLIKE_HDR(48)
716     CHARLIKE_HDR(49)
717     CHARLIKE_HDR(50)
718     CHARLIKE_HDR(51)
719     CHARLIKE_HDR(52)
720     CHARLIKE_HDR(53)
721     CHARLIKE_HDR(54)
722     CHARLIKE_HDR(55)
723     CHARLIKE_HDR(56)
724     CHARLIKE_HDR(57)
725     CHARLIKE_HDR(58)
726     CHARLIKE_HDR(59)
727     CHARLIKE_HDR(60)
728     CHARLIKE_HDR(61)
729     CHARLIKE_HDR(62)
730     CHARLIKE_HDR(63)
731     CHARLIKE_HDR(64)
732     CHARLIKE_HDR(65)
733     CHARLIKE_HDR(66)
734     CHARLIKE_HDR(67)
735     CHARLIKE_HDR(68)
736     CHARLIKE_HDR(69)
737     CHARLIKE_HDR(70)
738     CHARLIKE_HDR(71)
739     CHARLIKE_HDR(72)
740     CHARLIKE_HDR(73)
741     CHARLIKE_HDR(74)
742     CHARLIKE_HDR(75)
743     CHARLIKE_HDR(76)
744     CHARLIKE_HDR(77)
745     CHARLIKE_HDR(78)
746     CHARLIKE_HDR(79)
747     CHARLIKE_HDR(80)
748     CHARLIKE_HDR(81)
749     CHARLIKE_HDR(82)
750     CHARLIKE_HDR(83)
751     CHARLIKE_HDR(84)
752     CHARLIKE_HDR(85)
753     CHARLIKE_HDR(86)
754     CHARLIKE_HDR(87)
755     CHARLIKE_HDR(88)
756     CHARLIKE_HDR(89)
757     CHARLIKE_HDR(90)
758     CHARLIKE_HDR(91)
759     CHARLIKE_HDR(92)
760     CHARLIKE_HDR(93)
761     CHARLIKE_HDR(94)
762     CHARLIKE_HDR(95)
763     CHARLIKE_HDR(96)
764     CHARLIKE_HDR(97)
765     CHARLIKE_HDR(98)
766     CHARLIKE_HDR(99)
767     CHARLIKE_HDR(100)
768     CHARLIKE_HDR(101)
769     CHARLIKE_HDR(102)
770     CHARLIKE_HDR(103)
771     CHARLIKE_HDR(104)
772     CHARLIKE_HDR(105)
773     CHARLIKE_HDR(106)
774     CHARLIKE_HDR(107)
775     CHARLIKE_HDR(108)
776     CHARLIKE_HDR(109)
777     CHARLIKE_HDR(110)
778     CHARLIKE_HDR(111)
779     CHARLIKE_HDR(112)
780     CHARLIKE_HDR(113)
781     CHARLIKE_HDR(114)
782     CHARLIKE_HDR(115)
783     CHARLIKE_HDR(116)
784     CHARLIKE_HDR(117)
785     CHARLIKE_HDR(118)
786     CHARLIKE_HDR(119)
787     CHARLIKE_HDR(120)
788     CHARLIKE_HDR(121)
789     CHARLIKE_HDR(122)
790     CHARLIKE_HDR(123)
791     CHARLIKE_HDR(124)
792     CHARLIKE_HDR(125)
793     CHARLIKE_HDR(126)
794     CHARLIKE_HDR(127)
795     CHARLIKE_HDR(128)
796     CHARLIKE_HDR(129)
797     CHARLIKE_HDR(130)
798     CHARLIKE_HDR(131)
799     CHARLIKE_HDR(132)
800     CHARLIKE_HDR(133)
801     CHARLIKE_HDR(134)
802     CHARLIKE_HDR(135)
803     CHARLIKE_HDR(136)
804     CHARLIKE_HDR(137)
805     CHARLIKE_HDR(138)
806     CHARLIKE_HDR(139)
807     CHARLIKE_HDR(140)
808     CHARLIKE_HDR(141)
809     CHARLIKE_HDR(142)
810     CHARLIKE_HDR(143)
811     CHARLIKE_HDR(144)
812     CHARLIKE_HDR(145)
813     CHARLIKE_HDR(146)
814     CHARLIKE_HDR(147)
815     CHARLIKE_HDR(148)
816     CHARLIKE_HDR(149)
817     CHARLIKE_HDR(150)
818     CHARLIKE_HDR(151)
819     CHARLIKE_HDR(152)
820     CHARLIKE_HDR(153)
821     CHARLIKE_HDR(154)
822     CHARLIKE_HDR(155)
823     CHARLIKE_HDR(156)
824     CHARLIKE_HDR(157)
825     CHARLIKE_HDR(158)
826     CHARLIKE_HDR(159)
827     CHARLIKE_HDR(160)
828     CHARLIKE_HDR(161)
829     CHARLIKE_HDR(162)
830     CHARLIKE_HDR(163)
831     CHARLIKE_HDR(164)
832     CHARLIKE_HDR(165)
833     CHARLIKE_HDR(166)
834     CHARLIKE_HDR(167)
835     CHARLIKE_HDR(168)
836     CHARLIKE_HDR(169)
837     CHARLIKE_HDR(170)
838     CHARLIKE_HDR(171)
839     CHARLIKE_HDR(172)
840     CHARLIKE_HDR(173)
841     CHARLIKE_HDR(174)
842     CHARLIKE_HDR(175)
843     CHARLIKE_HDR(176)
844     CHARLIKE_HDR(177)
845     CHARLIKE_HDR(178)
846     CHARLIKE_HDR(179)
847     CHARLIKE_HDR(180)
848     CHARLIKE_HDR(181)
849     CHARLIKE_HDR(182)
850     CHARLIKE_HDR(183)
851     CHARLIKE_HDR(184)
852     CHARLIKE_HDR(185)
853     CHARLIKE_HDR(186)
854     CHARLIKE_HDR(187)
855     CHARLIKE_HDR(188)
856     CHARLIKE_HDR(189)
857     CHARLIKE_HDR(190)
858     CHARLIKE_HDR(191)
859     CHARLIKE_HDR(192)
860     CHARLIKE_HDR(193)
861     CHARLIKE_HDR(194)
862     CHARLIKE_HDR(195)
863     CHARLIKE_HDR(196)
864     CHARLIKE_HDR(197)
865     CHARLIKE_HDR(198)
866     CHARLIKE_HDR(199)
867     CHARLIKE_HDR(200)
868     CHARLIKE_HDR(201)
869     CHARLIKE_HDR(202)
870     CHARLIKE_HDR(203)
871     CHARLIKE_HDR(204)
872     CHARLIKE_HDR(205)
873     CHARLIKE_HDR(206)
874     CHARLIKE_HDR(207)
875     CHARLIKE_HDR(208)
876     CHARLIKE_HDR(209)
877     CHARLIKE_HDR(210)
878     CHARLIKE_HDR(211)
879     CHARLIKE_HDR(212)
880     CHARLIKE_HDR(213)
881     CHARLIKE_HDR(214)
882     CHARLIKE_HDR(215)
883     CHARLIKE_HDR(216)
884     CHARLIKE_HDR(217)
885     CHARLIKE_HDR(218)
886     CHARLIKE_HDR(219)
887     CHARLIKE_HDR(220)
888     CHARLIKE_HDR(221)
889     CHARLIKE_HDR(222)
890     CHARLIKE_HDR(223)
891     CHARLIKE_HDR(224)
892     CHARLIKE_HDR(225)
893     CHARLIKE_HDR(226)
894     CHARLIKE_HDR(227)
895     CHARLIKE_HDR(228)
896     CHARLIKE_HDR(229)
897     CHARLIKE_HDR(230)
898     CHARLIKE_HDR(231)
899     CHARLIKE_HDR(232)
900     CHARLIKE_HDR(233)
901     CHARLIKE_HDR(234)
902     CHARLIKE_HDR(235)
903     CHARLIKE_HDR(236)
904     CHARLIKE_HDR(237)
905     CHARLIKE_HDR(238)
906     CHARLIKE_HDR(239)
907     CHARLIKE_HDR(240)
908     CHARLIKE_HDR(241)
909     CHARLIKE_HDR(242)
910     CHARLIKE_HDR(243)
911     CHARLIKE_HDR(244)
912     CHARLIKE_HDR(245)
913     CHARLIKE_HDR(246)
914     CHARLIKE_HDR(247)
915     CHARLIKE_HDR(248)
916     CHARLIKE_HDR(249)
917     CHARLIKE_HDR(250)
918     CHARLIKE_HDR(251)
919     CHARLIKE_HDR(252)
920     CHARLIKE_HDR(253)
921     CHARLIKE_HDR(254)
922     CHARLIKE_HDR(255)
923 }
924
925 section "data" {
926  stg_INTLIKE_closure:
927     INTLIKE_HDR(-16) /* MIN_INTLIKE == -16 */
928     INTLIKE_HDR(-15)
929     INTLIKE_HDR(-14)
930     INTLIKE_HDR(-13)
931     INTLIKE_HDR(-12)
932     INTLIKE_HDR(-11)
933     INTLIKE_HDR(-10)
934     INTLIKE_HDR(-9)
935     INTLIKE_HDR(-8)
936     INTLIKE_HDR(-7)
937     INTLIKE_HDR(-6)
938     INTLIKE_HDR(-5)
939     INTLIKE_HDR(-4)
940     INTLIKE_HDR(-3)
941     INTLIKE_HDR(-2)
942     INTLIKE_HDR(-1)
943     INTLIKE_HDR(0)
944     INTLIKE_HDR(1)
945     INTLIKE_HDR(2)
946     INTLIKE_HDR(3)
947     INTLIKE_HDR(4)
948     INTLIKE_HDR(5)
949     INTLIKE_HDR(6)
950     INTLIKE_HDR(7)
951     INTLIKE_HDR(8)
952     INTLIKE_HDR(9)
953     INTLIKE_HDR(10)
954     INTLIKE_HDR(11)
955     INTLIKE_HDR(12)
956     INTLIKE_HDR(13)
957     INTLIKE_HDR(14)
958     INTLIKE_HDR(15)
959     INTLIKE_HDR(16)  /* MAX_INTLIKE == 16 */
960 }
961
962 #endif