Print this page
11972 resync smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch.h
          +++ new/usr/src/tools/smatch/src/smatch.h
↓ open down ↓ 99 lines elided ↑ open up ↑
 100  100  };
 101  101  DECLARE_PTR_LIST(constraint_list, struct constraint);
 102  102  
 103  103  struct bit_info {
 104  104          unsigned long long set;
 105  105          unsigned long long possible;
 106  106  };
 107  107  
 108  108  enum hook_type {
 109  109          EXPR_HOOK,
      110 +        EXPR_HOOK_AFTER,
 110  111          STMT_HOOK,
 111  112          STMT_HOOK_AFTER,
 112  113          SYM_HOOK,
 113  114          STRING_HOOK,
 114  115          DECLARATION_HOOK,
 115  116          ASSIGNMENT_HOOK,
 116  117          ASSIGNMENT_HOOK_AFTER,
 117  118          RAW_ASSIGNMENT_HOOK,
 118  119          GLOBAL_ASSIGNMENT_HOOK,
 119  120          LOGIC_HOOK,
↓ open down ↓ 29 lines elided ↑ open up ↑
 149  150  #define TRUE 1
 150  151  #define FALSE 0
 151  152  
 152  153  struct range_list;
 153  154  
 154  155  void add_hook(void *func, enum hook_type type);
 155  156  typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2);
 156  157  typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state);
 157  158  void add_merge_hook(int client_id, merge_func_t *func);
 158  159  void add_unmatched_state_hook(int client_id, unmatched_func_t *func);
 159      -void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *sm));
      160 +void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *cur, struct sm_state *other));
 160  161  typedef void (scope_hook)(void *data);
 161  162  void add_scope_hook(scope_hook *hook, void *data);
 162  163  typedef void (func_hook)(const char *fn, struct expression *expr, void *data);
 163  164  typedef void (implication_hook)(const char *fn, struct expression *call_expr,
 164  165                                  struct expression *assign_expr, void *data);
 165  166  typedef void (return_implies_hook)(struct expression *call_expr,
 166  167                                     int param, char *key, char *value);
 167  168  typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl);
 168  169  void add_function_hook(const char *look_for, func_hook *call_back, void *data);
 169  170  
↓ open down ↓ 28 lines elided ↑ open up ↑
 198  199  
 199  200  int outside_of_function(void);
 200  201  const char *get_filename(void);
 201  202  const char *get_base_file(void);
 202  203  char *get_function(void);
 203  204  int get_lineno(void);
 204  205  extern int final_pass;
 205  206  extern struct symbol *cur_func_sym;
 206  207  extern int option_debug;
 207  208  extern int local_debug;
      209 +bool debug_implied(void);
 208  210  extern int option_info;
 209  211  extern int option_spammy;
 210  212  extern int option_timeout;
 211  213  extern char *trace_variable;
 212  214  extern struct stree *global_states;
 213  215  int is_skipped_function(void);
 214  216  int is_silenced_function(void);
 215  217  extern bool implications_off;
 216  218  
 217  219  /* smatch_impossible.c */
↓ open down ↓ 142 lines elided ↑ open up ↑
 360  362  
 361  363  struct stree *get_all_states_from_stree(int owner, struct stree *source);
 362  364  struct stree *get_all_states_stree(int id);
 363  365  struct stree *__get_cur_stree(void);
 364  366  int is_reachable(void);
 365  367  void add_get_state_hook(void (*fn)(int owner, const char *name, struct symbol *sym));
 366  368  
 367  369  /* smatch_helper.c */
 368  370  DECLARE_PTR_LIST(int_stack, int);
 369  371  char *alloc_string(const char *str);
      372 +char *alloc_string_newline(const char *str);
 370  373  void free_string(char *str);
 371  374  void append(char *dest, const char *data, int buff_len);
 372  375  void remove_parens(char *str);
 373  376  struct smatch_state *alloc_state_num(int num);
 374  377  struct smatch_state *alloc_state_str(const char *name);
 375  378  struct smatch_state *merge_str_state(struct smatch_state *s1, struct smatch_state *s2);
 376  379  struct smatch_state *alloc_state_expr(struct expression *expr);
 377  380  struct expression *get_argument_from_call_expr(struct expression_list *args,
 378  381                                                 int num);
 379  382  
↓ open down ↓ 14 lines elided ↑ open up ↑
 394  397  int get_implied_value(struct expression *expr, sval_t *val);
 395  398  int get_implied_min(struct expression *expr, sval_t *sval);
 396  399  int get_implied_max(struct expression *expr, sval_t *val);
 397  400  int get_hard_max(struct expression *expr, sval_t *sval);
 398  401  int get_fuzzy_min(struct expression *expr, sval_t *min);
 399  402  int get_fuzzy_max(struct expression *expr, sval_t *max);
 400  403  int get_absolute_min(struct expression *expr, sval_t *sval);
 401  404  int get_absolute_max(struct expression *expr, sval_t *sval);
 402  405  int parse_call_math(struct expression *expr, char *math, sval_t *val);
 403  406  int parse_call_math_rl(struct expression *call, const char *math, struct range_list **rl);
      407 +const char *get_allocation_math(struct expression *expr);
 404  408  char *get_value_in_terms_of_parameter_math(struct expression *expr);
 405  409  char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
 406      -int is_zero(struct expression *expr);
      410 +int expr_is_zero(struct expression *expr);
 407  411  int known_condition_true(struct expression *expr);
 408  412  int known_condition_false(struct expression *expr);
 409  413  int implied_condition_true(struct expression *expr);
 410  414  int implied_condition_false(struct expression *expr);
 411  415  int can_integer_overflow(struct symbol *type, struct expression *expr);
 412  416  void clear_math_cache(void);
      417 +void set_fast_math_only(void);
      418 +void clear_fast_math_only(void);
 413  419  
 414  420  int is_array(struct expression *expr);
 415  421  struct expression *get_array_base(struct expression *expr);
 416  422  struct expression *get_array_offset(struct expression *expr);
 417  423  const char *show_state(struct smatch_state *state);
 418  424  struct statement *get_expression_statement(struct expression *expr);
 419  425  struct expression *strip_parens(struct expression *expr);
 420  426  struct expression *strip_expr(struct expression *expr);
 421  427  struct expression *strip_expr_set_parent(struct expression *expr);
 422  428  void scoped_state(int my_id, const char *name, struct symbol *sym);
 423  429  int is_error_return(struct expression *expr);
 424      -int getting_address(void);
      430 +int getting_address(struct expression *expr);
 425  431  int get_struct_and_member(struct expression *expr, const char **type, const char **member);
 426  432  char *get_member_name(struct expression *expr);
 427  433  char *get_fnptr_name(struct expression *expr);
 428  434  int cmp_pos(struct position pos1, struct position pos2);
 429  435  int positions_eq(struct position pos1, struct position pos2);
 430  436  struct statement *get_current_statement(void);
 431  437  struct statement *get_prev_statement(void);
 432  438  struct expression *get_last_expr_from_expression_stmt(struct expression *expr);
 433  439  int get_param_num_from_sym(struct symbol *sym);
 434  440  int get_param_num(struct expression *expr);
↓ open down ↓ 20 lines elided ↑ open up ↑
 455  461  int returns_unsigned(struct symbol *base_type);
 456  462  int is_pointer(struct expression *expr);
 457  463  int returns_pointer(struct symbol *base_type);
 458  464  sval_t sval_type_max(struct symbol *base_type);
 459  465  sval_t sval_type_min(struct symbol *base_type);
 460  466  int nr_bits(struct expression *expr);
 461  467  int is_void_pointer(struct expression *expr);
 462  468  int is_char_pointer(struct expression *expr);
 463  469  int is_string(struct expression *expr);
 464  470  int is_static(struct expression *expr);
 465      -int is_local_variable(struct expression *expr);
      471 +bool is_local_variable(struct expression *expr);
 466  472  int types_equiv(struct symbol *one, struct symbol *two);
 467  473  int fn_static(void);
 468  474  const char *global_static();
 469  475  struct symbol *cur_func_return_type(void);
 470  476  struct symbol *get_arg_type(struct expression *fn, int arg);
 471  477  struct symbol *get_member_type_from_key(struct expression *expr, const char *key);
 472  478  struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key);
 473  479  int is_struct(struct expression *expr);
 474  480  char *type_to_str(struct symbol *type);
 475  481  
↓ open down ↓ 41 lines elided ↑ open up ↑
 517  523  void smatch (struct string_list *filelist);
 518  524  int inside_loop(void);
 519  525  int definitely_inside_loop(void);
 520  526  struct expression *get_switch_expr(void);
 521  527  int in_expression_statement(void);
 522  528  void __process_post_op_stack(void);
 523  529  void __split_expr(struct expression *expr);
 524  530  void __split_label_stmt(struct statement *stmt);
 525  531  void __split_stmt(struct statement *stmt);
 526  532  extern int __in_function_def;
      533 +extern int __in_unmatched_hook;
 527  534  extern int option_assume_loops;
 528  535  extern int option_two_passes;
 529  536  extern int option_no_db;
 530  537  extern int option_file_output;
 531  538  extern int option_time;
 532  539  extern struct expression_list *big_expression_stack;
 533  540  extern struct expression_list *big_condition_stack;
 534  541  extern struct statement_list *big_statement_stack;
 535  542  int is_assigned_call(struct expression *expr);
 536  543  int inlinable(struct expression *expr);
↓ open down ↓ 129 lines elided ↑ open up ↑
 666  673  char *get_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
 667  674  char *map_call_to_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
 668  675  char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack);
 669  676  
 670  677  #define STRLEN_MAX_RET 1010101
 671  678  
 672  679  /* smatch_absolute.c */
 673  680  int get_absolute_min_helper(struct expression *expr, sval_t *sval);
 674  681  int get_absolute_max_helper(struct expression *expr, sval_t *sval);
 675  682  
 676      -/* smatch_local_values.c */
 677      -int get_local_rl(struct expression *expr, struct range_list **rl);
 678      -int get_local_max_helper(struct expression *expr, sval_t *sval);
 679      -int get_local_min_helper(struct expression *expr, sval_t *sval);
 680      -
 681  683  /* smatch_type_value.c */
 682  684  int get_db_type_rl(struct expression *expr, struct range_list **rl);
 683  685  /* smatch_data_val.c */
 684  686  int get_mtag_rl(struct expression *expr, struct range_list **rl);
 685  687  /* smatch_array_values.c */
 686  688  int get_array_rl(struct expression *expr, struct range_list **rl);
 687  689  
 688  690  /* smatch_states.c */
 689      -void __swap_cur_stree(struct stree *stree);
      691 +struct stree *__swap_cur_stree(struct stree *stree);
 690  692  void __push_fake_cur_stree();
 691  693  struct stree *__pop_fake_cur_stree();
 692  694  void __free_fake_cur_stree();
 693  695  void __set_fake_cur_stree_fast(struct stree *stree);
 694  696  void __pop_fake_cur_stree_fast(void);
 695  697  void __merge_stree_into_cur(struct stree *stree);
 696  698  
 697  699  int unreachable(void);
      700 +void __set_cur_stree_readonly(void);
      701 +void __set_cur_stree_writable(void);
 698  702  void __set_sm(struct sm_state *sm);
 699  703  void __set_sm_cur_stree(struct sm_state *sm);
 700  704  void __set_sm_fake_stree(struct sm_state *sm);
 701  705  void __set_true_false_sm(struct sm_state *true_state,
 702  706                          struct sm_state *false_state);
 703  707  void nullify_path(void);
 704  708  void __match_nullify_path_hook(const char *fn, struct expression *expr,
 705  709                                 void *unused);
 706  710  void __unnullify_path(void);
 707  711  int __path_is_null(void);
↓ open down ↓ 53 lines elided ↑ open up ↑
 761  765  void __push_conditions(void);
 762  766  void __discard_conditions(void);
 763  767  
 764  768  void __save_gotos(const char *name, struct symbol *sym);
 765  769  void __merge_gotos(const char *name, struct symbol *sym);
 766  770  
 767  771  void __print_cur_stree(void);
 768  772  
 769  773  /* smatch_hooks.c */
 770  774  void __pass_to_client(void *data, enum hook_type type);
 771      -void __pass_to_client_no_data(enum hook_type type);
 772  775  void __pass_case_to_client(struct expression *switch_expr,
 773  776                             struct range_list *rl);
 774  777  int __has_merge_function(int client_id);
 775  778  struct smatch_state *__client_merge_function(int owner,
 776  779                                               struct smatch_state *s1,
 777  780                                               struct smatch_state *s2);
 778  781  struct smatch_state *__client_unmatched_state_function(struct sm_state *sm);
 779      -void call_pre_merge_hook(struct sm_state *sm);
      782 +void call_pre_merge_hook(struct sm_state *cur, struct sm_state *other);
 780  783  void __push_scope_hooks(void);
 781  784  void __call_scope_hooks(void);
 782  785  
 783  786  /* smatch_function_hooks.c */
 784  787  void create_function_hook_hash(void);
 785  788  void __match_initializer_call(struct symbol *sym);
 786  789  
 787  790  /* smatch_db.c */
 788  791  enum info_type {
 789  792          INTERNAL        = 0,
↓ open down ↓ 77 lines elided ↑ open up ↑
 867  870  
 868  871  void db_ignore_states(int id);
 869  872  void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
 870  873  void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm));
 871  874  void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
 872  875  void add_returned_member_callback(int owner, void (*callback)(int return_id, char *return_ranges, struct expression *expr, char *printed_name, struct smatch_state *state));
 873  876  void select_call_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value));
 874  877  void select_return_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value));
 875  878  struct range_list *db_return_vals(struct expression *expr);
 876  879  struct range_list *db_return_vals_from_str(const char *fn_name);
      880 +struct range_list *db_return_vals_no_args(struct expression *expr);
 877  881  char *return_state_to_var_sym(struct expression *expr, int param, const char *key, struct symbol **sym);
 878  882  char *get_chunk_from_key(struct expression *arg, char *key, struct symbol **sym, struct var_sym_list **vsl);
 879  883  char *get_variable_from_key(struct expression *arg, const char *key, struct symbol **sym);
 880  884  const char *state_name_to_param_name(const char *state_name, const char *param_name);
 881  885  const char *get_param_name_var_sym(const char *name, struct symbol *sym);
 882  886  const char *get_param_name(struct sm_state *sm);
 883  887  const char *get_mtag_name_var_sym(const char *state_name, struct symbol *sym);
 884  888  const char *get_mtag_name_expr(struct expression *expr);
 885  889  char *get_data_info_name(struct expression *expr);
 886  890  int is_recursive_member(const char *param_name);
↓ open down ↓ 164 lines elided ↑ open up ↑
1051 1055  void print_held_locks();
1052 1056  
1053 1057  /* check_assigned_expr.c */
1054 1058  struct expression *get_assigned_expr(struct expression *expr);
1055 1059  struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym);
1056 1060  /* smatch_return_to_param.c */
1057 1061  void __add_return_to_param_mapping(struct expression *assign, const char *return_string);
1058 1062  char *map_call_to_param_name_sym(struct expression *expr, struct symbol **sym);
1059 1063  
1060 1064  /* smatch_comparison.c */
     1065 +#define UNKNOWN_COMPARISON 0
     1066 +#define IMPOSSIBLE_COMPARISON -1
1061 1067  struct compare_data {
1062 1068          /* The ->left and ->right expression pointers might be NULL (I'm lazy) */
1063 1069          struct expression *left;
1064 1070          const char *left_var;
1065 1071          struct var_sym_list *left_vsl;
1066 1072          int comparison;
1067 1073          struct expression *right;
1068 1074          const char *right_var;
1069 1075          struct var_sym_list *right_vsl;
1070 1076  };
1071 1077  DECLARE_ALLOCATOR(compare_data);
1072 1078  struct smatch_state *alloc_compare_state(
1073 1079                  struct expression *left,
1074 1080                  const char *left_var, struct var_sym_list *left_vsl,
1075 1081                  int comparison,
1076 1082                  struct expression *right,
1077 1083                  const char *right_var, struct var_sym_list *right_vsl);
1078      -int filter_comparison(int orig, int op);
     1084 +int comparison_intersection(int orig, int op);
1079 1085  int merge_comparisons(int one, int two);
1080 1086  int combine_comparisons(int left_compare, int right_compare);
1081 1087  int state_to_comparison(struct smatch_state *state);
1082 1088  struct smatch_state *merge_compare_states(struct smatch_state *s1, struct smatch_state *s2);
1083 1089  int get_comparison(struct expression *left, struct expression *right);
1084 1090  int get_comparison_no_extra(struct expression *a, struct expression *b);
1085 1091  int get_comparison_strings(const char *one, const char *two);
1086 1092  int possible_comparison(struct expression *a, int comparison, struct expression *b);
1087 1093  struct state_list *get_all_comparisons(struct expression *expr);
1088 1094  struct state_list *get_all_possible_equal_comparisons(struct expression *expr);
↓ open down ↓ 77 lines elided ↑ open up ↑
1166 1172                          struct state_list **true_stack,
1167 1173                          struct state_list **false_stack);
1168 1174  
1169 1175  /* check_string_len.c */
1170 1176  int get_formatted_string_size(struct expression *call, int arg);
1171 1177  int get_formatted_string_min_size(struct expression *call, int arg);
1172 1178  
1173 1179  /* smatch_param_set.c */
1174 1180  int param_was_set(struct expression *expr);
1175 1181  int param_was_set_var_sym(const char *name, struct symbol *sym);
     1182 +void print_limited_param_set(int return_id, char *return_ranges, struct expression *expr);
1176 1183  /* smatch_param_filter.c */
1177 1184  int param_has_filter_data(struct sm_state *sm);
1178 1185  
1179 1186  /* smatch_links.c */
1180 1187  void set_up_link_functions(int id, int linkid);
1181 1188  struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2);
1182 1189  void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym);
1183 1190  
1184      -/* smatch_auto_copy.c */
1185      -void set_auto_copy(int owner);
1186      -
1187 1191  /* check_buf_comparison */
1188 1192  const char *limit_type_str(unsigned int limit_type);
1189 1193  struct expression *get_size_variable(struct expression *buf, int *limit_type);
1190 1194  struct expression *get_array_variable(struct expression *size);
1191 1195  int buf_comparison_index_ok(struct expression *expr);
1192 1196  
1193 1197  /* smatch_untracked_param.c */
1194 1198  void mark_untracked(struct expression *expr, int param, const char *key, const char *value);
1195 1199  void add_untracked_param_hook(void (func)(struct expression *call, int param));
1196 1200  void add_lost_param_hook(void (func)(struct expression *call, int param));
↓ open down ↓ 31 lines elided ↑ open up ↑
1228 1232  /* smatch_container_of.c */
1229 1233  int get_param_from_container_of(struct expression *expr);
1230 1234  int get_offset_from_container_of(struct expression *expr);
1231 1235  char *get_container_name(struct expression *container, struct expression *expr);
1232 1236  
1233 1237  /* smatch_mtag.c */
1234 1238  int get_string_mtag(struct expression *expr, mtag_t *tag);
1235 1239  int get_toplevel_mtag(struct symbol *sym, mtag_t *tag);
1236 1240  int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new);
1237 1241  int expr_to_mtag_offset(struct expression *expr, mtag_t *tag, int *offset);
1238      -void update_mtag_data(struct expression *expr);
     1242 +void update_mtag_data(struct expression *expr, struct smatch_state *state);
1239 1243  int get_mtag_sval(struct expression *expr, sval_t *sval);
1240 1244  
1241 1245  /* Trinity fuzzer stuff */
1242 1246  const char *get_syscall_arg_type(struct symbol *sym);
1243 1247  
1244 1248  /* smatch_bit_info.c */
     1249 +struct bit_info *rl_to_binfo(struct range_list *rl);
1245 1250  struct bit_info *get_bit_info(struct expression *expr);
1246 1251  struct bit_info *get_bit_info_var_sym(const char *name, struct symbol *sym);
1247 1252  /* smatch_mem_tracker.c */
1248 1253  extern int option_mem;
1249 1254  unsigned long get_mem_kb(void);
1250 1255  unsigned long get_max_memory(void);
1251 1256  
1252 1257  /* check_is_nospec.c */
1253 1258  bool is_nospec(struct expression *expr);
1254 1259  long get_stmt_cnt(void);
1255 1260  
1256 1261  /* smatch_nul_terminator.c */
     1262 +bool is_nul_terminated_var_sym(const char *name, struct symbol *sym);
1257 1263  bool is_nul_terminated(struct expression *expr);
1258 1264  /* check_kernel.c  */
1259 1265  bool is_ignored_kernel_data(const char *name);
1260 1266  
1261 1267  static inline bool type_is_ptr(struct symbol *type)
1262 1268  {
1263 1269          return type &&
1264 1270                 (type->type == SYM_PTR ||
1265 1271                  type->type == SYM_ARRAY ||
1266 1272                  type->type == SYM_FN);
↓ open down ↓ 72 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX