从内核分配用户空间内存 [英] allocate user-space memory from kernel

查看:11
本文介绍了从内核分配用户空间内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打电话

sys_readlink(const char __user *path, char __user *buf, int bufsiz)

直接,但得到 EFAULT 错误代码.出现此错误是因为 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(size, GFP_USER) 类似于 kmalloc(size, GFP_KERNEL)并返回指向内核内存的指针.

kmalloc(size, GFP_USER) is similar to kmalloc(size, GFP_KERNEL) and returns pointer to kernel memory.

推荐答案

您可以使用 set_fs

mm_segment_t old_fs;

old_fs = get_fs();
set_fs(KERNEL_DS);
/* Your syscall here */
set_fs(old_fs);

这篇关于从内核分配用户空间内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆