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

treat hermit like wasm32 #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m-mueller678
Copy link

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
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.)

unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) as usize }
#[cfg(target_arch = "wasm32")]
#[cfg(any(target_arch = "wasm32",target_os = "hermit"))]
Copy link
Member

Choose a reason for hiding this comment

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

If there is absolutely no way to obtain the page size on hermit then lets hardcode it to something more appropriate for platforms hermit runs on (probably 4kB.)

@m-mueller678
Copy link
Author

Is page_size used for anything but controlling the size of allocations? If not, renaming to allocation_granularity or such might be appropriate.

Hermit uses Talc as an Allocator. Here is how Talc rounds up allocation sizes. As Talc stores some metadata along with each allocation, picking a power of two will have it just barely not fit within the size category. I could not find any special treatment for page size allocations, though maybe I missed it. Given this, an allocation granularity of 1 would make sense.

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