Comments (22)
I tried doing the same thing with one of the samples, and it has the same problem - here is a compressed version of it:
#include <cstdlib>
#include <iostream>
#include <boost/context/continuation.hpp>
LONG WINAPI XptHandler(struct _EXCEPTION_POINTERS* pInfo)
{
printf("ExceptionHandler\n");
return EXCEPTION_EXECUTE_HANDLER;
}
void Crash()
{
intptr_t* p = 0;
*p = 32;
}
namespace ctx = boost::context;
ctx::continuation f1( ctx::continuation && c) {
Crash();
return std::move( c);
}
int main() {
SetUnhandledExceptionFilter(XptHandler);
ctx::continuation c;
int data = 1;
c = ctx::callcc( f1, data);
int x;
std::cin >> x;
return EXIT_SUCCESS;
}
from context.
Could you check your example with Win32 please? Maybe the x64 version needs to preserve SEH too.
It migh also be possible that some additional parts of the TEB/TIB must be preserved during context switch too (probably undocumented by MS).
from context.
I forgot to mention it but the version using callcc was actually using x86(I didnt get around to figuring out how to compile boost in x64).
So it happens for both x64 and x86.
In windbg, !exchain reports a valid exchain in x86:
0:000:x86> !exchain
0000000000b2fe2c: ConsoleApplication1!__scrt_stub_for_is_c_termination_complete+e60 (0000000000a09e20)
0000000000b2ff8c: ConsoleApplication1!__scrt_stub_for_is_c_termination_complete+df0 (0000000000a09db0)
0000000000b2ffa8: ntdll_77b70000!FinalExceptionHandlerPad27+0 (0000000077bf2eeb)
Invalid exception stack at ffffffffffffffff
But not in x64:
0:000> !exchain
7 stack frames, scanning for handlers...
Frame 0x02: error getting module for 00000242ceb92070
Frame 0x03: error getting module for 0000000100000000
Frame 0x04: error getting module for 000000000000808f
Frame 0x05: error getting module for fdfdfdfd00000057
Frame 0x06: error getting module for 0000008034dff980
I assume thats related to your comment about preserving SEH - Not sure if it helps as it still does not call the exception handler in either case.
from context.
Strange, I assumed that x64 does table-based exception handling and doesn't require the x86's frame based exception handling (SEH chains on the stack). C++ exceptions are thrown and catched without problems in x64 Window apps.
At the moment I've no solution - sorry.
from context.
Replace
SetUnhandledExceptionFilter(XptHandler);
by
AddVectoredExceptionHandler(1, XptHandler);
XptHandler
gets called.
from context.
While its a proper workaround for the programs i provided, I think it is not a real fix.
As I read it, AddVectoredExceptionHandler and SetUnhandledExceptionFilter serves two different purposes.
Vectored gets called before handlers, Unhandled after.
http://cbloomrants.blogspot.com/2011/11/11-09-11-weird-shite-about-exceptions.html
http://stackoverflow.com/questions/28629351/is-addvectoredexceptionhandler-a-replacement-for-setunhandledexceptionfilter
from context.
I've no informations where the XptHandler will be stored if SetUnhandledExceptionFilter is used.
I think it is not the TEB because only special parts like stack begin/end, fiber local storage data are exchanged by jump_fcontext. Remains only the stack, but it seams undocumented by MS (at least I didn't found a usefull information at MSDN).
Do you have an idea?
from context.
as unit tests show, throwing and catching exceptions is working for 32bit/64bit - try/catch and __try/__except
from context.
I confused that on 32bit '!exchain' shows a correct exception handler chain but not for x64.
The question is if '!exchain' is permitted to e used on x64 (on x64 exception handler chain is not stored on the stack as done in i386).
BTW, at least in MS VC 2015 '!exchain' is not accepted as a vailid command (immediate window).
from context.
I used !exchain in windbg, there it works on x64 as well.
I dont have any suggestions as to what can be wrong ..
from context.
I believe that the prologue in jump_fcontext needs some additional statements (save frame pointer) that could fix the problem.
from context.
you could use WinFibers instead by applying property context-impl=winfib at b2 command line
from context.
Thanks for the workaround!
Out of curiosity: Do you consider the problem to be unfixable?
from context.
I believe it is fixable but I'm too busy + I don't use Windows (need for diving deeper into the Windows mechanisms).
from context.
Thanks for the workaround!
Out of curiosity: Do you consider the problem to be unfixable?
hello @jonasmr , so yo succeed to have "SetUnhandledExceptionFilter " working now ?
In our project we are using boost::coroutines2::coroutine and we have the same kind of issue : my crash handler is not working if crash hapened in coroutine. And I am a bit lost. I think it is related to "context switch" but cannot find what to do to correctly handle the crash. Do I need to setup my handler differently or do we badly use coroutine. Any help is welcome.
from context.
You could build/use boost.context/boost.coroutine2 with context-impl=winfib in order to use Windows Fibers instead the assembler (MS does not provide enough infos which parts of TEB have to be copied during context switch)
from context.
ok i'll try this. thanks.
from context.
as long as MS does not publish all relevant infos... yes
from context.
Hello again. At this time it is not clear for me where to make the change. Is it a compilation option for boost that I have to change, to use another context implementation. Or is it when I instantiate the coroutine that I have to setup it differently ?
from context.
ok I found something
https://www.boost.org/doc/libs/1_68_0/libs/context/doc/html/context/ff/implementations__fcontext_t__ucontext_t_and_winfiber.html
from context.
ok I found something
https://www.boost.org/doc/libs/1_68_0/libs/context/doc/html/context/ff/implementations__fcontext_t__ucontext_t_and_winfiber.html
correct - compile boost and your application with b2 property
context-impl=winfib
from context.
Yeah. It seems it is working. Thanks.
from context.
Related Issues (20)
- Document the difference between Fiber and Call/CC HOT 1
- Build x86_64 on MacOS with apple M1 arm64. HOT 1
- how to set size of 'protected_fixedsize_stack' ? HOT 1
- Floating point registers are not preserved HOT 1
- Build failing in develop branch on Windows x64 HOT 2
- The ucontext headers always use code for macOS. HOT 2
- Delete
- Segfault with ucontext on macOS (#184, continued) HOT 3
- CMake builds fails on QNX (qcc): Incorrect assembler invocation
- Not able to build for windows ARM64 with msvc toolset HOT 6
- Is the performance of boost context slow on kernel 3.10 like Centos7 HOT 1
- Asm parts are not compiled when building boost 1.83 on riscv64 linux HOT 7
- CMAKE_SIZEOF_VOID_P is empty when trying to build HOT 1
- ontop implementation on x86-64 sysv
- implementation doesn't match what the doc said HOT 1
- ASM support for sparc64 systems HOT 1
- Failure to assemble ARM64 code with MSVC's ARMASM64 HOT 2
- 1.85.0 Beta 1 RC 1 does not build on Mac OS X with gcc HOT 4
- Modular Boost C++ Libraries Request
- unknown feature "<context-impl>" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from context.