public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: linux-ia64@vger.kernel.org
Subject: [Linux-ia64] sigaltstack not working
Date: Mon, 17 Sep 2001 14:12:34 +0000	[thread overview]
Message-ID: <marc-linux-ia64-105590698805189@msgid-missing> (raw)

[-- 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 ();
    }
}

             reply	other threads:[~2001-09-17 14:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-17 14:12 Andreas Schwab [this message]
2001-09-17 15:07 ` [Linux-ia64] sigaltstack not working 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-ia64-105590698805189@msgid-missing \
    --to=schwab@suse.de \
    --cc=linux-ia64@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox