diff --git a/include/minix/callnr.h b/include/minix/callnr.h index 58c37c7dd..a204e48b4 100644 --- a/include/minix/callnr.h +++ b/include/minix/callnr.h @@ -69,8 +69,8 @@ #define REBOOT 76 #define SVRCTL 77 #define SYSUNAME 78 -#define GETSYSINFO 79 /* to PM, VFS, RS, or DS */ -#define GETDENTS 80 /* to FS */ +#define GETSYSINFO 79 /* to PM or VFS (obsolete) */ +#define GETDENTS 80 /* to VFS */ #define LLSEEK 81 /* to VFS */ #define FSTATFS 82 /* to VFS */ #define STATVFS 83 /* to VFS */ @@ -87,7 +87,7 @@ #define FTRUNCATE 94 /* to VFS */ #define FCHMOD 95 /* to VFS */ #define FCHOWN 96 /* to VFS */ -#define GETSYSINFO_UP 97 /* to PM or VFS */ +#define GETSYSINFO_UP 97 /* to PM (obsolete) */ #define SPROF 98 /* to PM */ #define CPROF 99 /* to PM */ diff --git a/include/minix/com.h b/include/minix/com.h index 04f289e44..04fc74d95 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -877,8 +877,10 @@ #define PM_NUID m2_i1 #define PM_NGID m2_i2 -/* Field names for GETSYSINFO_UP (PM). */ +/* Field names for GETSYSINFO_UP (PM) (obsolete). */ #define SIU_WHAT m2_i1 +# define SIU_LOADINFO 1 /* retrieve load info data */ +# define SIU_SYSTEMHZ 2 /* retrieve system clock frequency */ #define SIU_LEN m2_i2 #define SIU_WHERE m2_p1 @@ -902,6 +904,14 @@ # define GCOV_BUFF_P m1_p1 # define GCOV_BUFF_SZ m1_i1 +/* Common request to several system servers: retrieve system information. + * The GETSYSINFO userland call is an (old and deprecated) alias of this, so do + * not change the fields or old userland applications may break. + */ +#define COMMON_GETSYSINFO (COMMON_RQ_BASE+2) +# define SI_WHAT m1_i1 +# define SI_WHERE m1_p1 + /*===========================================================================* * Messages for VM server * *===========================================================================*/ diff --git a/include/minix/sysinfo.h b/include/minix/sysinfo.h index 53f21b104..d2b602c7d 100644 --- a/include/minix/sysinfo.h +++ b/include/minix/sysinfo.h @@ -6,15 +6,15 @@ #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)); -#define SIU_LOADINFO 1 /* retrieve load info data */ -#define SIU_SYSTEMHZ 2 /* retrieve system clock frequency */ -#define SIU_IDLETSC 3 /* retrieve cumulative idle timestamp count */ - -/* Exported system parameters. */ +/* What system info to retrieve with sysgetinfo(). */ +#define SI_PROC_TAB 2 /* copy of entire process table */ +#define SI_DMAP_TAB 3 /* get device <-> driver mappings */ +#define SI_DATA_STORE 5 /* get copy of data store mappings */ +#define SI_SUBSCRIPTION 6 /* get copy of data store subscriptions */ +#define SI_LOADINFO 7 /* get copy of load average structure */ +#define SI_CALL_STATS 9 /* system call statistics */ +#define SI_PROCPUB_TAB 11 /* copy of public entries of process table */ #endif diff --git a/include/minix/type.h b/include/minix/type.h index c88d8de2e..5dc039f74 100644 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -198,20 +198,5 @@ struct k_randomness { } bin[RANDOM_SOURCES]; }; -/* information on PCI devices */ - -#define PCIINFO_ENTRY_SIZE 80 - -struct pciinfo_entry { - u16_t pie_vid; - u16_t pie_did; - char pie_name[PCIINFO_ENTRY_SIZE]; -}; - -struct pciinfo { - size_t pi_count; - struct pciinfo_entry pi_entries[NR_PCIDEV]; -}; - #endif /* _TYPE_H */ diff --git a/include/unistd.h b/include/unistd.h index 24ff7e0a5..3edcdbf83 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -41,20 +41,6 @@ #define _PM_SEG_FLAG (1L << 30) /* for read() and write() to FS by PM */ #endif -/* What system info to retrieve with sysgetinfo(). */ -#define SI_KINFO 0 /* get kernel info via PM */ -#define SI_PROC_ADDR 1 /* address of process table */ -#define SI_PROC_TAB 2 /* copy of entire process table */ -#define SI_DMAP_TAB 3 /* get device <-> driver mappings */ -#define SI_MEM_ALLOC 4 /* get memory allocation data */ -#define SI_DATA_STORE 5 /* get copy of data store mappings */ -#define SI_SUBSCRIPTION 6 /* get copy of data store subscriptions */ -#define SI_LOADINFO 7 /* get copy of load average structure */ -#define SI_KPROC_TAB 8 /* copy of kernel process table */ -#define SI_CALL_STATS 9 /* system call statistics */ -#define SI_PCI_INFO 10 /* get kernel info via PM */ -#define SI_PROCPUB_TAB 11 /* copy of public entries of process table */ - /* NULL must be defined in according to POSIX Sec. 2.7.1. */ #include @@ -198,7 +184,6 @@ _PROTOTYPE( char *crypt, (const char *_key, const char *_salt) ); #endif -_PROTOTYPE( int getsysinfo, (endpoint_t who, int what, void *where) ); _PROTOTYPE( int getsigset, (sigset_t *sigset) ); _PROTOTYPE( int getprocnr, (void) ); _PROTOTYPE( int getnprocnr, (pid_t pid) ); diff --git a/lib/libc/other/Makefile.inc b/lib/libc/other/Makefile.inc index d8d902692..5950d97f1 100644 --- a/lib/libc/other/Makefile.inc +++ b/lib/libc/other/Makefile.inc @@ -20,7 +20,6 @@ SRCS+= \ _getpprocnr.c \ _getprocnr.c \ _getsigset.c \ - _getsysinfo.c \ _lseek64.c \ _mapdriver.c \ _mcontext.c \ diff --git a/lib/libc/other/_getsysinfo.c b/lib/libc/other/_getsysinfo.c deleted file mode 100644 index e43b3d4d8..000000000 --- a/lib/libc/other/_getsysinfo.c +++ /dev/null @@ -1,77 +0,0 @@ - -#include -#include -#include -#include -#define getsysinfo _getsysinfo -#define getsysinfo_up _getsysinfo_up -#include -#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 */ -int what; /* what information is requested */ -void *where; /* where to put it */ -{ - message m; - m.m1_i1 = what; - m.m1_p1 = where; - if (_syscall(who, GETSYSINFO, &m) < 0) return(-1); - 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 */ -int what; /* what information is requested */ -size_t size; /* input and output size */ -void *where; /* where to put it */ -{ - message m; - m.SIU_WHAT = what; - m.SIU_WHERE = where; - m.SIU_LEN = size; - return _syscall(who, GETSYSINFO_UP, &m); -} - diff --git a/lib/libc/syscall/Makefile.inc b/lib/libc/syscall/Makefile.inc index 05ed54ebf..6c81ffcce 100644 --- a/lib/libc/syscall/Makefile.inc +++ b/lib/libc/syscall/Makefile.inc @@ -56,7 +56,6 @@ SRCS+= \ getpprocnr.S \ getprocnr.S \ getsigset.S \ - getsysinfo.S \ getuid.S \ ioctl.S \ isatty.S \ diff --git a/lib/libc/syscall/getsysinfo.S b/lib/libc/syscall/getsysinfo.S deleted file mode 100644 index cd413b4b1..000000000 --- a/lib/libc/syscall/getsysinfo.S +++ /dev/null @@ -1,10 +0,0 @@ -#include - -IMPORT(_getsysinfo) -ENTRY(getsysinfo) - jmp _C_LABEL(_getsysinfo) - -IMPORT(_getsysinfo_up) -ENTRY(getsysinfo_up) - jmp _C_LABEL(_getsysinfo_up) - diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index e33d25942..f2475d135 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -5,6 +5,7 @@ LIB= sys SRCS= \ alloc_util.c \ assert.c \ + getsysinfo.c \ kernel_call.c \ panic.c \ pci_attr_r16.c \ diff --git a/lib/libsys/getidle.c b/lib/libsys/getidle.c index 90893fbfe..ce7ddf70d 100644 --- a/lib/libsys/getidle.c +++ b/lib/libsys/getidle.c @@ -6,21 +6,19 @@ * getidle(); * ... * idleperc = getidle(); - * printf("CPU usage: %lg%%\n", 100.0 - idleperc); + * if (idleperc >= 0.0) + * printf("CPU usage: %lg%%\n", 100.0 - idleperc); * - * This routine goes through PM to get the idle time, rather than making the - * sys_getinfo() call to the kernel directly. This means that it can be used - * by non-system processes as well, but it will incur some extra overhead in - * the system case. The overhead does not end up being measured, because the - * system is clearly not idle while the system calls are being made. In any - * case, for this reason, only one getidle() run is allowed at a time. + * Notes: + * - This functionality can only be used by system processes. + * - The kernel has to be compiled with CONFIG_IDLE_TSC support. + * - Only one getidle() run is allowed per process at a time. * - * Note that the kernel has to be compiled with CONFIG_IDLE_TSC support. */ #define _MINIX 1 #define _SYSTEM 1 -#include +#include #include #include @@ -52,8 +50,7 @@ double getidle(void) int r; if (!running) { - r = getsysinfo_up(PM_PROC_NR, SIU_IDLETSC, sizeof(idle), &idle); - if (r != sizeof(idle)) + if ((r = sys_getidletsc(&idle)) != OK) return -1.0; running = 1; @@ -67,8 +64,7 @@ double getidle(void) running = 0; - r = getsysinfo_up(PM_PROC_NR, SIU_IDLETSC, sizeof(idle2), &idle2); - if (r != sizeof(idle2)) + if ((r = sys_getidletsc(&idle2)) != OK) return -1.0; idelta = sub64(idle2, idle); diff --git a/lib/libsys/getsysinfo.c b/lib/libsys/getsysinfo.c new file mode 100644 index 000000000..575a90051 --- /dev/null +++ b/lib/libsys/getsysinfo.c @@ -0,0 +1,16 @@ + +#include +#include +#include + +PUBLIC int getsysinfo(who, what, where) +endpoint_t who; /* from whom to request info */ +int what; /* what information is requested */ +void *where; /* where to put it */ +{ + message m; + m.SI_WHAT = what; + m.SI_WHERE = where; + if (_syscall(who, COMMON_GETSYSINFO, &m) < 0) return(-1); + return(0); +} diff --git a/lib/libsys/pci_dev_name.c b/lib/libsys/pci_dev_name.c index f9ca48472..b4dfb1ba1 100644 --- a/lib/libsys/pci_dev_name.c +++ b/lib/libsys/pci_dev_name.c @@ -11,7 +11,7 @@ pci_dev_name.c *===========================================================================*/ PUBLIC char *pci_dev_name(u16_t vid, u16_t did) { - static char name[PCIINFO_ENTRY_SIZE]; /* We need a better interface for this */ + static char name[80]; /* We need a better interface for this */ int r; cp_grant_id_t gid; diff --git a/servers/ds/inc.h b/servers/ds/inc.h index 34064bd26..66f282415 100644 --- a/servers/ds/inc.h +++ b/servers/ds/inc.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include #include #include -#include #include #include "proto.h" diff --git a/servers/ds/main.c b/servers/ds/main.c index 27a59a9e1..0b7ba6f8e 100644 --- a/servers/ds/main.c +++ b/servers/ds/main.c @@ -72,7 +72,7 @@ PUBLIC int main(int argc, char **argv) case DS_SNAPSHOT: result = do_snapshot(&m); break; - case GETSYSINFO: + case COMMON_GETSYSINFO: result = do_getsysinfo(&m); break; default: diff --git a/servers/is/inc.h b/servers/is/inc.h index 08174df46..11e397f5b 100644 --- a/servers/is/inc.h +++ b/servers/is/inc.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/servers/pm/main.c b/servers/pm/main.c index 3032ff22a..09dbda2e3 100644 --- a/servers/pm/main.c +++ b/servers/pm/main.c @@ -128,6 +128,9 @@ PUBLIC int main() else result= ENOSYS; break; + case COMMON_GETSYSINFO: + result = do_getsysinfo(); + break; default: /* Else, if the system call number is valid, perform the * call. diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 4efccf2ce..fa5a2f2a1 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -60,8 +60,6 @@ PRIVATE char *uts_tbl[] = { PUBLIC unsigned long calls_stats[NCALLS]; #endif -FORWARD _PROTOTYPE( int getpciinfo, (struct pciinfo *pciinfo) ); - /*===========================================================================* * do_procstat * *===========================================================================*/ @@ -160,7 +158,6 @@ PUBLIC int do_getsysinfo() vir_bytes src_addr, dst_addr; struct kinfo kinfo; struct loadinfo loadinfo; - struct pciinfo pciinfo; static struct proc proctab[NR_PROCS+NR_TASKS]; size_t len; int s, r; @@ -174,38 +171,25 @@ PUBLIC int do_getsysinfo() return EPERM; } + /* This call should no longer be used by user applications. In the future, + * requests from non-system processes should be denied. For now, just warn. + */ + if (call_nr == GETSYSINFO) + { + printf("PM: obsolete call of do_getsysinfo() by proc %d '%s'\n", + mp->mp_endpoint, mp->mp_name); + } + switch(m_in.info_what) { - case SI_KINFO: /* kernel info is obtained via PM */ - sys_getkinfo(&kinfo); - src_addr = (vir_bytes) &kinfo; - len = sizeof(struct kinfo); - break; - case SI_PROC_ADDR: /* get address of PM process table */ - proc_addr = &mproc[0]; - src_addr = (vir_bytes) &proc_addr; - len = sizeof(struct mproc *); - break; case SI_PROC_TAB: /* copy entire process table */ src_addr = (vir_bytes) mproc; len = sizeof(struct mproc) * NR_PROCS; break; - case SI_KPROC_TAB: /* copy entire process table */ - if((r=sys_getproctab(proctab)) != OK) - return r; - src_addr = (vir_bytes) proctab; - len = sizeof(proctab); - break; case SI_LOADINFO: /* loadinfo is obtained via PM */ sys_getloadinfo(&loadinfo); src_addr = (vir_bytes) &loadinfo; len = sizeof(struct loadinfo); break; - case SI_PCI_INFO: /* PCI info is obtained via PM */ - if ((r=getpciinfo(&pciinfo)) != OK) - return r; - src_addr = (vir_bytes) &pciinfo; - len = sizeof(struct pciinfo); - break; #if ENABLE_SYSCALL_STATS case SI_CALL_STATS: src_addr = (vir_bytes) calls_stats; @@ -230,9 +214,11 @@ PUBLIC int do_getsysinfo_up() vir_bytes src_addr, dst_addr; struct loadinfo loadinfo; size_t len, real_len; - u64_t idle_tsc; int s; + printf("PM: obsolete call of do_getsysinfo_up() by proc %d '%s'\n", + mp->mp_endpoint, mp->mp_name); + switch(m_in.SIU_WHAT) { case SIU_LOADINFO: /* loadinfo is obtained via PM */ if ((s = sys_getloadinfo(&loadinfo)) != OK) @@ -244,12 +230,6 @@ PUBLIC int do_getsysinfo_up() src_addr = (vir_bytes) &system_hz; real_len = sizeof(system_hz); break; - case SIU_IDLETSC: - if ((s = sys_getidletsc(&idle_tsc)) != OK) - return s; - src_addr = (vir_bytes) &idle_tsc; - real_len = sizeof(idle_tsc); - break; default: return(EINVAL); } @@ -580,45 +560,3 @@ char *brk_addr; _brksize = brk_addr; return 0; } - -/*===========================================================================* - * getpciinfo * - *===========================================================================*/ - -PRIVATE int getpciinfo(pciinfo) -struct pciinfo *pciinfo; -{ - int devind, r; - struct pciinfo_entry *entry; - char *name; - u16_t vid, did; - - /* look up PCI process number */ - pci_init(); - - /* start enumerating devices */ - entry = pciinfo->pi_entries; - r = pci_first_dev(&devind, &vid, &did); - while (r) - { - /* fetch device name */ - name = pci_dev_name(vid, did); - if (!name) - name = ""; - - /* store device information in table */ - assert((char *) entry < (char *) (pciinfo + 1)); - entry->pie_vid = vid; - entry->pie_did = did; - strncpy(entry->pie_name, name, sizeof(entry->pie_name)); - entry->pie_name[sizeof(entry->pie_name) - 1] = 0; - entry++; - - /* continue with the next device */ - r = pci_next_dev(&devind, &vid, &did); - } - - /* store number of entries */ - pciinfo->pi_count = entry - pciinfo->pi_entries; - return OK; -} diff --git a/servers/rs/inc.h b/servers/rs/inc.h index 9c4cbba52..70bd8b7fc 100644 --- a/servers/rs/inc.h +++ b/servers/rs/inc.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #include #include #include -#include #include #include #include diff --git a/servers/rs/main.c b/servers/rs/main.c index a314938f8..a5293e3fa 100644 --- a/servers/rs/main.c +++ b/servers/rs/main.c @@ -91,7 +91,7 @@ PUBLIC int main(void) * Handle the request and send a reply to the caller. */ else { - if (call_nr != GETSYSINFO && + if (call_nr != COMMON_GETSYSINFO && (call_nr < RS_RQ_BASE || call_nr >= RS_RQ_BASE+0x100)) { /* Ignore invalid requests. Do not try to reply. */ @@ -111,7 +111,8 @@ PUBLIC int main(void) case RS_UPDATE: result = do_update(&m); break; case RS_CLONE: result = do_clone(&m); break; case RS_EDIT: result = do_edit(&m); break; - case GETSYSINFO: result = do_getsysinfo(&m); break; + case COMMON_GETSYSINFO: + result = do_getsysinfo(&m); break; case RS_LOOKUP: result = do_lookup(&m); break; /* Ready messages. */ case RS_INIT: result = do_init_ready(&m); break; diff --git a/servers/vfs/fscall.c b/servers/vfs/fscall.c index c6026ef4a..249c41efc 100644 --- a/servers/vfs/fscall.c +++ b/servers/vfs/fscall.c @@ -130,18 +130,14 @@ message *m; /* request/reply message pointer */ /* Initialize global variables for the nested call */ set_globals(m); - /* Perform the nested call */ - if (call_nr < 0 || call_nr >= NCALLS) { + /* Perform the nested call - only getsysinfo() is allowed right now */ + if (call_nr == COMMON_GETSYSINFO) { + r = do_getsysinfo(); + } else { printf("VFS: invalid nested call %d from FS %d\n", call_nr, who_e); r = ENOSYS; - } else { -#if ENABLE_SYSCALL_STATS - calls_stats[call_nr]++; -#endif - - r = (*call_vec[call_nr])(); } /* Store the result, and restore original global variables */ diff --git a/servers/vfs/main.c b/servers/vfs/main.c index 0a1b6a1f3..5588dc71e 100644 --- a/servers/vfs/main.c +++ b/servers/vfs/main.c @@ -162,7 +162,10 @@ PUBLIC int main(void) error= do_mapdriver(); if (error != SUSPEND) reply(who_e, error); break; - + case COMMON_GETSYSINFO: + error= do_getsysinfo(); + if (error != SUSPEND) reply(who_e, error); + break; default: /* Call the internal function that does the work. */ if (call_nr < 0 || call_nr >= NCALLS) { diff --git a/servers/vfs/misc.c b/servers/vfs/misc.c index 620db3c1c..924803a6c 100644 --- a/servers/vfs/misc.c +++ b/servers/vfs/misc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -72,12 +73,15 @@ PUBLIC int do_getsysinfo() if (!super_user) return(EPERM); + /* This call should no longer be used by user applications. In the future, + * requests from non-system processes should be denied. For now, just warn. + */ + if (call_nr == GETSYSINFO) { + printf("VFS: obsolete call of do_getsysinfo() by proc %d\n", + fp->fp_endpoint); + } + switch(m_in.info_what) { - case SI_PROC_ADDR: - proc_addr = &fproc[0]; - src_addr = (vir_bytes) &proc_addr; - len = sizeof(struct fproc *); - break; case SI_PROC_TAB: src_addr = (vir_bytes) fproc; len = sizeof(struct fproc) * NR_PROCS; diff --git a/servers/vfs/table.c b/servers/vfs/table.c index c46a04cca..b2557df8a 100644 --- a/servers/vfs/table.c +++ b/servers/vfs/table.c @@ -112,7 +112,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = { do_ftruncate, /* 94 = truncate */ do_chmod, /* 95 = fchmod */ do_chown, /* 96 = fchown */ - no_sys, /* 97 = getsysinfo_up */ + no_sys, /* 97 = (getsysinfo_up) */ no_sys, /* 98 = (sprofile) */ no_sys, /* 99 = (cprofile) */ /* THE MINIX3 ABI ENDS HERE */