Expand description

Kernel object basis.

Create new kernel object

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 lock::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

Empty kernel object. Just for test.

A Handle is how a specific process refers to a specific kernel object.

Information about a handle and the object it refers to.

Information about a handle itself, including its HandleValue.

The base struct of a kernel object.

Rights are associated with handles and convey privileges to perform actions on either the associated handle or the object associated with the handle.

Signals that waitable kernel objects expose to applications.

Constants

Invalid handle value.

Traits

Common interface of a kernel object.

Functions

Get an object’s type.

Asynchronous wait signal for multiple objects.

Type Definitions

The value refers to a Handle in user space.

The type of kernel object ID.

The type of kernel object signal handler.