123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #pragma once
- #include "mm.h"
- #include <common/glib.h>
- #include <common/printk.h>
- #include <common/kprint.h>
- #include <common/spinlock.h>
- #define SIZEOF_LONG_ALIGN(size) ((size + sizeof(long) - 1) & ~(sizeof(long) - 1))
- #define SIZEOF_INT_ALIGN(size) ((size + sizeof(int) - 1) & ~(sizeof(int) - 1))
- #define ESLAB_NOTNULL 101
- #define ENOT_IN_SLAB 102
- #define ECANNOT_FREE_MEM 103
- struct slab_obj
- {
- struct List list;
-
- struct Page *page;
- ul count_using;
- ul count_free;
-
- void *vaddr;
-
- ul bmp_len;
- ul bmp_count;
- ul *bmp;
- };
- struct slab
- {
- ul size;
- ul count_total_using;
- ul count_total_free;
-
- struct slab_obj *cache_pool_entry;
-
- struct slab_obj *cache_dma_pool_entry;
- spinlock_t lock;
-
- void *(*constructor)(void *vaddr, ul arg);
- void *(*destructor)(void *vaddr, ul arg);
- };
- void *kmalloc(unsigned long size, unsigned long flags);
- unsigned long kfree(void *address);
- struct slab *slab_create(ul size, void *(*constructor)(void *vaddr, ul arg), void *(*destructor)(void *vaddr, ul arg), ul arg);
- ul slab_destroy(struct slab *slab_pool);
- void *slab_malloc(struct slab *slab_pool, ul arg);
- ul slab_free(struct slab *slab_pool, void *addr, ul arg);
- struct slab_obj * kmalloc_create_slab_obj(ul size);
- ul slab_init();
|