This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH i386] make -mstack-arg-probe work on all x86 targets (instead of cygwin/mingw only)


> Based on whatever testing I did on x86_64-linux, it did seem to work.

Try this:

#include <stdio.h>
#include <stdlib.h>

static void probe_stack (unsigned long int size)
{
  asm volatile ("		\
    movq    %0, %%rax;		\
    movq    %%rsp, %%r10;	\
    cmpq    $0x1000, %%rax;	\
    jb      Ldone;		\
				\
   Lprobe:			\
    subq    $0x1000, %%r10;	\
    orl     $0x0, (%%r10);	\
    subq    $0x1000, %%rax;	\
    cmpq    $0x1000, %%rax;	\
    ja      Lprobe;		\
				\
   Ldone:			\
    subq    %%rax, %%r10;	\
    orl     $0x0, (%%r10);	\
    movq    %%r10, %%rsp;	\
  " : : "r" (size) : "rax", "r10" );
}

int main(int argc, char **argv)
{
  if (argc != 2)
    {
      puts ("error: size argument needed");
      exit (1);
    }

  probe_stack (atoi(argv[1]));
  return 0;
}

How far can you go without crashing?  On some kernels, it's very low (8KB), on 
others it's more like 80KB according to my experiments.

> It would be great to get this and the remaining -fstack-check patches
> checked in!

No disagreement. :-)

-- 
Eric Botcazou


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]