[Gc] GC_init from non-main thread fails with segfault

Reiterer, Horst horst.reiterer at fabasoft.com
Tue Jan 10 05:48:11 PST 2006


If the GC is initialized (GC_init) in a thread other than the process
main thread on a Linux platform (RHEL4, NPTL), the implementation causes
a segmentation fault because GC_push_all_stacks IMHO wrongly assumes
that the initiator thread equals the process main thread and sets the
stack bottom accordingly before calling GC_push_all_stack.

The stack trace is as follows:


The fault occurs while tracing the stack and accessing unmapped memory
as a result of the incorrect stack bottom - the current thread's stack
bottom should IMHO be passed to the function, not the main thread's
stack bottom.

The issue can be fixed by reading the stack address via
pthread_getattr_np and pthread_attr_getstackaddr and falling back to
GC_stackbottom if the current thread in GC_push_all_stacks is the
process main thread. Would this be a legitimate fix to consider for
inclusion? The problem here is identifying the main thread, I'm
currently doing that by comparing the results of getpid() and gettid()
but that obviously would not work in non-NPTL environments.

I guess that this case isn't currently being handled because the GC is
usually initialized right in the main thread. Or am I missing something?



More information about the Gc mailing list