xref: /inferno-os/libinterp/validstk.c (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 #include "lib9.h"
2 #include "isa.h"
3 #include "interp.h"
4 
5 static int depth;
6 
7 void
memchk(void * p,Type * t)8 memchk(void *p, Type *t)
9 {
10 	Heap *h;
11 	int i, j;
12 	ulong *v, **base;
13 
14 	if(depth > 100)
15 		return;
16 	depth++;
17 	base = p;
18 	for(i = 0; i < t->np; i++) {
19 		for(j = 0; j < 8; j++) {
20 			if(t->map[i] & (1<<(7-j))) {
21 				v = base[(i*8)+j];
22 				if(v != H) {
23 					h = D2H(v);
24 					hmsize(h);
25 					if(h->ref <= 0)
26 						abort();
27 					if(h->t != nil)
28 						memchk(v, h->t);
29 				}
30 			}
31 		}
32 	}
33 	depth--;
34 }
35 
36 void
validstk(void)37 validstk(void)
38 {
39 	Type *t;
40 	Frame *f;
41 	uchar *fp;
42 
43 	fp = R.FP;
44 	while(fp != nil) {
45 		f = (Frame*)fp;
46 		t = f->t;
47 		if(t == nil)
48 			t = SEXTYPE(f)->reg.TR;
49 
50 		memchk(f, t);
51 		fp = f->fp;
52 	}
53 }
54