Wed Mar 18 15:32:28 2009 UTC ()
* allow to specify PROT_READ/PROT_WRITE when mmapping a file
* add msync


(pooka)
diff -r1.19 -r1.20 src/sys/rump/include/rump/rumpuser.h
diff -r1.36 -r1.37 src/sys/rump/librump/rumpuser/rumpuser.c
diff -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/if_shmem.c

cvs diff -r1.19 -r1.20 src/sys/rump/include/rump/rumpuser.h (expand / switch to unified diff)

--- src/sys/rump/include/rump/rumpuser.h 2009/02/28 15:49:12 1.19
+++ src/sys/rump/include/rump/rumpuser.h 2009/03/18 15:32:27 1.20
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpuser.h,v 1.19 2009/02/28 15:49:12 pooka Exp $ */ 1/* $NetBSD: rumpuser.h,v 1.20 2009/03/18 15:32:27 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by Google Summer of Code. 6 * Development of this software was supported by Google Summer of Code.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -44,28 +44,33 @@ int rumpuser_getfileinfo(const char *, u @@ -44,28 +44,33 @@ int rumpuser_getfileinfo(const char *, u
44#define RUMPUSER_FT_REG 2 44#define RUMPUSER_FT_REG 2
45#define RUMPUSER_FT_BLK 3 45#define RUMPUSER_FT_BLK 3
46#define RUMPUSER_FT_OTHER 4 46#define RUMPUSER_FT_OTHER 4
47int rumpuser_nanosleep(uint64_t *, uint64_t *, int *); 47int rumpuser_nanosleep(uint64_t *, uint64_t *, int *);
48 48
49#define rumpuser_malloc(a,b) rumpuser__malloc(a,b,__func__,__LINE__); 49#define rumpuser_malloc(a,b) rumpuser__malloc(a,b,__func__,__LINE__);
50#define rumpuser_realloc(a,b,c) rumpuser__realloc(a,b,c,__func__,__LINE__); 50#define rumpuser_realloc(a,b,c) rumpuser__realloc(a,b,c,__func__,__LINE__);
51 51
52void *rumpuser__malloc(size_t, int, const char *, int); 52void *rumpuser__malloc(size_t, int, const char *, int);
53void *rumpuser__realloc(void *, size_t, int, const char *, int); 53void *rumpuser__realloc(void *, size_t, int, const char *, int);
54void rumpuser_free(void *); 54void rumpuser_free(void *);
55 55
56void *rumpuser_anonmmap(size_t, int, int, int *); 56void *rumpuser_anonmmap(size_t, int, int, int *);
57void *rumpuser_filemmap(int fd, off_t, size_t, int, int, int *); 57#define RUMPUSER_FILEMMAP_READ 0x01
 58#define RUMPUSER_FILEMMAP_WRITE 0x02
 59#define RUMPUSER_FILEMMAP_TRUNCATE 0x04
 60#define RUMPUSER_FILEMMAP_SHARED 0x08
 61void *rumpuser_filemmap(int fd, off_t, size_t, int, int *);
58void rumpuser_unmap(void *, size_t); 62void rumpuser_unmap(void *, size_t);
 63int rumpuser_memsync(void *, size_t, int *);
59 64
60int rumpuser_open(const char *, int, int *); 65int rumpuser_open(const char *, int, int *);
61int rumpuser_ioctl(int, u_long, void *, int *); 66int rumpuser_ioctl(int, u_long, void *, int *);
62int rumpuser_close(int, int *); 67int rumpuser_close(int, int *);
63int rumpuser_fsync(int, int *); 68int rumpuser_fsync(int, int *);
64 69
65typedef void (*rump_biodone_fn)(void *, size_t, int); 70typedef void (*rump_biodone_fn)(void *, size_t, int);
66 71
67ssize_t rumpuser_read(int, void *, size_t, int *); 72ssize_t rumpuser_read(int, void *, size_t, int *);
68ssize_t rumpuser_pread(int, void *, size_t, off_t, int *); 73ssize_t rumpuser_pread(int, void *, size_t, off_t, int *);
69ssize_t rumpuser_write(int, const void *, size_t, int *); 74ssize_t rumpuser_write(int, const void *, size_t, int *);
70ssize_t rumpuser_pwrite(int, const void *, size_t, off_t, int *); 75ssize_t rumpuser_pwrite(int, const void *, size_t, off_t, int *);
71void rumpuser_read_bio(int, void *, size_t, off_t, rump_biodone_fn, void *); 76void rumpuser_read_bio(int, void *, size_t, off_t, rump_biodone_fn, void *);

cvs diff -r1.36 -r1.37 src/sys/rump/librump/rumpuser/Attic/rumpuser.c (expand / switch to unified diff)

--- src/sys/rump/librump/rumpuser/Attic/rumpuser.c 2009/03/18 10:22:45 1.36
+++ src/sys/rump/librump/rumpuser/Attic/rumpuser.c 2009/03/18 15:32:27 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpuser.c,v 1.36 2009/03/18 10:22:45 cegger Exp $ */ 1/* $NetBSD: rumpuser.c,v 1.37 2009/03/18 15:32:27 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by Google Summer of Code 6 * Development of this software was supported by Google Summer of Code
7 * and the Finnish Cultural Foundation. 7 * and the Finnish Cultural Foundation.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32#if !defined(lint) 32#if !defined(lint)
33__RCSID("$NetBSD: rumpuser.c,v 1.36 2009/03/18 10:22:45 cegger Exp $"); 33__RCSID("$NetBSD: rumpuser.c,v 1.37 2009/03/18 15:32:27 pooka Exp $");
34#endif /* !lint */ 34#endif /* !lint */
35 35
36/* thank the maker for this */ 36/* thank the maker for this */
37#ifdef __linux__ 37#ifdef __linux__
38#define _XOPEN_SOURCE 500 38#define _XOPEN_SOURCE 500
39#define _BSD_SOURCE 39#define _BSD_SOURCE
40#define _FILE_OFFSET_BITS 64 40#define _FILE_OFFSET_BITS 64
41#include <features.h> 41#include <features.h>
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/event.h> 45#include <sys/event.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
@@ -172,52 +172,64 @@ rumpuser_anonmmap(size_t size, int align @@ -172,52 +172,64 @@ rumpuser_anonmmap(size_t size, int align
172 return rv; 172 return rv;
173} 173}
174 174
175void 175void
176rumpuser_unmap(void *addr, size_t len) 176rumpuser_unmap(void *addr, size_t len)
177{ 177{
178 int rv; 178 int rv;
179 179
180 rv = munmap(addr, len); 180 rv = munmap(addr, len);
181 assert(rv == 0); 181 assert(rv == 0);
182} 182}
183 183
184void * 184void *
185rumpuser_filemmap(int fd, off_t offset, size_t len, int shared, 185rumpuser_filemmap(int fd, off_t offset, size_t len, int flags, int *error)
186 int dotruncate, int *error) 
187{ 186{
188 void *rv; 187 void *rv;
189 int flags; 188 int mmflags, prot;
190 189
191 if (dotruncate) 190 if (flags & RUMPUSER_FILEMMAP_TRUNCATE)
192 ftruncate(fd, offset + len); 191 ftruncate(fd, offset + len);
193 192
194 flags = MAP_FILE; 193 mmflags = MAP_FILE;
195 if (shared) 194 if (flags & RUMPUSER_FILEMMAP_SHARED)
196 flags |= MAP_SHARED; 195 mmflags |= MAP_SHARED;
197 else 196 else
198 flags |= MAP_PRIVATE; 197 mmflags |= MAP_PRIVATE;
199 198
200 rv = mmap(NULL, len, PROT_READ|PROT_WRITE, flags, fd, offset); 199 prot = 0;
 200 if (flags & RUMPUSER_FILEMMAP_READ)
 201 prot |= PROT_READ;
 202 if (flags & RUMPUSER_FILEMMAP_WRITE)
 203 prot |= PROT_WRITE;
 204
 205 rv = mmap(NULL, len, PROT_READ|PROT_WRITE, mmflags, fd, offset);
201 if (rv == MAP_FAILED) { 206 if (rv == MAP_FAILED) {
202 *error = errno; 207 *error = errno;
203 return NULL; 208 return NULL;
204 } 209 }
205 210
206 *error = 0; 211 *error = 0;
207 return rv; 212 return rv;
208} 213}
209 214
210int 215int
 216rumpuser_memsync(void *addr, size_t len, int *error)
 217{
 218
 219 DOCALL_KLOCK(int, (msync(addr, len, MS_SYNC)));
 220}
 221
 222int
211rumpuser_open(const char *path, int flags, int *error) 223rumpuser_open(const char *path, int flags, int *error)
212{ 224{
213 225
214 DOCALL(int, (open(path, flags, 0644))); 226 DOCALL(int, (open(path, flags, 0644)));
215} 227}
216 228
217int 229int
218rumpuser_ioctl(int fd, u_long cmd, void *data, int *error) 230rumpuser_ioctl(int fd, u_long cmd, void *data, int *error)
219{ 231{
220 232
221 DOCALL_KLOCK(int, (ioctl(fd, cmd, data))); 233 DOCALL_KLOCK(int, (ioctl(fd, cmd, data)));
222} 234}
223 235

cvs diff -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/if_shmem.c (expand / switch to unified diff)

--- src/sys/rump/net/lib/libshmif/if_shmem.c 2009/03/01 20:50:04 1.4
+++ src/sys/rump/net/lib/libshmif/if_shmem.c 2009/03/18 15:32:27 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_shmem.c,v 1.4 2009/03/01 20:50:04 pooka Exp $ */ 1/* $NetBSD: if_shmem.c,v 1.5 2009/03/18 15:32:27 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by The Nokia Foundation. 6 * Development of this software was supported by The Nokia Foundation.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.4 2009/03/01 20:50:04 pooka Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.5 2009/03/18 15:32:27 pooka Exp $");
32 32
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/fcntl.h> 34#include <sys/fcntl.h>
35#include <sys/kmem.h> 35#include <sys/kmem.h>
36#include <sys/kthread.h> 36#include <sys/kthread.h>
37#include <sys/lock.h> 37#include <sys/lock.h>
38#include <sys/atomic.h> 38#include <sys/atomic.h>
39 39
40#include <net/if.h> 40#include <net/if.h>
41#include <net/if_ether.h> 41#include <net/if_ether.h>
42 42
43#include <netinet/in.h> 43#include <netinet/in.h>
44#include <netinet/in_var.h> 44#include <netinet/in_var.h>
@@ -187,27 +187,28 @@ rump_shmif_create(const char *path, int  @@ -187,27 +187,28 @@ rump_shmif_create(const char *path, int
187 187
188 randnum = arc4random(); 188 randnum = arc4random();
189 memcpy(&enaddr[2], &randnum, 4); 189 memcpy(&enaddr[2], &randnum, 4);
190 mynum = atomic_inc_uint_nv(&numif)-1; 190 mynum = atomic_inc_uint_nv(&numif)-1;
191 191
192 sc = kmem_zalloc(sizeof(*sc), KM_SLEEP); 192 sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
193 ifp = &sc->sc_ec.ec_if; 193 ifp = &sc->sc_ec.ec_if;
194 memcpy(sc->sc_myaddr, enaddr, sizeof(enaddr)); 194 memcpy(sc->sc_myaddr, enaddr, sizeof(enaddr));
195 195
196 sc->sc_memfd = rumpuser_open(path, O_RDWR | O_CREAT, &error); 196 sc->sc_memfd = rumpuser_open(path, O_RDWR | O_CREAT, &error);
197 if (sc->sc_memfd == -1) 197 if (sc->sc_memfd == -1)
198 goto fail; 198 goto fail;
199 sc->sc_busmem = rumpuser_filemmap(sc->sc_memfd, 0, BUSMEM_SIZE, 199 sc->sc_busmem = rumpuser_filemmap(sc->sc_memfd, 0, BUSMEM_SIZE,
200 1, 1, &error); 200 RUMPUSER_FILEMMAP_TRUNCATE | RUMPUSER_FILEMMAP_SHARED
 201 | RUMPUSER_FILEMMAP_READ | RUMPUSER_FILEMMAP_WRITE, &error);
201 if (error) 202 if (error)
202 goto fail; 203 goto fail;
203 204
204 lockbus(sc); 205 lockbus(sc);
205 if (*BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET) == 0) 206 if (*BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET) == 0)
206 *BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET) = IFMEM_DATA; 207 *BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET) = IFMEM_DATA;
207 sc->sc_nextpacket = *BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET); 208 sc->sc_nextpacket = *BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET);
208 sc->sc_prevgen = *BUSCTRL_ATOFF(sc, IFMEM_GENERATION); 209 sc->sc_prevgen = *BUSCTRL_ATOFF(sc, IFMEM_GENERATION);
209 unlockbus(sc); 210 unlockbus(sc);
210 211
211 sc->sc_kq = rumpuser_writewatchfile_setup(-1, sc->sc_memfd, 0, &error); 212 sc->sc_kq = rumpuser_writewatchfile_setup(-1, sc->sc_memfd, 0, &error);
212 if (sc->sc_kq == -1) 213 if (sc->sc_kq == -1)
213 goto fail; 214 goto fail;