From: Ben Gras Date: Mon, 28 Jun 2010 11:05:15 +0000 (+0000) Subject: library function to retrieve kernel proc table and sanity check it X-Git-Tag: v3.1.8~321 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/index.html?a=commitdiff_plain;h=8379b088459e42a17fd3fbfec1c87c052c830781;p=minix.git library function to retrieve kernel proc table and sanity check it --- diff --git a/include/minix/const.h b/include/minix/const.h index 4d881fb84..a3049eec2 100644 --- a/include/minix/const.h +++ b/include/minix/const.h @@ -187,4 +187,7 @@ #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 */ diff --git a/include/minix/sysinfo.h b/include/minix/sysinfo.h index c0d7ed3a0..53f21b104 100644 --- a/include/minix/sysinfo.h +++ b/include/minix/sysinfo.h @@ -6,6 +6,7 @@ #include _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)); diff --git a/kernel/proc.h b/kernel/proc.h index 544fd8a62..696d01003 100644 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -1,6 +1,8 @@ #ifndef PROC_H #define PROC_H +#include + #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 diff --git a/lib/libc/other/_getsysinfo.c b/lib/libc/other/_getsysinfo.c index fa8c22338..bd9213091 100644 --- a/lib/libc/other/_getsysinfo.c +++ b/lib/libc/other/_getsysinfo.c @@ -1,9 +1,23 @@ + #include +#include +#include #include #define getsysinfo _getsysinfo #define getsysinfo_up _getsysinfo_up #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#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 */