简体   繁体   English

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

[英]Sharing memory from the linux kernel to user space in single user mode

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等来实现,但是在单用户模式下,对于嵌入式设备,没有办法共享简单的指针吗?

"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. 在特殊文件或设备节点上使用mmap()是最自然的方法。

The pseudo sysfs file system ( /sys ) was intended for this very purpose (expose kernel data to userspace). 伪sysfs文件系统( /sys )用于此目的(将内核数据公开给用户空间)。 You may also write to these data structures from user space. 您也可以从用户空间写入这些数据结构。

Check out Greg Kroah-Hartman's Driver Tutorial 查看Greg Kroah-Hartman的驱动程序指南

Read SysFS Documentation 阅读SysFS文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM