diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-05-12 18:45:15 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-05-12 23:14:24 -0800 |
commit | 565b4a74d6c25c78b0d2b82d9529595fc6269308 (patch) | |
tree | 3e4440a60c5f8519352ce5b6c587a7d1a79c4655 /include/linux/vmalloc.h | |
parent | a588eb0d9e30dffa4b319a4715c1454ee1d911f1 (diff) |
Update bcachefs sources to 14e9ac5016 bcachefs: btree_iter fastpath
Diffstat (limited to 'include/linux/vmalloc.h')
-rw-r--r-- | include/linux/vmalloc.h | 37 |
1 files changed, 35 insertions, 2 deletions
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 */ |