xe166堆栈溢出异常处理
如果发生堆栈溢出陷阱,我希望控制器:
- 发送一条消息,通知用户发生了堆栈溢出,
- 在消息发送后进行重置
我想知道这是否是一个好主意在开始此异常处理之前重置堆栈指针,以确保该过程将在不弄乱内存的情况下完成,或者是否有更好的方法来处理此异常?
If a stack overflow trap occures, I would like the controller to:
- send a message to inform the user that a stack overflow occured
- do a reset when the message has been sent
I wonder if it is a good idea to reset the Stack Pointer before starting this exception handling to be sure that the procedure will be done without messing up memory or is there a better way to handle this exception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我对早期 C167 编程的记忆(我认为 xe166 就是从它而来)而言,堆栈溢出异常并不意味着有任何问题。这仅意味着您位于堆栈的末尾。事实上,只要有足够的技巧,您就可以使用堆栈溢出和堆栈下溢异常来将更大的堆栈“分页”进出主内存!
因此,如果您可以确保异常处理程序不再需要堆栈,那么您无需重置 SP 即可摆脱困境。尽管我想,您可能会从中调用一些函数,在这种情况下,拥有一些可用的堆栈空间可能会很有用:)
您关于“混乱的堆栈”的评论并不是问题所在 - 一旦堆栈指针到达末尾,任何进一步的堆栈使用都会弄乱其他事情,这些事情可能是您的异常代码将依赖的数据。听起来你必须保证重置发生,但如果你开始用错误的 SP 破坏内存,你无法预测会发生什么。
因此,如果它是一个远程关键系统,请找到一种方法来为“紧急堆栈”提供内存,然后将 SP 指向该系统,然后再继续处理异常处理程序。
The stack overflow exception doesn't mean anything is wrong yet as far as I recall from my days programming the early C167s (from which the xe166 comes I think). It just means you are right at the end of the stack. Indeed with sufficient jiggery pokery you can use the stack overflow and stack underflow exceptions to "page" a larger stack in and out of main memory!
So, if you can assure yourself that the exception handler needs no further stack then you could get away without resetting the SP. You're likely to be calling some functions from it though I imagine, in which case having some free stack space might be useful :)
Your comment regarding "messed up stack" is not quite the issue - once the stack pointer has reached the end, any further stack usage messes up other things which may be data your exception code is going to rely on. It sounds like you must guarantee a reset takes place, but it you start clobbering memory with an errant SP, you can't predict what might happen.
So, if it's a remotely critical system, find a way to afford the memory for an "emergency stack" then point the SP to that before proceeding with your exception handler.