Kernel: Switch static_asserts of a type size to AK::AssertSize

This will provide better debug ability when the size comparison fails.
This commit is contained in:
Brian Gianforcaro 2021-09-05 00:57:53 -07:00 committed by Andreas Kling
parent 112de58fe0
commit 472454cded
Notes: sideshowbarker 2024-07-18 04:40:22 +09:00
15 changed files with 25 additions and 19 deletions

View file

@ -7,6 +7,7 @@
#pragma once #pragma once
#include <AK/StdLibExtras.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/VirtualAddress.h> #include <Kernel/VirtualAddress.h>
@ -100,7 +101,7 @@ union [[gnu::packed]] Descriptor {
} }
}; };
static_assert(sizeof(Descriptor) == 8); static_assert(AssertSize<Descriptor, 8>());
enum class IDTEntryType { enum class IDTEntryType {
TaskGate32 = 0b0101, TaskGate32 = 0b0101,
@ -174,6 +175,6 @@ struct [[gnu::packed]] IDTEntry
}; };
// clang-format on // clang-format on
static_assert(sizeof(IDTEntry) == 2 * sizeof(void*)); static_assert(AssertSize<IDTEntry, 2 * sizeof(void*)>());
} }

View file

@ -132,8 +132,8 @@ private:
u64 m_raw; u64 m_raw;
}; };
static_assert(sizeof(PageDirectoryEntry) == 8); static_assert(AssertSize<PageDirectoryEntry, 8>());
static_assert(sizeof(PageTableEntry) == 8); static_assert(AssertSize<PageTableEntry, 8>());
class PageDirectoryPointerTable { class PageDirectoryPointerTable {
public: public:

View file

@ -121,7 +121,7 @@ struct [[gnu::packed]] RegisterState {
#else #else
# define REGISTER_STATE_SIZE (22 * 8) # define REGISTER_STATE_SIZE (22 * 8)
#endif #endif
static_assert(REGISTER_STATE_SIZE == sizeof(RegisterState)); static_assert(AssertSize<RegisterState, REGISTER_STATE_SIZE>());
inline void copy_kernel_registers_into_ptrace_registers(PtraceRegisters& ptrace_regs, const RegisterState& kernel_regs) inline void copy_kernel_registers_into_ptrace_registers(PtraceRegisters& ptrace_regs, const RegisterState& kernel_regs)
{ {

View file

@ -32,7 +32,7 @@ struct TrapFrame {
# define TRAP_FRAME_SIZE (3 * 8) # define TRAP_FRAME_SIZE (3 * 8)
#endif #endif
static_assert(TRAP_FRAME_SIZE == sizeof(TrapFrame)); static_assert(AssertSize<TrapFrame, TRAP_FRAME_SIZE>());
extern "C" void enter_trap_no_irq(TrapFrame* trap) __attribute__((used)); extern "C" void enter_trap_no_irq(TrapFrame* trap) __attribute__((used));
extern "C" void enter_trap(TrapFrame*) __attribute__((used)); extern "C" void enter_trap(TrapFrame*) __attribute__((used));

View file

@ -244,7 +244,7 @@ private:
bool m_in_use; // Has this TD been allocated (and therefore in use)? bool m_in_use; // Has this TD been allocated (and therefore in use)?
}; };
static_assert(sizeof(TransferDescriptor) == 32); // Transfer Descriptor is always 8 Dwords static_assert(AssertSize<TransferDescriptor, 32>()); // Transfer Descriptor is always 8 Dwords
// //
// Queue Head // Queue Head
@ -361,5 +361,5 @@ private:
bool m_in_use { false }; // Is this QH currently in use? bool m_in_use { false }; // Is this QH currently in use?
}; };
static_assert(sizeof(QueueHead) == 32); // Queue Head is always 8 Dwords static_assert(AssertSize<QueueHead, 32>()); // Queue Head is always 8 Dwords
} }

View file

@ -53,7 +53,7 @@ struct [[gnu::packed]] HubStatus {
u16 status { 0 }; u16 status { 0 };
u16 change { 0 }; u16 change { 0 };
}; };
static_assert(sizeof(HubStatus) == 4); static_assert(AssertSize<HubStatus, 4>());
static constexpr u16 HUB_STATUS_LOCAL_POWER_SOURCE = (1 << 0); static constexpr u16 HUB_STATUS_LOCAL_POWER_SOURCE = (1 << 0);
static constexpr u16 HUB_STATUS_OVER_CURRENT = (1 << 1); static constexpr u16 HUB_STATUS_OVER_CURRENT = (1 << 1);

View file

@ -80,6 +80,6 @@ struct [[gnu::packed]] VideoInfoBlock {
u8 checksum; u8 checksum;
}; };
static_assert(sizeof(VideoInfoBlock) == 128); static_assert(AssertSize<VideoInfoBlock, 128>());
} }

View file

@ -102,7 +102,7 @@ private:
void* m_base { nullptr }; void* m_base { nullptr };
void* m_end { nullptr }; void* m_end { nullptr };
static_assert(sizeof(FreeSlab) == templated_slab_size); static_assert(AssertSize<FreeSlab, templated_slab_size>());
}; };
static SlabAllocator<16> s_slab_allocator_16; static SlabAllocator<16> s_slab_allocator_16;

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/StdLibExtras.h>
#if LOCK_DEBUG #if LOCK_DEBUG
# include <AK/SourceLocation.h> # include <AK/SourceLocation.h>
#endif #endif
@ -25,6 +26,9 @@ using LockLocation = SourceLocation;
#else #else
struct LockLocation { struct LockLocation {
static constexpr LockLocation current() { return {}; } static constexpr LockLocation current() { return {}; }
private:
constexpr LockLocation() = default;
}; };
#endif #endif

View file

@ -40,7 +40,7 @@ private:
// NOTE: The rest of the header is 4 bytes // NOTE: The rest of the header is 4 bytes
}; };
static_assert(sizeof(ICMPHeader) == 4); static_assert(AssertSize<ICMPHeader, 4>());
struct [[gnu::packed]] ICMPEchoPacket { struct [[gnu::packed]] ICMPEchoPacket {
ICMPHeader header; ICMPHeader header;

View file

@ -102,7 +102,7 @@ private:
IPv4Address m_destination; IPv4Address m_destination;
}; };
static_assert(sizeof(IPv4Packet) == 20); static_assert(AssertSize<IPv4Packet, 20>());
inline NetworkOrdered<u16> internet_checksum(const void* ptr, size_t count) inline NetworkOrdered<u16> internet_checksum(const void* ptr, size_t count)
{ {

View file

@ -59,7 +59,7 @@ private:
static constexpr u16 LargeSend = 0x800u; static constexpr u16 LargeSend = 0x800u;
}; };
static_assert(sizeof(TXDescriptor) == 16u); static_assert(AssertSize<TXDescriptor, 16u>());
struct [[gnu::packed]] RXDescriptor { struct [[gnu::packed]] RXDescriptor {
volatile u16 buffer_size; // top 2 bits are reserved volatile u16 buffer_size; // top 2 bits are reserved
@ -83,7 +83,7 @@ private:
static constexpr u16 CRCError = 0x8; static constexpr u16 CRCError = 0x8;
}; };
static_assert(sizeof(RXDescriptor) == 16u); static_assert(AssertSize<RXDescriptor, 16u>());
enum class ChipVersion : u8 { enum class ChipVersion : u8 {
Unknown = 0, Unknown = 0,

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/StdLibExtras.h>
#include <Kernel/Net/IPv4.h> #include <Kernel/Net/IPv4.h>
namespace Kernel { namespace Kernel {
@ -36,7 +37,7 @@ private:
NetworkOrdered<u16> m_value; NetworkOrdered<u16> m_value;
}; };
static_assert(sizeof(TCPOptionMSS) == 4); static_assert(AssertSize<TCPOptionMSS, 4>());
class [[gnu::packed]] TCPPacket { class [[gnu::packed]] TCPPacket {
public: public:
@ -92,6 +93,6 @@ private:
NetworkOrdered<u16> m_urgent; NetworkOrdered<u16> m_urgent;
}; };
static_assert(sizeof(TCPPacket) == 20); static_assert(AssertSize<TCPPacket, 20>());
} }

View file

@ -813,7 +813,7 @@ public:
// It's not expected that the Process object will expand further because the first // It's not expected that the Process object will expand further because the first
// page is used for all unprotected values (which should be plenty of space for them). // page is used for all unprotected values (which should be plenty of space for them).
// The second page is being used exclusively for write-protected values. // The second page is being used exclusively for write-protected values.
static_assert(sizeof(Process) == (PAGE_SIZE * 2)); static_assert(AssertSize<Process, (PAGE_SIZE * 2)>());
extern RecursiveSpinlock g_profiling_lock; extern RecursiveSpinlock g_profiling_lock;

View file

@ -83,7 +83,7 @@ static_assert(__builtin_offsetof(HPETRegistersBlock, timers[1]) == 0x120);
// Note: The HPET specification says it reserves the range of byte 0x160 to // Note: The HPET specification says it reserves the range of byte 0x160 to
// 0x400 for comparators 3-31, but for implementing all 32 comparators the HPET // 0x400 for comparators 3-31, but for implementing all 32 comparators the HPET
// MMIO space has to be 1280 bytes and not 1024 bytes. // MMIO space has to be 1280 bytes and not 1024 bytes.
static_assert(sizeof(HPETRegistersBlock) == 0x500); static_assert(AssertSize<HPETRegistersBlock, 0x500>());
static u64 read_register_safe64(const HPETRegister& reg) static u64 read_register_safe64(const HPETRegister& reg)
{ {