将 Win32 SEH 与堆分配的堆栈帧混合使用 [英] Mixing Win32 SEH with heap-allocated stack frames

查看:14
本文介绍了将 Win32 SEH 与堆分配的堆栈帧混合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在不削弱 SEH 的情况下摆脱 Win32 的一大堆"模型?我希望能够在堆上分配堆栈帧,作为实现协程的一种方式.但是,我的代码目前依赖于 SEH,以及这篇文章,向下几页,说(与异常处理程序的遍历、扫描、强调我的有关):

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):

在这个链遍历过程中,操作系统对损坏的堆栈非常偏执.它检查所有链条目是否在堆栈范围内.(这些界限也记录在 TEB 中).操作系统还会检查堆栈中的所有条目是否按升序.如果您违反这些规则,操作系统将认为堆栈已损坏并且无法处理异常.这是 Win32 应用程序无法将其堆栈分解为多个不相交的段作为处理堆栈溢出的创新技术的原因之一.

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.

有没有人能够解决这个问题并在本机 Win32 应用程序中使用不相交的堆栈来使用 SEH?另外,是否还有其他 Win32 特定的陷阱"与不相交的堆栈?

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?

推荐答案

Fibers 专门添加到 Win32 中以支持这一点.开始阅读这里...检查这个警告 博客文章.

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

这篇关于将 Win32 SEH 与堆分配的堆栈帧混合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆