1 \section[storage-manager-check]{Checking Consistency of Storage Manager}
3 This code performs consistency/sanity checks on the stacks and heap.
4 It can be called each time round the mini-interpreter loop. Not
5 required if we're tail-jumping (no mini-interpreter).
9 #if ! ( defined(__STG_TAILJUMPS__) && defined(__GNUC__) )
11 /* Insist on the declaration of STG-machine registers */
14 #include "SMinternal.h"
16 #define isHeapPtr(p) \
17 ((p) >= heap_space && (p) < heap_space + SM_word_heap_size)
19 #if nextstep2_TARGET_OS || nextstep3_TARGET_OS /* ToDo: use END_BY_FUNNY_MEANS or something */
20 #define validInfoPtr(i) \
21 ((i) < (StgPtr) (get_end_result) /* && MIN_INFO_TYPE < INFO_TYPE(i) && INFO_TYPE(i) < MAX_INFO_TYPE */)
22 /* No Internal info tables allowed (type -1) */
25 #define validInfoPtr(i) \
26 ((i) < (P_) &end /* && MIN_INFO_TYPE < INFO_TYPE(i) && INFO_TYPE(i) < MAX_INFO_TYPE */)
27 /* No Internal info tables allowed (type -1) */
31 #define suspectPtr(p) ((p) < (P_)256)
34 #define validHeapPtr(p) \
35 ((p) >= semispaceInfo[semispace].base && (p) <= semispaceInfo[semispace].lim)
38 #define validHeapPtr(p) \
39 ((p) >= compactingInfo.base && (p) <= compactingInfo.lim)
42 #define validHeapPtr(p) \
43 ((p) >= dualmodeInfo.modeinfo[dualmodeInfo.mode].base && \
44 (p) <= dualmodeInfo.modeinfo[dualmodeInfo.mode].lim)
48 /* Two cases needed, depending on whether the 2-space GC is forced
50 #define validHeapPtr(p) \
51 (SM_force_gc == USE_2s ? \
52 ((p) >= appelInfo.space[appelInfo.semi_space].base && \
53 (p) <= appelInfo.space[appelInfo.semi_space].lim) : \
54 (((p) >= appelInfo.oldbase && (p) <= appelInfo.oldlim) || \
55 ((p) >= appelInfo.newbase && (p) <= appelInfo.newlim)) \
60 #define validHeapPtr(p) \
61 (((p) >= genInfo.oldbase && (p) <= genInfo.oldlim) || \
62 ((p) >= genInfo.newgen[genInfo.curnew].newbase && (p) <= genInfo.newgen[genInfo.curnew].newlim) || \
63 ((p) >= genInfo.allocbase && (p) <= genInfo.alloclim))
65 #define validHeapPtr(p) 0
73 void checkAStack(STG_NO_ARGS)
81 fprintf(stderr, "SuB (%lx) > SpB (%lx)\n", (W_) SuB, (W_) SpB);
85 fprintf(stderr, "SuA (%lx) < SpA (%lx)\n", (W_) SuA, (W_) SpA);
90 SUBTRACT_A_STK(stackptr, stackInfo.botA) >= 0;
91 stackptr = stackptr + AREL(1)) {
93 closurePtr = (P_) *stackptr;
95 if (suspectPtr(closurePtr)) {
96 fprintf(stderr, "Suspect heap ptr on A stk; SpA %lx, sp %lx, ptr %lx\n",
97 (W_) SpA, (W_) stackptr, (W_) closurePtr);
100 } else if (isHeapPtr(closurePtr) && ! validHeapPtr(closurePtr)) {
102 fprintf(stderr, "Bad heap ptr on A stk; SpA %lx, sp %lx, ptr %lx\n",
103 (W_) SpA, (W_) stackptr, (W_) closurePtr);
107 infoPtr = (P_) *closurePtr;
109 if (suspectPtr(infoPtr)) {
110 fprintf(stderr, "Suspect info ptr on A stk; SpA %lx, sp %lx, closure %lx info %lx\n",
111 (W_) SpA, (W_) stackptr, (W_) closurePtr, (W_) infoPtr);
114 } else if ( ! validInfoPtr(infoPtr)) {
115 fprintf(stderr, "Bad info ptr in A stk; SpA %lx, sp %lx, closure %lx, info %lx\n",
116 (W_) SpA, (W_) stackptr, (W_) closurePtr, (W_) infoPtr/* , INFO_TYPE(infoPtr) */);
125 #endif /* ! ( defined(__STG_TAILJUMPS__) && defined(__GNUC__) ) */