[英]How to return array in C from kernel to user with system call
I already did the hard part of adding a system call to the linux kernel. 我已经完成了向Linux内核添加系统调用的艰巨任务。 I need to return the following array: unsigned int counts[4]
我需要返回以下数组: unsigned int counts[4]
I can reference the array as curr->counts, but I don't think there is a return value for that, and I think it is bad to give a pointer into kernel space? 我可以将数组引用为curr-> counts,但是我不认为该值有返回值,并且我认为向内核空间提供指针是不好的吗?
Instead I'm thinking the best way is to return void and pass by parameter. 相反,我在想最好的方法是返回void并按参数传递。 Is that the way to go? 那是路要走吗?
See the kernel routine copy_to_user ()
. 参见内核例程copy_to_user ()
。 Design the system call interface to pass a parameter which is a pointer where to return the data. 设计系统调用接口以传递一个参数,该参数是一个指向返回数据的指针。
You are trying to do something like the read()
or gettimeofday()
system calls, right? 您正在尝试执行类似read()
或gettimeofday()
系统调用的操作,对吗? Those all return more than 32-bit results by using copy_to_user()
. 这些都使用copy_to_user()
返回超过32位的结果。
我会说是的-将数据复制到用户缓冲区可以避免各种问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.