blob: 6ae3dd7f7a51cc3beea27de17a0cce2d896ef1cd (
plain) (
blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#ifndef HEAP_H
#define HEAP_H
/*
* Allocate a block with specified (physical) alignment
*
* "align" must be a power of 2.
*
* Note that "align" affects the alignment of the physical address,
* not the virtual address. This is almost certainly what you want.
*
*/
extern void * emalloc ( size_t size, unsigned int align );
/*
* Allocate a block, with no particular alignment requirements.
*
*/
static inline void * malloc ( size_t size ) {
return emalloc ( size, sizeof ( void * ) );
}
/*
* Allocate all remaining space on the heap
*
*/
extern void * emalloc_all ( size_t *size );
/*
* Free a block.
*
* The caller must ensure that the block being freed is the last (most
* recent) block allocated on the heap, otherwise heap corruption will
* occur.
*
*/
extern void efree ( void *ptr );
static inline void free ( void *ptr ) {
efree ( ptr );
}
/*
* Free all allocated blocks on the heap
*
*/
extern void efree_all ( void );
/*
* Resize a block.
*
* The caller must ensure that the block being resized is the last
* (most recent) block allocated on the heap, otherwise heap
* corruption will occur.
*
*/
static inline void * erealloc ( void *ptr, size_t size, unsigned int align ) {
efree ( ptr );
return emalloc ( size, align );
}
/*
* Legacy API calls
*
*/
static inline void * allot ( size_t size ) {
return emalloc ( size, sizeof ( void * ) );
}
static inline void forget ( void *ptr ) {
efree ( ptr );
}
static inline void * allot2 ( size_t size, uint32_t mask ) {
return emalloc ( size, mask + 1 );
}
static inline void forget2 ( void *ptr ) {
efree ( ptr );
}
#endif /* HEAP_H */
|