lucet
lucet copied to clipboard
Add separate hostcall stack and switch to it during hostcalls
When an execution of a Lucet instance begins, we context switch off the host stack and onto a stack that is colocated next to the instance's heap. When that execution makes a host-call, we do not switch back to the host stack, but rather remain on the guest stack.
This leaves us in the following position: The amount of guest stack remaining is a guest-defined property when the guest makes a host-call. Stack overflows while in host code are fatal to the embedding process. Not good.
So, we propose the following: Host-calls switch back to the host stack. This isn't as heavyweight as the full context-switch as defined in https://github.com/fastly/lucet/blob/master/lucet-runtime/lucet-runtime-internals/src/context/context_asm.S. We should really only need to save and restore the stack pointer to make this work.
For clarity: This doesn't prevent stack overflows in host-calls from being fatal, but it does prevent it from being reliant upon how much stack the guest has used.
Upon further thought, this doesn't interact well with the future pause and resume semantics. We'd end up trashing the call stack when we pause.
So, there needs to be a separate hostcall stack.