Skip to content

Commit

Permalink
Fix unaligned memory access when reading DRM events
Browse files Browse the repository at this point in the history
Running with debug assertions enabled on armv7 (an stm32mp157) panics
due to unaligned memory reads:

thread 'main' panicked at 'misaligned pointer dereference: address must be a multiple of 0x8 but is 0xbec90b44', .../drm-0.9.0/src/control/mod.rs:906:34

Fix this by using the corresponding functions from core to safely
copy the data (in C we'd do a memcpy).
  • Loading branch information
tronical committed Mar 19, 2024
1 parent 328742f commit 55d96b1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,9 @@ impl Iterator for Events {
self.i += event.length as usize;
match event.type_ {
ffi::DRM_EVENT_VBLANK => {
let vblank_event =
unsafe { &*(event as *const _ as *const ffi::drm_event_vblank) };
let vblank_event = unsafe {
std::ptr::read_unaligned(event as *const _ as *const ffi::drm_event_vblank)
};
Some(Event::Vblank(VblankEvent {
frame: vblank_event.sequence,
time: Duration::new(
Expand All @@ -1143,8 +1144,9 @@ impl Iterator for Events {
}))
}
ffi::DRM_EVENT_FLIP_COMPLETE => {
let vblank_event =
unsafe { &*(event as *const _ as *const ffi::drm_event_vblank) };
let vblank_event = unsafe {
std::ptr::read_unaligned(event as *const _ as *const ffi::drm_event_vblank)
};
Some(Event::PageFlip(PageFlipEvent {
frame: vblank_event.sequence,
duration: Duration::new(
Expand Down

0 comments on commit 55d96b1

Please sign in to comment.