<small id='eNyvW'></small><noframes id='eNyvW'>

    1. <i id='eNyvW'><tr id='eNyvW'><dt id='eNyvW'><q id='eNyvW'><span id='eNyvW'><b id='eNyvW'><form id='eNyvW'><ins id='eNyvW'></ins><ul id='eNyvW'></ul><sub id='eNyvW'></sub></form><legend id='eNyvW'></legend><bdo id='eNyvW'><pre id='eNyvW'><center id='eNyvW'></center></pre></bdo></b><th id='eNyvW'></th></span></q></dt></tr></i><div id='eNyvW'><tfoot id='eNyvW'></tfoot><dl id='eNyvW'><fieldset id='eNyvW'></fieldset></dl></div>
      <tfoot id='eNyvW'></tfoot><legend id='eNyvW'><style id='eNyvW'><dir id='eNyvW'><q id='eNyvW'></q></dir></style></legend>

      • <bdo id='eNyvW'></bdo><ul id='eNyvW'></ul>
    2. SetJmp/LongJmp:为什么会抛出段错误?

      时间:2023-09-18

    3. <i id='ikCP7'><tr id='ikCP7'><dt id='ikCP7'><q id='ikCP7'><span id='ikCP7'><b id='ikCP7'><form id='ikCP7'><ins id='ikCP7'></ins><ul id='ikCP7'></ul><sub id='ikCP7'></sub></form><legend id='ikCP7'></legend><bdo id='ikCP7'><pre id='ikCP7'><center id='ikCP7'></center></pre></bdo></b><th id='ikCP7'></th></span></q></dt></tr></i><div id='ikCP7'><tfoot id='ikCP7'></tfoot><dl id='ikCP7'><fieldset id='ikCP7'></fieldset></dl></div>
        <tbody id='ikCP7'></tbody>
      <legend id='ikCP7'><style id='ikCP7'><dir id='ikCP7'><q id='ikCP7'></q></dir></style></legend>

            • <bdo id='ikCP7'></bdo><ul id='ikCP7'></ul>

            • <small id='ikCP7'></small><noframes id='ikCP7'>

                <tfoot id='ikCP7'></tfoot>
                本文介绍了SetJmp/LongJmp:为什么会抛出段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                以下代码总结了我目前遇到的问题.我当前的执行流程如下,我在 GCC 4.3 中运行.

                The following code summarizes the problem I have at the moment. My current execution flow is as follows and a I'm running in GCC 4.3.

                jmp_buf a_buf;
                jmp_buf b_buf;
                
                void b_helper()
                {
                    printf("entering b_helper");
                    if(setjmp(b_buf) == 0)
                    {
                        printf("longjmping to a_buf");
                        longjmp(a_buf, 1);
                    }
                    printf("returning from b_helper");
                    return; //segfaults right here
                }
                void b()
                {
                    b_helper();
                }
                void a()
                {
                    printf("setjmping a_buf");
                    if(setjmp(a_buf) == 0)
                    {
                        printf("calling b");
                        b();
                    }
                    printf("longjmping to b_buf");
                    longjmp(b_buf, 1);
                }
                int main()
                {
                    a();
                }
                

                上述执行流程在 b_helper 返回后立即创建了一个段错误.几乎就好像只有 b_helper 堆栈帧是有效的,并且它下面的堆栈被擦除了.

                The above execution flow creates a segfault right after the return in b_helper. It's almost as if only the b_helper stack frame is valid, and the stacks below it are erased.

                谁能解释为什么会这样?我猜这是一个 GCC 优化,它正在擦除未使用的堆栈帧或其他东西.

                Can anyone explain why this is happening? I'm guessing it's a GCC optimization that's erasing unused stack frames or something.

                谢谢.

                推荐答案

                您只能longjmp() 备份向上调用堆栈.调用 longjmp(b_buf, 1) 是事情开始出错的地方,因为 b_buf 引用的堆栈帧在 longjmp(a_buf) 之后不再存在.

                You can only longjmp() back up the call stack. The call to longjmp(b_buf, 1) is where things start to go wrong, because the stack frame referenced by b_buf no longer exists after the longjmp(a_buf).

                来自 longjmp 的文档:

                在调用 setjmp() 例程的例程返回后,不能调用 longjmp() 例程.

                The longjmp() routines may not be called after the routine which called the setjmp() routines returns.

                这包括通过longjmp()从函数中返回".

                This includes "returning" through a longjmp() out of the function.

                这篇关于SetJmp/LongJmp:为什么会抛出段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:c/c++ 编译器是否通过二的幂值将常量除法优化为 下一篇:如何在 MinGW 中启用实验性 C++11 并发功能?

                相关文章

                最新文章

                • <bdo id='JpOhj'></bdo><ul id='JpOhj'></ul>
                1. <i id='JpOhj'><tr id='JpOhj'><dt id='JpOhj'><q id='JpOhj'><span id='JpOhj'><b id='JpOhj'><form id='JpOhj'><ins id='JpOhj'></ins><ul id='JpOhj'></ul><sub id='JpOhj'></sub></form><legend id='JpOhj'></legend><bdo id='JpOhj'><pre id='JpOhj'><center id='JpOhj'></center></pre></bdo></b><th id='JpOhj'></th></span></q></dt></tr></i><div id='JpOhj'><tfoot id='JpOhj'></tfoot><dl id='JpOhj'><fieldset id='JpOhj'></fieldset></dl></div>
                  <tfoot id='JpOhj'></tfoot>

                    <legend id='JpOhj'><style id='JpOhj'><dir id='JpOhj'><q id='JpOhj'></q></dir></style></legend>
                  1. <small id='JpOhj'></small><noframes id='JpOhj'>