Re: Stack overflow code, can someone please explain this

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 9 Mar 2005 16:04:32 +0530, Kotian, Deepak
<Deepak.Kotian@xxxxxxxxx> wrote:
> Hi,
> Stack overflow code, can someone please explain this, it is there in do_IRQ() kernel
> function
> *********
>        __asm__ __volatile__(
>                "andl %%esp,%0"
>                : "=r" (esp) : "0" (THREAD_SIZE-1));
> *********

In Linux kernel, tke kernel stack of thread is of size THREAD_SIZE. At
the beginning the esp would be at "allocated stack base + THREAD_SIZE
- 1"
The stack then starts growing  downward. When it reaches the base, we
can know that the stack has overflown.

The above code simply ands the current esp value with the
THREAD_SIZE-1. This gives the offset from the base. So by analysing
the value we can find out if there was a stackoverflow


> Also,
> Could there be any other simpler way do calculate stack overflow without using
> assembly code.

I dont think so....

regards
Manish Regmi

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux