Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/mem/heap.h
1476 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
* Copyright (c) 2018-2024 CTCaer
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef _HEAP_H_
19
#define _HEAP_H_
20
21
#include <utils/types.h>
22
23
typedef struct _hnode
24
{
25
int used;
26
u32 size;
27
struct _hnode *prev;
28
struct _hnode *next;
29
u32 align[4]; // Align to arch cache line size.
30
} hnode_t;
31
32
typedef struct _heap
33
{
34
void *start;
35
hnode_t *first;
36
hnode_t *last;
37
} heap_t;
38
39
typedef struct
40
{
41
u32 total;
42
u32 used;
43
u32 nodes_total;
44
u32 nodes_used;
45
} heap_monitor_t;
46
47
void heap_init(void *base);
48
void heap_set(heap_t *heap);
49
void *malloc(u32 size);
50
void *calloc(u32 num, u32 size);
51
void *zalloc(u32 size);
52
void free(void *buf);
53
void heap_monitor(heap_monitor_t *mon, bool print_node_stats);
54
55
#endif
56
57