From ca34ece8ef42660f2a2259111f3295d4b8541e20 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 2 Nov 2023 00:01:12 +0200 Subject: [PATCH] BAN: Update ASSERT api its now much harder to mix < with <= and > with >= --- BAN/include/BAN/Assert.h | 12 ++++++------ kernel/arch/x86_64/PageTable.cpp | 6 +++--- kernel/kernel/Memory/VirtualRange.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/BAN/include/BAN/Assert.h b/BAN/include/BAN/Assert.h index 9e9de1b399..139d33e828 100644 --- a/BAN/include/BAN/Assert.h +++ b/BAN/include/BAN/Assert.h @@ -19,12 +19,12 @@ Kernel::panic(name "(" #lhs ", " #rhs ") ({} " #op " {}) failed", _lhs, _rhs); \ } while (false) - #define ASSERT_LT(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_LT", <) - #define ASSERT_LE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_LE", <=) - #define ASSERT_GT(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_GT", >) - #define ASSERT_GE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_GE", >=) - #define ASSERT_EQ(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_EQ", ==) - #define ASSERT_NE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_NE", !=) + #define ASSERT_LT(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_LT", <) + #define ASSERT_LTE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_LTE", <=) + #define ASSERT_GT(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_GT", >) + #define ASSERT_GTE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_GTE", >=) + #define ASSERT_EQ(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_EQ", ==) + #define ASSERT_NEQ(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_NEQ", !=) #define ASSERT_NOT_REACHED() Kernel::panic("ASSERT_NOT_REACHED() failed") #else #include diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index d3c5357024..2abd768a25 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -215,7 +215,7 @@ namespace Kernel void PageTable::map_fast_page(paddr_t paddr) { ASSERT(s_kernel); - ASSERT_GE(paddr, 0); + ASSERT_NEQ(paddr, 0); ASSERT(!interrupts_enabled()); constexpr vaddr_t uc_vaddr = uncanonicalize(fast_page()); @@ -326,7 +326,7 @@ namespace Kernel ASSERT(vaddr); ASSERT(vaddr != fast_page()); if (vaddr >= KERNEL_OFFSET) - ASSERT_GE(vaddr, (vaddr_t)g_kernel_start); + ASSERT_GTE(vaddr, (vaddr_t)g_kernel_start); if ((vaddr >= KERNEL_OFFSET) != (this == s_kernel)) Kernel::panic("unmapping {8H}, kernel: {}", vaddr, this == s_kernel); @@ -372,7 +372,7 @@ namespace Kernel ASSERT(vaddr); ASSERT(vaddr != fast_page()); if (vaddr >= KERNEL_OFFSET) - ASSERT_GE(vaddr, (vaddr_t)g_kernel_start); + ASSERT_GTE(vaddr, (vaddr_t)g_kernel_start); if ((vaddr >= KERNEL_OFFSET) != (this == s_kernel)) Kernel::panic("mapping {8H} to {8H}, kernel: {}", paddr, vaddr, this == s_kernel); diff --git a/kernel/kernel/Memory/VirtualRange.cpp b/kernel/kernel/Memory/VirtualRange.cpp index 69bcdb6981..0d9031de18 100644 --- a/kernel/kernel/Memory/VirtualRange.cpp +++ b/kernel/kernel/Memory/VirtualRange.cpp @@ -189,9 +189,9 @@ namespace Kernel return; // Verify no overflow - ASSERT_LE(bytes, size()); - ASSERT_LE(offset, size()); - ASSERT_LE(offset, size() - bytes); + ASSERT_LTE(bytes, size()); + ASSERT_LTE(offset, size()); + ASSERT_LTE(offset, size() - bytes); if (m_kmalloc || &PageTable::current() == &m_page_table) {