Re:Let’s write a simple Kernel (2014)
by DSMan195276 on Friday October 20, 2017 @10:31AM
(#15516053)
> The linux kernel does not follow this part of the ABI, so the compiler needs to be told that there is no red zone or functions will randomly see their stack frame clobbered by interrupt handlers.
You're absolute right, but I would add a qualifier that it is impossible for a kernel to use the redzone optimization. Certain architectures (Like x86) will push data onto the stack when an interrupt happens and there is no way to tell them to put that data after the first 128 bytes on the stack.
Re:Let’s write a simple Kernel (2014)
by convolvatron on Friday October 20, 2017 @01:21PM
(#15517485)
you could use some register other than %esp for your stack :)
Re:Let’s write a simple Kernel (2014)
by throwaway613834 on Friday October 20, 2017 @11:46AM
(#15516665)
Doesn't red-zoning break the fundamental contract of a stack pointer -- i.e., that it marks the end of the stack (and hence the location of the next item to be pushed)? This feature sounds like a bug to me...
Re:Let’s write a simple Kernel (2014)
by DSMan195276 on Friday October 20, 2017 @01:36PM
(#15517639)
In some ways yes, but it is only applied to functions where they call no other functions and thus "nobody" will ever know they never moved the stack pointer anyway. In those situations moving the stack pointer is just pointless extra work because it is a value that will never be used and then just restored to its original value.
I say "nobody" because in particular signal handlers (Which are basically just userland interrupts) can interrupt any part of userland code. However since they are generated entirely by the kernel it is easy enough for the kernel to obey the redzone and place the signal handler 128 bytes above the stack pointer, so in practice this isn't that big of a deal.
The linux kernel does not follow this part of the ABI, so the compiler needs to be told that there is no red zone or functions will randomly see their stack frame clobbered by interrupt handlers.