From: Ben Gras Date: Sat, 3 Oct 2009 12:17:46 +0000 (+0000) Subject: - exact magic values for entered/nonentered states in recursive enter check X-Git-Tag: v3.1.5~31 X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-verify.html?a=commitdiff_plain;h=6bd3002f0677643ad5319761839e9dcdbe9e429e;p=minix.git - exact magic values for entered/nonentered states in recursive enter check - read_*() functions to read segment selector values - decode loaded segments on panic --- diff --git a/kernel/arch/i386/klib386.s b/kernel/arch/i386/klib386.s index cc6cd748e..d506059f9 100755 --- a/kernel/arch/i386/klib386.s +++ b/kernel/arch/i386/klib386.s @@ -41,6 +41,9 @@ .define _thecr3 .define _write_cr4 .define _catch_pagefaults +.define _read_ds +.define _read_cs +.define _read_ss ! The routines only guarantee to preserve the registers the C compiler ! expects to be preserved (ebx, esi, edi, ebp, esp, segment registers, and @@ -573,6 +576,20 @@ _write_cr4: pop ebp ret +_read_ds: + mov eax, 0 + mov ax, ds + ret + +_read_cs: + mov eax, 0 + mov ax, cs + ret + +_read_ss: + mov eax, 0 + mov ax, ss + ret !*===========================================================================* !* getcr3val * diff --git a/kernel/arch/i386/protect.c b/kernel/arch/i386/protect.c index e0fa57619..c114baac2 100755 --- a/kernel/arch/i386/protect.c +++ b/kernel/arch/i386/protect.c @@ -403,6 +403,10 @@ PUBLIC void printseg(char *banner, int iscs, struct proc *pr, u32_t selector) kprintf("invalid index in ldt\n"); return; } + if(!pr) { + kprintf("local selector but unknown process\n"); + return; + } desc = &pr->p_seg.p_ldt[index]; } else { kprintf("GDT"); diff --git a/kernel/debug.h b/kernel/debug.h index c170039d0..978a311bc 100644 --- a/kernel/debug.h +++ b/kernel/debug.h @@ -41,24 +41,38 @@ #define TRACE(code, statement) #endif +#define ENTERED 0xBA5E1514 +#define NOTENTERED 0x1415BEE1 + #define NOREC_ENTER(varname) \ - static int varname = 0; \ + static int varname = NOTENTERED; \ int mustunlock = 0; \ if(!intr_disabled()) { lock; mustunlock = 1; } \ + if(varname != ENTERED && varname != NOTENTERED) { \ + printf("magictest: 0x%lx local: 0x%lx\n", magictest, varname);\ + minix_panic(#varname " bogus value on enter", varname); \ + } \ if(magictest != MAGICTEST) { \ + printf("magictest: 0x%lx local: 0x%lx\n", magictest, varname);\ minix_panic(#varname " magictest failed", __LINE__); \ } \ - if(varname) { \ + if(varname == ENTERED) { \ minix_panic(#varname " recursive enter", __LINE__); \ } \ - varname = 1; + varname = ENTERED; #define NOREC_RETURN(varname, v) do { \ - if(!varname) \ - minix_panic(#varname " flag off", __LINE__); \ if(!intr_disabled()) \ minix_panic(#varname " interrupts on", __LINE__); \ - varname = 0; \ + if(magictest != MAGICTEST) { \ + printf("magictest: 0x%lx local: 0x%lx\n", magictest, varname);\ + minix_panic(#varname " magictest failed", __LINE__); \ + } \ + if(varname != ENTERED && varname != NOTENTERED) { \ + printf("magictest: 0x%lx local: 0x%lx\n", magictest, varname);\ + minix_panic(#varname " bogus value on return", varname); \ + } \ + varname = NOTENTERED; \ if(mustunlock) { unlock; } \ return v; \ } while(0) diff --git a/kernel/utility.c b/kernel/utility.c index fa31cf3fe..67a17f338 100755 --- a/kernel/utility.c +++ b/kernel/utility.c @@ -48,6 +48,12 @@ if (minix_panicing++) { kprintf("\n"); } + printseg("cs: ", 1, NULL, read_cs()); + printseg("ds: ", 0, NULL, read_ds()); + if(read_ds() != read_ss()) { + printseg("ss: ", 0, NULL, read_ss()); + } + kprintf("kernel: "); util_stacktrace();