Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mild red zone bug. #11

Open
slembcke opened this issue Jun 11, 2022 · 2 comments
Open

Mild red zone bug. #11

slembcke opened this issue Jun 11, 2022 · 2 comments

Comments

@slembcke
Copy link

Spotted a pretty mild bug related to red zones. The current code shouldn't cause any bugs. It just wastes a few bytes of stack space.
https://github.com/edubart/minicoro/blob/main/minicoro.h#L742

You subtract the 128 bytes from the size of the stack, and then use that size to find the high address of the stack. The red zone is the space with lower addresses than the current stack pointer, while your reserved space is above the start of the stack. Also, the red zone really only applies meaningfully to leaf functions so they can skip adjusting the stack pointer without getting stomped by interrupts. Any function that calls resume/yield is no longer a leaf function, so you don't have to worry about it in your implementation.

@edubart
Copy link
Owner

edubart commented Jun 11, 2022

So this is not really a bug, just waste of stack space.

What about the x64 shadow space? At line
https://github.com/edubart/minicoro/blob/main/minicoro.h#L666

Maybe 128 bytes is a waste on Linux, but 32 bytes still required?

I am afraid of removing that line and causing bugs, I didn't study x86_64 ABI that well, so I reserved that space just to be safe.

@slembcke
Copy link
Author

slembcke commented Jun 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants