Print this page
new smatch
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch.h
+++ new/usr/src/tools/smatch/src/smatch.h
1 1 /*
2 2 * Copyright (C) 2006 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 * Copyright 2019 Joyent, Inc.
18 18 */
19 19
20 20 #ifndef SMATCH_H_
21 21 # define SMATCH_H_
22 22
23 23 #include <stdio.h>
24 24 #include <string.h>
25 25 #include <limits.h>
26 26 #include <sys/time.h>
27 27 #include <sqlite3.h>
28 28 #include "lib.h"
29 29 #include "allocate.h"
30 30 #include "scope.h"
31 31 #include "parse.h"
32 32 #include "expression.h"
33 33 #include "avl.h"
34 34
35 35 typedef struct {
36 36 struct symbol *type;
37 37 union {
38 38 long long value;
39 39 unsigned long long uvalue;
40 40 };
41 41 } sval_t;
42 42
43 43 typedef long long mtag_t;
44 44
45 45 struct smatch_state {
46 46 const char *name;
47 47 void *data;
48 48 };
49 49 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
50 50 extern struct smatch_state undefined;
51 51 extern struct smatch_state ghost;
52 52 extern struct smatch_state merged;
53 53 extern struct smatch_state true_state;
54 54 extern struct smatch_state false_state;
55 55 DECLARE_ALLOCATOR(smatch_state);
56 56
57 57 static inline void *INT_PTR(int i)
58 58 {
59 59 return (void *)(long)i;
60 60 }
61 61
62 62 static inline int PTR_INT(void *p)
63 63 {
64 64 return (int)(long)p;
65 65 }
66 66
67 67 struct tracker {
68 68 char *name;
69 69 struct symbol *sym;
70 70 unsigned short owner;
71 71 };
72 72 DECLARE_ALLOCATOR(tracker);
73 73 DECLARE_PTR_LIST(tracker_list, struct tracker);
74 74 DECLARE_PTR_LIST(stree_stack, struct stree);
75 75
76 76 /* The first 3 struct members must match struct tracker */
77 77 struct sm_state {
78 78 const char *name;
79 79 struct symbol *sym;
80 80 unsigned short owner;
81 81 unsigned short merged:1;
82 82 unsigned int line;
83 83 struct smatch_state *state;
84 84 struct stree *pool;
85 85 struct sm_state *left;
86 86 struct sm_state *right;
87 87 struct state_list *possible;
88 88 };
89 89
90 90 struct var_sym {
91 91 char *var;
92 92 struct symbol *sym;
93 93 };
94 94 DECLARE_ALLOCATOR(var_sym);
95 95 DECLARE_PTR_LIST(var_sym_list, struct var_sym);
96 96
97 97 struct constraint {
98 98 int op;
99 99 int id;
↓ open down ↓ |
99 lines elided |
↑ open up ↑ |
100 100 };
101 101 DECLARE_PTR_LIST(constraint_list, struct constraint);
102 102
103 103 struct bit_info {
104 104 unsigned long long set;
105 105 unsigned long long possible;
106 106 };
107 107
108 108 enum hook_type {
109 109 EXPR_HOOK,
110 + EXPR_HOOK_AFTER,
110 111 STMT_HOOK,
111 112 STMT_HOOK_AFTER,
112 113 SYM_HOOK,
113 114 STRING_HOOK,
114 115 DECLARATION_HOOK,
115 116 ASSIGNMENT_HOOK,
116 117 ASSIGNMENT_HOOK_AFTER,
117 118 RAW_ASSIGNMENT_HOOK,
118 119 GLOBAL_ASSIGNMENT_HOOK,
119 120 LOGIC_HOOK,
120 121 CONDITION_HOOK,
121 122 PRELOOP_HOOK,
122 123 SELECT_HOOK,
123 124 WHOLE_CONDITION_HOOK,
124 125 FUNCTION_CALL_HOOK_BEFORE,
125 126 FUNCTION_CALL_HOOK,
126 127 CALL_HOOK_AFTER_INLINE,
127 128 FUNCTION_CALL_HOOK_AFTER_DB,
128 129 CALL_ASSIGNMENT_HOOK,
129 130 MACRO_ASSIGNMENT_HOOK,
130 131 BINOP_HOOK,
131 132 OP_HOOK,
132 133 DEREF_HOOK,
133 134 CASE_HOOK,
134 135 ASM_HOOK,
135 136 CAST_HOOK,
136 137 SIZEOF_HOOK,
137 138 BASE_HOOK,
138 139 FUNC_DEF_HOOK,
139 140 AFTER_DEF_HOOK,
140 141 END_FUNC_HOOK,
141 142 AFTER_FUNC_HOOK,
142 143 RETURN_HOOK,
143 144 INLINE_FN_START,
144 145 INLINE_FN_END,
145 146 END_FILE_HOOK,
146 147 NUM_HOOKS,
147 148 };
148 149
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
149 150 #define TRUE 1
150 151 #define FALSE 0
151 152
152 153 struct range_list;
153 154
154 155 void add_hook(void *func, enum hook_type type);
155 156 typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2);
156 157 typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state);
157 158 void add_merge_hook(int client_id, merge_func_t *func);
158 159 void add_unmatched_state_hook(int client_id, unmatched_func_t *func);
159 -void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *sm));
160 +void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *cur, struct sm_state *other));
160 161 typedef void (scope_hook)(void *data);
161 162 void add_scope_hook(scope_hook *hook, void *data);
162 163 typedef void (func_hook)(const char *fn, struct expression *expr, void *data);
163 164 typedef void (implication_hook)(const char *fn, struct expression *call_expr,
164 165 struct expression *assign_expr, void *data);
165 166 typedef void (return_implies_hook)(struct expression *call_expr,
166 167 int param, char *key, char *value);
167 168 typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl);
168 169 void add_function_hook(const char *look_for, func_hook *call_back, void *data);
169 170
170 171 void add_function_assign_hook(const char *look_for, func_hook *call_back,
171 172 void *info);
172 173 void add_implied_return_hook(const char *look_for,
173 174 implied_return_hook *call_back,
174 175 void *info);
175 176 void add_macro_assign_hook(const char *look_for, func_hook *call_back,
176 177 void *info);
177 178 void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
178 179 void *info);
179 180 void return_implies_state(const char *look_for, long long start, long long end,
180 181 implication_hook *call_back, void *info);
181 182 void return_implies_state_sval(const char *look_for, sval_t start, sval_t end,
182 183 implication_hook *call_back, void *info);
183 184 void select_return_states_hook(int type, return_implies_hook *callback);
184 185 void select_return_states_before(void (*fn)(void));
185 186 void select_return_states_after(void (*fn)(void));
186 187 int get_implied_return(struct expression *expr, struct range_list **rl);
187 188 void allocate_hook_memory(void);
188 189
189 190 struct modification_data {
190 191 struct smatch_state *prev;
191 192 struct expression *cur;
192 193 };
193 194
194 195 typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr);
195 196 void add_modification_hook(int owner, modification_hook *call_back);
196 197 void add_modification_hook_late(int owner, modification_hook *call_back);
197 198 struct smatch_state *get_modification_state(struct expression *expr);
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
198 199
199 200 int outside_of_function(void);
200 201 const char *get_filename(void);
201 202 const char *get_base_file(void);
202 203 char *get_function(void);
203 204 int get_lineno(void);
204 205 extern int final_pass;
205 206 extern struct symbol *cur_func_sym;
206 207 extern int option_debug;
207 208 extern int local_debug;
209 +bool debug_implied(void);
208 210 extern int option_info;
209 211 extern int option_spammy;
210 212 extern int option_timeout;
211 213 extern char *trace_variable;
212 214 extern struct stree *global_states;
213 215 int is_skipped_function(void);
214 216 int is_silenced_function(void);
215 217 extern bool implications_off;
216 218
217 219 /* smatch_impossible.c */
218 220 int is_impossible_path(void);
219 221 void set_path_impossible(void);
220 222
221 223 extern FILE *sm_outfd;
222 224 extern FILE *sql_outfd;
223 225 extern FILE *caller_info_fd;
224 226 extern int sm_nr_checks;
225 227 extern int sm_nr_errors;
226 228 extern const char *progname;
227 229
228 230 /*
229 231 * How to use these routines:
230 232 *
231 233 * sm_fatal(): an internal error of some kind that should immediately exit
232 234 * sm_ierror(): an internal error
233 235 * sm_perror(): an internal error from parsing input source
234 236 * sm_error(): an error from input source
235 237 * sm_warning(): a warning from input source
236 238 * sm_info(): info message (from option_info)
237 239 * sm_debug(): debug message
238 240 * sm_msg(): other message (please avoid using this)
239 241 */
240 242
241 243 #define sm_printf(msg...) do { if (final_pass || option_debug || local_debug) fprintf(sm_outfd, msg); } while (0)
242 244
243 245 static inline void sm_prefix(void)
244 246 {
245 247 sm_printf("%s: %s:%d %s() ", progname, get_filename(), get_lineno(), get_function());
246 248 }
247 249
248 250 static inline void print_implied_debug_msg();
249 251
250 252 extern bool __silence_warnings_for_stmt;
251 253
252 254 #define sm_print_msg(type, msg...) \
253 255 do { \
254 256 print_implied_debug_msg(); \
255 257 if (!final_pass && !option_debug && !local_debug) \
256 258 break; \
257 259 if (__silence_warnings_for_stmt && !option_debug && !local_debug) \
258 260 break; \
259 261 if (!option_info && is_silenced_function()) \
260 262 break; \
261 263 sm_prefix(); \
262 264 if (type == 1) { \
263 265 sm_printf("warn: "); \
264 266 sm_nr_checks++; \
265 267 } else if (type == 2) { \
266 268 sm_printf("error: "); \
267 269 sm_nr_checks++; \
268 270 } else if (type == 3) { \
269 271 sm_printf("parse error: "); \
270 272 sm_nr_errors++; \
271 273 } \
272 274 sm_printf(msg); \
273 275 sm_printf("\n"); \
274 276 } while (0)
275 277
276 278 #define sm_msg(msg...) do { sm_print_msg(0, msg); } while (0)
277 279
278 280 #define local_debug(msg...) \
279 281 do { \
280 282 if (local_debug) \
281 283 sm_msg(msg); \
282 284 } while (0)
283 285
284 286 extern char *implied_debug_msg;
285 287 static inline void print_implied_debug_msg(void)
286 288 {
287 289 static struct symbol *last_printed = NULL;
288 290
289 291 if (!implied_debug_msg)
290 292 return;
291 293 if (last_printed == cur_func_sym)
292 294 return;
293 295 last_printed = cur_func_sym;
294 296 sm_msg("%s", implied_debug_msg);
295 297 }
296 298
297 299 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
298 300
299 301 #define sm_info(msg...) do { \
300 302 if (option_debug || (option_info && final_pass)) { \
301 303 sm_prefix(); \
302 304 sm_printf("info: "); \
303 305 sm_printf(msg); \
304 306 sm_printf("\n"); \
305 307 } \
306 308 } while(0)
307 309
308 310 #define sm_warning(msg...) do { sm_print_msg(1, msg); } while (0)
309 311 #define sm_error(msg...) do { sm_print_msg(2, msg); } while (0)
310 312 #define sm_perror(msg...) do { sm_print_msg(3, msg); } while (0)
311 313
312 314 static inline void sm_fatal(const char *fmt, ...)
313 315 {
314 316 va_list args;
315 317
316 318 va_start(args, fmt);
317 319 vfprintf(sm_outfd, fmt, args);
318 320 va_end(args);
319 321
320 322 fprintf(sm_outfd, "\n");
321 323
322 324 exit(1);
323 325 }
324 326
325 327 static inline void sm_ierror(const char *fmt, ...)
326 328 {
327 329 va_list args;
328 330
329 331 sm_nr_errors++;
330 332
331 333 fprintf(sm_outfd, "internal error: ");
332 334
333 335 va_start(args, fmt);
334 336 vfprintf(sm_outfd, fmt, args);
335 337 va_end(args);
336 338
337 339 fprintf(sm_outfd, "\n");
338 340 }
339 341 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
340 342
341 343 struct smatch_state *__get_state(int owner, const char *name, struct symbol *sym);
342 344 struct smatch_state *get_state(int owner, const char *name, struct symbol *sym);
343 345 struct smatch_state *get_state_expr(int owner, struct expression *expr);
344 346 struct state_list *get_possible_states(int owner, const char *name,
345 347 struct symbol *sym);
346 348 struct state_list *get_possible_states_expr(int owner, struct expression *expr);
347 349 struct sm_state *set_state(int owner, const char *name, struct symbol *sym,
348 350 struct smatch_state *state);
349 351 struct sm_state *set_state_expr(int owner, struct expression *expr,
350 352 struct smatch_state *state);
351 353 void delete_state(int owner, const char *name, struct symbol *sym);
352 354 void delete_state_expr(int owner, struct expression *expr);
353 355 void __delete_all_states_sym(struct symbol *sym);
354 356 void set_true_false_states(int owner, const char *name, struct symbol *sym,
355 357 struct smatch_state *true_state,
356 358 struct smatch_state *false_state);
357 359 void set_true_false_states_expr(int owner, struct expression *expr,
358 360 struct smatch_state *true_state,
359 361 struct smatch_state *false_state);
↓ open down ↓ |
142 lines elided |
↑ open up ↑ |
360 362
361 363 struct stree *get_all_states_from_stree(int owner, struct stree *source);
362 364 struct stree *get_all_states_stree(int id);
363 365 struct stree *__get_cur_stree(void);
364 366 int is_reachable(void);
365 367 void add_get_state_hook(void (*fn)(int owner, const char *name, struct symbol *sym));
366 368
367 369 /* smatch_helper.c */
368 370 DECLARE_PTR_LIST(int_stack, int);
369 371 char *alloc_string(const char *str);
372 +char *alloc_string_newline(const char *str);
370 373 void free_string(char *str);
371 374 void append(char *dest, const char *data, int buff_len);
372 375 void remove_parens(char *str);
373 376 struct smatch_state *alloc_state_num(int num);
374 377 struct smatch_state *alloc_state_str(const char *name);
375 378 struct smatch_state *merge_str_state(struct smatch_state *s1, struct smatch_state *s2);
376 379 struct smatch_state *alloc_state_expr(struct expression *expr);
377 380 struct expression *get_argument_from_call_expr(struct expression_list *args,
378 381 int num);
379 382
380 383 char *expr_to_var(struct expression *expr);
381 384 struct symbol *expr_to_sym(struct expression *expr);
382 385 char *expr_to_str(struct expression *expr);
383 386 char *expr_to_str_sym(struct expression *expr,
384 387 struct symbol **sym_ptr);
385 388 char *expr_to_var_sym(struct expression *expr,
386 389 struct symbol **sym_ptr);
387 390 char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym);
388 391 char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl);
389 392 int get_complication_score(struct expression *expr);
390 393
391 394 int sym_name_is(const char *name, struct expression *expr);
392 395 int get_const_value(struct expression *expr, sval_t *sval);
393 396 int get_value(struct expression *expr, sval_t *val);
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
394 397 int get_implied_value(struct expression *expr, sval_t *val);
395 398 int get_implied_min(struct expression *expr, sval_t *sval);
396 399 int get_implied_max(struct expression *expr, sval_t *val);
397 400 int get_hard_max(struct expression *expr, sval_t *sval);
398 401 int get_fuzzy_min(struct expression *expr, sval_t *min);
399 402 int get_fuzzy_max(struct expression *expr, sval_t *max);
400 403 int get_absolute_min(struct expression *expr, sval_t *sval);
401 404 int get_absolute_max(struct expression *expr, sval_t *sval);
402 405 int parse_call_math(struct expression *expr, char *math, sval_t *val);
403 406 int parse_call_math_rl(struct expression *call, const char *math, struct range_list **rl);
407 +const char *get_allocation_math(struct expression *expr);
404 408 char *get_value_in_terms_of_parameter_math(struct expression *expr);
405 409 char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
406 -int is_zero(struct expression *expr);
410 +int expr_is_zero(struct expression *expr);
407 411 int known_condition_true(struct expression *expr);
408 412 int known_condition_false(struct expression *expr);
409 413 int implied_condition_true(struct expression *expr);
410 414 int implied_condition_false(struct expression *expr);
411 415 int can_integer_overflow(struct symbol *type, struct expression *expr);
412 416 void clear_math_cache(void);
417 +void set_fast_math_only(void);
418 +void clear_fast_math_only(void);
413 419
414 420 int is_array(struct expression *expr);
415 421 struct expression *get_array_base(struct expression *expr);
416 422 struct expression *get_array_offset(struct expression *expr);
417 423 const char *show_state(struct smatch_state *state);
418 424 struct statement *get_expression_statement(struct expression *expr);
419 425 struct expression *strip_parens(struct expression *expr);
420 426 struct expression *strip_expr(struct expression *expr);
421 427 struct expression *strip_expr_set_parent(struct expression *expr);
422 428 void scoped_state(int my_id, const char *name, struct symbol *sym);
423 429 int is_error_return(struct expression *expr);
424 -int getting_address(void);
430 +int getting_address(struct expression *expr);
425 431 int get_struct_and_member(struct expression *expr, const char **type, const char **member);
426 432 char *get_member_name(struct expression *expr);
427 433 char *get_fnptr_name(struct expression *expr);
428 434 int cmp_pos(struct position pos1, struct position pos2);
429 435 int positions_eq(struct position pos1, struct position pos2);
430 436 struct statement *get_current_statement(void);
431 437 struct statement *get_prev_statement(void);
432 438 struct expression *get_last_expr_from_expression_stmt(struct expression *expr);
433 439 int get_param_num_from_sym(struct symbol *sym);
434 440 int get_param_num(struct expression *expr);
435 441 int ms_since(struct timeval *start);
436 442 int parent_is_gone_var_sym(const char *name, struct symbol *sym);
437 443 int parent_is_gone(struct expression *expr);
438 444 int invert_op(int op);
439 445 int op_remove_assign(int op);
440 446 int expr_equiv(struct expression *one, struct expression *two);
441 447 void push_int(struct int_stack **stack, int num);
442 448 int pop_int(struct int_stack **stack);
443 449
444 450 /* smatch_type.c */
445 451 struct symbol *get_real_base_type(struct symbol *sym);
446 452 int type_bytes(struct symbol *type);
447 453 int array_bytes(struct symbol *type);
448 454 struct symbol *get_pointer_type(struct expression *expr);
449 455 struct symbol *get_type(struct expression *expr);
450 456 struct symbol *get_final_type(struct expression *expr);
451 457 struct symbol *get_promoted_type(struct symbol *left, struct symbol *right);
452 458 int type_signed(struct symbol *base_type);
453 459 int expr_unsigned(struct expression *expr);
454 460 int expr_signed(struct expression *expr);
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
455 461 int returns_unsigned(struct symbol *base_type);
456 462 int is_pointer(struct expression *expr);
457 463 int returns_pointer(struct symbol *base_type);
458 464 sval_t sval_type_max(struct symbol *base_type);
459 465 sval_t sval_type_min(struct symbol *base_type);
460 466 int nr_bits(struct expression *expr);
461 467 int is_void_pointer(struct expression *expr);
462 468 int is_char_pointer(struct expression *expr);
463 469 int is_string(struct expression *expr);
464 470 int is_static(struct expression *expr);
465 -int is_local_variable(struct expression *expr);
471 +bool is_local_variable(struct expression *expr);
466 472 int types_equiv(struct symbol *one, struct symbol *two);
467 473 int fn_static(void);
468 474 const char *global_static();
469 475 struct symbol *cur_func_return_type(void);
470 476 struct symbol *get_arg_type(struct expression *fn, int arg);
471 477 struct symbol *get_member_type_from_key(struct expression *expr, const char *key);
472 478 struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key);
473 479 int is_struct(struct expression *expr);
474 480 char *type_to_str(struct symbol *type);
475 481
476 482 /* smatch_ignore.c */
477 483 void add_ignore(int owner, const char *name, struct symbol *sym);
478 484 int is_ignored(int owner, const char *name, struct symbol *sym);
479 485 void add_ignore_expr(int owner, struct expression *expr);
480 486 int is_ignored_expr(int owner, struct expression *expr);
481 487
482 488 /* smatch_var_sym */
483 489 struct var_sym *alloc_var_sym(const char *var, struct symbol *sym);
484 490 struct var_sym_list *expr_to_vsl(struct expression *expr);
485 491 void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
486 492 void add_var_sym_expr(struct var_sym_list **list, struct expression *expr);
487 493 void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
488 494 int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym);
489 495 struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl);
490 496 void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src);
491 497 struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two);
492 498 int var_sym_lists_equiv(struct var_sym_list *one, struct var_sym_list *two);
493 499 void free_var_sym_list(struct var_sym_list **list);
494 500 void free_var_syms_and_list(struct var_sym_list **list);
495 501
496 502 /* smatch_tracker */
497 503 struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym);
498 504 void add_tracker(struct tracker_list **list, int owner, const char *name,
499 505 struct symbol *sym);
500 506 void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr);
501 507 void del_tracker(struct tracker_list **list, int owner, const char *name,
502 508 struct symbol *sym);
503 509 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
504 510 struct symbol *sym);
505 511 void free_tracker_list(struct tracker_list **list);
506 512 void free_trackers_and_list(struct tracker_list **list);
507 513
508 514 /* smatch_conditions */
509 515 int in_condition(void);
510 516
511 517 /* smatch_flow.c */
512 518
513 519 extern int __in_fake_assign;
514 520 extern int __in_fake_parameter_assign;
515 521 extern int __in_fake_struct_assign;
516 522 extern int in_fake_env;
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
517 523 void smatch (struct string_list *filelist);
518 524 int inside_loop(void);
519 525 int definitely_inside_loop(void);
520 526 struct expression *get_switch_expr(void);
521 527 int in_expression_statement(void);
522 528 void __process_post_op_stack(void);
523 529 void __split_expr(struct expression *expr);
524 530 void __split_label_stmt(struct statement *stmt);
525 531 void __split_stmt(struct statement *stmt);
526 532 extern int __in_function_def;
533 +extern int __in_unmatched_hook;
527 534 extern int option_assume_loops;
528 535 extern int option_two_passes;
529 536 extern int option_no_db;
530 537 extern int option_file_output;
531 538 extern int option_time;
532 539 extern struct expression_list *big_expression_stack;
533 540 extern struct expression_list *big_condition_stack;
534 541 extern struct statement_list *big_statement_stack;
535 542 int is_assigned_call(struct expression *expr);
536 543 int inlinable(struct expression *expr);
537 544 extern int __inline_call;
538 545 extern struct expression *__inline_fn;
539 546 extern int __in_pre_condition;
540 547 extern int __bail_on_rest_of_function;
541 548 extern struct statement *__prev_stmt;
542 549 extern struct statement *__cur_stmt;
543 550 extern struct statement *__next_stmt;
544 551 void init_fake_env(void);
545 552 void end_fake_env(void);
546 553 int time_parsing_function(void);
547 554 bool taking_too_long(void);
548 555
549 556 /* smatch_struct_assignment.c */
550 557 struct expression *get_faked_expression(void);
551 558 void __fake_struct_member_assignments(struct expression *expr);
552 559
553 560 /* smatch_project.c */
554 561 int is_no_inline_function(const char *function);
555 562
556 563 /* smatch_conditions */
557 564 void __split_whole_condition(struct expression *expr);
558 565 void __handle_logic(struct expression *expr);
559 566 int is_condition(struct expression *expr);
560 567 int __handle_condition_assigns(struct expression *expr);
561 568 int __handle_select_assigns(struct expression *expr);
562 569 int __handle_expr_statement_assigns(struct expression *expr);
563 570
564 571 /* smatch_implied.c */
565 572 struct range_list_stack;
566 573 void param_limit_implications(struct expression *expr, int param, char *key, char *value);
567 574 struct stree *__implied_case_stree(struct expression *switch_expr,
568 575 struct range_list *case_rl,
569 576 struct range_list_stack **remaining_cases,
570 577 struct stree **raw_stree);
571 578 void overwrite_states_using_pool(struct sm_state *gate_sm, struct sm_state *pool_sm);
572 579 int assume(struct expression *expr);
573 580 void end_assume(void);
574 581 int impossible_assumption(struct expression *left, int op, sval_t sval);
575 582
576 583 /* smatch_slist.h */
577 584 bool has_dynamic_states(unsigned short owner);
578 585 void set_dynamic_states(unsigned short owner);
579 586
580 587 /* smatch_extras.c */
581 588 int in_warn_on_macro(void);
582 589 #define SMATCH_EXTRA 5 /* this is my_id from smatch extra set in smatch.c */
583 590 extern int RETURN_ID;
584 591
585 592 struct data_range {
586 593 sval_t min;
587 594 sval_t max;
588 595 };
589 596
590 597 #define MTAG_ALIAS_BIT (1ULL << 63)
591 598 #define MTAG_OFFSET_MASK 0xfffULL
592 599 #define MTAG_SEED 0xdead << 12
593 600
594 601 const extern unsigned long valid_ptr_min;
595 602 extern unsigned long valid_ptr_max;
596 603 extern const sval_t valid_ptr_min_sval;
597 604 extern sval_t valid_ptr_max_sval;
598 605 extern struct range_list *valid_ptr_rl;
599 606 void alloc_valid_ptr_rl(void);
600 607
601 608 static const sval_t array_min_sval = {
602 609 .type = &ptr_ctype,
603 610 {.value = 100000},
604 611 };
605 612 static const sval_t array_max_sval = {
606 613 .type = &ptr_ctype,
607 614 {.value = ULONG_MAX - 4095},
608 615 };
609 616 static const sval_t text_seg_min = {
610 617 .type = &ptr_ctype,
611 618 {.value = 4096},
612 619 };
613 620 static const sval_t text_seg_max = {
614 621 .type = &ptr_ctype,
615 622 {.value = ULONG_MAX - 4095},
616 623 };
617 624 static const sval_t data_seg_min = {
618 625 .type = &ptr_ctype,
619 626 {.value = 4096},
620 627 };
621 628 static const sval_t data_seg_max = {
622 629 .type = &ptr_ctype,
623 630 {.value = ULONG_MAX - 4095},
624 631 };
625 632 static const sval_t bss_seg_min = {
626 633 .type = &ptr_ctype,
627 634 {.value = 4096},
628 635 };
629 636 static const sval_t bss_seg_max = {
630 637 .type = &ptr_ctype,
631 638 {.value = ULONG_MAX - 4095},
632 639 };
633 640 static const sval_t stack_seg_min = {
634 641 .type = &ptr_ctype,
635 642 {.value = 4096},
636 643 };
637 644 static const sval_t stack_seg_max = {
638 645 .type = &ptr_ctype,
639 646 {.value = ULONG_MAX - 4095},
640 647 };
641 648 static const sval_t kmalloc_seg_min = {
642 649 .type = &ptr_ctype,
643 650 {.value = 4096},
644 651 };
645 652 static const sval_t kmalloc_seg_max = {
646 653 .type = &ptr_ctype,
647 654 {.value = ULONG_MAX - 4095},
648 655 };
649 656 static const sval_t vmalloc_seg_min = {
650 657 .type = &ptr_ctype,
651 658 {.value = 4096},
652 659 };
653 660 static const sval_t vmalloc_seg_max = {
654 661 .type = &ptr_ctype,
655 662 {.value = ULONG_MAX - 4095},
656 663 };
657 664 static const sval_t fn_ptr_min = {
658 665 .type = &ptr_ctype,
659 666 {.value = 4096},
660 667 };
661 668 static const sval_t fn_ptr_max = {
662 669 .type = &ptr_ctype,
663 670 {.value = ULONG_MAX - 4095},
664 671 };
665 672
↓ open down ↓ |
129 lines elided |
↑ open up ↑ |
666 673 char *get_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
667 674 char *map_call_to_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
668 675 char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack);
669 676
670 677 #define STRLEN_MAX_RET 1010101
671 678
672 679 /* smatch_absolute.c */
673 680 int get_absolute_min_helper(struct expression *expr, sval_t *sval);
674 681 int get_absolute_max_helper(struct expression *expr, sval_t *sval);
675 682
676 -/* smatch_local_values.c */
677 -int get_local_rl(struct expression *expr, struct range_list **rl);
678 -int get_local_max_helper(struct expression *expr, sval_t *sval);
679 -int get_local_min_helper(struct expression *expr, sval_t *sval);
680 -
681 683 /* smatch_type_value.c */
682 684 int get_db_type_rl(struct expression *expr, struct range_list **rl);
683 685 /* smatch_data_val.c */
684 686 int get_mtag_rl(struct expression *expr, struct range_list **rl);
685 687 /* smatch_array_values.c */
686 688 int get_array_rl(struct expression *expr, struct range_list **rl);
687 689
688 690 /* smatch_states.c */
689 -void __swap_cur_stree(struct stree *stree);
691 +struct stree *__swap_cur_stree(struct stree *stree);
690 692 void __push_fake_cur_stree();
691 693 struct stree *__pop_fake_cur_stree();
692 694 void __free_fake_cur_stree();
693 695 void __set_fake_cur_stree_fast(struct stree *stree);
694 696 void __pop_fake_cur_stree_fast(void);
695 697 void __merge_stree_into_cur(struct stree *stree);
696 698
697 699 int unreachable(void);
700 +void __set_cur_stree_readonly(void);
701 +void __set_cur_stree_writable(void);
698 702 void __set_sm(struct sm_state *sm);
699 703 void __set_sm_cur_stree(struct sm_state *sm);
700 704 void __set_sm_fake_stree(struct sm_state *sm);
701 705 void __set_true_false_sm(struct sm_state *true_state,
702 706 struct sm_state *false_state);
703 707 void nullify_path(void);
704 708 void __match_nullify_path_hook(const char *fn, struct expression *expr,
705 709 void *unused);
706 710 void __unnullify_path(void);
707 711 int __path_is_null(void);
708 712 void save_all_states(void);
709 713 void restore_all_states(void);
710 714 void free_goto_stack(void);
711 715 void clear_all_states(void);
712 716
713 717 struct sm_state *get_sm_state(int owner, const char *name,
714 718 struct symbol *sym);
715 719 struct sm_state *get_sm_state_expr(int owner, struct expression *expr);
716 720 void __push_true_states(void);
717 721 void __use_false_states(void);
718 722 void __discard_false_states(void);
719 723 void __merge_false_states(void);
720 724 void __merge_true_states(void);
721 725
722 726 void __negate_cond_stacks(void);
723 727 void __use_pre_cond_states(void);
724 728 void __use_cond_true_states(void);
725 729 void __use_cond_false_states(void);
726 730 void __push_cond_stacks(void);
727 731 void __fold_in_set_states(void);
728 732 void __free_set_states(void);
729 733 struct stree *__copy_cond_true_states(void);
730 734 struct stree *__copy_cond_false_states(void);
731 735 struct stree *__pop_cond_true_stack(void);
732 736 struct stree *__pop_cond_false_stack(void);
733 737 void __and_cond_states(void);
734 738 void __or_cond_states(void);
735 739 void __save_pre_cond_states(void);
736 740 void __discard_pre_cond_states(void);
737 741 struct stree *__get_true_states(void);
738 742 struct stree *__get_false_states(void);
739 743 void __use_cond_states(void);
740 744 extern struct state_list *__last_base_slist;
741 745
742 746 void __push_continues(void);
743 747 void __discard_continues(void);
744 748 void __process_continues(void);
745 749 void __merge_continues(void);
746 750
747 751 void __push_breaks(void);
748 752 void __process_breaks(void);
749 753 int __has_breaks(void);
750 754 void __merge_breaks(void);
751 755 void __use_breaks(void);
752 756
753 757 void __save_switch_states(struct expression *switch_expr);
754 758 void __discard_switches(void);
755 759 int have_remaining_cases(void);
756 760 void __merge_switches(struct expression *switch_expr, struct range_list *case_rl);
757 761 void __push_default(void);
758 762 void __set_default(void);
759 763 int __pop_default(void);
760 764
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
761 765 void __push_conditions(void);
762 766 void __discard_conditions(void);
763 767
764 768 void __save_gotos(const char *name, struct symbol *sym);
765 769 void __merge_gotos(const char *name, struct symbol *sym);
766 770
767 771 void __print_cur_stree(void);
768 772
769 773 /* smatch_hooks.c */
770 774 void __pass_to_client(void *data, enum hook_type type);
771 -void __pass_to_client_no_data(enum hook_type type);
772 775 void __pass_case_to_client(struct expression *switch_expr,
773 776 struct range_list *rl);
774 777 int __has_merge_function(int client_id);
775 778 struct smatch_state *__client_merge_function(int owner,
776 779 struct smatch_state *s1,
777 780 struct smatch_state *s2);
778 781 struct smatch_state *__client_unmatched_state_function(struct sm_state *sm);
779 -void call_pre_merge_hook(struct sm_state *sm);
782 +void call_pre_merge_hook(struct sm_state *cur, struct sm_state *other);
780 783 void __push_scope_hooks(void);
781 784 void __call_scope_hooks(void);
782 785
783 786 /* smatch_function_hooks.c */
784 787 void create_function_hook_hash(void);
785 788 void __match_initializer_call(struct symbol *sym);
786 789
787 790 /* smatch_db.c */
788 791 enum info_type {
789 792 INTERNAL = 0,
790 793 /*
791 794 * Changing these numbers is a pain. Don't do it. If you ever use a
792 795 * number it can't be re-used right away so there may be gaps.
793 796 * We select these in order by type so if the order matters, then give
794 797 * it a number below 100-999,9000-9999 ranges. */
795 798
796 799 PARAM_CLEARED = 101,
797 800 PARAM_LIMIT = 103,
798 801 PARAM_FILTER = 104,
799 802
800 803 PARAM_VALUE = 1001,
801 804 BUF_SIZE = 1002,
802 805 CAPPED_DATA = 1004,
803 806 RETURN_VALUE = 1005,
804 807 DEREFERENCE = 1006,
805 808 RANGE_CAP = 1007,
806 809 LOCK_HELD = 1008,
807 810 LOCK_RELEASED = 1009,
808 811 ABSOLUTE_LIMITS = 1010,
809 812 PARAM_ADD = 1012,
810 813 PARAM_FREED = 1013,
811 814 DATA_SOURCE = 1014,
812 815 FUZZY_MAX = 1015,
813 816 HARD_MAX = 2015,
814 817 STR_LEN = 1016,
815 818 ARRAY_LEN = 1017,
816 819 CAPABLE = 1018,
817 820 NS_CAPABLE = 1019,
818 821 CONTAINER = 1020,
819 822 CASTED_CALL = 1021,
820 823 TYPE_LINK = 1022,
821 824 UNTRACKED_PARAM = 1023,
822 825 LOST_PARAM = 2023,
823 826 CULL_PATH = 1024,
824 827 PARAM_SET = 1025,
825 828 PARAM_USED = 1026,
826 829 BYTE_UNITS = 1027,
827 830 COMPARE_LIMIT = 1028,
828 831 PARAM_COMPARE = 1029,
829 832 CONSTRAINT = 1031,
830 833 PASSES_TYPE = 1032,
831 834 CONSTRAINT_REQUIRED = 1033,
832 835 BIT_INFO = 1034,
833 836 NOSPEC = 1035,
834 837 NOSPEC_WB = 1036,
835 838 STMT_CNT = 1037,
836 839 TERMINATED = 1038,
837 840
838 841 /* put random temporary stuff in the 7000-7999 range for testing */
839 842 USER_DATA = 8017,
840 843 USER_DATA_SET = 9017,
841 844 NO_OVERFLOW = 8018,
842 845 NO_OVERFLOW_SIMPLE = 8019,
843 846 LOCKED = 8020,
844 847 UNLOCKED = 8021,
845 848 SET_FS = 8022,
846 849 ATOMIC_INC = 8023,
847 850 ATOMIC_DEC = 8024,
848 851 NO_SIDE_EFFECT = 8025,
849 852 FN_ARG_LINK = 8028,
850 853 DATA_VALUE = 8029,
851 854 ARRAYSIZE_ARG = 8033,
852 855 SIZEOF_ARG = 8034,
853 856 MEMORY_TAG = 8036,
854 857 MTAG_ASSIGN = 8035,
855 858 STRING_VALUE = 8041,
856 859
857 860 BYTE_COUNT = 8050,
858 861 ELEM_COUNT = 8051,
859 862 ELEM_LAST = 8052,
860 863 USED_LAST = 8053,
861 864 USED_COUNT = 8054,
862 865 };
863 866
864 867 extern struct sqlite3 *smatch_db;
865 868 extern struct sqlite3 *mem_db;
866 869 extern struct sqlite3 *cache_db;
↓ open down ↓ |
77 lines elided |
↑ open up ↑ |
867 870
868 871 void db_ignore_states(int id);
869 872 void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
870 873 void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm));
871 874 void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
872 875 void add_returned_member_callback(int owner, void (*callback)(int return_id, char *return_ranges, struct expression *expr, char *printed_name, struct smatch_state *state));
873 876 void select_call_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value));
874 877 void select_return_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value));
875 878 struct range_list *db_return_vals(struct expression *expr);
876 879 struct range_list *db_return_vals_from_str(const char *fn_name);
880 +struct range_list *db_return_vals_no_args(struct expression *expr);
877 881 char *return_state_to_var_sym(struct expression *expr, int param, const char *key, struct symbol **sym);
878 882 char *get_chunk_from_key(struct expression *arg, char *key, struct symbol **sym, struct var_sym_list **vsl);
879 883 char *get_variable_from_key(struct expression *arg, const char *key, struct symbol **sym);
880 884 const char *state_name_to_param_name(const char *state_name, const char *param_name);
881 885 const char *get_param_name_var_sym(const char *name, struct symbol *sym);
882 886 const char *get_param_name(struct sm_state *sm);
883 887 const char *get_mtag_name_var_sym(const char *state_name, struct symbol *sym);
884 888 const char *get_mtag_name_expr(struct expression *expr);
885 889 char *get_data_info_name(struct expression *expr);
886 890 int is_recursive_member(const char *param_name);
887 891
888 892 char *escape_newlines(const char *str);
889 893 void sql_exec(struct sqlite3 *db, int (*callback)(void*, int, char**, char**), void *data, const char *sql);
890 894
891 895 #define sql_helper(db, call_back, data, sql...) \
892 896 do { \
893 897 char sql_txt[1024]; \
894 898 \
895 899 sqlite3_snprintf(sizeof(sql_txt), sql_txt, sql); \
896 900 sm_debug("debug: %s\n", sql_txt); \
897 901 sql_exec(db, call_back, data, sql_txt); \
898 902 } while (0)
899 903
900 904
901 905 #define run_sql(call_back, data, sql...) \
902 906 do { \
903 907 if (option_no_db) \
904 908 break; \
905 909 sql_helper(smatch_db, call_back, data, sql); \
906 910 } while (0)
907 911
908 912 #define mem_sql(call_back, data, sql...) \
909 913 sql_helper(mem_db, call_back, data, sql)
910 914
911 915 #define cache_sql(call_back, data, sql...) \
912 916 sql_helper(cache_db, call_back, data, sql)
913 917
914 918 #define sql_insert_helper(table, db, ignore, late, values...) \
915 919 do { \
916 920 struct sqlite3 *_db = db; \
917 921 \
918 922 if (__inline_fn && !_db) \
919 923 _db = mem_db; \
920 924 if (_db) { \
921 925 char buf[1024]; \
922 926 char *err, *p = buf; \
923 927 int rc; \
924 928 \
925 929 p += snprintf(p, buf + sizeof(buf) - p, \
926 930 "insert %sinto %s values (", \
927 931 ignore ? "or ignore " : "", #table); \
928 932 p += snprintf(p, buf + sizeof(buf) - p, values); \
929 933 p += snprintf(p, buf + sizeof(buf) - p, ");"); \
930 934 sm_debug("mem-db: %s\n", buf); \
931 935 rc = sqlite3_exec(_db, buf, NULL, NULL, &err); \
932 936 if (rc != SQLITE_OK) { \
933 937 sm_ierror("SQL error #2: %s", err); \
934 938 sm_ierror("SQL: '%s'", buf); \
935 939 parse_error = 1; \
936 940 } \
937 941 break; \
938 942 } \
939 943 if (option_info) { \
940 944 FILE *tmp_fd = sm_outfd; \
941 945 sm_outfd = sql_outfd; \
942 946 sm_prefix(); \
943 947 sm_printf("SQL%s: insert %sinto " #table " values(", \
944 948 late ? "_late" : "", ignore ? "or ignore " : ""); \
945 949 sm_printf(values); \
946 950 sm_printf(");\n"); \
947 951 sm_outfd = tmp_fd; \
948 952 } \
949 953 } while (0)
950 954
951 955 #define sql_insert(table, values...) sql_insert_helper(table, 0, 0, 0, values);
952 956 #define sql_insert_or_ignore(table, values...) sql_insert_helper(table, 0, 1, 0, values);
953 957 #define sql_insert_late(table, values...) sql_insert_helper(table, 0, 0, 1, values);
954 958 #define sql_insert_cache(table, values...) sql_insert_helper(table, cache_db, 1, 0, values);
955 959
956 960 char *get_static_filter(struct symbol *sym);
957 961
958 962 void sql_insert_return_states(int return_id, const char *return_ranges,
959 963 int type, int param, const char *key, const char *value);
960 964 void sql_insert_caller_info(struct expression *call, int type, int param,
961 965 const char *key, const char *value);
962 966 void sql_insert_function_ptr(const char *fn, const char *struct_name);
963 967 void sql_insert_return_values(const char *return_values);
964 968 void sql_insert_return_implies(int type, int param, const char *key, const char *value);
965 969 void sql_insert_function_type_size(const char *member, const char *ranges);
966 970 void sql_insert_function_type_info(int type, const char *struct_type, const char *member, const char *value);
967 971 void sql_insert_type_info(int type, const char *member, const char *value);
968 972 void sql_insert_local_values(const char *name, const char *value);
969 973 void sql_insert_function_type_value(const char *type, const char *value);
970 974 void sql_insert_function_type(int param, const char *value);
971 975 void sql_insert_parameter_name(int param, const char *value);
972 976 void sql_insert_data_info(struct expression *data, int type, const char *value);
973 977 void sql_insert_data_info_var_sym(const char *var, struct symbol *sym, int type, const char *value);
974 978 void sql_save_constraint(const char *con);
975 979 void sql_save_constraint_required(const char *data, int op, const char *limit);
976 980 void sql_copy_constraint_required(const char *new_limit, const char *old_limit);
977 981 void sql_insert_fn_ptr_data_link(const char *ptr, const char *data);
978 982 void sql_insert_fn_data_link(struct expression *fn, int type, int param, const char *key, const char *value);
979 983 void sql_insert_mtag_about(mtag_t tag, const char *left_name, const char *right_name);
980 984 void sql_insert_mtag_map(mtag_t tag, int offset, mtag_t container);
981 985 void sql_insert_mtag_alias(mtag_t orig, mtag_t alias);
982 986 int mtag_map_select_container(mtag_t tag, int offset, mtag_t *container);
983 987 int mtag_map_select_tag(mtag_t container, int offset, mtag_t *tag);
984 988 struct smatch_state *swap_mtag_return(struct expression *expr, struct smatch_state *state);
985 989 struct range_list *swap_mtag_seed(struct expression *expr, struct range_list *rl);
986 990
987 991 void sql_select_return_states(const char *cols, struct expression *call,
988 992 int (*callback)(void*, int, char**, char**), void *info);
989 993 void sql_select_call_implies(const char *cols, struct expression *call,
990 994 int (*callback)(void*, int, char**, char**));
991 995
992 996 void open_smatch_db(char *db_file);
993 997
994 998 /* smatch_files.c */
995 999 int open_data_file(const char *filename);
996 1000 int open_schema_file(const char *schema);
997 1001 struct token *get_tokens_file(const char *filename);
998 1002
999 1003 /* smatch.c */
1000 1004 extern char *option_debug_check;
1001 1005 extern char *option_project_str;
1002 1006 extern char *bin_dir;
1003 1007 extern char *data_dir;
1004 1008 extern int option_no_data;
1005 1009 extern int option_full_path;
1006 1010 extern int option_param_mapper;
1007 1011 extern int option_call_tree;
1008 1012 extern int num_checks;
1009 1013
1010 1014 enum project_type {
1011 1015 PROJ_NONE,
1012 1016 PROJ_KERNEL,
1013 1017 PROJ_WINE,
1014 1018 PROJ_ILLUMOS_KERNEL,
1015 1019 PROJ_ILLUMOS_USER,
1016 1020 PROJ_UNKNOWN,
1017 1021 };
1018 1022 extern enum project_type option_project;
1019 1023 const char *check_name(unsigned short id);
1020 1024 int id_from_name(const char *name);
1021 1025
1022 1026
1023 1027 /* smatch_buf_size.c */
1024 1028 int get_array_size(struct expression *expr);
1025 1029 int get_array_size_bytes(struct expression *expr);
1026 1030 int get_array_size_bytes_min(struct expression *expr);
1027 1031 int get_array_size_bytes_max(struct expression *expr);
1028 1032 struct range_list *get_array_size_bytes_rl(struct expression *expr);
1029 1033 int get_real_array_size(struct expression *expr);
1030 1034 int last_member_is_resizable(struct symbol *type);
1031 1035 /* smatch_strlen.c */
1032 1036 int get_implied_strlen(struct expression *expr, struct range_list **rl);
1033 1037 int get_size_from_strlen(struct expression *expr);
1034 1038
1035 1039 /* smatch_capped.c */
1036 1040 int is_capped(struct expression *expr);
1037 1041 int is_capped_var_sym(const char *name, struct symbol *sym);
1038 1042
1039 1043 /* check_user_data.c */
1040 1044 int is_user_macro(struct expression *expr);
1041 1045 int is_capped_user_data(struct expression *expr);
1042 1046 int implied_user_data(struct expression *expr, struct range_list **rl);
1043 1047 struct stree *get_user_stree(void);
1044 1048 int get_user_rl(struct expression *expr, struct range_list **rl);
1045 1049 int is_user_rl(struct expression *expr);
1046 1050 int get_user_rl_var_sym(const char *name, struct symbol *sym, struct range_list **rl);
1047 1051 bool user_rl_capped(struct expression *expr);
1048 1052 struct range_list *var_user_rl(struct expression *expr);
1049 1053
1050 1054 /* check_locking.c */
↓ open down ↓ |
164 lines elided |
↑ open up ↑ |
1051 1055 void print_held_locks();
1052 1056
1053 1057 /* check_assigned_expr.c */
1054 1058 struct expression *get_assigned_expr(struct expression *expr);
1055 1059 struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym);
1056 1060 /* smatch_return_to_param.c */
1057 1061 void __add_return_to_param_mapping(struct expression *assign, const char *return_string);
1058 1062 char *map_call_to_param_name_sym(struct expression *expr, struct symbol **sym);
1059 1063
1060 1064 /* smatch_comparison.c */
1065 +#define UNKNOWN_COMPARISON 0
1066 +#define IMPOSSIBLE_COMPARISON -1
1061 1067 struct compare_data {
1062 1068 /* The ->left and ->right expression pointers might be NULL (I'm lazy) */
1063 1069 struct expression *left;
1064 1070 const char *left_var;
1065 1071 struct var_sym_list *left_vsl;
1066 1072 int comparison;
1067 1073 struct expression *right;
1068 1074 const char *right_var;
1069 1075 struct var_sym_list *right_vsl;
1070 1076 };
1071 1077 DECLARE_ALLOCATOR(compare_data);
1072 1078 struct smatch_state *alloc_compare_state(
1073 1079 struct expression *left,
1074 1080 const char *left_var, struct var_sym_list *left_vsl,
1075 1081 int comparison,
1076 1082 struct expression *right,
1077 1083 const char *right_var, struct var_sym_list *right_vsl);
1078 -int filter_comparison(int orig, int op);
1084 +int comparison_intersection(int orig, int op);
1079 1085 int merge_comparisons(int one, int two);
1080 1086 int combine_comparisons(int left_compare, int right_compare);
1081 1087 int state_to_comparison(struct smatch_state *state);
1082 1088 struct smatch_state *merge_compare_states(struct smatch_state *s1, struct smatch_state *s2);
1083 1089 int get_comparison(struct expression *left, struct expression *right);
1084 1090 int get_comparison_no_extra(struct expression *a, struct expression *b);
1085 1091 int get_comparison_strings(const char *one, const char *two);
1086 1092 int possible_comparison(struct expression *a, int comparison, struct expression *b);
1087 1093 struct state_list *get_all_comparisons(struct expression *expr);
1088 1094 struct state_list *get_all_possible_equal_comparisons(struct expression *expr);
1089 1095 void __add_return_comparison(struct expression *call, const char *range);
1090 1096 void __add_comparison_info(struct expression *expr, struct expression *call, const char *range);
1091 1097 char *get_printed_param_name(struct expression *call, const char *param_name, struct symbol *param_sym);
1092 1098 char *name_sym_to_param_comparison(const char *name, struct symbol *sym);
1093 1099 char *expr_equal_to_param(struct expression *expr, int ignore);
1094 1100 char *expr_lte_to_param(struct expression *expr, int ignore);
1095 1101 char *expr_param_comparison(struct expression *expr, int ignore);
1096 1102 int flip_comparison(int op);
1097 1103 int negate_comparison(int op);
1098 1104 int remove_unsigned_from_comparison(int op);
1099 1105 int param_compare_limit_is_impossible(struct expression *expr, int left_param, char *left_key, char *value);
1100 1106 void filter_by_comparison(struct range_list **rl, int comparison, struct range_list *right);
1101 1107 struct sm_state *comparison_implication_hook(struct expression *expr,
1102 1108 struct state_list **true_stack,
1103 1109 struct state_list **false_stack);
1104 1110 void __compare_param_limit_hook(struct expression *left_expr, struct expression *right_expr,
1105 1111 const char *state_name,
1106 1112 struct smatch_state *true_state, struct smatch_state *false_state);
1107 1113 int impossibly_high_comparison(struct expression *expr);
1108 1114
1109 1115 /* smatch_sval.c */
1110 1116 sval_t *sval_alloc(sval_t sval);
1111 1117 sval_t *sval_alloc_permanent(sval_t sval);
1112 1118 sval_t sval_blank(struct expression *expr);
1113 1119 sval_t sval_type_val(struct symbol *type, long long val);
1114 1120 sval_t sval_from_val(struct expression *expr, long long val);
1115 1121 int sval_is_ptr(sval_t sval);
1116 1122 int sval_unsigned(sval_t sval);
1117 1123 int sval_signed(sval_t sval);
1118 1124 int sval_bits(sval_t sval);
1119 1125 int sval_bits_used(sval_t sval);
1120 1126 int sval_is_negative(sval_t sval);
1121 1127 int sval_is_positive(sval_t sval);
1122 1128 int sval_is_min(sval_t sval);
1123 1129 int sval_is_max(sval_t sval);
1124 1130 int sval_is_a_min(sval_t sval);
1125 1131 int sval_is_a_max(sval_t sval);
1126 1132 int sval_is_negative_min(sval_t sval);
1127 1133 int sval_cmp_t(struct symbol *type, sval_t one, sval_t two);
1128 1134 int sval_cmp_val(sval_t one, long long val);
1129 1135 sval_t sval_min(sval_t one, sval_t two);
1130 1136 sval_t sval_max(sval_t one, sval_t two);
1131 1137 int sval_too_low(struct symbol *type, sval_t sval);
1132 1138 int sval_too_high(struct symbol *type, sval_t sval);
1133 1139 int sval_fits(struct symbol *type, sval_t sval);
1134 1140 sval_t sval_cast(struct symbol *type, sval_t sval);
1135 1141 sval_t sval_preop(sval_t sval, int op);
1136 1142 sval_t sval_binop(sval_t left, int op, sval_t right);
1137 1143 int sval_binop_overflows(sval_t left, int op, sval_t right);
1138 1144 int sval_binop_overflows_no_sign(sval_t left, int op, sval_t right);
1139 1145 int find_first_zero_bit(unsigned long long uvalue);
1140 1146 int sm_fls64(unsigned long long uvalue);
1141 1147 unsigned long long fls_mask(unsigned long long uvalue);
1142 1148 unsigned long long sval_fls_mask(sval_t sval);
1143 1149 const char *sval_to_str(sval_t sval);
1144 1150 const char *sval_to_str_or_err_ptr(sval_t sval);
1145 1151 const char *sval_to_numstr(sval_t sval);
1146 1152 sval_t ll_to_sval(long long val);
1147 1153
1148 1154 /* smatch_string_list.c */
1149 1155 int list_has_string(struct string_list *str_list, const char *str);
1150 1156 int insert_string(struct string_list **str_list, const char *str);
1151 1157 struct string_list *clone_str_list(struct string_list *orig);
1152 1158 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two);
1153 1159
1154 1160 /* smatch_start_states.c */
1155 1161 struct stree *get_start_states(void);
1156 1162
1157 1163 /* smatch_recurse.c */
1158 1164 int has_symbol(struct expression *expr, struct symbol *sym);
1159 1165 int has_variable(struct expression *expr, struct expression *var);
1160 1166 int has_inc_dec(struct expression *expr);
1161 1167
1162 1168 /* smatch_stored_conditions.c */
1163 1169 struct smatch_state *get_stored_condition(struct expression *expr);
1164 1170 struct expression_list *get_conditions(struct expression *expr);
1165 1171 struct sm_state *stored_condition_implication_hook(struct expression *expr,
↓ open down ↓ |
77 lines elided |
↑ open up ↑ |
1166 1172 struct state_list **true_stack,
1167 1173 struct state_list **false_stack);
1168 1174
1169 1175 /* check_string_len.c */
1170 1176 int get_formatted_string_size(struct expression *call, int arg);
1171 1177 int get_formatted_string_min_size(struct expression *call, int arg);
1172 1178
1173 1179 /* smatch_param_set.c */
1174 1180 int param_was_set(struct expression *expr);
1175 1181 int param_was_set_var_sym(const char *name, struct symbol *sym);
1182 +void print_limited_param_set(int return_id, char *return_ranges, struct expression *expr);
1176 1183 /* smatch_param_filter.c */
1177 1184 int param_has_filter_data(struct sm_state *sm);
1178 1185
1179 1186 /* smatch_links.c */
1180 1187 void set_up_link_functions(int id, int linkid);
1181 1188 struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2);
1182 1189 void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym);
1183 1190
1184 -/* smatch_auto_copy.c */
1185 -void set_auto_copy(int owner);
1186 -
1187 1191 /* check_buf_comparison */
1188 1192 const char *limit_type_str(unsigned int limit_type);
1189 1193 struct expression *get_size_variable(struct expression *buf, int *limit_type);
1190 1194 struct expression *get_array_variable(struct expression *size);
1191 1195 int buf_comparison_index_ok(struct expression *expr);
1192 1196
1193 1197 /* smatch_untracked_param.c */
1194 1198 void mark_untracked(struct expression *expr, int param, const char *key, const char *value);
1195 1199 void add_untracked_param_hook(void (func)(struct expression *call, int param));
1196 1200 void add_lost_param_hook(void (func)(struct expression *call, int param));
1197 1201 void mark_all_params_untracked(int return_id, char *return_ranges, struct expression *expr);
1198 1202
1199 1203 /* smatch_strings.c */
1200 1204 struct state_list *get_strings(struct expression *expr);
1201 1205 struct expression *fake_string_from_mtag(mtag_t tag);
1202 1206
1203 1207 /* smatch_estate.c */
1204 1208 int estate_get_single_value(struct smatch_state *state, sval_t *sval);
1205 1209
1206 1210 /* smatch_address.c */
1207 1211 int get_address_rl(struct expression *expr, struct range_list **rl);
1208 1212 int get_member_offset(struct symbol *type, const char *member_name);
1209 1213 int get_member_offset_from_deref(struct expression *expr);
1210 1214
1211 1215 /* for now this is in smatch_used_parameter.c */
1212 1216 void __get_state_hook(int owner, const char *name, struct symbol *sym);
1213 1217
1214 1218 /* smatch_buf_comparison.c */
1215 1219 int db_var_is_array_limit(struct expression *array, const char *name, struct var_sym_list *vsl);
1216 1220
1217 1221 struct stree *get_all_return_states(void);
1218 1222 struct stree_stack *get_all_return_strees(void);
1219 1223 int on_atomic_dec_path(void);
1220 1224 int was_inced(const char *name, struct symbol *sym);
1221 1225
1222 1226 /* smatch_constraints.c */
1223 1227 char *get_constraint_str(struct expression *expr);
1224 1228 struct constraint_list *get_constraints(struct expression *expr);
1225 1229 char *unmet_constraint(struct expression *data, struct expression *offset);
1226 1230 char *get_required_constraint(const char *data_str);
1227 1231
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
1228 1232 /* smatch_container_of.c */
1229 1233 int get_param_from_container_of(struct expression *expr);
1230 1234 int get_offset_from_container_of(struct expression *expr);
1231 1235 char *get_container_name(struct expression *container, struct expression *expr);
1232 1236
1233 1237 /* smatch_mtag.c */
1234 1238 int get_string_mtag(struct expression *expr, mtag_t *tag);
1235 1239 int get_toplevel_mtag(struct symbol *sym, mtag_t *tag);
1236 1240 int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new);
1237 1241 int expr_to_mtag_offset(struct expression *expr, mtag_t *tag, int *offset);
1238 -void update_mtag_data(struct expression *expr);
1242 +void update_mtag_data(struct expression *expr, struct smatch_state *state);
1239 1243 int get_mtag_sval(struct expression *expr, sval_t *sval);
1240 1244
1241 1245 /* Trinity fuzzer stuff */
1242 1246 const char *get_syscall_arg_type(struct symbol *sym);
1243 1247
1244 1248 /* smatch_bit_info.c */
1249 +struct bit_info *rl_to_binfo(struct range_list *rl);
1245 1250 struct bit_info *get_bit_info(struct expression *expr);
1246 1251 struct bit_info *get_bit_info_var_sym(const char *name, struct symbol *sym);
1247 1252 /* smatch_mem_tracker.c */
1248 1253 extern int option_mem;
1249 1254 unsigned long get_mem_kb(void);
1250 1255 unsigned long get_max_memory(void);
1251 1256
1252 1257 /* check_is_nospec.c */
1253 1258 bool is_nospec(struct expression *expr);
1254 1259 long get_stmt_cnt(void);
1255 1260
1256 1261 /* smatch_nul_terminator.c */
1262 +bool is_nul_terminated_var_sym(const char *name, struct symbol *sym);
1257 1263 bool is_nul_terminated(struct expression *expr);
1258 1264 /* check_kernel.c */
1259 1265 bool is_ignored_kernel_data(const char *name);
1260 1266
1261 1267 static inline bool type_is_ptr(struct symbol *type)
1262 1268 {
1263 1269 return type &&
1264 1270 (type->type == SYM_PTR ||
1265 1271 type->type == SYM_ARRAY ||
1266 1272 type->type == SYM_FN);
1267 1273 }
1268 1274
1269 1275 static inline int type_bits(struct symbol *type)
1270 1276 {
1271 1277 if (!type)
1272 1278 return 0;
1273 1279 if (type_is_ptr(type))
1274 1280 return bits_in_pointer;
1275 1281 if (!type->examined)
1276 1282 examine_symbol_type(type);
1277 1283 return type->bit_size;
1278 1284 }
1279 1285
1280 1286 static inline int type_unsigned(struct symbol *base_type)
1281 1287 {
1282 1288 if (!base_type)
1283 1289 return 0;
1284 1290 if (is_ptr_type(base_type))
1285 1291 return 1;
1286 1292 if (base_type->ctype.modifiers & MOD_UNSIGNED)
1287 1293 return 1;
1288 1294 return 0;
1289 1295 }
1290 1296
1291 1297 static inline int type_positive_bits(struct symbol *type)
1292 1298 {
1293 1299 if (!type)
1294 1300 return 0;
1295 1301 if (is_ptr_type(type))
1296 1302 return bits_in_pointer;
1297 1303 if (type_unsigned(type))
1298 1304 return type_bits(type);
1299 1305 return type_bits(type) - 1;
1300 1306 }
1301 1307
1302 1308 static inline int sval_positive_bits(sval_t sval)
1303 1309 {
1304 1310 return type_positive_bits(sval.type);
1305 1311 }
1306 1312
1307 1313 /*
1308 1314 * Returns -1 if one is smaller, 0 if they are the same and 1 if two is larger.
1309 1315 */
1310 1316 static inline int sval_cmp(sval_t one, sval_t two)
1311 1317 {
1312 1318 struct symbol *type;
1313 1319
1314 1320 type = one.type;
1315 1321 if (sval_positive_bits(two) > sval_positive_bits(one))
1316 1322 type = two.type;
1317 1323 if (type_bits(type) < 31)
1318 1324 type = &int_ctype;
1319 1325
1320 1326 one = sval_cast(type, one);
1321 1327 two = sval_cast(type, two);
1322 1328
1323 1329 if (type_unsigned(type)) {
1324 1330 if (one.uvalue < two.uvalue)
1325 1331 return -1;
1326 1332 if (one.uvalue == two.uvalue)
1327 1333 return 0;
1328 1334 return 1;
1329 1335 }
1330 1336 /* fix me handle type promotion and unsigned values */
1331 1337 if (one.value < two.value)
1332 1338 return -1;
1333 1339 if (one.value == two.value)
1334 1340 return 0;
1335 1341 return 1;
1336 1342 }
1337 1343
1338 1344 #endif /* !SMATCH_H_ */
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX