public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sjmunroe at us dot ibm dot com" <sourceware-bugzilla@sources.redhat.com>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/612] makecontext broken on powerpc-linux
Date: Mon, 20 Dec 2004 21:13:00 -0000	[thread overview]
Message-ID: <20041220211315.22608.qmail@sourceware.org> (raw)
In-Reply-To: <20041220133835.612.olh@suse.de>


------- Additional Comments From sjmunroe at us dot ibm dot com  2004-12-20 21:13 -------
This is a bad testcase coupled with internal changes to PPC ucontext_t to 
maintian backward compat and accomadate VMX (Altivec) which requires stonger 
alignment then the base ucontext_t.

>From the IEEE Std 1003.1, 2004:

"The uc_link member is used to determine the context that shall be resumed 
when the context being modified by makecontext() returns. The application 
shall ensure that the uc_link member is initialized prior to the call to 
makecontext().

The swapcontext() function shall save the current context in the context 
structure pointed to by oucp and shall set the context to the context 
structure pointed to by ucp."

If they had used swapcontext as suggested to create the resume context (oucp) 
it would have worked. Instead they used getcontext then made a copy (via 
memcpy) to another ucontext_t for the resume context (oucp) pointed to by the 
uc_link. 

This works on some architecture but the PPC ucontext_t contains internal 
pointers. From ucontext.h:

     * Different versions of the kernel have stored the registers on
     * signal delivery at different offsets from the ucontext struct.
     * Programs should thus use the uc_mcontext.uc_regs pointer to
     * find where the registers are actually stored.  The registers
     * will be stored within the ucontext_t struct but not necessarily
     * at a fixed address.  As a side-effect, this lets us achieve
     * 16-byte alignment for the register storage space if the
     * Altivec registers are to be saved, without requiring 16-byte
     * alignment on the whole ucontext_t.

So when the 1st ucontext_t (ucp) was copied to the 2nd ucontext_t (oucp) the 
uc_mcontext.uc_regs pointer still pointed back into the 1st ucontext_t. Then 
makecontext(ucp, ...) modified (ucp) to dispatch t1_func() (which effectively 
changes both contexts!)

When t1_func() returns, it branches to code in makecontext which follows 
uc_link to get the address of the resume context. Makecontext then calls 
setcontext to dispatch the resume context. But as the resume context (oucp) 
contains a uc_regs that points back into the context modified by makecontext 
we have an infinite loop (makecontaxt resume, setcontext, t1_func, ...)

Net you can't JUST COPY ucontexts on PPC because of the uc_regs pointer. PPC64 
does not fail in this case becuase gregset_t is at a fixed offset. But VMX 
registers (if used) are accessed via an internal mcontext.v_regs pointer 
(allows for internal quadword allignment). So a PPC64 testcase programmed this 
way and dependent on VMX state might also fail. Net any platform where the 
ucontext_t contains internal pointers is likely to fail this testcase.

But if the testcase did not copy the ucontext and instead used swapcontext to 
create the resume context call platforms should work.



-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=612

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


  parent reply	other threads:[~2004-12-20 21:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-20 13:38 [Bug libc/612] New: " olh at suse dot de
2004-12-20 13:39 ` [Bug libc/612] " olh at suse dot de
2004-12-20 13:56 ` aj at suse dot de
2004-12-20 21:13 ` sjmunroe at us dot ibm dot com [this message]
2004-12-20 21:18 ` olh at suse dot de
2004-12-20 21:45 ` sjmunroe at us dot ibm dot com
2005-04-28 16:08 ` sjmunroe at us dot ibm dot com
     [not found] <bug-612-131@http.sourceware.org/bugzilla/>
2021-09-12 16:46 ` ovilewade9 at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041220211315.22608.qmail@sourceware.org \
    --to=sourceware-bugzilla@sources.redhat.com \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).