瀏覽代碼

AK+LibGfx+LibJS: Pass -1 as the file descriptor to anonymous mmap

Serenity/Linux/macOS ignore the file descriptor when an anonymous
mapping is requested. However, BSDs require the fd to be -1.
Daniel Bertalan 3 年之前
父節點
當前提交
42e22f89a4
共有 3 個文件被更改,包括 3 次插入3 次删除
  1. 1 1
      AK/BumpAllocator.h
  2. 1 1
      Userland/Libraries/LibGfx/Bitmap.cpp
  3. 1 1
      Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp

+ 1 - 1
AK/BumpAllocator.h

@@ -106,7 +106,7 @@ protected:
 #ifdef __serenity__
 #ifdef __serenity__
                 new_chunk = serenity_mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_RANDOMIZED | MAP_PRIVATE, 0, 0, m_chunk_size, "BumpAllocator Chunk");
                 new_chunk = serenity_mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_RANDOMIZED | MAP_PRIVATE, 0, 0, m_chunk_size, "BumpAllocator Chunk");
 #else
 #else
-                new_chunk = mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
+                new_chunk = mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 #endif
 #endif
                 if (new_chunk == MAP_FAILED)
                 if (new_chunk == MAP_FAILED)
                     return false;
                     return false;

+ 1 - 1
Userland/Libraries/LibGfx/Bitmap.cpp

@@ -558,7 +558,7 @@ ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSiz
     map_flags |= MAP_PURGEABLE;
     map_flags |= MAP_PURGEABLE;
     void* data = mmap_with_name(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0, String::formatted("GraphicsBitmap [{}]", size).characters());
     void* data = mmap_with_name(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0, String::formatted("GraphicsBitmap [{}]", size).characters());
 #else
 #else
-    void* data = mmap(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0);
+    void* data = mmap(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, -1, 0);
 #endif
 #endif
     if (data == MAP_FAILED)
     if (data == MAP_FAILED)
         return Error::from_errno(errno);
         return Error::from_errno(errno);

+ 1 - 1
Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp

@@ -23,7 +23,7 @@ BasicBlock::BasicBlock(String name, size_t size)
     // The main issue we're working around here is that we don't want pointers into the bytecode stream to become invalidated
     // The main issue we're working around here is that we don't want pointers into the bytecode stream to become invalidated
     // during code generation due to dynamic buffer resizing. Otherwise we could just use a Vector.
     // during code generation due to dynamic buffer resizing. Otherwise we could just use a Vector.
     m_buffer_capacity = size;
     m_buffer_capacity = size;
-    m_buffer = (u8*)mmap(nullptr, m_buffer_capacity, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
+    m_buffer = (u8*)mmap(nullptr, m_buffer_capacity, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
     VERIFY(m_buffer != MAP_FAILED);
     VERIFY(m_buffer != MAP_FAILED);
 }
 }