Rob Earhart's WebLog

Yet another reason not to handle all SEH exceptions

... you'll probably forget to call _resetstkoflw() in your exception handler when it's a stack overflow exception.  This re-establishes the guard page, so that the next time the thread hits a stack overflow, it'll get another stack overflow exception; if you forget to call it, then the next time the thread runs off the end of its stack, it'll AV instead (if you're lucky), and not have anywhere to run the exception filter or termination handlers, which could be a problem if there are locks to be dropped, &c.

Everyone understands that you usually don't want to be using try/except, right?  try/finally is almost always more appropriate.

"Gee, Rob, why are you talking about exception handling so much?"  Mostly because in the core OS code, it's an area where there are a lot of unnecessary defects; it'd be nice if more people understood and tested this stuff.

Published Friday, December 17, 2004 5:03 PM by earhart
Filed under:

Comments

 

Michael Kaplan said:

_resetstkoflw has a funny history.

For years it did not exist at all but most people 'knew' it was possible (though it was probably out of most people's grasp to go and write it).

VBA had one, which gave VB/VBA developers a sincere lack of appreciation for the seriousness of stack overflow errors. Of course that solution was very x86 specific.

When Phil wrote this function I remember working with him andpointing out the difference on Win9x platforms with how the guard page stuff worked, but he did all of the real heavy lifting to create a C runtime function that does it all across wide range of platforms.
December 18, 2004 3:07 PM
 

Seth McCarus said:

Rob, nice to have found your blog. SEH is simple on the surface but there are so many hidden caveats - I wish that MSDN or some such reference had a real user's guide to SEH, not just the functions and keywords, but how it should be used.
January 3, 2005 3:40 PM
Anonymous comments are disabled

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker