diff options
-rw-r--r-- | Kernel/StdLib.cpp | 6 | ||||
-rw-r--r-- | Kernel/kmalloc.h | 8 |
2 files changed, 10 insertions, 4 deletions
diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 655fab3c6a..023f8e6ce5 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -9,7 +9,8 @@ void memcpy(void *dest_ptr, const void *src_ptr, dword n) { dword dest = (dword)dest_ptr; dword src = (dword)src_ptr; - if (n >= 12) { + // FIXME: Support starting at an unaligned address. + if (!(dest & 0x3) && !(src & 0x3) && n >= 12) { size_t dwords = n / sizeof(dword); asm volatile( "rep movsl\n" @@ -36,7 +37,8 @@ void strcpy(char* dest, const char *src) void* memset(void* dest_ptr, byte c, dword n) { dword dest = (dword)dest_ptr; - if (n >= 12) { + // FIXME: Support starting at an unaligned address. + if (!(dest & 0x3) && n >= 12) { size_t dwords = n / sizeof(dword); dword expanded_c = c; expanded_c <<= 8; diff --git a/Kernel/kmalloc.h b/Kernel/kmalloc.h index 1aeae01099..8c4a1522eb 100644 --- a/Kernel/kmalloc.h +++ b/Kernel/kmalloc.h @@ -1,5 +1,7 @@ #pragma once +//#define KMALLOC_DEBUG_LARGE_ALLOCATIONS + void kmalloc_init(); void* kmalloc_impl(dword size) __attribute__ ((malloc)); void* kmalloc_eternal(size_t) __attribute__ ((malloc)); @@ -20,8 +22,10 @@ inline void* operator new[](size_t, void* p) { return p; } ALWAYS_INLINE void* kmalloc(size_t size) { - // Any kernel allocation >= 32K is very suspicious, catch them. - if (size >= 0x8000) +#ifdef KMALLOC_DEBUG_LARGE_ALLOCATIONS + // Any kernel allocation >= 1M is 99.9% a bug. + if (size >= 1048576) asm volatile("cli;hlt"); +#endif return kmalloc_impl(size); } |