Revert "Use Genode functions to allocate memory."

This reverts commit 8fba63d09a.
This commit is contained in:
Michael Müller
2022-07-26 18:28:30 +02:00
parent 35065cfef8
commit 139b3a2d88
3 changed files with 11 additions and 14 deletions

View File

@@ -3,12 +3,10 @@
#include <cstdint>
#include <cstdlib>
#include <base/heap.h>
#include <mx/system/environment.h>
namespace mx::memory {
/**
* The global heap represents the heap, provided by the OS.
* TODO: Use Genode's interface here.
*/
class GlobalHeap
{
@@ -36,8 +34,7 @@ public:
*/
static void *allocate(const std::uint8_t numa_node_id, const std::size_t size)
{
/* TODO: Use component's heap */
return GlobalHeap::get_instance().heap().alloc(size);
return std::malloc(size);
}
/**
@@ -49,8 +46,9 @@ 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 GlobalHeap::get_instance().heap().alloc(alignment_helper::next_multiple(size, 64UL));
void *mem_chunk;
posix_memalign(&mem_chunk, 64U, alignment_helper::next_multiple(size, 64UL));
return mem_chunk;
}
/**
@@ -59,8 +57,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 */
GlobalHeap::heap().free(memory, size);
static void free(void *memory, const std::size_t size) {
std::free(memory);
}
};
} // namespace mx::memory

View File

@@ -2,7 +2,6 @@
#include <cstdint>
#include <cstdlib>
#include "global_heap.h"
namespace mx::memory {
/**
@@ -42,12 +41,12 @@ public:
/**
* @return Allocated memory using systems malloc (but aligned).
*/
[[nodiscard]] void *allocate(const std::uint16_t /*core_id*/) override { return GlobalHeap::heap().alloc(S); }
[[nodiscard]] void *allocate(const std::uint16_t /*core_id*/) override { return std::malloc(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 { GlobalHeap::heap().free(address, S); }
void free(const std::uint16_t /*core_id*/, void *address) noexcept override { std::free(address); }
};
} // namespace mx::memory

View File

@@ -1,8 +1,8 @@
#pragma once
#include "scheduler.h"
#include "task.h"
#include <iostream> /* TODO: Find Genode replacement, IO streams crash on Genode */
#include <memory> /* TODO: Deos this work with Genode? */
#include <iostream>
#include <memory>
#include <mx/memory/dynamic_size_allocator.h>
#include <mx/memory/fixed_size_allocator.h>
#include <mx/memory/task_allocator_interface.h>
@@ -80,7 +80,7 @@ public:
// Create a new resource builder.
if (_resource_builder == nullptr || need_new_scheduler)
{
_resource_builder = std::make_unique<resource::Builder>(*_scheduler, *_resource_allocator);
_resource_builder = std::make_unique<resource::Builder> (new resource::Builder(*_scheduler, *_resource_allocator));
}
return true;