Support the mmap() flag MAP_32BIT which asks for the allocated address
to be in the lower 32 bits. Some applications (like wrk and luajit)
use this flag and need it to work as expected.

By default, OSv mappings look for a hole starting at 0x200000000000.
With this patch and MAP_32BIT, we change that to 0x2000000.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
---
 libc/mman.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libc/mman.cc b/libc/mman.cc
index 0441265..73a3f41 100644
--- a/libc/mman.cc
+++ b/libc/mman.cc
@@ -130,6 +130,13 @@ void *mmap(void *addr, size_t length, int prot, int flags,
     auto mmap_flags = libc_flags_to_mmap(flags);
     auto mmap_perm  = libc_prot_to_perm(prot);
 
+    if ((flags & MAP_32BIT) && !(flags & MAP_FIXED) && !addr) {
+        // If addr is not specified, OSv by default starts mappings at address
+        // 0x200000000000ul (see mmu::allocate()).  MAP_32BIT asks for a lower
+        // default. If MAP_FIXED or addr were specified, the default does not
+        // matter anyway.
+        addr = (void*)0x2000000ul;
+    }
     if (flags & MAP_ANONYMOUS) {
         // We have already determined (see below) the region where the heap 
must be located. Now the JVM will request
         // fixed mappings inside that region
-- 
2.9.4

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to