4010755.patch revision 341
705N/A###############################################################################
705N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
705N/A# Use subject to license terms.
705N/A#
705N/A# Permission is hereby granted, free of charge, to any person obtaining a
705N/A# copy of this software and associated documentation files (the
705N/A# "Software"), to deal in the Software without restriction, including
705N/A# without limitation the rights to use, copy, modify, merge, publish,
705N/A# distribute, and/or sell copies of the Software, and to permit persons
705N/A# to whom the Software is furnished to do so, provided that the above
705N/A# copyright notice(s) and this permission notice appear in all copies of
705N/A# the Software and that both the above copyright notice(s) and this
705N/A# permission notice appear in supporting documentation.
705N/A#
705N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
705N/A# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
705N/A# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
705N/A# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
705N/A# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
705N/A# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
705N/A# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
705N/A# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
705N/A# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
705N/A#
705N/A# Except as contained in this notice, the name of a copyright holder
705N/A# shall not be used in advertising or otherwise to promote the sale, use
705N/A# or other dealings in this Software without prior written authorization
705N/A# of the copyright holder.
705N/A#
705N/A
705N/A4010755: SEGV in XFindContext if XInitThreads has been enabled
705N/A
705N/AXFindContext in Xlib was calling _XLockMutex with an uninitialized
705N/Amutex lock structure. The new version of XInitThreads activates the
705N/Alocking functions at any time, even after displays have been created.
705N/A
705N/AIn this new case, the context structure was created prior to
705N/AXInitThreads being invoked. As a result, the display contained an
705N/Aopaque pointer to this context structure, which still contained an
705N/Auninitialized lock structure.
705N/A
705N/AThe solution was to explicitly set the lock structure pointer to NULL
705N/A(as a flag) when creating the context, then check for NULL before
705N/Alocking. If NULL is found and threads are now enabled, then the
705N/Astructure gets reinitialized to the correct mutex lock structure
705N/Abefore the lock call.
705N/A
705N/AAnother area besides the functions in Context.c are the functions in
705N/AXrm.c. A similar fix was added to them as well.
705N/A
705N/A
705N/Adiff -urp -x '*~' -x '*.orig' src/Context.c src/Context.c
705N/A--- src/Context.c 2007-05-16 08:34:44.000000000 -0700
705N/A+++ src/Context.c 2008-02-12 21:00:44.588363000 -0800
705N/A@@ -192,6 +192,7 @@ int XSaveContext(
705N/A return XCNOMEM;
705N/A }
705N/A db->numentries = 0;
705N/A+ db->linfo.lock = (xmutex_t) NULL;
705N/A _XCreateMutex(&db->linfo);
705N/A #ifdef MOTIFBC
705N/A if (!display) *pdb = db; else
705N/A@@ -203,6 +204,8 @@ int XSaveContext(
705N/A UnlockDisplay(display);
705N/A }
}
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
head = &Hash(db, rid, context);
_XUnlockMutex(&db->linfo);
@@ -254,6 +257,8 @@ int XFindContext(display, rid, context,
}
if (!db)
return XCNOENT;
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
for (entry = Hash(db, rid, context); entry; entry = entry->next)
{
@@ -292,6 +297,8 @@ int XDeleteContext(display, rid, context
}
if (!db)
return XCNOENT;
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
for (prev = &Hash(db, rid, context);
(entry = *prev);
diff -urp -x '*~' -x '*.orig' src/Xrm.c src/Xrm.c
--- src/Xrm.c 2007-05-16 08:34:44.000000000 -0700
+++ src/Xrm.c 2008-02-12 21:00:44.594920000 -0800
@@ -500,6 +500,7 @@ static XrmDatabase NewDatabase(void)
db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec));
if (db) {
+ db->linfo.lock = (xmutex_t) NULL;
_XCreateMutex(&db->linfo);
db->table = (NTable)NULL;
db->mbstate = (XPointer)NULL;
@@ -775,7 +776,11 @@ void XrmCombineDatabase(
if (!*into) {
*into = from;
} else if (from) {
+ if (!(&from->linfo.lock))
+ _XCreateMutex(&from->linfo);
_XLockMutex(&from->linfo);
+ if (!(&(*into)->linfo.lock))
+ _XCreateMutex(&(*into)->linfo);
_XLockMutex(&(*into)->linfo);
if ((ftable = from->table)) {
prev = &(*into)->table;
@@ -1022,6 +1027,8 @@ void XrmQPutResource(
XrmValuePtr value)
{
if (!*pdb) *pdb = NewDatabase();
+ if (!(*pdb)->linfo.lock)
+ _XCreateMutex(&(*pdb)->linfo);
_XLockMutex(&(*pdb)->linfo);
PutEntry(*pdb, bindings, quarks, type, value);
_XUnlockMutex(&(*pdb)->linfo);
@@ -1038,6 +1045,8 @@ XrmPutResource(
XrmQuark quarks[MAXDBDEPTH+1];
if (!*pdb) *pdb = NewDatabase();
+ if (!(*pdb)->linfo.lock)
+ _XCreateMutex(&(*pdb)->linfo);
_XLockMutex(&(*pdb)->linfo);
XrmStringToBindingQuarkList(specifier, bindings, quarks);
PutEntry(*pdb, bindings, quarks, XrmStringToQuark(type), value);
@@ -1056,6 +1065,8 @@ XrmQPutStringResource(
if (!*pdb) *pdb = NewDatabase();
value.addr = (XPointer) str;
value.size = strlen(str)+1;
+ if (!(*pdb)->linfo.lock)
+ _XCreateMutex(&(*pdb)->linfo);
_XLockMutex(&(*pdb)->linfo);
PutEntry(*pdb, bindings, quarks, XrmQString, &value);
_XUnlockMutex(&(*pdb)->linfo);
@@ -1538,6 +1549,8 @@ XrmPutStringResource(
XrmStringToBindingQuarkList(specifier, bindings, quarks);
value.addr = (XPointer) str;
value.size = strlen(str)+1;
+ if (!(*pdb)->linfo.lock)
+ _XCreateMutex(&(*pdb)->linfo);
_XLockMutex(&(*pdb)->linfo);
PutEntry(*pdb, bindings, quarks, XrmQString, &value);
_XUnlockMutex(&(*pdb)->linfo);
@@ -1550,6 +1563,8 @@ XrmPutLineResource(
_Xconst char*line)
{
if (!*pdb) *pdb = NewDatabase();
+ if (!(*pdb)->linfo.lock)
+ _XCreateMutex(&(*pdb)->linfo);
_XLockMutex(&(*pdb)->linfo);
GetDatabase(*pdb, line, (char *)NULL, False);
_XUnlockMutex(&(*pdb)->linfo);
@@ -1562,6 +1577,8 @@ XrmGetStringDatabase(
XrmDatabase db;
db = NewDatabase();
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
GetDatabase(db, data, (char *)NULL, True);
_XUnlockMutex(&db->linfo);
@@ -1670,6 +1687,8 @@ XrmGetFileDatabase(
return (XrmDatabase)NULL;
db = NewDatabase();
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
GetDatabase(db, str, filename, True);
_XUnlockMutex(&db->linfo);
@@ -1694,6 +1713,8 @@ XrmCombineFileDatabase(
*target = db = NewDatabase();
} else
db = NewDatabase();
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
GetDatabase(db, str, filename, True);
_XUnlockMutex(&db->linfo);
@@ -1966,6 +1987,8 @@ Bool XrmEnumerateDatabase(
if (!db)
return False;
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
eclosure.db = db;
eclosure.proc = proc;
@@ -2262,6 +2285,8 @@ Bool XrmQGetSearchList(
closure.idx = -1;
closure.limit = listLength - 2;
if (db) {
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
table = db->table;
if (*names) {
@@ -2540,6 +2565,8 @@ Bool XrmQGetResource(
VClosureRec closure;
if (db && *names) {
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
closure.type = pType;
closure.value = pValue;
@@ -2636,6 +2663,8 @@ XrmLocaleOfDatabase(
XrmDatabase db)
{
const char* retval;
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
retval = (*db->methods->lcname)(db->mbstate);
_XUnlockMutex(&db->linfo);
@@ -2648,6 +2677,8 @@ void XrmDestroyDatabase(
register NTable table, next;
if (db) {
+ if (!db->linfo.lock)
+ _XCreateMutex(&db->linfo);
_XLockMutex(&db->linfo);
for (next = db->table; (table = next); ) {
next = table->next;