From 7a3e77c82dba79269b051d61a231a2cd88538b10 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Nov 2013 11:47:53 +0100 Subject: [PATCH] palloc()/pfree() replace our old kmalloc()/kfree() with PAGE_SIZE granularity --- include/metalsvm/stdlib.h | 52 +++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/include/metalsvm/stdlib.h b/include/metalsvm/stdlib.h index 1796fee0..9903c60f 100644 --- a/include/metalsvm/stdlib.h +++ b/include/metalsvm/stdlib.h @@ -29,9 +29,7 @@ #ifndef __STDLIB_H__ #define __STDLIB_H__ -#include -#include -#include +#include #ifdef __cplusplus extern "C" { @@ -55,46 +53,42 @@ extern "C" { void NORETURN abort(void); -/** @brief Kernel's memory allocator function. +/** @brief General page allocator function * - * This will just call mem_allocation with - * the flags MAP_KERNEL_SPACE and MAP_HEAP. - * - * @return Pointer to the new memory range - */ -void* kmalloc(size_t); - -/** @brief Kernel's more general memory allocator function. - * - * This function lets you choose flags for the newly allocated memory. + * This function allocates and maps whole pages. + * To avoid fragmentation you should use kmalloc() and kfree()! * * @param sz Desired size of the new memory - * @param flags Flags to specify + * @param flags Flags to for map_region(), vma_add() * * @return Pointer to the new memory range */ -void* mem_allocation(size_t sz, uint32_t flags); +void* palloc(size_t sz, uint32_t flags); -/** @brief Free memory +/** @brief Free general kernel memory * - * The kernel malloc doesn't track how - * much memory was allocated for which pointer, + * The pmalloc() doesn't track how much memory was allocated for which pointer, * so you have to specify how much memory shall be freed. - */ -void kfree(void*, size_t); - -/** @brief Create a new stack for a new task * - * @return start address of the new stack + * @param sz The size which should freed */ -void* create_stack(void); +void pfree(void* addr, size_t sz); -/** @brief Delete stack of a finished task +/** @brief The memory allocator function * - * @param addr Pointer to the stack - * @return 0 on success + * This allocator uses a buddy system to manage free memory. + * + * @return Pointer to the new memory range */ -int destroy_stack(task_t* addr); +void* kmalloc(size_t sz); + +/** @brief The memory free function + * + * Releases memory allocated by malloc() + * + * @param addr The address to the memory block allocated by malloc() + */ +void kfree(void* addr); /** @brief String to long *