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 max_func_pos
;
24 static int complained
;
26 static void scope_end(int size
)
31 static void match_declarations(struct symbol
*sym
)
36 base
= get_base_type(sym
);
37 if (sym
->ctype
.modifiers
& MOD_STATIC
)
39 name
= sym
->ident
->name
;
40 total_size
+= base
->bit_size
;
41 if (total_size
> max_size
) {
42 max_size
= total_size
;
43 max_lineno
= get_lineno();
44 max_func_pos
= get_func_pos();
46 if (base
->bit_size
>= 500 * 8) {
48 sm_msg("warn: '%s' puts %d bytes on stack", name
, base
->bit_size
/ 8);
50 add_scope_hook((scope_hook
*)&scope_end
, (void *)base
->bit_size
);
53 static void match_end_func(struct symbol
*sym
)
55 if ((max_size
>= 500 * 8) && !complained
) {
56 sm_printf("%s +%d %s(%d) ", get_filename(), max_lineno
, get_function(), max_func_pos
);
57 sm_printf("warn: function puts %d bytes on stack\n", max_size
/ 8);
66 void check_stack(int id
)
68 if (option_project
!= PROJ_KERNEL
)
72 add_hook(&match_declarations
, DECLARATION_HOOK
);
73 add_hook(&match_end_func
, END_FUNC_HOOK
);