remap_pfn_range如何将内核内存重新映射到用户空间? [英] How remap_pfn_range remaps kernel memory to user space?
问题描述
remap_pfn_range
函数(在驱动程序的mmap
调用中使用)可用于将内核内存映射到用户空间.怎么做?谁能解释确切的步骤?内核模式是特权模式(PM),而用户空间是非特权(NPM).在PM中,CPU可以访问所有内存,而在NPM中,某些内存是受限制的-CPU无法访问.调用remap_pfn_range
时,用户空间现在可以访问仅限于PM的那部分内存了吗?
remap_pfn_range
function (used in mmap
call in driver) can be used to map kernel memory to user space. How is it done? Can anyone explain precise steps? Kernel Mode is a privileged mode (PM) while user space is non privileged (NPM). In PM CPU can access all memory while in NPM some memory is restricted - cannot be accessed by CPU. When remap_pfn_range
is called, how is that range of memory which was restricted only to PM is now accessible to user space?
在remap_pfn_range
代码处,有pgprot_t struct
.这是与保护映射有关的结构.什么是保护映射?是上述问题的答案吗?
Looking at remap_pfn_range
code there is pgprot_t struct
. This is protection mapping related struct. What is protection mapping? Is it the answer to above question?
推荐答案
真的很简单,内核内存(通常)仅具有一个页面表项,其中特定于体系结构的位显示:此页面表项仅在CPU处于内核模式".
It's simple really, kernel memory (usually) simply has a page table entry with the architecture specific bit that says: "this page table entry is only valid while the CPU is in kernel mode".
remap_pfn_range的作用是创建另一个页表条目,并为未设置该位的同一物理内存页使用不同的虚拟地址.
What remap_pfn_range does is create another page table entry, with a different virtual address to the same physical memory page that doesn't have that bit set.
通常,这是个坏主意:-)
Usually, it's a bad idea btw :-)
这篇关于remap_pfn_range如何将内核内存重新映射到用户空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!