The stack grows downwards, so the end of the stack is the lowest address in the stack, and the structure's starting address. And stacks are stored at multiples of 8KB. Therefore, erasing the 13 least significant bits gets the lowest address of the stack and therefore the start of the structure.
Does this make sense?
Up vote 5 down vote favorite 1 share g+ share fb share tw.
I am currently reading 'Linux Kernel Development' by Robert Love and I do not understand what this bit of assembly is doing. Basically, in each process kernel stack, there is a struct thread_info which resides at the end of the stack. Now, on the x86 architecture, we can apparently grab this (assuming 8KB stack size) by using the following assembly movl $-8192, %eax andl %esp, %eax So basically ANDing the stack pointer by 0xffffe000.
I'm confused as to what is going on here? I don't see why masking the least significant 13 bits of %esp takes us to the struct. I know I'll feel stupid once it is explained, but it is bugging me.
Thanks. Linux assembly kernel link|improve this question asked Nov 28 '10 at 15:58tbh282.
When the struct is pushed on to the stack at the end, %esp is decremented. – tbh Nov 28 '10 at 16:39 The stack starts from a high memory address (when stuff is pushed, the stack pointer decreases). %esp points to the bottom of the stack, in that it points to the "current" bottom, rather than the bottom of the space that the stack is allowed to grow in.
– lijie Nov 28 '10 at 17:07 Ah, see I thought the struct was just pushed on at the end of everything rather than just shoved right down in the pit of the stack when the process is initialised and given it's own stack. OK, thanks lijie – tbh Nov 28 '10 at 18:00.
PS: Sorry, can't add links because kernel.org is down for maintenance.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.