从ulimit的结果知道,系统设定的stack size为8192kbytes,
sh-# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 2293
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 2293
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
sh-#
所以我们写出如下的测试程序来进行测试,
static int g_value = 0;
static void _recursive_test(void)
{
char s_str[1024] = {0};
while(g_value < 8*1024)
{
g_value++;
_recursive_test();
}
return;
}
int main(int argc, char *argv[])
{
_recursive_test();
while(1)
{
sleep(1);
}
exit(0);
}
运行测试程序,test_main程序会崩溃掉,
sh-# ./test_main &
4969
sh-#
从core dump查看callstack,可以看到有一个函数在被递归调用并且系统产生了SIGSEGV信号,
所以从直观上推测有可能是栈溢出引起的段非法访问。
sh-# ./gdb -c ./core_test_main_sig11_pid2491 ./test_main
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from ./test_main...done.
warning: exec file is newer than core file.
[New Thread 2491]
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.3
Core was generated by `/test_main'.
Program terminated with signal 11, Segmentation fault.
#0 0x401882c0 in memset () from /lib/libc.so.6
(gdb) bt 20
#0 0x401882c0 in memset () from /lib/libc.so.6
#1 0x000083e4 in _recursive_test ()
#2 0x00008400 in _recursive_test ()
#3 0x00008400 in _recursive_test ()
#4 0x00008400 in _recursive_test ()
#5 0x00008400 in _recursive_test ()
#6 0x00008400 in _recursive_test ()
#7 0x00008400 in _recursive_test ()
#8 0x00008400 in _recursive_test ()
#9 0x00008400 in _recursive_test ()
#10 0x00008400 in _recursive_test ()
#11 0x00008400 in _recursive_test ()
#12 0x00008400 in _recursive_test ()
#13 0x00008400 in _recursive_test ()
#14 0x00008400 in _recursive_test ()
#15 0x00008400 in _recursive_test ()
#16 0x00008400 in _recursive_test ()
#17 0x00008400 in _recursive_test ()
#18 0x00008400 in _recursive_test ()
#19 0x00008400 in _recursive_test ()
(More stack frames follow...)
(gdb)
问题:
需要学习进程的虚拟地址空间布局。