Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization:Do not use raw pointers #6

Open
flying-122 opened this issue May 19, 2022 · 3 comments
Open

optimization:Do not use raw pointers #6

flying-122 opened this issue May 19, 2022 · 3 comments

Comments

@flying-122
Copy link
Collaborator

pub(crate) struct Vcpu {
pub(crate) mmu: UniqueRef,
pub(crate) va_run: u64,

  • pub(crate) run: *mut RkvmRun, //here

It is better not to use raw pointers

@zhouhaoan
Copy link
Contributor

zhouhaoan commented May 19, 2022

It seems to be a Ref<> pointer in commit 89ef05fa(HEAD^), but modified to a raw pointer in the latest commit 5dca9316(HEAD). Both of them could be successfully compiled. Is it a mistake when commiting files?

@flying-122
Copy link
Collaborator Author

It seems to be a Ref<> pointer in commit 89ef05fa(HEAD^), but modified to a raw pointer in the latest commit 5dca9316(HEAD). Both of them could be successfully compiled. Is it a mistake when commiting files?

no. Ref<> cannot be converted to mutable

@zhouhaoan
Copy link
Contributor

zhouhaoan commented May 27, 2022

It seems to be a Ref<> pointer in commit 89ef05fa(HEAD^), but modified to a raw pointer in the latest commit 5dca9316(HEAD). Both of them could be successfully compiled. Is it a mistake when commiting files?

no. Ref<> cannot be converted to mutable

This is the related crates used in rust/kernel/sync/arc.rs, where the rust-kernel Ref is defined :

use core::{
    alloc::Layout,
    convert::{AsRef, TryFrom},
    marker::{PhantomData, Unsize},
    mem::{ManuallyDrop, MaybeUninit},
    ops::{Deref, DerefMut},
    pin::Pin,
    ptr::{self, NonNull},
};

Since the core::ops::DerefMut is not implemented to Ref, can we implement the DerefMut trait to rust-kernel Ref?

I think it can just write like this:

 impl<T: ?Sized> DerefMut for Ref<T> {
    type Target = T;

    fn deref_mut(&self) -> &mut Self::Target {
        
        unsafe { &mut self.ptr.as_mut().data }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants