mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
AK: Clean up some of the confusion that is AK/kmalloc.{cpp,h}
This commit is contained in:
parent
d11b5407a3
commit
60f236b285
7 changed files with 0 additions and 368 deletions
|
@ -1,22 +1,9 @@
|
|||
#include "kmalloc.h"
|
||||
|
||||
#ifndef SERENITY
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#if defined(SERENITY) && defined(USERLAND)
|
||||
#define USE_SYSTEM_MALLOC
|
||||
#endif
|
||||
|
||||
#define USE_SYSTEM_MALLOC
|
||||
|
||||
#ifndef USE_SYSTEM_MALLOC
|
||||
#include "SimpleMalloc.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_SYSTEM_MALLOC
|
||||
|
||||
extern "C" {
|
||||
|
||||
void* kcalloc(size_t nmemb, size_t size)
|
||||
|
@ -45,77 +32,3 @@ void* kmalloc_eternal(size_t size)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
extern "C" {
|
||||
|
||||
void* kcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
if (!nmemb || !size)
|
||||
return nullptr;
|
||||
return SimpleMalloc::allocate_zeroed(nmemb * size);
|
||||
}
|
||||
|
||||
void* kmalloc(size_t size)
|
||||
{
|
||||
if (!size)
|
||||
return nullptr;
|
||||
return SimpleMalloc::allocate(size);
|
||||
}
|
||||
|
||||
void* kmalloc_eternal(size_t size)
|
||||
{
|
||||
if (!size)
|
||||
return nullptr;
|
||||
return SimpleMalloc::allocate(size);
|
||||
}
|
||||
|
||||
void kfree(void* ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return;
|
||||
SimpleMalloc::free((byte*)ptr);
|
||||
}
|
||||
|
||||
void* krealloc(void* ptr, size_t size)
|
||||
{
|
||||
if (!ptr)
|
||||
return ptr;
|
||||
return SimpleMalloc::reallocate((byte*)ptr, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void* operator new(std::size_t size)
|
||||
{
|
||||
return kmalloc(size);
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t size)
|
||||
{
|
||||
return kmalloc(size);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr)
|
||||
{
|
||||
return kfree(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr)
|
||||
{
|
||||
return kfree(ptr);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, size_t)
|
||||
{
|
||||
return kfree(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, size_t)
|
||||
{
|
||||
return kfree(ptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue