mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
Kernel: Fix memset() on x86_64
Previously memset() only set half of the bytes to the requested value.
This commit is contained in:
parent
cdcb75709a
commit
e56a0d6af7
Notes:
sideshowbarker
2024-07-18 11:25:08 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/e56a0d6af70 Pull-request: https://github.com/SerenityOS/serenity/pull/8290 Reviewed-by: https://github.com/Hendiadyoin1
2 changed files with 18 additions and 8 deletions
14
AK/Types.h
14
AK/Types.h
|
@ -65,14 +65,24 @@ namespace std {
|
||||||
using nullptr_t = decltype(nullptr);
|
using nullptr_t = decltype(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr u32 explode_byte(u8 b)
|
static constexpr FlatPtr explode_byte(u8 b)
|
||||||
{
|
{
|
||||||
return b << 24 | b << 16 | b << 8 | b;
|
#if ARCH(I386)
|
||||||
|
return (u32)b << 24 | (u32)b << 16 | (u32)b << 8 | (u32)b;
|
||||||
|
#else
|
||||||
|
return (u64)b << 56 | (u64)b << 48 | (u64)b << 40 | (u64)b << 32 | (u64)b << 24 | (u64)b << 16 | (u64)b << 8 | (u64)b;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ARCH(I386)
|
||||||
static_assert(explode_byte(0xff) == 0xffffffff);
|
static_assert(explode_byte(0xff) == 0xffffffff);
|
||||||
static_assert(explode_byte(0x80) == 0x80808080);
|
static_assert(explode_byte(0x80) == 0x80808080);
|
||||||
static_assert(explode_byte(0x7f) == 0x7f7f7f7f);
|
static_assert(explode_byte(0x7f) == 0x7f7f7f7f);
|
||||||
|
#else
|
||||||
|
static_assert(explode_byte(0xff) == 0xffffffffffffffff);
|
||||||
|
static_assert(explode_byte(0x80) == 0x8080808080808080);
|
||||||
|
static_assert(explode_byte(0x7f) == 0x7f7f7f7f7f7f7f7f);
|
||||||
|
#endif
|
||||||
static_assert(explode_byte(0) == 0);
|
static_assert(explode_byte(0) == 0);
|
||||||
|
|
||||||
constexpr size_t align_up_to(const size_t value, const size_t alignment)
|
constexpr size_t align_up_to(const size_t value, const size_t alignment)
|
||||||
|
|
|
@ -356,12 +356,12 @@ void page_fault_handler(TrapFrame* trap)
|
||||||
regs.exception_code & PageFaultFlags::InstructionFetch ? "instruction fetch / " : "",
|
regs.exception_code & PageFaultFlags::InstructionFetch ? "instruction fetch / " : "",
|
||||||
regs.exception_code & PageFaultFlags::Write ? "write to" : "read from",
|
regs.exception_code & PageFaultFlags::Write ? "write to" : "read from",
|
||||||
VirtualAddress(fault_address));
|
VirtualAddress(fault_address));
|
||||||
u32 malloc_scrub_pattern = explode_byte(MALLOC_SCRUB_BYTE);
|
FlatPtr malloc_scrub_pattern = explode_byte(MALLOC_SCRUB_BYTE);
|
||||||
u32 free_scrub_pattern = explode_byte(FREE_SCRUB_BYTE);
|
FlatPtr free_scrub_pattern = explode_byte(FREE_SCRUB_BYTE);
|
||||||
u32 kmalloc_scrub_pattern = explode_byte(KMALLOC_SCRUB_BYTE);
|
FlatPtr kmalloc_scrub_pattern = explode_byte(KMALLOC_SCRUB_BYTE);
|
||||||
u32 kfree_scrub_pattern = explode_byte(KFREE_SCRUB_BYTE);
|
FlatPtr kfree_scrub_pattern = explode_byte(KFREE_SCRUB_BYTE);
|
||||||
u32 slab_alloc_scrub_pattern = explode_byte(SLAB_ALLOC_SCRUB_BYTE);
|
FlatPtr slab_alloc_scrub_pattern = explode_byte(SLAB_ALLOC_SCRUB_BYTE);
|
||||||
u32 slab_dealloc_scrub_pattern = explode_byte(SLAB_DEALLOC_SCRUB_BYTE);
|
FlatPtr slab_dealloc_scrub_pattern = explode_byte(SLAB_DEALLOC_SCRUB_BYTE);
|
||||||
if ((fault_address & 0xffff0000) == (malloc_scrub_pattern & 0xffff0000)) {
|
if ((fault_address & 0xffff0000) == (malloc_scrub_pattern & 0xffff0000)) {
|
||||||
dbgln("Note: Address {} looks like it may be uninitialized malloc() memory", VirtualAddress(fault_address));
|
dbgln("Note: Address {} looks like it may be uninitialized malloc() memory", VirtualAddress(fault_address));
|
||||||
} else if ((fault_address & 0xffff0000) == (free_scrub_pattern & 0xffff0000)) {
|
} else if ((fault_address & 0xffff0000) == (free_scrub_pattern & 0xffff0000)) {
|
||||||
|
|
Loading…
Reference in a new issue