Q: Interrupts?
Is it possible to interrupt execution to call another function, and then resume execution of the old function? I.e., in a game loop, I might want to do this. (I haven't read the game engine examples so there could be a different way of doing this.)
Yes, I use it all the time in my game engine. There's a chapter on this in the docs: https://libriscv.no/docs/emulator/vmcalls#interrupting-a-running-machine
If you don't care much about dealing with the complexity in the example, you can use machine.preempt(...) in place of machine.vmcall(...).
But essentially: VM calls are function calls into the sandboxed program that clobber registers/state, while preempted calls will store and restore the register state.
If you're using the C API, then I don't think there's an exposed API function that helps with that. But you can store registers before and restore after manually doing a vmcall. Also note that you can't interrupt a machine from another thread. Part of the low latency of libriscv is the assumption that everything happens in the same thread. In my game engine I have one VM instance per thread for this reason.