Don't use dword-by-dword memset/memcpy if the addresses are unaligned.

Also don't enable the large kmalloc catcher by default.
This commit is contained in:
Andreas Kling 2019-01-12 23:33:13 +01:00
parent 3ac977f50b
commit c43903eebd
Notes: sideshowbarker 2024-07-19 16:03:27 +09:00
2 changed files with 10 additions and 4 deletions

View File

@ -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;

View File

@ -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);
}