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