user_data2: add skb_network_header()
[smatch.git] / smatch.h
blob68daa2874dd73252219d5a82e4d539ad50b678f5
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);
69 DECLARE_PTR_LIST(stree_stack, struct stree);
71 /* The first 3 struct members must match struct tracker */
72 struct sm_state {
73 const char *name;
74 struct symbol *sym;
75 unsigned short owner;
76 unsigned short merged:1;
77 unsigned short implied:1;
78 unsigned int nr_children;
79 unsigned int line;
80 struct smatch_state *state;
81 struct stree *pool;
82 struct sm_state *left;
83 struct sm_state *right;
84 struct state_list *possible;
87 struct var_sym {
88 char *var;
89 struct symbol *sym;
91 DECLARE_ALLOCATOR(var_sym);
92 DECLARE_PTR_LIST(var_sym_list, struct var_sym);
94 enum hook_type {
95 EXPR_HOOK,
96 STMT_HOOK,
97 STMT_HOOK_AFTER,
98 SYM_HOOK,
99 STRING_HOOK,
100 DECLARATION_HOOK,
101 ASSIGNMENT_HOOK,
102 RAW_ASSIGNMENT_HOOK,
103 GLOBAL_ASSIGNMENT_HOOK,
104 LOGIC_HOOK,
105 CONDITION_HOOK,
106 PRELOOP_HOOK,
107 SELECT_HOOK,
108 WHOLE_CONDITION_HOOK,
109 FUNCTION_CALL_HOOK,
110 CALL_HOOK_AFTER_INLINE,
111 FUNCTION_CALL_HOOK_AFTER,
112 CALL_ASSIGNMENT_HOOK,
113 MACRO_ASSIGNMENT_HOOK,
114 BINOP_HOOK,
115 OP_HOOK,
116 DEREF_HOOK,
117 CASE_HOOK,
118 ASM_HOOK,
119 CAST_HOOK,
120 SIZEOF_HOOK,
121 BASE_HOOK,
122 FUNC_DEF_HOOK,
123 AFTER_DEF_HOOK,
124 END_FUNC_HOOK,
125 AFTER_FUNC_HOOK,
126 RETURN_HOOK,
127 INLINE_FN_START,
128 INLINE_FN_END,
129 END_FILE_HOOK,
132 #define TRUE 1
133 #define FALSE 0
135 struct range_list;
137 void add_hook(void *func, enum hook_type type);
138 typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2);
139 typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state);
140 void add_merge_hook(int client_id, merge_func_t *func);
141 void add_unmatched_state_hook(int client_id, unmatched_func_t *func);
142 void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *sm));
143 typedef void (scope_hook)(void *data);
144 void add_scope_hook(scope_hook *hook, void *data);
145 typedef void (func_hook)(const char *fn, struct expression *expr, void *data);
146 typedef void (implication_hook)(const char *fn, struct expression *call_expr,
147 struct expression *assign_expr, void *data);
148 typedef void (return_implies_hook)(struct expression *call_expr,
149 int param, char *key, char *value);
150 typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl);
151 void add_function_hook(const char *look_for, func_hook *call_back, void *data);
153 void add_function_assign_hook(const char *look_for, func_hook *call_back,
154 void *info);
155 void add_implied_return_hook(const char *look_for,
156 implied_return_hook *call_back,
157 void *info);
158 void add_macro_assign_hook(const char *look_for, func_hook *call_back,
159 void *info);
160 void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
161 void *info);
162 void return_implies_state(const char *look_for, long long start, long long end,
163 implication_hook *call_back, void *info);
164 void select_return_states_hook(int type, return_implies_hook *callback);
165 void select_return_states_before(void (*fn)(void));
166 void select_return_states_after(void (*fn)(void));
167 int get_implied_return(struct expression *expr, struct range_list **rl);
168 void allocate_hook_memory(void);
170 typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr);
171 void add_modification_hook(int owner, modification_hook *call_back);
172 void add_indirect_modification_hook(int owner, modification_hook *call_back);
174 int outside_of_function(void);
175 const char *get_filename(void);
176 const char *get_base_file(void);
177 char *get_function(void);
178 int get_lineno(void);
179 extern int final_pass;
180 extern struct symbol *cur_func_sym;
181 extern int option_debug;
182 extern int local_debug;
183 extern int option_info;
184 extern char *trace_variable;
185 extern struct stree *global_states;
186 int is_silenced_function(void);
188 extern FILE *sm_outfd;
189 #define sm_printf(msg...) do { if (final_pass || option_debug) fprintf(sm_outfd, msg); } while (0)
191 static inline void sm_prefix(void)
193 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
196 static inline void print_implied_debug_msg();
198 #define sm_msg(msg...) \
199 do { \
200 print_implied_debug_msg(); \
201 if (!option_debug && !final_pass) \
202 break; \
203 if (!option_info && is_silenced_function()) \
204 break; \
205 sm_prefix(); \
206 sm_printf(msg); \
207 sm_printf("\n"); \
208 } while (0)
210 #define local_debug(msg...) \
211 do { \
212 if (local_debug) \
213 sm_msg(msg); \
214 } while (0)
216 extern char *implied_debug_msg;
217 static inline void print_implied_debug_msg(void)
219 static struct symbol *last_printed = NULL;
221 if (!implied_debug_msg)
222 return;
223 if (last_printed == cur_func_sym)
224 return;
225 last_printed = cur_func_sym;
226 sm_msg("%s", implied_debug_msg);
229 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
231 #define sm_info(msg...) do { \
232 if (option_debug || (option_info && final_pass)) { \
233 sm_prefix(); \
234 sm_printf("info: "); \
235 sm_printf(msg); \
236 sm_printf("\n"); \
238 } while(0)
240 struct smatch_state *get_state(int owner, const char *name, struct symbol *sym);
241 struct smatch_state *get_state_expr(int owner, struct expression *expr);
242 struct state_list *get_possible_states(int owner, const char *name,
243 struct symbol *sym);
244 struct state_list *get_possible_states_expr(int owner, struct expression *expr);
245 struct sm_state *set_state(int owner, const char *name, struct symbol *sym,
246 struct smatch_state *state);
247 struct sm_state *set_state_expr(int owner, struct expression *expr,
248 struct smatch_state *state);
249 void delete_state(int owner, const char *name, struct symbol *sym);
250 void delete_state_expr(int owner, struct expression *expr);
251 void set_true_false_states(int owner, const char *name, struct symbol *sym,
252 struct smatch_state *true_state,
253 struct smatch_state *false_state);
254 void set_true_false_states_expr(int owner, struct expression *expr,
255 struct smatch_state *true_state,
256 struct smatch_state *false_state);
258 struct stree *get_all_states_from_stree(int owner, struct stree *source);
259 struct stree *get_all_states_stree(int id);
260 struct stree *__get_cur_stree(void);
261 int is_reachable(void);
263 /* smatch_helper.c */
264 char *alloc_string(const char *str);
265 void free_string(char *str);
266 void append(char *dest, const char *data, int buff_len);
267 void remove_parens(char *str);
268 struct smatch_state *alloc_state_num(int num);
269 struct smatch_state *alloc_state_str(const char *name);
270 struct expression *get_argument_from_call_expr(struct expression_list *args,
271 int num);
273 char *expr_to_var(struct expression *expr);
274 struct symbol *expr_to_sym(struct expression *expr);
275 char *expr_to_str(struct expression *expr);
276 char *expr_to_str_sym(struct expression *expr,
277 struct symbol **sym_ptr);
278 char *expr_to_var_sym(struct expression *expr,
279 struct symbol **sym_ptr);
281 int sym_name_is(const char *name, struct expression *expr);
282 int get_const_value(struct expression *expr, sval_t *sval);
283 int get_value(struct expression *expr, sval_t *val);
284 int get_implied_value(struct expression *expr, sval_t *val);
285 int get_implied_min(struct expression *expr, sval_t *sval);
286 int get_implied_max(struct expression *expr, sval_t *val);
287 int get_hard_max(struct expression *expr, sval_t *sval);
288 int get_fuzzy_min(struct expression *expr, sval_t *min);
289 int get_fuzzy_max(struct expression *expr, sval_t *max);
290 int get_absolute_min(struct expression *expr, sval_t *sval);
291 int get_absolute_max(struct expression *expr, sval_t *sval);
292 int parse_call_math(struct expression *expr, char *math, sval_t *val);
293 int parse_call_math_rl(struct expression *call, char *math, struct range_list **rl);
294 char *get_value_in_terms_of_parameter_math(struct expression *expr);
295 char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
296 int is_zero(struct expression *expr);
297 int known_condition_true(struct expression *expr);
298 int known_condition_false(struct expression *expr);
299 int implied_condition_true(struct expression *expr);
300 int implied_condition_false(struct expression *expr);
301 int can_integer_overflow(struct symbol *type, struct expression *expr);
303 int is_array(struct expression *expr);
304 struct expression *get_array_base(struct expression *expr);
305 struct expression *get_array_offset(struct expression *expr);
306 const char *show_state(struct smatch_state *state);
307 struct statement *get_expression_statement(struct expression *expr);
308 struct expression *strip_parens(struct expression *expr);
309 struct expression *strip_expr(struct expression *expr);
310 void scoped_state(int my_id, const char *name, struct symbol *sym);
311 int is_error_return(struct expression *expr);
312 int getting_address(void);
313 char *get_member_name(struct expression *expr);
314 char *get_fnptr_name(struct expression *expr);
315 int cmp_pos(struct position pos1, struct position pos2);
316 int positions_eq(struct position pos1, struct position pos2);
317 struct statement *get_current_statement(void);
318 struct statement *get_prev_statement(void);
319 int get_param_num_from_sym(struct symbol *sym);
320 int get_param_num(struct expression *expr);
321 int ms_since(struct timeval *start);
322 int parent_is_gone_var_sym(const char *name, struct symbol *sym);
323 int parent_is_gone(struct expression *expr);
324 int invert_op(int op);
326 /* smatch_type.c */
327 struct symbol *get_real_base_type(struct symbol *sym);
328 int type_bits(struct symbol *type);
329 int type_bytes(struct symbol *type);
330 int type_positive_bits(struct symbol *type);
331 struct symbol *get_pointer_type(struct expression *expr);
332 struct symbol *get_type(struct expression *expr);
333 int type_unsigned(struct symbol *base_type);
334 int type_signed(struct symbol *base_type);
335 int expr_unsigned(struct expression *expr);
336 int expr_signed(struct expression *expr);
337 int returns_unsigned(struct symbol *base_type);
338 int is_pointer(struct expression *expr);
339 int returns_pointer(struct symbol *base_type);
340 sval_t sval_type_max(struct symbol *base_type);
341 sval_t sval_type_min(struct symbol *base_type);
342 int nr_bits(struct expression *expr);
343 int is_void_pointer(struct expression *expr);
344 int is_char_pointer(struct expression *expr);
345 int is_string(struct expression *expr);
346 int is_static(struct expression *expr);
347 int types_equiv(struct symbol *one, struct symbol *two);
348 int fn_static(void);
349 const char *global_static();
350 struct symbol *cur_func_return_type(void);
351 struct symbol *get_arg_type(struct expression *fn, int arg);
352 struct symbol *get_member_type_from_key(struct expression *expr, char *key);
353 int is_struct(struct expression *expr);
354 char *type_to_str(struct symbol *type);
356 /* smatch_ignore.c */
357 void add_ignore(int owner, const char *name, struct symbol *sym);
358 int is_ignored(int owner, const char *name, struct symbol *sym);
360 /* smatch_var_sym */
361 struct var_sym *alloc_var_sym(const char *var, struct symbol *sym);
362 struct var_sym_list *expr_to_vsl(struct expression *expr);
363 void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
364 void add_var_sym_expr(struct var_sym_list **list, struct expression *expr);
365 void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
366 int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym);
367 struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl);
368 void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src);
369 struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two);
370 void free_var_sym_list(struct var_sym_list **list);
371 void free_var_syms_and_list(struct var_sym_list **list);
373 /* smatch_tracker */
374 struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym);
375 void add_tracker(struct tracker_list **list, int owner, const char *name,
376 struct symbol *sym);
377 void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr);
378 void del_tracker(struct tracker_list **list, int owner, const char *name,
379 struct symbol *sym);
380 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
381 struct symbol *sym);
382 void free_tracker_list(struct tracker_list **list);
383 void free_trackers_and_list(struct tracker_list **list);
385 /* smatch_conditions */
386 int in_condition(void);
388 /* smatch_flow.c */
390 extern int __in_fake_assign;
391 void smatch (int argc, char **argv);
392 int inside_loop(void);
393 int definitely_inside_loop(void);
394 struct expression *get_switch_expr(void);
395 int in_expression_statement(void);
396 void __process_post_op_stack(void);
397 void __split_expr(struct expression *expr);
398 void __split_stmt(struct statement *stmt);
399 extern int __in_function_def;
400 extern int option_assume_loops;
401 extern int option_known_conditions;
402 extern int option_two_passes;
403 extern int option_no_db;
404 extern int option_file_output;
405 extern int option_time;
406 extern struct expression_list *big_expression_stack;
407 extern struct statement_list *big_statement_stack;
408 int is_assigned_call(struct expression *expr);
409 int inlinable(struct expression *expr);
410 extern int __inline_call;
411 extern struct expression *__inline_fn;
412 extern int __in_pre_condition;
413 extern int __bail_on_rest_of_function;
414 extern struct statement *__prev_stmt;
415 extern struct statement *__cur_stmt;
416 extern struct statement *__next_stmt;
418 /* smatch_struct_assignment.c */
419 struct expression *get_faked_expression(void);
420 void __fake_struct_member_assignments(struct expression *expr);
422 /* smatch_project.c */
423 int is_no_inline_function(const char *function);
425 /* smatch_conditions */
426 void __split_whole_condition(struct expression *expr);
427 void __handle_logic(struct expression *expr);
428 int is_condition(struct expression *expr);
429 int __handle_condition_assigns(struct expression *expr);
430 int __handle_select_assigns(struct expression *expr);
431 int __handle_expr_statement_assigns(struct expression *expr);
433 /* smatch_implied.c */
434 extern int option_debug_implied;
435 extern int option_debug_related;
436 extern int option_no_implied;
437 struct range_list_stack;
438 struct stree *__implied_case_stree(struct expression *switch_expr,
439 struct expression *case_expr,
440 struct range_list_stack **remaining_cases,
441 struct stree **raw_stree);
442 struct range_list *__get_implied_values(struct expression *switch_expr);
443 void overwrite_states_using_pool(struct sm_state *sm);
444 void add_pool(struct stree_stack **pools, struct stree *new);
446 /* smatch_extras.c */
447 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
449 struct data_range {
450 sval_t min;
451 sval_t max;
454 extern long long valid_ptr_min, valid_ptr_max;
455 extern sval_t valid_ptr_min_sval, valid_ptr_max_sval;
456 static const sval_t array_min_sval = {
457 .type = &ptr_ctype,
458 {.value = 100000},
460 static const sval_t array_max_sval = {
461 .type = &ptr_ctype,
462 {.value = 199999},
464 static const sval_t text_seg_min = {
465 .type = &ptr_ctype,
466 {.value = 100000000},
468 static const sval_t text_seg_max = {
469 .type = &ptr_ctype,
470 {.value = 177777777},
472 static const sval_t data_seg_min = {
473 .type = &ptr_ctype,
474 {.value = 200000000},
476 static const sval_t data_seg_max = {
477 .type = &ptr_ctype,
478 {.value = 277777777},
480 static const sval_t bss_seg_min = {
481 .type = &ptr_ctype,
482 {.value = 300000000},
484 static const sval_t bss_seg_max = {
485 .type = &ptr_ctype,
486 {.value = 377777777},
488 static const sval_t stack_seg_min = {
489 .type = &ptr_ctype,
490 {.value = 400000000},
492 static const sval_t stack_seg_max = {
493 .type = &ptr_ctype,
494 {.value = 477777777},
496 static const sval_t kmalloc_seg_min = {
497 .type = &ptr_ctype,
498 {.value = 500000000},
500 static const sval_t kmalloc_seg_max = {
501 .type = &ptr_ctype,
502 {.value = 577777777},
504 static const sval_t vmalloc_seg_min = {
505 .type = &ptr_ctype,
506 {.value = 600000000},
508 static const sval_t vmalloc_seg_max = {
509 .type = &ptr_ctype,
510 {.value = 677777777},
513 #define STRLEN_MAX_RET 1010101
515 /* smatch_absolute.c */
516 int get_absolute_min_helper(struct expression *expr, sval_t *sval);
517 int get_absolute_max_helper(struct expression *expr, sval_t *sval);
519 /* smatch_local_values.c */
520 int get_local_rl(struct expression *expr, struct range_list **rl);
521 int get_local_max_helper(struct expression *expr, sval_t *sval);
522 int get_local_min_helper(struct expression *expr, sval_t *sval);
524 /* smatch_type_value.c */
525 int get_db_type_rl(struct expression *expr, struct range_list **rl);
527 /* smatch_states.c */
528 void __swap_cur_stree(struct stree *stree);
529 void __push_fake_cur_stree();
530 struct stree *__pop_fake_cur_stree();
531 void __free_fake_cur_stree();
532 void __set_fake_cur_stree_fast(struct stree *stree);
533 void __pop_fake_cur_stree_fast(void);
534 void __merge_stree_into_cur(struct stree *stree);
536 int unreachable(void);
537 void __set_sm(struct sm_state *sm);
538 void __set_true_false_sm(struct sm_state *true_state,
539 struct sm_state *false_state);
540 void nullify_path(void);
541 void __match_nullify_path_hook(const char *fn, struct expression *expr,
542 void *unused);
543 void __unnullify_path(void);
544 int __path_is_null(void);
545 void save_all_states(void);
546 void restore_all_states(void);
547 void free_goto_stack(void);
548 void clear_all_states(void);
550 struct sm_state *get_sm_state(int owner, const char *name,
551 struct symbol *sym);
552 struct sm_state *get_sm_state_expr(int owner, struct expression *expr);
553 void __push_true_states(void);
554 void __use_false_states(void);
555 void __discard_false_states(void);
556 void __merge_false_states(void);
557 void __merge_true_states(void);
559 void __negate_cond_stacks(void);
560 void __use_pre_cond_states(void);
561 void __use_cond_true_states(void);
562 void __use_cond_false_states(void);
563 void __push_cond_stacks(void);
564 struct stree *__copy_cond_true_states(void);
565 struct stree *__copy_cond_false_states(void);
566 struct stree *__pop_cond_true_stack(void);
567 struct stree *__pop_cond_false_stack(void);
568 void __and_cond_states(void);
569 void __or_cond_states(void);
570 void __save_pre_cond_states(void);
571 void __discard_pre_cond_states(void);
572 void __use_cond_states(void);
573 extern struct state_list *__last_base_slist;
575 void __warn_on_silly_pre_loops(void);
577 void __push_continues(void);
578 void __discard_continues(void);
579 void __process_continues(void);
580 void __merge_continues(void);
582 void __push_breaks(void);
583 void __process_breaks(void);
584 int __has_breaks(void);
585 void __merge_breaks(void);
586 void __use_breaks(void);
588 void __save_switch_states(struct expression *switch_expr);
589 void __discard_switches(void);
590 void __merge_switches(struct expression *switch_expr, struct expression *case_expr);
591 void __push_default(void);
592 void __set_default(void);
593 int __pop_default(void);
595 void __push_conditions(void);
596 void __discard_conditions(void);
598 void __save_gotos(const char *name);
599 void __merge_gotos(const char *name);
601 void __print_cur_stree(void);
603 /* smatch_hooks.c */
604 void __pass_to_client(void *data, enum hook_type type);
605 void __pass_to_client_no_data(enum hook_type type);
606 void __pass_case_to_client(struct expression *switch_expr,
607 struct expression *case_expr);
608 int __has_merge_function(int client_id);
609 struct smatch_state *__client_merge_function(int owner,
610 struct smatch_state *s1,
611 struct smatch_state *s2);
612 struct smatch_state *__client_unmatched_state_function(struct sm_state *sm);
613 void call_pre_merge_hook(struct sm_state *sm);
614 void __push_scope_hooks(void);
615 void __call_scope_hooks(void);
617 /* smatch_function_hooks.c */
618 void create_function_hook_hash(void);
619 void __match_initializer_call(struct symbol *sym);
621 /* smatch_db.c */
622 enum info_type {
623 INTERNAL = 0,
625 * Changing these numbers is a pain. Don't do it. If you ever use a
626 * number it can't be re-used right away so there may be gaps.
627 * We select these in order by type so if the order matters, then give
628 * it a number below 100-999,9000-9999 ranges. */
630 PARAM_CLEARED = 101,
631 PARAM_LIMIT = 103,
632 PARAM_FILTER = 104,
634 PARAM_VALUE = 1001,
635 BUF_SIZE = 1002,
636 USER_DATA = 1003,
637 CAPPED_DATA = 1004,
638 RETURN_VALUE = 1005,
639 DEREFERENCE = 1006,
640 RANGE_CAP = 1007,
641 LOCK_HELD = 1008,
642 LOCK_RELEASED = 1009,
643 ABSOLUTE_LIMITS = 1010,
644 PARAM_ADD = 1012,
645 PARAM_FREED = 1013,
646 DATA_SOURCE = 1014,
647 FUZZY_MAX = 1015,
648 STR_LEN = 1016,
649 ARRAY_LEN = 1017,
650 CAPABLE = 1018,
651 NS_CAPABLE = 1019,
652 TYPE_LINK = 1022,
653 UNTRACKED_PARAM = 1023,
654 CULL_PATH = 1024,
655 PARAM_SET = 1025,
656 PARAM_USED = 1026,
658 /* put random temporary stuff in the 7000-7999 range for testing */
659 USER_DATA3 = 8017,
660 USER_DATA_SET = 9018,
661 USER_DATA_LIMITED = 9019,
664 void debug_sql(const char *sql);
665 void debug_mem_sql(const char *sql);
666 void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
667 void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm));
668 void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
669 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));
670 void select_call_implies_hook(int type, void (*callback)(struct expression *arg, char *key, char *value));
671 struct range_list *db_return_vals(struct expression *expr);
672 char *return_state_to_var_sym(struct expression *expr, int param, char *key, struct symbol **sym);
673 char *get_variable_from_key(struct expression *arg, char *key, struct symbol **sym);
674 const char *get_param_name(struct sm_state *sm);
675 char *get_data_info_name(struct expression *expr);
677 #define run_sql(call_back, data, sql...) \
678 do { \
679 char sql_txt[1024]; \
680 if (option_no_db) \
681 break; \
682 snprintf(sql_txt, 1024, sql); \
683 debug_sql(sql_txt); \
684 sql_exec(call_back, data, sql_txt); \
685 } while (0)
687 /* like run_sql() but for the in-memory database */
688 #define mem_sql(call_back, data, sql...) \
689 do { \
690 char sql_txt[1024]; \
692 snprintf(sql_txt, sizeof(sql_txt), sql); \
693 sm_debug("in-mem: %s\n", sql_txt); \
694 debug_mem_sql(sql_txt); \
695 sql_mem_exec(call_back, data, sql_txt); \
696 } while (0)
698 char *get_static_filter(struct symbol *sym);
700 void sql_insert_return_states(int return_id, const char *return_ranges,
701 int type, int param, const char *key, const char *value);
702 void sql_insert_caller_info(struct expression *call, int type, int param,
703 const char *key, const char *value);
704 void sql_insert_function_ptr(const char *fn, const char *struct_name);
705 void sql_insert_return_values(const char *return_values);
706 void sql_insert_call_implies(int type, int param, const char *key, const char *value);
707 void sql_insert_function_type_size(const char *member, const char *ranges);
708 void sql_insert_local_values(const char *name, const char *value);
709 void sql_insert_function_type_value(const char *type, const char *value);
710 void sql_insert_function_type_info(int param, const char *value);
711 void sql_insert_data_info(struct expression *data, int type, const char *value);
713 void sql_select_return_states(const char *cols, struct expression *call,
714 int (*callback)(void*, int, char**, char**), void *info);
715 void sql_select_caller_info(const char *cols, struct symbol *sym,
716 int (*callback)(void*, int, char**, char**));
717 void sql_select_call_implies(const char *cols, struct expression *call,
718 int (*callback)(void*, int, char**, char**));
720 void sql_exec(int (*callback)(void*, int, char**, char**), void *data, const char *sql);
721 void sql_mem_exec(int (*callback)(void*, int, char**, char**), void *data, const char *sql);
723 void open_smatch_db(void);
725 /* smatch_files.c */
726 int open_data_file(const char *filename);
727 struct token *get_tokens_file(const char *filename);
729 /* smatch.c */
730 extern char *option_debug_check;
731 extern char *option_project_str;
732 extern char *data_dir;
733 extern int option_no_data;
734 extern int option_spammy;
735 extern int option_full_path;
736 extern int option_param_mapper;
737 extern int option_call_tree;
738 extern int num_checks;
740 enum project_type {
741 PROJ_NONE,
742 PROJ_KERNEL,
743 PROJ_WINE,
745 extern enum project_type option_project;
746 const char *check_name(unsigned short id);
749 /* smatch_buf_size.c */
750 int get_array_size(struct expression *expr);
751 int get_array_size_bytes(struct expression *expr);
752 int get_array_size_bytes_min(struct expression *expr);
753 int get_array_size_bytes_max(struct expression *expr);
754 struct range_list *get_array_size_bytes_rl(struct expression *expr);
755 int get_real_array_size(struct expression *expr);
756 /* smatch_strlen.c */
757 int get_implied_strlen(struct expression *expr, struct range_list **rl);
758 int get_size_from_strlen(struct expression *expr);
760 /* smatch_capped.c */
761 int is_capped(struct expression *expr);
762 int is_capped_var_sym(const char *name, struct symbol *sym);
764 /* check_user_data.c */
765 int is_user_macro(struct expression *expr);
766 int is_user_data(struct expression *expr);
767 int is_capped_user_data(struct expression *expr);
768 int implied_user_data(struct expression *expr, struct range_list **rl);
769 int get_user_rl(struct expression *expr, struct range_list **rl);
771 /* check_locking.c */
772 void print_held_locks();
774 /* check_assigned_expr.c */
775 struct expression *get_assigned_expr(struct expression *expr);
776 struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym);
778 /* smatch_comparison.c */
779 struct compare_data {
780 const char *var1;
781 struct var_sym_list *vsl1;
782 int comparison;
783 const char *var2;
784 struct var_sym_list *vsl2;
786 int get_comparison(struct expression *left, struct expression *right);
787 int get_comparison_strings(const char *one, const char *two);
788 int possible_comparison(struct expression *a, int comparison, struct expression *b);
789 struct state_list *get_all_comparisons(struct expression *expr);
790 struct state_list *get_all_possible_equal_comparisons(struct expression *expr);
791 void __add_comparison_info(struct expression *expr, struct expression *call, const char *range);
792 char *expr_equal_to_param(struct expression *expr, int ignore);
793 char *expr_lte_to_param(struct expression *expr, int ignore);
794 char *expr_param_comparison(struct expression *expr, int ignore);
795 int flip_comparison(int op);
796 int negate_comparison(int op);
797 void filter_by_comparison(struct range_list **rl, int comparison, struct range_list *right);
798 struct sm_state *comparison_implication_hook(struct expression *expr,
799 struct stree_stack **true_stack,
800 struct stree_stack **false_stack);
802 /* smatch_sval.c */
803 sval_t *sval_alloc(sval_t sval);
804 sval_t *sval_alloc_permanent(sval_t sval);
805 sval_t sval_blank(struct expression *expr);
806 sval_t sval_type_val(struct symbol *type, long long val);
807 sval_t sval_from_val(struct expression *expr, long long val);
808 int sval_unsigned(sval_t sval);
809 int sval_signed(sval_t sval);
810 int sval_bits(sval_t sval);
811 int sval_positive_bits(sval_t sval);
812 int sval_bits_used(sval_t sval);
813 int sval_is_negative(sval_t sval);
814 int sval_is_positive(sval_t sval);
815 int sval_is_min(sval_t sval);
816 int sval_is_max(sval_t sval);
817 int sval_is_a_min(sval_t sval);
818 int sval_is_a_max(sval_t sval);
819 int sval_is_negative_min(sval_t sval);
820 int sval_cmp(sval_t one, sval_t two);
821 int sval_cmp_t(struct symbol *type, sval_t one, sval_t two);
822 int sval_cmp_val(sval_t one, long long val);
823 sval_t sval_min(sval_t one, sval_t two);
824 sval_t sval_max(sval_t one, sval_t two);
825 int sval_too_low(struct symbol *type, sval_t sval);
826 int sval_too_high(struct symbol *type, sval_t sval);
827 int sval_fits(struct symbol *type, sval_t sval);
828 sval_t sval_cast(struct symbol *type, sval_t sval);
829 sval_t sval_preop(sval_t sval, int op);
830 sval_t sval_binop(sval_t left, int op, sval_t right);
831 int sval_binop_overflows(sval_t left, int op, sval_t right);
832 const char *sval_to_str(sval_t sval);
833 const char *sval_to_numstr(sval_t sval);
834 sval_t ll_to_sval(long long val);
836 /* smatch_string_list.c */
837 int list_has_string(struct string_list *str_list, char *str);
838 void insert_string(struct string_list **str_list, char *str);
839 struct string_list *clone_str_list(struct string_list *orig);
840 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two);
842 /* smatch_start_states.c */
843 struct stree *get_start_states(void);
845 /* smatch_recurse.c */
846 int has_symbol(struct expression *expr, struct symbol *sym);
847 int has_variable(struct expression *expr, struct expression *var);
848 int has_inc_dec(struct expression *expr);
850 /* smatch_stored_conditions.c */
851 struct smatch_state *get_stored_condition(struct expression *expr);
853 /* check_string_len.c */
854 int get_formatted_string_size(struct expression *call, int arg);
856 /* smatch_param_set.c */
857 int param_was_set(struct expression *expr);
858 /* smatch_param_filter.c */
859 int param_has_filter_data(struct sm_state *sm);
861 /* smatch_links.c */
862 void set_up_link_functions(int id, int linkid);
863 struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2);
864 void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym);
866 /* smatch_auto_copy.c */
867 void set_auto_copy(int owner);
869 /* check_buf_comparison */
870 struct expression *get_size_variable(struct expression *buf);
872 /* smatch_untracked_param.c */
873 void add_untracked_param_hook(void (func)(struct expression *call, int param));
875 /* smatch_impossible.c */
876 int is_impossible_path(void);
878 /* smatch_strings.c */
879 struct state_list *get_strings(struct expression *expr);
881 /* smatch_estate.c */
882 int estate_get_single_value(struct smatch_state *state, sval_t *sval);
884 /* smatch_address.c */
885 int get_address_rl(struct expression *expr, struct range_list **rl);
887 /* for now this is in smatch_used_parameter.c */
888 void __get_state_hook(int owner, const char *name, struct symbol *sym);
889 #endif /* !SMATCH_H_ */