check_kernel_printf.c: Simplify recursive calling
[smatch.git] / smatch.h
blob317d053ba4b41ab57066df36d384bf8cf5b6db14
1 /*
2 * Copyright (C) 2006 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #ifndef SMATCH_H_
19 # define SMATCH_H_
21 #include <stdio.h>
22 #include <string.h>
23 #include <limits.h>
24 #include <sys/time.h>
25 #include "lib.h"
26 #include "allocate.h"
27 #include "scope.h"
28 #include "parse.h"
29 #include "expression.h"
30 #include "avl.h"
32 typedef struct {
33 struct symbol *type;
34 union {
35 long long value;
36 unsigned long long uvalue;
38 } sval_t;
40 struct smatch_state {
41 const char *name;
42 void *data;
44 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
45 extern struct smatch_state undefined;
46 extern struct smatch_state ghost;
47 extern struct smatch_state merged;
48 extern struct smatch_state true_state;
49 extern struct smatch_state false_state;
50 DECLARE_ALLOCATOR(smatch_state);
52 static inline void *INT_PTR(int i)
54 return (void *)(long)i;
57 static inline int PTR_INT(void *p)
59 return (int)(long)p;
62 struct tracker {
63 char *name;
64 struct symbol *sym;
65 unsigned short owner;
67 DECLARE_ALLOCATOR(tracker);
68 DECLARE_PTR_LIST(tracker_list, struct tracker);
70 /* The first 3 struct members must match struct tracker */
71 struct sm_state {
72 const char *name;
73 struct symbol *sym;
74 unsigned short owner;
75 unsigned short merged:1;
76 unsigned short implied:1;
77 unsigned int nr_children;
78 unsigned int line;
79 struct smatch_state *state;
80 struct stree *pool;
81 struct sm_state *left;
82 struct sm_state *right;
83 struct state_list *possible;
86 struct var_sym {
87 char *var;
88 struct symbol *sym;
90 DECLARE_ALLOCATOR(var_sym);
91 DECLARE_PTR_LIST(var_sym_list, struct var_sym);
93 enum hook_type {
94 EXPR_HOOK,
95 STMT_HOOK,
96 STMT_HOOK_AFTER,
97 SYM_HOOK,
98 STRING_HOOK,
99 DECLARATION_HOOK,
100 ASSIGNMENT_HOOK,
101 RAW_ASSIGNMENT_HOOK,
102 GLOBAL_ASSIGNMENT_HOOK,
103 LOGIC_HOOK,
104 CONDITION_HOOK,
105 PRELOOP_HOOK,
106 SELECT_HOOK,
107 WHOLE_CONDITION_HOOK,
108 FUNCTION_CALL_HOOK,
109 CALL_HOOK_AFTER_INLINE,
110 FUNCTION_CALL_HOOK_AFTER,
111 CALL_ASSIGNMENT_HOOK,
112 MACRO_ASSIGNMENT_HOOK,
113 BINOP_HOOK,
114 OP_HOOK,
115 DEREF_HOOK,
116 CASE_HOOK,
117 ASM_HOOK,
118 CAST_HOOK,
119 SIZEOF_HOOK,
120 BASE_HOOK,
121 FUNC_DEF_HOOK,
122 AFTER_DEF_HOOK,
123 END_FUNC_HOOK,
124 AFTER_FUNC_HOOK,
125 RETURN_HOOK,
126 INLINE_FN_START,
127 INLINE_FN_END,
128 END_FILE_HOOK,
131 #define TRUE 1
132 #define FALSE 0
134 struct range_list;
136 void add_hook(void *func, enum hook_type type);
137 typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2);
138 typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state);
139 void add_merge_hook(int client_id, merge_func_t *func);
140 void add_unmatched_state_hook(int client_id, unmatched_func_t *func);
141 void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *sm));
142 typedef void (scope_hook)(void *data);
143 void add_scope_hook(scope_hook *hook, void *data);
144 typedef void (func_hook)(const char *fn, struct expression *expr, void *data);
145 typedef void (implication_hook)(const char *fn, struct expression *call_expr,
146 struct expression *assign_expr, void *data);
147 typedef void (return_implies_hook)(struct expression *call_expr,
148 int param, char *key, char *value);
149 typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl);
150 void add_function_hook(const char *look_for, func_hook *call_back, void *data);
152 void add_function_assign_hook(const char *look_for, func_hook *call_back,
153 void *info);
154 void add_implied_return_hook(const char *look_for,
155 implied_return_hook *call_back,
156 void *info);
157 void add_macro_assign_hook(const char *look_for, func_hook *call_back,
158 void *info);
159 void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
160 void *info);
161 void return_implies_state(const char *look_for, long long start, long long end,
162 implication_hook *call_back, void *info);
163 void select_return_states_hook(int type, return_implies_hook *callback);
164 void select_return_states_before(void (*fn)(void));
165 void select_return_states_after(void (*fn)(void));
166 int get_implied_return(struct expression *expr, struct range_list **rl);
167 void allocate_hook_memory(void);
169 typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr);
170 void add_modification_hook(int owner, modification_hook *call_back);
171 void add_indirect_modification_hook(int owner, modification_hook *call_back);
173 int outside_of_function(void);
174 const char *get_filename(void);
175 const char *get_base_file(void);
176 char *get_function(void);
177 int get_lineno(void);
178 extern int final_pass;
179 extern struct symbol *cur_func_sym;
180 extern int option_debug;
181 extern int local_debug;
182 extern int option_info;
183 extern char *trace_variable;
184 extern struct stree *global_states;
185 int is_silenced_function(void);
187 extern FILE *sm_outfd;
188 #define sm_printf(msg...) do { if (final_pass || option_debug) fprintf(sm_outfd, msg); } while (0)
190 static inline void sm_prefix(void)
192 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
195 static inline void print_implied_debug_msg();
197 #define sm_msg(msg...) \
198 do { \
199 print_implied_debug_msg(); \
200 if (!option_debug && !final_pass) \
201 break; \
202 if (!option_info && is_silenced_function()) \
203 break; \
204 sm_prefix(); \
205 sm_printf(msg); \
206 sm_printf("\n"); \
207 } while (0)
209 #define local_debug(msg...) \
210 do { \
211 if (local_debug) \
212 sm_msg(msg); \
213 } while (0)
215 extern char *implied_debug_msg;
216 static inline void print_implied_debug_msg(void)
218 static struct symbol *last_printed = NULL;
220 if (!implied_debug_msg)
221 return;
222 if (last_printed == cur_func_sym)
223 return;
224 last_printed = cur_func_sym;
225 sm_msg("%s", implied_debug_msg);
228 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
230 #define sm_info(msg...) do { \
231 if (option_debug || (option_info && final_pass)) { \
232 sm_prefix(); \
233 sm_printf("info: "); \
234 sm_printf(msg); \
235 sm_printf("\n"); \
237 } while(0)
239 struct smatch_state *get_state(int owner, const char *name, struct symbol *sym);
240 struct smatch_state *get_state_expr(int owner, struct expression *expr);
241 struct state_list *get_possible_states(int owner, const char *name,
242 struct symbol *sym);
243 struct state_list *get_possible_states_expr(int owner, struct expression *expr);
244 struct sm_state *set_state(int owner, const char *name, struct symbol *sym,
245 struct smatch_state *state);
246 struct sm_state *set_state_expr(int owner, struct expression *expr,
247 struct smatch_state *state);
248 void delete_state(int owner, const char *name, struct symbol *sym);
249 void delete_state_expr(int owner, struct expression *expr);
250 void set_true_false_states(int owner, const char *name, struct symbol *sym,
251 struct smatch_state *true_state,
252 struct smatch_state *false_state);
253 void set_true_false_states_expr(int owner, struct expression *expr,
254 struct smatch_state *true_state,
255 struct smatch_state *false_state);
257 struct stree *get_all_states_from_stree(int owner, struct stree *source);
258 struct stree *get_all_states_stree(int id);
259 struct stree *__get_cur_stree(void);
260 int is_reachable(void);
262 /* smatch_helper.c */
263 char *alloc_string(const char *str);
264 void free_string(char *str);
265 void append(char *dest, const char *data, int buff_len);
266 void remove_parens(char *str);
267 struct smatch_state *alloc_state_num(int num);
268 struct expression *get_argument_from_call_expr(struct expression_list *args,
269 int num);
271 char *expr_to_var(struct expression *expr);
272 struct symbol *expr_to_sym(struct expression *expr);
273 char *expr_to_str(struct expression *expr);
274 char *expr_to_str_sym(struct expression *expr,
275 struct symbol **sym_ptr);
276 char *expr_to_var_sym(struct expression *expr,
277 struct symbol **sym_ptr);
279 int sym_name_is(const char *name, struct expression *expr);
280 int get_const_value(struct expression *expr, sval_t *sval);
281 int get_value(struct expression *expr, sval_t *val);
282 int get_implied_value(struct expression *expr, sval_t *val);
283 int get_implied_min(struct expression *expr, sval_t *sval);
284 int get_implied_max(struct expression *expr, sval_t *val);
285 int get_hard_max(struct expression *expr, sval_t *sval);
286 int get_fuzzy_min(struct expression *expr, sval_t *min);
287 int get_fuzzy_max(struct expression *expr, sval_t *max);
288 int get_absolute_min(struct expression *expr, sval_t *sval);
289 int get_absolute_max(struct expression *expr, sval_t *sval);
290 int parse_call_math(struct expression *expr, char *math, sval_t *val);
291 int parse_call_math_rl(struct expression *call, char *math, struct range_list **rl);
292 char *get_value_in_terms_of_parameter_math(struct expression *expr);
293 char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
294 int is_zero(struct expression *expr);
295 int known_condition_true(struct expression *expr);
296 int known_condition_false(struct expression *expr);
297 int implied_condition_true(struct expression *expr);
298 int implied_condition_false(struct expression *expr);
299 int can_integer_overflow(struct symbol *type, struct expression *expr);
301 int is_array(struct expression *expr);
302 struct expression *get_array_base(struct expression *expr);
303 struct expression *get_array_offset(struct expression *expr);
304 const char *show_state(struct smatch_state *state);
305 struct statement *get_expression_statement(struct expression *expr);
306 struct expression *strip_parens(struct expression *expr);
307 struct expression *strip_expr(struct expression *expr);
308 void scoped_state(int my_id, const char *name, struct symbol *sym);
309 int is_error_return(struct expression *expr);
310 int getting_address(void);
311 char *get_member_name(struct expression *expr);
312 char *get_fnptr_name(struct expression *expr);
313 int cmp_pos(struct position pos1, struct position pos2);
314 int positions_eq(struct position pos1, struct position pos2);
315 struct statement *get_current_statement(void);
316 struct statement *get_prev_statement(void);
317 int get_param_num_from_sym(struct symbol *sym);
318 int get_param_num(struct expression *expr);
319 int ms_since(struct timeval *start);
320 int parent_is_gone_var_sym(const char *name, struct symbol *sym);
321 int parent_is_gone(struct expression *expr);
322 int invert_op(int op);
324 /* smatch_type.c */
325 struct symbol *get_real_base_type(struct symbol *sym);
326 int type_bits(struct symbol *type);
327 int type_bytes(struct symbol *type);
328 int type_positive_bits(struct symbol *type);
329 struct symbol *get_pointer_type(struct expression *expr);
330 struct symbol *get_type(struct expression *expr);
331 int type_unsigned(struct symbol *base_type);
332 int type_signed(struct symbol *base_type);
333 int expr_unsigned(struct expression *expr);
334 int returns_unsigned(struct symbol *base_type);
335 int is_pointer(struct expression *expr);
336 int returns_pointer(struct symbol *base_type);
337 sval_t sval_type_max(struct symbol *base_type);
338 sval_t sval_type_min(struct symbol *base_type);
339 int nr_bits(struct expression *expr);
340 int is_void_pointer(struct expression *expr);
341 int is_char_pointer(struct expression *expr);
342 int is_string(struct expression *expr);
343 int is_static(struct expression *expr);
344 int types_equiv(struct symbol *one, struct symbol *two);
345 int fn_static(void);
346 const char *global_static();
347 struct symbol *cur_func_return_type(void);
348 struct symbol *get_arg_type(struct expression *fn, int arg);
349 struct symbol *get_member_type_from_key(struct expression *expr, char *key);
350 int is_struct(struct expression *expr);
351 char *type_to_str(struct symbol *type);
353 /* smatch_ignore.c */
354 void add_ignore(int owner, const char *name, struct symbol *sym);
355 int is_ignored(int owner, const char *name, struct symbol *sym);
357 /* smatch_var_sym */
358 struct var_sym *alloc_var_sym(const char *var, struct symbol *sym);
359 struct var_sym_list *expr_to_vsl(struct expression *expr);
360 void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
361 void add_var_sym_expr(struct var_sym_list **list, struct expression *expr);
362 void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
363 int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym);
364 struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl);
365 void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src);
366 struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two);
367 void free_var_sym_list(struct var_sym_list **list);
368 void free_var_syms_and_list(struct var_sym_list **list);
370 /* smatch_tracker */
371 struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym);
372 void add_tracker(struct tracker_list **list, int owner, const char *name,
373 struct symbol *sym);
374 void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr);
375 void del_tracker(struct tracker_list **list, int owner, const char *name,
376 struct symbol *sym);
377 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
378 struct symbol *sym);
379 void free_tracker_list(struct tracker_list **list);
380 void free_trackers_and_list(struct tracker_list **list);
382 /* smatch_conditions */
383 int in_condition(void);
385 /* smatch_flow.c */
387 extern int __in_fake_assign;
388 void smatch (int argc, char **argv);
389 int inside_loop(void);
390 int definitely_inside_loop(void);
391 struct expression *get_switch_expr(void);
392 int in_expression_statement(void);
393 void __process_post_op_stack(void);
394 void __split_expr(struct expression *expr);
395 void __split_stmt(struct statement *stmt);
396 extern int __in_function_def;
397 extern int option_assume_loops;
398 extern int option_known_conditions;
399 extern int option_two_passes;
400 extern int option_no_db;
401 extern int option_file_output;
402 extern int option_time;
403 extern struct expression_list *big_expression_stack;
404 extern struct statement_list *big_statement_stack;
405 int is_assigned_call(struct expression *expr);
406 int inlinable(struct expression *expr);
407 extern int __inline_call;
408 extern struct expression *__inline_fn;
409 extern int __in_pre_condition;
410 extern int __bail_on_rest_of_function;
412 /* smatch_struct_assignment.c */
413 struct expression *get_faked_expression(void);
414 void __fake_struct_member_assignments(struct expression *expr);
416 /* smatch_project.c */
417 int is_no_inline_function(const char *function);
419 /* smatch_conditions */
420 void __split_whole_condition(struct expression *expr);
421 void __handle_logic(struct expression *expr);
422 int is_condition(struct expression *expr);
423 int __handle_condition_assigns(struct expression *expr);
424 int __handle_select_assigns(struct expression *expr);
425 int __handle_expr_statement_assigns(struct expression *expr);
427 /* smatch_implied.c */
428 extern int option_debug_implied;
429 extern int option_debug_related;
430 extern int option_no_implied;
431 struct range_list_stack;
432 struct stree *__implied_case_stree(struct expression *switch_expr,
433 struct expression *case_expr,
434 struct range_list_stack **remaining_cases,
435 struct stree **raw_stree);
436 struct range_list *__get_implied_values(struct expression *switch_expr);
437 void overwrite_states_using_pool(struct sm_state *sm);
439 /* smatch_extras.c */
440 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
442 struct data_range {
443 sval_t min;
444 sval_t max;
447 extern long long valid_ptr_min, valid_ptr_max;
448 extern sval_t valid_ptr_min_sval, valid_ptr_max_sval;
449 static const sval_t array_min_sval = {
450 .type = &ptr_ctype,
451 {.value = 100000},
453 static const sval_t array_max_sval = {
454 .type = &ptr_ctype,
455 {.value = 200000},
457 #define STRLEN_MAX_RET 1010101
459 /* smatch_absolute.c */
460 int get_absolute_min_helper(struct expression *expr, sval_t *sval);
461 int get_absolute_max_helper(struct expression *expr, sval_t *sval);
463 /* smatch_local_values.c */
464 int get_local_rl(struct expression *expr, struct range_list **rl);
465 int get_local_max_helper(struct expression *expr, sval_t *sval);
466 int get_local_min_helper(struct expression *expr, sval_t *sval);
468 /* smatch_type_value.c */
469 int get_db_type_rl(struct expression *expr, struct range_list **rl);
471 /* smatch_states.c */
472 void __swap_cur_stree(struct stree *stree);
473 void __push_fake_cur_stree();
474 struct stree *__pop_fake_cur_stree();
475 void __free_fake_cur_stree();
476 void __set_fake_cur_stree_fast(struct stree *stree);
477 void __pop_fake_cur_stree_fast(void);
478 void __merge_stree_into_cur(struct stree *stree);
480 int unreachable(void);
481 void __set_sm(struct sm_state *sm);
482 void __set_true_false_sm(struct sm_state *true_state,
483 struct sm_state *false_state);
484 void nullify_path(void);
485 void __match_nullify_path_hook(const char *fn, struct expression *expr,
486 void *unused);
487 void __unnullify_path(void);
488 int __path_is_null(void);
489 void save_all_states(void);
490 void restore_all_states(void);
491 void free_goto_stack(void);
492 void clear_all_states(void);
494 struct sm_state *get_sm_state(int owner, const char *name,
495 struct symbol *sym);
496 struct sm_state *get_sm_state_expr(int owner, struct expression *expr);
497 void __push_true_states(void);
498 void __use_false_states(void);
499 void __discard_false_states(void);
500 void __merge_false_states(void);
501 void __merge_true_states(void);
503 void __negate_cond_stacks(void);
504 void __use_pre_cond_states(void);
505 void __use_cond_true_states(void);
506 void __use_cond_false_states(void);
507 void __push_cond_stacks(void);
508 struct stree *__copy_cond_true_states(void);
509 struct stree *__copy_cond_false_states(void);
510 struct stree *__pop_cond_true_stack(void);
511 struct stree *__pop_cond_false_stack(void);
512 void __and_cond_states(void);
513 void __or_cond_states(void);
514 void __save_pre_cond_states(void);
515 void __discard_pre_cond_states(void);
516 void __use_cond_states(void);
517 extern struct state_list *__last_base_slist;
519 void __warn_on_silly_pre_loops(void);
521 void __push_continues(void);
522 void __discard_continues(void);
523 void __process_continues(void);
524 void __merge_continues(void);
526 void __push_breaks(void);
527 void __process_breaks(void);
528 int __has_breaks(void);
529 void __merge_breaks(void);
530 void __use_breaks(void);
532 void __save_switch_states(struct expression *switch_expr);
533 void __discard_switches(void);
534 void __merge_switches(struct expression *switch_expr, struct expression *case_expr);
535 void __push_default(void);
536 void __set_default(void);
537 int __pop_default(void);
539 void __push_conditions(void);
540 void __discard_conditions(void);
542 void __save_gotos(const char *name);
543 void __merge_gotos(const char *name);
545 void __print_cur_stree(void);
547 /* smatch_hooks.c */
548 void __pass_to_client(void *data, enum hook_type type);
549 void __pass_to_client_no_data(enum hook_type type);
550 void __pass_case_to_client(struct expression *switch_expr,
551 struct expression *case_expr);
552 int __has_merge_function(int client_id);
553 struct smatch_state *__client_merge_function(int owner,
554 struct smatch_state *s1,
555 struct smatch_state *s2);
556 struct smatch_state *__client_unmatched_state_function(struct sm_state *sm);
557 void call_pre_merge_hook(struct sm_state *sm);
558 void __push_scope_hooks(void);
559 void __call_scope_hooks(void);
561 /* smatch_function_hooks.c */
562 void create_function_hook_hash(void);
563 void __match_initializer_call(struct symbol *sym);
565 /* smatch_db.c */
566 enum info_type {
567 INTERNAL = 0,
569 * Changing these numbers is a pain. Don't do it. If you ever use a
570 * number it can't be re-used right away so there may be gaps.
571 * We select these in order by type so if the order matters, then give
572 * it a number below 100-999,9000-9999 ranges. */
574 PARAM_CLEARED = 101,
575 FILTER_VALUE = 102,
577 PARAM_VALUE = 1001,
578 BUF_SIZE = 1002,
579 USER_DATA = 1003,
580 CAPPED_DATA = 1004,
581 RETURN_VALUE = 1005,
582 DEREFERENCE = 1006,
583 RANGE_CAP = 1007,
584 LOCK_HELD = 1008,
585 LOCK_RELEASED = 1009,
586 ABSOLUTE_LIMITS = 1010,
587 LIMITED_VALUE = 1011,
588 ADDED_VALUE = 1012,
589 PARAM_FREED = 1013,
590 DATA_SOURCE = 1014,
591 FUZZY_MAX = 1015,
592 STR_LEN = 1016,
593 ARRAY_LEN = 1017,
594 CAPABLE = 1018,
595 NS_CAPABLE = 1019,
596 TYPE_LINK = 1022,
597 UNTRACKED_PARAM = 1023,
598 CULL_PATH = 1024,
599 PARAM_SET = 1025,
601 /* put random temporary stuff in the 7000-7999 range for testing */
602 USER_DATA3 = 8017,
603 USER_DATA_SET = 9018,
604 USER_DATA_LIMITED = 9019,
607 void debug_sql(const char *sql);
608 void debug_mem_sql(const char *sql);
609 void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
610 void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm));
611 void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
612 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));
613 void select_call_implies_hook(int type, void (*callback)(struct expression *arg, char *key, char *value));
614 struct range_list *db_return_vals(struct expression *expr);
615 char *return_state_to_var_sym(struct expression *expr, int param, char *key, struct symbol **sym);
616 char *get_variable_from_key(struct expression *arg, char *key, struct symbol **sym);
617 const char *get_param_name(struct sm_state *sm);
618 char *get_data_info_name(struct expression *expr);
620 #define run_sql(call_back, data, sql...) \
621 do { \
622 char sql_txt[1024]; \
623 if (option_no_db) \
624 break; \
625 snprintf(sql_txt, 1024, sql); \
626 debug_sql(sql_txt); \
627 sql_exec(call_back, data, sql_txt); \
628 } while (0)
630 /* like run_sql() but for the in-memory database */
631 #define mem_sql(call_back, data, sql...) \
632 do { \
633 char sql_txt[1024]; \
635 snprintf(sql_txt, sizeof(sql_txt), sql); \
636 sm_debug("in-mem: %s\n", sql_txt); \
637 debug_mem_sql(sql_txt); \
638 sql_mem_exec(call_back, data, sql_txt); \
639 } while (0)
641 void sql_insert_return_states(int return_id, const char *return_ranges,
642 int type, int param, const char *key, const char *value);
643 void sql_insert_caller_info(struct expression *call, int type, int param,
644 const char *key, const char *value);
645 void sql_insert_function_ptr(const char *fn, const char *struct_name);
646 void sql_insert_return_values(const char *return_values);
647 void sql_insert_call_implies(int type, int param, const char *key, const char *value);
648 void sql_insert_function_type_size(const char *member, const char *ranges);
649 void sql_insert_local_values(const char *name, const char *value);
650 void sql_insert_function_type_value(const char *type, const char *value);
651 void sql_insert_function_type_info(int param, const char *value);
652 void sql_insert_data_info(struct expression *data, int type, const char *value);
654 void sql_select_return_states(const char *cols, struct expression *call,
655 int (*callback)(void*, int, char**, char**), void *info);
656 void sql_select_caller_info(const char *cols, struct symbol *sym,
657 int (*callback)(void*, int, char**, char**));
658 void sql_select_call_implies(const char *cols, struct expression *call,
659 int (*callback)(void*, int, char**, char**));
661 void sql_exec(int (*callback)(void*, int, char**, char**), void *data, const char *sql);
662 void sql_mem_exec(int (*callback)(void*, int, char**, char**), void *data, const char *sql);
664 void open_smatch_db(void);
666 /* smatch_files.c */
667 int open_data_file(const char *filename);
668 struct token *get_tokens_file(const char *filename);
670 /* smatch.c */
671 extern char *option_debug_check;
672 extern char *option_project_str;
673 extern char *data_dir;
674 extern int option_no_data;
675 extern int option_spammy;
676 extern int option_full_path;
677 extern int option_param_mapper;
678 extern int option_call_tree;
679 extern int num_checks;
681 enum project_type {
682 PROJ_NONE,
683 PROJ_KERNEL,
684 PROJ_WINE,
686 extern enum project_type option_project;
687 const char *check_name(unsigned short id);
690 /* smatch_buf_size.c */
691 int get_array_size(struct expression *expr);
692 int get_array_size_bytes(struct expression *expr);
693 int get_array_size_bytes_min(struct expression *expr);
694 int get_array_size_bytes_max(struct expression *expr);
695 struct range_list *get_array_size_bytes_rl(struct expression *expr);
696 int get_real_array_size(struct expression *expr);
697 /* smatch_strlen.c */
698 int get_implied_strlen(struct expression *expr, struct range_list **rl);
699 int get_size_from_strlen(struct expression *expr);
701 /* smatch_capped.c */
702 int is_capped(struct expression *expr);
703 int is_capped_var_sym(const char *name, struct symbol *sym);
705 /* check_user_data.c */
706 int is_user_macro(struct expression *expr);
707 int is_user_data(struct expression *expr);
708 int is_capped_user_data(struct expression *expr);
709 int implied_user_data(struct expression *expr, struct range_list **rl);
710 int get_user_rl(struct expression *expr, struct range_list **rl);
712 /* check_locking.c */
713 void print_held_locks();
715 /* check_assigned_expr.c */
716 struct expression *get_assigned_expr(struct expression *expr);
717 struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym);
719 /* smatch_comparison.c */
720 struct compare_data {
721 const char *var1;
722 struct var_sym_list *vsl1;
723 int comparison;
724 const char *var2;
725 struct var_sym_list *vsl2;
727 int get_comparison(struct expression *left, struct expression *right);
728 int get_comparison_strings(const char *one, const char *two);
729 int possible_comparison(struct expression *a, int comparison, struct expression *b);
730 struct state_list *get_all_comparisons(struct expression *expr);
731 struct state_list *get_all_possible_equal_comparisons(struct expression *expr);
732 void __add_comparison_info(struct expression *expr, struct expression *call, const char *range);
733 char *expr_equal_to_param(struct expression *expr, int ignore);
734 char *expr_lte_to_param(struct expression *expr, int ignore);
735 char *expr_param_comparison(struct expression *expr, int ignore);
736 int flip_comparison(int op);
737 int negate_comparison(int op);
738 void filter_by_comparison(struct range_list **rl, int comparison, struct range_list *right);
740 /* smatch_sval.c */
741 sval_t *sval_alloc(sval_t sval);
742 sval_t *sval_alloc_permanent(sval_t sval);
743 sval_t sval_blank(struct expression *expr);
744 sval_t sval_type_val(struct symbol *type, long long val);
745 sval_t sval_from_val(struct expression *expr, long long val);
746 int sval_unsigned(sval_t sval);
747 int sval_signed(sval_t sval);
748 int sval_bits(sval_t sval);
749 int sval_positive_bits(sval_t sval);
750 int sval_bits_used(sval_t sval);
751 int sval_is_negative(sval_t sval);
752 int sval_is_positive(sval_t sval);
753 int sval_is_min(sval_t sval);
754 int sval_is_max(sval_t sval);
755 int sval_is_a_min(sval_t sval);
756 int sval_is_a_max(sval_t sval);
757 int sval_is_negative_min(sval_t sval);
758 int sval_cmp(sval_t one, sval_t two);
759 int sval_cmp_t(struct symbol *type, sval_t one, sval_t two);
760 int sval_cmp_val(sval_t one, long long val);
761 sval_t sval_min(sval_t one, sval_t two);
762 sval_t sval_max(sval_t one, sval_t two);
763 int sval_too_low(struct symbol *type, sval_t sval);
764 int sval_too_high(struct symbol *type, sval_t sval);
765 int sval_fits(struct symbol *type, sval_t sval);
766 sval_t sval_cast(struct symbol *type, sval_t sval);
767 sval_t sval_preop(sval_t sval, int op);
768 sval_t sval_binop(sval_t left, int op, sval_t right);
769 int sval_binop_overflows(sval_t left, int op, sval_t right);
770 const char *sval_to_str(sval_t sval);
771 const char *sval_to_numstr(sval_t sval);
772 sval_t ll_to_sval(long long val);
774 /* smatch_string_list.c */
775 int list_has_string(struct string_list *str_list, char *str);
776 void insert_string(struct string_list **str_list, char *str);
777 struct string_list *clone_str_list(struct string_list *orig);
778 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two);
780 /* smatch_start_states.c */
781 struct stree *get_start_states(void);
783 /* smatch_recurse.c */
784 int has_symbol(struct expression *expr, struct symbol *sym);
785 int has_variable(struct expression *expr, struct expression *var);
786 int has_inc_dec(struct expression *expr);
788 /* smatch_stored_conditions.c */
789 struct smatch_state *get_stored_condition(struct expression *expr);
791 /* check_string_len.c */
792 int get_formatted_string_size(struct expression *call, int arg);
794 /* smatch_param_set.c */
795 int param_was_set(struct expression *expr);
796 /* smatch_param_filter.c */
797 int param_has_filter_data(struct sm_state *sm);
799 /* smatch_links.c */
800 void set_up_link_functions(int id, int linkid);
801 void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym);
803 /* smatch_auto_copy.c */
804 void set_auto_copy(int owner);
806 /* check_buf_comparison */
807 struct expression *get_size_variable(struct expression *buf);
809 /* smatch_untracked_param.c */
810 void add_untracked_param_hook(void (func)(struct expression *call, int param));
812 /* smatch_impossible.c */
813 int is_impossible_path(void);
815 #endif /* !SMATCH_H_ */