且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

共享Linux内核模块中的内存,以供用户空间进程访问

更新时间:2023-09-13 18:21:52

您不能使用mmap之类的直接访问机制来安全地执行此操作,因为这样任何人都可以使用它.

You cannot do this securely with a direct access mechanism like mmap, because then anyone can use it.

在Linux中,用户内存和内核内存是独立的,并在单独的地址空间中实现.地址空间是虚拟化的,这意味着地址是从物理内存中抽象出来的.因为地址空间是虚拟化的,所以可以存在许多地址空间.实际上,内核本身位于一个地址空间中,而每个进程都位于其自己的地址空间中.这些地址空间由虚拟内存地址组成,从而允许许多具有独立地址空间的进程引用相当小的物理地址空间(计算机中的物理内存).这不仅方便,而且也很安全,因为每个地址空间都是独立且隔离的,因此很安全.

In Linux, user memory and kernel memory are independent and implemented in separate address spaces. The address spaces are virtualized, meaning that the addresses are abstracted from physical memory. Because the address spaces are virtualized, many can exist. In fact, the kernel itself resides in one address space, and each process resides in its own address space. These address spaces consist of virtual memory addresses, permitting many processes with independent address spaces to refer to a considerably smaller physical address space (the physical memory in the machine). Not only is this convenient, but it's also secure, because each address space is independent and isolated and therefore secure.

但是与此安全相关的费用. 由于每个进程(和内核)可以具有引用物理内存不同区域的相同地址,因此无法立即共享内存.(

But there's a cost associated with this security. Because each process (and the kernel) can have identical addresses that refer to different regions of physical memory, it's not immediately possible to share memory. (source)