[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Crash on x86 with doubles



On 1 Jul 2014, at 22:53, Thomas Leonard <talex5@xxxxxxxxx> wrote:

> I've got printing of floating point values working now on ARM, but
> while testing I discovered it crashes on x86.
> 
> This turned out to be unrelated to OCaml or Mirage. It seems that
> passing a double argument to any varargs function causes a crash on
> x86_64 if done from a Mini-OS thread. Can any x86 gurus here shed some
> light on what might cause that? x86 is a mystery to me.

First thing to check is that %rsp stack alignment is valid when you
enter the function, as it's required to be 16-byte aligned by the
x86_64 ABI if you're using the XMM registers.

An ancient diff in our local MiniOS that fixed one instance of this
is below. (I can't reproduce this instantly to give you a more precise
diagnosis as I'm travelling at the moment, apologies!)

-anil


commit c185b18d3e1809257d6b5dcba1bd258ec77565e1
Author: Anil Madhavapeddy <anil@xxxxxxxxxx>
Date:   Wed Jul 21 16:59:24 2010 +0100

    fix a nasty stack misalignment problem when executing code inside an event 
handler.
    The irq stack xen injects is only 8 byte aligned instead of 16, and so 
eventually any varargs call 
    Just adjust %esp directly in the callback to deal with this case.

diff --git a/runtime/kernel/hypervisor.c b/runtime/kernel/hypervisor.c
index 9f628c4..19c2134 100644
--- a/runtime/kernel/hypervisor.c
+++ b/runtime/kernel/hypervisor.c
@@ -46,6 +46,11 @@ void do_hypervisor_callback(struct pt_regs *regs)
 
     in_callback = 1;
 
+    /* Adjust the stack to be 16-byte aligned, so that functions
+       called from an event callback will respect the x86_64 ABI.
+       The Xen IRQ injection is only 8-bytes */
+    asm("andl $0xfffffff0, %esp");
+
     vcpu_info->evtchn_upcall_pending = 0;
     /* NB x86. No need for a barrier here -- XCHG is a barrier on x86. */
     l1 = xchg(&vcpu_info->evtchn_pending_sel, 0);
@@ -60,7 +65,7 @@ void do_hypervisor_callback(struct pt_regs *regs)
             l2 &= ~(1UL << l2i);
 
             port = (l1i * (sizeof(unsigned long) * 8)) + l2i;
-                       do_event(port, regs);
+            do_event(port, regs);
         }
     }
 



_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.