From: David van Moolenbroek Date: Sun, 3 Nov 2013 21:33:44 +0000 (+0100) Subject: libsys: various updates X-Git-Tag: v3.3.0~522 X-Git-Url: http://zhaoyanbai.com/repos/%22../static/icons/zlib_tech.html?a=commitdiff_plain;h=80bd109cd3fe770e7cbabc34ee1b44dcc0c8b239;p=minix.git 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 --- diff --git a/drivers/uds/ioc_uds.c b/drivers/uds/ioc_uds.c index 066069696..762bfd6f6 100644 --- a/drivers/uds/ioc_uds.c +++ b/drivers/uds/ioc_uds.c @@ -166,9 +166,9 @@ do_connect(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant) sizeof(struct sockaddr_un))) != OK) return rc; - if (checkperms(uds_fd_table[minor].owner, addr.sun_path, - UNIX_PATH_MAX) != OK) - return -errno; + if ((rc = checkperms(uds_fd_table[minor].owner, addr.sun_path, + UNIX_PATH_MAX)) != OK) + return rc; /* * Look for a socket of the same type that is listening on the @@ -355,9 +355,9 @@ do_bind(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant) if (addr.sun_path[0] == '\0') return ENOENT; - if (checkperms(uds_fd_table[minor].owner, addr.sun_path, - UNIX_PATH_MAX) != OK) - return -errno; + if ((rc = checkperms(uds_fd_table[minor].owner, addr.sun_path, + UNIX_PATH_MAX)) != OK) + return rc; /* Make sure the address isn't already in use by another socket. */ for (i = 0; i < NR_FDS; i++) { @@ -523,7 +523,7 @@ do_getsockopt_peercred(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant) /* Obtain the peer's credentials and copy them out. */ if ((rc = getnucred(uds_fd_table[peer_minor].owner, &cred)) < 0) - return -errno; + return rc; return sys_safecopyto(endpt, grant, 0, (vir_bytes) &cred, sizeof(struct uucred)); @@ -611,9 +611,9 @@ do_sendto(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant) if (addr.sun_family != AF_UNIX || addr.sun_path[0] == '\0') return EINVAL; - if (checkperms(uds_fd_table[minor].owner, addr.sun_path, - UNIX_PATH_MAX) != OK) - return -errno; + if ((rc = checkperms(uds_fd_table[minor].owner, addr.sun_path, + UNIX_PATH_MAX)) != OK) + return rc; memcpy(&uds_fd_table[minor].target, &addr, sizeof(struct sockaddr_un)); @@ -645,7 +645,7 @@ send_fds(devminor_t minor, struct msg_control *msg_ctrl, /* Obtain this socket's credentials. */ if ((rc = getnucred(from_ep, &data->cred)) < 0) - return -errno; + return rc; dprintf(("UDS: minor=%d cred={%d,%d,%d}\n", minor, data->cred.pid, data->cred.uid, data->cred.gid)); @@ -677,8 +677,6 @@ send_fds(devminor_t minor, struct msg_control *msg_ctrl, for (i = data->nfiledes; i < totalfds; i++) { if ((rc = copyfd(from_ep, data->fds[i], COPYFD_FROM)) < 0) { - rc = -errno; - printf("UDS: copyfd(COPYFD_FROM) failed: %d\n", rc); /* Revert the successful copyfd() calls made so far. */ @@ -747,8 +745,6 @@ recv_fds(devminor_t minor, struct ancillary *data, /* Copy to the target endpoint. */ for (i = 0; i < data->nfiledes; i++) { if ((rc = copyfd(to_ep, data->fds[i], COPYFD_TO)) < 0) { - rc = -errno; - printf("UDS: copyfd(COPYFD_TO) failed: %d\n", rc); /* Revert the successful copyfd() calls made so far. */ diff --git a/drivers/vnd/vnd.c b/drivers/vnd/vnd.c index 7289bc184..bf55d18cf 100644 --- a/drivers/vnd/vnd.c +++ b/drivers/vnd/vnd.c @@ -384,9 +384,10 @@ vnd_ioctl(devminor_t UNUSED(minor), unsigned long request, endpoint_t endpt, * making the IOCTL call. The result is either a newly * allocated file descriptor or an error. */ - if ((state.fd = copyfd(user_endpt, vnd.vnd_fildes, - COPYFD_FROM)) == -1) - return -errno; + if ((r = copyfd(user_endpt, vnd.vnd_fildes, COPYFD_FROM)) < 0) + return r; + + state.fd = r; /* The target file must be regular. */ if (fstat(state.fd, &st) == -1) { diff --git a/include/lib.h b/include/lib.h index a3018e841..f5d15cf07 100644 --- a/include/lib.h +++ b/include/lib.h @@ -36,16 +36,6 @@ void _loadname(const char *_name, message *_msgptr); int _len(const char *_s); void _begsig(int _dummy); -int getprocnr(void); -int getnprocnr(pid_t pid); -int getpprocnr(void); -int _pm_findproc(char *proc_name, int *proc_nr); -int mapdriver(char *label, int major); -pid_t getnpid(endpoint_t proc_ep); -uid_t getnuid(endpoint_t proc_ep); -gid_t getngid(endpoint_t proc_ep); -int checkperms(endpoint_t endpt, char *path, size_t size); -int copyfd(endpoint_t endpt, int fd, int what); ssize_t pread64(int fd, void *buf, size_t count, u64_t where); ssize_t pwrite64(int fd, const void *buf, size_t count, u64_t where); diff --git a/include/minix/callnr.h b/include/minix/callnr.h index f99aa3356..9914aafa8 100644 --- a/include/minix/callnr.h +++ b/include/minix/callnr.h @@ -91,7 +91,6 @@ #define EXEC_RESTART 102 /* to PM: final part of exec for RS */ #define GETPROCNR 104 /* to PM */ #define ISSETUGID 106 /* to PM: ask if process is tainted */ -#define GETEPINFO_O 107 /* to PM: get pid/uid/gid of an endpoint */ #define UTIMENS 108 /* to FS: [f]utimens(); also [fl]utimes */ #define FCNTL 109 /* to VFS */ #define TRUNCATE 110 /* to VFS */ diff --git a/include/minix/com.h b/include/minix/com.h index 72793dd63..1638dc568 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -895,6 +895,20 @@ # define COPYFD_TO 1 /* copy file descriptor to remote process */ # define COPYFD_CLOSE 2 /* close file descriptor in remote process */ +/* Field names for the getprocnr(2) call. */ +#define PM_GETPROCNR_PID m1_i1 +#define PM_GETPROCNR_ENDPT m1_i1 + +/* Field names for the getepinfo(2) call. */ +#define PM_GETEPINFO_ENDPT m1_i1 +#define PM_GETEPINFO_UID m1_i1 +#define PM_GETEPINFO_GID m1_i2 + +/* Field names for the mapdriver(2) call. */ +#define VFS_MAPDRIVER_MAJOR m1_i1 +#define VFS_MAPDRIVER_LABELLEN m1_i2 +#define VFS_MAPDRIVER_LABEL m1_p1 + /* Field names for GETRUSAGE related calls */ #define RU_ENDPT m1_i1 /* indicates a process for sys_getrusage */ #define RU_WHO m1_i1 /* who argument in getrusage call */ diff --git a/include/minix/ds.h b/include/minix/ds.h index b9d449ee2..3a8c6db47 100644 --- a/include/minix/ds.h +++ b/include/minix/ds.h @@ -23,9 +23,6 @@ #define DSF_OVERWRITE 0x01000 /* overwrite if entry exists */ #define DSF_INITIAL 0x02000 /* check subscriptions immediately */ -#define DSMF_COPY_MAPPED 0x20000 /* copy mapped memory range */ -#define DSMF_COPY_SNAPSHOT 0x40000 /* copy snapshot */ - /* DS constants. */ #define DS_MAX_KEYLEN 80 /* Max length of a key, including '\0'. */ diff --git a/include/minix/sef.h b/include/minix/sef.h index d36d67bea..1a6809101 100644 --- a/include/minix/sef.h +++ b/include/minix/sef.h @@ -8,6 +8,7 @@ /* SEF entry points for system processes. */ void sef_startup(void); int sef_receive_status(endpoint_t src, message *m_ptr, int *status_ptr); +endpoint_t sef_self(void); void sef_cancel(void); void sef_exit(int status); #define sef_receive(src, m_ptr) sef_receive_status(src, m_ptr, NULL) diff --git a/include/minix/syslib.h b/include/minix/syslib.h index 17b5812a1..37c2911a9 100644 --- a/include/minix/syslib.h +++ b/include/minix/syslib.h @@ -26,7 +26,6 @@ struct rusage; *==========================================================================*/ int _taskcall(endpoint_t who, int syscallnr, message *msgptr); int _kernel_call(int syscallnr, message *msgptr); -int _sendcall(endpoint_t who, int type, message *msgptr); int sys_abort(int how); int sys_enable_iop(endpoint_t proc_ep); @@ -261,5 +260,16 @@ int sys_setmcontext(endpoint_t proc, mcontext_t *mcp); /* input */ int tty_input_inject(int type, int code, int val); +/* Miscellaneous calls from servers and drivers. */ +pid_t srv_fork(uid_t reuid, gid_t regid); +int srv_kill(pid_t pid, int sig); +int getprocnr(pid_t pid, endpoint_t *proc_ep); +int mapdriver(char *label, devmajor_t major); +pid_t getnpid(endpoint_t proc_ep); +uid_t getnuid(endpoint_t proc_ep); +gid_t getngid(endpoint_t proc_ep); +int checkperms(endpoint_t endpt, char *path, size_t size); +int copyfd(endpoint_t endpt, int fd, int what); + #endif /* _SYSLIB_H */ diff --git a/kernel/extract-mfield.sh b/kernel/extract-mfield.sh index 4a1664768..a84ba8f56 100644 --- a/kernel/extract-mfield.sh +++ b/kernel/extract-mfield.sh @@ -5,7 +5,7 @@ set -e find_files_and_lines() ( find ../lib/libc/sys-minix ../lib/libsys -name '*.c' | \ - xargs egrep -n '((_sendcall|_syscall|_taskcall)\([^,][^,]*,[ ]*|_kernel_call\()[A-Z_][A-Z0-9_]*,[ ]*&m\)' | \ + xargs egrep -n '((_syscall|_taskcall)\([^,][^,]*,[ ]*|_kernel_call\()[A-Z_][A-Z0-9_]*,[ ]*&m\)' | \ cut -d: -f1,2 ) diff --git a/lib/libblockdriver/driver.c b/lib/libblockdriver/driver.c index 780abe0bd..b45ce39ba 100644 --- a/lib/libblockdriver/driver.c +++ b/lib/libblockdriver/driver.c @@ -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); diff --git a/lib/libchardriver/chardriver.c b/lib/libchardriver/chardriver.c index 21f065df1..427d98e09 100644 --- a/lib/libchardriver/chardriver.c +++ b/lib/libchardriver/chardriver.c @@ -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); diff --git a/lib/libi2cdriver/i2cdriver.c b/lib/libi2cdriver/i2cdriver.c index 9d5a6df20..382c72ecf 100644 --- a/lib/libi2cdriver/i2cdriver.c +++ b/lib/libi2cdriver/i2cdriver.c @@ -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); } diff --git a/lib/libinputdriver/inputdriver.c b/lib/libinputdriver/inputdriver.c index eacd0921f..5a8b8033a 100644 --- a/lib/libinputdriver/inputdriver.c +++ b/lib/libinputdriver/inputdriver.c @@ -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); diff --git a/lib/libminlib/Makefile b/lib/libminlib/Makefile index cc288f157..3199a04ef 100644 --- a/lib/libminlib/Makefile +++ b/lib/libminlib/Makefile @@ -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 diff --git a/lib/libminlib/getngid.c b/lib/libminlib/getngid.c deleted file mode 100644 index 60b9ac094..000000000 --- a/lib/libminlib/getngid.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -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 */ -} diff --git a/lib/libminlib/getnpid.c b/lib/libminlib/getnpid.c deleted file mode 100644 index 3f88cc196..000000000 --- a/lib/libminlib/getnpid.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -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); -} diff --git a/lib/libminlib/getnprocnr.c b/lib/libminlib/getnprocnr.c deleted file mode 100644 index 85521cb27..000000000 --- a/lib/libminlib/getnprocnr.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - - -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 */ -} - diff --git a/lib/libminlib/getnucred.c b/lib/libminlib/getnucred.c deleted file mode 100644 index f95a1d564..000000000 --- a/lib/libminlib/getnucred.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include - -#include - -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; -} diff --git a/lib/libminlib/getnuid.c b/lib/libminlib/getnuid.c deleted file mode 100644 index f02d1dbd9..000000000 --- a/lib/libminlib/getnuid.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -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 */ -} diff --git a/lib/libminlib/getprocnr.c b/lib/libminlib/getprocnr.c deleted file mode 100644 index 2f0d1e6fc..000000000 --- a/lib/libminlib/getprocnr.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - - -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 */ -} - diff --git a/lib/libminlib/mapdriver.c b/lib/libminlib/mapdriver.c deleted file mode 100644 index d91be239b..000000000 --- a/lib/libminlib/mapdriver.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include - - -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); -} - diff --git a/lib/libminlib/vm_memctl.c b/lib/libminlib/vm_memctl.c deleted file mode 100644 index 92e2b0c80..000000000 --- a/lib/libminlib/vm_memctl.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -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); -} diff --git a/lib/libminlib/vm_query_exit.c b/lib/libminlib/vm_query_exit.c deleted file mode 100644 index df109dde2..000000000 --- a/lib/libminlib/vm_query_exit.c +++ /dev/null @@ -1,33 +0,0 @@ -#define _SYSTEM 1 -#include -#include -#include - -/* 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); -} diff --git a/lib/libminlib/vm_set_priv.c b/lib/libminlib/vm_set_priv.c deleted file mode 100644 index f7d2ed026..000000000 --- a/lib/libminlib/vm_set_priv.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -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); -} - diff --git a/lib/libminlib/vm_update.c b/lib/libminlib/vm_update.c deleted file mode 100644 index e3e731325..000000000 --- a/lib/libminlib/vm_update.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -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); -} diff --git a/lib/libnetdriver/netdriver.c b/lib/libnetdriver/netdriver.c index a2176e451..2b6d0271b 100644 --- a/lib/libnetdriver/netdriver.c +++ b/lib/libnetdriver/netdriver.c @@ -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); } diff --git a/lib/libpuffs/glo.h b/lib/libpuffs/glo.h index 231817bd0..2ad31d177 100644 --- a/lib/libpuffs/glo.h +++ b/lib/libpuffs/glo.h @@ -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 diff --git a/lib/libpuffs/puffs.c b/lib/libpuffs/puffs.c index 7bda9e1ca..be991cb52 100644 --- a/lib/libpuffs/puffs.c +++ b/lib/libpuffs/puffs.c @@ -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; } diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index 230aae7c5..73678e198 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -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" diff --git a/lib/libminlib/checkperms.c b/lib/libsys/checkperms.c similarity index 73% rename from lib/libminlib/checkperms.c rename to lib/libsys/checkperms.c index 154f48734..cf0a4cb27 100644 --- a/lib/libminlib/checkperms.c +++ b/lib/libsys/checkperms.c @@ -1,4 +1,5 @@ -#include +#include "syslib.h" + #include #include #include @@ -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; } diff --git a/lib/libminlib/copyfd.c b/lib/libsys/copyfd.c similarity index 74% rename from lib/libminlib/copyfd.c rename to lib/libsys/copyfd.c index 7f5ed71c5..70cb9ca03 100644 --- a/lib/libminlib/copyfd.c +++ b/lib/libsys/copyfd.c @@ -1,4 +1,5 @@ -#include +#include "syslib.h" + #include 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); } diff --git a/lib/libsys/ds.c b/lib/libsys/ds.c index 371400b18..38d914e88 100644 --- a/lib/libsys/ds.c +++ b/lib/libsys/ds.c @@ -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; diff --git a/lib/libsys/fkey_ctl.c b/lib/libsys/fkey_ctl.c index a3c28a41b..94ec9478e 100644 --- a/lib/libsys/fkey_ctl.c +++ b/lib/libsys/fkey_ctl.c @@ -1,4 +1,5 @@ #include "sysutil.h" +#include /*===========================================================================* * 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; diff --git a/lib/libsys/getepinfo.c b/lib/libsys/getepinfo.c new file mode 100644 index 000000000..fda0a1b46 --- /dev/null +++ b/lib/libsys/getepinfo.c @@ -0,0 +1,75 @@ +#include "syslib.h" +#include +#include + +#include + +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; +} diff --git a/lib/libsys/getprocnr.c b/lib/libsys/getprocnr.c new file mode 100644 index 000000000..92f1badd4 --- /dev/null +++ b/lib/libsys/getprocnr.c @@ -0,0 +1,19 @@ +#include "syslib.h" +#include +#include + +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; +} diff --git a/lib/libsys/getsysinfo.c b/lib/libsys/getsysinfo.c index bb841b61c..27d0ff3e8 100644 --- a/lib/libsys/getsysinfo.c +++ b/lib/libsys/getsysinfo.c @@ -1,5 +1,6 @@ -#include +#include "syslib.h" +#include #include #include @@ -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); } diff --git a/lib/libsys/mapdriver.c b/lib/libsys/mapdriver.c new file mode 100644 index 000000000..f7a219ba3 --- /dev/null +++ b/lib/libsys/mapdriver.c @@ -0,0 +1,17 @@ +#include "syslib.h" + +#include +#include + +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); +} diff --git a/lib/libsys/sched_start.c b/lib/libsys/sched_start.c index ee72d38c5..7017047b3 100644 --- a/lib/libsys/sched_start.c +++ b/lib/libsys/sched_start.c @@ -2,6 +2,7 @@ #include #include #include +#include #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; diff --git a/lib/libsys/sched_stop.c b/lib/libsys/sched_stop.c index e53a2d728..f4b3d5f76 100644 --- a/lib/libsys/sched_stop.c +++ b/lib/libsys/sched_stop.c @@ -1,5 +1,6 @@ #include "syslib.h" #include +#include /*===========================================================================* * 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; diff --git a/lib/libsys/sef.c b/lib/libsys/sef.c index e964fa70b..24ffdf522 100644 --- a/lib/libsys/sef.c +++ b/lib/libsys/sef.c @@ -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 * *===========================================================================*/ diff --git a/lib/libsys/sef_init.c b/lib/libsys/sef_init.c index 049009ccd..ba67d05cd 100644 --- a/lib/libsys/sef_init.c +++ b/lib/libsys/sef_init.c @@ -2,6 +2,7 @@ #include #include #include +#include /* 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; diff --git a/lib/libsys/srv_fork.c b/lib/libsys/srv_fork.c new file mode 100644 index 000000000..67c40cecb --- /dev/null +++ b/lib/libsys/srv_fork.c @@ -0,0 +1,14 @@ +#include "syslib.h" + +#include + +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); +} diff --git a/lib/libsys/srv_kill.c b/lib/libsys/srv_kill.c new file mode 100644 index 000000000..540f87cc3 --- /dev/null +++ b/lib/libsys/srv_kill.c @@ -0,0 +1,14 @@ +#include "syslib.h" + +#include + +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); +} diff --git a/lib/libsys/taskcall.c b/lib/libsys/taskcall.c index eafa99cd1..b547471b7 100644 --- a/lib/libsys/taskcall.c +++ b/lib/libsys/taskcall.c @@ -6,13 +6,6 @@ #include #include -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; diff --git a/lib/libsys/vm_brk.c b/lib/libsys/vm_brk.c index 88fb80941..67808fe07 100644 --- a/lib/libsys/vm_brk.c +++ b/lib/libsys/vm_brk.c @@ -1,6 +1,7 @@ #include "syslib.h" +#include #include /*===========================================================================* @@ -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; diff --git a/lib/libsys/vm_exit.c b/lib/libsys/vm_exit.c index 35a0e4065..e133ac89d 100644 --- a/lib/libsys/vm_exit.c +++ b/lib/libsys/vm_exit.c @@ -1,6 +1,6 @@ #include "syslib.h" - +#include #include /*===========================================================================* @@ -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); diff --git a/lib/libsys/vm_fork.c b/lib/libsys/vm_fork.c index 5931f756d..52c3f306e 100644 --- a/lib/libsys/vm_fork.c +++ b/lib/libsys/vm_fork.c @@ -1,6 +1,7 @@ #include "syslib.h" +#include #include /*===========================================================================* @@ -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; diff --git a/lib/libsys/vm_info.c b/lib/libsys/vm_info.c index 0ff47c978..591d3b267 100644 --- a/lib/libsys/vm_info.c +++ b/lib/libsys/vm_info.c @@ -1,6 +1,7 @@ #include "syslib.h" +#include #include /*===========================================================================* @@ -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; diff --git a/lib/libsys/vm_map_phys.c b/lib/libsys/vm_map_phys.c index e98374387..135608197 100644 --- a/lib/libsys/vm_map_phys.c +++ b/lib/libsys/vm_map_phys.c @@ -1,35 +1,36 @@ -#define _SYSTEM 1 -#include +#include "syslib.h" + #include -#include #include #include #include -#include -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); } - diff --git a/lib/libsys/vm_memctl.c b/lib/libsys/vm_memctl.c new file mode 100644 index 000000000..1a4bea877 --- /dev/null +++ b/lib/libsys/vm_memctl.c @@ -0,0 +1,15 @@ +#include "syslib.h" +#include +#include + +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); +} diff --git a/lib/libsys/vm_notify_sig.c b/lib/libsys/vm_notify_sig.c index 386bd9d1c..cf631fa69 100644 --- a/lib/libsys/vm_notify_sig.c +++ b/lib/libsys/vm_notify_sig.c @@ -1,6 +1,7 @@ #include "syslib.h" +#include #include /*===========================================================================* @@ -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; diff --git a/lib/libsys/vm_query_exit.c b/lib/libsys/vm_query_exit.c new file mode 100644 index 000000000..1e6d892c7 --- /dev/null +++ b/lib/libsys/vm_query_exit.c @@ -0,0 +1,37 @@ +#include "syslib.h" +#include +#include + +/* + * 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); +} diff --git a/lib/libsys/vm_set_priv.c b/lib/libsys/vm_set_priv.c new file mode 100644 index 000000000..ae105e407 --- /dev/null +++ b/lib/libsys/vm_set_priv.c @@ -0,0 +1,17 @@ +#include "syslib.h" + +#include +#include + +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); +} diff --git a/lib/libsys/vm_umap.c b/lib/libsys/vm_umap.c index a1967d242..b6a45cdfe 100644 --- a/lib/libsys/vm_umap.c +++ b/lib/libsys/vm_umap.c @@ -1,6 +1,7 @@ #include "syslib.h" +#include #include /*===========================================================================* @@ -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; diff --git a/lib/libsys/vm_update.c b/lib/libsys/vm_update.c new file mode 100644 index 000000000..77027294d --- /dev/null +++ b/lib/libsys/vm_update.c @@ -0,0 +1,16 @@ +#include "syslib.h" + +#include +#include + +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); +} diff --git a/servers/ds/store.h b/servers/ds/store.h index 43e6ab12e..6868d38e3 100644 --- a/servers/ds/store.h +++ b/servers/ds/store.h @@ -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; }; diff --git a/servers/ext2/glo.h b/servers/ext2/glo.h index 2f20f8c8d..b805cc00e 100644 --- a/servers/ext2/glo.h +++ b/servers/ext2/glo.h @@ -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 diff --git a/servers/ext2/main.c b/servers/ext2/main.c index fc8b26503..7b0c715ac 100644 --- a/servers/ext2/main.c +++ b/servers/ext2/main.c @@ -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()); } diff --git a/servers/ipc/inc.h b/servers/ipc/inc.h index 24b879600..4e46aebd7 100644 --- a/servers/ipc/inc.h +++ b/servers/ipc/inc.h @@ -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; - diff --git a/servers/ipc/main.c b/servers/ipc/main.c index de371e598..d9381701b 100644 --- a/servers/ipc/main.c +++ b/servers/ipc/main.c @@ -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); } diff --git a/servers/ipc/sem.c b/servers/ipc/sem.c index e59cfaf5b..32090ecde 100644 --- a/servers/ipc/sem.c +++ b/servers/ipc/sem.c @@ -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; diff --git a/servers/ipc/shm.c b/servers/ipc/shm.c index caa99aa2f..3a5e576e5 100644 --- a/servers/ipc/shm.c +++ b/servers/ipc/shm.c @@ -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; diff --git a/servers/is/main.c b/servers/is/main.c index d8fc19bf4..59e3c5e40 100644 --- a/servers/is/main.c +++ b/servers/is/main.c @@ -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); diff --git a/servers/iso9660fs/glo.h b/servers/iso9660fs/glo.h index 9ddf8b2df..46b0cd905 100644 --- a/servers/iso9660fs/glo.h +++ b/servers/iso9660fs/glo.h @@ -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; diff --git a/servers/iso9660fs/main.c b/servers/iso9660fs/main.c index 8fae36a66..5e85dff56 100644 --- a/servers/iso9660fs/main.c +++ b/servers/iso9660fs/main.c @@ -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()); } diff --git a/servers/iso9660fs/protect.c b/servers/iso9660fs/protect.c index 8cfe9adfd..632dea793 100644 --- a/servers/iso9660fs/protect.c +++ b/servers/iso9660fs/protect.c @@ -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); } diff --git a/servers/mfs/glo.h b/servers/mfs/glo.h index 09d30d986..f6a7e99f1 100644 --- a/servers/mfs/glo.h +++ b/servers/mfs/glo.h @@ -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. diff --git a/servers/mfs/main.c b/servers/mfs/main.c index 039953fb9..0d0e0d74c 100644 --- a/servers/mfs/main.c +++ b/servers/mfs/main.c @@ -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); } diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 725e877ad..00f937472 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -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; - - 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); - } - } + ep = m_in.PM_GETEPINFO_ENDPT; + if (pm_isokendpt(ep, &slot) != OK) + return(ESRCH); - /* 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); } /*===========================================================================* diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 6762ccc65..68a09f6e4 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -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); diff --git a/servers/pm/table.c b/servers/pm/table.c index 2e39901e0..b84c1ff44 100644 --- a/servers/pm/table.c +++ b/servers/pm/table.c @@ -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 */ diff --git a/servers/rs/main.c b/servers/rs/main.c index 46fa104aa..5b1ddcc4c 100644 --- a/servers/rs/main.c +++ b/servers/rs/main.c @@ -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; diff --git a/servers/rs/manager.c b/servers/rs/manager.c index 43918103e..dc68d05dd 100644 --- a/servers/rs/manager.c +++ b/servers/rs/manager.c @@ -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); diff --git a/servers/rs/proto.h b/servers/rs/proto.h index 5b5b7d031..b8c47c097 100644 --- a/servers/rs/proto.h +++ b/servers/rs/proto.h @@ -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) diff --git a/servers/vfs/dmap.c b/servers/vfs/dmap.c index fd303e2c9..02f4c22ac 100644 --- a/servers/vfs/dmap.c +++ b/servers/vfs/dmap.c @@ -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); diff --git a/servers/vfs/param.h b/servers/vfs/param.h index a606c4df2..1a60c0fa2 100644 --- a/servers/vfs/param.h +++ b/servers/vfs/param.h @@ -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 diff --git a/test/ds/README b/test/ds/README index 5bb558071..208cec718 100644 --- a/test/ds/README +++ b/test/ds/README @@ -10,8 +10,8 @@ How the test works ================== `dstest` tests the new DS API (excluding ds_subscribe() and ds_check()). -test_u32, test_str, test_mem, test_label, and test_map test U32, STR, MEM, LABEL -and MAP type respectively. +test_u32, test_str, test_mem, and test_label test U32, STR, MEM, and LABEL +type respectively. Invalid invokation is tested as well. Erroneous conditions are tested only once. For example, publishing an entry with same label name, but without diff --git a/test/ds/dstest.c b/test/ds/dstest.c index f903b34a1..afd97624c 100644 --- a/test/ds/dstest.c +++ b/test/ds/dstest.c @@ -3,7 +3,6 @@ char *key_u32 = "test_u32"; char *key_str = "test_str"; char *key_mem = "test_mem"; -char *key_map = "test_map"; char *key_label = "test_label"; /*===========================================================================* @@ -128,10 +127,10 @@ void test_label(void) endpoint_t endpoint; /* Retrieve own label and endpoint. */ - r = ds_retrieve_label_name(label, getprocnr()); + r = ds_retrieve_label_name(label, sef_self()); assert(r == OK); r = ds_retrieve_label_endpt(label, &endpoint); - assert(r == OK && endpoint == getprocnr()); + assert(r == OK && endpoint == sef_self()); /* Publish and delete. */ r = ds_publish_label(label, endpoint, 0); @@ -142,65 +141,6 @@ void test_label(void) printf("DSTEST: LABEL test successful!\n"); } -/*===========================================================================* - * test_map * - *===========================================================================*/ -void test_map(void) -{ - char buf_buf[CLICK_SIZE * 2]; - char buf_buf2[CLICK_SIZE * 2]; - char *buf, *buf2; - char get_buf[CLICK_SIZE]; - int *p; - volatile int *p2; - int *get_p; - size_t get_len; - int is; - int r; - - buf = (char*) CLICK_CEIL(buf_buf); - buf2 = (char*) CLICK_CEIL(buf_buf2); - - p = (int *)buf; - p2 = (int *)buf2; - get_p = (int *)get_buf; - - *p = 1; - r = ds_publish_map(key_map, buf, CLICK_SIZE, 0); - assert(r == OK); - - r = ds_snapshot_map(key_map, &is); - assert(r == OK); - - /* Copy the mapped memory range. - * Set *p=2, then the mapped memory range should change too - * and *get_p should be 2. - */ - *p = 2; - get_len = CLICK_SIZE; - r = ds_retrieve_map(key_map, get_buf, &get_len, 0, DSMF_COPY_MAPPED); - assert(r == OK && get_len == CLICK_SIZE && *get_p == 2); - - /* Copy snapshot, where *get_p should still be 1. */ - get_len = CLICK_SIZE; - r = ds_retrieve_map(key_map, get_buf, &get_len, is, DSMF_COPY_SNAPSHOT); - assert(r == OK && get_len == CLICK_SIZE && *get_p == 1); - - /* Map the mapped memory range to @buf2, then set *p=3, which - * in turn should let *p2=3. - */ - get_len = CLICK_SIZE; - r = ds_retrieve_map(key_map, buf2, &get_len, 0, DSMF_MAP_MAPPED); - assert(r == OK && get_len == CLICK_SIZE); - *p = 3; - assert(*p2 == 3); - - r = ds_delete_map(key_map); - assert(r == OK); - - printf("DSTEST: MAP test successful!\n"); -} - /*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ @@ -210,7 +150,6 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info)) test_u32(); test_str(); test_mem(); - test_map(); test_label(); return OK; diff --git a/test/ds/subs.c b/test/ds/subs.c index ee774e312..d63ebe3b5 100644 --- a/test/ds/subs.c +++ b/test/ds/subs.c @@ -72,8 +72,6 @@ int main(void) if(r != OK) printf("error in ds_retrieve_mem.\n"); break; - case DSF_TYPE_MAP: - break; default: printf("error in type! %d\n", type); } diff --git a/test/safecopy/grantor.c b/test/safecopy/grantor.c index d4a3f338a..8790a91b4 100644 --- a/test/safecopy/grantor.c +++ b/test/safecopy/grantor.c @@ -32,13 +32,13 @@ int main(int argc, char **argv) /* Get the requestor's endpoint. */ read(fid_get, &ep_requestor, sizeof(ep_requestor)); - dprint("GRANTOR: getting requestor's endpoint: %d\n", ep_requestor); + dprint(("GRANTOR: getting requestor's endpoint: %d\n", ep_requestor)); /* Grant. */ gid = cpf_grant_direct(ep_requestor, (long)buf, BUF_SIZE, CPF_READ | CPF_WRITE); - ep_self = getprocnr(); - dprint("GRANTOR: sending my endpoint %d and gid %d\n", ep_self, gid); + ep_self = sef_self(); + dprint(("GRANTOR: sending my endpoint %d and gid %d\n", ep_self, gid)); write(fid_send, &ep_self, sizeof(ep_self)); write(fid_send, &gid, sizeof(gid)); diff --git a/test/safecopy/inc.h b/test/safecopy/inc.h index f5e1f321d..3c3180a3e 100644 --- a/test/safecopy/inc.h +++ b/test/safecopy/inc.h @@ -17,6 +17,7 @@ #include #include #include +#include #include /* TEST_PAGE_SHIFT = @@ -44,8 +45,8 @@ #define DEBUG 0 #if DEBUG -# define dprint printf +# define dprint(x) printf x #else -# define dprint (void) +# define dprint(x) #endif diff --git a/test/safecopy/requestor.c b/test/safecopy/requestor.c index 4c1ef9b68..9c6ce8b6a 100644 --- a/test/safecopy/requestor.c +++ b/test/safecopy/requestor.c @@ -63,15 +63,15 @@ int main(int argc, char **argv) /* Sending the endpoint to the granter, in order to let him * create the grant. */ - ep_self = getprocnr(); + ep_self = sef_self(); write(fid_send, &ep_self, sizeof(ep_self)); - dprint("REQUESTOR: sending my endpoint: %d\n", ep_self); + dprint(("REQUESTOR: sending my endpoint: %d\n", ep_self)); /* Getting the granter's endpoint and gid. */ read(fid_get, &ep_granter, sizeof(ep_granter)); read(fid_get, &gid, sizeof(gid)); - dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n", - ep_granter, gid); + dprint(("REQUESTOR: getting granter's endpoint %d and gid %d\n", + ep_granter, gid)); /* Test SAFECOPY. */ for(i = 0; i <= TEST_PAGE_SHIFT; i++) {