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 r, param;
int param;
endpoint_t proc_e = NONE;
struct sysgetenv sysgetenv;
message m;
char *to_whom, *operation, *what, *value;
unsigned i;
@ -60,10 +59,7 @@ int main (int argc, char *argv[])
else
usage();
m.m2_i1 = param;
m.m2_p1 = (char *) &sysgetenv;
r = _syscall(proc_e, SVRCTL, &m);
if (r != 0) {
if (svrctl(param, &sysgetenv) != 0) {
if (errno == ESRCH)
fprintf(stderr, "invalid parameter: %s\n", what);
else if (errno == EINVAL)
@ -87,10 +83,7 @@ int main (int argc, char *argv[])
else
usage();
m.m2_i1 = param;
m.m2_p1 = (char *) &sysgetenv;
r = _syscall(proc_e, SVRCTL, &m);
if (r != 0) {
if (svrctl(param, &sysgetenv) != 0) {
if (errno == ESRCH)
fprintf(stderr, "invalid parameter: %s\n", what);
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. */
#define EXIT 1
@ -66,7 +66,7 @@
#define SIGRETURN 75
#define REBOOT 76
#define SVRCTL 77
#define PM_SVRCTL 77 /* to PM */
#define SYSUNAME 78
#define LLSEEK 81 /* to VFS */
#define GETVFSSTAT 82 /* to VFS */
@ -106,6 +106,11 @@
#define VFS_VMCALL 117
#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 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_GETSYSINFO (RS_RQ_BASE + 9) /* get system information */
#define RS_INIT (RS_RQ_BASE + 20) /* service init 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_SNAPSHOT (DS_RQ_BASE + 5) /* take a snapshot */
#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 */
# define DS_KEY_GRANT m2_i1 /* key for the data */
@ -816,11 +819,10 @@
# define GCOV_BUFF_P m1_p1
# define GCOV_BUFF_SZ m1_i1
/* Common request to several system servers: retrieve system information. */
#define COMMON_GETSYSINFO (COMMON_RQ_BASE+2)
# define SI_WHAT m1_i1
# define SI_WHERE m1_p1
# define SI_SIZE m1_i2
/* Field names for the getsysinfo(2) call. */
#define SI_WHAT m1_i1
#define SI_WHERE m1_p1
#define SI_SIZE m1_i2
/* PM field names */
/* BRK */

View file

@ -22,10 +22,10 @@ int getrusage(int who, struct rusage *r_usage)
}
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;
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;
m.RU_RUSAGE_ADDR = r_usage;
return _syscall(VM_PROC_NR, VM_GETRUSAGE, &m);

View file

@ -16,11 +16,11 @@ int svrctl(int request, void *argp)
case 'M':
case 'S':
/* 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 'I':
/* VFS handles calls for itself and inet. */
return _syscall(VFS_PROC_NR, SVRCTL, &m);
return _syscall(VFS_PROC_NR, VFS_SVRCTL, &m);
default:
errno = EINVAL;
return -1;

View file

@ -1,5 +1,6 @@
#include "syslib.h"
#include <string.h>
#include <minix/sysinfo.h>
#include <minix/com.h>
@ -12,9 +13,20 @@ int getsysinfo(
)
{
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));
m.SI_WHAT = what;
m.SI_WHERE = where;
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:
result = do_check(&m);
break;
case COMMON_GETSYSINFO:
case DS_GETSYSINFO:
result = do_getsysinfo(&m);
break;
default:

View file

@ -116,9 +116,6 @@ 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.

View file

@ -88,7 +88,7 @@ int (*call_vec[])(void) = {
do_sigprocmask, /* 74 = sigprocmask */
do_sigreturn, /* 75 = sigreturn */
do_reboot, /* 76 = reboot */
do_svrctl, /* 77 = svrctl */
do_svrctl, /* 77 = pm_svrctl */
do_sysuname, /* 78 = sysuname */
no_sys, /* 79 = unused */
no_sys, /* 80 = (getdents) */
@ -134,8 +134,12 @@ int (*call_vec[])(void) = {
no_sys, /* 120 = unsused */
no_sys, /* 121 = (task reply) */
no_sys, /* 122 = (map driver ) */
do_getrusage, /* 123 = getrusage */
do_getrusage, /* 123 = pm_getrusage */
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": */
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.
*/
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. */
switch(call_nr) {
/* User requests. */
@ -113,8 +104,7 @@ 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 COMMON_GETSYSINFO:
result = do_getsysinfo(&m); break;
case RS_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;
@ -122,7 +112,7 @@ int main(void)
default:
printf("RS: warning: got unexpected request %d from %d\n",
m.m_type, m.m_source);
result = EINVAL;
result = ENOSYS;
}
/* Finally send reply message, unless disabled. */

View file

@ -233,27 +233,23 @@ static void do_work(void)
memset(&m_out, 0, sizeof(m_out));
if (job_call_nr == COMMON_GETSYSINFO) {
error = do_getsysinfo();
/* 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 {
/* 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
calls_stats[job_call_nr]++;
calls_stats[job_call_nr]++;
#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. */

View file

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

View file

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

View file

@ -91,7 +91,7 @@ int (*call_vec[])(message *m_out) = {
no_sys, /* 74 = (sigprocmask) */
no_sys, /* 75 = (sigreturn) */
no_sys, /* 76 = (reboot) */
do_svrctl, /* 77 = svrctl */
no_sys, /* 77 = (pm_svrctl) */
no_sys, /* 78 = (sysuname) */
no_sys, /* 79 = unused */
no_sys, /* 80 = unused */
@ -137,8 +137,12 @@ int (*call_vec[])(message *m_out) = {
no_sys, /* 120 = unsused */
no_sys, /* 121 = (task reply) */
do_mapdriver, /* 122 = mapdriver */
do_getrusage, /* 123 = getrusage */
no_sys, /* 123 = (pm_getrusage) */
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": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];