For common calls, give servers unique call numbers

The getsysinfo(2), getrusage(2), and svrctl(2) calls used the same
call number to different services. Since we want to give each service
its own call number ranges, this is no longer tenable. This patch
introduces per-service call numbers for these calls.

Note that the remainder of the COMMON_ range is left intact, as these
the remaining requests in it are processed by SEF and thus server-
agnostic. The range should really be prefixed with SEF_ now.

Change-Id: I80d728bbeb98227359c525494c433965b40fefc3
This commit is contained in:
David van Moolenbroek 2013-10-28 22:30:41 +01:00 committed by Lionel Sambuc
parent 80bd109cd3
commit 44d3230e40
14 changed files with 66 additions and 63 deletions

View file

@ -18,10 +18,9 @@ static char *bin_name;
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
int r, param; int param;
endpoint_t proc_e = NONE; endpoint_t proc_e = NONE;
struct sysgetenv sysgetenv; struct sysgetenv sysgetenv;
message m;
char *to_whom, *operation, *what, *value; char *to_whom, *operation, *what, *value;
unsigned i; unsigned i;
@ -60,10 +59,7 @@ int main (int argc, char *argv[])
else else
usage(); usage();
m.m2_i1 = param; if (svrctl(param, &sysgetenv) != 0) {
m.m2_p1 = (char *) &sysgetenv;
r = _syscall(proc_e, SVRCTL, &m);
if (r != 0) {
if (errno == ESRCH) if (errno == ESRCH)
fprintf(stderr, "invalid parameter: %s\n", what); fprintf(stderr, "invalid parameter: %s\n", what);
else if (errno == EINVAL) else if (errno == EINVAL)
@ -87,10 +83,7 @@ int main (int argc, char *argv[])
else else
usage(); usage();
m.m2_i1 = param; if (svrctl(param, &sysgetenv) != 0) {
m.m2_p1 = (char *) &sysgetenv;
r = _syscall(proc_e, SVRCTL, &m);
if (r != 0) {
if (errno == ESRCH) if (errno == ESRCH)
fprintf(stderr, "invalid parameter: %s\n", what); fprintf(stderr, "invalid parameter: %s\n", what);
else else

View file

@ -1,4 +1,4 @@
#define NCALLS 125 /* number of system calls allowed */ #define NCALLS 129 /* number of system calls allowed */
/* In case it isn't obvious enough: this list is sorted numerically. */ /* In case it isn't obvious enough: this list is sorted numerically. */
#define EXIT 1 #define EXIT 1
@ -66,7 +66,7 @@
#define SIGRETURN 75 #define SIGRETURN 75
#define REBOOT 76 #define REBOOT 76
#define SVRCTL 77 #define PM_SVRCTL 77 /* to PM */
#define SYSUNAME 78 #define SYSUNAME 78
#define LLSEEK 81 /* to VFS */ #define LLSEEK 81 /* to VFS */
#define GETVFSSTAT 82 /* to VFS */ #define GETVFSSTAT 82 /* to VFS */
@ -106,6 +106,11 @@
#define VFS_VMCALL 117 #define VFS_VMCALL 117
#define MAPDRIVER 122 /* to VFS, map a device */ #define MAPDRIVER 122 /* to VFS, map a device */
#define GETRUSAGE 123 /* to PM, VFS */ #define PM_GETRUSAGE 123 /* to PM */
#define VFS_CHECKPERMS 124 /* to VFS */ #define VFS_CHECKPERMS 124 /* to VFS */
#define PM_GETSYSINFO 125 /* to PM */
#define VFS_GETSYSINFO 126 /* to VFS */
#define VFS_GETRUSAGE 127 /* to VFS */
#define VFS_SVRCTL 128 /* to VFS */

View file

@ -648,6 +648,8 @@
#define RS_LOOKUP (RS_RQ_BASE + 8) /* lookup server name */ #define RS_LOOKUP (RS_RQ_BASE + 8) /* lookup server name */
#define RS_GETSYSINFO (RS_RQ_BASE + 9) /* get system information */
#define RS_INIT (RS_RQ_BASE + 20) /* service init message */ #define RS_INIT (RS_RQ_BASE + 20) /* service init message */
#define RS_LU_PREPARE (RS_RQ_BASE + 21) /* prepare to update message */ #define RS_LU_PREPARE (RS_RQ_BASE + 21) /* prepare to update message */
@ -683,6 +685,7 @@
#define DS_DELETE (DS_RQ_BASE + 4) /* delete data */ #define DS_DELETE (DS_RQ_BASE + 4) /* delete data */
#define DS_SNAPSHOT (DS_RQ_BASE + 5) /* take a snapshot */ #define DS_SNAPSHOT (DS_RQ_BASE + 5) /* take a snapshot */
#define DS_RETRIEVE_LABEL (DS_RQ_BASE + 6) /* retrieve label's name */ #define DS_RETRIEVE_LABEL (DS_RQ_BASE + 6) /* retrieve label's name */
#define DS_GETSYSINFO (DS_RQ_BASE + 7) /* get system information */
/* DS field names */ /* DS field names */
# define DS_KEY_GRANT m2_i1 /* key for the data */ # define DS_KEY_GRANT m2_i1 /* key for the data */
@ -816,11 +819,10 @@
# define GCOV_BUFF_P m1_p1 # define GCOV_BUFF_P m1_p1
# define GCOV_BUFF_SZ m1_i1 # define GCOV_BUFF_SZ m1_i1
/* Common request to several system servers: retrieve system information. */ /* Field names for the getsysinfo(2) call. */
#define COMMON_GETSYSINFO (COMMON_RQ_BASE+2) #define SI_WHAT m1_i1
# define SI_WHAT m1_i1 #define SI_WHERE m1_p1
# define SI_WHERE m1_p1 #define SI_SIZE m1_i2
# define SI_SIZE m1_i2
/* PM field names */ /* PM field names */
/* BRK */ /* BRK */

View file

@ -22,10 +22,10 @@ int getrusage(int who, struct rusage *r_usage)
} }
memset(r_usage, 0, sizeof(struct rusage)); memset(r_usage, 0, sizeof(struct rusage));
if ((rc = _syscall(PM_PROC_NR, GETRUSAGE, &m)) < 0) if ((rc = _syscall(PM_PROC_NR, PM_GETRUSAGE, &m)) < 0)
return rc; return rc;
m.RU_RUSAGE_ADDR = r_usage; m.RU_RUSAGE_ADDR = r_usage;
if ((rc = _syscall(VFS_PROC_NR, GETRUSAGE, &m)) < 0) if ((rc = _syscall(VFS_PROC_NR, VFS_GETRUSAGE, &m)) < 0)
return rc; return rc;
m.RU_RUSAGE_ADDR = r_usage; m.RU_RUSAGE_ADDR = r_usage;
return _syscall(VM_PROC_NR, VM_GETRUSAGE, &m); return _syscall(VM_PROC_NR, VM_GETRUSAGE, &m);

View file

@ -16,11 +16,11 @@ int svrctl(int request, void *argp)
case 'M': case 'M':
case 'S': case 'S':
/* PM handles calls for itself and the kernel. */ /* PM handles calls for itself and the kernel. */
return _syscall(PM_PROC_NR, SVRCTL, &m); return _syscall(PM_PROC_NR, PM_SVRCTL, &m);
case 'F': case 'F':
case 'I': case 'I':
/* VFS handles calls for itself and inet. */ /* VFS handles calls for itself and inet. */
return _syscall(VFS_PROC_NR, SVRCTL, &m); return _syscall(VFS_PROC_NR, VFS_SVRCTL, &m);
default: default:
errno = EINVAL; errno = EINVAL;
return -1; return -1;

View file

@ -1,5 +1,6 @@
#include "syslib.h" #include "syslib.h"
#include <string.h> #include <string.h>
#include <minix/sysinfo.h> #include <minix/sysinfo.h>
#include <minix/com.h> #include <minix/com.h>
@ -12,9 +13,20 @@ int getsysinfo(
) )
{ {
message m; message m;
int call_nr;
switch (who) {
case PM_PROC_NR: call_nr = PM_GETSYSINFO; break;
case VFS_PROC_NR: call_nr = VFS_GETSYSINFO; break;
case RS_PROC_NR: call_nr = RS_GETSYSINFO; break;
case DS_PROC_NR: call_nr = DS_GETSYSINFO; break;
default:
return ENOSYS;
}
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.SI_WHAT = what; m.SI_WHAT = what;
m.SI_WHERE = where; m.SI_WHERE = where;
m.SI_SIZE = size; m.SI_SIZE = size;
return _taskcall(who, COMMON_GETSYSINFO, &m); return _taskcall(who, call_nr, &m);
} }

View file

@ -69,7 +69,7 @@ int main(int argc, char **argv)
case DS_CHECK: case DS_CHECK:
result = do_check(&m); result = do_check(&m);
break; break;
case COMMON_GETSYSINFO: case DS_GETSYSINFO:
result = do_getsysinfo(&m); result = do_getsysinfo(&m);
break; break;
default: default:

View file

@ -116,9 +116,6 @@ int main()
else else
result= ENOSYS; result= ENOSYS;
break; break;
case COMMON_GETSYSINFO:
result = do_getsysinfo();
break;
default: default:
/* Else, if the system call number is valid, perform the /* Else, if the system call number is valid, perform the
* call. * call.

View file

@ -88,7 +88,7 @@ int (*call_vec[])(void) = {
do_sigprocmask, /* 74 = sigprocmask */ do_sigprocmask, /* 74 = sigprocmask */
do_sigreturn, /* 75 = sigreturn */ do_sigreturn, /* 75 = sigreturn */
do_reboot, /* 76 = reboot */ do_reboot, /* 76 = reboot */
do_svrctl, /* 77 = svrctl */ do_svrctl, /* 77 = pm_svrctl */
do_sysuname, /* 78 = sysuname */ do_sysuname, /* 78 = sysuname */
no_sys, /* 79 = unused */ no_sys, /* 79 = unused */
no_sys, /* 80 = (getdents) */ no_sys, /* 80 = (getdents) */
@ -134,8 +134,12 @@ int (*call_vec[])(void) = {
no_sys, /* 120 = unsused */ no_sys, /* 120 = unsused */
no_sys, /* 121 = (task reply) */ no_sys, /* 121 = (task reply) */
no_sys, /* 122 = (map driver ) */ no_sys, /* 122 = (map driver ) */
do_getrusage, /* 123 = getrusage */ do_getrusage, /* 123 = pm_getrusage */
no_sys, /* 124 = (checkperms) */ no_sys, /* 124 = (checkperms) */
do_getsysinfo, /* 125 = pm_getsysinfo */
no_sys, /* 126 = (vfs_getsysinfo) */
no_sys, /* 127 = (vfs_getrusage) */
no_sys, /* 128 = (vfs_svrctl) */
}; };
/* This should not fail with "array size is negative": */ /* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];

View file

@ -93,15 +93,6 @@ int main(void)
* Handle the request and send a reply to the caller. * Handle the request and send a reply to the caller.
*/ */
else { else {
if (call_nr != COMMON_GETSYSINFO &&
(call_nr < RS_RQ_BASE || call_nr >= RS_RQ_BASE+0x100))
{
/* Ignore invalid requests. Do not try to reply. */
printf("RS: warning: got invalid request %d from endpoint %d\n",
call_nr, m.m_source);
continue;
}
/* Handler functions are responsible for permission checking. */ /* Handler functions are responsible for permission checking. */
switch(call_nr) { switch(call_nr) {
/* User requests. */ /* User requests. */
@ -113,8 +104,7 @@ int main(void)
case RS_UPDATE: result = do_update(&m); break; case RS_UPDATE: result = do_update(&m); break;
case RS_CLONE: result = do_clone(&m); break; case RS_CLONE: result = do_clone(&m); break;
case RS_EDIT: result = do_edit(&m); break; case RS_EDIT: result = do_edit(&m); break;
case COMMON_GETSYSINFO: case RS_GETSYSINFO: result = do_getsysinfo(&m); break;
result = do_getsysinfo(&m); break;
case RS_LOOKUP: result = do_lookup(&m); break; case RS_LOOKUP: result = do_lookup(&m); break;
/* Ready messages. */ /* Ready messages. */
case RS_INIT: result = do_init_ready(&m); break; case RS_INIT: result = do_init_ready(&m); break;
@ -122,7 +112,7 @@ int main(void)
default: default:
printf("RS: warning: got unexpected request %d from %d\n", printf("RS: warning: got unexpected request %d from %d\n",
m.m_type, m.m_source); m.m_type, m.m_source);
result = EINVAL; result = ENOSYS;
} }
/* Finally send reply message, unless disabled. */ /* Finally send reply message, unless disabled. */

View file

@ -233,27 +233,23 @@ static void do_work(void)
memset(&m_out, 0, sizeof(m_out)); memset(&m_out, 0, sizeof(m_out));
if (job_call_nr == COMMON_GETSYSINFO) { /* At this point we assume that we're dealing with a call that has been
error = do_getsysinfo(); * made specifically to VFS. Typically it will be a POSIX call from a
* normal process, but we also handle a few calls made by drivers such
* such as UDS and VND through here. Call the internal function that
* does the work.
*/
if (job_call_nr < 0 || job_call_nr >= NCALLS) {
error = ENOSYS;
} else if (fp->fp_pid == PID_FREE) {
/* Process vanished before we were able to handle request.
* Replying has no use. Just drop it. */
error = SUSPEND;
} else { } else {
/* At this point we assume that we're dealing with a call that has been
* made specifically to VFS. Typically it will be a POSIX call from a
* normal process, but we also handle a few calls made by drivers such
* such as UDS and VND through here. Call the internal function that
* does the work.
*/
if (job_call_nr < 0 || job_call_nr >= NCALLS) {
error = ENOSYS;
} else if (fp->fp_pid == PID_FREE) {
/* Process vanished before we were able to handle request.
* Replying has no use. Just drop it. */
error = SUSPEND;
} else {
#if ENABLE_SYSCALL_STATS #if ENABLE_SYSCALL_STATS
calls_stats[job_call_nr]++; calls_stats[job_call_nr]++;
#endif #endif
error = (*call_vec[job_call_nr])(&m_out); error = (*call_vec[job_call_nr])(&m_out);
}
} }
/* Copy the results back to the user and send reply. */ /* Copy the results back to the user and send reply. */

View file

@ -51,7 +51,7 @@ static void free_proc(int flags);
/*===========================================================================* /*===========================================================================*
* do_getsysinfo * * do_getsysinfo *
*===========================================================================*/ *===========================================================================*/
int do_getsysinfo() int do_getsysinfo(message *UNUSED(m_out))
{ {
vir_bytes src_addr, dst_addr; vir_bytes src_addr, dst_addr;
size_t len, buf_size; size_t len, buf_size;

View file

@ -115,7 +115,7 @@ int do_sync(message *m_out);
int do_fsync(message *m_out); int do_fsync(message *m_out);
void pm_reboot(void); void pm_reboot(void);
int do_svrctl(message *m_out); int do_svrctl(message *m_out);
int do_getsysinfo(void); int do_getsysinfo(message *m_out);
int do_vm_call(message *m_out); int do_vm_call(message *m_out);
int pm_dumpcore(int sig, vir_bytes exe_name); int pm_dumpcore(int sig, vir_bytes exe_name);
void ds_event(void); void ds_event(void);

View file

@ -91,7 +91,7 @@ int (*call_vec[])(message *m_out) = {
no_sys, /* 74 = (sigprocmask) */ no_sys, /* 74 = (sigprocmask) */
no_sys, /* 75 = (sigreturn) */ no_sys, /* 75 = (sigreturn) */
no_sys, /* 76 = (reboot) */ no_sys, /* 76 = (reboot) */
do_svrctl, /* 77 = svrctl */ no_sys, /* 77 = (pm_svrctl) */
no_sys, /* 78 = (sysuname) */ no_sys, /* 78 = (sysuname) */
no_sys, /* 79 = unused */ no_sys, /* 79 = unused */
no_sys, /* 80 = unused */ no_sys, /* 80 = unused */
@ -137,8 +137,12 @@ int (*call_vec[])(message *m_out) = {
no_sys, /* 120 = unsused */ no_sys, /* 120 = unsused */
no_sys, /* 121 = (task reply) */ no_sys, /* 121 = (task reply) */
do_mapdriver, /* 122 = mapdriver */ do_mapdriver, /* 122 = mapdriver */
do_getrusage, /* 123 = getrusage */ no_sys, /* 123 = (pm_getrusage) */
do_checkperms, /* 124 = checkperms */ do_checkperms, /* 124 = checkperms */
no_sys, /* 125 = (pm_getsysinfo) */
do_getsysinfo, /* 126 = vfs_getsysinfo */
do_getrusage, /* 127 = vfs_getrusage */
do_svrctl, /* 128 = vfs_svrctl */
}; };
/* This should not fail with "array size is negative": */ /* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];