function_ptrs: allow function pointers to be stored to ulong struct members
[smatch.git] / smatch_buf_size.c
blob27d8bbde7ba883f96cbc0becc69acfb09ad0a4f2
1 /*
2 * Copyright (C) 2010 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 #include <stdlib.h>
19 #include <errno.h>
20 #include "parse.h"
21 #include "smatch.h"
22 #include "smatch_slist.h"
23 #include "smatch_extra.h"
24 #include "smatch_function_hashtable.h"
26 #define UNKNOWN_SIZE (-1)
28 static int my_size_id;
30 static DEFINE_HASHTABLE_INSERT(insert_func, char, int);
31 static DEFINE_HASHTABLE_SEARCH(search_func, char, int);
32 static struct hashtable *allocation_funcs;
34 static char *get_fn_name(struct expression *expr)
36 if (expr->type != EXPR_CALL)
37 return NULL;
38 if (expr->fn->type != EXPR_SYMBOL)
39 return NULL;
40 return expr_to_var(expr->fn);
43 static int is_allocation_function(struct expression *expr)
45 char *func;
46 int ret = 0;
48 func = get_fn_name(expr);
49 if (!func)
50 return 0;
51 if (search_func(allocation_funcs, func))
52 ret = 1;
53 free_string(func);
54 return ret;
57 static void add_allocation_function(const char *func, void *call_back, int param)
59 insert_func(allocation_funcs, (char *)func, (int *)1);
60 add_function_assign_hook(func, call_back, INT_PTR(param));
63 static int estate_to_size(struct smatch_state *state)
65 sval_t sval;
67 if (!state || !estate_rl(state))
68 return 0;
69 sval = estate_max(state);
70 return sval.value;
73 static struct smatch_state *size_to_estate(int size)
75 sval_t sval;
77 sval.type = &int_ctype;
78 sval.value = size;
80 return alloc_estate_sval(sval);
83 static struct range_list *size_to_rl(int size)
85 sval_t sval;
87 sval.type = &int_ctype;
88 sval.value = size;
90 return alloc_rl(sval, sval);
93 static struct smatch_state *unmatched_size_state(struct sm_state *sm)
95 return size_to_estate(UNKNOWN_SIZE);
98 static void set_size_undefined(struct sm_state *sm, struct expression *mod_expr)
100 set_state(sm->owner, sm->name, sm->sym, size_to_estate(UNKNOWN_SIZE));
103 static struct smatch_state *merge_size_func(struct smatch_state *s1, struct smatch_state *s2)
105 return merge_estates(s1, s2);
108 void set_param_buf_size(const char *name, struct symbol *sym, char *key, char *value)
110 struct range_list *rl = NULL;
111 struct smatch_state *state;
112 char fullname[256];
114 if (strncmp(key, "$", 1) != 0)
115 return;
117 snprintf(fullname, 256, "%s%s", name, key + 1);
119 str_to_rl(&int_ctype, value, &rl);
120 if (!rl || is_whole_rl(rl))
121 return;
122 state = alloc_estate_rl(rl);
123 set_state(my_size_id, fullname, sym, state);
126 static int bytes_per_element(struct expression *expr)
128 struct symbol *type;
130 if (!expr)
131 return 0;
132 if (expr->type == EXPR_STRING)
133 return 1;
134 if (expr->type == EXPR_PREOP && expr->op == '&') {
135 type = get_type(expr->unop);
136 if (type && type->type == SYM_ARRAY)
137 expr = expr->unop;
139 type = get_type(expr);
140 if (!type)
141 return 0;
143 if (type->type != SYM_PTR && type->type != SYM_ARRAY)
144 return 0;
146 type = get_base_type(type);
147 return type_bytes(type);
150 static int bytes_to_elements(struct expression *expr, int bytes)
152 int bpe;
154 bpe = bytes_per_element(expr);
155 if (bpe == 0)
156 return 0;
157 return bytes / bpe;
160 static int elements_to_bytes(struct expression *expr, int elements)
162 int bpe;
164 bpe = bytes_per_element(expr);
165 return elements * bpe;
168 static int get_initializer_size(struct expression *expr)
170 switch (expr->type) {
171 case EXPR_STRING:
172 return expr->string->length;
173 case EXPR_INITIALIZER: {
174 struct expression *tmp;
175 int i = 0;
177 FOR_EACH_PTR(expr->expr_list, tmp) {
178 if (tmp->type == EXPR_INDEX) {
179 if (tmp->idx_to >= i)
180 i = tmp->idx_to;
181 else
182 continue;
185 i++;
186 } END_FOR_EACH_PTR(tmp);
187 return i;
189 case EXPR_SYMBOL:
190 return get_array_size(expr);
192 return 0;
195 static struct range_list *db_size_rl;
196 static int db_size_callback(void *unused, int argc, char **argv, char **azColName)
198 struct range_list *tmp = NULL;
200 if (!db_size_rl) {
201 str_to_rl(&int_ctype, argv[0], &db_size_rl);
202 } else {
203 str_to_rl(&int_ctype, argv[0], &tmp);
204 db_size_rl = rl_union(db_size_rl, tmp);
206 return 0;
209 static struct range_list *size_from_db_type(struct expression *expr)
211 int this_file_only = 0;
212 char *name;
214 name = get_member_name(expr);
215 if (!name && is_static(expr)) {
216 name = expr_to_var(expr);
217 this_file_only = 1;
219 if (!name)
220 return NULL;
222 if (this_file_only) {
223 db_size_rl = NULL;
224 run_sql(db_size_callback, NULL,
225 "select size from function_type_size where type = '%s' and file = '%s';",
226 name, get_filename());
227 if (db_size_rl)
228 return db_size_rl;
229 return NULL;
232 db_size_rl = NULL;
233 run_sql(db_size_callback, NULL,
234 "select size from type_size where type = '%s';",
235 name);
236 return db_size_rl;
239 static struct range_list *size_from_db_symbol(struct expression *expr)
241 struct symbol *sym;
243 if (expr->type != EXPR_SYMBOL)
244 return NULL;
245 sym = expr->symbol;
246 if (!sym->ident ||
247 !(sym->ctype.modifiers & MOD_TOPLEVEL) ||
248 sym->ctype.modifiers & MOD_STATIC)
249 return NULL;
251 db_size_rl = NULL;
252 run_sql(db_size_callback, NULL,
253 "select value from data_info where file = 'extern' and data = '%s' and type = %d;",
254 sym->ident->name, BUF_SIZE);
255 return db_size_rl;
258 static struct range_list *size_from_db(struct expression *expr)
260 struct range_list *rl;
262 rl = size_from_db_symbol(expr);
263 if (rl)
264 return rl;
265 return size_from_db_type(expr);
268 static void db_returns_buf_size(struct expression *expr, int param, char *unused, char *math)
270 struct expression *call;
271 struct range_list *rl;
273 if (expr->type != EXPR_ASSIGNMENT)
274 return;
275 call = strip_expr(expr->right);
277 if (!parse_call_math_rl(call, math, &rl))
278 return;
279 rl = cast_rl(&int_ctype, rl);
280 set_state_expr(my_size_id, expr->left, alloc_estate_rl(rl));
283 static int get_real_array_size_from_type(struct symbol *type)
285 sval_t sval;
287 if (!type)
288 return 0;
289 if (!type || type->type != SYM_ARRAY)
290 return 0;
292 if (!get_implied_value(type->array_size, &sval))
293 return 0;
295 /* People put one element arrays on the end of structs */
296 if (sval.value == 1)
297 return 0;
299 return sval.value;
302 int get_real_array_size(struct expression *expr)
304 if (!expr)
305 return 0;
306 if (expr->type == EXPR_PREOP && expr->op == '&')
307 expr = expr->unop;
308 if (expr->type == EXPR_BINOP) /* array elements foo[5] */
309 return 0;
310 return get_real_array_size_from_type(get_type(expr));
313 static int get_size_from_initializer(struct expression *expr)
315 if (expr->type != EXPR_SYMBOL || !expr->symbol || !expr->symbol->initializer)
316 return 0;
317 if (expr->symbol->initializer == expr) /* int a = a; */
318 return 0;
319 return get_initializer_size(expr->symbol->initializer);
322 static struct range_list *get_stored_size_bytes(struct expression *expr)
324 struct smatch_state *state;
326 state = get_state_expr(my_size_id, expr);
327 if (!state)
328 return NULL;
329 return estate_rl(state);
332 static int get_bytes_from_address(struct expression *expr)
334 struct symbol *type;
335 int ret;
337 if (!option_spammy)
338 return 0;
339 if (expr->type != EXPR_PREOP || expr->op != '&')
340 return 0;
341 type = get_type(expr);
342 if (!type)
343 return 0;
345 if (type->type == SYM_PTR)
346 type = get_base_type(type);
348 ret = type_bytes(type);
349 if (ret == 1)
350 return 0; /* ignore char pointers */
352 return ret;
355 static struct expression *remove_addr_fluff(struct expression *expr)
357 struct expression *tmp;
358 sval_t sval;
360 expr = strip_expr(expr);
362 /* remove '&' and '*' operations that cancel */
363 while (expr && expr->type == EXPR_PREOP && expr->op == '&') {
364 tmp = strip_expr(expr->unop);
365 if (tmp->type != EXPR_PREOP)
366 break;
367 if (tmp->op != '*')
368 break;
369 expr = strip_expr(tmp->unop);
372 if (!expr)
373 return NULL;
375 /* "foo + 0" is just "foo" */
376 if (expr->type == EXPR_BINOP && expr->op == '+' &&
377 get_value(expr->right, &sval) && sval.value == 0)
378 return expr->left;
380 return expr;
383 static int is_last_member_of_struct(struct symbol *sym, struct ident *member)
385 struct symbol *tmp;
386 int i;
388 i = 0;
389 FOR_EACH_PTR_REVERSE(sym->symbol_list, tmp) {
390 if (i++ || !tmp->ident)
391 return 0;
392 if (tmp->ident == member)
393 return 1;
394 return 0;
395 } END_FOR_EACH_PTR_REVERSE(tmp);
397 return 0;
400 static int last_member_is_resizable(struct symbol *sym)
402 struct symbol *last_member;
403 struct symbol *type;
404 sval_t sval;
406 last_member = last_ptr_list((struct ptr_list *)sym->symbol_list);
407 if (!last_member || !last_member->ident)
408 return 0;
410 type = get_real_base_type(last_member);
411 if (type->type == SYM_STRUCT)
412 return last_member_is_resizable(type);
413 if (type->type != SYM_ARRAY)
414 return 0;
416 if (!get_implied_value(type->array_size, &sval))
417 return 0;
419 if (sval.value != 0 && sval.value != 1)
420 return 0;
422 return 1;
425 static int get_stored_size_end_struct_bytes(struct expression *expr)
427 struct symbol *sym;
428 struct symbol *base_sym;
429 struct smatch_state *state;
431 if (expr->type == EXPR_BINOP) /* array elements foo[5] */
432 return 0;
434 if (expr->type == EXPR_PREOP && expr->op == '&')
435 expr = strip_parens(expr->unop);
437 sym = expr_to_sym(expr);
438 if (!sym || !sym->ident)
439 return 0;
440 if (!type_bytes(sym))
441 return 0;
442 if (sym->type != SYM_NODE)
443 return 0;
445 base_sym = get_real_base_type(sym);
446 if (!base_sym || base_sym->type != SYM_PTR)
447 return 0;
448 base_sym = get_real_base_type(base_sym);
449 if (!base_sym || base_sym->type != SYM_STRUCT)
450 return 0;
452 if (!is_last_member_of_struct(base_sym, expr->member))
453 return 0;
454 if (!last_member_is_resizable(base_sym))
455 return 0;
457 state = get_state(my_size_id, sym->ident->name, sym);
458 if (!estate_to_size(state))
459 return 0;
461 return estate_to_size(state) - type_bytes(base_sym) + type_bytes(get_type(expr));
464 static struct range_list *alloc_int_rl(int value)
466 sval_t sval = {
467 .type = &int_ctype,
468 {.value = value},
471 return alloc_rl(sval, sval);
474 struct range_list *get_array_size_bytes_rl(struct expression *expr)
476 struct range_list *ret = NULL;
477 int size;
479 expr = remove_addr_fluff(expr);
480 if (!expr)
481 return NULL;
483 /* "BAR" */
484 if (expr->type == EXPR_STRING)
485 return alloc_int_rl(expr->string->length);
487 if (expr->type == EXPR_BINOP && expr->op == '+') {
488 sval_t offset;
489 struct symbol *type;
490 int bytes;
492 if (!get_implied_value(expr->right, &offset))
493 return NULL;
494 type = get_type(expr->left);
495 if (!type)
496 return NULL;
497 if (type->type != SYM_ARRAY && type->type != SYM_PTR)
498 return NULL;
499 type = get_real_base_type(type);
500 bytes = type_bytes(type);
501 if (bytes == 0)
502 return NULL;
503 offset.value *= bytes;
504 size = get_array_size_bytes(expr->left);
505 if (size <= 0)
506 return NULL;
507 return alloc_int_rl(size - offset.value);
510 /* buf[4] */
511 size = get_real_array_size(expr);
512 if (size)
513 return alloc_int_rl(elements_to_bytes(expr, size));
515 /* buf = malloc(1024); */
516 ret = get_stored_size_bytes(expr);
517 if (ret)
518 return ret;
520 size = get_stored_size_end_struct_bytes(expr);
521 if (size)
522 return alloc_int_rl(size);
524 /* char *foo = "BAR" */
525 size = get_size_from_initializer(expr);
526 if (size)
527 return alloc_int_rl(elements_to_bytes(expr, size));
529 size = get_bytes_from_address(expr);
530 if (size)
531 return alloc_int_rl(size);
533 ret = size_from_db(expr);
534 if (ret)
535 return ret;
537 return NULL;
540 int get_array_size_bytes(struct expression *expr)
542 struct range_list *rl;
543 sval_t sval;
545 rl = get_array_size_bytes_rl(expr);
546 if (!rl_to_sval(rl, &sval))
547 return 0;
548 if (sval.uvalue >= INT_MAX)
549 return 0;
550 return sval.value;
553 int get_array_size_bytes_max(struct expression *expr)
555 struct range_list *rl;
556 sval_t bytes;
558 rl = get_array_size_bytes_rl(expr);
559 if (!rl)
560 return 0;
561 bytes = rl_min(rl);
562 if (bytes.value < 0)
563 return 0;
564 bytes = rl_max(rl);
565 if (bytes.uvalue >= INT_MAX)
566 return 0;
567 return bytes.value;
570 int get_array_size_bytes_min(struct expression *expr)
572 struct range_list *rl;
573 struct data_range *range;
575 rl = get_array_size_bytes_rl(expr);
576 if (!rl)
577 return 0;
579 FOR_EACH_PTR(rl, range) {
580 if (range->min.value <= 0)
581 return 0;
582 if (range->max.value <= 0)
583 return 0;
584 if (range->min.uvalue >= INT_MAX)
585 return 0;
586 return range->min.value;
587 } END_FOR_EACH_PTR(range);
589 return 0;
592 int get_array_size(struct expression *expr)
594 if (!expr)
595 return 0;
596 return bytes_to_elements(expr, get_array_size_bytes_max(expr));
599 static struct expression *strip_ampersands(struct expression *expr)
601 struct symbol *type;
603 if (expr->type != EXPR_PREOP)
604 return expr;
605 if (expr->op != '&')
606 return expr;
607 type = get_type(expr->unop);
608 if (!type || type->type != SYM_ARRAY)
609 return expr;
610 return expr->unop;
613 static void info_record_alloction(struct expression *buffer, struct range_list *rl)
615 char *name;
617 if (!option_info)
618 return;
620 name = get_member_name(buffer);
621 if (!name && is_static(buffer))
622 name = expr_to_var(buffer);
623 if (!name)
624 return;
625 if (rl && !is_whole_rl(rl))
626 sql_insert_function_type_size(name, show_rl(rl));
627 else
628 sql_insert_function_type_size(name, "(-1)");
630 free_string(name);
633 static void store_alloc(struct expression *expr, struct range_list *rl)
635 struct symbol *type;
637 rl = clone_rl(rl); // FIXME!!!
638 set_state_expr(my_size_id, expr, alloc_estate_rl(rl));
640 type = get_type(expr);
641 if (!type)
642 return;
643 if (type->type != SYM_PTR)
644 return;
645 type = get_real_base_type(type);
646 if (!type)
647 return;
648 if (type == &void_ctype)
649 return;
650 if (type->type != SYM_BASETYPE && type->type != SYM_PTR)
651 return;
653 info_record_alloction(expr, rl);
656 static void match_array_assignment(struct expression *expr)
658 struct expression *left;
659 struct expression *right;
660 char *left_member, *right_member;
661 struct range_list *rl;
662 sval_t sval;
664 if (expr->op != '=')
665 return;
666 left = strip_expr(expr->left);
667 right = strip_expr(expr->right);
668 right = strip_ampersands(right);
670 if (!is_pointer(left))
671 return;
672 if (is_allocation_function(right))
673 return;
675 left_member = get_member_name(left);
676 right_member = get_member_name(right);
677 if (left_member && right_member && strcmp(left_member, right_member) == 0) {
678 free_string(left_member);
679 free_string(right_member);
680 return;
682 free_string(left_member);
683 free_string(right_member);
685 if (get_implied_value(right, &sval) && sval.value == 0) {
686 rl = alloc_int_rl(0);
687 goto store;
690 rl = get_array_size_bytes_rl(right);
692 store:
693 store_alloc(left, rl);
696 static void match_alloc(const char *fn, struct expression *expr, void *_size_arg)
698 int size_arg = PTR_INT(_size_arg);
699 struct expression *right;
700 struct expression *arg;
701 struct range_list *rl;
703 right = strip_expr(expr->right);
704 arg = get_argument_from_call_expr(right->args, size_arg);
705 get_absolute_rl(arg, &rl);
706 rl = cast_rl(&int_ctype, rl);
707 store_alloc(expr->left, rl);
710 static void match_calloc(const char *fn, struct expression *expr, void *unused)
712 struct expression *right;
713 struct expression *arg;
714 sval_t elements;
715 sval_t size;
717 right = strip_expr(expr->right);
718 arg = get_argument_from_call_expr(right->args, 0);
719 if (!get_implied_value(arg, &elements))
720 return; // FIXME!!!
721 arg = get_argument_from_call_expr(right->args, 1);
722 if (get_implied_value(arg, &size))
723 store_alloc(expr->left, size_to_rl(elements.value * size.value));
724 else
725 store_alloc(expr->left, size_to_rl(-1));
728 static void match_page(const char *fn, struct expression *expr, void *_unused)
730 sval_t page_size = {
731 .type = &int_ctype,
732 {.value = 4096},
735 store_alloc(expr->left, alloc_rl(page_size, page_size));
738 static void match_strndup(const char *fn, struct expression *expr, void *unused)
740 struct expression *fn_expr;
741 struct expression *size_expr;
742 sval_t size;
744 fn_expr = strip_expr(expr->right);
745 size_expr = get_argument_from_call_expr(fn_expr->args, 1);
746 if (get_implied_max(size_expr, &size)) {
747 size.value++;
748 store_alloc(expr->left, size_to_rl(size.value));
749 } else {
750 store_alloc(expr->left, size_to_rl(-1));
755 static void match_alloc_pages(const char *fn, struct expression *expr, void *_order_arg)
757 int order_arg = PTR_INT(_order_arg);
758 struct expression *right;
759 struct expression *arg;
760 sval_t sval;
762 right = strip_expr(expr->right);
763 arg = get_argument_from_call_expr(right->args, order_arg);
764 if (!get_implied_value(arg, &sval))
765 return;
766 if (sval.value < 0 || sval.value > 10)
767 return;
769 sval.type = &int_ctype;
770 sval.value = 1 << sval.value;
771 sval.value *= 4096;
773 store_alloc(expr->left, alloc_rl(sval, sval));
776 static void match_call(struct expression *expr)
778 struct expression *arg;
779 struct symbol *type;
780 struct range_list *rl;
781 int i;
783 i = -1;
784 FOR_EACH_PTR(expr->args, arg) {
785 i++;
786 type = get_type(arg);
787 if (!type || (type->type != SYM_PTR && type->type != SYM_ARRAY))
788 continue;
789 rl = get_array_size_bytes_rl(arg);
790 if (!rl)
791 continue;
792 if (is_whole_rl(rl))
793 continue;
794 sql_insert_caller_info(expr, BUF_SIZE, i, "$", show_rl(rl));
795 } END_FOR_EACH_PTR(arg);
798 static void struct_member_callback(struct expression *call, int param, char *printed_name, struct sm_state *sm)
800 if (sm->state == &merged ||
801 strcmp(sm->state->name, "(-1)") == 0 ||
802 strcmp(sm->state->name, "empty") == 0 ||
803 strcmp(sm->state->name, "0") == 0)
804 return;
805 sql_insert_caller_info(call, BUF_SIZE, param, printed_name, sm->state->name);
809 * This is slightly (very) weird because half of this stuff is handled in
810 * smatch_parse_call_math.c which is poorly named. But anyway, add some buf
811 * sizes here.
814 static void print_returned_allocations(int return_id, char *return_ranges, struct expression *expr)
816 char buf[16];
817 int size;
819 size = get_array_size_bytes(expr);
820 if (!size)
821 return;
823 snprintf(buf, sizeof(buf), "%d", size);
824 sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "", buf);
827 static void record_global_size(struct symbol *sym)
829 struct symbol *type;
830 int elements, bpe, bytes;
831 char buf[16];
833 if (!sym->ident)
834 return;
836 if (!(sym->ctype.modifiers & MOD_TOPLEVEL) ||
837 sym->ctype.modifiers & MOD_STATIC)
838 return;
840 type = get_real_base_type(sym);
841 elements = get_real_array_size_from_type(type);
842 if (elements <= 0)
843 return;
844 type = get_real_base_type(type);
845 bpe = type_bytes(type);
846 bytes = elements * bpe;
847 snprintf(buf, sizeof(buf), "%d", bytes);
848 sql_insert_data_info_var_sym(sym->ident->name, sym, BUF_SIZE, buf);
851 void register_buf_size(int id)
853 my_size_id = id;
855 add_unmatched_state_hook(my_size_id, &unmatched_size_state);
857 select_caller_info_hook(set_param_buf_size, BUF_SIZE);
858 select_return_states_hook(BUF_SIZE, &db_returns_buf_size);
859 add_split_return_callback(print_returned_allocations);
861 allocation_funcs = create_function_hashtable(100);
862 add_allocation_function("malloc", &match_alloc, 0);
863 add_allocation_function("calloc", &match_calloc, 0);
864 add_allocation_function("memdup", &match_alloc, 1);
865 add_allocation_function("realloc", &match_alloc, 1);
866 if (option_project == PROJ_KERNEL) {
867 add_allocation_function("kmalloc", &match_alloc, 0);
868 add_allocation_function("kmalloc_node", &match_alloc, 0);
869 add_allocation_function("kzalloc", &match_alloc, 0);
870 add_allocation_function("kzalloc_node", &match_alloc, 0);
871 add_allocation_function("vmalloc", &match_alloc, 0);
872 add_allocation_function("__vmalloc", &match_alloc, 0);
873 add_allocation_function("kcalloc", &match_calloc, 0);
874 add_allocation_function("kmalloc_array", &match_calloc, 0);
875 add_allocation_function("drm_malloc_ab", &match_calloc, 0);
876 add_allocation_function("drm_calloc_large", &match_calloc, 0);
877 add_allocation_function("sock_kmalloc", &match_alloc, 1);
878 add_allocation_function("kmemdup", &match_alloc, 1);
879 add_allocation_function("kmemdup_user", &match_alloc, 1);
880 add_allocation_function("dma_alloc_attrs", &match_alloc, 1);
881 add_allocation_function("pci_alloc_consistent", &match_alloc, 1);
882 add_allocation_function("pci_alloc_coherent", &match_alloc, 1);
883 add_allocation_function("devm_kmalloc", &match_alloc, 1);
884 add_allocation_function("devm_kzalloc", &match_alloc, 1);
885 add_allocation_function("krealloc", &match_alloc, 1);
886 add_allocation_function("__alloc_bootmem", &match_alloc, 0);
887 add_allocation_function("alloc_bootmem", &match_alloc, 0);
888 add_allocation_function("kmap", &match_page, 0);
889 add_allocation_function("get_zeroed_page", &match_page, 0);
890 add_allocation_function("alloc_pages", &match_alloc_pages, 1);
891 add_allocation_function("alloc_pages_current", &match_alloc_pages, 1);
892 add_allocation_function("__get_free_pages", &match_alloc_pages, 1);
895 add_allocation_function("strndup", match_strndup, 0);
896 if (option_project == PROJ_KERNEL)
897 add_allocation_function("kstrndup", match_strndup, 0);
899 add_modification_hook(my_size_id, &set_size_undefined);
901 add_merge_hook(my_size_id, &merge_size_func);
903 if (option_info)
904 add_hook(record_global_size, BASE_HOOK);
907 void register_buf_size_late(int id)
909 /* has to happen after match_alloc() */
910 add_hook(&match_array_assignment, ASSIGNMENT_HOOK);
912 add_hook(&match_call, FUNCTION_CALL_HOOK);
913 add_member_info_callback(my_size_id, struct_member_callback);