Possible to interleave `&mut` and `&` safely?
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- rust
- Domaine
- operating-systems
Piste de recherche
Start with the Node and Thread examples in the issue, then examine the proposed UnsafeCell and raw-pointer approaches in light of Rust's aliasing rules. Done means resolving both pointer-arithmetic and non-raw-pointer API questions, with the resulting guidance recorded in the issue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
I'm working on a linked list implementation for an embedded kernel. We have the following Thread structure, which will be a member of a list:
struct Node<T> {
next: Option<NonNull<Node<T>>>,
prev: Option<NonNull<Node<T>>>,
t: T,
}
struct Thread {
stack: [u8; STACK_SIZE],
id: u32,
...
}
The stack is the thread's stack, which will be used to hold arbitrary Rust values, which might include &mut references to other values in the stack (i.e., it might be self-referential). (While pinning is obviously a concern, that's not what this issue is about.)
In addition to self-references in the stack, we also need to be able to inspect other fields in Thread from inside the scheduler.
Here's an example - possibly problematic - sequence of events:
- Some code runs in the thread which writes a
&mutreference to the stack that also refers to the stack. - The thread yields control, which hands control over to the scheduler
- The scheduler obtains a
&Node<Thread>reference to the currently-running thread and reads itsidfield
While, in (3), we haven't read data from stack, I presume that it's still considered UB to have a &Node<Thread> while other &mut references exist which point into the stack, which overlaps with the referent of the &Node<Thread>?
My first thought was to just wrap the whole thing in UnsafeCell so that the Node API doesn't provide &Threads, but instead provides &UnsafeCell<Thread>s. But IIUC that doesn't solve the problem - it's still illegal to have &UnsafeCell<T> and &mut T overlap.
My next thought was to just use raw pointers and never synthesize & references.
Concretely, my questions are the following. All of them are in the context of &mut references existing which refer to stack.
- Given a
NonNull<Node<Thread>>, is it sound to perform pointer arithmetic to obtain aNonNull<u32>and dereference it? Specifically, is it problematic that the originalNonNull<Node<Thread>>refers to the wholeThread, including thestack? - Is there any way to provide a non-raw-pointer API which provides access to the inner
Tin aNode<T>which would play nicely with this use case?
- Langage dominant
- Aucune donnée de langage
- Étoiles
- 760
- Forks
- 68
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rust-lang/unsafe-code-guidelines
-
I-opsem-nominated
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
rust-lang/unsafe-code-guidelines#634 · 5 commentaires ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 12/100
rust-lang/unsafe-code-guidelines#632 · 8 commentaires · 1 réaction ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 10/100
rust-lang/unsafe-code-guidelines#631 · 7 commentaires ·
-
I-opsem-nominated
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
rust-lang/unsafe-code-guidelines#630 · 1 réaction ·
Toutes les issues de rust-lang/unsafe-code-guidelines
Issues similaires
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindPeut-être pris @arshil42 l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
[Cache] Downloads without symlinks fail on Windows for snapshot paths of 223-259 chars since #5354Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
huggingface/huggingface_hub#5481 ·
Les mainteneurs répondent en général sous 1 jour
-
Issue with hwdb warning messageOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
danielmiessler/LifeOS#3023 ·
Les mainteneurs répondent en général sous 5 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
anomalyco/hex#3067 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour