summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-09-04 11:47:49 -0600
committerAndreas Kling <kling@serenityos.org>2021-01-01 23:43:44 +0100
commite21cc4cff63c36917d83730871dfff1a9f0eb927 (patch)
tree3cadae41c5b4c66de98e9da32b79dbee3cc48c14 /Libraries
parentc3451899bcbdb1b268ff862ae37263d6ee99a423 (diff)
downloadserenity-e21cc4cff63c36917d83730871dfff1a9f0eb927.zip
Kernel: Remove MAP_PURGEABLE from mmap
This brings mmap more in line with other operating systems. Prior to this, it was impossible to request memory that was definitely committed, instead MAP_PURGEABLE would provide a region that was not actually purgeable, but also not fully committed, which meant that using such memory still could cause crashes when the underlying pages could no longer be allocated. This fixes some random crashes in low-memory situations where non-volatile memory is mapped (e.g. malloc, tls, Gfx::Bitmap, etc) but when a page in these regions is first accessed, there is insufficient physical memory available to commit a new page.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/malloc.cpp2
-rw-r--r--Libraries/LibC/mman.h2
-rw-r--r--Libraries/LibGfx/Bitmap.cpp10
3 files changed, 7 insertions, 7 deletions
diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp
index 37b748d044..49d1f598e3 100644
--- a/Libraries/LibC/malloc.cpp
+++ b/Libraries/LibC/malloc.cpp
@@ -154,7 +154,7 @@ extern "C" {
static void* os_alloc(size_t size, const char* name)
{
- auto* ptr = serenity_mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_PURGEABLE, 0, 0, ChunkedBlock::block_size, name);
+ auto* ptr = serenity_mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0, ChunkedBlock::block_size, name);
ASSERT(ptr != MAP_FAILED);
return ptr;
}
diff --git a/Libraries/LibC/mman.h b/Libraries/LibC/mman.h
index b783554365..5b02c59902 100644
--- a/Libraries/LibC/mman.h
+++ b/Libraries/LibC/mman.h
@@ -36,7 +36,7 @@
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
#define MAP_STACK 0x40
-#define MAP_PURGEABLE 0x80
+#define MAP_NORESERVE 0x80
#define PROT_READ 0x1
#define PROT_WRITE 0x2
diff --git a/Libraries/LibGfx/Bitmap.cpp b/Libraries/LibGfx/Bitmap.cpp
index f03851248b..5756451c3f 100644
--- a/Libraries/LibGfx/Bitmap.cpp
+++ b/Libraries/LibGfx/Bitmap.cpp
@@ -437,13 +437,13 @@ Optional<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, const
const auto pitch = minimum_pitch(size.width(), format);
const auto data_size_in_bytes = size_in_bytes(pitch, size.height());
- void* data = nullptr;
+ int map_flags = MAP_ANONYMOUS | MAP_PRIVATE;
+ if (purgeable == Purgeable::Yes)
+ map_flags |= MAP_NORESERVE;
#ifdef __serenity__
- int map_flags = purgeable == Purgeable::Yes ? (MAP_PURGEABLE | MAP_PRIVATE) : (MAP_ANONYMOUS | MAP_PRIVATE);
- data = mmap_with_name(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0, String::format("GraphicsBitmap [%dx%d]", size.width(), size.height()).characters());
+ void* data = mmap_with_name(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0, String::format("GraphicsBitmap [%dx%d]", size.width(), size.height()).characters());
#else
- int map_flags = (MAP_ANONYMOUS | MAP_PRIVATE);
- 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, 0, 0);
#endif
if (data == MAP_FAILED) {
perror("mmap");