How to allocate an executable page in a Linux kernel module?
c, executable, linux-kernel, memory-management, virtual-memory
Solution
#include <linux/vmalloc.h>
#include <asm/pgtype_types.h>
...
char *p = __vmalloc(byte_size, GFP_KERNEL, PAGE_KERNEL_EXEC);
...
if (p != NULL) vfree(p);
Problem
I'm writing a Linux kernel module, and I'd like to allocate an executable page. Plain `kmalloc()` returns a pointer within a non-executable page, and I get a kernel panic when executing code there. It has to work on Ubuntu Karmic x86, 2.6.31-20-generic-pae.