Implemented more STL and page allocation for malloc.

This commit is contained in:
2024-01-27 15:24:50 +01:00
parent edd9ee85c7
commit 193e3a19dc
13 changed files with 701 additions and 28 deletions

View File

@@ -5,9 +5,42 @@
#define BAD_APPLE_OS_MEMORY_HPP_INCLUDED
#include <cstddef>
#include <cstring>
#include <limits>
#include <new>
#include <type_traits>
namespace std
{
template<typename T>
struct allocator
{
using value_type = T;
using size_type = std::size_t;
using propagate_on_container_move_assignment = true_type;
constexpr allocator() noexcept = default;
constexpr allocator(const allocator&) noexcept = default;
template<typename U>
constexpr allocator(const allocator<U>&) noexcept {}
[[nodiscard]] constexpr T* allocate(size_t n)
{
if (numeric_limits<size_t>::max() / sizeof(T) < n)
{
__ba_throw bad_array_new_length();
}
return static_cast<T*>(::operator new(n * sizeof(T))); // TODO: alignment for bigger types
}
constexpr void deallocate(T* p, size_t n)
{
(void) n;
::operator delete(p); // TODO: bigger alignments
}
};
constexpr void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space) noexcept
{
if (space < size) {