1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

Kernel: Assert if rounding-up-to-page-size would wrap around to 0

If we try to align a number above 0xfffff000 to the next multiple of
the page size (4 KiB), it would wrap around to 0. This is most likely
never what we want, so let's assert if that happens.
This commit is contained in:
Andreas Kling 2021-02-14 09:57:19 +01:00
parent 198d641808
commit 09b1b09c19
19 changed files with 67 additions and 40 deletions

View file

@ -39,8 +39,23 @@
namespace Kernel {
#define PAGE_ROUND_UP(x) ((((FlatPtr)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
#define PAGE_ROUND_DOWN(x) (((FlatPtr)(x)) & ~(PAGE_SIZE - 1))
constexpr bool page_round_up_would_wrap(FlatPtr x)
{
return x > 0xfffff000u;
}
constexpr FlatPtr page_round_up(FlatPtr x)
{
FlatPtr rounded = (((FlatPtr)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1));
// Rounding up >0xffff0000 wraps back to 0. That's never what we want.
ASSERT(x == 0 || rounded != 0);
return rounded;
}
constexpr FlatPtr page_round_down(FlatPtr x)
{
return ((FlatPtr)(x)) & ~(PAGE_SIZE - 1);
}
inline u32 low_physical_to_virtual(u32 physical)
{