-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
Hello!
When C++ code on a cothread throws an exception the stack unwinding thinks it is from a noexcept
method and calls terminate instead of correctly unwinding the stack within the cothread. This seems to be a bug in how the new stack is prepared by libco
in the amd64.c
and x86.c
backends.
Repro:
#include <stdexcept>
#include <cstdio>
#include <libco.h>
cothread_t parent;
void will_throw()
{
throw std::runtime_error("Catch me!");
}
void entry()
{
try
{
will_throw();
}
catch (const std::exception& e)
{
std::printf("%s\n", e.what());
co_switch(parent);
}
}
int main()
{
parent = co_active();
auto cothread = co_create(262144 * sizeof(void*), &entry);
co_switch(cothread);
return 0;
}
Edit:
Correction: The statement "the stack unwinding thinks it is from a noexcept
method and calls terminate" is only true when the exception is thrown from a function called by the entry function from a try
block and only in the Debug configuration. If the exception is thrown directly from the try block then the exception object won't be caught properly and the executable tries to read from invalid memory.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed