pub struct HostState { /* private fields */ }Expand description
Everything the host keeps for one native run: the startup block the entry borrows, the process capability and the resources both point into.
It belongs to the host side of the task, not to the program’s coroutine: the
loader allocates it once, next to the heap and the image, and the coroutine
entry receives only a pointer to it. A program that writes past its own frames
therefore cannot damage the state xila_process_exit, the SDK’s heap access and
the standard error stream behind write(2) depend on, and a host that stops
resuming a coroutine can still reach what the coroutine owned.
The startup block and the capability point into the state, so it must not move once a run has begun: the allocation that holds it stays where it is until the run has ended for good. Building it, and moving it into that allocation, are free to move it, because nothing points into it yet.
It owns everything the program holds that the kernel or the host must release: the
arguments, the standard streams, the home directory, the graphics objects and a registry
of the handles the program opened itself. The program’s frames own none of it, so
HostState::release can close it all without running any of the program’s code,
whether the program returned, exited or was cancelled.
Implementations§
Source§impl HostState
impl HostState
Sourcepub fn new(
arguments: Vec<String>,
standard_input: Option<File>,
standard_output: Option<File>,
standard_error: Option<File>,
) -> Self
pub fn new( arguments: Vec<String>, standard_input: Option<File>, standard_output: Option<File>, standard_error: Option<File>, ) -> Self
The arguments and the standard streams of a program that has not started.
Sourcepub unsafe fn run_linked(
state: NonNull<Self>,
entry: unsafe extern "C" fn(*const XilaStartup) -> i32,
heap: NonNull<Heap>,
) -> i32
pub unsafe fn run_linked( state: NonNull<Self>, entry: unsafe extern "C" fn(*const XilaStartup) -> i32, heap: NonNull<Heap>, ) -> i32
Run a linked entry that gets no process capability and cannot exit early,
then drop the resources. The state belongs to the caller, as for
crate::ProcessLaunch::run.
§Safety
Same as run_main, and state and heap stay at their addresses and live
until native execution has permanently ended.
Source§impl HostState
impl HostState
Sourcepub fn open_handles(&self) -> usize
pub fn open_handles(&self) -> usize
How many handles the program has opened and not closed: files, directories, listings, children and sockets. It counts what a cancellation would close, and excludes the standard streams and the home directory, which are not the program’s to close.
Sourcepub unsafe fn release(state: NonNull<Self>)
pub unsafe fn release(state: NonNull<Self>)
Close and free everything the program still holds: the handles it opened, its graphics objects, its standard streams, its home directory and its strings. A program that returned or exited has released them already, so this does nothing then; one that was cancelled, or never ran, still holds them.
This is how a host cancels a program without running any of its code: drop the
coroutine first (which discards its frames), then release the state, then free it.
Closing may wait for the file system and the graphics lock, which blocks the
calling task as task::block_on does when no coroutine is running.
§Safety
state is live and at the address the program ran with, and no code of the program
runs, or ever will, while this does.