gpt4 book ai didi

linux - copy_to_user 在链表 linux 内核模块中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:01 25 4
gpt4 key购买 nike

我在编写 Linux 内核模块时遇到了 copy_to_user 宏的问题。使用此代码:

int err;
struct myElement *el;
list_for_each(cursor,&headList){
el=list_entry(cursor,struct myElement,link);
printk("data ptr= %s, data len=%d\n",el->data,el->i);
err=copy_to_user(buforUz,el->data,el->i);
printk("err=%d\n",err);
}

当我使用 cut 时,我可以使用 dmesg 检查 printk 是否显示正确的值(之前保存在分配内存中的字符串、指向存储字符串的内存的指针和字符串长度),但 copy_to_user 不复制任何内容。当我使用 strace 时,它​​显示它复制了 0 个字节:

read(3, "", 65536)                      = 0

这个问题可能是什么原因造成的?

最佳答案

我发现了问题。我的问题是我没有返回我读过的长度,而是 0,这是错误的,这就是它没有显示任何内容的原因。

关于linux - copy_to_user 在链表 linux 内核模块中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41104852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com