wagon icon indicating copy to clipboard operation
wagon copied to clipboard

Context-awareness

Open Xe opened this issue 6 years ago • 6 comments

It would be interesting to provide context-awareness to the exec.VM type. This would check the context Done every so often during execution, and if it is done then a new "took too long" error would be returned to the callee. This would make it possible for users to submit arbitrary untrusted webassembly code for a backend server to run and return the results without as much fear of users submitting code that blocks infinitely.

Xe avatar Jun 22 '18 00:06 Xe

Great idea ! Was wondering about how to solve that corner case too

On Fri, 22 Jun 2018, 02:45 Christine Dodrill, [email protected] wrote:

It would be interesting to provide context https://godoc.org/context-awareness to the exec.VM type. This would check the context Done every so often during execution, and if it is done then a new "took too long" error would be returned to the callee. This would make it possible for users to submit arbitrary untrusted webassembly code for a backend server to run and return the results without as much fear of users submitting code that blocks infinitely.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/go-interpreter/wagon/issues/62, or mute the thread https://github.com/notifications/unsubscribe-auth/ATuCwqZsL6YWjlbZHjV5Q8M24PGZkSKxks5t_D4OgaJpZM4Uy-j9 .

ghost avatar Jun 24 '18 14:06 ghost

apologies for the belated answer.

yes, having a context aware exec.VM type would definitely be interesting.

now, the also interesting thing would be to decide until what "depth" we want to weave it through:

  • down to each VM operation? (e.g. pushInt64, i32Load8s, ...)
  • only at VM.ExecCode ?
  • somewhere in the middle?
  • piggy back on what the Go runtime does for preemption ? (ie: only check at the end of loops, function calls, ...)

sbinet avatar Jun 27 '18 09:06 sbinet

  • down to each VM operation? (e.g. pushInt64, i32Load8s, ...)

This would be beyond overkill and would be super performance impactful.

  • only at VM.ExecCode ?

Probably check here too.

  • somewhere in the middle?

I was thinking every n operations or on function/loop/block barriers.

Xe avatar Jun 28 '18 23:06 Xe

down to each VM operation? (e.g. pushInt64, i32Load8s, ...)

This would be beyond overkill and would be super performance impactful.

I agree, I was just being facetious :)

I was thinking every n operations or on function/loop/block barriers.

every n operation is probably simplest to explain and implement, while not being too intrusive.

sbinet avatar Jun 29 '18 07:06 sbinet

How about every 65536 instructions? That constant is already used as the size of a memory page and it's a very nice, even number.

Xe avatar Jul 05 '18 17:07 Xe

SGTM

sbinet avatar Jul 05 '18 18:07 sbinet