Note that there are some explanatory texts on larger screens.

plurals
  1. POLinux kernel system call returns -1 instead of {-1, -256}
    primarykey
    data
    text
    <p>I'm a kernel newbie and am facing a weird issue. I have written a proof-of-concept calculator syscall and while it works fine for most computations, it is returning -1 when the SUBTRACTION result is between -1 to -256. If someone can throw some light on what could be happening, would appreciate it. Below is the syscall code.</p> <pre><code> 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; } </code></pre> <p>EDIT: Kernel version: Android Linux Kernel 3.10.xxx. Platform: Nexus7 ARM EABI. What I don't understand is why it is failing. The errno is not useful at all since it is setting -res_int to errno. Also, I don't understand why it is failing only when res_int is {-1, -256}.</p> <p>a=1200, b=1300 op='-' => res_int=-100 is an example case where printk prints -100, but in my userspace app, I receive -1.</p> <p>It looks like when res_int is {-1, -256}, errno is being set to -res_int.</p> <pre><code>root@android:/data/local # ./calc Please enter request in 'num1 oper num2' format: 2.45 - 2.2 returned from syscall with res_int = 250 errno = 22, strerror(errno) = Invalid argument Calculator result = 0.250000 root@android:/data/local # ./calc Please enter request in 'num1 oper num2' format: 2.2 - 2.45 returned from syscall with res_int = -1 errno = 250, strerror(errno) = Unknown error 250 Calculator result = -0.001000 root@android:/data/local # </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload