免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 1589 | 回复: 10
打印 上一主题 下一主题

请教诸位高手,小弟想实现内核空间和用户空间的公享内存,该怎么做? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-02 14:45 |只看该作者 |倒序浏览
请教诸位高手,小弟想实现内核空间和用户空间的公享内存来避免内核和用户空间的拷贝,请问该如何实现?
很急,多谢了。

论坛徽章:
0
2 [报告]
发表于 2006-09-02 15:59 |只看该作者
恰好我有同样的问题,找到obrire几个月前有贴说在内核kmalloc出连续内存来,告诉app地址和长度,直接open /dev/mem, lseek 到这个地址,然后memset memcpy。我没有试过,如果你成功了别忘了告诉大家。

论坛徽章:
0
3 [报告]
发表于 2006-09-04 14:52 |只看该作者
You could kmalloc some memory in kernel, and pass this memory's start address and length to user space by proc filesystem.

Then user process could read the memory parameter from proc, and use mmap function to map this memory to its virtual address space.

Now, you can use this memory to transfer data between user space and kernel space.

Last, you must pay attention the synchronese in the process of transfering data.

论坛徽章:
0
4 [报告]
发表于 2006-09-04 16:34 |只看该作者
to SNOW_INSKY,

void  *  mmap(void *start, size_t length, int prot , int flags, int fd,  off_t offset);

用户程序调用mmap用哪个参数去MAP内核kmalloc返回的从/proc得到的内存(比如0xc8001240)?

论坛徽章:
0
5 [报告]
发表于 2006-09-04 18:32 |只看该作者
原帖由 思一克 于 2006-9-4 16:34 发表
to SNOW_INSKY,

void  *  mmap(void *start, size_t length, int prot , int flags, int fd,  off_t offset);

用户程序调用mmap用哪个参数去MAP内核kmalloc返回的从/proc得到的内存(比如0xc8001240)?

我觉得这个时候不需要区别是否是内核了吧?start就是0xc8001240,没试过。

论坛徽章:
0
6 [报告]
发表于 2006-09-04 22:38 |只看该作者

谢谢大家

谢谢大家的帮助。
不过,我想实现是添加的内核模块和用户程序之间的公享内存。诸位大侠提到的方法都是驱动和用户程序间实现内存公享的方法吧?
不知道内核模块和用户程序之间的公享内存是否能实现?能的话该怎么实现呢?
请教了,多谢

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
7 [报告]
发表于 2006-09-05 08:31 |只看该作者

论坛徽章:
0
8 [报告]
发表于 2006-09-05 14:58 |只看该作者

回复 7楼 mq110 的帖子

you can malloc memort by kmalloc in the kernel space ,and then you can output the head address by character device or proc filesystem,and then in the user space ,you can read the character device or the proc filesystem to find the start address of the memory you malloc,then call mmap ,map the memory to the process space ,but in this method ,you must note that the  access of the share memory .

论坛徽章:
0
9 [报告]
发表于 2006-09-05 17:04 |只看该作者
原帖由 fire114 于 2006-9-4 22:38 发表
谢谢大家的帮助。
不过,我想实现是添加的内核模块和用户程序之间的公享内存。诸位大侠提到的方法都是驱动和用户程序间实现内存公享的方法吧?
不知道内核模块和用户程序之间的公享内存是否能实现?能的话该怎么 ...


内核模块和驱动有什么区别? 你给你的模块一个 io 接口不就可以 mmap 了?

论坛徽章:
0
10 [报告]
发表于 2006-09-05 22:36 |只看该作者

谢谢大家,谢谢斑竹

不过我有个疑问想确认,这个公享的内存应该是双向的吧??
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP