public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] sigaltstack not working
@ 2001-09-17 14:12 Andreas Schwab
  2001-09-17 15:07 ` David Mosberger
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andreas Schwab @ 2001-09-17 14:12 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

The appended program isn't working as expected.  As soon as the stack
limit is reached it hangs without actually executing the signal handler.

Andreas.

-- 
Andreas Schwab                                  "And now for something
Andreas.Schwab@suse.de				completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5

[-- Attachment #2: sigaltstack.c --]
[-- Type: text/plain, Size: 1206 bytes --]

#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <sys/types.h>
#include <sys/resource.h>

sigjmp_buf mainloop;

volatile int pass = 0;

void
stackoverflow_handler (int sig)
{
  pass++;
  printf ("Stack overflow %d caught.\n", pass);
  siglongjmp (mainloop, pass);
}

int
recurse (int n)
{
  printf ("%p\n", &n);
  if (n >= 0)
    return n + recurse (n + 1);
  else
    return 0;
}

int
main ()
{
  char mystack[16384];
  struct rlimit rl;
  stack_t ss;
  struct sigaction action;

  rl.rlim_cur = rl.rlim_max = 0x100000;	/* 1 MB */
  setrlimit (RLIMIT_STACK, &rl);
  ss.ss_sp = mystack;
  ss.ss_size = sizeof (mystack);
  ss.ss_flags = 0;
  if (sigaltstack (&ss, (stack_t *) 0) < 0)
    exit (0);

  action.sa_handler = stackoverflow_handler;
  action.sa_flags = SA_ONSTACK;
  sigemptyset (&action.sa_mask);
  if (sigaction (SIGSEGV, &action, 0) < 0)
    exit (0);

  switch (sigsetjmp (mainloop, 1))
    {
    case 0:
    case 1:
      printf ("Starting recursion pass %d.\n", pass + 1);
      recurse (0);
      printf ("no endless recursion?!\n");
      exit (1);

    case 2:
      printf ("Test passed.\n");
      exit (0);

    default:
      abort ();
    }
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-09-18  9:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-09-17 14:12 [Linux-ia64] sigaltstack not working Andreas Schwab
2001-09-17 15:07 ` David Mosberger
2001-09-17 15:27 ` Andreas Schwab
2001-09-17 15:33 ` David Mosberger
2001-09-18  5:53 ` David Mosberger
2001-09-18  8:50 ` Jes Sorensen
2001-09-18  9:21 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox