1 #ifndef __TOOLS_LINUX_VMALLOC_H
2 #define __TOOLS_LINUX_VMALLOC_H
7 #include "linux/slab.h"
8 #include "tools-util.h"
11 #define PAGE_KERNEL_EXEC 1
13 #define vfree(p) free(p)
15 static inline void *__vmalloc(unsigned long size, gfp_t gfp_mask)
20 size = round_up(size, PAGE_SIZE);
23 run_shrinkers(gfp_mask, i != 0);
25 p = aligned_alloc(PAGE_SIZE, size);
26 if (p && gfp_mask & __GFP_ZERO)
28 } while (!p && i++ < 10);
33 static inline void *vmalloc_exec(unsigned long size, gfp_t gfp_mask)
37 p = __vmalloc(size, gfp_mask);
41 if (mprotect(p, size, PROT_READ|PROT_WRITE|PROT_EXEC)) {
49 static inline void *vmalloc(unsigned long size)
51 return __vmalloc(size, GFP_KERNEL);
54 static inline void *vzalloc(unsigned long size)
56 return __vmalloc(size, GFP_KERNEL|__GFP_ZERO);
59 #endif /* __TOOLS_LINUX_VMALLOC_H */