sigaltstack doesn't do anything?

Craig Metz (cmetz@inner.net)
Sun, 28 Feb 1999 17:03:18 -0500


I've been working on a program that needs to flip stacks around, and I'm
finding that sigaltstack() doesn't seem to cause any actual behavioral change
to happen, at least not with Linux/i386 2.2.0 and glibc 2.1.

Take this test program:

#include <stdio.h>
#include <stdlib.h>
#include <sys/signal.h>

void *stack;

void callfoo(int bar)
{
printf("bar=%d, &bar=%p\n", bar, &bar);
};

void sighandler(int foo)
{
printf("foo=%d, &foo=%p\n", foo, &foo);
callfoo(42);
};

int main()
{
stack_t ss, oss;

if (!(stack = malloc(8192)))
exit(1);

memset(&ss, 0, sizeof(stack_t));
ss.ss_sp = stack;
ss.ss_size = 8192;

signal(SIGUSR1, sighandler);

if (sigaltstack(&ss, &oss))
exit(2);

printf("&ss=%p, stack=%p, oss.ss_sp=%p\n", &ss, stack, oss.ss_sp);

if (sigaltstack(&ss, &oss))
exit(2);

printf("oss.ss_sp=%p, oss.ss_size=%d, oss.ss_flags=%d\n", oss.ss_sp,
oss.ss_size, oss.ss_flags);

raise(SIGUSR1);

while(1);
};

When I run it, I get:

&ss=0xbffffacc, stack=0x804a828, oss.ss_sp=(nil)
oss.ss_sp=0x804a828, oss.ss_size=8192, oss.ss_flags=0
foo=10, &foo=0xbffff9cc
bar=42, &bar=0xbffff9c0

And if I send a SIGUSR1 from another terminal, it prints:

foo=10, &foo=0xbffff9e4
bar=42, &bar=0xbffff9d8

None of these stack-local variables are on the stack I told the system to
use. I've looked quickly at the kernel source, and it looks like the
sigaltstack code is checking and storing the stack info correctly, but the
system isn't actually doing anything with it.

Am I doing something wrong, is this feature not really implemented yet, or
is this a bug?

-Craig

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/