Mixing Win32 SEH with heap-allocated stack frames

一个人想着一个人 提交于 2019-12-13 12:48:42

问题


Is there a way to escape the "one big stack" model of Win32 without crippling SEH? I'd like to be able to allocate stack frames on the heap, as a way to implement coroutines. However, my code is currently depending on SEH, and this article, a few pages down, says (relating to traversal of exception handlers, scanning, emphasis mine):

The OS is pretty paranoid about corrupt stacks during this chain traversal. It checks that all chain entries are within the bounds of the stack. (These bounds are also recorded in the TEB). The OS also checks that all entries are in ascending order on the stack. If you violate these rules, the OS will consider the stack to be corrupt and will be unable to process exceptions. This is one of the reasons that a Win32 application cannot break its stack into multiple disjoint segments as an innovative technique for dealing with stack overflow.

So basically, if an exception occurs while the current stack frame is outside the "one big stack", the process will terminate instantly. Not ideal behavior.

Has anyone been able to work around this issue and utilitze SEH with a disjoint stack in a native Win32 app? Also, are there any other Win32-specific "gotchas" with disjoint stacks?


回答1:


Fibers were specifically added to Win32 to support this. Start reading here... Check this cautionary blog post as well.



来源:https://stackoverflow.com/questions/2357102/mixing-win32-seh-with-heap-allocated-stack-frames

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!