2020-01-18 03:38:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 04:24:48 -04:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 03:38:21 -05:00
|
|
|
*/
|
|
|
|
|
2018-10-10 05:53:07 -04:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-04 15:15:45 -04:00
|
|
|
#ifndef __serenity__
|
2020-02-25 09:58:24 -05:00
|
|
|
# include <new>
|
|
|
|
#endif
|
|
|
|
|
2019-04-20 06:58:02 -04:00
|
|
|
#ifdef KERNEL
|
2019-05-28 05:53:16 -04:00
|
|
|
# define AK_MAKE_ETERNAL \
|
|
|
|
public: \
|
|
|
|
void* operator new(size_t size) { return kmalloc_eternal(size); } \
|
|
|
|
\
|
|
|
|
private:
|
2018-10-31 18:19:15 -04:00
|
|
|
#else
|
2019-05-28 05:53:16 -04:00
|
|
|
# define AK_MAKE_ETERNAL
|
2018-10-31 18:19:15 -04:00
|
|
|
#endif
|
|
|
|
|
2020-02-09 09:50:13 -05:00
|
|
|
#if defined(KERNEL)
|
2019-09-16 03:01:44 -04:00
|
|
|
# include <Kernel/Heap/kmalloc.h>
|
2018-10-28 04:36:21 -04:00
|
|
|
#else
|
2019-05-28 05:53:16 -04:00
|
|
|
# include <stdlib.h>
|
2020-08-04 15:15:45 -04:00
|
|
|
|
2019-05-28 05:53:16 -04:00
|
|
|
# define kcalloc calloc
|
|
|
|
# define kmalloc malloc
|
|
|
|
# define kfree free
|
|
|
|
# define krealloc realloc
|
2020-08-04 15:15:45 -04:00
|
|
|
|
|
|
|
# ifdef __serenity__
|
|
|
|
|
2020-11-05 03:59:30 -05:00
|
|
|
# include <new>
|
|
|
|
|
2020-08-04 15:15:45 -04:00
|
|
|
inline void* operator new(size_t size)
|
|
|
|
{
|
|
|
|
return kmalloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator delete(void* ptr)
|
|
|
|
{
|
|
|
|
return kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator delete(void* ptr, size_t)
|
|
|
|
{
|
|
|
|
return kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void* operator new[](size_t size)
|
|
|
|
{
|
|
|
|
return kmalloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator delete[](void* ptr)
|
|
|
|
{
|
|
|
|
return kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator delete[](void* ptr, size_t)
|
|
|
|
{
|
|
|
|
return kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
# endif
|
|
|
|
|
2019-03-27 07:48:21 -04:00
|
|
|
#endif
|