Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux kernel development

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.

like image 924
tbh Avatar asked Nov 28 '10 15:11

tbh


People also ask

Is Linux kernel development hard?

Linux kernel programming is fairly easy. It is not required to have access to special hardware. There is still a lot of work to be done. You can allocate as much time as you want and as you can.

What is kernel programming in Linux?

The Linux® kernel is the main component of a Linux operating system (OS) and is the core interface between a computer's hardware and its processes. It communicates between the 2, managing resources as efficiently as possible.

How does Linux kernel development work?

The kernel development is a continuous process. A new version of the kernel is released when a set of features and bug fixes are ready. These new versions are called kernel releases. This process initiates with Linus Torvalds, wherein, he releases a new kernel and then opens a 2-week merge window.

Do Linux kernel developers get paid?

Linux Kernel Developer Salary. $127,000 is the 25th percentile. Salaries below this are outliers. $247,000 is the 90th percentile.


1 Answers

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?

like image 65
lijie Avatar answered Oct 23 '22 05:10

lijie