Skip to content

treat hermit like wasm32 #109

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

Merged
merged 3 commits into from
Mar 18, 2025
Merged

treat hermit like wasm32 #109

merged 3 commits into from
Mar 18, 2025

Conversation

m-mueller678
Copy link
Contributor

This implements stacker on hermit by treating it the same as wasm32

@nagisa
Copy link
Member

nagisa commented Dec 17, 2024

Could you please elaborate on why this implementation precisely is the right thing to do for the hermit targets and why e.g. psm-based implementation does not work? Is hermit running exclusively on esoteric architectures of some sort?

@m-mueller678
Copy link
Contributor Author

I forgot to mention, this intends to fix #108. If I can get an implementation that just compiles and does nothing, I would be happy too.

I chose the wasm implementation simply because I am not familiar enough with psm to adapt the psm implementation to do the right thing for Hermit.

From what I could gather from the source code, they differ in how they allocate memory and how they query page size. Hermit supports neither mmap nor sysconf, so I went with the wasm implementation.

Hermit usually runs on x86_64 and aarch64, though there might also be other supported architectures.

@nagisa
Copy link
Member

nagisa commented Dec 19, 2024

Ah so my bad. I didn't check the PR closely enough, and it looks like psm continues to be used. What psm does is entirely just switching stack pointers without worrying about how the stacks have been allocated. For all it cares, the stack could've been allocated with malloc. For systems like Linux malloc isn't super appropriate as there is no way to add a guard page to protect against stack overflows. If that's fine for hermit then I have no problem with such approach.

That said, using wasm implementation everywhere isn't always appropriate. For instance WASM has 64k pages by requirement in the specification. On code running on x86_64/arm the page size is most likely going to be smaller, though it probably won't hurt anybody if too large of a page size is specified. If hermit has no way to query the page size, then 4k is likely to be the more correct choice (though for malloc-based implementation it probably matters little either way -- might as well say the page size is 1.)

@m-mueller678
Copy link
Contributor Author

I moved StackRestoreGuard into its own module with two different implementations depending on target. I tried to leave the logic for mmap-using targets exactly the same. Some tings seemed wrong, I added to-dos for those.

@m-mueller678 m-mueller678 requested a review from nagisa March 17, 2025 15:28
Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@nagisa nagisa merged commit b0a87ec into rust-lang:master Mar 18, 2025
149 of 155 checks passed
@m-mueller678 m-mueller678 mentioned this pull request Mar 19, 2025
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

Successfully merging this pull request may close these issues.

2 participants