Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch.h
          +++ new/usr/src/tools/smatch/src/smatch.h
↓ open down ↓ 71 lines elided ↑ open up ↑
  72   72  DECLARE_ALLOCATOR(tracker);
  73   73  DECLARE_PTR_LIST(tracker_list, struct tracker);
  74   74  DECLARE_PTR_LIST(stree_stack, struct stree);
  75   75  
  76   76  /* The first 3 struct members must match struct tracker */
  77   77  struct sm_state {
  78   78          const char *name;
  79   79          struct symbol *sym;
  80   80          unsigned short owner;
  81   81          unsigned short merged:1;
  82      -        unsigned short skip_implications:1;
  83      -        unsigned int nr_children;
  84   82          unsigned int line;
  85   83          struct smatch_state *state;
  86   84          struct stree *pool;
  87   85          struct sm_state *left;
  88   86          struct sm_state *right;
  89   87          struct state_list *possible;
  90   88  };
  91   89  
  92   90  struct var_sym {
  93   91          char *var;
↓ open down ↓ 1 lines elided ↑ open up ↑
  95   93  };
  96   94  DECLARE_ALLOCATOR(var_sym);
  97   95  DECLARE_PTR_LIST(var_sym_list, struct var_sym);
  98   96  
  99   97  struct constraint {
 100   98          int op;
 101   99          int id;
 102  100  };
 103  101  DECLARE_PTR_LIST(constraint_list, struct constraint);
 104  102  
      103 +struct bit_info {
      104 +        unsigned long long set;
      105 +        unsigned long long possible;
      106 +};
      107 +
 105  108  enum hook_type {
 106  109          EXPR_HOOK,
 107  110          STMT_HOOK,
 108  111          STMT_HOOK_AFTER,
 109  112          SYM_HOOK,
 110  113          STRING_HOOK,
 111  114          DECLARATION_HOOK,
 112  115          ASSIGNMENT_HOOK,
 113  116          ASSIGNMENT_HOOK_AFTER,
 114  117          RAW_ASSIGNMENT_HOOK,
↓ open down ↓ 53 lines elided ↑ open up ↑
 168  171                                void *info);
 169  172  void add_implied_return_hook(const char *look_for,
 170  173                               implied_return_hook *call_back,
 171  174                               void *info);
 172  175  void add_macro_assign_hook(const char *look_for, func_hook *call_back,
 173  176                                void *info);
 174  177  void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
 175  178                                void *info);
 176  179  void return_implies_state(const char *look_for, long long start, long long end,
 177  180                           implication_hook *call_back, void *info);
      181 +void return_implies_state_sval(const char *look_for, sval_t start, sval_t end,
      182 +                         implication_hook *call_back, void *info);
 178  183  void select_return_states_hook(int type, return_implies_hook *callback);
 179  184  void select_return_states_before(void (*fn)(void));
 180  185  void select_return_states_after(void (*fn)(void));
 181  186  int get_implied_return(struct expression *expr, struct range_list **rl);
 182  187  void allocate_hook_memory(void);
 183  188  
 184  189  struct modification_data {
 185  190          struct smatch_state *prev;
 186  191          struct expression *cur;
 187  192  };
↓ open down ↓ 12 lines elided ↑ open up ↑
 200  205  extern struct symbol *cur_func_sym;
 201  206  extern int option_debug;
 202  207  extern int local_debug;
 203  208  extern int option_info;
 204  209  extern int option_spammy;
 205  210  extern int option_timeout;
 206  211  extern char *trace_variable;
 207  212  extern struct stree *global_states;
 208  213  int is_skipped_function(void);
 209  214  int is_silenced_function(void);
      215 +extern bool implications_off;
 210  216  
 211  217  /* smatch_impossible.c */
 212  218  int is_impossible_path(void);
 213  219  void set_path_impossible(void);
 214  220  
 215  221  extern FILE *sm_outfd;
 216  222  extern FILE *sql_outfd;
 217  223  extern FILE *caller_info_fd;
 218  224  extern int sm_nr_checks;
 219  225  extern int sm_nr_errors;
↓ open down ↓ 139 lines elided ↑ open up ↑
 359  365  void add_get_state_hook(void (*fn)(int owner, const char *name, struct symbol *sym));
 360  366  
 361  367  /* smatch_helper.c */
 362  368  DECLARE_PTR_LIST(int_stack, int);
 363  369  char *alloc_string(const char *str);
 364  370  void free_string(char *str);
 365  371  void append(char *dest, const char *data, int buff_len);
 366  372  void remove_parens(char *str);
 367  373  struct smatch_state *alloc_state_num(int num);
 368  374  struct smatch_state *alloc_state_str(const char *name);
      375 +struct smatch_state *merge_str_state(struct smatch_state *s1, struct smatch_state *s2);
 369  376  struct smatch_state *alloc_state_expr(struct expression *expr);
 370  377  struct expression *get_argument_from_call_expr(struct expression_list *args,
 371  378                                                 int num);
 372  379  
 373  380  char *expr_to_var(struct expression *expr);
 374  381  struct symbol *expr_to_sym(struct expression *expr);
 375  382  char *expr_to_str(struct expression *expr);
 376  383  char *expr_to_str_sym(struct expression *expr,
 377  384                                       struct symbol **sym_ptr);
 378  385  char *expr_to_var_sym(struct expression *expr,
↓ open down ↓ 7 lines elided ↑ open up ↑
 386  393  int get_value(struct expression *expr, sval_t *val);
 387  394  int get_implied_value(struct expression *expr, sval_t *val);
 388  395  int get_implied_min(struct expression *expr, sval_t *sval);
 389  396  int get_implied_max(struct expression *expr, sval_t *val);
 390  397  int get_hard_max(struct expression *expr, sval_t *sval);
 391  398  int get_fuzzy_min(struct expression *expr, sval_t *min);
 392  399  int get_fuzzy_max(struct expression *expr, sval_t *max);
 393  400  int get_absolute_min(struct expression *expr, sval_t *sval);
 394  401  int get_absolute_max(struct expression *expr, sval_t *sval);
 395  402  int parse_call_math(struct expression *expr, char *math, sval_t *val);
 396      -int parse_call_math_rl(struct expression *call, char *math, struct range_list **rl);
      403 +int parse_call_math_rl(struct expression *call, const char *math, struct range_list **rl);
 397  404  char *get_value_in_terms_of_parameter_math(struct expression *expr);
 398  405  char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
 399  406  int is_zero(struct expression *expr);
 400  407  int known_condition_true(struct expression *expr);
 401  408  int known_condition_false(struct expression *expr);
 402  409  int implied_condition_true(struct expression *expr);
 403  410  int implied_condition_false(struct expression *expr);
 404  411  int can_integer_overflow(struct symbol *type, struct expression *expr);
 405  412  void clear_math_cache(void);
 406  413  
↓ open down ↓ 15 lines elided ↑ open up ↑
 422  429  int positions_eq(struct position pos1, struct position pos2);
 423  430  struct statement *get_current_statement(void);
 424  431  struct statement *get_prev_statement(void);
 425  432  struct expression *get_last_expr_from_expression_stmt(struct expression *expr);
 426  433  int get_param_num_from_sym(struct symbol *sym);
 427  434  int get_param_num(struct expression *expr);
 428  435  int ms_since(struct timeval *start);
 429  436  int parent_is_gone_var_sym(const char *name, struct symbol *sym);
 430  437  int parent_is_gone(struct expression *expr);
 431  438  int invert_op(int op);
      439 +int op_remove_assign(int op);
 432  440  int expr_equiv(struct expression *one, struct expression *two);
 433  441  void push_int(struct int_stack **stack, int num);
 434  442  int pop_int(struct int_stack **stack);
 435  443  
 436  444  /* smatch_type.c */
 437  445  struct symbol *get_real_base_type(struct symbol *sym);
 438  446  int type_bytes(struct symbol *type);
 439  447  int array_bytes(struct symbol *type);
 440  448  struct symbol *get_pointer_type(struct expression *expr);
 441  449  struct symbol *get_type(struct expression *expr);
↓ open down ↓ 57 lines elided ↑ open up ↑
 499  507  
 500  508  /* smatch_conditions */
 501  509  int in_condition(void);
 502  510  
 503  511  /* smatch_flow.c */
 504  512  
 505  513  extern int __in_fake_assign;
 506  514  extern int __in_fake_parameter_assign;
 507  515  extern int __in_fake_struct_assign;
 508  516  extern int in_fake_env;
 509      -void smatch (int argc, char **argv);
      517 +void smatch (struct string_list *filelist);
 510  518  int inside_loop(void);
 511  519  int definitely_inside_loop(void);
 512  520  struct expression *get_switch_expr(void);
 513  521  int in_expression_statement(void);
 514  522  void __process_post_op_stack(void);
 515  523  void __split_expr(struct expression *expr);
 516  524  void __split_label_stmt(struct statement *stmt);
 517  525  void __split_stmt(struct statement *stmt);
 518  526  extern int __in_function_def;
 519  527  extern int option_assume_loops;
↓ open down ↓ 9 lines elided ↑ open up ↑
 529  537  extern int __inline_call;
 530  538  extern struct expression *__inline_fn;
 531  539  extern int __in_pre_condition;
 532  540  extern int __bail_on_rest_of_function;
 533  541  extern struct statement *__prev_stmt;
 534  542  extern struct statement *__cur_stmt;
 535  543  extern struct statement *__next_stmt;
 536  544  void init_fake_env(void);
 537  545  void end_fake_env(void);
 538  546  int time_parsing_function(void);
      547 +bool taking_too_long(void);
 539  548  
 540  549  /* smatch_struct_assignment.c */
 541  550  struct expression *get_faked_expression(void);
 542  551  void __fake_struct_member_assignments(struct expression *expr);
 543  552  
 544  553  /* smatch_project.c */
 545  554  int is_no_inline_function(const char *function);
 546  555  
 547  556  /* smatch_conditions */
 548  557  void __split_whole_condition(struct expression *expr);
 549  558  void __handle_logic(struct expression *expr);
 550  559  int is_condition(struct expression *expr);
 551  560  int __handle_condition_assigns(struct expression *expr);
 552  561  int __handle_select_assigns(struct expression *expr);
 553  562  int __handle_expr_statement_assigns(struct expression *expr);
 554  563  
 555  564  /* smatch_implied.c */
 556      -extern int option_debug_implied;
 557      -extern int option_debug_related;
 558  565  struct range_list_stack;
 559  566  void param_limit_implications(struct expression *expr, int param, char *key, char *value);
 560  567  struct stree *__implied_case_stree(struct expression *switch_expr,
 561  568                                     struct range_list *case_rl,
 562  569                                     struct range_list_stack **remaining_cases,
 563  570                                     struct stree **raw_stree);
 564  571  void overwrite_states_using_pool(struct sm_state *gate_sm, struct sm_state *pool_sm);
 565  572  int assume(struct expression *expr);
 566  573  void end_assume(void);
 567  574  int impossible_assumption(struct expression *left, int op, sval_t sval);
 568  575  
      576 +/* smatch_slist.h */
      577 +bool has_dynamic_states(unsigned short owner);
      578 +void set_dynamic_states(unsigned short owner);
      579 +
 569  580  /* smatch_extras.c */
      581 +int in_warn_on_macro(void);
 570  582  #define SMATCH_EXTRA 5 /* this is my_id from smatch extra set in smatch.c */
 571  583  extern int RETURN_ID;
 572  584  
 573  585  struct data_range {
 574  586          sval_t min;
 575  587          sval_t max;
 576  588  };
 577  589  
 578  590  #define MTAG_ALIAS_BIT (1ULL << 63)
 579  591  #define MTAG_OFFSET_MASK 0xfffULL
      592 +#define MTAG_SEED 0xdead << 12
 580  593  
 581      -extern long long valid_ptr_min, valid_ptr_max;
 582      -extern sval_t valid_ptr_min_sval, valid_ptr_max_sval;
      594 +const extern unsigned long valid_ptr_min;
      595 +extern unsigned long valid_ptr_max;
      596 +extern const sval_t valid_ptr_min_sval;
      597 +extern sval_t valid_ptr_max_sval;
 583  598  extern struct range_list *valid_ptr_rl;
      599 +void alloc_valid_ptr_rl(void);
      600 +
 584  601  static const sval_t array_min_sval = {
 585  602          .type = &ptr_ctype,
 586  603          {.value = 100000},
 587  604  };
 588  605  static const sval_t array_max_sval = {
 589  606          .type = &ptr_ctype,
 590      -        {.value = 199999},
      607 +        {.value = ULONG_MAX - 4095},
 591  608  };
 592  609  static const sval_t text_seg_min = {
 593  610          .type = &ptr_ctype,
 594      -        {.value = 100000000},
      611 +        {.value = 4096},
 595  612  };
 596  613  static const sval_t text_seg_max = {
 597  614          .type = &ptr_ctype,
 598      -        {.value = 177777777},
      615 +        {.value = ULONG_MAX - 4095},
 599  616  };
 600  617  static const sval_t data_seg_min = {
 601  618          .type = &ptr_ctype,
 602      -        {.value = 200000000},
      619 +        {.value = 4096},
 603  620  };
 604  621  static const sval_t data_seg_max = {
 605  622          .type = &ptr_ctype,
 606      -        {.value = 277777777},
      623 +        {.value = ULONG_MAX - 4095},
 607  624  };
 608  625  static const sval_t bss_seg_min = {
 609  626          .type = &ptr_ctype,
 610      -        {.value = 300000000},
      627 +        {.value = 4096},
 611  628  };
 612  629  static const sval_t bss_seg_max = {
 613  630          .type = &ptr_ctype,
 614      -        {.value = 377777777},
      631 +        {.value = ULONG_MAX - 4095},
 615  632  };
 616  633  static const sval_t stack_seg_min = {
 617  634          .type = &ptr_ctype,
 618      -        {.value = 400000000},
      635 +        {.value = 4096},
 619  636  };
 620  637  static const sval_t stack_seg_max = {
 621  638          .type = &ptr_ctype,
 622      -        {.value = 477777777},
      639 +        {.value = ULONG_MAX - 4095},
 623  640  };
 624  641  static const sval_t kmalloc_seg_min = {
 625  642          .type = &ptr_ctype,
 626      -        {.value = 500000000},
      643 +        {.value = 4096},
 627  644  };
 628  645  static const sval_t kmalloc_seg_max = {
 629  646          .type = &ptr_ctype,
 630      -        {.value = 577777777},
      647 +        {.value = ULONG_MAX - 4095},
 631  648  };
 632  649  static const sval_t vmalloc_seg_min = {
 633  650          .type = &ptr_ctype,
 634      -        {.value = 600000000},
      651 +        {.value = 4096},
 635  652  };
 636  653  static const sval_t vmalloc_seg_max = {
 637  654          .type = &ptr_ctype,
 638      -        {.value = 677777777},
      655 +        {.value = ULONG_MAX - 4095},
 639  656  };
 640  657  static const sval_t fn_ptr_min = {
 641  658          .type = &ptr_ctype,
 642      -        {.value = 700000000},
      659 +        {.value = 4096},
 643  660  };
 644  661  static const sval_t fn_ptr_max = {
 645  662          .type = &ptr_ctype,
 646      -        {.value = 777777777},
      663 +        {.value = ULONG_MAX - 4095},
 647  664  };
 648  665  
 649  666  char *get_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
 650  667  char *map_call_to_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
 651      -char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
 652      -char *map_long_to_short_name_sym_nostack(const char *name, struct symbol *sym, struct symbol **new_sym);
      668 +char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack);
 653  669  
 654  670  #define STRLEN_MAX_RET 1010101
 655  671  
 656  672  /* smatch_absolute.c */
 657  673  int get_absolute_min_helper(struct expression *expr, sval_t *sval);
 658  674  int get_absolute_max_helper(struct expression *expr, sval_t *sval);
 659  675  
 660  676  /* smatch_local_values.c */
 661  677  int get_local_rl(struct expression *expr, struct range_list **rl);
 662  678  int get_local_max_helper(struct expression *expr, sval_t *sval);
↓ open down ↓ 113 lines elided ↑ open up ↑
 776  792           * number it can't be re-used right away so there may be gaps.
 777  793           * We select these in order by type so if the order matters, then give
 778  794           * it a number below 100-999,9000-9999 ranges. */
 779  795  
 780  796          PARAM_CLEARED   = 101,
 781  797          PARAM_LIMIT     = 103,
 782  798          PARAM_FILTER    = 104,
 783  799  
 784  800          PARAM_VALUE     = 1001,
 785  801          BUF_SIZE        = 1002,
 786      -        USER_DATA       = 1003,
 787  802          CAPPED_DATA     = 1004,
 788  803          RETURN_VALUE    = 1005,
 789  804          DEREFERENCE     = 1006,
 790  805          RANGE_CAP       = 1007,
 791  806          LOCK_HELD       = 1008,
 792  807          LOCK_RELEASED   = 1009,
 793  808          ABSOLUTE_LIMITS = 1010,
 794  809          PARAM_ADD       = 1012,
 795  810          PARAM_FREED     = 1013,
 796  811          DATA_SOURCE     = 1014,
 797  812          FUZZY_MAX       = 1015,
      813 +        HARD_MAX        = 2015,
 798  814          STR_LEN         = 1016,
 799  815          ARRAY_LEN       = 1017,
 800  816          CAPABLE         = 1018,
 801  817          NS_CAPABLE      = 1019,
 802  818          CONTAINER       = 1020,
 803  819          CASTED_CALL     = 1021,
 804  820          TYPE_LINK       = 1022,
 805  821          UNTRACKED_PARAM = 1023,
      822 +        LOST_PARAM      = 2023,
 806  823          CULL_PATH       = 1024,
 807  824          PARAM_SET       = 1025,
 808  825          PARAM_USED      = 1026,
 809  826          BYTE_UNITS      = 1027,
 810  827          COMPARE_LIMIT   = 1028,
 811  828          PARAM_COMPARE   = 1029,
 812  829          CONSTRAINT      = 1031,
 813  830          PASSES_TYPE     = 1032,
 814  831          CONSTRAINT_REQUIRED = 1033,
      832 +        BIT_INFO        = 1034,
 815  833          NOSPEC          = 1035,
 816  834          NOSPEC_WB       = 1036,
 817  835          STMT_CNT        = 1037,
 818  836          TERMINATED      = 1038,
 819  837  
 820  838          /* put random temporary stuff in the 7000-7999 range for testing */
 821      -        USER_DATA3      = 8017,
 822      -        USER_DATA3_SET  = 9017,
      839 +        USER_DATA       = 8017,
      840 +        USER_DATA_SET   = 9017,
 823  841          NO_OVERFLOW     = 8018,
 824  842          NO_OVERFLOW_SIMPLE = 8019,
 825  843          LOCKED          = 8020,
 826  844          UNLOCKED        = 8021,
 827  845          SET_FS          = 8022,
 828  846          ATOMIC_INC      = 8023,
 829  847          ATOMIC_DEC      = 8024,
 830  848          NO_SIDE_EFFECT  = 8025,
 831  849          FN_ARG_LINK     = 8028,
 832  850          DATA_VALUE      = 8029,
 833  851          ARRAYSIZE_ARG   = 8033,
 834  852          SIZEOF_ARG      = 8034,
 835  853          MEMORY_TAG      = 8036,
 836  854          MTAG_ASSIGN     = 8035,
 837  855          STRING_VALUE    = 8041,
      856 +
      857 +        BYTE_COUNT      = 8050,
      858 +        ELEM_COUNT      = 8051,
      859 +        ELEM_LAST       = 8052,
      860 +        USED_LAST       = 8053,
      861 +        USED_COUNT      = 8054,
 838  862  };
 839  863  
 840  864  extern struct sqlite3 *smatch_db;
 841  865  extern struct sqlite3 *mem_db;
 842  866  extern struct sqlite3 *cache_db;
 843  867  
 844  868  void db_ignore_states(int id);
 845  869  void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
 846  870  void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm));
 847  871  void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
↓ open down ↓ 4 lines elided ↑ open up ↑
 852  876  struct range_list *db_return_vals_from_str(const char *fn_name);
 853  877  char *return_state_to_var_sym(struct expression *expr, int param, const char *key, struct symbol **sym);
 854  878  char *get_chunk_from_key(struct expression *arg, char *key, struct symbol **sym, struct var_sym_list **vsl);
 855  879  char *get_variable_from_key(struct expression *arg, const char *key, struct symbol **sym);
 856  880  const char *state_name_to_param_name(const char *state_name, const char *param_name);
 857  881  const char *get_param_name_var_sym(const char *name, struct symbol *sym);
 858  882  const char *get_param_name(struct sm_state *sm);
 859  883  const char *get_mtag_name_var_sym(const char *state_name, struct symbol *sym);
 860  884  const char *get_mtag_name_expr(struct expression *expr);
 861  885  char *get_data_info_name(struct expression *expr);
      886 +int is_recursive_member(const char *param_name);
 862  887  
 863  888  char *escape_newlines(const char *str);
 864  889  void sql_exec(struct sqlite3 *db, int (*callback)(void*, int, char**, char**), void *data, const char *sql);
 865  890  
 866  891  #define sql_helper(db, call_back, data, sql...)                                 \
 867  892  do {                                                                            \
 868  893          char sql_txt[1024];                                                     \
 869  894                                                                                  \
 870  895          sqlite3_snprintf(sizeof(sql_txt), sql_txt, sql);                        \
 871  896          sm_debug("debug: %s\n", sql_txt);                                       \
↓ open down ↓ 73 lines elided ↑ open up ↑
 945  970  void sql_insert_function_type(int param, const char *value);
 946  971  void sql_insert_parameter_name(int param, const char *value);
 947  972  void sql_insert_data_info(struct expression *data, int type, const char *value);
 948  973  void sql_insert_data_info_var_sym(const char *var, struct symbol *sym, int type, const char *value);
 949  974  void sql_save_constraint(const char *con);
 950  975  void sql_save_constraint_required(const char *data, int op, const char *limit);
 951  976  void sql_copy_constraint_required(const char *new_limit, const char *old_limit);
 952  977  void sql_insert_fn_ptr_data_link(const char *ptr, const char *data);
 953  978  void sql_insert_fn_data_link(struct expression *fn, int type, int param, const char *key, const char *value);
 954  979  void sql_insert_mtag_about(mtag_t tag, const char *left_name, const char *right_name);
 955      -void insert_mtag_data(sval_t sval, struct range_list *rl);
 956  980  void sql_insert_mtag_map(mtag_t tag, int offset, mtag_t container);
 957  981  void sql_insert_mtag_alias(mtag_t orig, mtag_t alias);
 958  982  int mtag_map_select_container(mtag_t tag, int offset, mtag_t *container);
 959  983  int mtag_map_select_tag(mtag_t container, int offset, mtag_t *tag);
      984 +struct smatch_state *swap_mtag_return(struct expression *expr, struct smatch_state *state);
      985 +struct range_list *swap_mtag_seed(struct expression *expr, struct range_list *rl);
 960  986  
 961  987  void sql_select_return_states(const char *cols, struct expression *call,
 962  988          int (*callback)(void*, int, char**, char**), void *info);
 963  989  void sql_select_call_implies(const char *cols, struct expression *call,
 964  990          int (*callback)(void*, int, char**, char**));
 965  991  
 966  992  void open_smatch_db(char *db_file);
 967  993  
 968  994  /* smatch_files.c */
 969  995  int open_data_file(const char *filename);
↓ open down ↓ 35 lines elided ↑ open up ↑
1005 1031  /* smatch_strlen.c */
1006 1032  int get_implied_strlen(struct expression *expr, struct range_list **rl);
1007 1033  int get_size_from_strlen(struct expression *expr);
1008 1034  
1009 1035  /* smatch_capped.c */
1010 1036  int is_capped(struct expression *expr);
1011 1037  int is_capped_var_sym(const char *name, struct symbol *sym);
1012 1038  
1013 1039  /* check_user_data.c */
1014 1040  int is_user_macro(struct expression *expr);
1015      -int is_user_data(struct expression *expr);
1016 1041  int is_capped_user_data(struct expression *expr);
1017 1042  int implied_user_data(struct expression *expr, struct range_list **rl);
1018 1043  struct stree *get_user_stree(void);
1019 1044  int get_user_rl(struct expression *expr, struct range_list **rl);
1020      -int get_user_rl_spammy(struct expression *expr, struct range_list **rl);
1021 1045  int is_user_rl(struct expression *expr);
1022 1046  int get_user_rl_var_sym(const char *name, struct symbol *sym, struct range_list **rl);
     1047 +bool user_rl_capped(struct expression *expr);
     1048 +struct range_list *var_user_rl(struct expression *expr);
1023 1049  
1024 1050  /* check_locking.c */
1025 1051  void print_held_locks();
1026 1052  
1027 1053  /* check_assigned_expr.c */
1028 1054  struct expression *get_assigned_expr(struct expression *expr);
1029 1055  struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym);
1030 1056  /* smatch_return_to_param.c */
1031 1057  void __add_return_to_param_mapping(struct expression *assign, const char *return_string);
1032 1058  char *map_call_to_param_name_sym(struct expression *expr, struct symbol **sym);
↓ open down ↓ 15 lines elided ↑ open up ↑
1048 1074                  const char *left_var, struct var_sym_list *left_vsl,
1049 1075                  int comparison,
1050 1076                  struct expression *right,
1051 1077                  const char *right_var, struct var_sym_list *right_vsl);
1052 1078  int filter_comparison(int orig, int op);
1053 1079  int merge_comparisons(int one, int two);
1054 1080  int combine_comparisons(int left_compare, int right_compare);
1055 1081  int state_to_comparison(struct smatch_state *state);
1056 1082  struct smatch_state *merge_compare_states(struct smatch_state *s1, struct smatch_state *s2);
1057 1083  int get_comparison(struct expression *left, struct expression *right);
     1084 +int get_comparison_no_extra(struct expression *a, struct expression *b);
1058 1085  int get_comparison_strings(const char *one, const char *two);
1059 1086  int possible_comparison(struct expression *a, int comparison, struct expression *b);
1060 1087  struct state_list *get_all_comparisons(struct expression *expr);
1061 1088  struct state_list *get_all_possible_equal_comparisons(struct expression *expr);
1062 1089  void __add_return_comparison(struct expression *call, const char *range);
1063 1090  void __add_comparison_info(struct expression *expr, struct expression *call, const char *range);
1064 1091  char *get_printed_param_name(struct expression *call, const char *param_name, struct symbol *param_sym);
1065 1092  char *name_sym_to_param_comparison(const char *name, struct symbol *sym);
1066 1093  char *expr_equal_to_param(struct expression *expr, int ignore);
1067 1094  char *expr_lte_to_param(struct expression *expr, int ignore);
↓ open down ↓ 34 lines elided ↑ open up ↑
1102 1129  sval_t sval_min(sval_t one, sval_t two);
1103 1130  sval_t sval_max(sval_t one, sval_t two);
1104 1131  int sval_too_low(struct symbol *type, sval_t sval);
1105 1132  int sval_too_high(struct symbol *type, sval_t sval);
1106 1133  int sval_fits(struct symbol *type, sval_t sval);
1107 1134  sval_t sval_cast(struct symbol *type, sval_t sval);
1108 1135  sval_t sval_preop(sval_t sval, int op);
1109 1136  sval_t sval_binop(sval_t left, int op, sval_t right);
1110 1137  int sval_binop_overflows(sval_t left, int op, sval_t right);
1111 1138  int sval_binop_overflows_no_sign(sval_t left, int op, sval_t right);
     1139 +int find_first_zero_bit(unsigned long long uvalue);
     1140 +int sm_fls64(unsigned long long uvalue);
1112 1141  unsigned long long fls_mask(unsigned long long uvalue);
1113 1142  unsigned long long sval_fls_mask(sval_t sval);
1114 1143  const char *sval_to_str(sval_t sval);
     1144 +const char *sval_to_str_or_err_ptr(sval_t sval);
1115 1145  const char *sval_to_numstr(sval_t sval);
1116 1146  sval_t ll_to_sval(long long val);
1117 1147  
1118 1148  /* smatch_string_list.c */
1119 1149  int list_has_string(struct string_list *str_list, const char *str);
1120      -void insert_string(struct string_list **str_list, const char *str);
     1150 +int insert_string(struct string_list **str_list, const char *str);
1121 1151  struct string_list *clone_str_list(struct string_list *orig);
1122 1152  struct string_list *combine_string_lists(struct string_list *one, struct string_list *two);
1123 1153  
1124 1154  /* smatch_start_states.c */
1125 1155  struct stree *get_start_states(void);
1126 1156  
1127 1157  /* smatch_recurse.c */
1128 1158  int has_symbol(struct expression *expr, struct symbol *sym);
1129 1159  int has_variable(struct expression *expr, struct expression *var);
1130 1160  int has_inc_dec(struct expression *expr);
1131 1161  
1132 1162  /* smatch_stored_conditions.c */
1133 1163  struct smatch_state *get_stored_condition(struct expression *expr);
1134 1164  struct expression_list *get_conditions(struct expression *expr);
1135 1165  struct sm_state *stored_condition_implication_hook(struct expression *expr,
1136 1166                          struct state_list **true_stack,
1137 1167                          struct state_list **false_stack);
1138 1168  
1139 1169  /* check_string_len.c */
1140 1170  int get_formatted_string_size(struct expression *call, int arg);
     1171 +int get_formatted_string_min_size(struct expression *call, int arg);
1141 1172  
1142 1173  /* smatch_param_set.c */
1143 1174  int param_was_set(struct expression *expr);
1144 1175  int param_was_set_var_sym(const char *name, struct symbol *sym);
1145 1176  /* smatch_param_filter.c */
1146 1177  int param_has_filter_data(struct sm_state *sm);
1147 1178  
1148 1179  /* smatch_links.c */
1149 1180  void set_up_link_functions(int id, int linkid);
1150 1181  struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2);
1151 1182  void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym);
1152 1183  
1153 1184  /* smatch_auto_copy.c */
1154 1185  void set_auto_copy(int owner);
1155 1186  
1156 1187  /* check_buf_comparison */
1157      -struct expression *get_size_variable(struct expression *buf);
     1188 +const char *limit_type_str(unsigned int limit_type);
     1189 +struct expression *get_size_variable(struct expression *buf, int *limit_type);
1158 1190  struct expression *get_array_variable(struct expression *size);
     1191 +int buf_comparison_index_ok(struct expression *expr);
1159 1192  
1160 1193  /* smatch_untracked_param.c */
1161 1194  void mark_untracked(struct expression *expr, int param, const char *key, const char *value);
1162 1195  void add_untracked_param_hook(void (func)(struct expression *call, int param));
     1196 +void add_lost_param_hook(void (func)(struct expression *call, int param));
1163 1197  void mark_all_params_untracked(int return_id, char *return_ranges, struct expression *expr);
1164 1198  
1165 1199  /* smatch_strings.c */
1166 1200  struct state_list *get_strings(struct expression *expr);
1167 1201  struct expression *fake_string_from_mtag(mtag_t tag);
1168 1202  
1169 1203  /* smatch_estate.c */
1170 1204  int estate_get_single_value(struct smatch_state *state, sval_t *sval);
1171 1205  
1172 1206  /* smatch_address.c */
↓ open down ↓ 14 lines elided ↑ open up ↑
1187 1221  
1188 1222  /* smatch_constraints.c */
1189 1223  char *get_constraint_str(struct expression *expr);
1190 1224  struct constraint_list *get_constraints(struct expression *expr);
1191 1225  char *unmet_constraint(struct expression *data, struct expression *offset);
1192 1226  char *get_required_constraint(const char *data_str);
1193 1227  
1194 1228  /* smatch_container_of.c */
1195 1229  int get_param_from_container_of(struct expression *expr);
1196 1230  int get_offset_from_container_of(struct expression *expr);
     1231 +char *get_container_name(struct expression *container, struct expression *expr);
1197 1232  
1198 1233  /* smatch_mtag.c */
1199 1234  int get_string_mtag(struct expression *expr, mtag_t *tag);
1200 1235  int get_toplevel_mtag(struct symbol *sym, mtag_t *tag);
1201      -int get_mtag(struct expression *expr, mtag_t *tag);
1202      -int get_mtag_offset(struct expression *expr, mtag_t *tag, int *offset);
1203 1236  int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new);
1204 1237  int expr_to_mtag_offset(struct expression *expr, mtag_t *tag, int *offset);
1205 1238  void update_mtag_data(struct expression *expr);
1206 1239  int get_mtag_sval(struct expression *expr, sval_t *sval);
1207      -int get_mtag_addr_sval(struct expression *expr, sval_t *sval);
1208 1240  
1209 1241  /* Trinity fuzzer stuff */
1210 1242  const char *get_syscall_arg_type(struct symbol *sym);
1211 1243  
     1244 +/* smatch_bit_info.c */
     1245 +struct bit_info *get_bit_info(struct expression *expr);
     1246 +struct bit_info *get_bit_info_var_sym(const char *name, struct symbol *sym);
1212 1247  /* smatch_mem_tracker.c */
1213 1248  extern int option_mem;
     1249 +unsigned long get_mem_kb(void);
1214 1250  unsigned long get_max_memory(void);
1215 1251  
1216 1252  /* check_is_nospec.c */
1217 1253  bool is_nospec(struct expression *expr);
     1254 +long get_stmt_cnt(void);
1218 1255  
1219 1256  /* smatch_nul_terminator.c */
1220 1257  bool is_nul_terminated(struct expression *expr);
     1258 +/* check_kernel.c  */
     1259 +bool is_ignored_kernel_data(const char *name);
1221 1260  
     1261 +static inline bool type_is_ptr(struct symbol *type)
     1262 +{
     1263 +        return type &&
     1264 +               (type->type == SYM_PTR ||
     1265 +                type->type == SYM_ARRAY ||
     1266 +                type->type == SYM_FN);
     1267 +}
     1268 +
1222 1269  static inline int type_bits(struct symbol *type)
1223 1270  {
1224 1271          if (!type)
1225 1272                  return 0;
1226      -        if (type->type == SYM_PTR)  /* Sparse doesn't set this for &pointers */
     1273 +        if (type_is_ptr(type))
1227 1274                  return bits_in_pointer;
1228      -        if (type->type == SYM_ARRAY)
1229      -                return bits_in_pointer;
1230 1275          if (!type->examined)
1231 1276                  examine_symbol_type(type);
1232 1277          return type->bit_size;
1233 1278  }
1234 1279  
1235      -static inline bool type_is_ptr(struct symbol *type)
1236      -{
1237      -        return type && (type->type == SYM_PTR || type->type == SYM_ARRAY);
1238      -}
1239      -
1240 1280  static inline int type_unsigned(struct symbol *base_type)
1241 1281  {
1242 1282          if (!base_type)
1243 1283                  return 0;
     1284 +        if (is_ptr_type(base_type))
     1285 +                return 1;
1244 1286          if (base_type->ctype.modifiers & MOD_UNSIGNED)
1245 1287                  return 1;
1246 1288          return 0;
1247 1289  }
1248 1290  
1249 1291  static inline int type_positive_bits(struct symbol *type)
1250 1292  {
1251 1293          if (!type)
1252 1294                  return 0;
1253      -        if (type->type == SYM_ARRAY)
1254      -                return bits_in_pointer - 1;
     1295 +        if (is_ptr_type(type))
     1296 +                return bits_in_pointer;
1255 1297          if (type_unsigned(type))
1256 1298                  return type_bits(type);
1257 1299          return type_bits(type) - 1;
1258 1300  }
1259 1301  
1260 1302  static inline int sval_positive_bits(sval_t sval)
1261 1303  {
1262 1304          return type_positive_bits(sval.type);
1263 1305  }
1264 1306  
↓ open down ↓ 32 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX