mprotect()类似于Linux内核中的功能

Dav*_*ave 6 linux kernel mprotect

我在一个Linux内核模块中,比如说,我分配了一些内存vmalloc().我想让内存具有读,写和执行权限.干净,适当的方式是什么?基本上,这通常相当于调用mprotect(),但在内核空间中.

如果我做的页面走,pgd_offset(),pud_offset(),pmd_offset(),pte_offset_map(),然后pte_mkwrite(),我碰上链接错误,当我试图在2.6.39.此外,似乎如果我正在进行页面漫步,它是一个黑客,应该有一个更清洁,更合适的方法.

我的内核模块将是一个可加载模块,因此我无法使用内部符号.

在此先感谢您的指导.

use*_*056 5

这个问题有一个很好的答案:https://unix.stackexchange.com/questions/450557/is-there-any-function-analogous-to-mprotect-in-the-linux-kernel

asm-generic/set_memory.h:int set_memory_ro(unsigned long addr, int numpages);
asm-generic/set_memory.h:int set_memory_rw(unsigned long addr, int numpages);
asm-generic/set_memory.h:int set_memory_x(unsigned long addr, int numpages);
asm-generic/set_memory.h:int set_memory_nx(unsigned long addr, int numpages);
Run Code Online (Sandbox Code Playgroud)

它们在这里定义:https ://elixir.bootlin.com/linux/v4.3/source/arch/x86/include/asm/cacheflush.h#L47