swapcontext and stack size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, I have a bug when I compile and run this program extracted from the ccan[1],
the important point is the size of the stack

       { "HAVE_POINTER_SAFE_MAKECONTEXT", "passing pointers via makecontext()",
          "DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE",
          "HAVE_UCONTEXT", NULL,
          "#include <stddef.h>\n"
          "#include <ucontext.h>\n"
          "static int worked = 0;\n"
          "static char stack[2048];\n"
          "static ucontext_t a, b;\n"
          "static void fn(void *p, void *q) {\n"
          "     void *cp = &worked;\n"
          "     void *cq = (void *)(~((ptrdiff_t)cp));\n"
          "     if ((p == cp) && (q == cq))\n"
          "             worked = 1;\n"
          "     swapcontext(&a, &b);\n"
          "}\n"
          "int main(void) {\n"
          "     void *ap = &worked;\n"
          "     void *aq = (void *)(~((ptrdiff_t)ap));\n"
          "     getcontext(&a);\n"
          "     a.uc_stack.ss_sp = stack;\n"
          "     a.uc_stack.ss_size = sizeof(stack);\n"
          "     makecontext(&a, (void (*)(void))fn, 2, ap, aq);\n"
          "     swapcontext(&b, &a);\n"
          "     return worked ? 0 : 1;\n"
          "}\n"
        },

This code work on x86 32bits arch, but it segfault on x86_64 arch with gcc9

BUt it works on gcc8 on both arch.

So my question is what has changed between gcc8 and gcc9 around the stack size.

PS: Is I replace 2048 by 8192, it works in all cases.

Cheers

Frederic


[1] https://github.com/rustyrussell/ccan/blob/master/tools/configurator/configurator.c



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux