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
19 * The kernel has a small stack so putting huge structs and arrays on the
28 static int total_size
;
30 static int max_lineno
;
31 static int complained
;
33 #define MAX_ALLOWED 1000
35 static void scope_end(void *_size
)
37 int size
= PTR_INT(_size
);
41 static void match_declarations(struct symbol
*sym
)
46 base
= get_base_type(sym
);
47 if (sym
->ctype
.modifiers
& MOD_STATIC
)
49 name
= sym
->ident
->name
;
50 total_size
+= type_bytes(base
);
51 if (total_size
> max_size
) {
52 max_size
= total_size
;
53 max_lineno
= get_lineno();
55 if (type_bytes(base
) >= MAX_ALLOWED
) {
57 sm_msg("warn: '%s' puts %d bytes on stack", name
, type_bytes(base
));
59 add_scope_hook(&scope_end
, INT_PTR(type_bytes(base
)));
62 static void match_end_func(struct symbol
*sym
)
67 if ((max_size
>= MAX_ALLOWED
) && !complained
) {
68 sm_printf("%s:%d %s() ", get_filename(), max_lineno
, get_function());
69 sm_printf("warn: function puts %d bytes on stack\n", max_size
);
77 void check_stack(int id
)
79 if (option_project
!= PROJ_KERNEL
|| !option_spammy
)
83 add_hook(&match_declarations
, DECLARATION_HOOK
);
84 add_hook(&match_end_func
, END_FUNC_HOOK
);