-
Notifications
You must be signed in to change notification settings - Fork 944
Port to WebAssembly #32
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
Conversation
Rebased against the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome you got this port done so quickly! Yet another advantage of a small codebase.
Some remarks:
- can you remove the whitespace differences is the pull request? (only if not too much work)
- is
arc4random_buf
available by default in WASI? don't we need a header file? - in
os.c
, the best is to only modify the lowlevelmi_mmap
andmi_munmap
functions and notos_alloc
andos_free
; can you move your modifications there? If you feel unsure, I can also accept the pull request as is, and do it for you now that I see how it works. Just let me know.
Thanks again!
Hi! And thanks for your feedback! The whitespace diffs have been removed.
I'm a bit reluctant to adding the changes to This can be revisited once |
@jedisct1 : I see what you mean about Generally, I would like this code to be reused for any |
Sounds good. I moved the WebAssembly-specific allocation to |
IIUC this implementation leaks memory everytime mimalloc decides to free a page? Seems weird that is the intended behaviour... maybe free should put the page on a freelist? |
@santagada: yes, that is why I haven't merged yet. I am working in the |
That PR to support WebAssembly was adjusted to the Can you give it a new look? |
Ah great -- the |
Yes, it seems to work perfectly fine here. I'm using it in a branch of the wasi libc, with |
Awesome. Thanks for contributing this and let me know how it works for you. |
Thanks you! |
errno = ENOMEM; | ||
return NULL; | ||
} | ||
return (void*) aligned_base; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a subtle race condition here: between the __builtin_wasm_memory_size
call and the __builtin_wasm_memory_grow
call, other threads could do __builtin_wasm_memory_grow
. We should return something based on the return value of __builtin_wasm_memory_grow
.
This makes mimalloc compatible with the WebAssembly Standard Interface.
I'm considering it as a dlmalloc replacement for wasi-libc, and have been successfully running it in this scenario.