Module: xenomai-2.6
Branch: master
Commit: 3bd460bd22295e87a9850fd8439e94557f094904

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 43fc2d0..8ec152f 100644
--- a/include/asm-x86/bits/shadow_32.h
+++ b/include/asm-x86/bits/shadow_32.h
@@ -127,6 +127,7 @@ static inline void xnarch_handle_mayday(struct xnarchtcb 
                                        struct pt_regs *regs,
                                        unsigned long tramp)
+       tcb->mayday.esp = regs->x86reg_sp;
        tcb->mayday.eip = regs->x86reg_ip;
        tcb->mayday.eax = regs->x86reg_ax;
        regs->x86reg_ip = tramp;
@@ -137,6 +138,7 @@ static inline void xnarch_fixup_mayday(struct xnarchtcb 
        regs->x86reg_ip = tcb->mayday.eip;
        regs->x86reg_ax = tcb->mayday.eax;
+       regs->x86reg_sp = tcb->mayday.esp;
 #endif /* XNARCH_HAVE_MAYDAY */
diff --git a/include/asm-x86/system_32.h b/include/asm-x86/system_32.h
index 3c1507e..bb630a6 100644
--- a/include/asm-x86/system_32.h
+++ b/include/asm-x86/system_32.h
@@ -52,6 +52,7 @@ typedef struct xnarchtcb {      /* Per-thread arch-dependent 
block */
        struct {
                unsigned long eip;
                unsigned long eax;
+               unsigned long esp;
        } mayday;

Xenomai-git mailing list

Reply via email to