Print this page
11972 resync smatch
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_locking.c
+++ new/usr/src/tools/smatch/src/check_locking.c
1 1 /*
2 2 * Copyright (C) 2009 Dan Carpenter.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 /*
19 19 * This test checks that locks are held the same across all returns.
20 20 *
21 21 * Of course, some functions are designed to only hold the locks on success.
22 22 * Oh well... We can rewrite it later if we want.
23 23 *
24 24 * The list of wine locking functions came from an earlier script written
25 25 * by Michael Stefaniuc.
26 26 *
27 27 */
28 28
29 29 #include "parse.h"
30 30 #include "smatch.h"
31 31 #include "smatch_extra.h"
32 32 #include "smatch_slist.h"
33 33
34 34 static int my_id;
35 35
36 36 static int func_has_transition;
37 37
38 38 STATE(locked);
39 39 STATE(start_state);
40 40 STATE(unlocked);
41 41 STATE(impossible);
42 42
43 43 enum action {
44 44 LOCK,
45 45 UNLOCK,
46 46 };
47 47
48 48 enum return_type {
49 49 ret_any,
50 50 ret_non_zero,
51 51 ret_zero,
52 52 ret_one,
53 53 ret_negative,
54 54 ret_positive,
55 55 };
56 56
57 57 #define RETURN_VAL -1
58 58 #define NO_ARG -2
59 59
60 60 struct lock_info {
61 61 const char *function;
62 62 enum action action;
63 63 const char *name;
64 64 int arg;
65 65 enum return_type return_type;
66 66 };
67 67
68 68 static struct lock_info wine_lock_table[] = {
69 69 {"create_window_handle", LOCK, "create_window_handle", RETURN_VAL, ret_non_zero},
70 70 {"WIN_GetPtr", LOCK, "create_window_handle", RETURN_VAL, ret_non_zero},
71 71 {"WIN_ReleasePtr", UNLOCK, "create_window_handle", 0, ret_any},
72 72 {"EnterCriticalSection", LOCK, "CriticalSection", 0, ret_any},
73 73 {"LeaveCriticalSection", UNLOCK, "CriticalSection", 0, ret_any},
74 74 {"RtlEnterCriticalSection", LOCK, "RtlCriticalSection", 0, ret_any},
75 75 {"RtlLeaveCriticalSection", UNLOCK, "RtlCriticalSection", 0, ret_any},
76 76 {"GDI_GetObjPtr", LOCK, "GDI_Get", 0, ret_non_zero},
77 77 {"GDI_ReleaseObj", UNLOCK, "GDI_Get", 0, ret_any},
78 78 {"LdrLockLoaderLock", LOCK, "LdrLockLoaderLock", 2, ret_any},
79 79 {"LdrUnlockLoaderLock", UNLOCK, "LdrLockLoaderLock", 1, ret_any},
80 80 {"_lock", LOCK, "_lock", 0, ret_any},
81 81 {"_unlock", UNLOCK, "_lock", 0, ret_any},
82 82 {"msiobj_lock", LOCK, "msiobj_lock", 0, ret_any},
83 83 {"msiobj_unlock", UNLOCK, "msiobj_lock", 0, ret_any},
84 84 {"RtlAcquirePebLock", LOCK, "PebLock", NO_ARG, ret_any},
85 85 {"RtlReleasePebLock", UNLOCK, "PebLock", NO_ARG, ret_any},
86 86 {"server_enter_uninterrupted_section", LOCK, "server_uninterrupted_section", 0, ret_any},
87 87 {"server_leave_uninterrupted_section", UNLOCK, "server_uninterrupted_section", 0, ret_any},
88 88 {"RtlLockHeap", LOCK, "RtlLockHeap", 0, ret_any},
89 89 {"RtlUnlockHeap", UNLOCK, "RtlLockHeap", 0, ret_any},
90 90 {"_EnterSysLevel", LOCK, "SysLevel", 0, ret_any},
91 91 {"_LeaveSysLevel", UNLOCK, "SysLevel", 0, ret_any},
92 92 {"USER_Lock", LOCK, "USER_Lock", NO_ARG, ret_any},
93 93 {"USER_Unlock", UNLOCK, "USER_Lock", NO_ARG, ret_any},
94 94 {"wine_tsx11_lock", LOCK, "wine_tsx11_lock", NO_ARG, ret_any},
95 95 {"wine_tsx11_unlock", UNLOCK, "wine_tsx11_lock", NO_ARG, ret_any},
96 96 {"wine_tsx11_lock_ptr", LOCK, "wine_tsx11_lock_ptr", NO_ARG, ret_any},
97 97 {"wine_tsx11_unlock_ptr", UNLOCK, "wine_tsx11_lock_ptr", NO_ARG, ret_any},
98 98 {"wined3d_mutex_lock", LOCK, "wined3d_mutex_lock", NO_ARG, ret_any},
99 99 {"wined3d_mutex_unlock", UNLOCK, "wined3d_mutex_lock", NO_ARG, ret_any},
100 100 {"X11DRV_DIB_Lock", LOCK, "X11DRV_DIB_Lock", 0, ret_any},
101 101 {"X11DRV_DIB_Unlock", UNLOCK, "X11DRV_DIB_Lock", 0, ret_any},
102 102 };
103 103
104 104 static struct lock_info kernel_lock_table[] = {
105 105 {"lock_kernel", LOCK, "BKL", NO_ARG, ret_any},
106 106 {"unlock_kernel", UNLOCK, "BKL", NO_ARG, ret_any},
107 107
108 108 {"spin_lock", LOCK, "spin_lock", 0, ret_any},
109 109 {"spin_unlock", UNLOCK, "spin_lock", 0, ret_any},
110 110 {"spin_lock_nested", LOCK, "spin_lock", 0, ret_any},
111 111 {"_spin_lock", LOCK, "spin_lock", 0, ret_any},
112 112 {"_spin_unlock", UNLOCK, "spin_lock", 0, ret_any},
113 113 {"_spin_lock_nested", LOCK, "spin_lock", 0, ret_any},
114 114 {"__spin_lock", LOCK, "spin_lock", 0, ret_any},
115 115 {"__spin_unlock", UNLOCK, "spin_lock", 0, ret_any},
116 116 {"__spin_lock_nested", LOCK, "spin_lock", 0, ret_any},
117 117 {"raw_spin_lock", LOCK, "spin_lock", 0, ret_any},
118 118 {"raw_spin_unlock", UNLOCK, "spin_lock", 0, ret_any},
119 119 {"_raw_spin_lock", LOCK, "spin_lock", 0, ret_any},
120 120 {"_raw_spin_lock_nested", LOCK, "spin_lock", 0, ret_any},
121 121 {"_raw_spin_unlock", UNLOCK, "spin_lock", 0, ret_any},
122 122 {"__raw_spin_lock", LOCK, "spin_lock", 0, ret_any},
123 123 {"__raw_spin_unlock", UNLOCK, "spin_lock", 0, ret_any},
124 124
125 125 {"spin_lock_irq", LOCK, "spin_lock", 0, ret_any},
126 126 {"spin_unlock_irq", UNLOCK, "spin_lock", 0, ret_any},
127 127 {"_spin_lock_irq", LOCK, "spin_lock", 0, ret_any},
128 128 {"_spin_unlock_irq", UNLOCK, "spin_lock", 0, ret_any},
129 129 {"__spin_lock_irq", LOCK, "spin_lock", 0, ret_any},
130 130 {"__spin_unlock_irq", UNLOCK, "spin_lock", 0, ret_any},
131 131 {"_raw_spin_lock_irq", LOCK, "spin_lock", 0, ret_any},
132 132 {"_raw_spin_unlock_irq", UNLOCK, "spin_lock", 0, ret_any},
133 133 {"__raw_spin_unlock_irq", UNLOCK, "spin_lock", 0, ret_any},
134 134 {"spin_lock_irqsave", LOCK, "spin_lock", 0, ret_any},
135 135 {"spin_unlock_irqrestore", UNLOCK, "spin_lock", 0, ret_any},
136 136 {"_spin_lock_irqsave", LOCK, "spin_lock", 0, ret_any},
137 137 {"_spin_unlock_irqrestore", UNLOCK, "spin_lock", 0, ret_any},
138 138 {"__spin_lock_irqsave", LOCK, "spin_lock", 0, ret_any},
139 139 {"__spin_unlock_irqrestore", UNLOCK, "spin_lock", 0, ret_any},
140 140 {"_raw_spin_lock_irqsave", LOCK, "spin_lock", 0, ret_any},
141 141 {"_raw_spin_unlock_irqrestore", UNLOCK, "spin_lock", 0, ret_any},
142 142 {"__raw_spin_lock_irqsave", LOCK, "spin_lock", 0, ret_any},
143 143 {"__raw_spin_unlock_irqrestore", UNLOCK, "spin_lock", 0, ret_any},
144 144 {"spin_lock_irqsave_nested", LOCK, "spin_lock", 0, ret_any},
145 145 {"_spin_lock_irqsave_nested", LOCK, "spin_lock", 0, ret_any},
146 146 {"__spin_lock_irqsave_nested", LOCK, "spin_lock", 0, ret_any},
147 147 {"_raw_spin_lock_irqsave_nested", LOCK, "spin_lock", 0, ret_any},
148 148 {"spin_lock_bh", LOCK, "spin_lock", 0, ret_any},
149 149 {"spin_unlock_bh", UNLOCK, "spin_lock", 0, ret_any},
150 150 {"_spin_lock_bh", LOCK, "spin_lock", 0, ret_any},
151 151 {"_spin_unlock_bh", UNLOCK, "spin_lock", 0, ret_any},
152 152 {"__spin_lock_bh", LOCK, "spin_lock", 0, ret_any},
153 153 {"__spin_unlock_bh", UNLOCK, "spin_lock", 0, ret_any},
154 154
155 155 {"spin_trylock", LOCK, "spin_lock", 0, ret_one},
156 156 {"_spin_trylock", LOCK, "spin_lock", 0, ret_one},
157 157 {"__spin_trylock", LOCK, "spin_lock", 0, ret_one},
158 158 {"raw_spin_trylock", LOCK, "spin_lock", 0, ret_one},
159 159 {"_raw_spin_trylock", LOCK, "spin_lock", 0, ret_one},
160 160 {"spin_trylock_irq", LOCK, "spin_lock", 0, ret_one},
161 161 {"spin_trylock_irqsave", LOCK, "spin_lock", 0, ret_one},
162 162 {"spin_trylock_bh", LOCK, "spin_lock", 0, ret_one},
163 163 {"_spin_trylock_bh", LOCK, "spin_lock", 0, ret_one},
164 164 {"__spin_trylock_bh", LOCK, "spin_lock", 0, ret_one},
165 165 {"__raw_spin_trylock", LOCK, "spin_lock", 0, ret_one},
166 166 {"_atomic_dec_and_lock", LOCK, "spin_lock", 1, ret_one},
167 167
168 168 {"read_lock", LOCK, "read_lock", 0, ret_any},
169 169 {"read_unlock", UNLOCK, "read_lock", 0, ret_any},
170 170 {"_read_lock", LOCK, "read_lock", 0, ret_any},
171 171 {"_read_unlock", UNLOCK, "read_lock", 0, ret_any},
172 172 {"__read_lock", LOCK, "read_lock", 0, ret_any},
173 173 {"__read_unlock", UNLOCK, "read_lock", 0, ret_any},
174 174 {"_raw_read_lock", LOCK, "read_lock", 0, ret_any},
175 175 {"_raw_read_unlock", UNLOCK, "read_lock", 0, ret_any},
176 176 {"__raw_read_lock", LOCK, "read_lock", 0, ret_any},
177 177 {"__raw_read_unlock", UNLOCK, "read_lock", 0, ret_any},
178 178 {"read_lock_irq", LOCK, "read_lock", 0, ret_any},
179 179 {"read_unlock_irq" , UNLOCK, "read_lock", 0, ret_any},
180 180 {"_read_lock_irq", LOCK, "read_lock", 0, ret_any},
181 181 {"_read_unlock_irq", UNLOCK, "read_lock", 0, ret_any},
182 182 {"__read_lock_irq", LOCK, "read_lock", 0, ret_any},
183 183 {"__read_unlock_irq", UNLOCK, "read_lock", 0, ret_any},
184 184 {"read_lock_irqsave", LOCK, "read_lock", 0, ret_any},
185 185 {"read_unlock_irqrestore", UNLOCK, "read_lock", 0, ret_any},
186 186 {"_read_lock_irqsave", LOCK, "read_lock", 0, ret_any},
187 187 {"_read_unlock_irqrestore", UNLOCK, "read_lock", 0, ret_any},
188 188 {"__read_lock_irqsave", LOCK, "read_lock", 0, ret_any},
189 189 {"__read_unlock_irqrestore", UNLOCK, "read_lock", 0, ret_any},
190 190 {"read_lock_bh", LOCK, "read_lock", 0, ret_any},
191 191 {"read_unlock_bh", UNLOCK, "read_lock", 0, ret_any},
192 192 {"_read_lock_bh", LOCK, "read_lock", 0, ret_any},
193 193 {"_read_unlock_bh", UNLOCK, "read_lock", 0, ret_any},
194 194 {"__read_lock_bh", LOCK, "read_lock", 0, ret_any},
195 195 {"__read_unlock_bh", UNLOCK, "read_lock", 0, ret_any},
196 196 {"_raw_read_lock_bh", LOCK, "read_lock", 0, ret_any},
197 197 {"_raw_read_unlock_bh", UNLOCK, "read_lock", 0, ret_any},
198 198 {"__raw_read_lock_bh", LOCK, "read_lock", 0, ret_any},
199 199 {"__raw_read_unlock_bh", UNLOCK, "read_lock", 0, ret_any},
200 200
201 201 {"generic__raw_read_trylock", LOCK, "read_lock", 0, ret_one},
202 202 {"read_trylock", LOCK, "read_lock", 0, ret_one},
203 203 {"_read_trylock", LOCK, "read_lock", 0, ret_one},
204 204 {"raw_read_trylock", LOCK, "read_lock", 0, ret_one},
205 205 {"_raw_read_trylock", LOCK, "read_lock", 0, ret_one},
206 206 {"__raw_read_trylock", LOCK, "read_lock", 0, ret_one},
207 207 {"__read_trylock", LOCK, "read_lock", 0, ret_one},
208 208
209 209 {"write_lock", LOCK, "write_lock", 0, ret_any},
210 210 {"write_unlock", UNLOCK, "write_lock", 0, ret_any},
211 211 {"_write_lock", LOCK, "write_lock", 0, ret_any},
212 212 {"_write_unlock", UNLOCK, "write_lock", 0, ret_any},
213 213 {"__write_lock", LOCK, "write_lock", 0, ret_any},
214 214 {"__write_unlock", UNLOCK, "write_lock", 0, ret_any},
215 215 {"write_lock_irq", LOCK, "write_lock", 0, ret_any},
216 216 {"write_unlock_irq", UNLOCK, "write_lock", 0, ret_any},
217 217 {"_write_lock_irq", LOCK, "write_lock", 0, ret_any},
218 218 {"_write_unlock_irq", UNLOCK, "write_lock", 0, ret_any},
219 219 {"__write_lock_irq", LOCK, "write_lock", 0, ret_any},
220 220 {"__write_unlock_irq", UNLOCK, "write_lock", 0, ret_any},
221 221 {"write_lock_irqsave", LOCK, "write_lock", 0, ret_any},
222 222 {"write_unlock_irqrestore", UNLOCK, "write_lock", 0, ret_any},
223 223 {"_write_lock_irqsave", LOCK, "write_lock", 0, ret_any},
224 224 {"_write_unlock_irqrestore", UNLOCK, "write_lock", 0, ret_any},
225 225 {"__write_lock_irqsave", LOCK, "write_lock", 0, ret_any},
226 226 {"__write_unlock_irqrestore", UNLOCK, "write_lock", 0, ret_any},
227 227 {"write_lock_bh", LOCK, "write_lock", 0, ret_any},
228 228 {"write_unlock_bh", UNLOCK, "write_lock", 0, ret_any},
229 229 {"_write_lock_bh", LOCK, "write_lock", 0, ret_any},
230 230 {"_write_unlock_bh", UNLOCK, "write_lock", 0, ret_any},
231 231 {"__write_lock_bh", LOCK, "write_lock", 0, ret_any},
232 232 {"__write_unlock_bh", UNLOCK, "write_lock", 0, ret_any},
233 233 {"_raw_write_lock", LOCK, "write_lock", 0, ret_any},
234 234 {"__raw_write_lock", LOCK, "write_lock", 0, ret_any},
235 235 {"_raw_write_unlock", UNLOCK, "write_lock", 0, ret_any},
236 236 {"__raw_write_unlock", UNLOCK, "write_lock", 0, ret_any},
237 237
238 238 {"write_trylock", LOCK, "write_lock", 0, ret_one},
239 239 {"_write_trylock", LOCK, "write_lock", 0, ret_one},
240 240 {"raw_write_trylock", LOCK, "write_lock", 0, ret_one},
241 241 {"_raw_write_trylock", LOCK, "write_lock", 0, ret_one},
242 242 {"__write_trylock", LOCK, "write_lock", 0, ret_one},
243 243 {"__raw_write_trylock", LOCK, "write_lock", 0, ret_one},
244 244
245 245 {"down", LOCK, "sem", 0, ret_any},
246 246 {"up", UNLOCK, "sem", 0, ret_any},
247 247 {"down_trylock", LOCK, "sem", 0, ret_zero},
248 248 {"down_timeout", LOCK, "sem", 0, ret_zero},
249 249 {"down_interruptible", LOCK, "sem", 0, ret_zero},
250 250
251 251
252 252 {"down_write", LOCK, "rw_sem", 0, ret_any},
253 253 {"downgrade_write", UNLOCK, "rw_sem", 0, ret_any},
254 254 {"downgrade_write", LOCK, "read_sem", 0, ret_any},
255 255 {"up_write", UNLOCK, "rw_sem", 0, ret_any},
256 256 {"down_write_trylock", LOCK, "rw_sem", 0, ret_one},
257 257 {"down_write_killable", LOCK, "rw_sem", 0, ret_zero},
258 258 {"down_read", LOCK, "read_sem", 0, ret_any},
259 259 {"down_read_trylock", LOCK, "read_sem", 0, ret_one},
260 260 {"down_read_killable", LOCK, "read_sem", 0, ret_zero},
261 261 {"up_read", UNLOCK, "read_sem", 0, ret_any},
262 262
263 263 {"mutex_lock", LOCK, "mutex", 0, ret_any},
264 264 {"mutex_lock_io", LOCK, "mutex", 0, ret_any},
265 265 {"mutex_unlock", UNLOCK, "mutex", 0, ret_any},
266 266 {"mutex_lock_nested", LOCK, "mutex", 0, ret_any},
267 267 {"mutex_lock_io_nested", LOCK, "mutex", 0, ret_any},
268 268
269 269 {"mutex_lock_interruptible", LOCK, "mutex", 0, ret_zero},
270 270 {"mutex_lock_interruptible_nested", LOCK, "mutex", 0, ret_zero},
271 271 {"mutex_lock_killable", LOCK, "mutex", 0, ret_zero},
272 272 {"mutex_lock_killable_nested", LOCK, "mutex", 0, ret_zero},
273 273
274 274 {"mutex_trylock", LOCK, "mutex", 0, ret_one},
275 275
276 276 {"raw_local_irq_disable", LOCK, "irq", NO_ARG, ret_any},
277 277 {"raw_local_irq_enable", UNLOCK, "irq", NO_ARG, ret_any},
278 278 {"spin_lock_irq", LOCK, "irq", NO_ARG, ret_any},
279 279 {"spin_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
280 280 {"_spin_lock_irq", LOCK, "irq", NO_ARG, ret_any},
281 281 {"_spin_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
282 282 {"__spin_lock_irq", LOCK, "irq", NO_ARG, ret_any},
283 283 {"__spin_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
284 284 {"_raw_spin_lock_irq", LOCK, "irq", NO_ARG, ret_any},
285 285 {"_raw_spin_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
286 286 {"__raw_spin_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
287 287 {"spin_trylock_irq", LOCK, "irq", NO_ARG, ret_one},
288 288 {"read_lock_irq", LOCK, "irq", NO_ARG, ret_any},
289 289 {"read_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
290 290 {"_read_lock_irq", LOCK, "irq", NO_ARG, ret_any},
291 291 {"_read_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
292 292 {"__read_lock_irq", LOCK, "irq", NO_ARG, ret_any},
293 293 {"__read_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
294 294 {"write_lock_irq", LOCK, "irq", NO_ARG, ret_any},
295 295 {"write_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
296 296 {"_write_lock_irq", LOCK, "irq", NO_ARG, ret_any},
297 297 {"_write_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
298 298 {"__write_lock_irq", LOCK, "irq", NO_ARG, ret_any},
299 299 {"__write_unlock_irq", UNLOCK, "irq", NO_ARG, ret_any},
300 300
301 301 {"arch_local_irq_save", LOCK, "irqsave", RETURN_VAL, ret_any},
302 302 {"arch_local_irq_restore", UNLOCK, "irqsave", 0, ret_any},
303 303 {"__raw_local_irq_save", LOCK, "irqsave", RETURN_VAL, ret_any},
304 304 {"raw_local_irq_restore", UNLOCK, "irqsave", 0, ret_any},
305 305 {"spin_lock_irqsave_nested", LOCK, "irqsave", RETURN_VAL, ret_any},
306 306 {"spin_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
307 307 {"spin_lock_irqsave", LOCK, "irqsave", 1, ret_any},
308 308 {"spin_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
309 309 {"_spin_lock_irqsave_nested", LOCK, "irqsave", RETURN_VAL, ret_any},
310 310 {"_spin_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
311 311 {"_spin_lock_irqsave", LOCK, "irqsave", 1, ret_any},
312 312 {"_spin_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
313 313 {"__spin_lock_irqsave_nested", LOCK, "irqsave", 1, ret_any},
314 314 {"__spin_lock_irqsave", LOCK, "irqsave", 1, ret_any},
315 315 {"__spin_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
316 316 {"_raw_spin_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
317 317 {"_raw_spin_lock_irqsave", LOCK, "irqsave", 1, ret_any},
318 318 {"_raw_spin_unlock_irqrestore",UNLOCK, "irqsave", 1, ret_any},
319 319 {"__raw_spin_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
320 320 {"__raw_spin_unlock_irqrestore",UNLOCK, "irqsave", 1, ret_any},
321 321 {"_raw_spin_lock_irqsave_nested", LOCK, "irqsave", RETURN_VAL, ret_any},
322 322 {"spin_trylock_irqsave", LOCK, "irqsave", 1, ret_one},
323 323 {"read_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
324 324 {"read_lock_irqsave", LOCK, "irqsave", 1, ret_any},
325 325 {"read_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
326 326 {"_read_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
327 327 {"_read_lock_irqsave", LOCK, "irqsave", 1, ret_any},
328 328 {"_read_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
329 329 {"__read_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
330 330 {"__read_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
331 331 {"write_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
332 332 {"write_lock_irqsave", LOCK, "irqsave", 1, ret_any},
333 333 {"write_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
334 334 {"_write_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
335 335 {"_write_lock_irqsave", LOCK, "irqsave", 1, ret_any},
336 336 {"_write_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
337 337 {"__write_lock_irqsave", LOCK, "irqsave", RETURN_VAL, ret_any},
338 338 {"__write_unlock_irqrestore", UNLOCK, "irqsave", 1, ret_any},
339 339
340 340 {"local_bh_disable", LOCK, "bottom_half", NO_ARG, ret_any},
341 341 {"_local_bh_disable", LOCK, "bottom_half", NO_ARG, ret_any},
342 342 {"__local_bh_disable", LOCK, "bottom_half", NO_ARG, ret_any},
343 343 {"local_bh_enable", UNLOCK, "bottom_half", NO_ARG, ret_any},
344 344 {"_local_bh_enable", UNLOCK, "bottom_half", NO_ARG, ret_any},
345 345 {"__local_bh_enable", UNLOCK, "bottom_half", NO_ARG, ret_any},
346 346 {"spin_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
347 347 {"spin_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
348 348 {"_spin_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
349 349 {"_spin_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
350 350 {"__spin_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
351 351 {"__spin_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
352 352 {"read_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
353 353 {"read_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
354 354 {"_read_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
355 355 {"_read_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
356 356 {"__read_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
357 357 {"__read_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
358 358 {"_raw_read_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
359 359 {"_raw_read_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
360 360 {"write_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
361 361 {"write_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
362 362 {"_write_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
363 363 {"_write_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
364 364 {"__write_lock_bh", LOCK, "bottom_half", NO_ARG, ret_any},
365 365 {"__write_unlock_bh", UNLOCK, "bottom_half", NO_ARG, ret_any},
366 366 {"spin_trylock_bh", LOCK, "bottom_half", NO_ARG, ret_one},
367 367 {"_spin_trylock_bh", LOCK, "bottom_half", NO_ARG, ret_one},
368 368 {"__spin_trylock_bh", LOCK, "bottom_half", NO_ARG, ret_one},
369 369
370 370 {"ffs_mutex_lock", LOCK, "mutex", 0, ret_zero},
371 371 };
372 372
373 373 static struct lock_info *lock_table;
374 374
375 375 static struct tracker_list *starts_locked;
376 376 static struct tracker_list *starts_unlocked;
377 377
378 378 struct locks_on_return {
379 379 int line;
380 380 struct tracker_list *locked;
381 381 struct tracker_list *unlocked;
382 382 struct tracker_list *impossible;
383 383 struct range_list *return_values;
384 384 };
385 385 DECLARE_PTR_LIST(return_list, struct locks_on_return);
386 386 static struct return_list *all_returns;
387 387
388 388 static char *make_full_name(const char *lock, const char *var)
389 389 {
390 390 static char tmp_buf[512];
391 391
392 392 snprintf(tmp_buf, sizeof(tmp_buf), "%s:%s", lock, var);
393 393 remove_parens(tmp_buf);
394 394 return alloc_string(tmp_buf);
395 395 }
396 396
397 397 static struct expression *remove_spinlock_check(struct expression *expr)
398 398 {
399 399 if (expr->type != EXPR_CALL)
400 400 return expr;
401 401 if (expr->fn->type != EXPR_SYMBOL)
402 402 return expr;
403 403 if (strcmp(expr->fn->symbol_name->name, "spinlock_check"))
404 404 return expr;
405 405 expr = get_argument_from_call_expr(expr->args, 0);
406 406 return expr;
407 407 }
408 408
409 409 static char *get_full_name(struct expression *expr, int index)
410 410 {
411 411 struct expression *arg;
412 412 char *name = NULL;
413 413 char *full_name = NULL;
414 414 struct lock_info *lock = &lock_table[index];
415 415
416 416 if (lock->arg == RETURN_VAL) {
417 417 name = expr_to_var(expr->left);
418 418 full_name = make_full_name(lock->name, name);
419 419 } else if (lock->arg == NO_ARG) {
420 420 full_name = make_full_name(lock->name, "");
421 421 } else {
422 422 arg = get_argument_from_call_expr(expr->args, lock->arg);
423 423 if (!arg)
424 424 goto free;
425 425 arg = remove_spinlock_check(arg);
426 426 name = expr_to_str(arg);
427 427 if (!name)
428 428 goto free;
429 429 full_name = make_full_name(lock->name, name);
430 430 }
431 431 free:
432 432 free_string(name);
433 433 return full_name;
434 434 }
435 435
436 436 static struct smatch_state *get_start_state(struct sm_state *sm)
437 437 {
438 438 int is_locked = 0;
439 439 int is_unlocked = 0;
440 440
441 441 if (in_tracker_list(starts_locked, my_id, sm->name, sm->sym))
442 442 is_locked = 1;
443 443 if (in_tracker_list(starts_unlocked, my_id, sm->name, sm->sym))
444 444 is_unlocked = 1;
445 445 if (is_locked && is_unlocked)
446 446 return &undefined;
447 447 if (is_locked)
448 448 return &locked;
↓ open down ↓ |
448 lines elided |
↑ open up ↑ |
449 449 if (is_unlocked)
450 450 return &unlocked;
451 451 return &undefined;
452 452 }
453 453
454 454 static struct smatch_state *unmatched_state(struct sm_state *sm)
455 455 {
456 456 return &start_state;
457 457 }
458 458
459 -static void pre_merge_hook(struct sm_state *sm)
459 +static void pre_merge_hook(struct sm_state *cur, struct sm_state *other)
460 460 {
461 461 if (is_impossible_path())
462 - set_state(my_id, sm->name, sm->sym, &impossible);
462 + set_state(my_id, cur->name, cur->sym, &impossible);
463 463 }
464 464
465 465 static bool nestable(const char *name)
466 466 {
467 467 if (strstr(name, "read_sem:"))
468 468 return true;
469 469 if (strcmp(name, "bottom_half:") == 0)
470 470 return true;
471 471 return false;
472 472 }
473 473
474 474 static void do_lock(const char *name)
475 475 {
476 476 struct sm_state *sm;
477 477
478 478 if (__inline_fn)
479 479 return;
480 480
481 481 sm = get_sm_state(my_id, name, NULL);
482 482 if (!sm)
483 483 add_tracker(&starts_unlocked, my_id, name, NULL);
484 484 if (sm && slist_has_state(sm->possible, &locked) && !nestable(name))
485 485 sm_error("double lock '%s'", name);
486 486 if (sm)
487 487 func_has_transition = TRUE;
488 488 set_state(my_id, name, NULL, &locked);
489 489 }
490 490
491 491 static void do_lock_failed(const char *name)
492 492 {
493 493 struct sm_state *sm;
494 494
495 495 if (__inline_fn)
496 496 return;
497 497
498 498 sm = get_sm_state(my_id, name, NULL);
499 499 if (!sm)
500 500 add_tracker(&starts_unlocked, my_id, name, NULL);
501 501 set_state(my_id, name, NULL, &unlocked);
502 502 }
503 503
504 504 static void do_unlock(const char *name)
505 505 {
506 506 struct sm_state *sm;
507 507
508 508 if (__inline_fn)
509 509 return;
510 510 if (__path_is_null())
511 511 return;
512 512 sm = get_sm_state(my_id, name, NULL);
513 513 if (!sm)
514 514 add_tracker(&starts_locked, my_id, name, NULL);
515 515 if (sm && slist_has_state(sm->possible, &unlocked) &&
516 516 strcmp(name, "bottom_half:") != 0)
517 517 sm_error("double unlock '%s'", name);
518 518 if (sm)
519 519 func_has_transition = TRUE;
520 520 set_state(my_id, name, NULL, &unlocked);
521 521 }
522 522
523 523 static void match_lock_held(const char *fn, struct expression *call_expr,
524 524 struct expression *assign_expr, void *_index)
525 525 {
526 526 int index = PTR_INT(_index);
527 527 char *lock_name;
528 528 struct lock_info *lock = &lock_table[index];
529 529
530 530 if (lock->arg == NO_ARG) {
531 531 lock_name = get_full_name(NULL, index);
532 532 } else if (lock->arg == RETURN_VAL) {
533 533 if (!assign_expr)
534 534 return;
535 535 lock_name = get_full_name(assign_expr, index);
536 536 } else {
537 537 lock_name = get_full_name(call_expr, index);
538 538 }
539 539 if (!lock_name)
540 540 return;
541 541 do_lock(lock_name);
542 542 free_string(lock_name);
543 543 }
544 544
545 545 static void match_lock_failed(const char *fn, struct expression *call_expr,
546 546 struct expression *assign_expr, void *_index)
547 547 {
548 548 int index = PTR_INT(_index);
549 549 char *lock_name;
550 550 struct lock_info *lock = &lock_table[index];
551 551
552 552 if (lock->arg == NO_ARG) {
553 553 lock_name = get_full_name(NULL, index);
554 554 } else if (lock->arg == RETURN_VAL) {
555 555 if (!assign_expr)
556 556 return;
557 557 lock_name = get_full_name(assign_expr, index);
558 558 } else {
559 559 lock_name = get_full_name(call_expr, index);
560 560 }
561 561 if (!lock_name)
562 562 return;
563 563 do_lock_failed(lock_name);
564 564 free_string(lock_name);
565 565 }
566 566
567 567 static void match_returns_locked(const char *fn, struct expression *expr,
568 568 void *_index)
569 569 {
570 570 char *full_name = NULL;
571 571 int index = PTR_INT(_index);
572 572 struct lock_info *lock = &lock_table[index];
573 573
574 574 if (lock->arg != RETURN_VAL)
575 575 return;
576 576 full_name = get_full_name(expr, index);
577 577 do_lock(full_name);
578 578 }
579 579
580 580 static void match_lock_unlock(const char *fn, struct expression *expr, void *_index)
581 581 {
582 582 char *full_name = NULL;
583 583 int index = PTR_INT(_index);
584 584 struct lock_info *lock = &lock_table[index];
585 585
586 586 if (__inline_fn)
587 587 return;
588 588
589 589 full_name = get_full_name(expr, index);
590 590 if (!full_name)
591 591 return;
592 592 if (lock->action == LOCK)
593 593 do_lock(full_name);
594 594 else
595 595 do_unlock(full_name);
596 596 free_string(full_name);
597 597 }
598 598
599 599 static struct locks_on_return *alloc_return(struct expression *expr)
600 600 {
601 601 struct locks_on_return *ret;
602 602
603 603 ret = malloc(sizeof(*ret));
604 604 if (!get_implied_rl(expr, &ret->return_values))
605 605 ret->return_values = NULL;
606 606 ret->line = get_lineno();
607 607 ret->locked = NULL;
608 608 ret->unlocked = NULL;
609 609 ret->impossible = NULL;
610 610 return ret;
611 611 }
612 612
613 613 static int check_possible(struct sm_state *sm)
614 614 {
615 615 struct sm_state *tmp;
616 616 int islocked = 0;
617 617 int isunlocked = 0;
618 618 int undef = 0;
619 619
620 620 if (!option_spammy)
621 621 return 0;
622 622
623 623 FOR_EACH_PTR(sm->possible, tmp) {
624 624 if (tmp->state == &locked)
625 625 islocked = 1;
626 626 if (tmp->state == &unlocked)
627 627 isunlocked = 1;
628 628 if (tmp->state == &start_state) {
629 629 struct smatch_state *s;
630 630
631 631 s = get_start_state(tmp);
632 632 if (s == &locked)
633 633 islocked = 1;
634 634 else if (s == &unlocked)
635 635 isunlocked = 1;
636 636 else
637 637 undef = 1;
638 638 }
639 639 if (tmp->state == &undefined)
640 640 undef = 1; // i don't think this is possible any more.
641 641 } END_FOR_EACH_PTR(tmp);
642 642 if ((islocked && isunlocked) || undef) {
643 643 sm_warning("'%s' is sometimes locked here and sometimes unlocked.", sm->name);
644 644 return 1;
645 645 }
646 646 return 0;
647 647 }
648 648
649 649 static struct position warned_pos;
650 650
651 651 static void match_return(int return_id, char *return_ranges, struct expression *expr)
652 652 {
653 653 struct locks_on_return *ret;
654 654 struct stree *stree;
655 655 struct sm_state *tmp;
656 656
657 657 if (!final_pass)
658 658 return;
659 659 if (__inline_fn)
660 660 return;
661 661
662 662 if (expr && cmp_pos(expr->pos, warned_pos) == 0)
663 663 return;
664 664
665 665 ret = alloc_return(expr);
666 666
667 667 stree = __get_cur_stree();
668 668 FOR_EACH_MY_SM(my_id, stree, tmp) {
669 669 if (tmp->state == &locked) {
670 670 add_tracker(&ret->locked, tmp->owner, tmp->name,
671 671 tmp->sym);
672 672 } else if (tmp->state == &unlocked) {
673 673 add_tracker(&ret->unlocked, tmp->owner, tmp->name,
674 674 tmp->sym);
675 675 } else if (tmp->state == &start_state) {
676 676 struct smatch_state *s;
677 677
678 678 s = get_start_state(tmp);
679 679 if (s == &locked)
680 680 add_tracker(&ret->locked, tmp->owner, tmp->name,
681 681 tmp->sym);
682 682 if (s == &unlocked)
683 683 add_tracker(&ret->unlocked, tmp->owner,tmp->name,
684 684 tmp->sym);
685 685 } else if (tmp->state == &impossible) {
686 686 add_tracker(&ret->impossible, tmp->owner, tmp->name,
687 687 tmp->sym);
688 688 } else {
689 689 if (check_possible(tmp)) {
690 690 if (expr)
691 691 warned_pos = expr->pos;
692 692 }
693 693 }
694 694 } END_FOR_EACH_SM(tmp);
695 695 add_ptr_list(&all_returns, ret);
696 696 }
697 697
698 698 static void add_line(struct range_list **rl, int line)
699 699 {
700 700 sval_t sval = sval_type_val(&int_ctype, line);
701 701
702 702 add_range(rl, sval, sval);
703 703 }
704 704
705 705 static int line_printed(struct range_list *rl, int line)
706 706 {
707 707 sval_t sval = sval_type_val(&int_ctype, line);
708 708
709 709 return rl_has_sval(rl, sval);
710 710 }
711 711
712 712 static void print_inconsistent_returns(struct tracker *lock,
713 713 struct smatch_state *start)
714 714 {
715 715 struct locks_on_return *tmp;
716 716 struct range_list *printed = NULL;
717 717 int i;
718 718
719 719 sm_warning("inconsistent returns '%s'.", lock->name);
720 720 sm_printf(" Locked on: ");
721 721
722 722 i = 0;
723 723 FOR_EACH_PTR(all_returns, tmp) {
724 724 if (line_printed(printed, tmp->line))
725 725 continue;
726 726 if (in_tracker_list(tmp->unlocked, lock->owner, lock->name, lock->sym))
727 727 continue;
728 728 if (in_tracker_list(tmp->locked, lock->owner, lock->name, lock->sym)) {
729 729 if (i++)
730 730 sm_printf(" ");
731 731 sm_printf("line %d\n", tmp->line);
732 732 add_line(&printed, tmp->line);
733 733 continue;
734 734 }
735 735 if (start == &locked) {
736 736 if (i++)
737 737 sm_printf(" ");
738 738 sm_printf("line %d\n", tmp->line);
739 739 add_line(&printed, tmp->line);
740 740 }
741 741 } END_FOR_EACH_PTR(tmp);
742 742
743 743 sm_printf(" Unlocked on: ");
744 744 printed = NULL;
745 745 i = 0;
746 746 FOR_EACH_PTR(all_returns, tmp) {
747 747 if (line_printed(printed, tmp->line))
748 748 continue;
749 749 if (in_tracker_list(tmp->unlocked, lock->owner, lock->name, lock->sym)) {
750 750 if (i++)
751 751 sm_printf(" ");
752 752 sm_printf("line %d\n", tmp->line);
753 753 add_line(&printed, tmp->line);
754 754 continue;
755 755 }
756 756 if (in_tracker_list(tmp->locked, lock->owner, lock->name, lock->sym))
757 757 continue;
758 758 if (start == &unlocked) {
759 759 if (i++)
760 760 sm_printf(" ");
761 761 sm_printf("line %d\n", tmp->line);
762 762 add_line(&printed, tmp->line);
763 763 }
764 764 } END_FOR_EACH_PTR(tmp);
765 765 }
766 766
767 767 static int matches_return_type(struct range_list *rl, enum return_type type)
768 768 {
769 769 sval_t zero_sval = ll_to_sval(0);
770 770 sval_t one_sval = ll_to_sval(1);
771 771
772 772 /* All these double negatives are super ugly! */
773 773
774 774 switch (type) {
775 775 case ret_zero:
776 776 return !possibly_true_rl(rl, SPECIAL_NOTEQUAL, alloc_rl(zero_sval, zero_sval));
777 777 case ret_one:
778 778 return !possibly_true_rl(rl, SPECIAL_NOTEQUAL, alloc_rl(one_sval, one_sval));
779 779 case ret_non_zero:
780 780 return !possibly_true_rl(rl, SPECIAL_EQUAL, alloc_rl(zero_sval, zero_sval));
781 781 case ret_negative:
782 782 return !possibly_true_rl(rl, SPECIAL_GTE, alloc_rl(zero_sval, zero_sval));
783 783 case ret_positive:
784 784 return !possibly_true_rl(rl, '<', alloc_rl(zero_sval, zero_sval));
785 785 case ret_any:
786 786 default:
787 787 return 1;
788 788 }
789 789 }
790 790
791 791 static int match_held(struct tracker *lock, struct locks_on_return *this_return, struct smatch_state *start)
792 792 {
793 793 if (in_tracker_list(this_return->impossible, lock->owner, lock->name, lock->sym))
794 794 return 0;
795 795 if (in_tracker_list(this_return->unlocked, lock->owner, lock->name, lock->sym))
796 796 return 0;
797 797 if (in_tracker_list(this_return->locked, lock->owner, lock->name, lock->sym))
798 798 return 1;
799 799 if (start == &unlocked)
800 800 return 0;
801 801 return 1;
802 802 }
803 803
804 804 static int match_released(struct tracker *lock, struct locks_on_return *this_return, struct smatch_state *start)
805 805 {
806 806 if (in_tracker_list(this_return->impossible, lock->owner, lock->name, lock->sym))
807 807 return 0;
808 808 if (in_tracker_list(this_return->unlocked, lock->owner, lock->name, lock->sym))
809 809 return 1;
810 810 if (in_tracker_list(this_return->locked, lock->owner, lock->name, lock->sym))
811 811 return 0;
812 812 if (start == &unlocked)
813 813 return 1;
814 814 return 0;
815 815 }
816 816
817 817 static int held_on_return(struct tracker *lock, struct smatch_state *start, enum return_type type)
818 818 {
819 819 struct locks_on_return *tmp;
820 820
821 821 FOR_EACH_PTR(all_returns, tmp) {
822 822 if (!matches_return_type(tmp->return_values, type))
823 823 continue;
824 824 if (match_held(lock, tmp, start))
825 825 return 1;
826 826 } END_FOR_EACH_PTR(tmp);
827 827 return 0;
828 828 }
829 829
830 830 static int released_on_return(struct tracker *lock, struct smatch_state *start, enum return_type type)
831 831 {
832 832 struct locks_on_return *tmp;
833 833
834 834 FOR_EACH_PTR(all_returns, tmp) {
835 835 if (!matches_return_type(tmp->return_values, type))
836 836 continue;
837 837 if (match_released(lock, tmp, start))
838 838 return 1;
839 839 } END_FOR_EACH_PTR(tmp);
840 840 return 0;
841 841 }
842 842
843 843 static void check_returns_consistently(struct tracker *lock,
844 844 struct smatch_state *start)
845 845 {
846 846 struct symbol *type;
847 847
848 848 if (!held_on_return(lock, start, ret_any) ||
849 849 !released_on_return(lock, start, ret_any))
850 850 return;
851 851
852 852 if (held_on_return(lock, start, ret_zero) &&
853 853 !held_on_return(lock, start, ret_non_zero))
854 854 return;
855 855
856 856 if (held_on_return(lock, start, ret_positive) &&
857 857 !held_on_return(lock, start, ret_zero))
858 858 return;
859 859
860 860 if (held_on_return(lock, start, ret_positive) &&
861 861 !held_on_return(lock, start, ret_negative))
862 862 return;
863 863
864 864 type = cur_func_return_type();
865 865 if (type && type->type == SYM_PTR) {
866 866 if (held_on_return(lock, start, ret_non_zero) &&
867 867 !held_on_return(lock, start, ret_zero))
868 868 return;
869 869 }
870 870
871 871 print_inconsistent_returns(lock, start);
872 872 }
873 873
874 874 static void check_consistency(struct symbol *sym)
875 875 {
876 876 struct tracker *tmp;
877 877
878 878 FOR_EACH_PTR(starts_locked, tmp) {
879 879 if (in_tracker_list(starts_unlocked, tmp->owner, tmp->name,
880 880 tmp->sym))
881 881 sm_error("locking inconsistency. We assume "
882 882 "'%s' is both locked and unlocked at the "
883 883 "start.",
884 884 tmp->name);
885 885 } END_FOR_EACH_PTR(tmp);
886 886
887 887 FOR_EACH_PTR(starts_locked, tmp) {
888 888 check_returns_consistently(tmp, &locked);
889 889 } END_FOR_EACH_PTR(tmp);
890 890
891 891 FOR_EACH_PTR(starts_unlocked, tmp) {
892 892 check_returns_consistently(tmp, &unlocked);
893 893 } END_FOR_EACH_PTR(tmp);
894 894 }
895 895
896 896 static void clear_lists(void)
897 897 {
898 898 struct locks_on_return *tmp;
899 899
900 900 func_has_transition = FALSE;
901 901
902 902 free_trackers_and_list(&starts_locked);
903 903 free_trackers_and_list(&starts_unlocked);
904 904
905 905 FOR_EACH_PTR(all_returns, tmp) {
906 906 free_trackers_and_list(&tmp->locked);
907 907 free_trackers_and_list(&tmp->unlocked);
908 908 free(tmp);
909 909 } END_FOR_EACH_PTR(tmp);
910 910 __free_ptr_list((struct ptr_list **)&all_returns);
911 911 }
912 912
913 913 static void match_func_end(struct symbol *sym)
914 914 {
915 915 if (__inline_fn)
916 916 return;
917 917
918 918 if (func_has_transition)
919 919 check_consistency(sym);
920 920 }
921 921
922 922 static void match_after_func(struct symbol *sym)
923 923 {
924 924 if (__inline_fn)
925 925 return;
926 926 clear_lists();
927 927 }
928 928
929 929 static void register_lock(int index)
930 930 {
931 931 struct lock_info *lock = &lock_table[index];
932 932 void *idx = INT_PTR(index);
933 933
934 934 if (lock->return_type == ret_non_zero) {
935 935 return_implies_state(lock->function, 1, INT_MAX, &match_lock_held, idx);
936 936 return_implies_state(lock->function, 0, 0, &match_lock_failed, idx);
937 937 } else if (lock->return_type == ret_any && lock->arg == RETURN_VAL) {
938 938 add_function_assign_hook(lock->function, &match_returns_locked, idx);
939 939 } else if (lock->return_type == ret_any) {
940 940 add_function_hook(lock->function, &match_lock_unlock, idx);
941 941 } else if (lock->return_type == ret_zero) {
942 942 return_implies_state(lock->function, 0, 0, &match_lock_held, idx);
943 943 return_implies_state(lock->function, -4095, -1, &match_lock_failed, idx);
944 944 } else if (lock->return_type == ret_one) {
945 945 return_implies_state(lock->function, 1, 1, &match_lock_held, idx);
946 946 return_implies_state(lock->function, 0, 0, &match_lock_failed, idx);
947 947 }
948 948 }
949 949
950 950 static void load_table(struct lock_info *_lock_table, int size)
951 951 {
952 952 int i;
953 953
954 954 lock_table = _lock_table;
955 955
956 956 for (i = 0; i < size; i++) {
957 957 if (lock_table[i].action == LOCK)
958 958 register_lock(i);
959 959 else
960 960 add_function_hook(lock_table[i].function, &match_lock_unlock, INT_PTR(i));
961 961 }
962 962 }
963 963
964 964 /* print_held_locks() is used in check_call_tree.c */
965 965 void print_held_locks(void)
966 966 {
967 967 struct stree *stree;
968 968 struct sm_state *sm;
969 969 int i = 0;
970 970
971 971 stree = __get_cur_stree();
972 972 FOR_EACH_MY_SM(my_id, stree, sm) {
973 973 if (sm->state != &locked)
974 974 continue;
975 975 if (i++)
976 976 sm_printf(" ");
977 977 sm_printf("'%s'", sm->name);
978 978 } END_FOR_EACH_SM(sm);
979 979 }
980 980
981 981 void check_locking(int id)
982 982 {
983 983 my_id = id;
984 984
985 985 if (option_project == PROJ_WINE)
986 986 load_table(wine_lock_table, ARRAY_SIZE(wine_lock_table));
987 987 else if (option_project == PROJ_KERNEL)
988 988 load_table(kernel_lock_table, ARRAY_SIZE(kernel_lock_table));
989 989 else
990 990 return;
991 991
992 992 add_unmatched_state_hook(my_id, &unmatched_state);
993 993 add_pre_merge_hook(my_id, &pre_merge_hook);
994 994 add_split_return_callback(match_return);
995 995 add_hook(&match_func_end, END_FUNC_HOOK);
996 996 add_hook(&match_after_func, AFTER_FUNC_HOOK);
997 997
998 998 }
↓ open down ↓ |
526 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX