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 modules 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-通用'
这可能是什么原因造成的?