public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* swapcontext and stack size
@ 2019-11-16 10:09 PICCA Frederic-Emmanuel
  0 siblings, 0 replies; only message in thread
From: PICCA Frederic-Emmanuel @ 2019-11-16 10:09 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-16 10:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-16 10:09 swapcontext and stack size PICCA Frederic-Emmanuel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).