Discussion:
own stackframe -> prob with exception handling
(too old to reply)
olk
2010-03-13 18:08:24 UTC
Permalink
I've some code which creates its own stackframe and does some kine of
context switching (using inline assembler). The code works until the
function of the new context throws an exception. Even if I've installed
an exception handler (try/catch block) I get an unhandled exception
fault (I debugged it with MS VC - catch caluse note entered even not the
catch(...).
I guess on windows some special code is required for my own stackframe
in order to the exception handling correct?!

Any hints are welcome.

Oliver
Jochen Kalmbach [MVP]
2010-03-13 18:13:36 UTC
Permalink
Hi olk!
Post by olk
I've some code which creates its own stackframe and does some kine of
context switching (using inline assembler).
Why not switch the whole stack?
Or: Why not use CreateFiber? and SwitchToFiber?
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
olk
2010-03-13 18:20:33 UTC
Permalink
Post by Jochen Kalmbach [MVP]
Hi olk!
Post by olk
I've some code which creates its own stackframe and does some kine of
context switching (using inline assembler).
Why not switch the whole stack?
The code works similiar to ucotnext -> makecontext()/swapcontext() etc.
What it doesis: it creates an stack on an range in the memory. It saves
the registers. Such context objects can bes sappwed. So it does swap the
whole stack (assigned to it).
Post by Jochen Kalmbach [MVP]
Or: Why not use CreateFiber? and SwitchToFiber?
Has some problems. for instance you can not move fibers between threads.
You have the ugly ConvertThreadToFiber()/ConvertFiberToThread() stuff etc.

I need to know how to get the surounding exception handler recognized.
Alexander Grigoriev
2010-03-13 20:34:03 UTC
Permalink
A thread context contains stack limits. If stack pointer outside of those
limits, expection can't be handled.
Post by olk
I've some code which creates its own stackframe and does some kine of
context switching (using inline assembler). The code works until the
function of the new context throws an exception. Even if I've installed an
exception handler (try/catch block) I get an unhandled exception fault (I
debugged it with MS VC - catch caluse note entered even not the
catch(...).
I guess on windows some special code is required for my own stackframe in
order to the exception handling correct?!
Any hints are welcome.
Oliver
olk
2010-03-13 22:15:30 UTC
Permalink
Post by Alexander Grigoriev
A thread context contains stack limits. If stack pointer outside of those
limits, expection can't be handled.
stacksize is 64kB - the code works. If I throw an exception the
sourounding exceptio nhandler is not invoked:

try
{
throw std::runtime_erro("abc"); // app is aborted because unhandled
exception
}
catch( std::exception const& e)
{}
catch(...)

I'm looking through MSDN and I saw some articesl about Frame-based
Exception Handling (SEH) etc. but I'm not sure if this would point me to
a solution.
{}

Loading...