Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97b17f5

Browse files
bradjclschuermann
authored andcommitted
Merge pull request tock#2468 from tock/pr_2446_comment_cleanup
Pr 2446 comment cleanup
2 parents 30d78d1 + 673ff9d commit 97b17f5

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

kernel/src/mem.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ pub trait Read {
3333
/// A default instance of an AppSlice must return 0.
3434
fn len(&self) -> usize;
3535

36-
/// Pointer to the userspace memory region.
36+
/// Pointer to the first byte of the userspace memory region.
3737
///
3838
/// If the length of the initially shared memory region
3939
/// (irrespective of the return value of [`len`](Read::len)) is 0,
40-
/// this function must return a pointer to address `0x0`. This is
41-
/// because processes allow buffers with length 0 to reclaim
42-
/// shared memory with the kernel and are allowed to specify _any_
43-
/// address, even if it is not contained within their address
44-
/// space. These _dummy addresses_ should not be leaked to outside
45-
/// code.
40+
/// this function returns a pointer to address `0x0`. This is
41+
/// because processes may allow buffers with length 0 to share no
42+
/// no memory with the kernel. Because these buffers have zero
43+
/// length, they may have any pointer value. However, these
44+
/// _dummy addresses_ should not be leaked, so this method returns
45+
/// 0 for zero-length slices.
4646
///
4747
/// # Default AppSlice
4848
///
@@ -124,6 +124,13 @@ impl ReadWriteAppSlice {
124124
Self::new(ptr, len, process_id)
125125
}
126126

127+
/// Consumes the ReadWriteAppSlice, returning its constituent
128+
/// pointer and size. This ensures that there cannot simultaneously
129+
/// be both a `ReadWriteAppSlice` and a pointer to its internal data.
130+
///
131+
/// `consume` can be used when the kernel needs to pass the underlying
132+
/// values across the kernel-to-user boundary (e.g., in return values to
133+
/// system calls).
127134
pub(crate) fn consume(self) -> (*mut u8, usize) {
128135
(self.ptr, self.len)
129136
}
@@ -234,6 +241,13 @@ impl ReadOnlyAppSlice {
234241
Self::new(ptr, len, process_id)
235242
}
236243

244+
/// Consumes the ReadOnlyAppSlice, returning its constituent
245+
/// pointer and size. This ensures that there cannot simultaneously
246+
/// be both a `ReadOnlyAppSlice` and a pointer to its internal data.
247+
///
248+
/// `consume` can be used when the kernel needs to pass the underlying
249+
/// values across the kernel-to-user boundary (e.g., in return values to
250+
/// system calls).
237251
pub(crate) fn consume(self) -> (*const u8, usize) {
238252
(self.ptr, self.len)
239253
}

0 commit comments

Comments
 (0)