51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
|
|
#ifndef HEAP_H_
|
||
|
|
#define HEAP_H_
|
||
|
|
|
||
|
|
#include <heap/_liballoc.h>
|
||
|
|
#include <mango/types.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
typedef enum heap_result {
|
||
|
|
HEAP_OK = 0,
|
||
|
|
HEAP_ERR_NO_MEMORY,
|
||
|
|
HEAP_ERR_INVALID_ARGUMENT,
|
||
|
|
} heap_result_t;
|
||
|
|
|
||
|
|
typedef struct heap {
|
||
|
|
kern_handle_t heap_region;
|
||
|
|
/* amount of space requested from the heap by the user */
|
||
|
|
size_t heap_req_alloc;
|
||
|
|
/* amount of space requested from the system by the heap */
|
||
|
|
size_t heap_sys_alloc;
|
||
|
|
/* base address of the heap */
|
||
|
|
virt_addr_t heap_base;
|
||
|
|
|
||
|
|
union {
|
||
|
|
struct {
|
||
|
|
struct liballoc_major *l_memRoot;
|
||
|
|
struct liballoc_major *l_bestBet;
|
||
|
|
|
||
|
|
unsigned int l_pageSize;
|
||
|
|
unsigned int l_pageCount;
|
||
|
|
unsigned long long l_allocated;
|
||
|
|
unsigned long long l_inuse;
|
||
|
|
|
||
|
|
long long l_warningCount;
|
||
|
|
long long l_errorCount;
|
||
|
|
long long l_possibleOverruns;
|
||
|
|
} heap_liballoc;
|
||
|
|
};
|
||
|
|
} heap_t;
|
||
|
|
|
||
|
|
extern kern_status_t heap_init(heap_t *heap, size_t size);
|
||
|
|
extern kern_status_t heap_destroy(heap_t *heap);
|
||
|
|
|
||
|
|
extern void *heap_alloc(heap_t *heap, size_t sz);
|
||
|
|
extern void *heap_realloc(heap_t *heap, void *p, size_t sz);
|
||
|
|
extern void *heap_calloc(heap_t *heap, size_t num, size_t itemsz);
|
||
|
|
extern void heap_free(heap_t *heap, void *p);
|
||
|
|
|
||
|
|
extern void *heap_expand(heap_t *heap, size_t size);
|
||
|
|
|
||
|
|
#endif
|