-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem.h
More file actions
32 lines (24 loc) · 826 Bytes
/
mem.h
File metadata and controls
32 lines (24 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* OneOS-ARM Memory Management */
#ifndef MEM_H
#define MEM_H
/* Define basic types for bare-metal */
typedef unsigned char uint8_t;
typedef unsigned int size_t;
#define NULL ((void*)0)
/* Memory block header for heap allocator */
typedef struct mem_block {
size_t size; /* Size of this block (excluding header) */
struct mem_block *next; /* Next block in free list */
struct mem_block *prev; /* Previous block in free list */
uint8_t free; /* 1 if free, 0 if allocated */
} mem_block_t;
/* Initialize heap allocator */
void mem_init(void *heap_start, size_t heap_size);
/* Allocate memory */
void *kmalloc(size_t size);
/* Free memory */
void kfree(void *ptr);
/* Get heap statistics */
size_t mem_get_used(void);
size_t mem_get_free(void);
#endif