qemu-devel
[Top][All Lists]
Advanced

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

Re: [RFC PATCH v5 0/8] Add Rust support, implement ARM PL011


From: Manos Pitsidianakis
Subject: Re: [RFC PATCH v5 0/8] Add Rust support, implement ARM PL011
Date: Thu, 25 Jul 2024 17:48:04 +0300

On Thu, 25 Jul 2024 at 14:19, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On Thu, Jul 25, 2024 at 12:14 PM Manos Pitsidianakis
> <manos.pitsidianakis@linaro.org> wrote:
> > >Unfortunately that's a *mut, not a &mut. A &mut must be unique, so the cast
> > >in pl011_read() is undefined behavior.
> >
> > Actually it's:
> >
> >   unsafe { qemu_chr_fe_accept_input(&mut self.char_backend) };
> >
> > And you can ensure there's no disjoint borrowing by making a wrapper
> > function that mutably borrows self, e.g.
> >
> > fn accept_input(&mut self) {
> >   unsafe { qemu_chr_fe_accept_input(&mut self.char_backend) };
> > }
> >
> > This is not undefined behavior, since the cast in pl011_read creates a
> > mutable reference that does not outlive the same call to pl011_read.
>
> pl011_receive (called by qemu_chr_fe_accept_input) creates a mutable
> reference that *overlaps* the lifetime of the outer reference created
> by pl011_read. This is undefined behavior. You're effectively writing:

There is no overlap there, sorry. Once qemu_chr_fe_accept_input
returns, any references it created do not exist anymore.



reply via email to

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