This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
problem with pthreads and sigaltstack
- From: Stas Sergeev <stsp at users dot sourceforge dot net>
- To: libc-alpha at sources dot redhat dot com
- Date: Sun, 16 Nov 2003 04:21:19 +0300 (MSK)
- Subject: problem with pthreads and sigaltstack
- I-remoteaddress: 80.250.162.71
- I-remotehost:
- Reply-to: Stas Sergeev <stsp at users dot sourceforge dot net>
Hello.
I have a problem which is that my program
crashes when is simply linked with -lpthread.
My program uses the sigaltstack() and the
sigaction() to set up the signal handlers.
When the signal is received, the
pthread_sighandler() is invoked first, and
gets a SIGSEGV inside itself.
Looking into a linuxthreads sources, I can see
what happens:
pthread_sighandler() calls the thread_self(),
which returns an invalid pointer. It does this:
return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
where the STACK_SIZE is defined to 2Mb, while
I set up the signal stack only to 64Kb with the
sigaltstack, so the pointer returned by the
thread_self() inside the sighandler is totally
bogus.
I don't know where the problem is. My current
workaround is to reserve 2Mb above the alt stack.
This allows my program to be linked with the
pthreads lib and the signal handlers are working
properly, but this is a definitely wrong way
because the pointer returned by thread_self()
doesn't point to any real data that pthread may
expect.
I am using the rather old glibc-2.2.4-19(RH) and
probably the problem will go away if I upgrade,
but I strongly suspect that I am doing something
wrong.
Any ideas where the real problem can be? Is it
the problem with pthreads and I have to upgrade,
or does it look more like a problem somewhere in
an app and it is doing something pthreads can't
tolerate?
I could probably use something like
pthread_attr_setstackaddr() and then pthread_create(),
but I only want to make my program to not crash
when it is linked with the libpthread. What is
the proper way of doing that?
My linux kernel is 2.4.22 and is running on an
AMD Athlon, if that matters.
Thanks for any help.