Skip to content

Larger canvas at SlotPool::create_buffer #488

@l4l

Description

@l4l

For given buffer, canvas = SlotPool::create_buffer(..), canvas might be bigger than the one returned from buffer.canvas(). This happens because of buffer alignment at the allocation:

len = (len + 63) & !63;

for the Buffer::canvas it explicitly limits the canvas by height*stride as expected:

let len = (self.height as usize) * (self.stride as usize);
if self.slot.inner.active_buffers.load(Ordering::Relaxed) != 0 {
return None;
}
if self.slot.inner.free_list.as_ptr() == Arc::as_ptr(&pool.free_list) {
Some(&mut pool.inner.mmap()[self.slot.inner.offset..][..len])

while the Slot::raw_data_mut inside create_buffer has only a bound of the allocated slot:

&mut self.inner.mmap()[slot.inner.offset..][..slot.inner.len]

This implementation is fine if documented. Although I would rather prefer these two to be the same without exposing inner stuff. Also, is SlotPool::raw_data_mut really sound considering aliasing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions