Skip to main content

HostState

Struct HostState 

Source
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

Source

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.

Source

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

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.