From f39f262c76f5ab4624e14e69bf1ffacafc5cc803 Mon Sep 17 00:00:00 2001 From: Antti Kantee Date: Wed, 4 Sep 2013 22:51:36 +0300 Subject: [PATCH] Add some sort of emulation for mmap --- Makefile | 1 + emul.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libc_stubs.c | 2 -- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 emul.c diff --git a/Makefile b/Makefile index 3a8d665..b561940 100644 --- 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 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 +#include + +#include +#include +#include +#include + +#include /* 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; +} diff --git a/libc_stubs.c b/libc_stubs.c index 0e9fb9d..570e03c 100644 --- a/libc_stubs.c +++ b/libc_stubs.c @@ -27,8 +27,6 @@ STUB(__sigprocmask14); STUB(_exit); STUB(_lwp_kill); STUB(_lwp_self); -STUB(_mmap); -STUB(munmap); STUB(__wait450); STUB(__fork); -- 2.39.5