Giter Site home page Giter Site logo

data-race safety about memmap-rs HOT 4 CLOSED

danburkert avatar danburkert commented on June 26, 2024
data-race safety

from memmap-rs.

Comments (4)

danburkert avatar danburkert commented on June 26, 2024 1

@tomjakubowski is exactly right. My current plan is to remove the Deref and DerefMut impls on Mmap and replace it with a pair of methods:

unsafe fn as_slice(&self) -> &[u8];
unsafe fn as_mut_slice(&mut self) -> &[u8];

Additionally, I would like to add support for file locks (even if it is only advisory on POSIX systems) in order to have a runtime check of safety.

from memmap-rs.

xrl avatar xrl commented on June 26, 2024

What assumptions are broken? Seems fine to me. The mmaps of the same file have different lifetimes and the underlying semantics of how a mmap work are left to the user to consider.

from memmap-rs.

tomjakubowski avatar tomjakubowski commented on June 26, 2024

What assumptions are broken? Seems fine to me. The mmaps of the same file have different lifetimes and the underlying semantics of how a mmap work are left to the user to consider.

The compiler assumes that data behind a &T, where T does not contain UnsafeCell, will not be changed for the lifetime of the reference. It also assumes that a &mut T has exclusive access to its memory. If either of these assumptions are violated, then your program has undefined behavior.

Are data races confined to just shared mmaps, or do anonymous maps expose data races?

A child process can observe writes to shared, anonymous mmaps created by its parent, so I suspect that sticking to anonymous maps isn't sufficient. Maybe anonymous, private mmaps are free from data races.

from memmap-rs.

danburkert avatar danburkert commented on June 26, 2024

I think this issue is fixed. The state of the world is: accessing memory from a Mmap requires an unsafe block, with the invariants clearly marked on the slicing methods (users should ensure that other processes or views are not accessing the memory concurrently). I'm going to punt on file locks, since that is outside the scope of this crate. If someone comes up with a good cross-platform flock interface, this could be used along with the Mmap constructors that take a File for additional runtime safety.

from memmap-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.