This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/14362] Incorrect ioctl declaration


http://sourceware.org/bugzilla/show_bug.cgi?id=14362

--- Comment #7 from Linus Torvalds <torvalds@linux-foundation.org> 2013-01-15 17:03:58 UTC ---
(In reply to comment #6)
> Current FreeBSD still uses unsigned long.  Note that the POSIX ioctl is for
> STREAMS only and marked obsolete.  I think this should be considered a
> documentation bug.

Why would you consider it a documentation bug, when it clearly results in real
bugs, and the FreeBSD/Darwin type is *wrong*?

The fact is, casting it to unsigned int is the correct thing to do. There are
actual bug reports about BSD itself due to this exact same problem. 

If you google for it, you'll see this discussed on the gnulib lists, on the
perl mailing lists, etc etc. The FreeBSD/Darwin ioctl() declaration is *wrong*.

And it's not wrong because it actually *uses* 64 bits. No, it is "unsigned
long" just because of historical accidents, back when "long" was 32-bit. 

Even *Apple* knows it is a bug, and actually uses "unsigned int" in their own
code. See for example

 
http://valgrind-variant.googlecode.com/svn-history/r66/trunk/valgrind/coregrind/m_syswrap/syswrap-darwin.c

which has a big Apple copyright, and look for ioctl. Look at the code that
actually reads the arguments (PRE_REG_READ3): the "request" argument is read as
an "unsigned int".

As noted, this does not actually cause problems on Linux, because unlike
FreeBSD, Linux knows what the f*ck it is doing, and just ignores the upper bits
exactly because of possible sign confusion. So I don't care as a Linux person.
But I think glibc should try to actually help Darwin. Because there are ioctl
commands on Darwin that have bit 31 set, and they cause problems.

Go and look at the BSD sys/sys/ioccom.h file itself if you don't believe me.
The constants are clearly 32-bit ones, with IOC_IN being bit#31 (ok, so I don't
know where the actual Darwin SDK is, and I wouldn't want to download it anyway,
but I can find the FreeBSD sources, and there is even a comment there talking
about how the *high* three bits specify the direction. And they are high bits
only in 32-bit. See for example

    http://fxr.watson.org/fxr/source/sys/ioccom.h

The fact is, the FreeBSD/Darwin *declaration* is wrong. And no, it's not just
wrong in the documentation sense. It's wrong in the "real code breaks" sense.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]