-
Notifications
You must be signed in to change notification settings - Fork 636
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
Add callback to handle memory.grow failures #2522
Add callback to handle memory.grow failures #2522
Conversation
do you mean just printing a diagnostic message? |
My use case is more about logging, storing some stats and doing some cleanup in the embedder. Without that, the execution can crash at any point (in which there's an allocation) and from the embedder there won't be any way to automatically understand that the cause is the |
for logging purpose, i guess it's better to provide more info like:
|
8ec6b66
to
bc58296
Compare
just a general note: is there any specific reason why we need why cannot we call a separate function and then just maybe I'm missing some context |
bc58296
to
5cfa33a
Compare
It just looked cleaner than calling |
5cfa33a
to
c3cd8ae
Compare
24e1a12
to
4ca1a77
Compare
4ca1a77
to
136c50a
Compare
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.
LGTM
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.
lgtm
Be curious about the use case. Does it like
It seems like a general global exception handler with variants exceptions is better than a set of callbacks for every possible scenarios. |
Yes, that's my use case
Do you mean to implement a general global exception handler in the runtime? |
Does the uncheckable exception only happen during allocation or it is a general behaviour in Rust? Is it safe to say |
Yes, the one that I was trying to address happens in Rust whenever a memory allocation fails. It can be raised by any library included (e.g. standard library) and currently there's no way to catch it. To reproduce it, you can just set the maximum linear memory size to a small value and compile some Rust code that allocates memory.
I think so. |
I think it's worth to mention in this thread that (a cross-runtime) alternative for that would be to add a compiler pass that wraps memory.grow opcode with some additional error checking logic. And that can be extended to handle any other future usecases. |
Is it safe to say the embedded will meet an un-handled exception when the rust code hit a If so, shall we avoid |
The |
Is it safe to say the embedded will meet an un-handled exception when the rust code hit a |
Yes |
When embedding WAMR, this PR allows to register a callback that is invoked when memory.grow fails. In case of memory allocation failures, some languages allow to handle the error (e.g. by checking the return code of malloc/calloc in C), some others (e.g. Rust) just panic.
When embedding WAMR, this PR allows to register a callback that is invoked when memory.grow fails. In case of memory allocation failures, some languages allow to handle the error (e.g. by checking the return code of malloc/calloc in C), some others (e.g. Rust) just panic.
When embedding WAMR, this PR allows to register a callback that is invoked when
memory.grow
fails.In case of memory allocation failures, some languages allow to handle the error (e.g. by checking the return code of
malloc
/calloc
in c), some others (e.g. Rust) just panic. For the latter, it is useful to have a callback function that would be called before the wasm execution crashes, allowing the embedder to detect and handle thememory.grow
error. It comes in handy when using shared memory since shared memory forces the maximum linear memory size to be set at compilation time. Setting a value that is too low can lead to memory allocation failures (i.e.memory.grow
failures).It would be nice to capture the crash in Rust directly, but the feature is experimental (rust-lang/rust#51540).