mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Rename memory_manager to heap_manager
This commit is contained in:
@@ -88,8 +88,8 @@ kutil:
|
|||||||
- src/libraries/kutil/include
|
- src/libraries/kutil/include
|
||||||
source:
|
source:
|
||||||
- src/libraries/kutil/assert.cpp
|
- src/libraries/kutil/assert.cpp
|
||||||
|
- src/libraries/kutil/heap_manager.cpp
|
||||||
- src/libraries/kutil/memory.cpp
|
- src/libraries/kutil/memory.cpp
|
||||||
- src/libraries/kutil/memory_manager.cpp
|
|
||||||
|
|
||||||
makerd:
|
makerd:
|
||||||
kind: exe
|
kind: exe
|
||||||
@@ -109,5 +109,5 @@ tests:
|
|||||||
- kutil
|
- kutil
|
||||||
source:
|
source:
|
||||||
- src/tests/linked_list.cpp
|
- src/tests/linked_list.cpp
|
||||||
|
- src/tests/heap_manager.cpp
|
||||||
- src/tests/main.cpp
|
- src/tests/main.cpp
|
||||||
- src/tests/memory_manager.cpp
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "kutil/assert.h"
|
#include "kutil/assert.h"
|
||||||
#include "kutil/memory_manager.h"
|
#include "kutil/heap_manager.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "page_manager.h"
|
#include "page_manager.h"
|
||||||
|
|
||||||
page_manager g_page_manager;
|
page_manager g_page_manager;
|
||||||
kutil::memory_manager g_kernel_memory_manager;
|
kutil::heap_manager g_kernel_heap_manager;
|
||||||
|
|
||||||
|
|
||||||
static uintptr_t
|
static uintptr_t
|
||||||
@@ -161,10 +161,10 @@ page_manager::init(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new (&g_kernel_memory_manager) kutil::memory_manager(
|
new (&g_kernel_heap_manager) kutil::heap_manager(
|
||||||
reinterpret_cast<void *>(end),
|
reinterpret_cast<void *>(end),
|
||||||
mm_grow_callback);
|
mm_grow_callback);
|
||||||
kutil::setup::set_heap(&g_kernel_memory_manager);
|
kutil::setup::set_heap(&g_kernel_heap_manager);
|
||||||
|
|
||||||
m_kernel_pml4 = get_pml4();
|
m_kernel_pml4 = get_pml4();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "kutil/assert.h"
|
#include "kutil/assert.h"
|
||||||
#include "kutil/memory.h"
|
#include "kutil/memory.h"
|
||||||
#include "kutil/memory_manager.h"
|
#include "kutil/heap_manager.h"
|
||||||
|
|
||||||
namespace kutil {
|
namespace kutil {
|
||||||
|
|
||||||
|
|
||||||
struct memory_manager::mem_header
|
struct heap_manager::mem_header
|
||||||
{
|
{
|
||||||
mem_header(mem_header *prev, mem_header *next, uint8_t size) :
|
mem_header(mem_header *prev, mem_header *next, uint8_t size) :
|
||||||
m_prev(prev), m_next(next)
|
m_prev(prev), m_next(next)
|
||||||
@@ -67,7 +67,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
memory_manager::memory_manager() :
|
heap_manager::heap_manager() :
|
||||||
m_start(nullptr),
|
m_start(nullptr),
|
||||||
m_length(0),
|
m_length(0),
|
||||||
m_grow(nullptr)
|
m_grow(nullptr)
|
||||||
@@ -75,7 +75,7 @@ memory_manager::memory_manager() :
|
|||||||
kutil::memset(m_free, 0, sizeof(m_free));
|
kutil::memset(m_free, 0, sizeof(m_free));
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_manager::memory_manager(void *start, grow_callback grow_cb) :
|
heap_manager::heap_manager(void *start, grow_callback grow_cb) :
|
||||||
m_start(start),
|
m_start(start),
|
||||||
m_length(0),
|
m_length(0),
|
||||||
m_grow(grow_cb)
|
m_grow(grow_cb)
|
||||||
@@ -85,7 +85,7 @@ memory_manager::memory_manager(void *start, grow_callback grow_cb) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
memory_manager::allocate(size_t length)
|
heap_manager::allocate(size_t length)
|
||||||
{
|
{
|
||||||
size_t total = length + sizeof(mem_header);
|
size_t total = length + sizeof(mem_header);
|
||||||
unsigned size = min_size;
|
unsigned size = min_size;
|
||||||
@@ -98,7 +98,7 @@ memory_manager::allocate(size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
memory_manager::free(void *p)
|
heap_manager::free(void *p)
|
||||||
{
|
{
|
||||||
mem_header *header = reinterpret_cast<mem_header *>(p);
|
mem_header *header = reinterpret_cast<mem_header *>(p);
|
||||||
header -= 1; // p points after the header
|
header -= 1; // p points after the header
|
||||||
@@ -120,7 +120,7 @@ memory_manager::free(void *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
memory_manager::grow_memory()
|
heap_manager::grow_memory()
|
||||||
{
|
{
|
||||||
size_t length = (1 << max_size);
|
size_t length = (1 << max_size);
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ memory_manager::grow_memory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
memory_manager::ensure_block(unsigned size)
|
heap_manager::ensure_block(unsigned size)
|
||||||
{
|
{
|
||||||
if (get_free(size) != nullptr) return;
|
if (get_free(size) != nullptr) return;
|
||||||
else if (size == max_size) {
|
else if (size == max_size) {
|
||||||
@@ -154,8 +154,8 @@ memory_manager::ensure_block(unsigned size)
|
|||||||
get_free(size) = orig;
|
get_free(size) = orig;
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_manager::mem_header *
|
heap_manager::mem_header *
|
||||||
memory_manager::pop_free(unsigned size)
|
heap_manager::pop_free(unsigned size)
|
||||||
{
|
{
|
||||||
ensure_block(size);
|
ensure_block(size);
|
||||||
mem_header *block = get_free(size);
|
mem_header *block = get_free(size);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
/// \file memory_manager.h
|
/// \file heap_manager.h
|
||||||
/// A buddy allocator and related definitions.
|
/// A buddy allocator and related definitions.
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@@ -7,19 +7,19 @@
|
|||||||
namespace kutil {
|
namespace kutil {
|
||||||
|
|
||||||
|
|
||||||
/// Manager for allocation of virtual memory.
|
/// Manager for allocation of heap memory.
|
||||||
class memory_manager
|
class heap_manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using grow_callback = void (*)(void *start, size_t length);
|
using grow_callback = void (*)(void *start, size_t length);
|
||||||
|
|
||||||
/// Default constructor. Creates an invalid manager.
|
/// Default constructor. Creates an invalid manager.
|
||||||
memory_manager();
|
heap_manager();
|
||||||
|
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
/// \arg start Pointer to the start of the heap to be managed
|
/// \arg start Pointer to the start of the heap to be managed
|
||||||
/// \arg grow_cb Function pointer to grow the heap size
|
/// \arg grow_cb Function pointer to grow the heap size
|
||||||
memory_manager(void *start, grow_callback grow_cb);
|
heap_manager(void *start, grow_callback grow_cb);
|
||||||
|
|
||||||
/// Allocate memory from the area managed.
|
/// Allocate memory from the area managed.
|
||||||
/// \arg length The amount of memory to allocate, in bytes
|
/// \arg length The amount of memory to allocate, in bytes
|
||||||
@@ -63,7 +63,7 @@ protected:
|
|||||||
|
|
||||||
grow_callback m_grow;
|
grow_callback m_grow;
|
||||||
|
|
||||||
memory_manager(const memory_manager &) = delete;
|
heap_manager(const heap_manager &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace kutil
|
} // namespace kutil
|
||||||
@@ -68,13 +68,13 @@ inline T* mask_pointer(T *p, uintptr_t mask)
|
|||||||
uint8_t checksum(const void *p, size_t len, size_t off = 0);
|
uint8_t checksum(const void *p, size_t len, size_t off = 0);
|
||||||
|
|
||||||
|
|
||||||
class memory_manager;
|
class heap_manager;
|
||||||
|
|
||||||
namespace setup {
|
namespace setup {
|
||||||
|
|
||||||
/// Set the heap that malloc() / free() will use.
|
/// Set the heap that malloc() / free() will use.
|
||||||
/// \arg mm The heap manager for the heap to use.
|
/// \arg mm The heap manager for the heap to use.
|
||||||
void set_heap(memory_manager *mm);
|
void set_heap(heap_manager *mm);
|
||||||
|
|
||||||
} // namespace kutil::setup
|
} // namespace kutil::setup
|
||||||
} // namespace kutil
|
} // namespace kutil
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "kutil/memory.h"
|
#include "kutil/memory.h"
|
||||||
#include "kutil/memory_manager.h"
|
#include "kutil/heap_manager.h"
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
enum class __attribute__ ((__type_visibility("default"))) align_val_t : size_t { };
|
enum class __attribute__ ((__type_visibility("default"))) align_val_t : size_t { };
|
||||||
@@ -17,10 +17,10 @@ namespace kutil {
|
|||||||
|
|
||||||
namespace setup {
|
namespace setup {
|
||||||
|
|
||||||
static memory_manager *heap_memory_manager;
|
static heap_manager *heap_memory_manager;
|
||||||
|
|
||||||
void
|
void
|
||||||
set_heap(memory_manager *mm)
|
set_heap(heap_manager *mm)
|
||||||
{
|
{
|
||||||
setup::heap_memory_manager = mm;
|
setup::heap_memory_manager = mm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "kutil/memory.h"
|
#include "kutil/memory.h"
|
||||||
#include "kutil/memory_manager.h"
|
#include "kutil/heap_manager.h"
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
using namespace kutil;
|
using namespace kutil;
|
||||||
@@ -35,7 +35,7 @@ TEST_CASE( "Buddy blocks tests", "[memory buddy]" )
|
|||||||
|
|
||||||
memory = aligned_alloc(max_block, 4 * max_block);
|
memory = aligned_alloc(max_block, 4 * max_block);
|
||||||
|
|
||||||
memory_manager mm(memory, grow_callback);
|
heap_manager mm(memory, grow_callback);
|
||||||
|
|
||||||
// The ctor should have allocated an initial block
|
// The ctor should have allocated an initial block
|
||||||
CHECK( total_alloc_size == max_block );
|
CHECK( total_alloc_size == max_block );
|
||||||
Reference in New Issue
Block a user