mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +00:00
AK: Fix Bitmap not finding unset ranges at the end of the map
When we switched the Bitmap code to operating 32 bits at a time, we neglected to look in the trailing remainder bits after the last full 32-bit word. This patch fixes that and adds a couple of tests for Bitmap that I hacked up while tracking down this bug. I found this bug when noticing that the kernel would OOM while there were still some pages left in the physical page allocator.
This commit is contained in:
parent
8182a709e3
commit
bf7b77e252
2 changed files with 152 additions and 1 deletions
14
AK/Bitmap.h
14
AK/Bitmap.h
|
@ -243,6 +243,18 @@ public:
|
|||
}
|
||||
|
||||
if (free_chunks < min_length) {
|
||||
size_t first_trailing_bit = (m_size / 32) * 32;
|
||||
size_t trailing_bits = size() % 32;
|
||||
for (size_t i = 0; i < trailing_bits; ++i) {
|
||||
if (!get(first_trailing_bit + i)) {
|
||||
if (!free_chunks)
|
||||
*start_of_free_chunks = first_trailing_bit + i;
|
||||
if (++free_chunks >= min_length)
|
||||
return min(free_chunks, max_length);
|
||||
} else {
|
||||
free_chunks = 0;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -340,7 +352,7 @@ public:
|
|||
static constexpr u32 max_size = 0xffffffff;
|
||||
|
||||
private:
|
||||
size_t size_in_bytes() const { return ceil_div(m_size, 8); }
|
||||
size_t size_in_bytes() const { return ceil_div(m_size, static_cast<size_t>(8)); }
|
||||
|
||||
u8* m_data { nullptr };
|
||||
size_t m_size { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue