Expand description
This module provides several Context structs, intended to bundle together current relevant objects in the hierarchy.
These are meant to replace worker_getActiveThread
, etc. Passing around
the current context explicitly instead of putting them in globals both
allows us to avoid interior mutability (and its associated runtime cost and
fallibility), and lets us keep a hierarchical object structure (e.g. allow
holding a mutable Process and a mutable Thread belonging to that process
simultaneously).
Most code (e.g. syscall handlers) can take a ThreadContext
argument and use
that to manipulate anything on the Host. The current Thread
and Process
should typically be accessed directly. e.g. since a mutable reference to the
current Thread
exists at ThreadContext::thread
, it cannot also be
accessible via ThreadContext::process
or ThreadContext::host
.
The manner in which they’re unavailable isn’t implemented yet, but the current plan is that they’ll be temporarily removed from their collections. e.g. something conceptually like:
impl Process {
pub fn continue_thread(&mut self, host_ctx: &mut HostContext, tid: ThreadId) {
let thread = self.threads.get_mut(tid).take();
thread.continue(&mut host_ctx.add_process(self));
self.threads.get_mut(tid).replace(thread);
}
}
The Context objects are designed to allow simultaneously borrowing from multiple of their objects. This is currently implemented by exposing their fields directly - Rust then allows each field to be borrowed independently. This could alternatively be implemented by providing methods that borrow some or all of their internal references simultaneously.
Structs§
- Represent the “current”
Host
. - Shadow’s C code doesn’t know about contexts. In places where C code calls Rust code, we can build them from C pointers.