From 6577b1a5ef911d1ece0858f0be83aa959869118f Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Sun, 19 Sep 2021 21:23:34 -0400 Subject: Mark all registers as transparent Guarantees that the layout is the same as the inner type. Since UnsafeCell is also transparent, this ensures that the register has the same ABI as T. Today's registers work without this. Otherwise, RAL register blocks would have unaccounted offsets / wrong sizes. This is for completness, and a signal for others that a transmute might be OK. Requires Rust 1.28. --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c1eca44..6122f01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ use core::cell::UnsafeCell; /// /// Access to this register must be synchronised; if multiple threads (or the main thread and an /// interrupt service routine) are accessing it simultaneously you may encounter data races. +#[repr(transparent)] pub struct RWRegister { register: UnsafeCell, } @@ -51,6 +52,7 @@ impl RWRegister { /// /// Access to this register must be synchronised; if multiple threads (or the main thread and an /// interrupt service routine) are accessing it simultaneously you may encounter data races. +#[repr(transparent)] pub struct UnsafeRWRegister { register: UnsafeCell, } @@ -85,6 +87,7 @@ impl UnsafeRWRegister { /// /// Access to this register must be synchronised; if multiple threads (or the main thread and an /// interrupt service routine) are accessing it simultaneously you may encounter data races. +#[repr(transparent)] pub struct RORegister { register: UnsafeCell, } @@ -107,6 +110,7 @@ impl RORegister { /// /// Access to this register must be synchronised; if multiple threads (or the main thread and an /// interrupt service routine) are accessing it simultaneously you may encounter data races. +#[repr(transparent)] pub struct UnsafeRORegister { register: UnsafeCell, } @@ -132,6 +136,7 @@ impl UnsafeRORegister { /// /// Access to this register must be synchronised; if multiple threads (or the main thread and an /// interrupt service routine) are accessing it simultaneously you may encounter data races. +#[repr(transparent)] pub struct WORegister { register: UnsafeCell, } @@ -154,6 +159,7 @@ impl WORegister { /// /// Access to this register must be synchronised; if multiple threads (or the main thread and an /// interrupt service routine) are accessing it simultaneously you may encounter data races. +#[repr(transparent)] pub struct UnsafeWORegister { register: UnsafeCell, } -- cgit v1.2.3