Comments (1)
I thought about the use of StableDeref
a bit more. The guarantees it provides with regard to DerefMut
are a bit hard to grasp. For example, Vec
implements StableDeref
, even though it can re-allocate if you push to it. My understanding is that the stable address guarantee for DerefMut
types only holds as long as you don't call &mut self
methods on the type itself. But the documentation doesn't explicitly state that.
Let's take a step back. Here is what I gather are the minimum requirements a generic safe DMA buffer type has to fulfill:
- It must be a pointer.
Otherwise the buffer would be part of theTransfer
struct and move around with it on the stack, which we cannot allow (see 3). - The referenced buffer must be valid (i.e. not freed) for the length of the transfer.
Otherwise the compiler could re-use the buffer space for other data, while the DMA was still reading from/writing to it. - The referenced buffer must be at a stable address for the length of the transfer.
Same reason as 2. Additionally, data returned from DMA reads would be incomplete when the buffer moved in the meantime.
Requirements 2 and 3 must be true even if we take mem::forget
into account: If the Transfer
is mem::forget
ten, we won't be able to stop the DMA since the destructor is not run. So the buffer needs to stay valid and stable afterwards.
Looking at the types StableDeref
is implemented for out of the box, it looks like all of them fulfill the above requirements. So provided I'm not missing an essential requirement above, using StableDeref
for DMA buffers should be fine. In fact, it seems to be exactly what we need in terms of guarantees.
from embedonomicon.
Related Issues (20)
- Links need to be updated for new books location HOT 1
- Reminder: Back out hardcoded mdbook v0.2.1 version HOT 2
- gcc-arm-none-eabi Install instructions out of date for Ubuntu 18.04? HOT 6
- no files found ./target/thumbv7m-none-eabi/debug/deps/app-*.o
- remedy for `eh_personality` error HOT 2
- Link error in memory layout example
- Travis builds are failing HOT 2
- grep command has wrong case HOT 1
- CI could be more flexible when checking objdumps
- Some examples produce warnings when run
- Add Software Guide Posts for Board Crate Writers
- Question about EXTERN(RESET_VECTOR) HOT 2
- Imlementation of Entirely new Embedded Architecture for Rust HOT 1
- Endless copy loop: Incorrect implementation or wrongly compiled? HOT 6
- Nightly/newer versions of llvm-binutils no longer recognize `--arch-name`
- Update CI
- --no-show-raw-insn with one '-' at start in examples HOT 3
- Exception Handling vector table objdump addresses inconsistent
- Address of functions missing in dissassembly
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 embedonomicon.