2018-10-10 09:53:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-27 11:48:21 +00:00
|
|
|
#ifndef KERNEL
|
|
|
|
#include <new>
|
|
|
|
#endif
|
|
|
|
|
2018-10-31 22:19:15 +00:00
|
|
|
#if defined(SERENITY) && defined(KERNEL)
|
|
|
|
#define AK_MAKE_ETERNAL \
|
|
|
|
public: \
|
|
|
|
void* operator new(size_t size) { return kmalloc_eternal(size); } \
|
2019-04-03 14:50:08 +00:00
|
|
|
void* operator new(size_t, void* ptr) { return ptr; } \
|
2018-10-31 22:19:15 +00:00
|
|
|
private:
|
|
|
|
#else
|
|
|
|
#define AK_MAKE_ETERNAL
|
|
|
|
#endif
|
|
|
|
|
2018-10-28 08:36:21 +00:00
|
|
|
#ifdef KERNEL
|
2018-10-17 08:55:43 +00:00
|
|
|
#include <Kernel/kmalloc.h>
|
2018-10-28 08:36:21 +00:00
|
|
|
#else
|
|
|
|
#include <LibC/stdlib.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2019-02-15 11:30:48 +00:00
|
|
|
[[gnu::malloc, gnu::returns_nonnull]] void* kmalloc(size_t size);
|
|
|
|
[[gnu::malloc, gnu::returns_nonnull]] void* kmalloc_eternal(size_t);
|
|
|
|
[[gnu::returns_nonnull]] void* krealloc(void* ptr, size_t size);
|
2018-10-28 08:36:21 +00:00
|
|
|
void kfree(void* ptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-27 11:48:21 +00:00
|
|
|
inline void* operator new(size_t size)
|
|
|
|
{
|
|
|
|
return kmalloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator delete(void* ptr)
|
|
|
|
{
|
|
|
|
return kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void* operator new[](size_t size)
|
|
|
|
{
|
|
|
|
return kmalloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator delete[](void* ptr)
|
|
|
|
{
|
|
|
|
return kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|