Debian Bug report logs - #504699
libc6: makecontext() on AMD64 does not handle pointers; docs do not make this clear

version graph

Package: manpages-dev; Maintainer for manpages-dev is Martin Schulze <joey@debian.org>; Source for manpages-dev is src:manpages.

Reported by: Paul Evans <leonerd@leonerd.org.uk>

Date: Thu, 6 Nov 2008 11:30:01 UTC

Severity: minor

Fixed in version manpages/3.14-1

Done: Joey Schulze <joey@infodrom.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, GNU Libc Maintainers <debian-glibc@lists.debian.org>:
Bug#504699; Package libc6. (Thu, 06 Nov 2008 11:30:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Evans <leonerd@leonerd.org.uk>:
New Bug report received and forwarded. Copy sent to GNU Libc Maintainers <debian-glibc@lists.debian.org>. (Thu, 06 Nov 2008 11:30:03 GMT) Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Paul Evans <leonerd@leonerd.org.uk>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: libc6: makecontext() on AMD64 does not handle pointers; docs do not make this clear
Date: Thu, 06 Nov 2008 11:27:01 +0000
Package: libc6
Version: 2.7-15
Severity: normal


makecontext() on AMD64 cannot pass pointer arguments to the invoked
function; they get squashed to 32bit values, ignoring the top bits.

I'm aware that the POSIX spec doesn't require the ability to pass
pointers, though it isn't all that clear on the subject.

I've had a variety of C programmers read the makecontext(3) manpage, and
most of them didn't spot the fact it can't do pointers until I
specifically mentioned this fact. The current documentation is
insufficiently clear on the subject.

I'd like to propose either:

 a) Extending makecontext() on AMD64 so it can pass pointers, and add a
    section to the manpage to explain that you cannot portably do this,
    but GNU libc happens to allow it,

or

 b) Explain in the manpage that GNU libc cannot pass pointers.

Naturally I'd prefer option a because that is more useful; without the
ability to pass a pointer, it becomes much harder to actually use the
function to perform useful work in real programs, aside from the tiny
trivial examples usually given.


-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.26-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages libc6 depends on:
ii  libgcc1                       1:4.3.2-1  GCC support library

libc6 recommends no packages.

Versions of packages libc6 suggests:
pn  glibc-doc                     <none>     (no description available)
ii  locales                       2.7-15     GNU C Library: National Language (

-- debconf information:
  glibc/upgrade: true
  glibc/restart-failed:
  glibc/restart-services:




Information forwarded to debian-bugs-dist@lists.debian.org, GNU Libc Maintainers <debian-glibc@lists.debian.org>:
Bug#504699; Package libc6. (Thu, 06 Nov 2008 16:18:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Aurelien Jarno <aurelien@aurel32.net>:
Extra info received and forwarded to list. Copy sent to GNU Libc Maintainers <debian-glibc@lists.debian.org>. (Thu, 06 Nov 2008 16:18:06 GMT) Full text and rfc822 format available.

Message #10 received at 504699@bugs.debian.org (full text, mbox):

From: Aurelien Jarno <aurelien@aurel32.net>
To: Paul Evans <leonerd@leonerd.org.uk>, 504699@bugs.debian.org
Cc: control@bugs.debian.org
Subject: Re: Bug#504699: libc6: makecontext() on AMD64 does not handle pointers; docs do not make this clear
Date: Thu, 6 Nov 2008 17:14:03 +0100
reassign 504699 manpages-dev
severity 504699 minor
thanks

On Thu, Nov 06, 2008 at 11:27:01AM +0000, Paul Evans wrote:
> Package: libc6
> Version: 2.7-15
> Severity: normal
> 
> 
> makecontext() on AMD64 cannot pass pointer arguments to the invoked
> function; they get squashed to 32bit values, ignoring the top bits.
> 
> I'm aware that the POSIX spec doesn't require the ability to pass
> pointers, though it isn't all that clear on the subject.

It is pretty clear from the POSIX specification:

| Before a call is made to makecontext( ), the application shall ensure that the context being
| modified has a stack allocated for it. The application shall ensure that the value of argc matches
| the number of arguments of type int passed to func; otherwise, the behavior is undefined.

The original POSIX specification even has "int" in bold in the text.


> I've had a variety of C programmers read the makecontext(3) manpage, and
> most of them didn't spot the fact it can't do pointers until I
> specifically mentioned this fact. The current documentation is
> insufficiently clear on the subject.
> 
> I'd like to propose either:
> 
>  a) Extending makecontext() on AMD64 so it can pass pointers, and add a
>     section to the manpage to explain that you cannot portably do this,
>     but GNU libc happens to allow it,

This is not possible, as it would break the ABI, something we do not
want, and break the compliance to POSIX.

> or
> 
>  b) Explain in the manpage that GNU libc cannot pass pointers.

It already looks clear to me:

| When this context is later activated (using setcontext(2) or swapcontext()) the function
| func is called, and passed the series of integer (int) arguments that follow  argc;

Again the type of the argument (int) is precised.

Anyway it's not a glibc bug, so I'll reassign it to manpages-dev and
let the maintainer of this package either to close the bug or to precise
the documentation.

> Naturally I'd prefer option a because that is more useful; without the
> ability to pass a pointer, it becomes much harder to actually use the
> function to perform useful work in real programs, aside from the tiny
> trivial examples usually given.
> 
> 
> -- System Information:
> Debian Release: lenny/sid
>   APT prefers testing
>   APT policy: (990, 'testing'), (500, 'unstable')
> Architecture: amd64 (x86_64)
> 
> Kernel: Linux 2.6.26-1-amd64 (SMP w/4 CPU cores)
> Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/bash
> 
> Versions of packages libc6 depends on:
> ii  libgcc1                       1:4.3.2-1  GCC support library
> 
> libc6 recommends no packages.
> 
> Versions of packages libc6 suggests:
> pn  glibc-doc                     <none>     (no description available)
> ii  locales                       2.7-15     GNU C Library: National Language (
> 
> -- debconf information:
>   glibc/upgrade: true
>   glibc/restart-failed:
>   glibc/restart-services:
> 
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-glibc-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> 
> 

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net




Bug reassigned from package `libc6' to `manpages-dev'. Request was from Aurelien Jarno <aurelien@aurel32.net> to control@bugs.debian.org. (Thu, 06 Nov 2008 16:18:08 GMT) Full text and rfc822 format available.

Severity set to `minor' from `normal' Request was from Aurelien Jarno <aurelien@aurel32.net> to control@bugs.debian.org. (Thu, 06 Nov 2008 16:18:09 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#504699; Package manpages-dev. (Thu, 06 Nov 2008 19:51:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Petr Salinger <Petr.Salinger@seznam.cz>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>.

Your message did not contain a Subject field. They are recommended and useful because the title of a $gBug is determined using this field. Please remember to include a Subject field in your messages in future.

(Thu, 06 Nov 2008 19:51:04 GMT) Full text and rfc822 format available.


Message #19 received at 504699@bugs.debian.org (full text, mbox):

From: Petr Salinger <Petr.Salinger@seznam.cz>
To: Paul Evans <leonerd@leonerd.org.uk>, 504699@bugs.debian.org
Cc: debian-glibc@lists.debian.org
Date: Thu, 6 Nov 2008 21:10:16 +0100 (CET)
>>  a) Extending makecontext() on AMD64 so it can pass pointers, and add a
>>     section to the manpage to explain that you cannot portably do this,
>>     but GNU libc happens to allow it,

> This is not possible, as it would break the ABI, something we do not
> want, and break the compliance to POSIX.

It is possible, as far as passing int is unaffected,
all other cases have undefined behaviour in POSIX.
In fact, the needed source change is already in glibc 2.8.

http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/unix/sysv/linux/x86_64/makecontext.c.diff?r1=1.5&r2=1.6&cvsroot=glibc

But it is not possible to pass ints, longs and pointers
in general on all architectures.

Petr




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#504699; Package manpages-dev. (Thu, 06 Nov 2008 21:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to mtk.manpages@gmail.com:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Thu, 06 Nov 2008 21:21:07 GMT) Full text and rfc822 format available.

Message #24 received at 504699@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Petr Salinger" <Petr.Salinger@seznam.cz>, 504699@bugs.debian.org
Cc: "Paul Evans" <leonerd@leonerd.org.uk>, debian-glibc@lists.debian.org
Subject: Re: Bug#504699: (no subject)
Date: Thu, 6 Nov 2008 16:14:45 -0500
I'm the upstream upstream man-pages maintainer.  I'd entertain a patch
to improve the documentation, or if someone can give a clear, simple
explanation of what needs to be changed, I'll do the patch myself.

It sounds like some people on this thread have already done some
digging, and I don't want to repeat their effort from scratch.  Also,
reading the bug thread, it's not clear if, from the point of view of
the reported, things are currently "broken" on AMD64, but will be
fixed in a future glibc release.  I'd appreciate some clarification on
that.

Thanks,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#504699; Package manpages-dev. (Fri, 07 Nov 2008 14:42:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Aurelien Jarno <aurelien@aurel32.net>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Fri, 07 Nov 2008 14:42:03 GMT) Full text and rfc822 format available.

Message #29 received at 504699@bugs.debian.org (full text, mbox):

From: Aurelien Jarno <aurelien@aurel32.net>
To: mtk.manpages@gmail.com
Cc: Petr Salinger <Petr.Salinger@seznam.cz>, 504699@bugs.debian.org, Paul Evans <leonerd@leonerd.org.uk>, debian-glibc@lists.debian.org
Subject: Re: Bug#504699: (no subject)
Date: Fri, 07 Nov 2008 15:41:20 +0100
Michael Kerrisk a écrit :
> I'm the upstream upstream man-pages maintainer.  I'd entertain a patch
> to improve the documentation, or if someone can give a clear, simple
> explanation of what needs to be changed, I'll do the patch myself.
> 
> It sounds like some people on this thread have already done some
> digging, and I don't want to repeat their effort from scratch.  Also,
> reading the bug thread, it's not clear if, from the point of view of
> the reported, things are currently "broken" on AMD64, but will be
> fixed in a future glibc release.  I'd appreciate some clarification on
> that.

The part *may* need to be emphasised:

| When this context is later activated (using setcontext(2) or
| swapcontext()) the function func is called, and passed the series of
| integer (int) arguments that follow  argc;

The bug reporter made some confusion between int and void*, the two
having the same size on a 32-bit machine, but not on a 64-bit machine.

The current code has been changed in glibc 2.8 to ensure that *some
architectures* may allow a 64-bit value instead of an int, but there is
no guarantee it will work on all 64-bit architecture.

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#504699; Package manpages-dev. (Fri, 07 Nov 2008 22:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to mtk.manpages@gmail.com:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Fri, 07 Nov 2008 22:51:03 GMT) Full text and rfc822 format available.

Message #34 received at 504699@bugs.debian.org (full text, mbox):

From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Aurelien Jarno" <aurelien@aurel32.net>
Cc: "Petr Salinger" <Petr.Salinger@seznam.cz>, 504699@bugs.debian.org, "Paul Evans" <leonerd@leonerd.org.uk>, debian-glibc@lists.debian.org
Subject: Re: Bug#504699: (no subject)
Date: Fri, 7 Nov 2008 17:49:14 -0500
How would folk feel about the addition of the following test under
NOTES?  Are the staments about x86-64 accurate?

       On architectures where int and pointer types are the same
       size  (e.g.,  x86-32,  where both types are 32 bits), you
       may be able to get away with passing  pointers  as  argu-
       ments  to  makecontext()  following argc.  However, doing
       this is not  guaranteed  to  be  portable,  is  undefined
       according  to  the standards, and won't work on architec-
       tures where pointers are larger than ints.  Nevertheless,
       starting  with  version  2.8  glibc makes some changes to
       makecontext(3), to permit this on some  64-bit  architec-
       tures (e.g., x86-64).

Cheers,

Michael

--- a/man3/makecontext.3
+++ b/man3/makecontext.3
@@ -113,6 +113,22 @@ to be used as the stack, regardless of the
direction of growth of
 the stack.
 Thus, it is not necessary for the user program to
 worry about this direction.
+
+On architectures where
+.I int
+and pointer types are the same size
+(e.g., x86-32, where both types are 32 bits),
+you may be able to get away with passing pointers as arguments to
+.BR makecontext ()
+following
+.IR argc .
+However, doing this is not guaranteed to be portable,
+is undefined according to the standards,
+and won't work on architectures where pointers are larger than
+.IR int s.
+Nevertheless, starting with version 2.8 glibc makes some changes to
+.BR makecontext (3),
+to permit this on some 64-bit architectures (e.g., x86-64).
 .SH EXAMPLE
 .PP
 The example program below demonstrates the use of




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#504699; Package manpages-dev. (Sat, 08 Nov 2008 01:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul LeoNerd Evans <leonerd@leonerd.org.uk>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Sat, 08 Nov 2008 01:24:02 GMT) Full text and rfc822 format available.

Message #39 received at 504699@bugs.debian.org (full text, mbox):

From: Paul LeoNerd Evans <leonerd@leonerd.org.uk>
To: mtk.manpages@gmail.com
Cc: Aurelien Jarno <aurelien@aurel32.net>, Petr Salinger <Petr.Salinger@seznam.cz>, 504699@bugs.debian.org, Paul Evans <leonerd@leonerd.org.uk>, debian-glibc@lists.debian.org
Subject: Re: Bug#504699: (no subject)
Date: Sat, 8 Nov 2008 01:21:01 +0000
[Message part 1 (text/plain, inline)]
On Fri, Nov 07, 2008 at 05:49:14PM -0500, Michael Kerrisk wrote:
> How would folk feel about the addition of the following test under
> NOTES?  Are the staments about x86-64 accurate?
> 
>        On architectures where int and pointer types are the same
>        size  (e.g.,  x86-32,  where both types are 32 bits), you
>        may be able to get away with passing  pointers  as  argu-
>        ments  to  makecontext()  following argc.  However, doing
>        this is not  guaranteed  to  be  portable,  is  undefined
>        according  to  the standards, and won't work on architec-
>        tures where pointers are larger than ints.  Nevertheless,
>        starting  with  version  2.8  glibc makes some changes to
>        makecontext(3), to permit this on some  64-bit  architec-
>        tures (e.g., x86-64).

That looks good to me. I'd be happy with that.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/
[signature.asc (application/pgp-signature, inline)]

Reply sent to Joey Schulze <joey@infodrom.org>:
You have taken responsibility. (Sat, 29 Nov 2008 11:33:18 GMT) Full text and rfc822 format available.

Notification sent to Paul Evans <leonerd@leonerd.org.uk>:
Bug acknowledged by developer. (Sat, 29 Nov 2008 11:33:18 GMT) Full text and rfc822 format available.

Message #44 received at 504699-close@bugs.debian.org (full text, mbox):

From: Joey Schulze <joey@infodrom.org>
To: 504699-close@bugs.debian.org
Subject: Bug#504699: fixed in manpages 3.14-1
Date: Sat, 29 Nov 2008 11:17:11 +0000
Source: manpages
Source-Version: 3.14-1

We believe that the bug you reported is fixed in the latest version of
manpages, which is due to be installed in the Debian FTP archive:

manpages-dev_3.14-1_all.deb
  to pool/main/m/manpages/manpages-dev_3.14-1_all.deb
manpages_3.14-1.diff.gz
  to pool/main/m/manpages/manpages_3.14-1.diff.gz
manpages_3.14-1.dsc
  to pool/main/m/manpages/manpages_3.14-1.dsc
manpages_3.14-1_all.deb
  to pool/main/m/manpages/manpages_3.14-1_all.deb
manpages_3.14.orig.tar.gz
  to pool/main/m/manpages/manpages_3.14.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 504699@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Joey Schulze <joey@infodrom.org> (supplier of updated manpages package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Sat, 29 Nov 2008 12:01:13 +0100
Source: manpages
Binary: manpages manpages-dev
Architecture: source all
Version: 3.14-1
Distribution: unstable
Urgency: low
Maintainer: Martin Schulze <joey@debian.org>
Changed-By: Joey Schulze <joey@infodrom.org>
Description: 
 manpages   - Manual pages about using a GNU/Linux system
 manpages-dev - Manual pages about using GNU/Linux for development
Closes: 504699 504787 506299
Changes: 
 manpages (3.14-1) unstable; urgency=low
 .
   * New upstream version
     . Fix description of range of function value return in atan2(3)
       (closes: Bug#506299)
     . Clarify and add more detail in RETURN VALUE description in
       getpwnam(3) and getgrnam(3) (closes: Bug#504787)
     . Add text on use of pointer arguments to makecontext(3) (closes:
       Bug#504699)
     . Document that LOG_KERN messages can't be generated from user
       processes in syslog(3)
   * Avoid distribution of more pthread manpages that are currently also
     provided by glibc-doc:
     . pthread_attr_setinheritsched(3)
     . pthread_cancel(3)
     . pthread_cleanup_pop(3)
     . pthread_cleanup_push(3)
     . pthread_setcancelstate(3)
     . pthread_setcanceltype(3)
     . pthread_testcancel(3)
Checksums-Sha1: 
 24893a0610d560906b338402596dd61625b3cb23 964 manpages_3.14-1.dsc
 f69bdd0ab2fe373a266809905b40e5e1ef6427d5 1520978 manpages_3.14.orig.tar.gz
 d04ba3dfb8a3fe897539c471bca78ceec07e6b5c 49494 manpages_3.14-1.diff.gz
 121fae93537754ee85d5d52b9a70c23fa9f61fc8 650242 manpages_3.14-1_all.deb
 71e58f698ea1a8f6fe3ade522eb15702475a9698 1522358 manpages-dev_3.14-1_all.deb
Checksums-Sha256: 
 d06a5b800d6d42b11fe3c4c58bea1972bfbd4fe4807e99531acebaab912e9919 964 manpages_3.14-1.dsc
 e93c51c18329484b0fe9d7b6d6bd1c57bcaabcab97aca06e570eb963f330d355 1520978 manpages_3.14.orig.tar.gz
 0dfe78de3db50a53a43482623c4609420fa941431f7178190fd03d358b6c380d 49494 manpages_3.14-1.diff.gz
 0eb9bf2d24336f5d1521b0d63e9d2f897cc9669bbc754be06e525d4e2b03b1d8 650242 manpages_3.14-1_all.deb
 b4b64abbb972f0eb840fe6871e8aeed4aad23378ed9e6ce0afc8ac210b8586c2 1522358 manpages-dev_3.14-1_all.deb
Files: 
 6f99cf576d6c6f78e1b127ff13c018ea 964 doc important manpages_3.14-1.dsc
 356983f0fc29e0a221f576d979a09d02 1520978 doc important manpages_3.14.orig.tar.gz
 4c67932cc6b7e7785c105b3c91b38e9b 49494 doc important manpages_3.14-1.diff.gz
 84baa24ec0cdb4815373703e2d2eeba2 650242 doc important manpages_3.14-1_all.deb
 ee20b1ea55967cd29d4ffd26e9b35e20 1522358 doc optional manpages-dev_3.14-1_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFJMSGWW5ql+IAeqTIRAgD/AJ90bJA8DssEO8veGT60ADAPuWl4SQCdHU4u
tM3lixpjlK000EtX8FBt7nI=
=cwsx
-----END PGP SIGNATURE-----





Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Mon, 16 Feb 2009 08:48:31 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Fri Apr 25 07:48:39 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.