Skip to content

Commit 5bf2afe

Browse files
committed
Improve docs.
1 parent 7a73a2d commit 5bf2afe

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/rights.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
//! Provides wrappers for Mach port right names.
2+
//!
3+
//! The module provides 3 types [`SendRight`], [`SendOnceRight`] and [`RecvRight`] that are wrappers
4+
//! for raw `mach_port_t` values (aka Mach port names).
5+
//!
6+
//! # Ownership
7+
//!
8+
//! Each of these values represent a single user reference on the corresponding right to a Mach
9+
//! port. That means when a value is dropped, the task loses a reference to the Mach port right
10+
//! represented by the wrapped name (through a call to `mach_port_mod_refs`). Additionally,
11+
//! [`SendRight`] wrappers can be cloned which increases the number of references to the port's
12+
//! send right.
213
314
use crate::{
415
msg::{MsgBuffer, MsgBuilder, MsgParser, RecvError, SendError},
@@ -98,14 +109,14 @@ impl SendRight {
98109
impl Clone for SendRight {
99110
#[inline(always)]
100111
fn clone(&self) -> Self {
101-
self.mod_refs(1);
112+
assert_eq!(self.mod_refs(1), KERN_SUCCESS);
102113

103114
SendRight(self.0)
104115
}
105116

106117
#[inline(always)]
107118
fn clone_from(&mut self, source: &Self) {
108-
source.mod_refs(1);
119+
assert_eq!(self.mod_refs(1), KERN_SUCCESS);
109120

110121
self.0 = source.0;
111122
}

src/traits.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@
22
33
use mach2::port::{mach_port_right_t, mach_port_t};
44

5-
/// A trait for everything that wraps a raw Mach port name (aka `mach_port_t`) and can be converted
6-
/// into it.
5+
/// A trait to get a raw Mach port name (`mach_port_t`) from an object.
76
pub trait AsRawName {
87
/// Specifies the disposition value to be set in a port descriptor when the represented right
98
/// reference has to be moved to the receiver's IPC space.
109
///
1110
/// This should be one of the `MACH_MSG_TYPE_MOVE_*` constants.
1211
const MSG_TYPE: mach_port_right_t;
1312

14-
/// Converts a type into a raw Mach port name. This function should not alter reference counts
15-
/// of any port rights.
13+
/// Extracts the raw Mach port name.
14+
///
15+
/// This function is intended to **borrow** a Mach port right reference. That is, the ownership
16+
/// of the reference isn't passed to the caller, and the name is only guaranteed to represent
17+
/// the corresponding port right only during the lifetime of the original object.
18+
///
19+
/// This function should not alter reference counts of the port right represented by the name.
1620
fn as_raw_name(&self) -> mach_port_t;
1721
}
1822

19-
/// A trait for everything that wraps a raw Mach port name (aka `mach_port_t`) and can be converted
20-
/// into it.
23+
/// A trait to convert an object into a raw Mach port name (`mach_port_t`) while taking ownership
24+
/// of the port right reference represented by the name.
2125
pub trait IntoRawName: AsRawName {
22-
/// Converts a type into a raw Mach port name. This function should not alter reference counts
23-
/// of any port rights.
26+
/// Converts an object into a raw Mach port name.
27+
///
28+
/// This function is intended to **pass** a Mach port right reference from a destructed object
29+
/// to the caller. That means the caller will be responsible for properly dropping the reference
30+
/// when it is no longer needed.
31+
///
32+
/// This function should not alter reference counts of the port right represented by the name.
2433
fn into_raw_name(self) -> mach_port_t;
2534
}

0 commit comments

Comments
 (0)