MonkOS  v0.1
A simple 64-bit operating system (x86_64)
heap.h
Go to the documentation of this file.
1 //============================================================================
2 /// @file heap.h
3 /// @brief A simple heap memory manager
4 //
5 // Copyright 2016 Brett Vickers.
6 // Use of this source code is governed by a BSD-style license
7 // that can be found in the MonkOS LICENSE file.
8 //============================================================================
9 
10 #pragma once
11 
12 #include <core.h>
13 #include <kernel/mem/paging.h>
14 
15 typedef struct heap heap_t;
16 
17 //----------------------------------------------------------------------------
18 // @function heap_create
19 /// @brief Create a new heap from which to allocate virtual memory.
20 /// @param[in] pt The page table from which virtual memory is to be
21 /// allocated.
22 /// @param[in] vaddr The virtual address of the first byte to use for
23 /// the heap.
24 /// @param[in] maxpages The maximum number of pages that the heap will
25 /// grow to fill.
26 /// @returns A pointer to a the created heap structure.
27 //----------------------------------------------------------------------------
28 heap_t *
29 heap_create(pagetable_t *pt, void *vaddr, uint64_t maxpages);
30 
31 //----------------------------------------------------------------------------
32 // @function heap_destroy
33 /// @brief Destroy a heap, returning its memory to page table.
34 /// @param[in] heap The heap to be destroyed.
35 //----------------------------------------------------------------------------
36 void
37 heap_destroy(heap_t *heap);
38 
39 //----------------------------------------------------------------------------
40 // @function heap_alloc
41 /// @brief Allocate memory from a heap.
42 /// @param[in] heap The heap from which to allocate the memory.
43 /// @param[in] size The size, in bytes, of the allocation.
44 /// @returns A pointer to a the allocated memory.
45 //----------------------------------------------------------------------------
46 void *
47 heap_alloc(heap_t *heap, uint64_t size);
48 
49 //----------------------------------------------------------------------------
50 // @function heap_free
51 /// @brief Free memory previously allocated with heap_alloc.
52 /// @param[in] heap The heap from which the memory was allocated.
53 /// @param[in] ptr A pointer to the memory that was allocated.
54 //----------------------------------------------------------------------------
55 void
56 heap_free(heap_t *heap, void *ptr);
Core include file.
Definition: heap.c:32
pagetable_t * pt
Definition: heap.c:34
A pagetable structure.
Definition: paging.h:66
void * heap_alloc(heap_t *heap, uint64_t size)
Allocate memory from a heap.
Definition: heap.c:239
heap_t * heap_create(pagetable_t *pt, void *vaddr, uint64_t maxpages)
Create a new heap from which to allocate virtual memory.
Definition: heap.c:61
void * vaddr
Definition: heap.c:35
uint64_t maxpages
Definition: heap.c:37
Paged memory management.
void heap_free(heap_t *heap, void *ptr)
Free memory previously allocated with heap_alloc.
Definition: heap.c:319
void heap_destroy(heap_t *heap)
Destroy a heap, returning its memory to page table.
Definition: heap.c:90