xref: /minix3/minix/servers/vm/sanitycheck.h (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #ifndef _SANITYCHECK_H
2*433d6423SLionel Sambuc #define _SANITYCHECK_H 1
3*433d6423SLionel Sambuc 
4*433d6423SLionel Sambuc #include <assert.h>
5*433d6423SLionel Sambuc 
6*433d6423SLionel Sambuc #include "vm.h"
7*433d6423SLionel Sambuc 
8*433d6423SLionel Sambuc #if SANITYCHECKS
9*433d6423SLionel Sambuc 
10*433d6423SLionel Sambuc #define PT_SANE(p) { pt_sanitycheck((p), __FILE__, __LINE__); }
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc /* This macro is used in the sanity check functions, where file and
13*433d6423SLionel Sambuc  * line are function arguments.
14*433d6423SLionel Sambuc  */
15*433d6423SLionel Sambuc #define MYASSERT(c) do { if(!(c)) { \
16*433d6423SLionel Sambuc         printf("VM:%s:%d: %s failed (last sanity check %s:%d)\n", file, line, #c, sc_lastfile, sc_lastline); \
17*433d6423SLionel Sambuc 	panic("sanity check failed"); } } while(0)
18*433d6423SLionel Sambuc 
19*433d6423SLionel Sambuc #define SLABSANITYCHECK(l) if(_minix_kerninfo) { \
20*433d6423SLionel Sambuc 	slab_sanitycheck(__FILE__, __LINE__); }
21*433d6423SLionel Sambuc 
22*433d6423SLionel Sambuc #define SANITYCHECK(l) if(!nocheck && _minix_kerninfo && 0) {  \
23*433d6423SLionel Sambuc 		struct vmproc *vmpr;	\
24*433d6423SLionel Sambuc 		assert(incheck == 0);	\
25*433d6423SLionel Sambuc 		incheck = 1;		\
26*433d6423SLionel Sambuc 		usedpages_reset();	\
27*433d6423SLionel Sambuc 	slab_sanitycheck(__FILE__, __LINE__);	\
28*433d6423SLionel Sambuc 	for(vmpr = vmproc; vmpr < &vmproc[VMP_NR]; vmpr++) { \
29*433d6423SLionel Sambuc 		if((vmpr->vm_flags & (VMF_INUSE))) { \
30*433d6423SLionel Sambuc 			PT_SANE(&vmpr->vm_pt); \
31*433d6423SLionel Sambuc 		} \
32*433d6423SLionel Sambuc 	} \
33*433d6423SLionel Sambuc 	map_sanitycheck(__FILE__, __LINE__); \
34*433d6423SLionel Sambuc 	mem_sanitycheck(__FILE__, __LINE__); \
35*433d6423SLionel Sambuc 	assert(incheck == 1);	\
36*433d6423SLionel Sambuc 	incheck = 0;		\
37*433d6423SLionel Sambuc 	/* printf("(%s:%d OK) ", __FILE__, __LINE__); */ \
38*433d6423SLionel Sambuc 	sc_lastfile = __FILE__; sc_lastline = __LINE__; \
39*433d6423SLionel Sambuc 	}
40*433d6423SLionel Sambuc 
41*433d6423SLionel Sambuc #define SLABSANE(ptr) { \
42*433d6423SLionel Sambuc 	if(!slabsane_f(__FILE__, __LINE__, ptr, sizeof(*(ptr)))) { \
43*433d6423SLionel Sambuc 		printf("VM:%s:%d: SLABSANE(%s)\n", __FILE__, __LINE__, #ptr); \
44*433d6423SLionel Sambuc 		panic("SLABSANE failed");	\
45*433d6423SLionel Sambuc 	} \
46*433d6423SLionel Sambuc }
47*433d6423SLionel Sambuc 
48*433d6423SLionel Sambuc #else
49*433d6423SLionel Sambuc #define SANITYCHECK(l)
50*433d6423SLionel Sambuc #define SLABSANITYCHECK(l)
51*433d6423SLionel Sambuc #define SLABSANE(ptr)
52*433d6423SLionel Sambuc #define MYASSERT(c)
53*433d6423SLionel Sambuc #define PT_SANE(p)
54*433d6423SLionel Sambuc #endif
55*433d6423SLionel Sambuc 
56*433d6423SLionel Sambuc #if MEMPROTECT
57*433d6423SLionel Sambuc #define USE(obj, code) do {		\
58*433d6423SLionel Sambuc 	slabunlock(obj, sizeof(*obj));	\
59*433d6423SLionel Sambuc 	do {				\
60*433d6423SLionel Sambuc 		code			\
61*433d6423SLionel Sambuc 	} while(0);			\
62*433d6423SLionel Sambuc 	slablock(obj, sizeof(*obj));	\
63*433d6423SLionel Sambuc } while(0)
64*433d6423SLionel Sambuc #else
65*433d6423SLionel Sambuc #define USE(obj, code) do { code } while(0)
66*433d6423SLionel Sambuc #endif
67*433d6423SLionel Sambuc 
68*433d6423SLionel Sambuc #endif
69