|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [MirageOS-devel] Crash on x86 with doubles
On 2 July 2014 09:02, Anil Madhavapeddy <anil@xxxxxxxxxx> wrote:
> 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!)
Ah, that was indeed the problem. I changed the x86 arch_create_thread
to skip 8 bytes and now it works!
Though, it seemed that it *was* 16-byte aligned before, and is now off
by 8 bytes, which I don't understand. I'll send the patch to xen-devel
and they can decide if it's the right fix.
Thanks!
> -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);
> }
> }
>
>
>
--
Dr Thomas Leonard http://0install.net/
GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1
GPG: DA98 25AE CAD0 8975 7CDA BD8E 0713 3F96 CA74 D8BA
_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |