我正在编写一个 Linux 内核模块,我想分配一个可执行页面。Plainkmalloc()
在一个不可执行的页面中返回一个指针,当在那里执行代码时我得到一个内核恐慌。它必须在 Ubuntu Karmic x86、2.6.31-20-generic-pae 上工作。
问问题
3009 次
2 回答
11
#include <linux/vmalloc.h>
#include <asm/pgtype_types.h>
...
char *p = __vmalloc(byte_size, GFP_KERNEL, PAGE_KERNEL_EXEC);
...
if (p != NULL) vfree(p);
于 2010-03-16T23:31:54.483 回答
1
/**
* vmalloc_exec - allocate virtually contiguous, executable memory
* @size: allocation size
*
* Kernel-internal function to allocate enough pages to cover @size
* the page level allocator and map them into contiguous and
* executable kernel virtual space.
*
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*
* Return: pointer to the allocated memory or %NULL on error
*/
void *vmalloc_exec(unsigned long size)
{
return __vmalloc_node(size, 1, GFP_KERNEL, PAGE_KERNEL_EXEC,
NUMA_NO_NODE, __builtin_return_address(0));
}
于 2019-05-31T02:49:59.873 回答