qemu-rust
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 14/26] rust: qom: move bridge for TypeInfo functions out of p


From: Zhao Liu
Subject: Re: [PATCH 14/26] rust: qom: move bridge for TypeInfo functions out of pl011
Date: Wed, 11 Dec 2024 00:02:15 +0800

> +unsafe extern "C" fn rust_instance_init<T: ObjectImpl>(obj: *mut Object) {
> +    // SAFETY: obj is an instance of T, since rust_instance_init<T>
> +    // is called from QOM core as the instance_init function
> +    // for class T
> +    unsafe { T::INSTANCE_INIT.unwrap()(&mut *obj.cast::<T>()) }
> +}

Here's the difference, why doesn't init() narrow the unsafe scope like
post_init() does?

> +unsafe extern "C" fn rust_instance_post_init<T: ObjectImpl>(obj: *mut 
> Object) {
> +    // SAFETY: obj is an instance of T, since rust_instance_post_init<T>
> +    // is called from QOM core as the instance_post_init function
> +    // for class T
> +    //
> +    // FIXME: it's not really guaranteed that there are no backpointers to
> +    // obj; it's quite possible that they have been created by 
> instance_init().
> +    // The receiver should be &self, not &mut self.
> +    T::INSTANCE_POST_INIT.unwrap()(unsafe { &mut *obj.cast::<T>() })
> +}
> +





reply via email to

[Prev in Thread] Current Thread [Next in Thread]