Using `pointer::add` with volatile memory

Aperta
#582 13 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Start with the quoted pointer::add safety requirements and the linked Rust std::ptr sections on provenance and allocations. Then examine how those rules apply to &raw mut (*volatile_ptr).field for volatile memory. Done means resolving or documenting whether this pattern is valid and what supported approach should be used.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When working with volatile memory it's common to do so entirely using raw pointers, making sure to never create a reference so that the volatile memory never gets considered a real allocation in the opsem.

The pointer::add method has these safety requirements:

If the computed offset is non-zero, then self must be derived from a pointer to some allocation, and the entire memory range between self and the result must be in bounds of that allocation. In particular, this range must not “wrap around” the edge of the address space.

The point of never creating a reference to the memory is to avoid assuming that there is a real allocation there. This is so that it's illegal for LLVM to introduce a spurious read to the volatile memory. From my reading of pointer::add it seems the same applies to that method.

However, this puts us in a somewhat tricky situation. It means that &raw mut (*volatile_ptr).field does not work for getting a pointer to a field of a struct in volatile memory, and the layout of volatile memory is often described by referring to an equivalent C struct. This is a challenge since there are no convenient alternatives to &raw mut.

Lingua principale
Nessun dato sulla lingua
Stelle
760
Fork
68
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/unsafe-code-guidelines

Tutte le issue di rust-lang/unsafe-code-guidelines

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.