diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2018-10-02 21:26:48 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2018-10-02 21:26:48 -0400 |
commit | c66410f6319284b94e21758539ac25bfb4694d3a (patch) | |
tree | 73c1ac0da5c6507d4111cf967549184c964552c9 /src/kernel/heap.h | |
parent | 231c796f50ac4dc277978a6568e8083412c765e0 (diff) |
folder restructure
Diffstat (limited to 'src/kernel/heap.h')
-rw-r--r-- | src/kernel/heap.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/kernel/heap.h b/src/kernel/heap.h new file mode 100644 index 0000000..c817e4d --- /dev/null +++ b/src/kernel/heap.h @@ -0,0 +1,61 @@ +/** + * @file heap.h + * A basic memory manager + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef HEAP_H_ +#define HEAP_H_ + +#include <stdint.h> + +/** + * Initializes memory management of the given heap. + * No overflow stuff is done, so... be careful. + * @param buf The heap to use for allocations + */ +void heap_init(void *buf); + +/** + * Returns the amount of free, allocatable memory, in bytes. + * @return Amount of free memory in bytes + */ +uint32_t heap_free(void); + +/** + * Allocates a chunk of memory. + * @param size How many bytes to claim + * @return Pointer to the allocated buffer + */ +void *malloc(uint32_t size); + +/** + * Allocates and zeros a chunk of memory. + * @param count How many of whatever to allocate + * @param size Byte count of each whatever + * @return Pointer to the allocated buffer + */ +void *calloc(uint32_t count, uint32_t size); + +/** + * Frees the buffer allocated through malloc/calloc. + * Please don't double-free. + * @param The buffer to release + */ +void free(void *buf); + +#endif // HEAP_H_ |