On Wed, Jul 15, 2020 at 03:06:18PM +0200, Rainer Orth wrote:
> I must admit I missed that in that terrible nested maze of #ifdef's
> compiler-rt uses.
> 
> > I mean, while the ifndef/define change is guarded by #if SANITIZER_SOLARIS,
> > the last changed line is not.  I'm afraid I don't know if
> > ucontext->uc_mcontext.gregs[REG_UESP] or 
> > ucontext->uc_mcontext.gregs[REG_ESP];
> > is what we want to use on i686-linux...
> 
> So far, I've regtested both GCC and LLVM master on x86_64-pc-linux-gnu
> (both m64 and m32 multilibs) and there were no regressions.
> 
> I've then tried to make sense of the situation in the Linux kernel
> sources and found some hints suggesting that REG_UESP is right here,
> too:
> 
> * arch/x86/um/os-Linux/mcontext.c has
> 
> void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)
> {
> #ifdef __i386__
> #define COPY2(X,Y) regs->gp[X] = mc->gregs[REG_##Y]
> #define COPY(X) regs->gp[X] = mc->gregs[REG_##X]
> [...]
>         COPY(EDI); COPY(ESI); COPY(EBP);
>         COPY2(UESP, ESP); /* sic */
> 
> * Similarly in arch/x86/um/user-offsets.c:
> 
> void foo(void)
> {
> #ifdef __i386__
> [...]
>         DEFINE(HOST_IP, EIP);
>         DEFINE(HOST_SP, UESP);
> [...]
>         DEFINE(HOST_BP, EBP);
> 
> * And arch/x86/include/uapi/asm/sigcontext.h:
> 
> struct sigcontext_32 {
> [...]
>         __u32                           bp;
>         __u32                           sp;
> [...]
>         __u32                           sp_at_signal;
>         __u16                           ss, __ssh;
> 
> I may still be mistaken, but all this suggests that Linux might be
> playing games with ESP and UESP, while Solaris and NetBSD (see below)
> keep them separate, but in the end UESP is the register to use.

I think what matters more is
kernel/signal.c and ia32/ia32_signal.c doing:
                put_user_ex(regs->sp, &sc->sp);
...
                put_user_ex(regs->sp, &sc->sp_at_signal);
i.e. both ESP and UESP ought to have the same value in the end on Linux.

Your patch is ok for trunk and for 10.3 after a few weeks (10.2 is frozen
ATM anyway) so that if there are some problems (like say some headers not
defining REG_UESP or something similar), we'll find that out on trunk first.

        Jakub

Reply via email to