我需要将整数传递给内核模块,在那里计算 sin 并返回结果。
首先,内核有内置的 sin fixp_t fixp_sin(unsigned int degrees)
函数,它返回定点数(可以是负数)。
所以,我的问题是:如果我使用 ioctl 将整数传递给内核模块,计算 sin,我如何返回负结果?
ioctl 将负返回值检测为错误。
最佳答案
I need to pass integer to kernel module, calculate sin there and return result.
不是将整数值传递给 ioctl()
,而是可以传递结构。此结构可以具有输入和输出数据字段。无需处理 ioctl()
返回值。
将结构传递给 char 驱动程序的 ioctl() 示例
https://github.com/jeyaramvrp/kernel-module-programming/tree/master/sample-char-dir
关于c - 如何使用 ioctl 将负整数作为有效结果返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35002881/