diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-09-05 00:57:53 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-05 20:08:57 +0200 |
commit | 472454cdeda1ab87e879670f44993960013973ff (patch) | |
tree | ad8c5c51d9ce3fcab18579f573aa35dd8c2a22a2 | |
parent | 112de58fe0601ef95544ab474f35ade14f947391 (diff) | |
download | serenity-472454cdeda1ab87e879670f44993960013973ff.zip |
Kernel: Switch static_asserts of a type size to AK::AssertSize
This will provide better debug ability when the size comparison fails.
-rw-r--r-- | Kernel/Arch/x86/DescriptorTable.h | 5 | ||||
-rw-r--r-- | Kernel/Arch/x86/PageDirectory.h | 4 | ||||
-rw-r--r-- | Kernel/Arch/x86/RegisterState.h | 2 | ||||
-rw-r--r-- | Kernel/Arch/x86/TrapFrame.h | 2 | ||||
-rw-r--r-- | Kernel/Bus/USB/UHCI/UHCIDescriptorTypes.h | 4 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBHub.h | 2 | ||||
-rw-r--r-- | Kernel/Graphics/Definitions.h | 2 | ||||
-rw-r--r-- | Kernel/Heap/SlabAllocator.cpp | 2 | ||||
-rw-r--r-- | Kernel/Locking/LockLocation.h | 4 | ||||
-rw-r--r-- | Kernel/Net/ICMP.h | 2 | ||||
-rw-r--r-- | Kernel/Net/IPv4.h | 2 | ||||
-rw-r--r-- | Kernel/Net/RTL8168NetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/TCP.h | 5 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Time/HPET.cpp | 2 |
15 files changed, 25 insertions, 19 deletions
diff --git a/Kernel/Arch/x86/DescriptorTable.h b/Kernel/Arch/x86/DescriptorTable.h index 907dd5f998..7068ed6f3e 100644 --- a/Kernel/Arch/x86/DescriptorTable.h +++ b/Kernel/Arch/x86/DescriptorTable.h @@ -7,6 +7,7 @@ #pragma once +#include <AK/StdLibExtras.h> #include <AK/Types.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 { TaskGate32 = 0b0101, @@ -174,6 +175,6 @@ struct [[gnu::packed]] IDTEntry }; // clang-format on -static_assert(sizeof(IDTEntry) == 2 * sizeof(void*)); +static_assert(AssertSize<IDTEntry, 2 * sizeof(void*)>()); } diff --git a/Kernel/Arch/x86/PageDirectory.h b/Kernel/Arch/x86/PageDirectory.h index f965e600b2..2a349644b4 100644 --- a/Kernel/Arch/x86/PageDirectory.h +++ b/Kernel/Arch/x86/PageDirectory.h @@ -132,8 +132,8 @@ private: u64 m_raw; }; -static_assert(sizeof(PageDirectoryEntry) == 8); -static_assert(sizeof(PageTableEntry) == 8); +static_assert(AssertSize<PageDirectoryEntry, 8>()); +static_assert(AssertSize<PageTableEntry, 8>()); class PageDirectoryPointerTable { public: diff --git a/Kernel/Arch/x86/RegisterState.h b/Kernel/Arch/x86/RegisterState.h index cefd54209b..ceb7f3ec73 100644 --- a/Kernel/Arch/x86/RegisterState.h +++ b/Kernel/Arch/x86/RegisterState.h @@ -121,7 +121,7 @@ struct [[gnu::packed]] RegisterState { #else # define REGISTER_STATE_SIZE (22 * 8) #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) { diff --git a/Kernel/Arch/x86/TrapFrame.h b/Kernel/Arch/x86/TrapFrame.h index 4a6b1e6143..41c39b1173 100644 --- a/Kernel/Arch/x86/TrapFrame.h +++ b/Kernel/Arch/x86/TrapFrame.h @@ -32,7 +32,7 @@ struct TrapFrame { # define TRAP_FRAME_SIZE (3 * 8) #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(TrapFrame*) __attribute__((used)); diff --git a/Kernel/Bus/USB/UHCI/UHCIDescriptorTypes.h b/Kernel/Bus/USB/UHCI/UHCIDescriptorTypes.h index 9ddc31ad21..3f95302b11 100644 --- a/Kernel/Bus/USB/UHCI/UHCIDescriptorTypes.h +++ b/Kernel/Bus/USB/UHCI/UHCIDescriptorTypes.h @@ -244,7 +244,7 @@ private: 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 @@ -361,5 +361,5 @@ private: 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 } diff --git a/Kernel/Bus/USB/USBHub.h b/Kernel/Bus/USB/USBHub.h index 80ea4f6ba9..3ae22489cb 100644 --- a/Kernel/Bus/USB/USBHub.h +++ b/Kernel/Bus/USB/USBHub.h @@ -53,7 +53,7 @@ struct [[gnu::packed]] HubStatus { u16 status { 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_OVER_CURRENT = (1 << 1); diff --git a/Kernel/Graphics/Definitions.h b/Kernel/Graphics/Definitions.h index a96e051b13..49885a574f 100644 --- a/Kernel/Graphics/Definitions.h +++ b/Kernel/Graphics/Definitions.h @@ -80,6 +80,6 @@ struct [[gnu::packed]] VideoInfoBlock { u8 checksum; }; -static_assert(sizeof(VideoInfoBlock) == 128); +static_assert(AssertSize<VideoInfoBlock, 128>()); } diff --git a/Kernel/Heap/SlabAllocator.cpp b/Kernel/Heap/SlabAllocator.cpp index c20f676bad..9a74e8c17c 100644 --- a/Kernel/Heap/SlabAllocator.cpp +++ b/Kernel/Heap/SlabAllocator.cpp @@ -102,7 +102,7 @@ private: void* m_base { 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; diff --git a/Kernel/Locking/LockLocation.h b/Kernel/Locking/LockLocation.h index a0fcf7d9a1..ea040576f8 100644 --- a/Kernel/Locking/LockLocation.h +++ b/Kernel/Locking/LockLocation.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/StdLibExtras.h> #if LOCK_DEBUG # include <AK/SourceLocation.h> #endif @@ -25,6 +26,9 @@ using LockLocation = SourceLocation; #else struct LockLocation { static constexpr LockLocation current() { return {}; } + +private: + constexpr LockLocation() = default; }; #endif diff --git a/Kernel/Net/ICMP.h b/Kernel/Net/ICMP.h index 82c8df3dde..0b0e807ce8 100644 --- a/Kernel/Net/ICMP.h +++ b/Kernel/Net/ICMP.h @@ -40,7 +40,7 @@ private: // NOTE: The rest of the header is 4 bytes }; -static_assert(sizeof(ICMPHeader) == 4); +static_assert(AssertSize<ICMPHeader, 4>()); struct [[gnu::packed]] ICMPEchoPacket { ICMPHeader header; diff --git a/Kernel/Net/IPv4.h b/Kernel/Net/IPv4.h index cf9da889ae..704ef1754f 100644 --- a/Kernel/Net/IPv4.h +++ b/Kernel/Net/IPv4.h @@ -102,7 +102,7 @@ private: IPv4Address m_destination; }; -static_assert(sizeof(IPv4Packet) == 20); +static_assert(AssertSize<IPv4Packet, 20>()); inline NetworkOrdered<u16> internet_checksum(const void* ptr, size_t count) { diff --git a/Kernel/Net/RTL8168NetworkAdapter.h b/Kernel/Net/RTL8168NetworkAdapter.h index 713ca32503..c893270cb6 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.h +++ b/Kernel/Net/RTL8168NetworkAdapter.h @@ -59,7 +59,7 @@ private: static constexpr u16 LargeSend = 0x800u; }; - static_assert(sizeof(TXDescriptor) == 16u); + static_assert(AssertSize<TXDescriptor, 16u>()); struct [[gnu::packed]] RXDescriptor { volatile u16 buffer_size; // top 2 bits are reserved @@ -83,7 +83,7 @@ private: static constexpr u16 CRCError = 0x8; }; - static_assert(sizeof(RXDescriptor) == 16u); + static_assert(AssertSize<RXDescriptor, 16u>()); enum class ChipVersion : u8 { Unknown = 0, diff --git a/Kernel/Net/TCP.h b/Kernel/Net/TCP.h index d3a85d8f8c..243e19ecca 100644 --- a/Kernel/Net/TCP.h +++ b/Kernel/Net/TCP.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/StdLibExtras.h> #include <Kernel/Net/IPv4.h> namespace Kernel { @@ -36,7 +37,7 @@ private: NetworkOrdered<u16> m_value; }; -static_assert(sizeof(TCPOptionMSS) == 4); +static_assert(AssertSize<TCPOptionMSS, 4>()); class [[gnu::packed]] TCPPacket { public: @@ -92,6 +93,6 @@ private: NetworkOrdered<u16> m_urgent; }; -static_assert(sizeof(TCPPacket) == 20); +static_assert(AssertSize<TCPPacket, 20>()); } diff --git a/Kernel/Process.h b/Kernel/Process.h index 6eda1f0d1a..a556cc0ec8 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -813,7 +813,7 @@ public: // 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). // 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; diff --git a/Kernel/Time/HPET.cpp b/Kernel/Time/HPET.cpp index 7e07731850..ee6d8e75cd 100644 --- a/Kernel/Time/HPET.cpp +++ b/Kernel/Time/HPET.cpp @@ -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 // 0x400 for comparators 3-31, but for implementing all 32 comparators the HPET // 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) { |