Skip to content
Snippets Groups Projects
Commit 98b2cdfa authored by Georgy Kirichenko's avatar Georgy Kirichenko Committed by Vladimir Davydov
Browse files

Proper unwind for currently executing fiber

Each yielded fiber has a preserved coro state stored in a corresponding
variable however an executing fiber has a volatile state placed in CPU
registers (stack pointer, instruction pointer and non-volatile registers)
and corresponding context-storing variable value is invalid.
For already yielded fiber we have to use a special asm-written handler to make
a temporary switch to the preserved state and capture executing context what
is not needed for executing fiber.
After the patch for the executing fiber NULL is passed to the backtrace
function as coro context and then backtrace function could decide should
it use special context-switching handler or might just use unw_getcontext
from the unwind library.
parent 85878bcf
No related branches found
No related tags found
No related merge requests found
......@@ -366,12 +366,32 @@ __asm__ volatile(
#endif
}
/**
* Call `cb' callback for each `coro_ctx' contained frame or the current
* executed coroutine if `coro_ctx' is NULL. A coro_context is a structure
* created on each coroutine yield to store execution context so for an
* on-CPU coroutine there is no valid coro_context could be defined and
* NULL is passed.
*/
void
backtrace_foreach(backtrace_cb cb, coro_context *coro_ctx, void *cb_ctx)
{
unw_cursor_t unw_cur;
unw_context_t unw_ctx;
coro_unwcontext(&unw_ctx, coro_ctx);
if (coro_ctx == NULL) {
/*
* Current executing coroutine and simple unw_getcontext
* should function.
*/
unw_getcontext(&unw_ctx);
} else {
/*
* Execution context is stored in the coro_ctx
* so use special context-switching handler to
* capture an unwind context.
*/
coro_unwcontext(&unw_ctx, coro_ctx);
}
unw_init_local(&unw_cur, &unw_ctx);
int frame_no = 0;
unw_word_t sp = 0, old_sp = 0, ip, offset;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment