Giter Club home page Giter Club logo

Comments (4)

Wasabi375 avatar Wasabi375 commented on July 17, 2024

Also if I read the Rustonmicon correctly they probably consider page faults as something that should be marked as unsafe.

  • A reference cannot outlive its referent

https://doc.rust-lang.org/nomicon/references.html

from x86_64.

phil-opp avatar phil-opp commented on July 17, 2024

4. map the page again

This would require an unsafe operation in our current API.

from x86_64.

Wasabi375 avatar Wasabi375 commented on July 17, 2024

Maybe your right. That said I personally am not sure about the idea that page faults are not UB, but I guess it's not that big of a deal.

I just found #202 and I understand where you're coming from on this point. Would you be willing to accept a PR that adds some reasoning for this in the documentation for unmap. Looks like I'm not the only one who thinks that way.

from x86_64.

phil-opp avatar phil-opp commented on July 17, 2024

Page faults are often handled transparently by the operating system, e.g. when swapping out pages to disk. When the CPU tries to access the referenced value, the OS can handle the page fault by reading the original page back from disk and restoring the original mapping. So the referenced value still exists and is still alive, it's just is no longer in RAM.

Another example are pages that are marked as copy-on-write during fork. Once the CPU tries to modify a value (e.g. referenced by a &mut) a page fault occurs. The OS typically reacts by copying the page to a new physical frame so that it can safely modified.

Of course this all depends on the correct behavior of the OS. When it maps the wrong page on a page fault, it's definitely undefined behavior. We model this in our API by making the map_to method unsafe because that's the place where you need to ensure that no mutable aliasing etc occurs.

So I guess the question is: Is there a way to cause UB using unmap without using any other unsafe method such as map_to? Is it UB to abort a user program on such a page fault?

I'm happy to discuss this further and I'm not strongly opposed to make unmap unsafe if there is a good reason. We just try to only define methods as unsafe if absolutely needed because otherwise the whole crate would consist of unsafe methods.

from x86_64.

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.