Commit 34e35233 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

Fix stop_thread unwinding information

This corrects the unwind information for `stg_stop_thread`, which
allows us to unwind back to the C stack after reaching the end of the 
STG stack.

Test Plan: Validate

Reviewers: simonmar, austin, erikd

Reviewed By: simonmar

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2746
parent 5279b08b
......@@ -111,6 +111,20 @@
#define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
/* -----------------------------------------------------------------------------
How large is the stack frame saved by StgRun?
world. Used in StgCRun.c.
-------------------------------------------------------------------------- */
#if defined(x86_64_HOST_ARCH)
# if defined(mingw32_HOST_OS)
/* 8 larger than necessary to make the alignment right*/
# define STG_RUN_STACK_FRAME_SIZE 80
# else
# define STG_RUN_STACK_FRAME_SIZE 48
# endif
#endif
/* -----------------------------------------------------------------------------
How much Haskell stack space to reserve for the saving of registers
etc. in the case of a stack/heap overflow.
......
......@@ -320,11 +320,7 @@ StgRunIsImplementedInAssembler(void)
:
: "i"(RESERVED_C_STACK_BYTES),
#if defined(mingw32_HOST_OS)
"i"(80 /*stack frame size; 8 too large to make the alignment right*/)
#else
"i"(48 /*stack frame size*/)
#endif
"i"(STG_RUN_STACK_FRAME_SIZE /* stack frame size */)
);
/*
* See Note [Stack Alignment on X86]
......
......@@ -67,11 +67,19 @@ INFO_TABLE_RET(stg_stop_thread, STOP_FRAME,
debuggers to find their way back to the C stack.
This is a bit fiddly as we assume the layout of the stack prepared
for us by StgRun.
for us by StgRun. Note that in most cases StgRun is written in assembler
and therefore has no associated unwind information. For this reason we
need to identify the platform stack pointer and return address values for
the StgRun's caller.
*/
#ifdef x86_64_HOST_ARCH
unwind MachSp = MachSp + RESERVED_C_STACK_BYTES + 0x38 + 8,
UnwindReturnReg = W_[MachSp + RESERVED_C_STACK_BYTES + 0x38];
// offset of 8 in MachSp value due to return address
unwind MachSp = MachSp + RESERVED_C_STACK_BYTES + STG_RUN_STACK_FRAME_SIZE + 8,
UnwindReturnReg = W_[MachSp + RESERVED_C_STACK_BYTES + STG_RUN_STACK_FRAME_SIZE];
#else
// FIXME: Fill in for other platforms
unwind MachSp = return,
UnwindReturnReg = return;
#endif
Sp = Sp + SIZEOF_StgStopFrame - WDS(2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment