This is the mail archive of the libc-alpha@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]

Re: {make,set,swap}context broken on powerpc32


Jakub Jelinek wrote:

On Tue, Dec 19, 2006 at 04:48:09PM +1100, Paul Mackerras wrote:


Steven Munroe writes:



Note that sys_swapcontext can happily use, as its second argument, a
ucontext where the uc_mcontext.uc_regs field is not 16-byte aligned,
though, so glibc could work around the kernel bug by doing the memmove
in makecontext as you suggest.




I would like to avoid any memmove by aligning the regs buffer properly
in the first place.


I don't understand why makecontext has to set the regs pointer at all,
given that the user has to call getcontext first.  Why can't
makecontext just use the pointer that getcontext has set?

If you do that then there is no problem using the sys_swapcontext
syscall even on kernels that have the alignment bug, as long as you
use sys_swapcontext for setcontext and swapcontext. (And yes I will
fix the alignment bug in the kernel.)



I completely agree, I also see no reason to align in makecontext@@GLIBC_2.3.4. POSIX requires that the ucontext_t passed to makecontext has been initialized by a getcontext call, and either glibc is configured to use swapcontext syscall (in this case the kernel should make sure it is aligned, but even if it does not, we are using swapcontext syscall everywhere and the kernel doesn't need it aligned), or we are not using swapcontext syscall anywhere and getcontext@@GLIBC_2.3.4 pure userland implementation initializes uc_mcontext.uc_regs to an aligned value.

Attached is a patch to change makecontext.c as well as a testcase
I posted just inline when starting this thread.



This is similar to the patch I submitted on 12/13/06, http://sources.redhat.com/ml/libc-alpha/2006-12/msg00115.html.

This is fine if all cases that create/initialize a ucontext set the pointer and align the reg save area. At the moment the makecontext only sets up integer/pointer parms to pass to the func. But to be complete it really should handle floating point and vector parms, which requires that the regs save area is quadword aligned (even if the kernel can handle unaligned VRs that ABI for parameter passing does not.

My patch went further and aligned and set the uc_regs pointer before the call to sys_swapcontext (assuming the kernel would use the uc_regs address). Alternatively the kernel can make sure the reg save area is aligned and uc_regs is set.


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