[英]How do you return 1, 0, or -1 based off a given integer that is positive, zero or negative using only bitwise C operations and no "-"
[英]How to return negative integer as valid result using ioctl?
我需要將整數傳遞給內核模塊,在那里計算sin並返回結果。
首先,內核具有內置的sin fixp_t fixp_sin(unsigned int degrees)
函數,該函數返回定點數(可以為負數)。
所以,我的問題是:如果我使用ioctl將整數傳遞給內核模塊,計算出sin,我如何才能將負結果返回?
ioctl將負返回值檢測為錯誤。
我需要將整數傳遞給內核模塊,在那里計算sin並返回結果。
可以傳遞結構,而不是將整數值傳遞給ioctl()
。 該結構可以具有輸入和輸出數據字段。 無需弄亂ioctl()
返回值。
將結構傳遞給char驅動程序的示例ioctl()
https://github.com/jeyaramvrp/kernel-module-programming/tree/master/sample-char-dir
ioctl()
絕不返回浮點值。 但是您可以將指針傳遞到可以填充的用戶空間內存:
float f = 1.0;
ioctl(fd, SIOCCALCSIN, &f);
f在這里是一個inout參數,采用您為其計算竇值的值,並用結果覆蓋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.