Bug 881 - NPTL threads inherit alternate signal stack
Summary: NPTL threads inherit alternate signal stack
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: nptl (show other bugs)
Version: 2.3.4
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-27 16:03 UTC by Michael Kerrisk
Modified: 2005-04-28 15:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Kerrisk 2005-04-27 16:03:43 UTC
The POSIX.1-2003 specification of pthread_create() says:

    The alternate signal stack shall not be inherited

However, as the simple program below shows, the settings 
established by sigaltstack() are inherited in the new thread 
created by pthread_create().  When I run this program on one 
x86 system I see:

    $ ./a.out
    main:  Checked alternate stack is at:   0x804a008, 0, 8192
    Thread: Initial alternate stack is at:  0x804a008, 0, 8192

I notice that Solaris 8 seems to behave the same as Linux/glibc, 
but that Tru64 5.1B does what I would expect, showing the fields 
of the sigstack structure as being zeroed in the thread (i.e.,
the last line of output above).

(Assuming I've interpreted the standard correctly...) Is this 
fixable? Or otherwise, is it documented somewhere?.

Cheers,

Michael

/* thread_sigaltstack_simple.c */

#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#define errExit(msg)            { perror(msg); exit(EXIT_FAILURE); }

#define errExitEN(en, msg)      { errno = en; perror(msg); \
                                  exit(EXIT_FAILURE); }

static void *
threadFunc1(void *arg)
{
    stack_t os;

    if (sigaltstack(NULL, &os) == -1) errExit("sigaltstack");
    printf("Thread: Initial alternate stack is at: %10p, %d, %ld\n",
            os.ss_sp, os.ss_flags, (long) os.ss_size);

    return NULL;
} 

int
main(int argc, char *argv[])
{
    pthread_t t1;
    int s;
    stack_t sigstack, os;

    sigstack.ss_sp = malloc(SIGSTKSZ);
    if (sigstack.ss_sp == NULL) errExit("malloc");
    sigstack.ss_size = SIGSTKSZ;
    sigstack.ss_flags = 0;
    if (sigaltstack(&sigstack, NULL) == -1) errExit("sigaltstack");

    if (sigaltstack(NULL, &os) == -1) errExit("sigaltstack");
    printf("main:  Checked alternate stack is at:  %10p, %d, %ld\n",
            os.ss_sp, os.ss_flags, (long) os.ss_size);

    s = pthread_create(&t1, NULL, threadFunc1, (void *) 1);
    if (s != 0) errExitEN(s, "pthread_create");

    s = pthread_join(t1, NULL);
    if (s != 0) errExitEN(s, "pthread_join");

    exit(EXIT_SUCCESS);
}
Comment 1 Ulrich Drepper 2005-04-28 15:10:13 UTC
This is a kernel issue.