Expose raw-pointer futex wake/wait APIs instead of only &AtomicU32
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- linux, rust
- Ambito
- operating-systems
Direzione di ricerca
Inizia con rustix:🧵:futex::wake e la sua chiamata a futex_val2, quindi esamina le API futex circostanti e le relative convenzioni per la gestione dei puntatori. Determina l’API per raw pointer e il contratto di sicurezza adatti all’interfaccia esistente; il lavoro è completo quando viene esposta un’operazione wake unsafe basata sull’indirizzo senza richiedere un riferimento Rust fabbricato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
rustix::thread::futex::wake currently requires a Rust reference:
#[inline]
pub fn wake(uaddr: &AtomicU32, flags: Flags, val: u32) -> io::Result<usize> {
// SAFETY: The raw pointers come from references or null.
unsafe { futex_val2(uaddr, Operation::Wake, flags, val, 0, ptr::null(), 0) }
}
This is too restrictive for some valid futex use cases.
The kernel futex interface fundamentally operates on an address. In some synchronization designs, the caller only has a raw pointer to the futex word, and creating an &AtomicU32 is not justified by Rust’s reference rules.
A concrete example is a futex embedded in a node or frame owned by another thread, including stack allocation. The waking thread may only know the target futex address via a raw pointer stored in a queue. Once the waiter is woken, it may return immediately and destroy the node / stack frame before the waking function returns. In that situation, requiring &AtomicU32 forces the caller to materialize a reference where only a raw-pointer contract is actually available.
Sketch:
struct Node {
state: AtomicU32,
next: AtomicPtr<Node>,
}
fn waiter_thread() {
let node = Node {
state: AtomicU32::new(0),
next: AtomicPtr::new(core::ptr::null_mut()),
};
enqueue(&node as *const Node);
unsafe {
// blocks while state == 0
futex_wait_raw(core::ptr::addr_of!(node.state), 0);
}
// after wake, this stack frame may exit immediately
}
fn waking_thread(node: *const Node) {
let futex_ptr = unsafe { core::ptr::addr_of!((*node).state) };
unsafe {
// This is the shape we need.
// Constructing `&AtomicU32` here is the problem.
futex_wake_raw(futex_ptr, Flags::PRIVATE, 1);
}
}
Today, libraries built on top of rustix end up needing to do one of these:
- Manufacture
&AtomicU32from a raw pointer even though they only truly have an address-based contract. - Avoid
rustixfor this case. - Carry extra ownership/borrowing structure that the kernel API does not require.
The problem is not that a raw-pointer API would be “safe”; it should be unsafe. The point is that the unsafety boundary should match the actual contract: “caller must provide a valid futex address for the duration of the syscall”, not “caller must already have a Rust reference”.
Proposed addition:
pub unsafe fn wake_ptr(
uaddr: *const AtomicU32,
flags: Flags,
val: u32,
) -> io::Result<usize>;
or perhaps
pub unsafe fn wake_ptr(
uaddr: NonNull<AtomicU32>,
flags: Flags,
val: u32,
) -> io::Result<usize>;
That would let higher-level synchronization code express the correct contract without fabricating references where only raw-pointer validity is available.
- Lingua principale
- Rust
- Stelle
- 2.1k
- Fork
- 322
- Merge medio
- 5g 16h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bytecodealliance/rustix
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
bytecodealliance/rustix#1736 ·
I maintainer di solito rispondono entro 1 giorno
-
termios::Termios::OutputModes does not expose some const for muslForse già presa @xtqqczze l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bytecodealliance/rustix#1706 · 31 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
net feature alone fails to compile in 1.1.5: sockopt uses crate::timespec, which net does not gate inForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
bytecodealliance/rustix#1689 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Wrong flag used for (set_)ipv6_multicast_hopsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bytecodealliance/rustix#1660 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
bytecodealliance/rustix#1635 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di bytecodealliance/rustix
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
longbridge/gpui-kit#3871 ·
I maintainer di solito rispondono entro 1 giorno
-
area:models enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
fix v1 repository metadataApertagood first issue help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
servo/rust-smallvec#864 ·
-
bug frontend ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno