libsys: various updates

- move system calls for use by services from libminlib into libsys;
- move srv_fork(2) and srv_kill(2) from RS and into libsys;
- replace getprocnr(2) with sef_self(3);
- rename previous getnprocnr(2) to getprocnr(2);
- clean up getepinfo(2);
- change all libsys calls that used _syscall to use _taskcall, so as
  to avoid going through errno to pass errors; this is already how
  most calls work anyway, and many of the calls previously using
  _syscall were already assumed to return the actual error;
- initialize request messages to zero, for future compatibility
  (note that this does not include PCI calls, which are in need of a
  much bigger overhaul, nor kernel calls);
- clean up more of dead DS code as a side effect.

Change-Id: I8788f54c68598fcf58e23486e270c2d749780ebb
This commit is contained in:
David van Moolenbroek
2013-11-03 22:33:44 +01:00
committed by Lionel Sambuc
parent efd3487bc5
commit 80bd109cd3
82 changed files with 477 additions and 544 deletions

View File

@@ -11,7 +11,6 @@
#define NR_DS_KEYS (2*NR_SYS_PROCS) /* number of entries */
#define NR_DS_SUBS (4*NR_SYS_PROCS) /* number of subscriptions */
#define NR_DS_SNAPSHOT 5 /* number of snapshots */
/* Base 'class' for the following 3 structs. */
struct data_store {
@@ -26,13 +25,6 @@ struct data_store {
size_t length;
size_t reallen;
} mem;
struct dsi_map {
void *data;
size_t length;
void *realpointer;
void *snapshots[NR_DS_SNAPSHOT];
int sindex;
} map;
} u;
};

View File

@@ -30,8 +30,6 @@ EXTERN gid_t caller_gid;
EXTERN int req_nr;
EXTERN endpoint_t SELF_E;
EXTERN char user_path[PATH_MAX+1]; /* pathname to be processed */
EXTERN dev_t fs_dev; /* The device that is handled by this FS proc

View File

@@ -152,8 +152,6 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
init_inode_cache();
SELF_E = getprocnr();
/* just a small number before we find out the block size at mount time */
lmfs_buf_pool(10);
@@ -214,5 +212,5 @@ static void reply(
)
{
if (OK != send(who, m_out)) /* send the message */
printf("ext2(%d) was unable to send reply\n", SELF_E);
printf("ext2(%d) was unable to send reply\n", sef_self());
}

View File

@@ -44,5 +44,3 @@ void sem_process_vm_notify(void);
EXTERN int identifier;
EXTERN endpoint_t who_e;
EXTERN int call_type;
EXTERN endpoint_t SELF_E;

View File

@@ -3,7 +3,6 @@
int identifier = 0x1234;
endpoint_t who_e;
int call_type;
endpoint_t SELF_E;
static struct {
int type;
@@ -140,10 +139,8 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
{
/* Initialize the ipc server. */
SELF_E = getprocnr();
if(verbose)
printf("IPC: self: %d\n", SELF_E);
printf("IPC: self: %d\n", sef_self());
return(OK);
}

View File

@@ -312,7 +312,7 @@ int do_semctl(message *m)
ds = (struct semid_ds *) opt;
if (!ds)
return EFAULT;
r = sys_datacopy(SELF_E, (vir_bytes) &sem->semid_ds,
r = sys_datacopy(SELF, (vir_bytes) &sem->semid_ds,
who_e, (vir_bytes) ds, sizeof(struct semid_ds));
if (r != OK)
return EINVAL;
@@ -325,7 +325,7 @@ int do_semctl(message *m)
return EPERM;
ds = (struct semid_ds *) opt;
r = sys_datacopy(who_e, (vir_bytes) ds,
SELF_E, (vir_bytes) &tmp_ds, sizeof(struct semid_ds));
SELF, (vir_bytes) &tmp_ds, sizeof(struct semid_ds));
if (r != OK)
return EINVAL;
sem->semid_ds.sem_perm.uid = tmp_ds.sem_perm.uid;
@@ -357,7 +357,7 @@ int do_semctl(message *m)
return ENOMEM;
for (i = 0; i < sem->semid_ds.sem_nsems; i++)
buf[i] = sem->sems[i].semval;
r = sys_datacopy(SELF_E, (vir_bytes) buf,
r = sys_datacopy(SELF, (vir_bytes) buf,
who_e, (vir_bytes) opt,
sizeof(unsigned short) * sem->semid_ds.sem_nsems);
if (r != OK)
@@ -389,7 +389,7 @@ int do_semctl(message *m)
if (!buf)
return ENOMEM;
r = sys_datacopy(who_e, (vir_bytes) opt,
SELF_E, (vir_bytes) buf,
SELF, (vir_bytes) buf,
sizeof(unsigned short) * sem->semid_ds.sem_nsems);
if (r != OK)
return EINVAL;
@@ -470,7 +470,7 @@ int do_semop(message *m)
if (!sops)
goto out_free;
r = sys_datacopy(who_e, (vir_bytes) m->SEMOP_OPS,
SELF_E, (vir_bytes) sops,
SELF, (vir_bytes) sops,
sizeof(struct sembuf) * nsops);
if (r != OK) {
r = EINVAL;

View File

@@ -76,7 +76,7 @@ int do_shmget(message *m)
PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
if (shm->page == (vir_bytes) MAP_FAILED)
return ENOMEM;
shm->vm_id = vm_getphys(SELF_E, (void *) shm->page);
shm->vm_id = vm_getphys(sef_self(), (void *) shm->page);
memset((void *)shm->page, 0, size);
shm->shmid_ds.shm_perm.cuid =
@@ -132,7 +132,7 @@ int do_shmat(message *m)
if (!check_perm(&shm->shmid_ds.shm_perm, who_e, flag))
return EACCES;
ret = vm_remap(who_e, SELF_E, (void *)addr, (void *)shm->page,
ret = vm_remap(who_e, sef_self(), (void *)addr, (void *)shm->page,
shm->shmid_ds.shm_segsz);
if (ret == MAP_FAILED)
return ENOMEM;
@@ -155,7 +155,7 @@ void update_refcount_and_destroy(void)
for (i = 0, j = 0; i < shm_list_nr; i++) {
u8_t rc;
rc = vm_getrefcount(SELF_E, (void *) shm_list[i].page);
rc = vm_getrefcount(sef_self(), (void *) shm_list[i].page);
if (rc == (u8_t) -1) {
printf("IPC: can't find physical region.\n");
continue;
@@ -243,7 +243,7 @@ int do_shmctl(message *m)
/* check whether it has read permission */
if (!check_perm(&shm->shmid_ds.shm_perm, who_e, 0444))
return EACCES;
r = sys_datacopy(SELF_E, (vir_bytes)&shm->shmid_ds,
r = sys_datacopy(SELF, (vir_bytes)&shm->shmid_ds,
who_e, (vir_bytes)ds, sizeof(struct shmid_ds));
if (r != OK)
return EFAULT;
@@ -255,7 +255,7 @@ int do_shmctl(message *m)
uid != 0)
return EPERM;
r = sys_datacopy(who_e, (vir_bytes)ds,
SELF_E, (vir_bytes)&tmp_ds, sizeof(struct shmid_ds));
SELF, (vir_bytes)&tmp_ds, sizeof(struct shmid_ds));
if (r != OK)
return EFAULT;
shm->shmid_ds.shm_perm.uid = tmp_ds.shm_perm.uid;
@@ -282,7 +282,7 @@ int do_shmctl(message *m)
sinfo.shmmni = MAX_SHM_NR;
sinfo.shmseg = (unsigned long) -1;
sinfo.shmall = (unsigned long) -1;
r = sys_datacopy(SELF_E, (vir_bytes)&sinfo,
r = sys_datacopy(SELF, (vir_bytes)&sinfo,
who_e, (vir_bytes)ds, sizeof(struct shminfo));
if (r != OK)
return EFAULT;
@@ -302,7 +302,7 @@ int do_shmctl(message *m)
s_info.shm_swp = 0;
s_info.swap_attempts = 0;
s_info.swap_successes = 0;
r = sys_datacopy(SELF_E, (vir_bytes)&s_info,
r = sys_datacopy(SELF, (vir_bytes)&s_info,
who_e, (vir_bytes)ds, sizeof(struct shm_info));
if (r != OK)
return EFAULT;
@@ -314,7 +314,7 @@ int do_shmctl(message *m)
if (id < 0 || id >= shm_list_nr)
return EINVAL;
shm = &shm_list[id];
r = sys_datacopy(SELF_E, (vir_bytes)&shm->shmid_ds,
r = sys_datacopy(SELF, (vir_bytes)&shm->shmid_ds,
who_e, (vir_bytes)ds, sizeof(struct shmid_ds));
if (r != OK)
return EFAULT;

View File

@@ -16,8 +16,6 @@ static message m_out; /* the output message used for reply */
static endpoint_t who_e; /* caller's proc number */
static int callnr; /* system call number */
extern int errno; /* error number set by system library */
/* Declare some local functions. */
static void get_work(void);
static void reply(int whom, int result);

View File

@@ -21,8 +21,6 @@ EXTERN gid_t caller_gid;
EXTERN int req_nr; /* request number to the server */
EXTERN int SELF_E; /* process number */
EXTERN short path_processed; /* number of characters processed */
EXTERN char user_path[PATH_MAX+1]; /* pathname to be processed */
EXTERN char *vfs_slink_storage;

View File

@@ -102,8 +102,6 @@ static int sef_cb_init_fresh(int type, sef_init_info_t *info)
{
/* Initialize the iso9660fs server. */
/* SELF_E will contain the id of this process */
SELF_E = getprocnr();
/* hash_init(); */ /* Init the table with the ids */
setenv("TZ","",1); /* Used to calculate the time */
@@ -145,5 +143,5 @@ int who;
message *m_out; /* report result */
{
if (OK != send(who, m_out)) /* send the message */
printf("ISOFS(%d) was unable to send reply\n", SELF_E);
printf("ISOFS(%d) was unable to send reply\n", sef_self());
}

View File

@@ -20,7 +20,7 @@ int fs_access()
/* Temporarily open the file. */
if ( (rip = get_dir_record(fs_m_in.REQ_INODE_NR)) == NULL) {
printf("ISOFS(%d) get_dir_record by fs_access() failed\n", SELF_E);
printf("ISOFS(%d) get_dir_record by fs_access() failed\n", sef_self());
return(EINVAL);
}

View File

@@ -28,8 +28,6 @@ EXTERN gid_t caller_gid;
EXTERN int req_nr;
EXTERN endpoint_t SELF_E;
EXTERN char user_path[PATH_MAX]; /* pathname to be processed */
EXTERN dev_t fs_dev; /* The device that is handled by this FS proc.

View File

@@ -117,7 +117,6 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
init_inode_cache();
SELF_E = getprocnr();
lmfs_buf_pool(DEFAULT_NR_BUFS);
return(OK);
@@ -177,7 +176,7 @@ static void reply(
)
{
if (OK != send(who, m_out)) /* send the message */
printf("MFS(%d) was unable to send reply\n", SELF_E);
printf("MFS(%d) was unable to send reply\n", sef_self());
}
@@ -194,7 +193,7 @@ static void cch_check(void)
req_nr != REQ_PUTNODE && req_nr != REQ_READSUPER &&
req_nr != REQ_MOUNTPOINT && req_nr != REQ_UNMOUNT &&
req_nr != REQ_SYNC && req_nr != REQ_LOOKUP) {
printf("MFS(%d) inode(%lu) cc: %d req_nr: %d\n", SELF_E,
printf("MFS(%d) inode(%lu) cc: %d req_nr: %d\n", sef_self(),
inode[i].i_num, inode[i].i_count - cch[i], req_nr);
}

View File

@@ -3,7 +3,7 @@
* The entry points into this file are:
* do_reboot: kill all processes, then reboot system
* do_getsysinfo: request copy of PM data structure (Jorrit N. Herder)
* do_getprocnr: lookup process slot number (Jorrit N. Herder)
* do_getprocnr: lookup endpoint by process ID
* do_getepinfo: get the pid/uid/gid of a process given its endpoint
* do_getsetpriority: get/set process priority
* do_svrctl: process manager control
@@ -171,118 +171,40 @@ int do_getsysinfo()
/*===========================================================================*
* do_getprocnr *
*===========================================================================*/
int do_getprocnr()
int do_getprocnr(void)
{
register struct mproc *rmp;
static char search_key[PROC_NAME_LEN+1];
int key_len;
int s;
/* This call should be moved to DS. */
if (mp->mp_effuid != 0)
{
/* For now, allow non-root processes to request their own endpoint. */
if (m_in.pid < 0 && m_in.namelen == 0) {
mp->mp_reply.PM_ENDPT = who_e;
mp->mp_reply.PM_PENDPT = NONE;
return OK;
}
printf("PM: unauthorized call of do_getprocnr by proc %d\n",
mp->mp_endpoint);
sys_diagctl_stacktrace(mp->mp_endpoint);
/* This check should be replaced by per-call ACL checks. */
if (who_e != RS_PROC_NR) {
printf("PM: unauthorized call of do_getprocnr by %d\n", who_e);
return EPERM;
}
#if 0
printf("PM: do_getprocnr(%d) call from endpoint %d, %s\n",
m_in.pid, mp->mp_endpoint, mp->mp_name);
#endif
if (m_in.pid >= 0) { /* lookup process by pid */
if ((rmp = find_proc(m_in.pid)) != NULL) {
mp->mp_reply.PM_ENDPT = rmp->mp_endpoint;
#if 0
printf("PM: pid result: %d\n", rmp->mp_endpoint);
#endif
return(OK);
}
return(ESRCH);
} else if (m_in.namelen > 0) { /* lookup process by name */
key_len = MIN(m_in.namelen, PROC_NAME_LEN);
if (OK != (s=sys_datacopy(who_e, (vir_bytes) m_in.PMBRK_ADDR,
SELF, (vir_bytes) search_key, key_len)))
return(s);
search_key[key_len] = '\0'; /* terminate for safety */
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if (((rmp->mp_flags & (IN_USE | EXITING)) == IN_USE) &&
strncmp(rmp->mp_name, search_key, key_len)==0) {
mp->mp_reply.PM_ENDPT = rmp->mp_endpoint;
return(OK);
}
}
return(ESRCH);
} else { /* return own/parent process number */
#if 0
printf("PM: endpt result: %d\n", mp->mp_reply.PM_ENDPT);
#endif
mp->mp_reply.PM_ENDPT = who_e;
mp->mp_reply.PM_PENDPT = mproc[mp->mp_parent].mp_endpoint;
}
if ((rmp = find_proc(m_in.PM_GETPROCNR_PID)) == NULL)
return(ESRCH);
mp->mp_reply.PM_GETPROCNR_ENDPT = rmp->mp_endpoint;
return(OK);
}
/*===========================================================================*
* do_getepinfo *
*===========================================================================*/
int do_getepinfo()
int do_getepinfo(void)
{
register struct mproc *rmp;
struct mproc *rmp;
endpoint_t ep;
int slot;
ep = m_in.PM_ENDPT;
ep = m_in.PM_GETEPINFO_ENDPT;
if (pm_isokendpt(ep, &slot) != OK)
return(ESRCH);
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) {
mp->mp_reply.reply_res2 = rmp->mp_effuid;
mp->mp_reply.reply_res3 = rmp->mp_effgid;
return(rmp->mp_pid);
}
}
/* Process not found */
return(ESRCH);
}
/*===========================================================================*
* do_getepinfo_o *
*===========================================================================*/
int do_getepinfo_o()
{
register struct mproc *rmp;
endpoint_t ep;
/* This call should be moved to DS. */
if (mp->mp_effuid != 0) {
printf("PM: unauthorized call of do_getepinfo_o by proc %d\n",
mp->mp_endpoint);
sys_diagctl_stacktrace(mp->mp_endpoint);
return EPERM;
}
ep = m_in.PM_ENDPT;
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) {
mp->mp_reply.reply_res2 = (short) rmp->mp_effuid;
mp->mp_reply.reply_res3 = (char) rmp->mp_effgid;
return(rmp->mp_pid);
}
}
/* Process not found */
return(ESRCH);
rmp = &mproc[slot];
mp->mp_reply.PM_GETEPINFO_UID = rmp->mp_effuid;
mp->mp_reply.PM_GETEPINFO_GID = rmp->mp_effgid;
return(rmp->mp_pid);
}
/*===========================================================================*

View File

@@ -49,7 +49,6 @@ int do_sysuname(void);
int do_getsysinfo(void);
int do_getprocnr(void);
int do_getepinfo(void);
int do_getepinfo_o(void);
int do_svrctl(void);
int do_getsetpriority(void);
int do_getrusage(void);

View File

@@ -118,7 +118,7 @@ int (*call_vec[])(void) = {
do_getprocnr, /* 104 = getprocnr */
no_sys, /* 105 = unused */
do_get, /* 106 = issetugid */
do_getepinfo_o, /* 107 = getepinfo XXX: old implementation*/
no_sys, /* 107 = unused */
no_sys, /* 108 = (utimens) */
no_sys, /* 109 = unused */
no_sys, /* 110 = unused */

View File

@@ -413,8 +413,8 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
/* Get pid from PM. */
rp->r_pid = getnpid(rpub->endpoint);
if(rp->r_pid == -1) {
panic("unable to get pid");
if(rp->r_pid < 0) {
panic("unable to get pid: %d", rp->r_pid);
}
}
@@ -433,11 +433,12 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
/* Fork a new RS instance with root:operator. */
pid = srv_fork(0, 0);
if(pid == -1) {
panic("unable to fork a new RS instance");
if(pid < 0) {
panic("unable to fork a new RS instance: %d", pid);
}
replica_pid = pid ? pid : getpid();
replica_endpoint = getnprocnr(replica_pid);
if ((s = getprocnr(replica_pid, &replica_endpoint)) != 0)
panic("unable to get replica endpoint: %d", s);
replica_rp->r_pid = replica_pid;
replica_rp->r_pub->endpoint = replica_endpoint;

View File

@@ -210,30 +210,6 @@ void build_cmd_dep(struct rproc *rp)
rpub->proc_name[len]= '\0';
}
/*===========================================================================*
* srv_fork *
*===========================================================================*/
pid_t srv_fork(uid_t reuid, gid_t regid)
{
message m;
m.m1_i1 = (int) reuid;
m.m1_i2 = (int) regid;
return _syscall(PM_PROC_NR, SRV_FORK, &m);
}
/*===========================================================================*
* srv_kill *
*===========================================================================*/
int srv_kill(pid_t pid, int sig)
{
message m;
m.m1_i1 = pid;
m.m1_i2 = sig;
return(_syscall(PM_PROC_NR, SRV_KILL, &m));
}
/*===========================================================================*
* srv_update *
*===========================================================================*/
@@ -481,14 +457,15 @@ struct rproc *rp;
if(rs_verbose)
printf("RS: forking child with srv_fork()...\n");
child_pid= srv_fork(rp->r_uid, 0); /* Force group to operator for now */
if(child_pid == -1) {
printf("RS: srv_fork() failed (error %d)\n", errno);
if(child_pid < 0) {
printf("RS: srv_fork() failed (error %d)\n", child_pid);
free_slot(rp);
return(errno);
return(child_pid);
}
/* Get endpoint of the child. */
child_proc_nr_e = getnprocnr(child_pid);
if ((s = getprocnr(child_pid, &child_proc_nr_e)) != 0)
panic("unable to get child endpoint: %d", s);
/* There is now a child process. Update the system process table. */
child_proc_nr_n = _ENDPOINT_P(child_proc_nr_e);
@@ -677,8 +654,8 @@ struct rproc *rp; /* pointer to service slot */
*/
setuid(0);
if (mapdriver(rpub->label, rpub->dev_nr) != OK) {
return kill_service(rp, "couldn't map driver", errno);
if ((r = mapdriver(rpub->label, rpub->dev_nr)) != OK) {
return kill_service(rp, "couldn't map driver", r);
}
}
@@ -1133,7 +1110,8 @@ static int run_script(struct rproc *rp)
exit(1);
default:
/* Set the privilege structure for the child process. */
endpoint = getnprocnr(pid);
if ((r = getprocnr(pid, &endpoint)) != 0)
panic("unable to get child endpoint: %d", r);
if ((r = sys_privctl(endpoint, SYS_PRIV_SET_USER, NULL))
!= OK) {
return kill_service(rp,"can't set script privileges",r);

View File

@@ -34,8 +34,6 @@ int copy_rs_start(endpoint_t src_e, char *src_rs_start, struct rs_start
int copy_label(endpoint_t src_e, char *src_label, size_t src_len, char
*dst_label, size_t dst_len);
void build_cmd_dep(struct rproc *rp);
int srv_fork(uid_t reuid, gid_t regid);
int srv_kill(pid_t pid, int sig);
int srv_update(endpoint_t src_e, endpoint_t dst_e);
#define kill_service(rp, errstr, err) \
kill_service_debug(__FILE__, __LINE__, rp, errstr, err)

View File

@@ -123,12 +123,12 @@ int do_mapdriver(message *UNUSED(m_out))
/* Only RS can map drivers. */
if (who_e != RS_PROC_NR) return(EPERM);
label_vir = (vir_bytes) job_m_in.md_label;
label_len = (size_t) job_m_in.md_label_len;
major = job_m_in.md_major;
label_vir = (vir_bytes) job_m_in.VFS_MAPDRIVER_LABEL;
label_len = (size_t) job_m_in.VFS_MAPDRIVER_LABELLEN;
major = job_m_in.VFS_MAPDRIVER_MAJOR;
/* Get the label */
if (label_len+1 > sizeof(label)) { /* Can we store this label? */
if (label_len > sizeof(label)) { /* Can we store this label? */
printf("VFS: do_mapdriver: label too long\n");
return(EINVAL);
}
@@ -137,7 +137,10 @@ int do_mapdriver(message *UNUSED(m_out))
printf("VFS: do_mapdriver: sys_vircopy failed: %d\n", r);
return(EINVAL);
}
label[label_len] = '\0'; /* Terminate label */
if (label[label_len-1] != '\0') {
printf("VFS: do_mapdriver: label not null-terminated\n");
return(EINVAL);
}
/* Now we know how the driver is called, fetch its endpoint */
r = ds_retrieve_label_endpt(label, &endpoint);

View File

@@ -46,9 +46,6 @@
#define whence m2_i2
#define svrctl_req m2_i1
#define svrctl_argp m2_p1
#define md_label m2_p1
#define md_label_len m2_l1
#define md_major m2_i1
/* The following names are synonyms for the variables in the output message. */
#define reply_type m_type