palloc()/pfree() replace our old kmalloc()/kfree() with PAGE_SIZE granularity

This commit is contained in:
Steffen Vogel 2013-11-20 11:47:53 +01:00
parent 9018781eee
commit 7a3e77c82d

View file

@ -29,9 +29,7 @@
#ifndef __STDLIB_H__ #ifndef __STDLIB_H__
#define __STDLIB_H__ #define __STDLIB_H__
#include <metalsvm/config.h> #include <metalsvm/stddef.h>
#include <metalsvm/tasks_types.h>
#include <asm/stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -55,46 +53,42 @@ extern "C" {
void NORETURN abort(void); void NORETURN abort(void);
/** @brief Kernel's memory allocator function. /** @brief General page allocator function
* *
* This will just call mem_allocation with * This function allocates and maps whole pages.
* the flags MAP_KERNEL_SPACE and MAP_HEAP. * To avoid fragmentation you should use kmalloc() and kfree()!
*
* @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.
* *
* @param sz Desired size of the new memory * @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 * @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 * The pmalloc() doesn't track how much memory was allocated for which pointer,
* much memory was allocated for which pointer,
* so you have to specify how much memory shall be freed. * 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 * This allocator uses a buddy system to manage free memory.
* @return 0 on success *
* @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 /** @brief String to long
* *