|
|
Subscribe / Log in / New account

A sys_poll() ABI tweak

By Jonathan Corbet
February 22, 2012
The poll() system call has three parameters, one of which is a timeout value specifying an upper bound (in milliseconds) for how long the process will wait. The manual page indicates that the type of this value is int. For reasons lost in history, though, the kernel's internal implementation of poll() has always expected the timeout value to be a long integer. And that has created a source of occasional bugs.

Most of the time, things just work. The int and long types tend to be the same on most architectures, and, in cases where they are different, glibc sign-extends the timeout value appropriately. Things go wrong, though, when a 32-bit process is running on an x86-64 system. In that case, the 32-bit sys_poll() function just passes the timeout value directly to the native kernel version, without sign extension. So if the timeout value is negative (an indication that poll() should wait forever if need be), the kernel will eventually see a large, positive timeout instead.

There are various ways this problem could be fixed. What Linus has chosen to do, though, is to just change the type of the timeout parameter to int inside the kernel. Since the timeout is now a 32-bit quantity on all systems, that particular source of confusion is removed. There is a small risk to this approach, though: it is possible that some program somewhere was actually making use of 64-bit timeouts. Doing so would require replacing or bypassing glibc (because its sign extension makes 64-bit timeouts unusable), so it's unlikely that anybody has bothered, but one never knows. If this change were to break a real application, it would have to be reverted in favor of a more complicated solution.

Linus's patch was merged for 3.3-rc5, so anybody who objects has a few weeks to make their concerns known.

Index entries for this article
KernelDevelopment model/User-space ABI


to post comments

A sys_poll() ABI tweak

Posted Feb 26, 2012 2:34 UTC (Sun) by jzbiciak (guest, #5246) [Link]

Well, lessee... 2 billion milliseconds is 2 million seconds. That's just over 23 days. Are there good reasons to have timeouts longer than that that aren't actually infinite?

A sys_poll() ABI tweak

Posted Feb 27, 2012 19:47 UTC (Mon) by dmarti (subscriber, #11625) [Link]

Anyone who's actually using timeouts that long has probably already been tarred and feathered by their QA dept. How would you test them?

A sys_poll() ABI tweak

Posted Mar 5, 2012 23:45 UTC (Mon) by landley (guest, #6789) [Link] (2 responses)

No, int and long _aren't_ the same size on "most" architectures. They're the same size on 32 bit architectures, different on 64 bit. There's a standard for this, which Linux follows (and MacOS X, and most other unix variants):

http://www.unix.org/whitepapers/64bit.html

Here's the rationale:

http://www.unix.org/version2/whatsnew/lp64_wp.html

And here's the insane legacy reasons Windows decided to do something else instead:

http://blogs.msdn.com/b/oldnewthing/archive/2005/01/31/36...

Rob

A sys_poll() ABI tweak

Posted Mar 6, 2012 7:03 UTC (Tue) by khim (subscriber, #9252) [Link] (1 responses)

No, int and long _aren't_ the same size on "most" architectures.

Of course they are!

They're the same size on 32 bit architectures, different on 64 bit.

Not always and anyway: number of 32 bit architectures dwarfs the number of 64 bit architectures, so what's your point?

A sys_poll() ABI tweak

Posted Mar 7, 2012 10:39 UTC (Wed) by sdalley (subscriber, #18550) [Link]

The quality of posts does vary, doesn't it.

After reading landley's GP, and the references he supplied, I understand the subtleties of the actual situation.

After reading khim's post, I am left completely uninformed, and with the strong impression that the poster is an arrogant twerp. It's only an impression, though, and I could be wrong ...


Copyright © 2012, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds