On Tue, Mar 10, 2026 at 07:52:47PM +0000, Timur Tabi wrote:
> On Mon, 2026-03-09 at 20:59 +0100, Danilo Krummrich wrote:
>
> > > + /// Low-level write from a raw pointer. Caller must ensure ptr is
> > > valid for `len` bytes.
> > > + fn write_raw(&mut self, ptr: *const u8, len: usize) -> Result {
> >
> > The method has to be unsafe as the caller has to promise that ptr is indeed
> > a
> > slice with len elements.
>
> Ok.
>
> > Another option would be to pass a fat pointer, i.e. *const [u8]. write_dma()
> > would then need to use ptr::slice_from_raw_parts() and the safety
> > requirement of
> > this function becomes that ptr simply has to be valid.
>
> So I tried this approach, but the end result was that write_raw() and
> write_slice() were practically
> identical. At this point, why bother with write_raw() -- just have
> write_dma() call write_slice():
>
> let src_ptr = unsafe { alloc.start_ptr().add(offset) };
> let slice = unsafe { core::slice::from_raw_parts(src_ptr, count) };
> self.write_slice(slice)
>
> I think this is better, but I wanted to get your opinion before I posted a v8
> with this change.
Unfortunately, the creation of a reference into volatile memory is not
legal. Here, 'reference' includes slices. You can implement
`write_slice` in terms of `write_raw`, but the reverse will not work.
Alice