我是一个内核新手,面临着一个奇怪的问题.我编写了一个概念验证计算器系统调用,虽然它适用于大多数计算,但当SUBTRACTION结果介于-1到-256之间时它返回-1.如果有人可以对可能发生的事情有所了解,那就会很感激.下面是系统调用代码.
SYSCALL_DEFINE3(calc, int, a, int, b , char, op) {
int res_int;
switch(op) {
case '+': res_int = a + b;
break;
case '-': res_int = a - b;
break;
case '*': res_int = a * b;
break;
case '/': res_int = (a*1000) / b;
break;
}
printk(KERN_INFO "KERNEL CALC RESULT : %d %c %d = %ld",a, op, b, res_int);
return res_int;
}
Run Code Online (Sandbox Code Playgroud)
编辑:内核版本:Android Linux内核3.10.xxx.平台:Nexus7 ARM EABI.我不明白的是它失败的原因.errno完全没用,因为它将-res_int设置为errno.另外,我不明白为什么只有当res_int为{-1,-256}时才会失败.
a = 1200,b = 1300 op =' - '=> res_int = -100是printk打印-100的示例,但在我的用户空间应用程序中,我收到-1.
看起来当res_int为{-1,-256}时,errno被设置为-res_int. …