将 Win32 SEH 与堆分配的堆栈帧混合
有没有一种方法可以摆脱 Win32 的“一大堆”模型而不破坏 SEH?我希望能够在堆上分配堆栈帧,作为实现协程的一种方式。但是,我的代码目前依赖于 SEH,并且这篇文章< /a>,往下几页,说(与异常处理程序的遍历、扫描有关,强调我的):
操作系统对链遍历期间损坏的堆栈非常偏执。它检查所有链条目是否在堆栈范围内。 (这些界限也记录在 TEB 中)。操作系统还会检查堆栈上的所有条目是否按升序排列。如果违反这些规则,操作系统将认为堆栈已损坏并且无法处理异常。这是 Win32 应用程序无法将其堆栈分成多个不相交段作为处理堆栈溢出的创新技术的原因之一。
所以基本上,如果当前堆栈帧位于“一大堆栈”之外时发生异常,则进程将立即终止。不理想的行为。
有没有人能够解决这个问题并在本机 Win32 应用程序中使用不相交堆栈来使用 SEH?另外,是否还有其他特定于 Win32 且具有不相交堆栈的“陷阱”?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Win32 中专门添加了纤程来支持这一点。 此处开始阅读... 检查此内容也请注意博客文章。
Fibers were specifically added to Win32 to support this. Start reading here... Check this cautionary blog post as well.