Disable the Red Zone (Extra Post) #1002
Replies: 7 comments 1 reply
-
There is one small thing that I cannot understand: what does leaf function mean? Does it implies that the two instructions can be optimized when it comes to tail recursive optimization? Thank you! |
Beta Was this translation helpful? Give feedback.
-
A leaf function is a function that does not call other functions, i.e. a leaf node in the call graph of the program. A tail recursive function that doesn't call other functions can be turned into a leaf function, because tail recursion can be turned into a loop. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the article.
Why this optimization exists at all when it leads problem with exceptions or hardware interrupts? Are there situations that using red zone is absolutely safe? I thought "normal" code can have exceptions too. |
Beta Was this translation helpful? Give feedback.
-
When you are running in userspace, the kernel adjusts the stack pointer to take the red zone into account before calling the signal handler. The kernel itself tells the processor to switch to a different stack for the exception handler when calling the exception happened in userspace. Because this needs some extra setup, it isn't done in this OS. This means you still need to disable the red zone for the kernel. |
Beta Was this translation helpful? Give feedback.
-
For normal userspace applications this optimization is not a problem because the kernel usually switches to a completely different stack through a hardware mechanism whenever an interrupt or an exception occurs. Thus, no data of the userspace stack is overwritten, even with the red zone optimization. Edit: Seems like bjorn3 beat me to it :). |
Beta Was this translation helpful? Give feedback.
-
Got it, thanks for the explanations! |
Beta Was this translation helpful? Give feedback.
-
Is the System V ABI unrelated to the AMD64 ABI reference the first "red zone" link in the first paragraph? I ask because the claim there about the red-zone not being modified by interrupt handlers seems to contradict this one. That article reads,
|
Beta Was this translation helpful? Give feedback.
-
This is a general purpose comment thread for the “Disable the Red Zone” post.
Beta Was this translation helpful? Give feedback.
All reactions