Re: stack overflow

Andreas Dilger
2003-09-12T22:52:48Z

On Sep 12, 2003 18:53 +0100, Breno wrote:
> Hi ... this is my idea to check a stack overflow. What do you think ?
>
> #define STACK_LIMIT (1024*8192)/PAGE_SIZE
>
> int check_stack_overflow(struct task_struct *tsk)
> {
>
> unsigned long stack_size,stack_addr,stack_ptr;
> int i;
>
> if(tsk->mm != NULL)
> {
> stack_addr = tsk->mm->start_stack;
>
> stack_ptr = tsk->thread.esp;
>
> for(i=0; i < stack_ptr; i++)
> stack_addr++;
>
> stack_size = (stack_addr - stack_ptr)/PAGE_SIZE;
>
> if(stack_size > ( STACK_LIMIT - 1))

Well, with the exception of the fact that STACK_LIMIT is 8MB, and kernel
stacks are only 8kB (on i386)...

Also, see "do_IRQ()" (i386) for CONFIG_DEBUG_STACKOVERFLOW to see this already.

Cheers, Andreas
--
Andreas Dilger