Clearing up kutil/kernel memory code separation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "memory.h"
|
||||
#include "memory_manager.h"
|
||||
|
||||
void * operator new (size_t, void *p) noexcept { return p; }
|
||||
void * operator new (size_t n) { return kutil::malloc(n); }
|
||||
@@ -8,6 +9,32 @@ void operator delete[] (void *p) noexcept { return kutil::free(p); }
|
||||
|
||||
namespace kutil {
|
||||
|
||||
namespace setup {
|
||||
|
||||
static memory_manager *heap_memory_manager;
|
||||
|
||||
void
|
||||
set_heap(memory_manager *mm)
|
||||
{
|
||||
setup::heap_memory_manager = mm;
|
||||
}
|
||||
|
||||
} // namespace kutil::setup
|
||||
|
||||
|
||||
void *
|
||||
malloc(size_t n)
|
||||
{
|
||||
return setup::heap_memory_manager->allocate(n);
|
||||
}
|
||||
|
||||
void
|
||||
free(void *p)
|
||||
{
|
||||
setup::heap_memory_manager->free(p);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
memset(void *s, uint8_t v, size_t n)
|
||||
{
|
||||
|
||||
@@ -11,15 +11,12 @@ void * operator new (size_t, void *p) noexcept;
|
||||
|
||||
namespace kutil {
|
||||
|
||||
/// Allocate memory. Note: this needs to be implemented
|
||||
/// by the kernel, or other program using this library.
|
||||
/// Allocate memory.
|
||||
/// \arg n The number of bytes to allocate
|
||||
/// \returns The allocated memory
|
||||
void * malloc(size_t n);
|
||||
|
||||
/// Free memory allocated by malloc(). Note: this needs
|
||||
/// to be implemented by the kernel, or other program
|
||||
/// using this library.
|
||||
/// Free memory allocated by malloc().
|
||||
/// \arg p A pointer previously returned by malloc()
|
||||
void free(void *p);
|
||||
|
||||
@@ -72,4 +69,14 @@ inline T* mask_pointer(T *p, addr_t mask)
|
||||
/// \arg off An optional offset into the region
|
||||
uint8_t checksum(const void *p, size_t len, size_t off = 0);
|
||||
|
||||
|
||||
class memory_manager;
|
||||
|
||||
namespace setup {
|
||||
|
||||
/// Set the heap that malloc() / free() will use.
|
||||
/// \arg mm The heap manager for the heap to use.
|
||||
void set_heap(memory_manager *mm);
|
||||
|
||||
} // namespace kutil::setup
|
||||
} // namespace kutil
|
||||
|
||||
Reference in New Issue
Block a user