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