* allow to specify PROT_READ/PROT_WRITE when mmapping a file
* add msync
This commit is contained in:
parent
35fb64746b
commit
f09f82998f
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rumpuser.h,v 1.19 2009/02/28 15:49:12 pooka Exp $ */
|
||||
/* $NetBSD: rumpuser.h,v 1.20 2009/03/18 15:32:27 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
@ -54,8 +54,13 @@ void *rumpuser__realloc(void *, size_t, int, const char *, int);
|
||||
void rumpuser_free(void *);
|
||||
|
||||
void *rumpuser_anonmmap(size_t, int, int, int *);
|
||||
void *rumpuser_filemmap(int fd, off_t, size_t, int, int, int *);
|
||||
#define RUMPUSER_FILEMMAP_READ 0x01
|
||||
#define RUMPUSER_FILEMMAP_WRITE 0x02
|
||||
#define RUMPUSER_FILEMMAP_TRUNCATE 0x04
|
||||
#define RUMPUSER_FILEMMAP_SHARED 0x08
|
||||
void *rumpuser_filemmap(int fd, off_t, size_t, int, int *);
|
||||
void rumpuser_unmap(void *, size_t);
|
||||
int rumpuser_memsync(void *, size_t, int *);
|
||||
|
||||
int rumpuser_open(const char *, int, int *);
|
||||
int rumpuser_ioctl(int, u_long, void *, int *);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rumpuser.c,v 1.36 2009/03/18 10:22:45 cegger Exp $ */
|
||||
/* $NetBSD: rumpuser.c,v 1.37 2009/03/18 15:32:27 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint)
|
||||
__RCSID("$NetBSD: rumpuser.c,v 1.36 2009/03/18 10:22:45 cegger Exp $");
|
||||
__RCSID("$NetBSD: rumpuser.c,v 1.37 2009/03/18 15:32:27 pooka Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
/* thank the maker for this */
|
||||
@ -182,22 +182,27 @@ rumpuser_unmap(void *addr, size_t len)
|
||||
}
|
||||
|
||||
void *
|
||||
rumpuser_filemmap(int fd, off_t offset, size_t len, int shared,
|
||||
int dotruncate, int *error)
|
||||
rumpuser_filemmap(int fd, off_t offset, size_t len, int flags, int *error)
|
||||
{
|
||||
void *rv;
|
||||
int flags;
|
||||
int mmflags, prot;
|
||||
|
||||
if (dotruncate)
|
||||
if (flags & RUMPUSER_FILEMMAP_TRUNCATE)
|
||||
ftruncate(fd, offset + len);
|
||||
|
||||
flags = MAP_FILE;
|
||||
if (shared)
|
||||
flags |= MAP_SHARED;
|
||||
mmflags = MAP_FILE;
|
||||
if (flags & RUMPUSER_FILEMMAP_SHARED)
|
||||
mmflags |= MAP_SHARED;
|
||||
else
|
||||
flags |= MAP_PRIVATE;
|
||||
mmflags |= MAP_PRIVATE;
|
||||
|
||||
rv = mmap(NULL, len, PROT_READ|PROT_WRITE, flags, fd, offset);
|
||||
prot = 0;
|
||||
if (flags & RUMPUSER_FILEMMAP_READ)
|
||||
prot |= PROT_READ;
|
||||
if (flags & RUMPUSER_FILEMMAP_WRITE)
|
||||
prot |= PROT_WRITE;
|
||||
|
||||
rv = mmap(NULL, len, PROT_READ|PROT_WRITE, mmflags, fd, offset);
|
||||
if (rv == MAP_FAILED) {
|
||||
*error = errno;
|
||||
return NULL;
|
||||
@ -207,6 +212,13 @@ rumpuser_filemmap(int fd, off_t offset, size_t len, int shared,
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
rumpuser_memsync(void *addr, size_t len, int *error)
|
||||
{
|
||||
|
||||
DOCALL_KLOCK(int, (msync(addr, len, MS_SYNC)));
|
||||
}
|
||||
|
||||
int
|
||||
rumpuser_open(const char *path, int flags, int *error)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_shmem.c,v 1.4 2009/03/01 20:50:04 pooka Exp $ */
|
||||
/* $NetBSD: if_shmem.c,v 1.5 2009/03/18 15:32:27 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.4 2009/03/01 20:50:04 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.5 2009/03/18 15:32:27 pooka Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/fcntl.h>
|
||||
@ -197,7 +197,8 @@ rump_shmif_create(const char *path, int *ifnum)
|
||||
if (sc->sc_memfd == -1)
|
||||
goto fail;
|
||||
sc->sc_busmem = rumpuser_filemmap(sc->sc_memfd, 0, BUSMEM_SIZE,
|
||||
1, 1, &error);
|
||||
RUMPUSER_FILEMMAP_TRUNCATE | RUMPUSER_FILEMMAP_SHARED
|
||||
| RUMPUSER_FILEMMAP_READ | RUMPUSER_FILEMMAP_WRITE, &error);
|
||||
if (error)
|
||||
goto fail;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user