mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
Everywhere: Fix some alignment issues
When creating uninitialized storage for variables, we need to make sure that the alignment is correct. Fixes a KUBSAN failure when running kernels compiled with Clang. In `Syscalls/socket.cpp`, we can simply use local variables, as `sockaddr_un` is a POD type. Along with moving the `alignas` specifier to the correct member, `AK::Optional`'s internal buffer has been made non-zeroed by default. GCC emitted bogus uninitialized memory access warnings, so we now use `__builtin_launder` to tell the compiler that we know what we are doing. This might disable some optimizations, but judging by how GCC failed to notice that the memory's initialization is dependent on `m_has_value`, I'm not sure that's a bad thing.
This commit is contained in:
parent
45a82b2a5b
commit
b9f30c6f2a
5 changed files with 17 additions and 17 deletions
|
@ -26,8 +26,8 @@
|
|||
|
||||
static Threading::Lock& malloc_lock()
|
||||
{
|
||||
static u32 lock_storage[sizeof(Threading::Lock) / sizeof(u32)];
|
||||
return *reinterpret_cast<Threading::Lock*>(&lock_storage);
|
||||
alignas(Threading::Lock) static u8 lock_storage[sizeof(Threading::Lock)];
|
||||
return *reinterpret_cast<Threading::Lock*>(lock_storage);
|
||||
}
|
||||
|
||||
constexpr size_t number_of_hot_chunked_blocks_to_keep_around = 16;
|
||||
|
@ -111,8 +111,8 @@ struct BigAllocator {
|
|||
// are run. Similarly, we can not allow global destructors to destruct
|
||||
// them. We could have used AK::NeverDestoyed to prevent the latter,
|
||||
// but it would have not helped with the former.
|
||||
static u8 g_allocators_storage[sizeof(Allocator) * num_size_classes];
|
||||
static u8 g_big_allocators_storage[sizeof(BigAllocator)];
|
||||
alignas(Allocator) static u8 g_allocators_storage[sizeof(Allocator) * num_size_classes];
|
||||
alignas(BigAllocator) static u8 g_big_allocators_storage[sizeof(BigAllocator)];
|
||||
|
||||
static inline Allocator (&allocators())[num_size_classes]
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue