zx/
property.rs

1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Type-safe bindings for Zircon object properties.
6
7use crate::sys;
8use std::ops::Deref;
9use zerocopy::{FromBytes, Immutable, IntoBytes};
10
11/// Object property types for use with [object_get_property()] and [object_set_property].
12#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
13#[repr(transparent)]
14pub struct Property(u32);
15
16impl Deref for Property {
17    type Target = u32;
18
19    fn deref(&self) -> &Self::Target {
20        &self.0
21    }
22}
23
24/// A definition for properties about a zircon object.
25///
26/// # Safety
27///
28/// `PROPERTY` must correspond to a valid property type and `PropTy` must be the
29/// corresponding value type for that property. See
30/// https://fuchsia.dev/fuchsia-src/reference/syscalls/object_get_property for a
31/// list of available properties and their corresponding value types.
32///
33/// It must be valid to treat `PropTy` as its corresponding property type and
34/// writing the property type to a `PropTy` must completely initialize it. That
35/// is, `PropTy` must be "transparent" over the property type.
36pub(crate) unsafe trait PropertyQuery {
37    /// The raw `Property` value
38    const PROPERTY: Property;
39    /// The data type of this property
40    type PropTy: IntoBytes + FromBytes + Immutable;
41}
42
43assoc_values!(Property, [
44    NAME = sys::ZX_PROP_NAME;
45
46    #[cfg(target_arch = "x86_64")]
47    REGISTER_GS = sys::ZX_PROP_REGISTER_GS;
48    #[cfg(target_arch = "x86_64")]
49    REGISTER_FS = sys::ZX_PROP_REGISTER_FS;
50
51    PROCESS_BREAK_ON_LOAD = sys::ZX_PROP_PROCESS_BREAK_ON_LOAD;
52    PROCESS_DEBUG_ADDR = sys::ZX_PROP_PROCESS_DEBUG_ADDR;
53    PROCESS_VDSO_BASE_ADDRESS = sys::ZX_PROP_PROCESS_VDSO_BASE_ADDRESS;
54    SOCKET_RX_THRESHOLD = sys::ZX_PROP_SOCKET_RX_THRESHOLD;
55    SOCKET_TX_THRESHOLD = sys::ZX_PROP_SOCKET_TX_THRESHOLD;
56    CHANNEL_TX_MSG_MAX = sys::ZX_PROP_CHANNEL_TX_MSG_MAX;
57    JOB_KILL_ON_OOM = sys::ZX_PROP_JOB_KILL_ON_OOM;
58    EXCEPTION_STATE = sys::ZX_PROP_EXCEPTION_STATE;
59    VMO_CONTENT_SIZE = sys::ZX_PROP_VMO_CONTENT_SIZE;
60    STREAM_MODE_APPEND = sys::ZX_PROP_STREAM_MODE_APPEND;
61]);