Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux ioctl return value interpreted by who?

Tags:

ioctl

I'm working with a custom kernel char device which sometimes returns large negative values (around the thousands, say -2000) for its ioctl().

In userspace, I don't get these values returned from the ioctl call. Instead I get a return value of -1 back with errno set to the negated value from the kernel module (+2000).

As far as I can read and google, __syscall_return() is the macro which is supposed to interpret negative return values as errors. But, it only seems to look for values between -1 and -125. So I didn't expect these large negative values to be translated.

Where are these return values translated? Is it expected behaviour?

I am on Linux 2.6.35.10 with EGLIBC 2.11.3-4+deb6u6.

like image 329
Alexander Torstling Avatar asked Mar 10 '26 12:03

Alexander Torstling


1 Answers

The translation and move to errno occur on the libc level. Both Gnu libc and μClibc treat negative numbers down to at least -4095 as error conditions, per http://www.makelinux.net/ldd3/chp-6-sect-1

See https://github.molgen.mpg.de/git-mirror/glibc/blob/85b290451e4d3ab460a57f1c5966c5827ca807ca/sysdeps/unix/sysv/linux/aarch64/ioctl.S for the Gnu libc implementation of ioctl.

like image 136
BRPocock Avatar answered Mar 16 '26 07:03

BRPocock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!