diff options
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/compiler.h | 4 | ||||
-rw-r--r-- | include/linux/mempool.h | 28 | ||||
-rw-r--r-- | include/linux/slab.h | 5 | ||||
-rw-r--r-- | include/linux/vmalloc.h | 37 |
4 files changed, 55 insertions, 19 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index e5c31a6c..915a6f88 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -166,4 +166,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s #define flush_cache_vmap(start, end) do { } while (0) #define flush_cache_vunmap(start, end) do { } while (0) +#ifdef __x86_64 +#define CONFIG_X86_64 y +#endif + #endif /* _TOOLS_LINUX_COMPILER_H */ diff --git a/include/linux/mempool.h b/include/linux/mempool.h index ddf6f941..37d81492 100644 --- a/include/linux/mempool.h +++ b/include/linux/mempool.h @@ -10,8 +10,14 @@ struct kmem_cache; +typedef void * (mempool_alloc_t)(gfp_t gfp_mask, void *pool_data); +typedef void (mempool_free_t)(void *element, void *pool_data); + typedef struct mempool_s { - size_t elem_size; + size_t elem_size; + void *pool_data; + mempool_alloc_t *alloc; + mempool_free_t *free; } mempool_t; static inline bool mempool_initialized(mempool_t *pool) @@ -60,24 +66,22 @@ static inline int mempool_init_kmalloc_pool(mempool_t *pool, int min_nr, size_t return 0; } -static inline mempool_t *mempool_create_kmalloc_pool(int min_nr, size_t size) -{ - mempool_t *pool = malloc(sizeof(*pool)); - pool->elem_size = size; - return pool; -} - static inline int mempool_init_page_pool(mempool_t *pool, int min_nr, int order) { pool->elem_size = PAGE_SIZE << order; return 0; } -static inline mempool_t *mempool_create_page_pool(int min_nr, int order) +static inline int mempool_init(mempool_t *pool, int min_nr, + mempool_alloc_t *alloc_fn, + mempool_free_t *free_fn, + void *pool_data) { - mempool_t *pool = malloc(sizeof(*pool)); - pool->elem_size = PAGE_SIZE << order; - return pool; + pool->elem_size = (size_t) pool_data; + pool->pool_data = pool_data; + pool->alloc = alloc_fn; + pool->free = free_fn; + return 0; } #endif /* _LINUX_MEMPOOL_H */ diff --git a/include/linux/slab.h b/include/linux/slab.h index 58fb73ed..d0d8790d 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -43,9 +43,6 @@ static inline void *krealloc(void *old, size_t size, gfp_t flags) #define kcalloc(n, size, flags) calloc(n, size) #define kmalloc_array(n, size, flags) calloc(n, size) -#define vmalloc(size) malloc(size) -#define vzalloc(size) calloc(1, size) - #define kfree(p) free(p) #define kvfree(p) free(p) #define kzfree(p) free(p) @@ -89,8 +86,6 @@ do { \ #define VM_NO_GUARD 0x00000040 /* don't add guard page */ #define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */ -#define PAGE_KERNEL 0 - static inline void vunmap(const void *addr) {} static inline void *vmap(struct page **pages, unsigned int count, diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index eb6284d7..debdcedb 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -1,8 +1,41 @@ #ifndef __TOOLS_LINUX_VMALLOC_H #define __TOOLS_LINUX_VMALLOC_H -#define vmalloc(size) malloc(size) -#define __vmalloc(size, flags, prot) malloc(size) +#include <stdlib.h> +#include <sys/mman.h> + +#include "tools-util.h" + +#define PAGE_KERNEL 0 +#define PAGE_KERNEL_EXEC 1 + #define vfree(p) free(p) +static inline void *__vmalloc(unsigned long size, gfp_t gfp_mask, unsigned prot) +{ + void *p = aligned_alloc(PAGE_SIZE, size); + + if (p && prot == PAGE_KERNEL_EXEC) { + if (mprotect(p, size, PROT_READ|PROT_WRITE|PROT_EXEC)) { + vfree(p); + p = NULL; + } + } + + if (p && (gfp_mask & __GFP_ZERO)) + memset(p, 0, size); + + return p; +} + +static inline void *vmalloc(unsigned long size) +{ + return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL); +} + +static inline void *vzalloc(unsigned long size) +{ + return __vmalloc(size, GFP_KERNEL|__GFP_ZERO, PAGE_KERNEL); +} + #endif /* __TOOLS_LINUX_VMALLOC_H */ |