sigaltstack not working
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.
Signature · 4 lines
Andreas Schwab "And now for something [email protected] 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
#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;
voidstackoverflow_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 ();
}
}Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andreas Schwab
Andreas> The appended program isn't working as expected. As soon as Andreas> the stack limit is reached it hangs without actually Andreas> executing the signal handler.
I'm aware of this problem and it's on my todo list, but I'm not sure exactly when I'll find time to fix it. Did you encounter this in a real program or just with a test program?
--david
David Mosberger <[email protected]> writes:
|> >>>>> On 17 Sep 2001 16:12:34 +0200, Andreas Schwab <[email protected]> said: |> |> Andreas> The appended program isn't working as expected. As soon as |> Andreas> the stack limit is reached it hangs without actually |> Andreas> executing the signal handler. |> |> I'm aware of this problem and it's on my todo list, but I'm not sure |> exactly when I'll find time to fix it. Did you encounter this in a |> real program or just with a test program?
It is derived from a test program in clisp 2.26 that verifies that catching stack overflow works. That test is even worse, you can only kill it with SIGKILL.
Andreas.
Signature · 4 lines
Andreas Schwab "And now for something [email protected] 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
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andreas Schwab
Andreas> It is derived from a test program in clisp 2.26 that Andreas> verifies that catching stack overflow works. That test is Andreas> even worse, you can only kill it with SIGKILL.
OK, that makes sense. I'll look into it asap.
On an unrelated note: I fixed the ia32 subsystem so it can run realplay v8, mozilla v0.94 (including Flash plug-in), and OpenOffice 638, among others. If someone has an urgent need for this, I can make an interim patch availabe. Otherwise, it will show up in 2.4.10 (which presumably will happen soon).
--david
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andreas Schwab
Andreas> The appended program isn't working as expected. As soon as Andreas> the stack limit is reached it hangs without actually Andreas> executing the signal handler.
Below is a first draft to fix this problem. With the patch applied, the test program works fine. I call it a "first draft" since it hasn't received a whole lot of testing yet. I'd appreciate it if others could help with testing. If you find any bugs, please let me know (and if it works, I appreciate a note, too ;-).
For completeness, it is also necessary to update the MINSIGSTKSZ and SIGSTKSZ macros in include/asm-ia64/signal.h. I'm using the following values now:
#define MINSIGSTKSZ 131027 /* min. stack size for sigaltstack() */ #define SIGSTKSZ 262144 /* default stack size for sigaltstack() */
The old values were far too small. The new values are somewhat largish but it's better to be safe here as the values really can't be increased without breaking binary compatibility. Thanks to Rafael Hernandez for finding this!
Jes, will you make the corresponding changes to sigcontext.h and signal.h in libc?
Thanks,
--david
include/asm-ia64/sigcontext.h renamed from include/asm-ia64/sigcontext.h~ +2 -1
@@ -40,7 +40,8 @@unsigned long sc_gr[32 ];/* general registers (static partition) */ struct ia64_fpreg sc_fr[128 ];/* floating-point registers */ -unsigned long sc_rsvd[16 ];/* reserved for future use */ +unsigned long sc_loadrs; +unsigned long sc_rsvd[15 ];/* reserved for future use */ /* * The mask must come last so we can increase _NSIG_WORDS
arch/ia64/tools/print_offsets.c renamed from arch/ia64/tools/print_offsets.c~ +1 -0
@@ -165,6 +165,7 @@ { "IA64_SIGCONTEXT_FR6_OFFSET", offsetof (struct sigcontext, sc_fr[6]) }, { "IA64_SIGCONTEXT_PR_OFFSET", offsetof (struct sigcontext, sc_pr) }, { "IA64_SIGCONTEXT_R12_OFFSET", offsetof (struct sigcontext, sc_gr[12]) }, + { "IA64_SIGCONTEXT_LOADRS_OFFSET", offsetof (struct sigcontext, sc_loadrs) }, { "IA64_SIGFRAME_ARG0_OFFSET", offsetof (struct sigframe, arg0) }, { "IA64_SIGFRAME_ARG1_OFFSET", offsetof (struct sigframe, arg1) }, { "IA64_SIGFRAME_ARG2_OFFSET", offsetof (struct sigframe, arg2) },
arch/ia64/kernel/gate.S renamed from arch/ia64/kernel/gate.S~ +12 -6
@@ -74,7 +74,8 @@ .vframesp SP_OFF+SIGCONTEXT_OFF .body - .prologue + .label_state 1 + adds base0=SIGHANDLER_OFF,sp adds base1=RBS_BASE_OFF,sp br.call.sptk.many rp
@@ -156,6 +157,8 @@ mov r15=__NR_rt_sigreturn break __BREAK_SYSCALL + .body + .copy_state 1 setup_rbs: mov ar.rsc=0 // put RSE into enforced lazy mode ;;
@@ -180,22 +183,25 @@ mov ar.rsc=0xf // set RSE into eager mode, pl 3 br.cond.sptk back_from_setup_rbs + .prologue + .copy_state 1 + .spillsp ar.rnat, RNAT_OFF+SIGCONTEXT_OFF + .body restore_rbs: alloc r2=ar.pfs,0,0,0,0 // alloc null frame adds r16=(LOADRS_OFF+SIGCONTEXT_OFF),sp ;; ld8 r14=[r16] + adds r16=(RNAT_OFF+SIGCONTEXT_OFF),sp ;; mov ar.rsc=r14 // put RSE into enforced lazy mode + ld8 r14=[r16] // get new rnat ;; loadrs // restore dirty partition - - adds r16=(RNAT_OFF+SIGCONTEXT_OFF),sp ;; - ld8 r14=[r16] // get new rnat - mov ar.bspstore=r15 // set old register backing store area + mov ar.bspstore=r15 // switch back to old register backing store area ;; - mov ar.rnat=r14 // establish new rnat + mov ar.rnat=r14 // restore RNaT mov ar.rsc=0xf // (will be restored later on from sc_ar_rsc) // invala not necessary as that will happen when returning to user-mode br.cond.sptk back_from_restore_rbs
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"David" = David Mosberger <[email protected]> writes:
David> Jes, will you make the corresponding changes to sigcontext.h David> and signal.h in libc?
Sure, I'll look at it when I get back to Canada, hopefully next week.
Cheers
Jes
David Mosberger <[email protected]> writes:
|> --- lia64-kdb/arch/ia64/kernel/gate.S~ Mon Sep 17 18:54:41 2001
|> +++ lia64-kdb/arch/ia64/kernel/gate.S Mon Sep 17 21:18:39 2001
This does not apply on top of the 2.4.9-ia64-010820 patch.
Andreas.
Signature · 4 lines
Andreas Schwab "And now for something [email protected] 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