rust-uio icon indicating copy to clipboard operation
rust-uio copied to clipboard

Impossible to get file lock again after opening a device and doing map_mapping

Open SebastianHambura opened this issue 8 months ago • 0 comments

While doing some more test, I think I found a bug: rust-uio is not always unlocking the file when dropping, and then we try to get the lock again it's blocking and waiting forever.

I was trying to use uiodevice to get the raw memory of my custom device, copy the data into a Rust struct using Deku, change some value in the rust struct, and then write the new value back to the device.

Reading is working fine, but trying to write back hangs on devfile.lock_exclusive()?;. Replacing this call by try_lock_exclusive raises an Error ( Resource temporarily unavailable (os error 11) ). My guess is that we get a file lock, but we because we do memory mapping afterwards, when we drop the file it's not completely dropped, and the lock survives.

Anyways, adding the following seems to solve the issue (but I'm wondering if we should also unmap the memory at the same time ?):

impl Drop for UioDevice {
    fn drop(&mut self) {
        self.devfile.unlock();
    }
}

Sorry if that doesn't make sense, I'm not very used to work on that kind of things.

SebastianHambura avatar Jun 13 '24 13:06 SebastianHambura