Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::memory::allocator::ChunkHeader Struct Reference

A span of memory in the heap, can be allocated or free. Used as a node in a doubly linked list. More...

#include <bump.h>

Public Member Functions

bool is_valid ()
 
ChunkHeader * prev_chunk ()
 
ChunkHeader * next_chunk ()
 

Public Attributes

uint16_t canary
 Trip value to detect buffer overflows.
 
ChunkHeader * next
 Pointer to the chunk after this one in the list.
 
ChunkHeader * prev
 Pointer to the chunk before this one in the list.
 
uint8_t allocated
 Whether this chunk is in use or can be allocated.
 
size_t size
 The size of this span of memory (not including the MemoryChunk struct itself)
 

Detailed Description

A span of memory in the heap, can be allocated or free. Used as a node in a doubly linked list.

Definition at line 25 of file bump.h.

Member Function Documentation

◆ is_valid()

bool ChunkHeader::is_valid ( )

Validate that a given chunk is as expected

Returns
True if the chunk is valid, false if any check fails

Definition at line 39 of file bump.cpp.

39 {
40 return canary == EXPECTED_CANARY;
41}
uint16_t canary
Trip value to detect buffer overflows.
Definition bump.h:27

References canary.

Referenced by next_chunk(), and prev_chunk().

◆ next_chunk()

chunk_header_t * ChunkHeader::next_chunk ( )

Safely gets the next chunk. Will crash the program (not the kernel) if invalid chunk

Returns
The next chunk node in the linked list or nullptr if this is the last node
Todo:
PANIC here to make easier to debug, change to crash the prog isntead

Definition at line 67 of file bump.cpp.

67 {
68
69 // Make sure the chunk is not poiting to garbage
70 if (!is_valid())
71 ASSERT(false, "Invalid memory chunk detected (possible buffer overflow)\n");
72
73 return next;
74}
ChunkHeader * next
Pointer to the chunk after this one in the list.
Definition bump.h:29

References is_valid(), and next.

Referenced by MaxOS::memory::allocator::BumpAllocator::allocate(), and MaxOS::memory::allocator::BumpAllocator::amount_used().

◆ prev_chunk()

chunk_header_t * ChunkHeader::prev_chunk ( )

Safely gets the prev chunk. Will crash the program (not the kernel) if invalid chunk

Returns
The previous chunk node in the linked list or nullptr if this is the start node
Todo:
PANIC here to make easier to debug, change to crash the prog isntead

Definition at line 50 of file bump.cpp.

50 {
51
52 // Make sure the chunk is not poiting to garbage
53 if (!is_valid())
54 ASSERT(false, "Invalid memory chunk detected (possible buffer overflow)\n");
55
56 return prev;
57}
ChunkHeader * prev
Pointer to the chunk before this one in the list.
Definition bump.h:30

References is_valid(), and prev.

Referenced by MaxOS::memory::allocator::BumpAllocator::unallocate().

Member Data Documentation

◆ allocated

uint8_t MaxOS::memory::allocator::ChunkHeader::allocated

Whether this chunk is in use or can be allocated.

Definition at line 32 of file bump.h.

Referenced by MaxOS::memory::allocator::BumpAllocator::allocate(), and MaxOS::memory::allocator::BumpAllocator::setup_region().

◆ canary

uint16_t MaxOS::memory::allocator::ChunkHeader::canary

Trip value to detect buffer overflows.

Definition at line 27 of file bump.h.

Referenced by MaxOS::memory::allocator::BumpAllocator::allocate(), is_valid(), and MaxOS::memory::allocator::BumpAllocator::setup_region().

◆ next

ChunkHeader* MaxOS::memory::allocator::ChunkHeader::next

Pointer to the chunk after this one in the list.

Definition at line 29 of file bump.h.

Referenced by MaxOS::memory::allocator::BumpAllocator::allocate(), next_chunk(), and MaxOS::memory::allocator::BumpAllocator::setup_region().

◆ prev

ChunkHeader* MaxOS::memory::allocator::ChunkHeader::prev

Pointer to the chunk before this one in the list.

Definition at line 30 of file bump.h.

Referenced by MaxOS::memory::allocator::BumpAllocator::allocate(), prev_chunk(), and MaxOS::memory::allocator::BumpAllocator::setup_region().

◆ size

size_t MaxOS::memory::allocator::ChunkHeader::size

The size of this span of memory (not including the MemoryChunk struct itself)

Definition at line 33 of file bump.h.

Referenced by MaxOS::memory::allocator::BumpAllocator::allocate(), MaxOS::memory::allocator::BumpAllocator::setup_region(), and MaxOS::memory::allocator::BumpAllocator::unallocate().


The documentation for this struct was generated from the following files: