]> Zhao Yanbai Git Server - minix.git/commitdiff
library function to retrieve kernel proc table and sanity check it
authorBen Gras <ben@minix3.org>
Mon, 28 Jun 2010 11:05:15 +0000 (11:05 +0000)
committerBen Gras <ben@minix3.org>
Mon, 28 Jun 2010 11:05:15 +0000 (11:05 +0000)
include/minix/const.h
include/minix/sysinfo.h
kernel/proc.h
lib/libc/other/_getsysinfo.c

index 4d881fb84f114dc3d9252e9b0074aa7ec91ebf48..a3049eec20e7fcc2b613fcd87c3df89faaa3d7bc 100644 (file)
 #define VERBOSEBOOT_MAX   3
 #define VERBOSEBOOTVARNAME "verbose"
 
+/* magic value to put in struct proc entries for sanity checks. */
+#define PMAGIC 0xC0FFEE1
+
 #endif /* _MINIX_CONST_H */
index c0d7ed3a0936ac6f37ed6e2c896c18c2dbc6af7a..53f21b1044d04c27723185f30e9d902a7510b0a8 100644 (file)
@@ -6,6 +6,7 @@
 #include <minix/type.h>
 
 _PROTOTYPE( int getsysinfo, (endpoint_t who, int what, void *where)       );
+_PROTOTYPE( int minix_getkproctab, (void *pr, int nprocs, int assert));
 _PROTOTYPE( ssize_t getsysinfo_up, (endpoint_t who, int what, size_t size,
        void *where));
 
index 544fd8a62fc9b45aae27cd5821c60685a95bf88c..696d01003d691b9ece7d58388e42a47e5c91ad86 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef PROC_H
 #define PROC_H
 
+#include <minix/const.h>
+
 #ifndef __ASSEMBLY__
 
 /* Here is the declaration of the process table.  It contains all process
@@ -102,7 +104,6 @@ struct proc {
   } p_vmrequest;
 
   int p_found; /* consistency checking variables */
-#define PMAGIC 0xC0FFEE1
   int p_magic;         /* check validity of proc pointers */
 
 #if DEBUG_TRACE
index fa8c223388134c6f7637b295ad30736170a97bb0..bd921309171037f1a571762fed8209e253b8fa36 100644 (file)
@@ -1,9 +1,23 @@
+
 #include <lib.h>
+#include <unistd.h>
+#include <timers.h>
 #include <minix/endpoint.h>
 #define getsysinfo     _getsysinfo
 #define getsysinfo_up  _getsysinfo_up
 #include <minix/sysinfo.h>
+#include <minix/const.h>
+
+#include <minix/ipc.h>
+#include <minix/com.h>
+#include <minix/sysinfo.h>
+#include <minix/config.h>
+#include <minix/type.h>
+#include <minix/const.h>
+#include <stdio.h>
 
+#include <machine/archtypes.h>
+#include "../../../kernel/proc.h"
 
 PUBLIC int getsysinfo(who, what, where)
 endpoint_t who;                        /* from whom to request info */
@@ -17,6 +31,35 @@ void *where;                 /* where to put it */
   return(0);
 }
 
+PUBLIC int minix_getkproctab(void *vpr, int nprocs, int assert)
+{
+       int r, i, fail = 0;
+       struct proc *pr = vpr;
+
+       if((r=getsysinfo(PM_PROC_NR, SI_KPROC_TAB, pr)) < 0)
+               return r;
+
+       for(i = 0; i < nprocs; i++) {
+               if(pr[i].p_magic != PMAGIC) {
+                       fail = 1;
+                       break;
+               }
+       }
+
+       if(!fail)
+               return 0;
+
+       if(assert) {
+               fprintf(stderr, "%s: process table failed sanity check.\n", getprogname());
+               fprintf(stderr, "is kernel out of sync?\n");
+               exit(1);
+       }
+
+       errno = ENOSYS;
+
+       return -1;
+}
+
 /* Unprivileged variant of getsysinfo. */
 PUBLIC ssize_t getsysinfo_up(who, what, size, where)
 endpoint_t who;                        /* from whom to request info */