From: Ben Gras Date: Fri, 25 Sep 2009 11:12:06 +0000 (+0000) Subject: pre-APPROVEd (thanks Arun) sanity check function. X-Git-Tag: v3.1.5~87 X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-coverage.html?a=commitdiff_plain;h=1d0854e6dbef4f50a6be3d2c2efa24ca90869ad4;p=minix.git pre-APPROVEd (thanks Arun) sanity check function. --- diff --git a/kernel/arch/i386/protect.c b/kernel/arch/i386/protect.c index b2ae9eaff..e0fa57619 100755 --- a/kernel/arch/i386/protect.c +++ b/kernel/arch/i386/protect.c @@ -339,6 +339,49 @@ PUBLIC void alloc_segments(register struct proc *rp) rp->p_reg.ds = (DS_LDT_INDEX*DESC_SIZE) | TI | privilege; } +/*===========================================================================* + * check_segments * + *===========================================================================*/ +PUBLIC void check_segments(char *File, int line) +{ + int checked = 0; +int fail = 0; +struct proc *rp; +for (rp = BEG_PROC_ADDR; rp < END_PROC_ADDR; ++rp) { + + int privilege; + int cs, ds; + + if (RTS_ISSET(rp, SLOT_FREE)) + continue; + + if( (iskernelp(rp))) + privilege = TASK_PRIVILEGE; + else + privilege = USER_PRIVILEGE; + + cs = (CS_LDT_INDEX*DESC_SIZE) | TI | privilege; + ds = (DS_LDT_INDEX*DESC_SIZE) | TI | privilege; + +#define CHECK(s1, s2) if(s1 != s2) { \ + printf("%s:%d: " #s1 " != " #s2 " for ep %d\n", \ + File, line, rp->p_endpoint); fail++; } checked++; + + CHECK(rp->p_reg.cs, cs); + CHECK(rp->p_reg.gs, ds); + CHECK(rp->p_reg.fs, ds); + CHECK(rp->p_reg.ss, ds); + if(rp->p_endpoint != -2) { + CHECK(rp->p_reg.es, ds); + } + CHECK(rp->p_reg.ds, ds); + } + if(fail) { + printf("%d/%d checks failed\n", fail, checked); + minix_panic("wrong", fail); + } +} + /*===========================================================================* * printseg * *===========================================================================*/