Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib Add library for rump syscall client stubs.
details: https://anonhg.NetBSD.org/src/rev/67ba71b19f70
branches: trunk
changeset: 758438:67ba71b19f70
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Nov 04 21:01:28 2010 +0000
description:
Add library for rump syscall client stubs.
diffstat:
lib/Makefile | 4 +-
lib/librumpclient/Makefile | 15 ++
lib/librumpclient/rumpclient.c | 211 ++++++++++++++++++++++++++++++++++++++++
lib/librumpclient/rumpclient.h | 38 +++++++
lib/librumpclient/shlib_version | 4 +
5 files changed, 270 insertions(+), 2 deletions(-)
diffs (truncated from 302 to 300 lines):
diff -r 412975dfb6ca -r 67ba71b19f70 lib/Makefile
--- a/lib/Makefile Thu Nov 04 20:57:00 2010 +0000
+++ b/lib/Makefile Thu Nov 04 21:01:28 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.152 2010/10/31 11:52:50 mbalmer Exp $
+# $NetBSD: Makefile,v 1.153 2010/11/04 21:01:28 pooka Exp $
# from: @(#)Makefile 5.25.1.1 (Berkeley) 5/7/91
.include <bsd.own.mk>
@@ -9,7 +9,7 @@
libintl libkvm libm \
libossaudio libpcap libpci libpmc libposix libprop libpthread \
libpthread_dbg libpuffs libresolv librmt librpcsvc librt \
- libterminfo libusbhid libutil libwrap liby libz
+ librumpclient libterminfo libusbhid libutil libwrap liby libz
SUBDIR+=../external/bsd/flex/lib
SUBDIR+=../external/mit/lua/lib
diff -r 412975dfb6ca -r 67ba71b19f70 lib/librumpclient/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumpclient/Makefile Thu Nov 04 21:01:28 2010 +0000
@@ -0,0 +1,15 @@
+# $NetBSD: Makefile,v 1.1 2010/11/04 21:01:29 pooka Exp $
+#
+
+.PATH: ${.CURDIR}/../../sys/rump/librump/rumpkern
+
+LIB= rumpclient
+
+INCS= rumpclient.h
+INCSDIR= /usr/include/rump
+
+CPPFLAGS+= -DRUMP_CLIENT -I${.CURDIR} -I${.CURDIR}/../librumpuser
+SRCS= rumpclient.c
+SRCS+= rump_syscalls.c
+
+.include <bsd.lib.mk>
diff -r 412975dfb6ca -r 67ba71b19f70 lib/librumpclient/rumpclient.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumpclient/rumpclient.c Thu Nov 04 21:01:28 2010 +0000
@@ -0,0 +1,211 @@
+/* $NetBSD: rumpclient.c,v 1.1 2010/11/04 21:01:29 pooka Exp $ */
+
+/*
+ * Copyright (c) 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.
+ */
+
+/*
+ * Client side routines for rump syscall proxy.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD");
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <pthread.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rump/rumpclient.h>
+
+#include "sp_common.c"
+
+static struct spclient clispc;
+
+static int
+send_syscall_req(struct spclient *spc, int sysnum,
+ const void *data, size_t dlen)
+{
+ struct rsp_hdr rhdr;
+
+ rhdr.rsp_len = sizeof(rhdr) + dlen;
+ rhdr.rsp_reqno = nextreq++;
+ rhdr.rsp_type = RUMPSP_SYSCALL_REQ;
+ rhdr.rsp_sysnum = sysnum;
+
+ dosend(spc, &rhdr, sizeof(rhdr));
+ dosend(spc, data, dlen);
+
+ return 0;
+}
+
+static int
+send_copyin_resp(struct spclient *spc, uint64_t reqno, void *data, size_t dlen)
+{
+ struct rsp_hdr rhdr;
+
+ rhdr.rsp_len = sizeof(rhdr) + dlen;
+ rhdr.rsp_reqno = reqno;
+ rhdr.rsp_type = RUMPSP_COPYIN_RESP;
+ rhdr.rsp_sysnum = 0;
+
+ dosend(spc, &rhdr, sizeof(rhdr));
+ dosend(spc, data, dlen);
+
+ return 0;
+}
+
+static int
+send_anonmmap_resp(struct spclient *spc, uint64_t reqno, void *addr)
+{
+ struct rsp_hdr rhdr;
+
+ rhdr.rsp_len = sizeof(rhdr) + sizeof(addr);
+ rhdr.rsp_reqno = reqno;
+ rhdr.rsp_type = RUMPSP_ANONMMAP_RESP;
+ rhdr.rsp_sysnum = 0;
+
+ dosend(spc, &rhdr, sizeof(rhdr));
+ dosend(spc, &addr, sizeof(addr));
+
+ return 0;
+}
+
+int
+rumpclient_syscall(int sysnum, const void *data, size_t dlen,
+ register_t *retval)
+{
+ struct rsp_sysresp *resp;
+ struct rsp_copydata *copydata;
+ struct pollfd pfd;
+ size_t maplen;
+ void *mapaddr;
+ int gotresp;
+
+ DPRINTF(("rump_sp_syscall: executing syscall %d\n", sysnum));
+
+ send_syscall_req(&clispc, sysnum, data, dlen);
+
+ DPRINTF(("rump_sp_syscall: syscall %d request sent. "
+ "waiting for response\n", sysnum));
+
+ pfd.fd = clispc.spc_fd;
+ pfd.events = POLLIN;
+
+ gotresp = 0;
+ while (!gotresp) {
+ while (readframe(&clispc) < 1)
+ poll(&pfd, 1, INFTIM);
+
+ switch (clispc.spc_hdr.rsp_type) {
+ case RUMPSP_COPYIN_REQ:
+ /*LINTED*/
+ copydata = (struct rsp_copydata *)clispc.spc_buf;
+ DPRINTF(("rump_sp_syscall: copyin request: %p/%zu\n",
+ copydata->rcp_addr, copydata->rcp_len));
+ send_copyin_resp(&clispc, clispc.spc_hdr.rsp_reqno,
+ copydata->rcp_addr, copydata->rcp_len);
+ clispc.spc_off = 0;
+ break;
+ case RUMPSP_COPYOUT_REQ:
+ /*LINTED*/
+ copydata = (struct rsp_copydata *)clispc.spc_buf;
+ DPRINTF(("rump_sp_syscall: copyout request: %p/%zu\n",
+ copydata->rcp_addr, copydata->rcp_len));
+ /*LINTED*/
+ memcpy(copydata->rcp_addr, copydata->rcp_data,
+ copydata->rcp_len);
+ clispc.spc_off = 0;
+ break;
+ case RUMPSP_ANONMMAP_REQ:
+ /*LINTED*/
+ maplen = *(size_t *)clispc.spc_buf;
+ mapaddr = mmap(NULL, maplen, PROT_READ|PROT_WRITE,
+ MAP_ANON, -1, 0);
+ if (mapaddr == MAP_FAILED)
+ mapaddr = NULL;
+ send_anonmmap_resp(&clispc,
+ clispc.spc_hdr.rsp_reqno, mapaddr);
+ clispc.spc_off = 0;
+ break;
+ case RUMPSP_SYSCALL_RESP:
+ DPRINTF(("rump_sp_syscall: got response \n"));
+ gotresp = 1;
+ break;
+ }
+ }
+
+ /*LINTED*/
+ resp = (struct rsp_sysresp *)clispc.spc_buf;
+ memcpy(retval, &resp->rsys_retval, sizeof(resp->rsys_retval));
+ clispc.spc_off = 0;
+
+ return resp->rsys_error;
+}
+
+int
+rumpclient_init()
+{
+ struct sockaddr *sap;
+ char *p;
+ unsigned idx;
+ int error, s;
+
+ if ((p = getenv("RUMP_SP_CLIENT")) == NULL)
+ return ENOENT;
+
+ if ((error = parseurl(p, &sap, &idx, 0)) != 0)
+ return error;
+
+ s = socket(parsetab[idx].domain, SOCK_STREAM, 0);
+ if (s == -1)
+ return errno;
+
+ if (connect(s, sap, sap->sa_len) == -1) {
+ fprintf(stderr, "rump_sp: client connect failed\n");
+ return errno;
+ }
+ if ((error = parsetab[idx].connhook(s)) != 0) {
+ fprintf(stderr, "rump_sp: connect hook failed\n");
+ return error;
+ }
+
+ clispc.spc_fd = s;
+
+ return 0;
+}
diff -r 412975dfb6ca -r 67ba71b19f70 lib/librumpclient/rumpclient.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumpclient/rumpclient.h Thu Nov 04 21:01:28 2010 +0000
@@ -0,0 +1,38 @@
+/* $NetBSD: rumpclient.h,v 1.1 2010/11/04 21:01:29 pooka Exp $ */
+
+/*-
+ * Copyright (c) 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.
+ */
+
+#ifndef _RUMP_RUMPCLIENT_H_
+#define _RUMP_RUMPCLIENT_H_
+
+__BEGIN_DECLS
+
+int rumpclient_syscall(int, const void *, size_t, register_t *);
+int rumpclient_init(void);
+
+__END_DECLS
+
+#endif /* _RUMP_RUMPCLIENT_H_ */
diff -r 412975dfb6ca -r 67ba71b19f70 lib/librumpclient/shlib_version
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librumpclient/shlib_version Thu Nov 04 21:01:28 2010 +0000
@@ -0,0 +1,4 @@
+# $NetBSD: shlib_version,v 1.1 2010/11/04 21:01:29 pooka Exp $
+#
Home |
Main Index |
Thread Index |
Old Index