Max OS
0.3
Loading...
Searching...
No Matches
bump.h
1
//
2
// Created by 98max on 8/07/2026.
3
//
4
5
#ifndef MAXOS_ALLOCATOR_BUMP_H
6
#define MAXOS_ALLOCATOR_BUMP_H
7
8
#include <cstddef>
9
#include <cstdint>
10
11
#include <libcommon/assert.h>
12
13
#include <
memory/allocator/allocator.h
>
14
15
namespace
MaxOS::memory::allocator {
16
17
18
constexpr
uint16_t EXPECTED_CANARY = 0xC0DE;
19
constexpr
size_t
CHUNK_ALIGNMENT = 0x10;
20
25
typedef
struct
alignas(CHUNK_ALIGNMENT)
ChunkHeader
{
26
27
uint16_t
canary
;
28
29
ChunkHeader
*
next
;
30
ChunkHeader
*
prev
;
31
32
uint8_t
allocated
;
33
size_t
size
;
34
35
bool
is_valid();
36
ChunkHeader
* prev_chunk();
37
ChunkHeader
* next_chunk();
38
39
}
chunk_header_t
;
40
41
constexpr
size_t
CHUNK_HEADER_SIZE =
sizeof
(
chunk_header_t
);
42
47
class
BumpAllocator
:
public
MemoryAllocator
{
48
49
private
:
50
chunk_header_t
* m_first_memory_chunk =
nullptr
;
51
chunk_header_t
* m_last_memory_chunk =
nullptr
;
52
53
void
* expand_heap(
size_t
size)
final
;
54
virtual
void
* allocate_extra_space(
size_t
requested_size,
size_t
& actual_size);
55
56
bool
m_setup =
false
;
57
58
59
public
:
60
BumpAllocator
();
61
virtual
~BumpAllocator
();
62
63
void
setup_region(uintptr_t address,
size_t
length)
final
;
64
65
void
* allocate(
size_t
size)
final
;
66
void
unallocate(
void
* pointer)
final
;
67
68
size_t
amount_used() final;
69
size_t
align(
size_t
size) final;
70
71
};
72
73
}
74
75
#endif
//MAXOS_ALLOCATOR_BUMP_H
allocator.h
needs breif
MaxOS::memory::allocator::BumpAllocator
Basic doubly linked list bump memory allocator.
Definition
bump.h:47
MaxOS::memory::allocator::BumpAllocator::~BumpAllocator
virtual ~BumpAllocator()
Destructs a Bump memory allocator.
MaxOS::memory::allocator::MemoryAllocator
Generic memory allocator type.
Definition
allocator.h:23
MaxOS::memory::allocator::ChunkHeader
A span of memory in the heap, can be allocated or free. Used as a node in a doubly linked list.
Definition
bump.h:25
MaxOS::memory::allocator::ChunkHeader::next
ChunkHeader * next
Pointer to the chunk after this one in the list.
Definition
bump.h:29
MaxOS::memory::allocator::ChunkHeader::allocated
uint8_t allocated
Whether this chunk is in use or can be allocated.
Definition
bump.h:32
MaxOS::memory::allocator::ChunkHeader::prev
ChunkHeader * prev
Pointer to the chunk before this one in the list.
Definition
bump.h:30
MaxOS::memory::allocator::ChunkHeader::size
size_t size
The size of this span of memory (not including the MemoryChunk struct itself)
Definition
bump.h:33
MaxOS::memory::allocator::ChunkHeader::canary
uint16_t canary
Trip value to detect buffer overflows.
Definition
bump.h:27
kernel
include
memory
allocator
bump.h
Generated by
1.9.8