4010755.patch revision 688
###############################################################################
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use subject to license terms.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, provided that the above
# copyright notice(s) and this permission notice appear in all copies of
# the Software and that both the above copyright notice(s) and this
# permission notice appear in supporting documentation.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Except as contained in this notice, the name of a copyright holder
# shall not be used in advertising or otherwise to promote the sale, use
# or other dealings in this Software without prior written authorization
# of the copyright holder.
#
4010755: SEGV in XFindContext if XInitThreads has been enabled
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 when
locking. If NULL is found and threads are now enabled, then the
structure gets reinitialized to the correct mutex lock structure
in 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.
diff -urp -x '*~' -x '*.orig' src/Context.c src/Context.c
--- src/Context.c 2009-01-28 21:09:42.000000000 -0800
+++ src/Context.c 2009-04-08 00:17:42.988516000 -0700
@@ -192,6 +192,9 @@ int XSaveContext(
return XCNOMEM;
}
db->numentries = 0;
+#ifdef SUNSOFT
+ db->linfo.lock = (xmutex_t) NULL;
+#endif
_XCreateMutex(&db->linfo);
#ifdef MOTIFBC
if (!display) *pdb = db; else
diff -urp -x '*~' -x '*.orig' src/Xrm.c src/Xrm.c
--- src/Xrm.c 2009-03-25 17:52:09.000000000 -0700
+++ src/Xrm.c 2009-04-08 00:17:43.008271000 -0700
@@ -498,6 +498,9 @@ static XrmDatabase NewDatabase(void)
db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec));
if (db) {
+#ifdef SUNSOFT
+ db->linfo.lock = (xmutex_t) NULL;
+#endif
_XCreateMutex(&db->linfo);
db->table = (NTable)NULL;
db->mbstate = (XPointer)NULL;
diff -urp -x '*~' -x '*.orig' src/locking.c src/locking.c
--- src/locking.c 2009-04-08 00:17:31.819992000 -0700
+++ src/locking.c 2009-04-08 00:17:43.009128000 -0700
@@ -105,6 +105,16 @@ static void _XLockMutex(
XTHREADS_FILE_LINE_ARGS
)
{
+#ifdef SUNSOFT
+ /* Make sure any locks in structures that were created before calling
+ * XInitThreads are initialized before locking, now that we allow calls
+ * to XInitThreads after other Xlib calls (Sun bugs 1234757 & 4010755)
+ */
+ if (lip->lock == NULL) {
+ static void _XCreateMutex(LockInfoPtr lip); /* Forward declaration */
+ _XCreateMutex(lip);
+ }
+#endif /* SUNSOFT */
xmutex_lock(lip->lock);
}