diff --git a/src/mx/memory/global_heap.h b/src/mx/memory/global_heap.h index e2434a3..01f0566 100644 --- a/src/mx/memory/global_heap.h +++ b/src/mx/memory/global_heap.h @@ -2,6 +2,8 @@ #include "alignment_helper.h" #include #include +#include +#include namespace mx::memory { /** @@ -10,7 +12,12 @@ namespace mx::memory { */ class GlobalHeap { +private: + static Genode::Heap _heap; + public: + static Genode::Heap &heap() { return _heap; } + /** * Allocates the given size on the given NUMA node. * @@ -21,6 +28,7 @@ public: static void *allocate(const std::uint8_t numa_node_id, const std::size_t size) { /* TODO: Use component's heap */ + _heap.alloc(size); } /** @@ -33,7 +41,7 @@ public: static void *allocate_cache_line_aligned(const std::size_t size) { /* TODO: Use component's heap, as std::aligned_alloc might not be thread-safe */ - return std::malloc(alignment_helper::next_multiple(size, 64UL)); + return _heap.alloc(alignment_helper::next_multiple(size, 64UL)); } /** @@ -42,6 +50,8 @@ public: * @param memory Pointer to memory. * @param size Size of the allocated object. */ - static void free(void *memory, const std::size_t size) { /* TODO: Free via Genode component's heap */ } + static void free(void *memory, const std::size_t size) { /* TODO: Free via Genode component's heap */ + _heap.free(memory, size); + } }; } // namespace mx::memory \ No newline at end of file diff --git a/src/mx/memory/task_allocator_interface.h b/src/mx/memory/task_allocator_interface.h index d44fd07..4cec512 100644 --- a/src/mx/memory/task_allocator_interface.h +++ b/src/mx/memory/task_allocator_interface.h @@ -2,6 +2,7 @@ #include #include +#include "global_heap.h" namespace mx::memory { /** @@ -41,12 +42,12 @@ public: /** * @return Allocated memory using systems malloc (but aligned). */ - [[nodiscard]] void *allocate(const std::uint16_t /*core_id*/) override { return std::malloc(S); } + [[nodiscard]] void *allocate(const std::uint16_t /*core_id*/) override { return GlobalHeap::heap().alloc(S); } /** * Frees the given memory using systems free. * @param address Memory to free. */ - void free(const std::uint16_t /*core_id*/, void *address) noexcept override { std::free(address); } + void free(const std::uint16_t /*core_id*/, void *address) noexcept override { GlobalHeap::heap().free(address); } }; } // namespace mx::memory \ No newline at end of file diff --git a/src/mx/tasking/profiling/profiling_task.cpp b/src/mx/tasking/profiling/profiling_task.cpp index b252e6f..033fff2 100644 --- a/src/mx/tasking/profiling/profiling_task.cpp +++ b/src/mx/tasking/profiling/profiling_task.cpp @@ -7,7 +7,7 @@ using namespace mx::tasking::profiling; ProfilingTask::ProfilingTask(mx::util::maybe_atomic &is_running, mx::tasking::Channel &channel) - : _is_running(is_running), _channel(channel), _timer(*new Timer::Connection(*system::Environment::env)) + : _is_running(is_running), _channel(channel), _timer (*new (memory::GlobalHeap::heap())Timer::Connection(*system::Environment::env)) { _idle_ranges.reserve(1 << 16); } diff --git a/src/mx/tasking/runtime.h b/src/mx/tasking/runtime.h index c2664ce..03ba742 100644 --- a/src/mx/tasking/runtime.h +++ b/src/mx/tasking/runtime.h @@ -80,7 +80,7 @@ public: // Create a new resource builder. if (_resource_builder == nullptr || need_new_scheduler) { - _resource_builder = new resource::Builder(*_scheduler, *_resource_allocator); + _resource_builder = new(memory::GlobalHeap::heap()) resource::Builder(*_scheduler, *_resource_allocator); } return true;