Comments (1)
Hey @phil-opp, I recently went down the rabbit hole researching references to "volatile" memory in Rust. If you haven't seen them yet, here are some convincing resources that support your idea to use raw pointers and volatile operations:
- https://lokathor.github.io/volatile/
- https://users.rust-lang.org/t/how-to-make-an-access-volatile-without-std-library/85533
- https://internals.rust-lang.org/t/volatile-wrapping-structs/10273
- rust-lang/unsafe-code-guidelines#33
Many of those resources are more concerned with spurious reads, but what I got from them is when interacting with memory "owned" by the hardware and that can be modified by the hardware, it is better to wrap raw pointers and use volatile reads/writes. My current thinking is Rust references are more appropriate for data created by Rust, either on the heap or the stack, that is fully "owned" by Rust.
In my OS, I wrote some simple wrapper types around raw pointers for registers, and a register_struct!
macro that allows easily constructing types that contain these registers at specified offsets. (I took inspiration from voladdress
).
I actually came across this specific issue because I wanted to wrap a type I have for physical memory allocation in a Mutex
so I could use it as an impl Allocator
when I need to create physically contiguous memory chunks, and Allocator
uses &self
on its methods. However, I also needed it for Mapper.identity_map()
, which requires both &mut self
and a &mut FrameAllocator
. I couldn't quite figure out how to make this work without aliasing mutable memory, and went searching for a solution.
P.S. I read both editions of your "Writing an OS in Rust" blog series and I learned so much! Thanks for investing in the bare metal Rust ecosystem. It is really rewarding to learn about and use.
from x86_64.
Related Issues (20)
- Set minimal scoped permissions to github workflow HOT 1
- Create a Security Policy
- IDT and page table code causing trouble in Confidential Computing space HOT 1
- Hash pin workflow dependencies HOT 9
- `Descriptor::tss_segment` too restrictive? HOT 2
- recursive page table with recursive index 511 is unsound HOT 7
- How can I set 2MiB page frame in my Page Directory Table? HOT 1
- How do I map to a virtualized physical address? HOT 1
- Enable OpenSSF Scorecard Action HOT 2
- [Question] Is there a reason to not support pagemaps level 5 ? HOT 2
- Trait for Entry handler function types? HOT 2
- Should we add an register abstraction? How should it work with and ?
- `VirtAddr` arithmetic may panic HOT 2
- Returning FrameAlreadyMapped error when it shouldn't HOT 10
- Should have a way to construct an `InterruptStackFrameValue`? HOT 3
- A `VirtualAddr` panic is triggered when the page table called `clean_up` HOT 3
- `Sealed::DEBUG_STR` is publicly accessible HOT 10
- PageTable: Handling of pages without the present flag set HOT 2
- `Mapper::unmap` should be unsafe HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from x86_64.