Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Make hypercall calling conventions consistent: iff a hyperca...



details:   https://anonhg.NetBSD.org/src/rev/9bf9f7efbfca
branches:  trunk
changeset: 786493:9bf9f7efbfca
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Apr 30 00:03:52 2013 +0000

description:
Make hypercall calling conventions consistent: iff a hypercall can fail,
it returns an int containing the error value.

diffstat:

 lib/librumpuser/rumpuser.c                   |  189 +++++++++++++++-----------
 lib/librumpuser/rumpuser_pth.c               |   42 ++---
 lib/librumpuser/rumpuser_sp.c                |   46 +++--
 sys/rump/dev/lib/libugenhc/rumpcomp_user.c   |   12 +-
 sys/rump/dev/lib/libugenhc/ugenhc.c          |   39 ++---
 sys/rump/fs/lib/libsyspuffs/puffs_rumpglue.c |   25 +-
 sys/rump/include/rump/rumpuser.h             |   39 ++---
 sys/rump/librump/rumpkern/cprng_stub.c       |   11 +-
 sys/rump/librump/rumpkern/emul.c             |    7 +-
 sys/rump/librump/rumpkern/klock.c            |    6 +-
 sys/rump/librump/rumpkern/locks.c            |   40 +++--
 sys/rump/librump/rumpkern/signals.c          |   10 +-
 sys/rump/librump/rumpkern/vm.c               |   21 +-
 sys/rump/librump/rumpvfs/rumpblk.c           |   17 +-
 sys/rump/librump/rumpvfs/rumpfs.c            |   46 +++---
 sys/rump/net/lib/libshmif/if_shmem.c         |   41 +++--
 sys/rump/net/lib/libshmif/rumpcomp_user.c    |   97 ++++++++-----
 sys/rump/net/lib/libshmif/rumpcomp_user.h    |    8 +-
 sys/rump/net/lib/libsockin/rumpcomp_user.c   |   63 ++++----
 sys/rump/net/lib/libsockin/rumpcomp_user.h   |   16 +-
 sys/rump/net/lib/libsockin/sockin.c          |   56 +++----
 sys/rump/net/lib/libvirtif/if_virt.c         |   20 +-
 sys/rump/net/lib/libvirtif/rumpcomp_user.c   |   55 +++++--
 sys/rump/net/lib/libvirtif/rumpcomp_user.h   |   10 +-
 24 files changed, 491 insertions(+), 425 deletions(-)

diffs (truncated from 2419 to 300 lines):

diff -r 6bf10e4d256d -r 9bf9f7efbfca lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Mon Apr 29 21:21:10 2013 +0000
+++ b/lib/librumpuser/rumpuser.c        Tue Apr 30 00:03:52 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.44 2013/04/29 20:08:48 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.45 2013/04/30 00:03:52 pooka Exp $      */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.44 2013/04/29 20:08:48 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.45 2013/04/30 00:03:52 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -98,16 +98,16 @@
 }
 
 int
-rumpuser_getfileinfo(const char *path, uint64_t *sizep, int *ftp, int *error)
+rumpuser_getfileinfo(const char *path, uint64_t *sizep, int *ftp)
 {
        struct stat sb;
-       uint64_t size;
-       int needsdev = 0, rv = 0, ft;
+       uint64_t size = 0;
+       int needsdev = 0, rv = 0, ft = 0;
        int fd = -1;
 
        if (stat(path, &sb) == -1) {
-               seterror(errno);
-               return -1;
+               rv = errno;
+               goto out;
        }
 
        switch (sb.st_mode & S_IFMT) {
@@ -152,8 +152,7 @@
 
                fd = open(path, O_RDONLY);
                if (fd == -1) {
-                       seterror(errno);
-                       rv = -1;
+                       rv = errno;
                        goto out;
                }
 
@@ -164,8 +163,7 @@
                }
                fprintf(stderr, "error: device size query not implemented on "
                    "this platform\n");
-               seterror(EOPNOTSUPP);
-               rv = -1;
+               rv = EOPNOTSUPP;
                goto out;
 #else
                struct disklabel lab;
@@ -174,8 +172,7 @@
 
                fd = open(path, O_RDONLY);
                if (fd == -1) {
-                       seterror(errno);
-                       rv = -1;
+                       rv = errno;
                        goto out;
                }
 
@@ -197,8 +194,7 @@
                        goto out;
                }
 
-               seterror(errno);
-               rv = -1;
+               rv = errno;
 #endif /* __NetBSD__ */
        }
 
@@ -213,8 +209,8 @@
        return rv;
 }
 
-void *
-rumpuser_malloc(size_t howmuch, int alignment)
+int
+rumpuser_malloc(size_t howmuch, int alignment, void **memp)
 {
        void *mem;
        int rv;
@@ -229,10 +225,10 @@
                            alignment);
                        abort();
                }
-               mem = NULL;
        }
 
-       return mem;
+       *memp = mem;
+       return rv;
 }
 
 /*ARGSUSED1*/
@@ -243,12 +239,12 @@
        free(ptr);
 }
 
-void *
+int
 rumpuser_anonmmap(void *prefaddr, size_t size, int alignbit,
-       int exec, int *error)
+       int exec, void **memp)
 {
-       void *rv;
-       int prot;
+       void *mem;
+       int prot, rv;
 
 #ifndef MAP_ALIGNED
 #define MAP_ALIGNED(a) 0
@@ -260,12 +256,15 @@
        prot = PROT_READ|PROT_WRITE;
        if (exec)
                prot |= PROT_EXEC;
-       rv = mmap(prefaddr, size, prot,
+       mem = mmap(prefaddr, size, prot,
            MAP_PRIVATE | MAP_ANON | MAP_ALIGNED(alignbit), -1, 0);
-       if (rv == MAP_FAILED) {
-               seterror(errno);
-               return NULL;
+       if (mem == MAP_FAILED) {
+               rv = errno;
+       } else {
+               *memp = mem;
+               rv = 0;
        }
+
        return rv;
 }
 
@@ -279,9 +278,9 @@
 }
 
 int
-rumpuser_open(const char *path, int ruflags, int *error)
+rumpuser_open(const char *path, int ruflags, int *fdp)
 {
-       int flags;
+       int fd, flags, rv;
 
        switch (ruflags & RUMPUSER_OPEN_ACCMODE) {
        case RUMPUSER_OPEN_RDONLY:
@@ -294,8 +293,8 @@
                flags = O_RDWR;
                break;
        default:
-               *error = EINVAL;
-               return -1;
+               rv = EINVAL;
+               goto out;
        }
 
 #define TESTSET(_ru_, _h_) if (ruflags & _ru_) flags |= _h_;
@@ -303,11 +302,20 @@
        TESTSET(RUMPUSER_OPEN_EXCL, O_EXCL);
 #undef TESTSET
 
-       DOCALL_KLOCK(int, (open(path, flags, 0644)));
+       KLOCK_WRAP(fd = open(path, flags, 0644));
+       if (fd == -1) {
+               rv = errno;
+       } else {
+               *fdp = fd;
+               rv = 0;
+       }
+
+ out:
+       return rv;
 }
 
 int
-rumpuser_close(int fd, int *error)
+rumpuser_close(int fd)
 {
        int nlocks;
 
@@ -324,38 +332,48 @@
  * If you encounter POSIX platforms where they aren't, add some
  * translation for iovlen > 1.
  */
-ssize_t
+int
 rumpuser_iovread(int fd, struct rumpuser_iovec *ruiov, size_t iovlen,
-       off_t off, int *error)
+       off_t off, size_t *retp)
 {
        struct iovec *iov = (struct iovec *)ruiov;
-       ssize_t rv;
+       ssize_t nn;
+       int rv;
 
        if (off == RUMPUSER_IOV_NOSEEK)
-               KLOCK_WRAP(rv = readv(fd, iov, iovlen));
+               KLOCK_WRAP(nn = readv(fd, iov, iovlen));
        else
-               KLOCK_WRAP(rv = preadv(fd, iov, iovlen, off));
+               KLOCK_WRAP(nn = preadv(fd, iov, iovlen, off));
 
-       if (rv == -1)
-               seterror(errno);
+       if (nn == -1) {
+               rv = errno;
+       } else {
+               *retp = (size_t)nn;
+               rv = 0;
+       }
 
        return rv;
 }
 
-ssize_t
+int
 rumpuser_iovwrite(int fd, const struct rumpuser_iovec *ruiov, size_t iovlen,
-       off_t off, int *error)
+       off_t off, size_t *retp)
 {
        const struct iovec *iov = (const struct iovec *)ruiov;
-       ssize_t rv;
+       ssize_t nn;
+       int rv;
 
        if (off == RUMPUSER_IOV_NOSEEK)
-               KLOCK_WRAP(rv = writev(fd, iov, iovlen));
+               KLOCK_WRAP(nn = writev(fd, iov, iovlen));
        else 
-               KLOCK_WRAP(rv = pwritev(fd, iov, iovlen, off));
+               KLOCK_WRAP(nn = pwritev(fd, iov, iovlen, off));
 
-       if (rv == -1)
-               seterror(errno);
+       if (nn == -1) {
+               rv = errno;
+       } else {
+               *retp = (size_t)nn;
+               rv = 0;
+       }
 
        return rv;
 }
@@ -384,12 +402,14 @@
 
        rv = clock_gettime(clk, &ts);
        if (rv == -1) {
-               return errno;
+               rv = errno;
+       } else {
+               *sec = ts.tv_sec;
+               *nsec = ts.tv_nsec;
+               rv = 0;
        }
-       *sec = ts.tv_sec;
-       *nsec = ts.tv_nsec;
 
-       return 0;
+       return rv;
 }
 
 int
@@ -489,6 +509,7 @@
 int
 rumpuser_getparam(const char *name, void *buf, size_t blen)
 {
+       int rv;
 
        if (strcmp(name, RUMPUSER_PARAM_NCPU) == 0) {
                int ncpu;
@@ -497,7 +518,7 @@
                        ncpu = gethostncpu();
                        snprintf(buf, blen, "%d", ncpu);
                }
-               return 0;
+               rv = 0;
        } else if (strcmp(name, RUMPUSER_PARAM_HOSTNAME) == 0) {
                char tmp[MAXHOSTNAMELEN];
 
@@ -507,22 +528,24 @@
                        snprintf(buf, blen, "rump-%05d.%s",
                            (int)getpid(), tmp);
                }
-               return 0;
+               rv = 0;
        } else if (*name == '_') {
-               return EINVAL;
+               rv = EINVAL;
        } else {
                if (getenv_r(name, buf, blen) == -1)
-                       return errno;
+                       rv = errno;
                else



Home | Main Index | Thread Index | Old Index