4010755.patch revision 919
341N/A###############################################################################
688N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
919N/A# Use is subject to license terms.
341N/A#
341N/A# Permission is hereby granted, free of charge, to any person obtaining a
919N/A# copy of this software and associated documentation files (the "Software"),
919N/A# to deal in the Software without restriction, including without limitation
919N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A# and/or sell copies of the Software, and to permit persons to whom the
919N/A# Software is furnished to do so, subject to the following conditions:
919N/A#
919N/A# The above copyright notice and this permission notice (including the next
919N/A# paragraph) shall be included in all copies or substantial portions of the
919N/A# Software.
919N/A#
919N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A# DEALINGS IN THE SOFTWARE.
341N/A#
341N/A
341N/A4010755: SEGV in XFindContext if XInitThreads has been enabled
341N/A
341N/AXFindContext in Xlib was calling _XLockMutex with an uninitialized
341N/Amutex lock structure. The new version of XInitThreads activates the
341N/Alocking functions at any time, even after displays have been created.
341N/A
341N/AIn this new case, the context structure was created prior to
341N/AXInitThreads being invoked. As a result, the display contained an
341N/Aopaque pointer to this context structure, which still contained an
341N/Auninitialized lock structure.
341N/A
341N/AThe solution was to explicitly set the lock structure pointer to NULL
688N/A(as a flag) when creating the context, then check for NULL when
341N/Alocking. If NULL is found and threads are now enabled, then the
341N/Astructure gets reinitialized to the correct mutex lock structure
688N/Ain the lock call.
341N/A
341N/AAnother area besides the functions in Context.c are the functions in
341N/AXrm.c. A similar fix was added to them as well.
341N/A
341N/A
341N/Adiff -urp -x '*~' -x '*.orig' src/Context.c src/Context.c
688N/A--- src/Context.c 2009-01-28 21:09:42.000000000 -0800
688N/A+++ src/Context.c 2009-04-08 00:17:42.988516000 -0700
688N/A@@ -192,6 +192,9 @@ int XSaveContext(
341N/A return XCNOMEM;
341N/A }
341N/A db->numentries = 0;
688N/A+#ifdef SUNSOFT
341N/A+ db->linfo.lock = (xmutex_t) NULL;
688N/A+#endif
341N/A _XCreateMutex(&db->linfo);
341N/A #ifdef MOTIFBC
341N/A if (!display) *pdb = db; else
341N/Adiff -urp -x '*~' -x '*.orig' src/Xrm.c src/Xrm.c
688N/A--- src/Xrm.c 2009-03-25 17:52:09.000000000 -0700
688N/A+++ src/Xrm.c 2009-04-08 00:17:43.008271000 -0700
688N/A@@ -498,6 +498,9 @@ static XrmDatabase NewDatabase(void)
341N/A
341N/A db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec));
341N/A if (db) {
688N/A+#ifdef SUNSOFT
341N/A+ db->linfo.lock = (xmutex_t) NULL;
688N/A+#endif
341N/A _XCreateMutex(&db->linfo);
341N/A db->table = (NTable)NULL;
341N/A db->mbstate = (XPointer)NULL;
688N/Adiff -urp -x '*~' -x '*.orig' src/locking.c src/locking.c
688N/A--- src/locking.c 2009-04-08 00:17:31.819992000 -0700
688N/A+++ src/locking.c 2009-04-08 00:17:43.009128000 -0700
688N/A@@ -105,6 +105,16 @@ static void _XLockMutex(
688N/A XTHREADS_FILE_LINE_ARGS
688N/A )
341N/A {
688N/A+#ifdef SUNSOFT
688N/A+ /* Make sure any locks in structures that were created before calling
688N/A+ * XInitThreads are initialized before locking, now that we allow calls
688N/A+ * to XInitThreads after other Xlib calls (Sun bugs 1234757 & 4010755)
688N/A+ */
688N/A+ if (lip->lock == NULL) {
688N/A+ static void _XCreateMutex(LockInfoPtr lip); /* Forward declaration */
688N/A+ _XCreateMutex(lip);
688N/A+ }
688N/A+#endif /* SUNSOFT */
688N/A xmutex_lock(lip->lock);
688N/A }
341N/A