2008-11-19 13:26:10 +01:00
|
|
|
#ifndef _SANITYCHECK_H
|
|
|
|
#define _SANITYCHECK_H 1
|
|
|
|
|
2010-04-12 13:25:24 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#include "vm.h"
|
|
|
|
|
|
|
|
#if SANITYCHECKS
|
|
|
|
|
|
|
|
/* This macro is used in the sanity check functions, where file and
|
|
|
|
* line are function arguments.
|
|
|
|
*/
|
|
|
|
#define MYASSERT(c) do { if(!(c)) { \
|
|
|
|
printf("VM:%s:%d: %s failed\n", file, line, #c); \
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sanity check failed"); } } while(0)
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
#define SLABSANITYCHECK(l) if((l) <= vm_sanitychecklevel) { \
|
|
|
|
slab_sanitycheck(__FILE__, __LINE__); }
|
|
|
|
|
2009-04-22 14:39:29 +02:00
|
|
|
#define SANITYCHECK(l) if(!nocheck && ((l) <= vm_sanitychecklevel)) { \
|
2010-04-12 13:25:24 +02:00
|
|
|
struct vmproc *vmpr; \
|
2010-04-12 14:37:28 +02:00
|
|
|
assert(incheck == 0); \
|
2009-09-21 16:49:49 +02:00
|
|
|
incheck = 1; \
|
|
|
|
usedpages_reset(); \
|
|
|
|
slab_sanitycheck(__FILE__, __LINE__); \
|
2010-04-12 13:25:24 +02:00
|
|
|
for(vmpr = vmproc; vmpr < &vmproc[VMP_NR]; vmpr++) { \
|
|
|
|
if((vmpr->vm_flags & (VMF_INUSE | VMF_HASPT)) == \
|
2008-11-19 13:26:10 +01:00
|
|
|
(VMF_INUSE | VMF_HASPT)) { \
|
2010-04-12 13:25:24 +02:00
|
|
|
PT_SANE(&vmpr->vm_pt); \
|
2008-11-19 13:26:10 +01:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
map_sanitycheck(__FILE__, __LINE__); \
|
2010-04-12 14:37:28 +02:00
|
|
|
assert(incheck == 1); \
|
2009-09-21 16:49:49 +02:00
|
|
|
incheck = 0; \
|
2008-11-19 13:26:10 +01:00
|
|
|
}
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
#define SLABSANE(ptr) { \
|
|
|
|
if(!slabsane_f(__FILE__, __LINE__, ptr, sizeof(*(ptr)))) { \
|
|
|
|
printf("VM:%s:%d: SLABSANE(%s)\n", __FILE__, __LINE__, #ptr); \
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("SLABSANE failed"); \
|
2009-09-21 16:49:49 +02:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#else
|
|
|
|
#define SANITYCHECK
|
2009-09-21 16:49:49 +02:00
|
|
|
#define SLABSANITYCHECK(l)
|
|
|
|
#define SLABSANE(ptr)
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
|
|
|
|
2010-05-05 13:35:04 +02:00
|
|
|
#if MEMPROTECT
|
|
|
|
#define USE(obj, code) do { \
|
|
|
|
slabunlock(obj, sizeof(*obj)); \
|
|
|
|
do { \
|
|
|
|
code \
|
|
|
|
} while(0); \
|
|
|
|
slablock(obj, sizeof(*obj)); \
|
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
#define USE(obj, code) do { code } while(0)
|
|
|
|
#endif
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|