从分配内核的用户存储空间 [英] allocate user-space memory from kernel
本文介绍了从分配内核的用户存储空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图调用
sys_readlink(const char __user *path, char __user *buf, int bufsiz)
直接,但得到EFAULT错误code。出现此错误的原因的 BUF 的从内核空间指向的内存。
directly, but get EFAULT error code. This error appears because buf points to memory from kernel-space.
那么,有没有从内核分配用户存储空间可能的方式?
So, is there possible way to allocate user-space memory from kernel ?
的kmalloc(大小,GFP_USER)
类似于的kmalloc(大小,GFP_KERNEL)
并返回指针到内核内存。
kmalloc(size, GFP_USER)
is similar to kmalloc(size, GFP_KERNEL)
and returns pointer to kernel memory.
推荐答案
您可以暂时禁用内存地址的有效性通过检查 set_fs
You can temporarily disable memory address validity checking by using set_fs
mm_segment_t old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
/* Your syscall here */
set_fs(old_fs);
这篇关于从分配内核的用户存储空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文