|
1 ############################################################################### |
|
2 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
|
3 # Use subject to license terms. |
|
4 # |
|
5 # Permission is hereby granted, free of charge, to any person obtaining a |
|
6 # copy of this software and associated documentation files (the |
|
7 # "Software"), to deal in the Software without restriction, including |
|
8 # without limitation the rights to use, copy, modify, merge, publish, |
|
9 # distribute, and/or sell copies of the Software, and to permit persons |
|
10 # to whom the Software is furnished to do so, provided that the above |
|
11 # copyright notice(s) and this permission notice appear in all copies of |
|
12 # the Software and that both the above copyright notice(s) and this |
|
13 # permission notice appear in supporting documentation. |
|
14 # |
|
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
|
18 # OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
19 # HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL |
|
20 # INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING |
|
21 # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
22 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
23 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
24 # |
|
25 # Except as contained in this notice, the name of a copyright holder |
|
26 # shall not be used in advertising or otherwise to promote the sale, use |
|
27 # or other dealings in this Software without prior written authorization |
|
28 # of the copyright holder. |
|
29 # |
|
30 |
|
31 4010755: SEGV in XFindContext if XInitThreads has been enabled |
|
32 |
|
33 XFindContext in Xlib was calling _XLockMutex with an uninitialized |
|
34 mutex lock structure. The new version of XInitThreads activates the |
|
35 locking functions at any time, even after displays have been created. |
|
36 |
|
37 In this new case, the context structure was created prior to |
|
38 XInitThreads being invoked. As a result, the display contained an |
|
39 opaque pointer to this context structure, which still contained an |
|
40 uninitialized lock structure. |
|
41 |
|
42 The solution was to explicitly set the lock structure pointer to NULL |
|
43 (as a flag) when creating the context, then check for NULL before |
|
44 locking. If NULL is found and threads are now enabled, then the |
|
45 structure gets reinitialized to the correct mutex lock structure |
|
46 before the lock call. |
|
47 |
|
48 Another area besides the functions in Context.c are the functions in |
|
49 Xrm.c. A similar fix was added to them as well. |
|
50 |
|
51 |
|
52 diff -urp -x '*~' -x '*.orig' src/Context.c src/Context.c |
|
53 --- src/Context.c 2007-05-16 08:34:44.000000000 -0700 |
|
54 +++ src/Context.c 2008-02-12 21:00:44.588363000 -0800 |
|
55 @@ -192,6 +192,7 @@ int XSaveContext( |
|
56 return XCNOMEM; |
|
57 } |
|
58 db->numentries = 0; |
|
59 + db->linfo.lock = (xmutex_t) NULL; |
|
60 _XCreateMutex(&db->linfo); |
|
61 #ifdef MOTIFBC |
|
62 if (!display) *pdb = db; else |
|
63 @@ -203,6 +204,8 @@ int XSaveContext( |
|
64 UnlockDisplay(display); |
|
65 } |
|
66 } |
|
67 + if (!db->linfo.lock) |
|
68 + _XCreateMutex(&db->linfo); |
|
69 _XLockMutex(&db->linfo); |
|
70 head = &Hash(db, rid, context); |
|
71 _XUnlockMutex(&db->linfo); |
|
72 @@ -254,6 +257,8 @@ int XFindContext(display, rid, context, |
|
73 } |
|
74 if (!db) |
|
75 return XCNOENT; |
|
76 + if (!db->linfo.lock) |
|
77 + _XCreateMutex(&db->linfo); |
|
78 _XLockMutex(&db->linfo); |
|
79 for (entry = Hash(db, rid, context); entry; entry = entry->next) |
|
80 { |
|
81 @@ -292,6 +297,8 @@ int XDeleteContext(display, rid, context |
|
82 } |
|
83 if (!db) |
|
84 return XCNOENT; |
|
85 + if (!db->linfo.lock) |
|
86 + _XCreateMutex(&db->linfo); |
|
87 _XLockMutex(&db->linfo); |
|
88 for (prev = &Hash(db, rid, context); |
|
89 (entry = *prev); |
|
90 diff -urp -x '*~' -x '*.orig' src/Xrm.c src/Xrm.c |
|
91 --- src/Xrm.c 2007-05-16 08:34:44.000000000 -0700 |
|
92 +++ src/Xrm.c 2008-02-12 21:00:44.594920000 -0800 |
|
93 @@ -500,6 +500,7 @@ static XrmDatabase NewDatabase(void) |
|
94 |
|
95 db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec)); |
|
96 if (db) { |
|
97 + db->linfo.lock = (xmutex_t) NULL; |
|
98 _XCreateMutex(&db->linfo); |
|
99 db->table = (NTable)NULL; |
|
100 db->mbstate = (XPointer)NULL; |
|
101 @@ -775,7 +776,11 @@ void XrmCombineDatabase( |
|
102 if (!*into) { |
|
103 *into = from; |
|
104 } else if (from) { |
|
105 + if (!(&from->linfo.lock)) |
|
106 + _XCreateMutex(&from->linfo); |
|
107 _XLockMutex(&from->linfo); |
|
108 + if (!(&(*into)->linfo.lock)) |
|
109 + _XCreateMutex(&(*into)->linfo); |
|
110 _XLockMutex(&(*into)->linfo); |
|
111 if ((ftable = from->table)) { |
|
112 prev = &(*into)->table; |
|
113 @@ -1022,6 +1027,8 @@ void XrmQPutResource( |
|
114 XrmValuePtr value) |
|
115 { |
|
116 if (!*pdb) *pdb = NewDatabase(); |
|
117 + if (!(*pdb)->linfo.lock) |
|
118 + _XCreateMutex(&(*pdb)->linfo); |
|
119 _XLockMutex(&(*pdb)->linfo); |
|
120 PutEntry(*pdb, bindings, quarks, type, value); |
|
121 _XUnlockMutex(&(*pdb)->linfo); |
|
122 @@ -1038,6 +1045,8 @@ XrmPutResource( |
|
123 XrmQuark quarks[MAXDBDEPTH+1]; |
|
124 |
|
125 if (!*pdb) *pdb = NewDatabase(); |
|
126 + if (!(*pdb)->linfo.lock) |
|
127 + _XCreateMutex(&(*pdb)->linfo); |
|
128 _XLockMutex(&(*pdb)->linfo); |
|
129 XrmStringToBindingQuarkList(specifier, bindings, quarks); |
|
130 PutEntry(*pdb, bindings, quarks, XrmStringToQuark(type), value); |
|
131 @@ -1056,6 +1065,8 @@ XrmQPutStringResource( |
|
132 if (!*pdb) *pdb = NewDatabase(); |
|
133 value.addr = (XPointer) str; |
|
134 value.size = strlen(str)+1; |
|
135 + if (!(*pdb)->linfo.lock) |
|
136 + _XCreateMutex(&(*pdb)->linfo); |
|
137 _XLockMutex(&(*pdb)->linfo); |
|
138 PutEntry(*pdb, bindings, quarks, XrmQString, &value); |
|
139 _XUnlockMutex(&(*pdb)->linfo); |
|
140 @@ -1538,6 +1549,8 @@ XrmPutStringResource( |
|
141 XrmStringToBindingQuarkList(specifier, bindings, quarks); |
|
142 value.addr = (XPointer) str; |
|
143 value.size = strlen(str)+1; |
|
144 + if (!(*pdb)->linfo.lock) |
|
145 + _XCreateMutex(&(*pdb)->linfo); |
|
146 _XLockMutex(&(*pdb)->linfo); |
|
147 PutEntry(*pdb, bindings, quarks, XrmQString, &value); |
|
148 _XUnlockMutex(&(*pdb)->linfo); |
|
149 @@ -1550,6 +1563,8 @@ XrmPutLineResource( |
|
150 _Xconst char*line) |
|
151 { |
|
152 if (!*pdb) *pdb = NewDatabase(); |
|
153 + if (!(*pdb)->linfo.lock) |
|
154 + _XCreateMutex(&(*pdb)->linfo); |
|
155 _XLockMutex(&(*pdb)->linfo); |
|
156 GetDatabase(*pdb, line, (char *)NULL, False); |
|
157 _XUnlockMutex(&(*pdb)->linfo); |
|
158 @@ -1562,6 +1577,8 @@ XrmGetStringDatabase( |
|
159 XrmDatabase db; |
|
160 |
|
161 db = NewDatabase(); |
|
162 + if (!db->linfo.lock) |
|
163 + _XCreateMutex(&db->linfo); |
|
164 _XLockMutex(&db->linfo); |
|
165 GetDatabase(db, data, (char *)NULL, True); |
|
166 _XUnlockMutex(&db->linfo); |
|
167 @@ -1670,6 +1687,8 @@ XrmGetFileDatabase( |
|
168 return (XrmDatabase)NULL; |
|
169 |
|
170 db = NewDatabase(); |
|
171 + if (!db->linfo.lock) |
|
172 + _XCreateMutex(&db->linfo); |
|
173 _XLockMutex(&db->linfo); |
|
174 GetDatabase(db, str, filename, True); |
|
175 _XUnlockMutex(&db->linfo); |
|
176 @@ -1694,6 +1713,8 @@ XrmCombineFileDatabase( |
|
177 *target = db = NewDatabase(); |
|
178 } else |
|
179 db = NewDatabase(); |
|
180 + if (!db->linfo.lock) |
|
181 + _XCreateMutex(&db->linfo); |
|
182 _XLockMutex(&db->linfo); |
|
183 GetDatabase(db, str, filename, True); |
|
184 _XUnlockMutex(&db->linfo); |
|
185 @@ -1966,6 +1987,8 @@ Bool XrmEnumerateDatabase( |
|
186 |
|
187 if (!db) |
|
188 return False; |
|
189 + if (!db->linfo.lock) |
|
190 + _XCreateMutex(&db->linfo); |
|
191 _XLockMutex(&db->linfo); |
|
192 eclosure.db = db; |
|
193 eclosure.proc = proc; |
|
194 @@ -2262,6 +2285,8 @@ Bool XrmQGetSearchList( |
|
195 closure.idx = -1; |
|
196 closure.limit = listLength - 2; |
|
197 if (db) { |
|
198 + if (!db->linfo.lock) |
|
199 + _XCreateMutex(&db->linfo); |
|
200 _XLockMutex(&db->linfo); |
|
201 table = db->table; |
|
202 if (*names) { |
|
203 @@ -2540,6 +2565,8 @@ Bool XrmQGetResource( |
|
204 VClosureRec closure; |
|
205 |
|
206 if (db && *names) { |
|
207 + if (!db->linfo.lock) |
|
208 + _XCreateMutex(&db->linfo); |
|
209 _XLockMutex(&db->linfo); |
|
210 closure.type = pType; |
|
211 closure.value = pValue; |
|
212 @@ -2636,6 +2663,8 @@ XrmLocaleOfDatabase( |
|
213 XrmDatabase db) |
|
214 { |
|
215 const char* retval; |
|
216 + if (!db->linfo.lock) |
|
217 + _XCreateMutex(&db->linfo); |
|
218 _XLockMutex(&db->linfo); |
|
219 retval = (*db->methods->lcname)(db->mbstate); |
|
220 _XUnlockMutex(&db->linfo); |
|
221 @@ -2648,6 +2677,8 @@ void XrmDestroyDatabase( |
|
222 register NTable table, next; |
|
223 |
|
224 if (db) { |
|
225 + if (!db->linfo.lock) |
|
226 + _XCreateMutex(&db->linfo); |
|
227 _XLockMutex(&db->linfo); |
|
228 for (next = db->table; (table = next); ) { |
|
229 next = table->next; |