XIL enables MT-SAFE Xlib by calling XInitThreads prior to using Xlib in an
MT-HOT fashion. This causes a SEGV when running sdtimage because Xlib appears
to call mutex_lock on a NULL mutex in XFindContext().
To reproduce:
setenv LD_LIBRARY_PATH $XILHOME/lib:$LD_LIBRARY_PATH
setenv XIL_DISPLAY SUNWxlib
/usr/dt/bin/sdtimage /shared/xil/data/images/tiff/Parrots.tiff
A core file will be generated that has the following stack trace:
t@0 l@1 <1> where
=>[1] _lock_try_adaptive(0x0, 0x1c594, 0xefffe2dd, 0xc79f0, 0xef19f3d4, 0xef353dd0), at 0xeeba410c
[2] _ti_pthread_mutex_lock(0x0, 0xeebb45cc, 0xc79f0, 0xef3f0034, 0xef19f3d4, 0xef30f404), at 0xeeb98048
[3] XFindContext(0x9e3a8, 0xa77a0, 0xffffffff, 0xefffdb4c, 0xef37a26c, 0xeee93130), at 0xef30f404
[4] _XmGetWidgetExtData(0xa77a0, 0x3, 0xef3f0034, 0x0, 0xa77a0, 0xef43a82c), at 0xef439844
[5] _XmGetFocusData(0xa77a0, 0xef573e18, 0xefffdfa8, 0xc79f0, 0xf9178, 0x0), at 0xef478304
[6] _XmNavigSetValues(0xefffe2c8, 0xefffdfa8, 0xc79f0, 0xef573e18, 0xefffdd68, 0x0), at 0xef47a2cc
[7] SetValues(0xefffe2c8, 0xefffdfa8, 0xc79f0, 0xf9178, 0xefffdd68, 0xef573e18), at 0xef476fc0
[8] CallSetValues(0x0, 0xefffe2c8, 0xefffdfa8, 0xc79f0, 0xf9178, 0xef476e94), at 0xef3c583c
[9] CallSetValues(0x0, 0xefffe2c8, 0xefffdfa8, 0xc79f0, 0xf9178, 0x3), at 0xef3c57d4
[10] XtSetValues(0xef3f3b34, 0xf9178, 0xef3f3b30, 0x0, 0x9db48, 0xef57f66c), at 0xef3c5e00
[11] XtVaSetValues(0xc79f0, 0x0, 0x0, 0x98b54, 0x200, 0x99273), at 0xef3d9ea0
[12] resize_canvas(0x9a9a0, 0x99273, 0x9a998, 0x98b54, 0x9a800, 0x9a323), at 0x4d9b0
[13] open_newfile(0x9a800, 0x9a9a0, 0x9a98c, 0x9a7e8, 0x0, 0xc6488), at 0x32564
[14] main(0x81a34, 0x1, 0x9a7e8, 0xc6488, 0xefffef2a, 0xefffef01), at 0x2d740
XFindContext in Xlib was calling _XLockMutex with an uninitialized
mutex lock structure. The new version of XInitThreads activates
the locking functions at any time, even after displays have been
created.
In this new case, the context structure was created prior to XInitThreads
being invoked. As a result, the display contained an opaque pointer to
this context structure, which still contained an uninitialized lock structure.
The solution was to explicitly set the lock structure pointer to NULL (as a
flag) when creating the context, then check for NULL before locking. If
NULL is found and threads are now enabled, then the structure gets
reinitialized to the correct mutex lock structure before the lock call.
Another area besides the functions in Context.c are the functions in
Xrm.c. A similar fix was added to them as well.