mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
c02c9880b6
This is useful for static locals that never need to be destroyed: Thing& Thing::the() { static Eternal<Thing> the; return the; } The object will be allocated in data segment memory and will never have its destructor invoked.
51 lines
908 B
C++
51 lines
908 B
C++
#pragma once
|
|
|
|
#ifndef KERNEL
|
|
#include <new>
|
|
#endif
|
|
|
|
#if defined(SERENITY) && defined(KERNEL)
|
|
#define AK_MAKE_ETERNAL \
|
|
public: \
|
|
void* operator new(size_t size) { return kmalloc_eternal(size); } \
|
|
void* operator new(size_t, void* ptr) { return ptr; } \
|
|
private:
|
|
#else
|
|
#define AK_MAKE_ETERNAL
|
|
#endif
|
|
|
|
#ifdef KERNEL
|
|
#include <Kernel/kmalloc.h>
|
|
#else
|
|
#include <LibC/stdlib.h>
|
|
|
|
extern "C" {
|
|
|
|
[[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);
|
|
void kfree(void* ptr);
|
|
|
|
}
|
|
|
|
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
|