阅读《Linux Kernel Delelop》时遇到的问题
时间:2011-01-21
来源:互联网
以下是讲述系统调用的实现的所给的例子:
/*
* silly_copy - utterly worthless syscall that copies the len bytes from
* 'src' to 'dst' using the kernel as an intermediary in the copy for no
* good reason. But it makes for a good example!
*/
asmlinkage long sys_silly_copy(unsigned long *src,
unsigned long *dst,
unsigned long len)
{
unsigned long buf;
/* fail if the kernel wordsize and user wordsize do not match */
if (len != sizeof(buf))
return -EINVAL;
/* copy src, which is in the user's address space, into buf */
if (copy_from_user(&buf, src, len))
return -EFAULT;
/* copy buf into dst, which is in the user's address space */
if (copy_to_user(dst, &buf, len))
return -EFAULT;
/* return amount of data copied */
return len;
}
标红部分不明白, len是要复制数据的长度 它和sizeof(buf)得到long型字节数比较 怎么就能确定用户空间和内核空间的字长是否相等,这两个量在逻辑上好像没有联系
/*
* silly_copy - utterly worthless syscall that copies the len bytes from
* 'src' to 'dst' using the kernel as an intermediary in the copy for no
* good reason. But it makes for a good example!
*/
asmlinkage long sys_silly_copy(unsigned long *src,
unsigned long *dst,
unsigned long len)
{
unsigned long buf;
/* fail if the kernel wordsize and user wordsize do not match */
if (len != sizeof(buf))
return -EINVAL;
/* copy src, which is in the user's address space, into buf */
if (copy_from_user(&buf, src, len))
return -EFAULT;
/* copy buf into dst, which is in the user's address space */
if (copy_to_user(dst, &buf, len))
return -EFAULT;
/* return amount of data copied */
return len;
}
标红部分不明白, len是要复制数据的长度 它和sizeof(buf)得到long型字节数比较 怎么就能确定用户空间和内核空间的字长是否相等,这两个量在逻辑上好像没有联系
作者: Yuek_Lee 发布时间: 2011-01-21
注释说得很清楚啊
len 就是用户空间 unsinged long的size。
len 就是用户空间 unsinged long的size。
作者: baozhao 发布时间: 2011-01-21
就是拿它做跳板吧,长度当然应该吻合了
作者: amarant 发布时间: 2011-01-21
len 的值就是你用户空间传递的内存的大小。因为这个函数可能就是传递一个 unsigned long 的数值,但是需要读取和写入,因此使用指针形式。
用户空间调用的时候,len 的值应该是 sizeof(unsigned long)。这里判断一下,防止读写出现错误。
用户空间调用的时候,len 的值应该是 sizeof(unsigned long)。这里判断一下,防止读写出现错误。
作者: Godbach 发布时间: 2011-01-21
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28