Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump/librump/rumpkern Add an initial console device and ...
details: https://anonhg.NetBSD.org/src/rev/05c4c3058caf
branches: trunk
changeset: 789778:05c4c3058caf
user: pooka <pooka%NetBSD.org@localhost>
date: Sat Sep 07 17:58:00 2013 +0000
description:
Add an initial console device and open fd's 0/1/2 for initproc. This is
again useful in standalone-type environments such as Xen, where all
printf/etc calls go through the rump kernel.
diffstat:
sys/rump/librump/rumpkern/Makefile.rumpkern | 4 +-
sys/rump/librump/rumpkern/cons.c | 133 ++++++++++++++++++++++++++++
sys/rump/librump/rumpkern/rump.c | 18 ++-
sys/rump/librump/rumpkern/rump_private.h | 4 +-
4 files changed, 150 insertions(+), 9 deletions(-)
diffs (227 lines):
diff -r 54ab8890d8ac -r 05c4c3058caf sys/rump/librump/rumpkern/Makefile.rumpkern
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern Sat Sep 07 17:23:55 2013 +0000
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern Sat Sep 07 17:58:00 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.rumpkern,v 1.131 2013/09/03 21:32:21 pooka Exp $
+# $NetBSD: Makefile.rumpkern,v 1.132 2013/09/07 17:58:00 pooka Exp $
#
.include "${RUMPTOP}/Makefile.rump"
@@ -19,7 +19,7 @@
#
# Source modules, first the ones specifically implemented for librump.
#
-SRCS+= rump.c rumpcopy.c emul.c intr.c lwproc.c klock.c \
+SRCS+= rump.c rumpcopy.c cons.c emul.c intr.c lwproc.c klock.c \
kobj_rename.c ltsleep.c scheduler.c \
signals.c sleepq.c threads.c vm.c cprng_stub.c
diff -r 54ab8890d8ac -r 05c4c3058caf sys/rump/librump/rumpkern/cons.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/librump/rumpkern/cons.c Sat Sep 07 17:58:00 2013 +0000
@@ -0,0 +1,133 @@
+/* $NetBSD: cons.c,v 1.1 2013/09/07 17:58:00 pooka Exp $ */
+
+/*
+ * Copyright (c) 2013 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.
+ */
+
+/*
+ * rumpcons, a (very) simple console-type device which relays output
+ * to the rumpuser_putchar() hypercall. This is most useful in
+ * environments where there is no Unix-like host (e.g. Xen DomU).
+ * It's currently a truly half duplex console since there is support
+ * only for writing to the console (there is no hypercall for reading
+ * the host console).
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.1 2013/09/07 17:58:00 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/proc.h>
+#include <sys/stat.h>
+
+#include <rump/rumpuser.h>
+
+#include "rump_private.h"
+
+static int rumpcons_write(struct file *, off_t *, struct uio *,
+ kauth_cred_t, int);
+static int rumpcons_stat(struct file *, struct stat *);
+
+static const struct fileops rumpcons_fileops = {
+ .fo_read = (void *)nullop,
+ .fo_write = rumpcons_write,
+ .fo_ioctl = fbadop_ioctl,
+ .fo_fcntl = fnullop_fcntl,
+ .fo_poll = fnullop_poll,
+ .fo_stat = rumpcons_stat,
+ .fo_close = (void *)nullop,
+ .fo_kqfilter = fnullop_kqfilter,
+ .fo_restart = fnullop_restart,
+};
+
+void
+rump_consdev_init(void)
+{
+ struct file *fp;
+ int fd, error;
+
+ /*
+ * We want to open the descriptors for the implicit proc
+ * so that they get inherited by default to all processes.
+ */
+ KASSERT(curproc->p_pid == 1);
+ KASSERT(fd_getfile(0) == NULL);
+
+ /* then, map a file descriptor to the device */
+ if ((error = fd_allocfile(&fp, &fd)) != 0)
+ panic("cons fd_allocfile failed: %d", error);
+
+ fp->f_flag = FWRITE;
+ fp->f_type = DTYPE_MISC;
+ fp->f_ops = &rumpcons_fileops;
+ fp->f_data = NULL;
+ fd_affix(curproc, fp, fd);
+
+ KASSERT(fd == 0);
+ error += fd_dup2(fp, 1, 0);
+ error += fd_dup2(fp, 2, 0);
+
+ if (error)
+ panic("failed to dup fd 0/1/2");
+}
+
+static int
+rumpcons_write(struct file *fp, off_t *off, struct uio *uio,
+ kauth_cred_t cred, int flags)
+{
+ char *buf;
+ size_t len, n;
+ int error;
+
+ buf = kmem_alloc(PAGE_SIZE, KM_SLEEP);
+ while (uio->uio_resid > 0) {
+ len = min(PAGE_SIZE, uio->uio_resid);
+ error = uiomove(buf, len, uio);
+ if (error)
+ break;
+
+ for (n = 0; n < len; n++) {
+ rumpuser_putchar(*(buf+n));
+ }
+ }
+ kmem_free(buf, PAGE_SIZE);
+
+ return error;
+}
+
+static int
+rumpcons_stat(struct file *fp, struct stat *sb)
+{
+
+ memset(sb, 0, sizeof(*sb));
+ sb->st_mode = 0600;
+ sb->st_atimespec = sb->st_mtimespec = sb->st_ctimespec = boottime;
+ sb->st_birthtimespec = boottime;
+
+ return 0;
+}
diff -r 54ab8890d8ac -r 05c4c3058caf sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c Sat Sep 07 17:23:55 2013 +0000
+++ b/sys/rump/librump/rumpkern/rump.c Sat Sep 07 17:58:00 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rump.c,v 1.273 2013/09/04 17:56:08 pooka Exp $ */
+/* $NetBSD: rump.c,v 1.274 2013/09/07 17:58:00 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.273 2013/09/04 17:56:08 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.274 2013/09/07 17:58:00 pooka Exp $");
#include <sys/systm.h>
#define ELFSIZE ARCH_ELFSIZE
@@ -251,7 +251,7 @@
struct timespec ts;
int64_t sec;
long nsec;
- struct lwp *l;
+ struct lwp *l, *initlwp;
int i, numcpu;
/* not reentrant */
@@ -471,10 +471,10 @@
vmem_rehash_start();
/*
- * Create init, used to attach implicit threads in rump.
+ * Create init (proc 1), used to attach implicit threads in rump.
* (note: must be done after vfsinit to get cwdi)
*/
- (void)rump__lwproc_alloclwp(NULL); /* dummy thread for initproc */
+ initlwp = rump__lwproc_alloclwp(NULL);
mutex_enter(proc_lock);
initproc = proc_find_raw(1);
mutex_exit(proc_lock);
@@ -542,8 +542,14 @@
rump_component_init(RUMP_COMPONENT_POSTINIT);
+ /* component inits done */
+ bootlwp = NULL;
+
+ /* open 0/1/2 for init */
+ rump_lwproc_switch(initlwp);
+ rump_consdev_init();
+
/* release cpu */
- bootlwp = NULL;
rump_unschedule();
return 0;
diff -r 54ab8890d8ac -r 05c4c3058caf sys/rump/librump/rumpkern/rump_private.h
--- a/sys/rump/librump/rumpkern/rump_private.h Sat Sep 07 17:23:55 2013 +0000
+++ b/sys/rump/librump/rumpkern/rump_private.h Sat Sep 07 17:58:00 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rump_private.h,v 1.75 2013/09/03 19:55:13 pooka Exp $ */
+/* $NetBSD: rump_private.h,v 1.76 2013/09/07 17:58:00 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -145,4 +145,6 @@
void rump_thread_init(void);
void rump_thread_allow(void);
+void rump_consdev_init(void);
+
#endif /* _SYS_RUMP_PRIVATE_H_ */
Home |
Main Index |
Thread Index |
Old Index