From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14095 invoked by alias); 12 Apr 2010 16:56:07 -0000 Received: (qmail 13796 invoked by uid 22791); 12 Apr 2010 16:56:05 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Apr 2010 16:55:53 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3CGthKA002939 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 12 Apr 2010 12:55:52 -0400 Received: from hase.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3CGbsTg007703 for ; Mon, 12 Apr 2010 12:37:55 -0400 From: Andreas Schwab To: libc-hacker@sourceware.org Subject: [PATCH] Fix use of ucontext_t objects in tst-makecontext3 X-Yow: Jesus is my POSTMASTER GENERAL.. Date: Mon, 12 Apr 2010 16:56:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2010-04/txt/msg00012.txt.bz2 Objects of type ucontext_t cannot be copied, only getcontext can properly initialize them. For example, on powerpc the structure contains a pointer into itself, so makecontext modifies the original object by side effect. Andreas. 2010-04-12 Andreas Schwab * stdlib/tst-makecontext3.c (main): Initialize ucontext_t objects only with getcontext. Test for unimplemented makecontext by checking errno. --- stdlib/tst-makecontext3.c | 62 ++++++++++++++++++++++++--------------------- 1 files changed, 33 insertions(+), 29 deletions(-) diff --git a/stdlib/tst-makecontext3.c b/stdlib/tst-makecontext3.c index f127c6a..a44169a 100644 --- a/stdlib/tst-makecontext3.c +++ b/stdlib/tst-makecontext3.c @@ -136,38 +136,42 @@ main (void) exit (1); } - ctx[1] = ctx[0]; + if (getcontext (&ctx[1]) != 0) + { + printf ("%s: getcontext: %m\n", __FUNCTION__); + exit (1); + } + ctx[1].uc_stack.ss_sp = st1; ctx[1].uc_stack.ss_size = sizeof st1; ctx[1].uc_link = &ctx[0]; - { - ucontext_t tempctx = ctx[1]; - makecontext (&ctx[1], (void (*) (void)) f1, 33, - 0x00000001 << flag, 0x00000004 << flag, - 0x00000012 << flag, 0x00000048 << flag, - 0x00000123 << flag, 0x0000048d << flag, - 0x00001234 << flag, 0x000048d1 << flag, - 0x00012345 << flag, 0x00048d15 << flag, - 0x00123456 << flag, 0x0048d159 << flag, - 0x01234567 << flag, 0x048d159e << flag, - 0x12345678 << flag, 0x48d159e2 << flag, - 0x23456789 << flag, 0x8d159e26 << flag, - 0x3456789a << flag, 0xd159e26a << flag, - 0x456789ab << flag, 0x159e26af << flag, - 0x56789abc << flag, 0x59e26af3 << flag, - 0x6789abcd << flag, 0x9e26af37 << flag, - 0x789abcde << flag, 0xe26af37b << flag, - 0x89abcdef << flag, 0x26af37bc << flag, - 0x9abcdef0 << flag, 0x6af37bc3 << flag, - 0xabcdef0f << flag); - - /* Without this check, a stub makecontext can make us spin forever. */ - if (memcmp (&tempctx, &ctx[1], sizeof ctx[1]) == 0) - { - puts ("makecontext was a no-op, presuming not implemented"); - return 0; - } - } + errno = 0; + makecontext (&ctx[1], (void (*) (void)) f1, 33, + 0x00000001 << flag, 0x00000004 << flag, + 0x00000012 << flag, 0x00000048 << flag, + 0x00000123 << flag, 0x0000048d << flag, + 0x00001234 << flag, 0x000048d1 << flag, + 0x00012345 << flag, 0x00048d15 << flag, + 0x00123456 << flag, 0x0048d159 << flag, + 0x01234567 << flag, 0x048d159e << flag, + 0x12345678 << flag, 0x48d159e2 << flag, + 0x23456789 << flag, 0x8d159e26 << flag, + 0x3456789a << flag, 0xd159e26a << flag, + 0x456789ab << flag, 0x159e26af << flag, + 0x56789abc << flag, 0x59e26af3 << flag, + 0x6789abcd << flag, 0x9e26af37 << flag, + 0x789abcde << flag, 0xe26af37b << flag, + 0x89abcdef << flag, 0x26af37bc << flag, + 0x9abcdef0 << flag, 0x6af37bc3 << flag, + 0xabcdef0f << flag); + + /* Without this check, a stub makecontext can make us spin forever. */ + if (errno == ENOSYS) + { + puts ("makecontext not implemented"); + back_in_main = 1; + return 0; + } /* Play some tricks with this context. */ if (++global == 1) -- 1.7.0.1 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different."