【发布时间】:2018-05-23 19:40:52
【问题描述】:
I am trying to test linux kernel stack size in 64 bit.
我发现了这种奇怪的行为。 我编写了以下代码来使内核崩溃,但奇怪的是 仅当 printk 未注释时才会崩溃, 否则运行良好,没有错误/警告!!。
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int __init crash_stack_init(void)
{
long arr[1024];
long *a;
a = &arr[0];
//printk("%p\n", &arr[0]);
return 0;
}
enter code here
static void __exit crash_stack_exit(void)
{
}
module_init(crash_stack_init);
module_exit(crash_stack_exit);
Here is the "make" output without the printk,
make -C /lib/modules/4.4.0-53-generic/build M=/home/naveenvc/work/ker/crash_stack 模块 make[1]: 进入目录'/usr/src/linux-headers-4.4.0-53-generic' CC [M] /home/naveenvc/work/ker/crash_stack/crash_stack.o 建筑模块,第 2 阶段。 MODPOST 1 个模块 CC /home/naveenvc/work/ker/crash_stack/crash_stack.mod.o LD [M] /home/naveenvc/work/ker/crash_stack/crash_stack.ko make[1]: 离开目录'/usr/src/linux-headers-4.4.0-53-generic'
And make output with printk,
make -C /lib/modules/4.4.0-53-generic/build M=/home/naveenvc/work/ker/crash_stack modules make[1]:进入 目录 '/usr/src/linux-headers-4.4.0-53-generic' CC [M] /home/naveenvc/work/ker/crash_stack/crash_stack.o > /home/naveenvc/work/ker/crash_stack/crash_stack.c:在函数中 ‘crash_stack_init’: /home/naveenvc/work/ker/crash_stack/crash_stack.c:14:1:警告: 8200 字节的帧大小大于 1024 字节 [-Wframe-larger-than=] } ^
建筑模块,第 2 阶段。MODPOST 1 模块 CC
/home/naveenvc/work/ker/crash_stack/crash_stack.mod.o LD [M] /home/naveenvc/work/ker/crash_stack/crash_stack.ko make[1]:离开 目录'/usr/src/linux-headers-4.4.0-53-generic'
这可能是什么原因造成的?
【问题讨论】:
-
当然 printk() 也使用了一些堆栈,所以你的函数 + printk 的组合堆栈使用量变得太多了
-
合规性与总堆栈使用量无关(这将略高于允许大小的一半),而是该特定功能的使用
标签: c linux linux-kernel printk