]> Zhao Yanbai Git Server - minix.git/commitdiff
pre-APPROVEd (thanks Arun) sanity check function.
authorBen Gras <ben@minix3.org>
Fri, 25 Sep 2009 11:12:06 +0000 (11:12 +0000)
committerBen Gras <ben@minix3.org>
Fri, 25 Sep 2009 11:12:06 +0000 (11:12 +0000)
kernel/arch/i386/protect.c

index b2ae9eaff8959879ac264529957a47637437480a..e0fa57619ba77bad551d6d8fa9695a50879dada5 100755 (executable)
@@ -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                             *
  *===========================================================================*/