Module zircon_object::object [−][src]
Kernel object basis.
Create new kernel object
- Create a new struct.
- Make sure it has a field named
base
with typeKObjectBase
. - Implement
KernelObject
trait withimpl_kobject
macro.
Example
use zircon_object::object::*; extern crate alloc; pub struct SampleObject { base: KObjectBase, } impl_kobject!(SampleObject);
Implement methods for kernel object
Constructor
Each kernel object should have a constructor returns Arc<Self>
(or a pair of them, e.g. Channel
).
Don’t return Self
since it must be created on heap.
Example
use zircon_object::object::*; use std::sync::Arc; pub struct SampleObject { base: KObjectBase, } impl SampleObject { pub fn new() -> Arc<Self> { Arc::new(SampleObject { base: KObjectBase::new(), }) } }
Interior mutability
All kernel objects use the interior mutability pattern :
each method takes either &self
or &Arc<Self>
as the first argument.
To handle mutable variable, create another inner structure, and put it into the object with a lock wrapped.
Example
use zircon_object::object::*; use std::sync::Arc; use spin::Mutex; pub struct SampleObject { base: KObjectBase, inner: Mutex<SampleObjectInner>, } struct SampleObjectInner { x: usize, } impl SampleObject { pub fn set_x(&self, x: usize) { let mut inner = self.inner.lock(); inner.x = x; } }
Downcast trait to concrete type
KernelObject
inherit downcast_rs::DowncastSync
trait.
You can use downcast_arc
method to downcast Arc<dyn KernelObject>
to Arc<T: KernelObject>
.
Example
use zircon_object::object::*; use std::sync::Arc; let object: Arc<dyn KernelObject> = DummyObject::new(); let concrete = object.downcast_arc::<DummyObject>().unwrap();
Re-exports
pub use super::*; |
Structs
DummyObject | Empty kernel object. Just for test. |
Handle | A Handle is how a specific process refers to a specific kernel object. |
HandleBasicInfo | Information about a handle and the object it refers to. |
HandleInfo | Information about a handle itself, including its |
KObjectBase | The base struct of a kernel object. |
Rights | Rights are associated with handles and convey privileges to perform actions on either the associated handle or the object associated with the handle. |
Signal | Signals that waitable kernel objects expose to applications. |
Constants
INVALID_HANDLE | Invalid handle value. |
Traits
KernelObject | Common interface of a kernel object. |
Functions
obj_type | Get an object’s type. |
wait_signal_many | Asynchronous wait signal for multiple objects. |
Type Definitions
HandleValue | The value refers to a Handle in user space. |
KoID | The type of kernel object ID. |
SignalHandler | The type of kernel object signal handler. |