4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * The kernel has a small stack so putting huge structs and arrays on the
20 static int total_size
;
22 static int max_lineno
;
23 static int complained
;
25 static void scope_end(int size
)
30 static void match_declarations(struct symbol
*sym
)
35 base
= get_base_type(sym
);
36 if (sym
->ctype
.modifiers
& MOD_STATIC
)
38 name
= sym
->ident
->name
;
39 total_size
+= base
->bit_size
;
40 if (total_size
> max_size
) {
41 max_size
= total_size
;
42 max_lineno
= get_lineno();
44 if (base
->bit_size
>= 500 * 8) {
46 sm_msg("warn: '%s' puts %d bytes on stack", name
, base
->bit_size
/ 8);
48 add_scope_hook((scope_hook
*)&scope_end
, INT_PTR(base
->bit_size
));
51 static void match_end_func(struct symbol
*sym
)
53 if ((max_size
>= 500 * 8) && !complained
) {
54 sm_printf("%s:%d %s() ", get_filename(), max_lineno
, get_function());
55 sm_printf("warn: function puts %d bytes on stack\n", max_size
/ 8);
63 void check_stack(int id
)
65 if (option_project
!= PROJ_KERNEL
)
69 add_hook(&match_declarations
, DECLARATION_HOOK
);
70 add_hook(&match_end_func
, END_FUNC_HOOK
);