Module Name:    src
Committed By:   pooka
Date:           Thu Nov  4 21:01:29 UTC 2010

Modified Files:
        src/lib: Makefile
Added Files:
        src/lib/librumpclient: Makefile rumpclient.c rumpclient.h shlib_version

Log Message:
Add library for rump syscall client stubs.


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/lib/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/librumpclient/Makefile \
    src/lib/librumpclient/rumpclient.c src/lib/librumpclient/rumpclient.h \
    src/lib/librumpclient/shlib_version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/Makefile
diff -u src/lib/Makefile:1.152 src/lib/Makefile:1.153
--- src/lib/Makefile:1.152	Sun Oct 31 11:52:50 2010
+++ src/lib/Makefile	Thu Nov  4 21:01:28 2010
@@ -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

Added files:

Index: src/lib/librumpclient/Makefile
diff -u /dev/null src/lib/librumpclient/Makefile:1.1
--- /dev/null	Thu Nov  4 21:01:29 2010
+++ src/lib/librumpclient/Makefile	Thu Nov  4 21:01:29 2010
@@ -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>
Index: src/lib/librumpclient/rumpclient.c
diff -u /dev/null src/lib/librumpclient/rumpclient.c:1.1
--- /dev/null	Thu Nov  4 21:01:29 2010
+++ src/lib/librumpclient/rumpclient.c	Thu Nov  4 21:01:29 2010
@@ -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;
+}
Index: src/lib/librumpclient/rumpclient.h
diff -u /dev/null src/lib/librumpclient/rumpclient.h:1.1
--- /dev/null	Thu Nov  4 21:01:29 2010
+++ src/lib/librumpclient/rumpclient.h	Thu Nov  4 21:01:29 2010
@@ -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_ */
Index: src/lib/librumpclient/shlib_version
diff -u /dev/null src/lib/librumpclient/shlib_version:1.1
--- /dev/null	Thu Nov  4 21:01:29 2010
+++ src/lib/librumpclient/shlib_version	Thu Nov  4 21:01:29 2010
@@ -0,0 +1,4 @@
+#	$NetBSD: shlib_version,v 1.1 2010/11/04 21:01:29 pooka Exp $
+#
+major=0
+minor=0

Reply via email to