uClinux kernel panic: Stack overflow
If you’re using ucLinux, you may get kernel panic errors coming out of nowhere. There may be several reasons (buffer overflow, out of memory..), but the most common is stack overflow for the process or one of the threads. To increase the stack size of a flat binary you’ll need to adjust the LDFLAGS as follows:
1 |
LDFLAGS+=-Wl,-elf2flt="-s65536" |
This will set the stack size to 64KB. To change the stack size of a thread (e.g. 32KB below), you’ll need to set the stack size attribute:
1 2 3 4 5 6 7 |
pthread_attr_init(&attr); err = pthread_attr_setstacksize(&attr, 32*1024); if (err) { printf("pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno)); } err = pthread_create(&pthThread, &attr, thread, NULL); |
How to detect which thread suffers from stack overflow? First, you can check your code for recursive function calls and local variables (especially arrays) both of which will be added at runtime to the stack to estimate what should be the stack size. So if you have large arrays you may use a pointer + a call to malloc instead. If this can not fix […]