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
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++) {
/* 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));
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));
/* 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));
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. */
/* 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. */
* 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) {
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);
#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 */
# 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 */
#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'. */
/* 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)
*==========================================================================*/
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);
/* 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 */
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
)
}
/* 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);
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);
}
/* 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);
}
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);
# 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
+++ /dev/null
-#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 */
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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 */
-}
-
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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 */
-}
+++ /dev/null
-#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 */
-}
-
+++ /dev/null
-#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);
-}
-
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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);
-}
-
+++ /dev/null
-#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);
-}
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);
}
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
static int sef_cb_init_fresh(int type, sef_init_info_t *info)
{
/* Initialize the Minix file server. */
- SELF_E = getprocnr();
return(OK);
}
)
{
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;
}
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 \
kprintf.c \
kputc.c \
kputs.c \
+ mapdriver.c \
optset.c \
panic.c \
safecopies.c \
sef_ping.c \
sef_signal.c \
sqrt_approx.c \
+ srv_fork.c \
+ srv_kill.c \
stacktrace.c \
sys_abort.c \
sys_clear.c \
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"
-#include <lib.h>
+#include "syslib.h"
+
#include <unistd.h>
#include <string.h>
#include <minix/safecopies.h>
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;
}
-#include <lib.h>
+#include "syslib.h"
+
#include <string.h>
int
m.VFS_COPYFD_FD = fd;
m.VFS_COPYFD_WHAT = what;
- return _syscall(VFS_PROC_NR, COPYFD, &m);
+ return _taskcall(VFS_PROC_NR, COPYFD, &m);
}
#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;
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;
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;
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;
}
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);
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;
#include "sysutil.h"
+#include <string.h>
/*===========================================================================*
* fkey_ctl *
*/
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;
--- /dev/null
+#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;
+}
--- /dev/null
+#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;
+}
-#include <lib.h>
+#include "syslib.h"
+#include <string.h>
#include <minix/sysinfo.h>
#include <minix/com.h>
)
{
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);
}
--- /dev/null
+#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);
+}
#include <assert.h>
#include <machine/archtypes.h>
#include <minix/timers.h>
+#include <string.h>
#include "kernel/config.h"
#include "kernel/const.h"
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;
}
/* 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;
#include "syslib.h"
#include <assert.h>
+#include <string.h>
/*===========================================================================*
* sched_stop *
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;
/* 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;
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;
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 *
*===========================================================================*/
#include <assert.h>
#include <unistd.h>
#include <minix/sysutil.h>
+#include <string.h>
/* SEF Init callbacks. */
static struct sef_cbs {
break;
}
+ memset(&m, 0, sizeof(m));
m.m_source = sef_self_endpoint;
m.m_type = RS_INIT;
m.RS_INIT_RESULT = result;
--- /dev/null
+#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);
+}
--- /dev/null
+#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);
+}
#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;
#include "syslib.h"
+#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
{
message m;
+ memset(&m, 0, sizeof(m));
m.VMB_ENDPOINT = ep;
m.VMB_ADDR = (void *) addr;
#include "syslib.h"
-
+#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
message m;
int result;
+ memset(&m, 0, sizeof(m));
m.VME_ENDPOINT = ep;
result = _taskcall(VM_PROC_NR, VM_EXIT, &m);
message m;
int result;
+ memset(&m, 0, sizeof(m));
m.VMWE_ENDPOINT = ep;
result = _taskcall(VM_PROC_NR, VM_WILLEXIT, &m);
#include "syslib.h"
+#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
message m;
int result;
+ memset(&m, 0, sizeof(m));
m.VMF_ENDPOINT = ep;
m.VMF_SLOTNO = slot;
#include "syslib.h"
+#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
{
message m;
+ memset(&m, 0, sizeof(m));
m.VMI_WHAT = VMIW_STATS;
m.VMI_PTR = (void *) vsi;
{
message m;
+ memset(&m, 0, sizeof(m));
m.VMI_WHAT = VMIW_USAGE;
m.VMI_EP = who;
m.VMI_PTR = (void *) vui;
message m;
int result;
+ memset(&m, 0, sizeof(m));
m.VMI_WHAT = VMIW_REGION;
m.VMI_EP = who;
m.VMI_COUNT = count;
-#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);
}
-
--- /dev/null
+#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);
+}
#include "syslib.h"
+#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
message m;
int result;
+ memset(&m, 0, sizeof(m));
m.VM_NOTIFY_SIG_ENDPOINT = ep;
m.VM_NOTIFY_SIG_IPC = ipc_ep;
--- /dev/null
+#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);
+}
--- /dev/null
+#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);
+}
#include "syslib.h"
+#include <string.h>
#include <minix/vm.h>
/*===========================================================================*
message m;
int result;
+ memset(&m, 0, sizeof(m));
m.VMU_SEG = seg;
m.VMU_OFFSET = (char *) offset;
m.VMU_LENGTH = (char *) len;
--- /dev/null
+#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);
+}
#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 {
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;
};
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
init_inode_cache();
- SELF_E = getprocnr();
-
/* just a small number before we find out the block size at mount time */
lmfs_buf_pool(10);
)
{
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());
}
EXTERN int identifier;
EXTERN endpoint_t who_e;
EXTERN int call_type;
-EXTERN endpoint_t SELF_E;
-
int identifier = 0x1234;
endpoint_t who_e;
int call_type;
-endpoint_t SELF_E;
static struct {
int type;
{
/* 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);
}
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;
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;
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)
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;
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;
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 =
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;
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;
/* 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;
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;
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;
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;
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;
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);
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;
{
/* 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 */
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());
}
/* 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);
}
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.
init_inode_cache();
- SELF_E = getprocnr();
lmfs_buf_pool(DEFAULT_NR_BUFS);
return(OK);
)
{
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());
}
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);
}
* 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
/*===========================================================================*
* 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);
}
/*===========================================================================*
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);
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 */
/* 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);
}
}
/* 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;
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 *
*===========================================================================*/
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);
*/
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);
}
}
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);
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)
/* 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);
}
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);
#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
==================
`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
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";
/*===========================================================================*
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);
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 *
*===========================================================================*/
test_u32();
test_str();
test_mem();
- test_map();
test_label();
return OK;
if(r != OK)
printf("error in ds_retrieve_mem.\n");
break;
- case DSF_TYPE_MAP:
- break;
default:
printf("error in type! %d\n", type);
}
/* 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));
#include <minix/safecopies.h>
#include <minix/syslib.h>
#include <minix/sysutil.h>
+#include <minix/minlib.h>
#include <errno.h>
/* TEST_PAGE_SHIFT =
#define DEBUG 0
#if DEBUG
-# define dprint printf
+# define dprint(x) printf x
#else
-# define dprint (void)
+# define dprint(x)
#endif
/* 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++) {