如何在 Linux 内核模块中分配可执行页面? [英] How to allocate an executable page in a Linux kernel module?

查看:32
本文介绍了如何在 Linux 内核模块中分配可执行页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Linux 内核模块,我想分配一个可执行页面.普通的 kmalloc() 在不可执行的页面中返回一个指针,在那里执行代码时我会遇到内核恐慌.它必须在 Ubuntu Karmic x86、2.6.31-20-generic-pae 上运行.

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.

推荐答案

#include <linux/vmalloc.h>
#include <asm/pgtype_types.h>
...
char *p = __vmalloc(byte_size, GFP_KERNEL, PAGE_KERNEL_EXEC);
...
if (p != NULL) vfree(p);

这篇关于如何在 Linux 内核模块中分配可执行页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆