Module: xenomai-forge
Branch: master
Commit: 6a1c985bea61f7caad5a142b4238780ecdfb001d

Author: Philippe Gerum <>
Date:   Mon Jun  4 08:52:41 2012 +0200

x86: fix mayday support in 32bit+SEP mode

The mayday syscall (__xn_sys_mayday) will not return to its caller,
but rather to the runaway code originally preempted by the mayday
event, once the faulty thread is relaxed.

For this reason, we have to fix up the user stack pointer before
returning from the mayday syscall handler, to discard the data pushed
onto the stack by the sysenter prologue in vDSO to kick

This bug is only seen on x86_32 when SYSENTER is enabled, because we
won't get any data pushed onto the user stack for issuing
__xn_sys_mayday in long mode, or whenever a legacy int80 syscall is

We do the fix up simply by restoring the original ESP before returning
from the mayday syscall handler, which will do the right thing when
SEP is enabled, or lead to a nop otherwise.


 include/asm-x86/bits/shadow_32.h |    2 ++
 include/asm-x86/system_32.h      |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/include/asm-x86/bits/shadow_32.h b/include/asm-x86/bits/shadow_32.h
index 12a2996..a682f87 100644
--- a/include/asm-x86/bits/shadow_32.h
+++ b/include/asm-x86/bits/shadow_32.h
@@ -120,6 +120,7 @@ static inline void xnarch_handle_mayday(struct xnarchtcb 
                                        struct pt_regs *regs,
                                        unsigned long tramp)
+       tcb->mayday.esp = regs->sp;
        tcb->mayday.eip = regs->ip;
        tcb->mayday.eax = regs->ax;
        regs->ip = tramp;
@@ -130,6 +131,7 @@ static inline void xnarch_fixup_mayday(struct xnarchtcb 
        regs->ip = tcb->mayday.eip;
        regs->ax = tcb->mayday.eax;
+       regs->sp = tcb->mayday.esp;
 #endif /* !_XENO_ASM_X86_BITS_SHADOW_32_H */
diff --git a/include/asm-x86/system_32.h b/include/asm-x86/system_32.h
index 491fb60..5176d27 100644
--- a/include/asm-x86/system_32.h
+++ b/include/asm-x86/system_32.h
@@ -51,6 +51,7 @@ typedef struct xnarchtcb {      /* Per-thread arch-dependent 
block */
        struct {
                unsigned long eip;
                unsigned long eax;
+               unsigned long esp;
        } mayday;
        /* User mode side */

Xenomai-git mailing list

Reply via email to