From dd8777093d249bd8cff6c2d21c38b69258fa2ef7 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Thu, 20 Aug 2020 16:54:54 +0200 Subject: [PATCH] libc: don't treat 'mmap()' address hint w/o MAP_FIXED flag as error Fixes #3855 --- repos/libports/src/lib/libc/file_operations.cc | 10 ++++++++-- repos/libports/src/lib/libc/vfs_plugin.cc | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/repos/libports/src/lib/libc/file_operations.cc b/repos/libports/src/lib/libc/file_operations.cc index e892dab551..6e61039f91 100644 --- a/repos/libports/src/lib/libc/file_operations.cc +++ b/repos/libports/src/lib/libc/file_operations.cc @@ -413,9 +413,15 @@ __SYS_(void *, mmap, (void *addr, ::size_t length, int prot, int flags, int libc_fd, ::off_t offset), { - /* handle requests for anonymous memory */ - if (!addr && libc_fd == -1) { + if ((flags & MAP_ANONYMOUS) || (flags & MAP_ANON)) { + + if (flags & MAP_FIXED) { + Genode::error("mmap for fixed predefined address not supported yet"); + errno = EINVAL; + return MAP_FAILED; + } + bool const executable = prot & PROT_EXEC; void *start = mem_alloc(executable)->alloc(length, PAGE_SHIFT); if (!start) { diff --git a/repos/libports/src/lib/libc/vfs_plugin.cc b/repos/libports/src/lib/libc/vfs_plugin.cc index 02d193efbb..fef94b38bb 100644 --- a/repos/libports/src/lib/libc/vfs_plugin.cc +++ b/repos/libports/src/lib/libc/vfs_plugin.cc @@ -1640,8 +1640,8 @@ void *Libc::Vfs_plugin::mmap(void *addr_in, ::size_t length, int prot, int flags return (void *)-1; } - if (addr_in != 0) { - error("mmap for predefined address not supported"); + if (flags & MAP_FIXED) { + error("mmap for fixed predefined address not supported yet"); errno = EINVAL; return (void *)-1; }