diff --git a/memory/memory.hpp b/memory/memory.hpp index f377e5a..de5fb5b 100644 --- a/memory/memory.hpp +++ b/memory/memory.hpp @@ -57,4 +57,22 @@ bool operator!=(const kAllocator &, const kAllocator &) { // operators new and delete only call kMalloc/kFree, so C++ code // must stay after paging setup void *operator new(std::size_t size); -void operator delete(void *ptr) noexcept; +void *operator new[](std::size_t size); + +#if __cplusplus >= 201703L +void *operator new(std::size_t size, std::align_val_t align); +void *operator new[](std::size_t size, std::align_val_t align); +#endif + +void operator delete(void *ptr) noexcept; +void operator delete[](void *ptr) noexcept; +#if __cplusplus >= 201402L +void operator delete(void *ptr, std::size_t size) noexcept; +void operator delete[](void *ptr, std::size_t size) noexcept; +#endif +#if __cplusplus >= 201703L +void operator delete(void *ptr, std::align_val_t align) noexcept; +void operator delete[](void *ptr, std::align_val_t align) noexcept; +void operator delete(void *ptr, std::size_t size, std::align_val_t align) noexcept; +void operator delete[](void *ptr, std::size_t size, std::align_val_t align) noexcept; +#endif diff --git a/memory/memory_cpp.cpp b/memory/memory_cpp.cpp index b35f4fa..4463c70 100644 --- a/memory/memory_cpp.cpp +++ b/memory/memory_cpp.cpp @@ -1,13 +1,27 @@ +#include "memory.h" #include "memory.hpp" -void *operator new(std::size_t size) { - void *data = kMalloc(size); - /*if (!data) { - throw helos::bad_alloc(); - }*/ - return data; -} +#include "../extlib/dlmalloc/malloc-2.8.6.h" -void operator delete(void *ptr) noexcept { - kFree(ptr); -} +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) noexcept { kFree(ptr); } +void operator delete[](void *ptr) noexcept { kFree(ptr); } + + +#if __cplusplus >= 201703L +void *operator new(std::size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); } +void *operator new[](std::size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); } +#endif + +#if __cplusplus >= 201402L +void operator delete(void *ptr, std::size_t size) noexcept { kFree(ptr); } +void operator delete[](void *ptr, std::size_t size) noexcept { kFree(ptr); } +#endif +#if __cplusplus >= 201703L +void operator delete(void *ptr, std::align_val_t align) noexcept { kFree(ptr); } +void operator delete[](void *ptr, std::align_val_t align) noexcept { kFree(ptr); } +void operator delete(void *ptr, std::size_t size, std::align_val_t align) noexcept { kFree(ptr); } +void operator delete[](void *ptr, std::size_t size, std::align_val_t align) noexcept { kFree(ptr); } +#endif