Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src librumpuser is not _KERNEL code and does not belong in sys. ...
details: https://anonhg.NetBSD.org/src/rev/66b0f99deea3
branches: trunk
changeset: 752458:66b0f99deea3
user: pooka <pooka%NetBSD.org@localhost>
date: Fri Feb 26 18:54:20 2010 +0000
description:
librumpuser is not _KERNEL code and does not belong in sys. Move
the source files from src/sys/rump/librump/rumpuser to src/lib/librumpuser
(from where it is already built). Even so, keep rumpuser.h in
sys/rump/include for kernel source tree self-containment.
diffstat:
lib/librumpuser/Makefile | 23 +-
lib/librumpuser/rumpuser.3 | 50 ++
lib/librumpuser/rumpuser.c | 573 ++++++++++++++++++++++++
lib/librumpuser/rumpuser_dl.c | 413 +++++++++++++++++
lib/librumpuser/rumpuser_int.h | 61 ++
lib/librumpuser/rumpuser_net.c | 125 +++++
lib/librumpuser/rumpuser_pth.c | 526 ++++++++++++++++++++++
lib/librumpuser/rumpuser_pth_dummy.c | 296 ++++++++++++
lib/librumpuser/shlib_version | 4 +
sys/rump/librump/Makefile | 6 +-
sys/rump/librump/rumpuser/Makefile | 22 -
sys/rump/librump/rumpuser/rumpuser.3 | 50 --
sys/rump/librump/rumpuser/rumpuser.c | 576 -------------------------
sys/rump/librump/rumpuser/rumpuser_dl.c | 413 -----------------
sys/rump/librump/rumpuser/rumpuser_int.h | 61 --
sys/rump/librump/rumpuser/rumpuser_net.c | 125 -----
sys/rump/librump/rumpuser/rumpuser_pth.c | 529 ----------------------
sys/rump/librump/rumpuser/rumpuser_pth_dummy.c | 296 ------------
18 files changed, 2068 insertions(+), 2081 deletions(-)
diffs (truncated from 4232 to 300 lines):
diff -r e9d4ab4894b9 -r 66b0f99deea3 lib/librumpuser/Makefile
--- a/lib/librumpuser/Makefile Fri Feb 26 18:47:13 2010 +0000
+++ b/lib/librumpuser/Makefile Fri Feb 26 18:54:20 2010 +0000
@@ -1,9 +1,24 @@
-# $NetBSD: Makefile,v 1.1 2008/07/29 13:17:41 pooka Exp $
+# $NetBSD: Makefile,v 1.2 2010/02/26 18:54:20 pooka Exp $
#
-.PATH: ${.CURDIR}/../../sys/rump/librump/rumpuser
+WARNS= 4
+
+# rumpuser.h is in sys/rump for inclusion by kernel components
+.PATH: ${.CURDIR}/../../sys/rump/include/rump
+
+LIB= rumpuser
+LIBDPLIBS+= pthread ${.CURDIR}/../libpthread
-LIBDPLIBS+= pthread ${.CURDIR}/../libpthread
+SRCS= rumpuser.c rumpuser_net.c
+SRCS+= rumpuser_pth.c
+SRCS+= rumpuser_dl.c
+
+INCSDIR= /usr/include/rump
+INCS= rumpuser.h
+
MAN= rumpuser.3
-.include "${.CURDIR}/../../sys/rump/librump/rumpuser/Makefile"
+CPPFLAGS+= -D_REENTRANT
+
+
+.include <bsd.lib.mk>
diff -r e9d4ab4894b9 -r 66b0f99deea3 lib/librumpuser/rumpuser.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumpuser/rumpuser.3 Fri Feb 26 18:54:20 2010 +0000
@@ -0,0 +1,50 @@
+.\" $NetBSD: rumpuser.3,v 1.1 2010/02/26 18:54:20 pooka Exp $
+.\"
+.\" Copyright (c) 2008 Antti Kantee. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd July 28, 2008
+.Dt RUMPUSER 3
+.Os
+.Sh NAME
+.Nm rumpuser
+.Nd rump user namespace helper routines
+.Sh LIBRARY
+rump User Library (librumpuser, \-lrumpuser)
+.Sh SYNOPSIS
+.In rump/rumpuser.h
+.Sh DESCRIPTION
+.Nm
+is a user namespace helper library for runnable userspace meta programs.
+From rump emulation code compiled with
+.Dv -D_KERNEL
+is it not possible to directly call routines such as system calls
+for reading and writing files or devices.
+This is where
+.Nm
+comes into play by providing a bridge between the two namespaces.
+Another example of its services is a way to call pthread routines,
+used for emulating kernel threads and synchronization mechanisms
+in rump.
+.Sh SEE ALSO
+.Xr rump 3
diff -r e9d4ab4894b9 -r 66b0f99deea3 lib/librumpuser/rumpuser.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumpuser/rumpuser.c Fri Feb 26 18:54:20 2010 +0000
@@ -0,0 +1,573 @@
+/* $NetBSD: rumpuser.c,v 1.1 2010/02/26 18:54:20 pooka Exp $ */
+
+/*
+ * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: rumpuser.c,v 1.1 2010/02/26 18:54:20 pooka Exp $");
+#endif /* !lint */
+
+/* thank the maker for this */
+#ifdef __linux__
+#define _XOPEN_SOURCE 500
+#define _BSD_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <features.h>
+#endif
+
+#include <sys/param.h>
+#include <sys/event.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/uio.h>
+
+#ifdef __NetBSD__
+#include <sys/disklabel.h>
+#endif
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <rump/rumpuser.h>
+
+#include "rumpuser_int.h"
+
+int
+rumpuser_getfileinfo(const char *path, uint64_t *sizep, int *ftp, int *error)
+{
+ struct stat sb;
+ uint64_t size;
+ int needsdev = 0, rv = 0, ft;
+
+ if (stat(path, &sb) == -1) {
+ *error = errno;
+ return -1;
+ }
+
+ switch (sb.st_mode & S_IFMT) {
+ case S_IFDIR:
+ ft = RUMPUSER_FT_DIR;
+ break;
+ case S_IFREG:
+ ft = RUMPUSER_FT_REG;
+ break;
+ case S_IFBLK:
+ ft = RUMPUSER_FT_BLK;
+ needsdev = 1;
+ break;
+ case S_IFCHR:
+ ft = RUMPUSER_FT_CHR;
+ needsdev = 1;
+ break;
+ default:
+ ft = RUMPUSER_FT_OTHER;
+ break;
+ }
+
+ if (!needsdev) {
+ size = sb.st_size;
+ } else if (sizep) {
+ /*
+ * Welcome to the jungle. Of course querying the kernel
+ * for a device partition size is supposed to be far from
+ * trivial. On NetBSD we use ioctl. On $other platform
+ * we have a problem. We try "the lseek trick" and just
+ * fail if that fails. Platform specific code can later
+ * be written here if appropriate.
+ *
+ * On NetBSD we hope and pray that for block devices nobody
+ * else is holding them open, because otherwise the kernel
+ * will not permit us to open it. Thankfully, this is
+ * usually called only in bootstrap and then we can
+ * forget about it.
+ */
+#ifndef __NetBSD__
+ off_t off;
+ int fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ *error = errno;
+ rv = -1;
+ goto out;
+ }
+
+ off = lseek(fd, 0, SEEK_END);
+ close(fd);
+ if (off != 0) {
+ size = off;
+ goto out;
+ }
+ fprintf(stderr, "error: device size query not implemented on "
+ "this platform\n");
+ *error = EOPNOTSUPP;
+ rv = -1;
+ goto out;
+#else
+ struct disklabel lab;
+ struct partition *parta;
+ int fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ *error = errno;
+ rv = -1;
+ goto out;
+ }
+
+ if (ioctl(fd, DIOCGDINFO, &lab) == -1) {
+ *error = errno;
+ rv = -1;
+ goto out;
+ }
+ close(fd);
+
+ parta = &lab.d_partitions[DISKPART(sb.st_rdev)];
+ size = (uint64_t)lab.d_secsize * parta->p_size;
+#endif /* __NetBSD__ */
+ }
+
+ out:
+ if (rv == 0 && sizep)
+ *sizep = size;
+ if (rv == 0 && ftp)
+ *ftp = ft;
+
+ return rv;
+}
+
+int
+rumpuser_nanosleep(uint64_t *sec, uint64_t *nsec, int *error)
+{
+ struct timespec rqt, rmt;
+ int rv;
+
+ /*LINTED*/
+ rqt.tv_sec = *sec;
+ /*LINTED*/
+ rqt.tv_nsec = *nsec;
+
+ KLOCK_WRAP(rv = nanosleep(&rqt, &rmt));
+ if (rv == -1)
+ *error = errno;
+
+ *sec = rmt.tv_sec;
+ *nsec = rmt.tv_nsec;
+
+ return rv;
+}
+
+void *
+rumpuser__malloc(size_t howmuch, int canfail, const char *func, int line)
+{
+ void *rv;
+
+ rv = malloc(howmuch);
+ if (rv == NULL && canfail == 0) {
+ warn("malloc failed %s (%d)", func, line);
+ abort();
+ }
+
+ return rv;
+}
+
+void *
+rumpuser__realloc(void *ptr, size_t howmuch, int canfail,
+ const char *func, int line)
+{
Home |
Main Index |
Thread Index |
Old Index