Thread (4 messages) 4 messages, 3 authors, 2011-09-16

thread_info address calculation

From: Dave Hylands <hidden>
Date: 2011-09-16 15:52:43

Hi Vijay,

On Fri, Sep 16, 2011 at 5:16 AM, Vijay Chauhan [off-list ref] wrote:
quoted
It's the same thing as you read:
THREAD size is 8kb so the operation looks like the following:
current_stack_pointer & ~(8191) == current_stack_pointet & 0xFFFFFE00
(last 13 bits are 0)
Ok. Got it.

But how ANDing it with current stack pointer points to the address of
thread_info structure.
Suppose stack is growing from higher to lower memory address.
Since the memory for the stack is allocated using a power-of-2
allocator, when you ask for 8K of memory, it is also 8K aligned. The
stack will start at the end of the 8K region and grow towards the
beginning. The thread_info will be stored at the beginning.

ANDing any valid stack pointer with the mask will return the beginning
of the 8K block.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help