libsys: various updates

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

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

View File

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

View File

@@ -1,27 +0,0 @@
#include <lib.h>
#include <unistd.h>
#include <string.h>
#include <minix/safecopies.h>
int
checkperms(endpoint_t endpt, char *path, size_t size)
{
cp_grant_id_t grant;
message m;
int r;
if ((grant = cpf_grant_direct(VFS_PROC_NR, (vir_bytes) path, size,
CPF_READ | CPF_WRITE)) == GRANT_INVALID)
return -1; /* called function sets errno */
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);
cpf_revoke(grant); /* does not touch errno */
return r;
}

View File

@@ -1,15 +0,0 @@
#include <lib.h>
#include <string.h>
int
copyfd(endpoint_t endpt, int fd, int what)
{
message m;
memset(&m, 0, sizeof(m));
m.VFS_COPYFD_ENDPT = endpt;
m.VFS_COPYFD_FD = fd;
m.VFS_COPYFD_WHAT = what;
return _syscall(VFS_PROC_NR, COPYFD, &m);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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