]> xenbits.xensource.com Git - rumpuser-xen.git/commitdiff
Add some sort of emulation for mmap
authorAntti Kantee <pooka@iki.fi>
Wed, 4 Sep 2013 19:51:36 +0000 (22:51 +0300)
committerAntti Kantee <pooka@iki.fi>
Wed, 4 Sep 2013 19:51:36 +0000 (22:51 +0300)
Makefile
emul.c [new file with mode: 0644]
libc_stubs.c

index 3a8d6656ca061047c0927a5ddd37b6a81fd1b89d..b56194045e6a1d748b150896fe4be107dce9a01e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -69,6 +69,7 @@ TARGET := rump-kernel
 SUBDIRS := lib xenbus console
 
 src-$(CONFIG_BLKFRONT) += blkfront.c
+src-y += emul.c
 src-y += events.c
 src-$(CONFIG_FBFRONT) += fbfront.c
 src-y += gntmap.c
diff --git a/emul.c b/emul.c
new file mode 100644 (file)
index 0000000..9063dd5
--- /dev/null
+++ b/emul.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2013 Antti Kantee.  See COPYING */
+
+/*
+ * Emulate a bit of mmap.  Currently just MAP_ANON
+ * and MAP_FILE+PROT_READ are supported.  For files, it's not true
+ * mmap, but should cover a good deal of the cases anyway.
+ */
+
+/* for libc namespace */
+#define mmap _mmap
+
+#include <sys/cdefs.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <mini-os/os.h> /* for PAGE_SIZE */
+
+void *
+mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)
+{
+       void *v;
+       ssize_t nn;
+       int error;
+
+       if ((fd != -1 && prot != PROT_READ) || addr != NULL) {
+               errno = ENOTSUP;
+               return MAP_FAILED;
+       }
+
+       if ((error = posix_memalign(&v, len, PAGE_SIZE)) != 0) {
+               errno = error;
+               return MAP_FAILED;
+       }
+
+       if (flags & MAP_ANON)
+               return v;
+
+       if ((nn = pread(fd, v, len, off)) == -1) {
+               error = errno;
+               free(v);
+               errno = error;
+               return MAP_FAILED;
+       }
+       return v;
+}
+#undef mmap
+__weak_alias(mmap,_mmap);
+
+int
+madvise(void *addr, size_t len, int adv)
+{
+
+       /* thanks for the advise, pal */
+       return 0;
+}
+
+int
+munmap(void *addr, size_t len)
+{
+
+       free(addr);
+       return 0;
+}
index 0e9fb9db970f3d3ea4fb0a140f0cc11b173ecb52..570e03c0e645d374cd75276383525dac4950d95c 100644 (file)
@@ -27,8 +27,6 @@ STUB(__sigprocmask14);
 STUB(_exit);
 STUB(_lwp_kill);
 STUB(_lwp_self);
-STUB(_mmap);
-STUB(munmap);
 STUB(__wait450);
 STUB(__fork);