Expand description
The execution module contains state for an instance’s execution, and exposes functions
building that state into something appropriate for safe use externally.
So far as state tracked in this module is concerned, there are two key items: “terminability” and “execution domain”.
§Terminability
This specifically answers the question “is it safe to initiate termination of this instance right now?”. An instance becomes terminable when it begins executing, and stops being terminable when it is terminated, or when it stops executing. Termination does not directly map to the idea of guest code currently executing on a processor, because termination can occur during host code, or while a guest has yielded execution. As a result, termination can only be treated as a best-effort to deschedule a guest, and is typically quick when it occurs during guest code execution, or immediately upon resuming execution of guest code (exiting host code, or resuming a yielded instance).
§Execution Domain
Execution domains allow us to distinguish what an appropriate mechanism to signal termination
is. This means that changing of an execution domain must be atomic - it would be an error to
read the current execution domain, continue with that domain to determine temination, and
simultaneously for execution to continue possibly into a different execution domain. For
example, beginning termination directly at the start of a hostcall, where sending SIGALRM may
be appropriate, while the domain switches to Hostcall and is no longer appropriate for
signalling, would be an error.
§Instance Lifecycle and KillState
And now we can enumerate interleavings of execution and timeout, to see the expected state at possible points of interest in an instance’s lifecycle:
Instance created- terminable:
false - execution_domain:
Guest
- terminable:
Instance::run called- terminable:
true - execution_domain:
Guest
- terminable:
Instance::run executing- terminable:
true, or false - execution_domain:
Guest, Hostcall, or Terminated execution_domainwill only beGuestwhen executing guest code, only beHostcallwhen executing a hostcall, but may also beTerminatedwhile in a hostcall to indicate that it should exit when the hostcall completes.terminablewill be false if and only ifexecution_domainisTerminated.
- terminable:
Instance::run returns- terminable:
false - execution_domain:
Guest, Hostcall, or Terminated execution_domainwill beGuestwhen the initial guest function returns,Hostcallwhen terminated bylucet_hostcall_terminate!, andTerminatedwhen exiting due to a termination request.
- terminable:
Guest function executing- terminable:
true - execution_domain:
Guest
- terminable:
Guest function returns- terminable:
true - execution_domain:
Guest
- terminable:
Hostcall called- terminable:
true - execution_domain:
Hostcall
- terminable:
Hostcall executing- terminable:
true - execution_domain:
Hostcall, or Terminated execution_domainwill typically beHostcall, but may beTerminatedif termination of the instance is requested during the hostcall.terminablewill be false if and only ifexecution_domainisTerminated.
- terminable:
Hostcall yields- This is a specific point in “Hostcall executing” and has no further semantics.
Hostcall resumes- This is a specific point in “Hostcall executing” and has no further semantics.
Hostcall returns- terminable:
true - execution_domain:
Guest execution_domainmay beTerminatedbefore returning, in which caseterminablewill be false, but the hostcall would then exit. If a hostcall successfully returns to its caller it was not terminated, so the only state an instance will have after returning from a hostcall will be that it’s executing terminable guest code.
- terminable:
Structs§
- Kill
State - All instance state a remote kill switch needs to determine if and how to signal that execution should stop.
- Kill
Switch - An object that can be used to terminate an instance’s execution from a separate thread.