Print this page
new smatch


  42         delete_ptr_list_last((struct ptr_list **)stack_stack);
  43         return stack;
  44 }
  45 
  46 static struct stree_stack *return_stree_stack;
  47 static struct stree_stack_stack *saved_stack_stack;
  48 static struct stree *all_return_states;
  49 static struct stree_stack *saved_stack;
  50 
  51 void all_return_states_hook(void (*callback)(void))
  52 {
  53         struct return_states_callback *rs_cb = __alloc_return_states_callback(0);
  54 
  55         rs_cb->callback = callback;
  56         add_ptr_list(&callback_list, rs_cb);
  57 }
  58 
  59 static void call_hooks(void)
  60 {
  61         struct return_states_callback *rs_cb;

  62 
  63         __set_fake_cur_stree_fast(all_return_states);
  64         FOR_EACH_PTR(callback_list, rs_cb) {
  65                 rs_cb->callback();
  66         } END_FOR_EACH_PTR(rs_cb);
  67         __pop_fake_cur_stree_fast();
  68 }
  69 
  70 static void match_return(int return_id, char *return_ranges, struct expression *expr)
  71 {
  72         struct stree *stree;
  73 
  74         stree = clone_stree(__get_cur_stree());
  75         merge_stree_no_pools(&all_return_states, stree);
  76         push_stree(&return_stree_stack, stree);
  77 }
  78 
  79 static void match_end_func(struct symbol *sym)
  80 {
  81         /*
  82          * FIXME: either this isn't needed or we need to copy a stree into the
  83          * return_stree_stack as well.
  84          */
  85         merge_stree(&all_return_states, __get_cur_stree());
  86         call_hooks();
  87 }


  99 {
 100         /* This free_stree() isn't needed is it?? */
 101         free_stree(&all_return_states);
 102 
 103         all_return_states = pop_stree(&saved_stack);
 104         return_stree_stack = pop_stree_stack(&saved_stack_stack);
 105 }
 106 
 107 struct stree *get_all_return_states(void)
 108 {
 109         return all_return_states;
 110 }
 111 
 112 struct stree_stack *get_all_return_strees(void)
 113 {
 114         return return_stree_stack;
 115 }
 116 
 117 static void free_resources(struct symbol *sym)
 118 {
 119         struct stree *tmp;
 120 
 121         free_stree(&all_return_states);
 122 
 123         FOR_EACH_PTR(return_stree_stack, tmp) {
 124                 free_stree(&tmp);
 125         } END_FOR_EACH_PTR(tmp);
 126         free_stree_stack(&return_stree_stack);
 127 }
 128 
 129 void register_returns_early(int id)
 130 {
 131         RETURN_ID = id;
 132 
 133         set_dynamic_states(RETURN_ID);
 134         add_split_return_callback(match_return);
 135 }
 136 
 137 void register_returns(int id)
 138 {
 139         add_hook(&match_end_func, END_FUNC_HOOK);
 140         add_hook(&match_save_states, INLINE_FN_START);
 141         add_hook(&match_restore_states, INLINE_FN_END);
 142         add_hook(&free_resources, AFTER_FUNC_HOOK);
 143 }


  42         delete_ptr_list_last((struct ptr_list **)stack_stack);
  43         return stack;
  44 }
  45 
  46 static struct stree_stack *return_stree_stack;
  47 static struct stree_stack_stack *saved_stack_stack;
  48 static struct stree *all_return_states;
  49 static struct stree_stack *saved_stack;
  50 
  51 void all_return_states_hook(void (*callback)(void))
  52 {
  53         struct return_states_callback *rs_cb = __alloc_return_states_callback(0);
  54 
  55         rs_cb->callback = callback;
  56         add_ptr_list(&callback_list, rs_cb);
  57 }
  58 
  59 static void call_hooks(void)
  60 {
  61         struct return_states_callback *rs_cb;
  62         struct stree *orig;
  63 
  64         orig = __swap_cur_stree(all_return_states);
  65         FOR_EACH_PTR(callback_list, rs_cb) {
  66                 rs_cb->callback();
  67         } END_FOR_EACH_PTR(rs_cb);
  68         __swap_cur_stree(orig);
  69 }
  70 
  71 static void match_return(int return_id, char *return_ranges, struct expression *expr)
  72 {
  73         struct stree *stree;
  74 
  75         stree = clone_stree(__get_cur_stree());
  76         merge_stree_no_pools(&all_return_states, stree);
  77         push_stree(&return_stree_stack, stree);
  78 }
  79 
  80 static void match_end_func(struct symbol *sym)
  81 {
  82         /*
  83          * FIXME: either this isn't needed or we need to copy a stree into the
  84          * return_stree_stack as well.
  85          */
  86         merge_stree(&all_return_states, __get_cur_stree());
  87         call_hooks();
  88 }


 100 {
 101         /* This free_stree() isn't needed is it?? */
 102         free_stree(&all_return_states);
 103 
 104         all_return_states = pop_stree(&saved_stack);
 105         return_stree_stack = pop_stree_stack(&saved_stack_stack);
 106 }
 107 
 108 struct stree *get_all_return_states(void)
 109 {
 110         return all_return_states;
 111 }
 112 
 113 struct stree_stack *get_all_return_strees(void)
 114 {
 115         return return_stree_stack;
 116 }
 117 
 118 static void free_resources(struct symbol *sym)
 119 {


 120         free_stree(&all_return_states);
 121         free_stack_and_strees(&return_stree_stack);




 122 }
 123 
 124 void register_returns_early(int id)
 125 {
 126         RETURN_ID = id;
 127 
 128         set_dynamic_states(RETURN_ID);
 129         add_split_return_callback(match_return);
 130 }
 131 
 132 void register_returns(int id)
 133 {
 134         add_hook(&match_end_func, END_FUNC_HOOK);
 135         add_hook(&match_save_states, INLINE_FN_START);
 136         add_hook(&match_restore_states, INLINE_FN_END);
 137         add_hook(&free_resources, AFTER_FUNC_HOOK);
 138 }