2018-10-10 12:53:07 +03:00
|
|
|
#include <cstdio>
|
|
|
|
#include "SimpleMalloc.h"
|
2018-10-17 11:55:43 +03:00
|
|
|
#include "kmalloc.h"
|
2018-10-10 16:11:43 +03:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#define USE_SYSTEM_MALLOC
|
|
|
|
|
|
|
|
#ifdef USE_SYSTEM_MALLOC
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2018-10-16 14:59:28 +03:00
|
|
|
void* kcalloc(size_t nmemb, size_t size)
|
2018-10-10 16:11:43 +03:00
|
|
|
{
|
|
|
|
return calloc(nmemb, size);
|
|
|
|
}
|
|
|
|
|
2018-10-16 14:59:28 +03:00
|
|
|
void* kmalloc(size_t size)
|
2018-10-10 16:11:43 +03:00
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void kfree(void* ptr)
|
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
2018-10-16 14:59:28 +03:00
|
|
|
void* krealloc(void* ptr, size_t size)
|
2018-10-10 16:11:43 +03:00
|
|
|
{
|
|
|
|
return realloc(ptr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2018-10-16 14:59:28 +03:00
|
|
|
void* kcalloc(size_t nmemb, size_t size)
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
|
|
|
if (!nmemb || !size)
|
|
|
|
return nullptr;
|
|
|
|
return SimpleMalloc::allocateZeroed(nmemb * size);
|
|
|
|
}
|
|
|
|
|
2018-10-16 14:59:28 +03:00
|
|
|
void* kmalloc(size_t size)
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
|
|
|
if (!size)
|
|
|
|
return nullptr;
|
|
|
|
return SimpleMalloc::allocate(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void kfree(void* ptr)
|
|
|
|
{
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
SimpleMalloc::free((byte*)ptr);
|
|
|
|
}
|
|
|
|
|
2018-10-16 14:59:28 +03:00
|
|
|
void* krealloc(void* ptr, size_t size)
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-10-10 16:11:43 +03:00
|
|
|
#endif
|
|
|
|
|