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

@@ -111,7 +111,7 @@ void blockdriver_announce(int type)
}
/* Publish a driver up event. */
if ((r = ds_retrieve_label_name(label, getprocnr())) != OK)
if ((r = ds_retrieve_label_name(label, sef_self())) != OK)
panic("blockdriver_init: unable to get own label: %d", r);
snprintf(key, DS_MAX_KEYLEN, "%s%s", driver_prefix, label);

View File

@@ -110,7 +110,7 @@ void chardriver_announce(void)
panic("chardriver_announce: sys_statectl failed: %d", r);
/* Publish a driver up event. */
if ((r = ds_retrieve_label_name(label, getprocnr())) != OK)
if ((r = ds_retrieve_label_name(label, sef_self())) != OK)
panic("chardriver_announce: unable to get own label: %d", r);
snprintf(key, DS_MAX_KEYLEN, "%s%s", driver_prefix, label);

View File

@@ -26,7 +26,7 @@ i2cdriver_announce(uint32_t bus)
}
/* Publish a driver up event. */
r = ds_retrieve_label_name(label, getprocnr());
r = ds_retrieve_label_name(label, sef_self());
if (r != OK) {
panic("unable to get own label: %d\n", r);
}

View File

@@ -26,7 +26,7 @@ inputdriver_announce(unsigned int type)
int r;
/* Publish a driver up event. */
if ((r = ds_retrieve_label_name(label, getprocnr())) != OK)
if ((r = ds_retrieve_label_name(label, sef_self())) != OK)
panic("libinputdriver: unable to retrieve own label: %d", r);
snprintf(key, sizeof(key), "%s%s", driver_prefix, label);

View File

@@ -30,11 +30,6 @@ SRCS+= servxcheck.c
# queryparam
SRCS+= paramvalue.c
# Minix servers/drivers syscall. FIXME: these should be moved into libsys.
SRCS+= checkperms.c copyfd.c getngid.c getnpid.c getnprocnr.c getnucred.c \
getnuid.c getprocnr.c mapdriver.c vm_memctl.c vm_set_priv.c \
vm_query_exit.c vm_update.c
SRCS+= oneC_sum.c
SUBDIR+= pkgconfig

View File

@@ -1,10 +0,0 @@
#include <lib.h>
#include <unistd.h>
gid_t getngid(endpoint_t proc_ep)
{
message m;
m.m1_i1 = proc_ep; /* search gid for this process */
if (_syscall(PM_PROC_NR, GETEPINFO, &m) < 0) return ( (gid_t) -1);
return( (gid_t) m.m2_i2); /* return search result */
}

View File

@@ -1,9 +0,0 @@
#include <lib.h>
#include <unistd.h>
pid_t getnpid(endpoint_t proc_ep)
{
message m;
m.m1_i1 = proc_ep; /* search pid for this process */
return _syscall(PM_PROC_NR, GETEPINFO, &m);
}

View File

@@ -1,14 +0,0 @@
#include <lib.h>
#include <unistd.h>
int getnprocnr(pid_t pid)
{
message m;
int t = GETPROCNR;
m.m1_i1 = pid; /* pass pid >=0 to search for */
m.m1_i2 = 0; /* don't pass name to search for */
if (_syscall(PM_PROC_NR, t, &m) < 0) return(-1);
return(m.m1_i1); /* return search result */
}

View File

@@ -1,32 +0,0 @@
#include <errno.h>
#include <lib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ucred.h>
int
getnucred(endpoint_t proc_ep, struct uucred *ucred)
{
message m;
pid_t pid;
if (ucred == NULL) {
errno = EFAULT;
return -1;
}
m.m1_i1 = proc_ep; /* search for this process */
pid = _syscall(PM_PROC_NR, GETEPINFO, &m);
if (pid < 0) {
return -1;
}
/* Only two fields are used for now, so ensure the rest is zeroed out. */
memset(ucred, 0, sizeof(struct uucred));
ucred->cr_uid = m.PM_NUID;
ucred->cr_gid = m.PM_NGID;
return 0;
}

View File

@@ -1,10 +0,0 @@
#include <lib.h>
#include <unistd.h>
uid_t getnuid(endpoint_t proc_ep)
{
message m;
m.m1_i1 = proc_ep; /* search uid for this process */
if (_syscall(PM_PROC_NR, GETEPINFO, &m) < 0) return ( (uid_t) -1);
return( (uid_t) m.m2_i1); /* return search result */
}

View File

@@ -1,13 +0,0 @@
#include <lib.h>
#include <unistd.h>
int getprocnr()
{
message m;
m.m1_i1 = -1; /* don't pass pid to search for */
m.m1_i2 = 0; /* don't pass name to search for */
if (_syscall(PM_PROC_NR, GETPROCNR, &m) < 0) return(-1);
return(m.m1_i1); /* return own process number */
}

View File

@@ -1,17 +0,0 @@
#include <lib.h>
#include <string.h>
#include <unistd.h>
int mapdriver(label, major)
char *label;
int major;
{
message m;
m.m2_p1 = label;
m.m2_l1 = strlen(label);
m.m2_i1 = major;
if (_syscall(VFS_PROC_NR, MAPDRIVER, &m) < 0) return(-1);
return(0);
}

View File

@@ -1,11 +0,0 @@
#include <lib.h>
#include <unistd.h>
int vm_memctl(endpoint_t ep, int req)
{
message m;
m.VM_RS_CTL_ENDPT = ep;
m.VM_RS_CTL_REQ = req;
return _syscall(VM_PROC_NR, VM_RS_MEMCTL, &m);
}

View File

@@ -1,33 +0,0 @@
#define _SYSTEM 1
#include <lib.h>
#include <unistd.h>
#include <string.h>
/* return -1, when the query itself or the processing of query has errors.
* return 1, when there are more processes waiting to be queried.
* return 0, when there are no more processes.
* note that for the return value of 0 and 1, the 'endpt' is set accordingly.
*/
int vm_query_exit(int *endpt)
{
message m;
int r;
r = _syscall(VM_PROC_NR, VM_QUERY_EXIT, &m);
if (r != OK)
return -1;
if (endpt == NULL)
return -1;
*endpt = m.VM_QUERY_RET_PT;
return (m.VM_QUERY_IS_MORE ? 1 : 0);
}
int vm_watch_exit(endpoint_t ep)
{
message m;
memset(&m, 0, sizeof(m));
m.VM_WE_EP = ep;
return _syscall(VM_PROC_NR, VM_WATCH_EXIT, &m);
}

View File

@@ -1,12 +0,0 @@
#include <lib.h>
#include <unistd.h>
int vm_set_priv(endpoint_t ep, void *buf, int sys_proc)
{
message m;
m.VM_RS_NR = ep;
m.VM_RS_BUF = (long) buf;
m.VM_RS_SYS = sys_proc;
return _syscall(VM_PROC_NR, VM_RS_SET_PRIV, &m);
}

View File

@@ -1,11 +0,0 @@
#include <lib.h>
#include <unistd.h>
int vm_update(endpoint_t src_e, endpoint_t dst_e)
{
message m;
m.VM_RS_SRC_ENDPT = src_e;
m.VM_RS_DST_ENDPT = dst_e;
return _syscall(VM_PROC_NR, VM_RS_UPDATE, &m);
}

View File

@@ -28,7 +28,7 @@ void netdriver_announce()
char *driver_prefix = "drv.net.";
/* Publish a driver up event. */
r = ds_retrieve_label_name(label, getprocnr());
r = ds_retrieve_label_name(label, sef_self());
if (r != OK) {
panic("driver_announce: unable to get own label: %d\n", r);
}

View File

@@ -43,8 +43,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

@@ -694,7 +694,6 @@ static void sef_local_startup()
static int sef_cb_init_fresh(int type, sef_init_info_t *info)
{
/* Initialize the Minix file server. */
SELF_E = getprocnr();
return(OK);
}
@@ -769,7 +768,7 @@ static void reply(
)
{
if (OK != send(who, m_out)) /* send the message */
lpuffs_debug("libpuffs(%d) was unable to send reply\n", SELF_E);
lpuffs_debug("libpuffs(%d) was unable to send reply\n", sef_self());
last_request_transid = 0;
}

View File

@@ -9,12 +9,16 @@ SRCS+= \
alloc_util.c \
assert.c \
asynsend.c \
checkperms.c \
copyfd.c \
ds.c \
env_get_prm.c \
env_panic.c \
env_parse.c \
env_prefix.c \
fkey_ctl.c \
getepinfo.c \
getprocnr.c \
getticks.c \
getsysinfo.c \
getuptime.c \
@@ -22,6 +26,7 @@ SRCS+= \
kprintf.c \
kputc.c \
kputs.c \
mapdriver.c \
optset.c \
panic.c \
safecopies.c \
@@ -33,6 +38,8 @@ SRCS+= \
sef_ping.c \
sef_signal.c \
sqrt_approx.c \
srv_fork.c \
srv_kill.c \
stacktrace.c \
sys_abort.c \
sys_clear.c \
@@ -84,9 +91,13 @@ SRCS+= \
vm_fork.c \
vm_info.c \
vm_map_phys.c \
vm_memctl.c \
vm_notify_sig.c \
vm_umap.c \
vm_procctl.c \
vm_query_exit.c \
vm_set_priv.c \
vm_update.c \
vprintf.c
.if ${MKPCI} != "no"

View File

@@ -1,4 +1,5 @@
#include <lib.h>
#include "syslib.h"
#include <unistd.h>
#include <string.h>
#include <minix/safecopies.h>
@@ -12,16 +13,16 @@ checkperms(endpoint_t endpt, char *path, size_t size)
if ((grant = cpf_grant_direct(VFS_PROC_NR, (vir_bytes) path, size,
CPF_READ | CPF_WRITE)) == GRANT_INVALID)
return -1; /* called function sets errno */
return ENOMEM;
memset(&m, 0, sizeof(m));
m.VFS_CHECKPERMS_ENDPT = endpt;
m.VFS_CHECKPERMS_GRANT = grant;
m.VFS_CHECKPERMS_COUNT = size;
r = _syscall(VFS_PROC_NR, VFS_CHECKPERMS, &m);
r = _taskcall(VFS_PROC_NR, VFS_CHECKPERMS, &m);
cpf_revoke(grant); /* does not touch errno */
cpf_revoke(grant);
return r;
}

View File

@@ -1,4 +1,5 @@
#include <lib.h>
#include "syslib.h"
#include <string.h>
int
@@ -11,5 +12,5 @@ copyfd(endpoint_t endpt, int fd, int what)
m.VFS_COPYFD_FD = fd;
m.VFS_COPYFD_WHAT = what;
return _syscall(VFS_PROC_NR, COPYFD, &m);
return _taskcall(VFS_PROC_NR, COPYFD, &m);
}

View File

@@ -4,9 +4,7 @@
#include "syslib.h"
static message m;
static int do_invoke_ds(int type, const char *ds_name)
static int do_invoke_ds(message *m, int type, const char *ds_name)
{
cp_grant_id_t g_key;
size_t len_key;
@@ -24,12 +22,12 @@ static int do_invoke_ds(int type, const char *ds_name)
g_key = cpf_grant_direct(DS_PROC_NR, (vir_bytes) ds_name,
len_key, access);
if(!GRANT_VALID(g_key))
return errno;
return ENOMEM;
m.DS_KEY_GRANT = g_key;
m.DS_KEY_LEN = len_key;
m->DS_KEY_GRANT = g_key;
m->DS_KEY_LEN = len_key;
r = _taskcall(DS_PROC_NR, type, &m);
r = _taskcall(DS_PROC_NR, type, m);
cpf_revoke(g_key);
return r;
@@ -37,34 +35,42 @@ static int do_invoke_ds(int type, const char *ds_name)
int ds_publish_label(const char *ds_name, endpoint_t endpoint, int flags)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_VAL = (u32_t) endpoint;
m.DS_FLAGS = DSF_TYPE_LABEL | flags;
return do_invoke_ds(DS_PUBLISH, ds_name);
return do_invoke_ds(&m, DS_PUBLISH, ds_name);
}
int ds_publish_u32(const char *ds_name, u32_t value, int flags)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_VAL = value;
m.DS_FLAGS = DSF_TYPE_U32 | flags;
return do_invoke_ds(DS_PUBLISH, ds_name);
return do_invoke_ds(&m, DS_PUBLISH, ds_name);
}
static int ds_publish_raw(const char *ds_name, void *vaddr, size_t length,
int flags)
{
cp_grant_id_t gid;
message m;
int r;
/* Grant for memory range. */
gid = cpf_grant_direct(DS_PROC_NR, (vir_bytes)vaddr, length, CPF_READ);
if(!GRANT_VALID(gid))
return errno;
return ENOMEM;
memset(&m, 0, sizeof(m));
m.DS_VAL = gid;
m.DS_VAL_LEN = length;
m.DS_FLAGS = flags;
r = do_invoke_ds(DS_PUBLISH, ds_name);
r = do_invoke_ds(&m, DS_PUBLISH, ds_name);
cpf_revoke(gid);
return r;
@@ -83,36 +89,37 @@ int ds_publish_mem(const char *ds_name, void *vaddr, size_t length, int flags)
return ds_publish_raw(ds_name, vaddr, length, flags | DSF_TYPE_MEM);
}
int ds_snapshot_map(const char *ds_name, int *nr_snapshot)
{
int r;
r = do_invoke_ds(DS_SNAPSHOT, ds_name);
*nr_snapshot = m.DS_NR_SNAPSHOT;
return r;
}
int ds_retrieve_label_name(char *ds_name, endpoint_t endpoint)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.DS_VAL = (u32_t) endpoint;
r = do_invoke_ds(DS_RETRIEVE_LABEL, ds_name);
r = do_invoke_ds(&m, DS_RETRIEVE_LABEL, ds_name);
return r;
}
int ds_retrieve_label_endpt(const char *ds_name, endpoint_t *endpoint)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_LABEL;
r = do_invoke_ds(DS_RETRIEVE, ds_name);
r = do_invoke_ds(&m, DS_RETRIEVE, ds_name);
*endpoint = (endpoint_t) m.DS_VAL;
return r;
}
int ds_retrieve_u32(const char *ds_name, u32_t *value)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_U32;
r = do_invoke_ds(DS_RETRIEVE, ds_name);
r = do_invoke_ds(&m, DS_RETRIEVE, ds_name);
*value = m.DS_VAL;
return r;
}
@@ -120,18 +127,20 @@ int ds_retrieve_u32(const char *ds_name, u32_t *value)
static int ds_retrieve_raw(const char *ds_name, char *vaddr, size_t *length,
int flags)
{
message m;
cp_grant_id_t gid;
int r;
/* Grant for memory range. */
gid = cpf_grant_direct(DS_PROC_NR, (vir_bytes)vaddr, *length, CPF_WRITE);
if(!GRANT_VALID(gid))
return errno;
return ENOMEM;
memset(&m, 0, sizeof(m));
m.DS_VAL = gid;
m.DS_VAL_LEN = *length;
m.DS_FLAGS = flags;
r = do_invoke_ds(DS_RETRIEVE, ds_name);
r = do_invoke_ds(&m, DS_RETRIEVE, ds_name);
*length = m.DS_VAL_LEN;
cpf_revoke(gid);
@@ -154,38 +163,56 @@ int ds_retrieve_mem(const char *ds_name, char *vaddr, size_t *length)
int ds_delete_u32(const char *ds_name)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_U32;
return do_invoke_ds(DS_DELETE, ds_name);
return do_invoke_ds(&m, DS_DELETE, ds_name);
}
int ds_delete_str(const char *ds_name)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_STR;
return do_invoke_ds(DS_DELETE, ds_name);
return do_invoke_ds(&m, DS_DELETE, ds_name);
}
int ds_delete_mem(const char *ds_name)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_MEM;
return do_invoke_ds(DS_DELETE, ds_name);
return do_invoke_ds(&m, DS_DELETE, ds_name);
}
int ds_delete_label(const char *ds_name)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_LABEL;
return do_invoke_ds(DS_DELETE, ds_name);
return do_invoke_ds(&m, DS_DELETE, ds_name);
}
int ds_subscribe(const char *regexp, int flags)
{
message m;
memset(&m, 0, sizeof(m));
m.DS_FLAGS = flags;
return do_invoke_ds(DS_SUBSCRIBE, regexp);
return do_invoke_ds(&m, DS_SUBSCRIBE, regexp);
}
int ds_check(char *ds_key, int *type, endpoint_t *owner_e)
{
message m;
int r;
r = do_invoke_ds(DS_CHECK, ds_key);
memset(&m, 0, sizeof(m));
r = do_invoke_ds(&m, DS_CHECK, ds_key);
if(type) *type = m.DS_FLAGS;
if(owner_e) *owner_e = m.DS_OWNER;
return r;

View File

@@ -1,4 +1,5 @@
#include "sysutil.h"
#include <string.h>
/*===========================================================================*
* fkey_ctl *
@@ -15,6 +16,7 @@ int *sfkeys; /* bit masks for Shift F1-F12 keys */
*/
message m;
int s;
memset(&m, 0, sizeof(m));
m.FKEY_REQUEST = request;
m.FKEY_FKEYS = (fkeys) ? *fkeys : 0;
m.FKEY_SFKEYS = (sfkeys) ? *sfkeys : 0;

75
lib/libsys/getepinfo.c Normal file
View File

@@ -0,0 +1,75 @@
#include "syslib.h"
#include <string.h>
#include <unistd.h>
#include <sys/ucred.h>
static pid_t
getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.PM_GETEPINFO_ENDPT = proc_ep;
if ((r = _taskcall(PM_PROC_NR, GETEPINFO, &m)) < 0)
return r;
if (uid != NULL)
*uid = m.PM_GETEPINFO_UID;
if (gid != NULL)
*gid = m.PM_GETEPINFO_GID;
return (pid_t) r;
}
pid_t
getnpid(endpoint_t proc_ep)
{
return getepinfo(proc_ep, NULL, NULL);
}
uid_t
getnuid(endpoint_t proc_ep)
{
uid_t uid;
int r;
if ((r = getepinfo(proc_ep, &uid, NULL)) < 0)
return (uid_t) r;
return uid;
}
gid_t
getngid(endpoint_t proc_ep)
{
gid_t gid;
int r;
if ((r = getepinfo(proc_ep, NULL, &gid)) < 0)
return (gid_t) r;
return gid;
}
int
getnucred(endpoint_t proc_ep, struct uucred *ucred)
{
uid_t uid;
gid_t gid;
int r;
if (ucred == NULL)
return EFAULT;
if ((r = getepinfo(proc_ep, &uid, &gid)) < 0)
return r;
/* Only two fields are used for now; ensure the rest is zeroed out. */
memset(ucred, 0, sizeof(struct uucred));
ucred->cr_uid = uid;
ucred->cr_gid = gid;
return r;
}

19
lib/libsys/getprocnr.c Normal file
View File

@@ -0,0 +1,19 @@
#include "syslib.h"
#include <unistd.h>
#include <string.h>
int
getprocnr(pid_t pid, endpoint_t *proc_e)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.PM_GETPROCNR_PID = pid;
if ((r = _taskcall(PM_PROC_NR, GETPROCNR, &m)) < 0)
return r;
*proc_e = m.PM_GETPROCNR_ENDPT;
return r;
}

View File

@@ -1,5 +1,6 @@
#include <lib.h>
#include "syslib.h"
#include <string.h>
#include <minix/sysinfo.h>
#include <minix/com.h>
@@ -11,9 +12,9 @@ int getsysinfo(
)
{
message m;
memset(&m, 0, sizeof(m));
m.SI_WHAT = what;
m.SI_WHERE = where;
m.SI_SIZE = size;
if (_syscall(who, COMMON_GETSYSINFO, &m) < 0) return(-1);
return(0);
return _taskcall(who, COMMON_GETSYSINFO, &m);
}

17
lib/libsys/mapdriver.c Normal file
View File

@@ -0,0 +1,17 @@
#include "syslib.h"
#include <string.h>
#include <unistd.h>
int
mapdriver(char *label, devmajor_t major)
{
message m;
memset(&m, 0, sizeof(m));
m.VFS_MAPDRIVER_LABEL = label;
m.VFS_MAPDRIVER_LABELLEN = strlen(label) + 1;
m.VFS_MAPDRIVER_MAJOR = major;
return _taskcall(VFS_PROC_NR, MAPDRIVER, &m);
}

View File

@@ -2,6 +2,7 @@
#include <assert.h>
#include <machine/archtypes.h>
#include <minix/timers.h>
#include <string.h>
#include "kernel/config.h"
#include "kernel/const.h"
@@ -23,7 +24,8 @@ int sched_inherit(endpoint_t scheduler_e,
assert(_ENDPOINT_P(parent_e) >= 0);
assert(maxprio < NR_SCHED_QUEUES);
assert(newscheduler_e);
memset(&m, 0, sizeof(m));
m.SCHEDULING_ENDPOINT = schedulee_e;
m.SCHEDULING_PARENT = parent_e;
m.SCHEDULING_MAXPRIO = (int) maxprio;
@@ -79,6 +81,7 @@ int sched_start(endpoint_t scheduler_e,
}
/* A user-space scheduler must schedule this process. */
memset(&m, 0, sizeof(m));
m.SCHEDULING_ENDPOINT = schedulee_e;
m.SCHEDULING_PARENT = parent_e;
m.SCHEDULING_MAXPRIO = (int) maxprio;

View File

@@ -1,5 +1,6 @@
#include "syslib.h"
#include <assert.h>
#include <string.h>
/*===========================================================================*
* sched_stop *
@@ -18,6 +19,7 @@ int sched_stop(endpoint_t scheduler_e, endpoint_t schedulee_e)
assert(_ENDPOINT_P(scheduler_e) >= 0);
assert(_ENDPOINT_P(schedulee_e) >= 0);
memset(&m, 0, sizeof(m));
m.SCHEDULING_ENDPOINT = schedulee_e;
if ((rv = _taskcall(scheduler_e, SCHEDULING_STOP, &m))) {
return rv;

View File

@@ -9,7 +9,7 @@
/* Self variables. */
#define SEF_SELF_NAME_MAXLEN 20
char sef_self_name[SEF_SELF_NAME_MAXLEN];
endpoint_t sef_self_endpoint;
endpoint_t sef_self_endpoint = NONE;
int sef_self_priv_flags;
int sef_self_first_receive_done;
int sef_self_receiving;
@@ -68,8 +68,8 @@ void sef_startup()
if((sef_self_priv_flags & ROOT_SYS_PROC) && sef_self_endpoint != RS_PROC_NR) {
r = vm_update(RS_PROC_NR, sef_self_endpoint);
if(r != OK) {
panic("unable to update RS from instance %d to %d",
RS_PROC_NR, sef_self_endpoint);
panic("unable to update RS from instance %d to %d: %d",
RS_PROC_NR, sef_self_endpoint, r);
}
old_endpoint = sef_self_endpoint;
sef_self_endpoint = RS_PROC_NR;
@@ -190,6 +190,19 @@ int sef_receive_status(endpoint_t src, message *m_ptr, int *status_ptr)
return r;
}
/*===========================================================================*
* sef_self *
*===========================================================================*/
endpoint_t sef_self(void)
{
/* Return the process's own endpoint number. */
if (sef_self_endpoint == NONE)
panic("sef_self called before initialization");
return sef_self_endpoint;
}
/*===========================================================================*
* sef_cancel *
*===========================================================================*/

View File

@@ -2,6 +2,7 @@
#include <assert.h>
#include <unistd.h>
#include <minix/sysutil.h>
#include <string.h>
/* SEF Init callbacks. */
static struct sef_cbs {
@@ -62,6 +63,7 @@ static int process_init(int type, sef_init_info_t *info)
break;
}
memset(&m, 0, sizeof(m));
m.m_source = sef_self_endpoint;
m.m_type = RS_INIT;
m.RS_INIT_RESULT = result;

14
lib/libsys/srv_fork.c Normal file
View File

@@ -0,0 +1,14 @@
#include "syslib.h"
#include <string.h>
pid_t
srv_fork(uid_t reuid, gid_t regid)
{
message m;
memset(&m, 0, sizeof(m));
m.m1_i1 = (int) reuid;
m.m1_i2 = (int) regid;
return _taskcall(PM_PROC_NR, SRV_FORK, &m);
}

14
lib/libsys/srv_kill.c Normal file
View File

@@ -0,0 +1,14 @@
#include "syslib.h"
#include <string.h>
int
srv_kill(pid_t pid, int sig)
{
message m;
memset(&m, 0, sizeof(m));
m.m1_i1 = pid;
m.m1_i2 = sig;
return _taskcall(PM_PROC_NR, SRV_KILL, &m);
}

View File

@@ -6,13 +6,6 @@
#include <lib.h>
#include <minix/syslib.h>
int _sendcall(endpoint_t who, int type, message *msgptr)
{
msgptr->m_type = type;
return send(who, msgptr);
}
int _taskcall(who, syscallnr, msgptr)
endpoint_t who;
int syscallnr;

View File

@@ -1,6 +1,7 @@
#include "syslib.h"
#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
@@ -10,6 +11,7 @@ int vm_brk(endpoint_t ep, char *addr)
{
message m;
memset(&m, 0, sizeof(m));
m.VMB_ENDPOINT = ep;
m.VMB_ADDR = (void *) addr;

View File

@@ -1,6 +1,6 @@
#include "syslib.h"
#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
@@ -11,6 +11,7 @@ int vm_exit(endpoint_t ep)
message m;
int result;
memset(&m, 0, sizeof(m));
m.VME_ENDPOINT = ep;
result = _taskcall(VM_PROC_NR, VM_EXIT, &m);
@@ -26,6 +27,7 @@ int vm_willexit(endpoint_t ep)
message m;
int result;
memset(&m, 0, sizeof(m));
m.VMWE_ENDPOINT = ep;
result = _taskcall(VM_PROC_NR, VM_WILLEXIT, &m);

View File

@@ -1,6 +1,7 @@
#include "syslib.h"
#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
@@ -11,6 +12,7 @@ int vm_fork(endpoint_t ep, int slot, endpoint_t *childep)
message m;
int result;
memset(&m, 0, sizeof(m));
m.VMF_ENDPOINT = ep;
m.VMF_SLOTNO = slot;

View File

@@ -1,6 +1,7 @@
#include "syslib.h"
#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
@@ -10,6 +11,7 @@ int vm_info_stats(struct vm_stats_info *vsi)
{
message m;
memset(&m, 0, sizeof(m));
m.VMI_WHAT = VMIW_STATS;
m.VMI_PTR = (void *) vsi;
@@ -23,6 +25,7 @@ int vm_info_usage(endpoint_t who, struct vm_usage_info *vui)
{
message m;
memset(&m, 0, sizeof(m));
m.VMI_WHAT = VMIW_USAGE;
m.VMI_EP = who;
m.VMI_PTR = (void *) vui;
@@ -39,6 +42,7 @@ int vm_info_region(endpoint_t who, struct vm_region_info *vri,
message m;
int result;
memset(&m, 0, sizeof(m));
m.VMI_WHAT = VMIW_REGION;
m.VMI_EP = who;
m.VMI_COUNT = count;

View File

@@ -1,35 +1,36 @@
#define _SYSTEM 1
#include <lib.h>
#include "syslib.h"
#include <sys/mman.h>
#include <minix/syslib.h>
#include <minix/vm.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
void *vm_map_phys(endpoint_t who, void *phaddr, size_t len)
void *
vm_map_phys(endpoint_t who, void *phaddr, size_t len)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.VMMP_EP = who;
m.VMMP_PHADDR = phaddr;
m.VMMP_LEN = len;
r = _taskcall(VM_PROC_NR, VM_MAP_PHYS, &m);
if(r != OK) return MAP_FAILED;
if (r != OK) return MAP_FAILED;
return (void *) m.VMMP_VADDR_REPLY;
}
int vm_unmap_phys(endpoint_t who, void *vaddr, size_t len)
int
vm_unmap_phys(endpoint_t who, void *vaddr, size_t len)
{
message m;
memset(&m, 0, sizeof(m));
m.VMUP_EP = who;
m.VMUP_VADDR = vaddr;
return _taskcall(VM_PROC_NR, VM_UNMAP_PHYS, &m);
}

15
lib/libsys/vm_memctl.c Normal file
View File

@@ -0,0 +1,15 @@
#include "syslib.h"
#include <unistd.h>
#include <string.h>
int
vm_memctl(endpoint_t ep, int req)
{
message m;
memset(&m, 0, sizeof(m));
m.VM_RS_CTL_ENDPT = ep;
m.VM_RS_CTL_REQ = req;
return _taskcall(VM_PROC_NR, VM_RS_MEMCTL, &m);
}

View File

@@ -1,6 +1,7 @@
#include "syslib.h"
#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
@@ -11,6 +12,7 @@ int vm_notify_sig(endpoint_t ep, endpoint_t ipc_ep)
message m;
int result;
memset(&m, 0, sizeof(m));
m.VM_NOTIFY_SIG_ENDPOINT = ep;
m.VM_NOTIFY_SIG_IPC = ipc_ep;

View File

@@ -0,0 +1,37 @@
#include "syslib.h"
#include <unistd.h>
#include <string.h>
/*
* Return a negative error code if the query itself or the processing of the
* query resulted in an error.
* Return 1 if there are more processes waiting to be queried.
* Return 0 if there are no more processes.
* Note that for the return value of 0 and 1, the 'endpt' is set accordingly.
*/
int
vm_query_exit(int *endpt)
{
message m;
int r;
memset(&m, 0, sizeof(m));
r = _taskcall(VM_PROC_NR, VM_QUERY_EXIT, &m);
if (r != OK)
return r;
if (endpt == NULL)
return EFAULT;
*endpt = m.VM_QUERY_RET_PT;
return (m.VM_QUERY_IS_MORE ? 1 : 0);
}
int
vm_watch_exit(endpoint_t ep)
{
message m;
memset(&m, 0, sizeof(m));
m.VM_WE_EP = ep;
return _taskcall(VM_PROC_NR, VM_WATCH_EXIT, &m);
}

17
lib/libsys/vm_set_priv.c Normal file
View File

@@ -0,0 +1,17 @@
#include "syslib.h"
#include <unistd.h>
#include <string.h>
int
vm_set_priv(endpoint_t ep, void *buf, int sys_proc)
{
message m;
memset(&m, 0, sizeof(m));
m.VM_RS_NR = ep;
m.VM_RS_BUF = (long) buf;
m.VM_RS_SYS = sys_proc;
return _taskcall(VM_PROC_NR, VM_RS_SET_PRIV, &m);
}

View File

@@ -1,6 +1,7 @@
#include "syslib.h"
#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
@@ -11,6 +12,7 @@ int vm_umap(int seg, vir_bytes offset, vir_bytes len, phys_bytes *addr)
message m;
int result;
memset(&m, 0, sizeof(m));
m.VMU_SEG = seg;
m.VMU_OFFSET = (char *) offset;
m.VMU_LENGTH = (char *) len;

16
lib/libsys/vm_update.c Normal file
View File

@@ -0,0 +1,16 @@
#include "syslib.h"
#include <unistd.h>
#include <string.h>
int
vm_update(endpoint_t src_e, endpoint_t dst_e)
{
message m;
memset(&m, 0, sizeof(m));
m.VM_RS_SRC_ENDPT = src_e;
m.VM_RS_DST_ENDPT = dst_e;
return _taskcall(VM_PROC_NR, VM_RS_UPDATE, &m);
}