1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibGfx: Make Gfx::Bitmap::set_nonvolatile() report allocation failure

Making a bitmap non-volatile after being volatile may fail to allocate
physical pages after the kernel stole the old pages in a purge.

This is different from the pages being purged, but reallocated. In that
case, they are simply replaced with zero-fill-on-demand pages as if
they were freshly allocated.
This commit is contained in:
Andreas Kling 2021-07-24 22:49:48 +02:00
parent 24b5295b30
commit 143443e0b6
Notes: sideshowbarker 2024-07-18 08:22:11 +09:00
23 changed files with 57 additions and 46 deletions

View file

@ -22,7 +22,7 @@
#include <LibGfx/PNGLoader.h>
#include <LibGfx/PPMLoader.h>
#include <LibGfx/ShareableBitmap.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <sys/mman.h>
@ -533,21 +533,27 @@ void Bitmap::set_volatile()
m_volatile = true;
}
[[nodiscard]] bool Bitmap::set_nonvolatile()
[[nodiscard]] bool Bitmap::set_nonvolatile(bool& was_purged)
{
if (!m_volatile)
if (!m_volatile) {
was_purged = false;
return true;
}
#ifdef __serenity__
int rc = madvise(m_data, size_in_bytes(), MADV_SET_NONVOLATILE);
if (rc < 0) {
if (errno == ENOMEM) {
was_purged = was_purged_int;
return false;
}
perror("madvise(MADV_SET_NONVOLATILE)");
VERIFY_NOT_REACHED();
}
#else
int rc = 0;
was_purged = rc != 0;
#endif
m_volatile = false;
return rc == 0;
return true;
}
ShareableBitmap Bitmap::to_shareable_bitmap() const
@ -600,5 +606,4 @@ Vector<RGBA32> Bitmap::palette_to_vector() const
vector.unchecked_append(palette_color(i).value());
return vector;
}
}