Hi, was reading your code as a nice little reference, and I think the extract_mask() function of exec.rs could be replaced with the 1.83 stabilisation of Waker::data().
|
/// Exploits our known Waker structure to extract the notification mask from a |
|
/// Waker. |
|
/// |
|
/// If this is applied to a Waker that isn't from this executor (specifically, |
|
/// one not generated by `waker_for_task`), this will cause spurious and almost |
|
/// certainly incorrect wakeups. Currently I don't feel like that risk is great |
|
/// enough to mark this unsafe -- it can't violate *memory* safety for certain. |
|
/// |
|
/// In practice this function compiles down to a single inlined load |
|
/// instruction. |
|
fn extract_mask(waker: &Waker) -> usize { |
|
// Determine whether the pointer member comes first or second within the |
|
// representation of RawWaker. This is currently compile-time simplified |
|
// and goes away. |
|
// |
|
// Safety: we are using `transmute` to inspect the raw composition of a |
|
// Waker. That direction is safe -- it's a fancy version of casting a |
|
// pointer to an integer. Transmuting the _other_ direction would be very |
|
// unsafe. |
|
let ptr_first = unsafe { |
|
let (cell0, _) = mem::transmute::<Waker, (usize, usize)>( |
|
Waker::from_raw(RawWaker::new( |
|
1234 as *const (), |
|
&VTABLE, |
|
)) |
|
); |
|
cell0 == 1234usize |
|
}; |
|
|
|
let waker: *const Waker = waker; |
|
// Safety: at the moment, `Waker` consists exactly of a `*const ()` and a |
|
// `&'static RawWakerVTable` (or equivalent pointer), and this is unlikely |
|
// to change. We've already verified above that we can find the parameter |
|
// word, which is what we care about. Extracting it cannot violate memory |
|
// safety, since we're just reading initialized memory. |
|
unsafe { |
|
let parts = &*(waker as *const (usize, usize)); |
|
if ptr_first { |
|
parts.0 |
|
} else { |
|
parts.1 |
|
} |
|
} |
|
} |
https://dev-doc.rust-lang.org/std/task/struct.Waker.html#method.data
Possibly not 100% desired since it's quite new, but it'd be nice to use if possible. (unfortunately, cfg-version gating seems to still be nightly only...)
Hi, was reading your code as a nice little reference, and I think the
extract_mask()function ofexec.rscould be replaced with the 1.83 stabilisation ofWaker::data().lilos/os/src/exec.rs
Lines 203 to 246 in 7fc6c64
https://dev-doc.rust-lang.org/std/task/struct.Waker.html#method.data
Possibly not 100% desired since it's quite new, but it'd be nice to use if possible. (unfortunately, cfg-version gating seems to still be nightly only...)