kmalloc/kfree interface

This commit is contained in:
Taku Shimosawa
2011-11-13 15:18:20 +09:00
parent c5cdd121f6
commit ca96e1f818
2 changed files with 15 additions and 4 deletions

View File

@ -1,7 +1,9 @@
#ifndef __HEADER_KMALLOC_H #ifndef __HEADER_KMALLOC_H
#define __HEADER_KMALLOC_H #define __HEADER_KMALLOC_H
void *kmalloc(int size, int flag); #include <aal/mm.h>
void *kmalloc(int size, enum aal_mc_ap_flag flag);
void kfree(void *ptr); void kfree(void *ptr);
#endif #endif

View File

@ -1,4 +1,5 @@
#include <kmsg.h> #include <kmsg.h>
#include <kmalloc.h>
#include <string.h> #include <string.h>
#include <aal/cpu.h> #include <aal/cpu.h>
#include <aal/debug.h> #include <aal/debug.h>
@ -38,8 +39,8 @@ void free_pages(void *va, int npages)
} }
static struct aal_mc_pa_ops allocator = { static struct aal_mc_pa_ops allocator = {
.alloc = allocate_pages, .alloc_page = allocate_pages,
.free = free_pages, .free_page = free_pages,
}; };
static void page_fault_handler(unsigned long address, void *regs) static void page_fault_handler(unsigned long address, void *regs)
@ -81,6 +82,12 @@ static void page_allocator_init(void)
aal_mc_set_page_fault_handler(page_fault_handler); aal_mc_set_page_fault_handler(page_fault_handler);
} }
void register_kmalloc(void)
{
allocator.alloc = kmalloc;
allocator.free = kfree;
}
static struct aal_page_allocator_desc *vmap_allocator; static struct aal_page_allocator_desc *vmap_allocator;
static void virtual_allocator_init(void) static void virtual_allocator_init(void)
@ -131,9 +138,11 @@ void kmalloc_init(void)
h->next = &v->free_list; h->next = &v->free_list;
h->size = 0; h->size = 0;
register_kmalloc();
} }
void *kmalloc(int size, int flag) void *kmalloc(int size, enum aal_mc_ap_flag flag)
{ {
struct cpu_local_var *v = get_this_cpu_local_var(); struct cpu_local_var *v = get_this_cpu_local_var();
struct malloc_header *h = &v->free_list, *prev, *p; struct malloc_header *h = &v->free_list, *prev, *p;