以单用户模式从linux内核共享内存到用户空间

时间:2021-06-03 20:52:00

I have a kernel module that allocates memory and I would like to share this memory with a user process. In normal mode we can only do that with: mmap, /proc, shmem, etc. but in single user mode, for embedded devices, isn't there a way to share a simple pointer?

我有一个分配内存的内核模块,我想与用户进程共享这个内存。在正常模式下,我们只能使用mmap、/proc、shmem等,但是在单一用户模式下,对于嵌入式设备,难道没有共享一个简单指针的方法吗?

2 个解决方案

#1


1  

"Single user mode" is a convention defined by userspace. It has no significance to the kernel; all of the same rules apply as "normal mode".

“单用户模式”是用户空间定义的约定。它对内核没有意义;所有的规则都适用于“正常模式”。

If you want to access memory -- any memory -- from userspace, you will need to map that memory into the process somehow. Using mmap() on a special file or device node is the most natural way of doing this.

如果您想从userspace访问内存(任何内存),您需要以某种方式将该内存映射到进程中。在特殊的文件或设备节点上使用mmap()是最自然的方法。

#2


1  

The pseudo sysfs file system (/sys) was intended for this very purpose (expose kernel data to userspace). You may also write to these data structures from user space.

伪sysfs文件系统(/sys)就是为此目的而设计的(向用户空间公开内核数据)。您也可以从用户空间写入这些数据结构。

Check out Greg Kroah-Hartman's Driver Tutorial

看看Greg Kroah-Hartman的驾驶教程

Read SysFS Documentation

阅读SysFS文档

#1


1  

"Single user mode" is a convention defined by userspace. It has no significance to the kernel; all of the same rules apply as "normal mode".

“单用户模式”是用户空间定义的约定。它对内核没有意义;所有的规则都适用于“正常模式”。

If you want to access memory -- any memory -- from userspace, you will need to map that memory into the process somehow. Using mmap() on a special file or device node is the most natural way of doing this.

如果您想从userspace访问内存(任何内存),您需要以某种方式将该内存映射到进程中。在特殊的文件或设备节点上使用mmap()是最自然的方法。

#2


1  

The pseudo sysfs file system (/sys) was intended for this very purpose (expose kernel data to userspace). You may also write to these data structures from user space.

伪sysfs文件系统(/sys)就是为此目的而设计的(向用户空间公开内核数据)。您也可以从用户空间写入这些数据结构。

Check out Greg Kroah-Hartman's Driver Tutorial

看看Greg Kroah-Hartman的驾驶教程

Read SysFS Documentation

阅读SysFS文档