wasmtime: Consume fuel on all return paths #8837
Open
+17
−35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As far as I can tell, when functions use a
return
instruction rather than falling off the end, fuel was not being tracked correctly. Thefuel_function_exit
method was only called fromafter_translate_function
, which is only called once all the instructions in the function have been translated, not at each return.In this commit I switched to calling
fuel_function_exit
fromhandle_before_return
instead, alongside some of thewmemcheck
hooks. That should ensure that it happens on every function exit, regardless of what form that exit takes.I think
after_translate_function
is fundamentally difficult to use correctly, and it wasn't used for anything else, so I've also removed it in this commit. And I did a minor cleanup at the site of one of the calls tohandle_before_return
while I was looking at it.