关于setjmp的/ longjmp的 [英] About setjmp/longjmp

查看:115
本文介绍了关于setjmp的/ longjmp的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究的的setjmp / longjmp的并发现了的setjmp 保存寄存器,如指令指针,堆栈指针等...

I was investigating setjmp/longjmp and found out that setjmp saves registers such as instruction pointer, stack pointer etc...

不过我不明白这里要说的是,不能在线程本身的堆栈中的数据调用之间修改为的setjmp 的longjmp 。在这种情况下,不会的longjmp 无法正常工作。

However what I don't get here is that, can't the data in the stack of the thread itself be modified between the call to setjmp and longjmp. In that case, wouldn't longjmp not work as expected.

为了明确这一点,例如,当的longjmp 恢复堆栈指针,说,在现在的堆栈指针指向内存中的数据是不一样的是,当的setjmp 被调用。会发生这种情况?如果出现这种情况,是不是麻烦吗?

To make it clear, for example, when longjmp restores the stack pointer, say the data in the memory the stack pointer is pointing now is not the same as was when setjmp was called. Can this happen? And if that happens, aren't we in trouble?

还有什么是该语句的意思,的的longjmp()程序可能不被其称为setjmp的(常规之后调用)例程的回报。

Also what is meant by the statement, "The longjmp() routines may not be called after the routine which called the setjmp() routines returns."

推荐答案

堆栈指针标志着堆栈的拿来主义和未使用部分之间的分工。当你调用的setjmp ,目前所有的调用帧都在拿来主义的一面,而发生在的setjmp ,但在此之前它被称为的setjmp 返回功能,对保存堆栈指针的未使用方其呼叫帧。请注意,调用的longjmp 之后,调用函数的setjmp 返回调用未定义行为,所以这种情况下,并不需要是考虑的。

The stack pointer marks the division between the "used" and "unused" portions of the stack. When you call setjmp, all current call frames are on the "used" side, and any calls that take place after setjmp, but before the function which called setjmp returns, have their call frames on the "unused" side of the saved stack pointer. Note that calling longjmp after the function which called setjmp has returned invokes undefined behavior, so that case does not need to be considered.

现在,它可能是在一些现有呼叫帧的局部变量后的setjmp 修改,或者通过调用函数或通过指针,这也是原因之一有必要使用挥发性在很多情况下...

Now, it's possible that local variables in some of the existing call frames are modified after setjmp, either by the calling function or through pointers, and this is one reason why it's necessary to use volatile in many cases...

这篇关于关于setjmp的/ longjmp的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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