Re: MemoryFence()


Paolo Bonzini <pbonzini@...>
 

Il ven 5 feb 2021, 19:47 Laszlo Ersek <lersek@...> ha scritto:

On 02/05/21 19:32, Paolo Bonzini wrote:

Unaligned pointers are already undefined behavior so you can ignore how
they are dealt with at the processor level.
My question was unclearly asked, sorry. Let's say we have a UINT32 at an
address that's not a multiple of 4, but a multiple of 2. A pointer to
that UINT32 is "acceptably aligned" on x86, but not "naturally aligned".
Dereferencing the pointer is not undefined (my reading of C99 suggests
that alignment requirements are implementation-defined), but I don't
know if the atomicity guarantee holds.
Got it, it's a very good question. All edk2 porting targets should
naturally align all types not larger than pointers. I can only think of old
m68k that had 2-byte aligned 32-bit pointers.

Another example; we may have a pointer to a packed structure, and we
might want to poke at a UINT32 field in that structure. Not through a
naked pointer-to-UINT32 of course, which would throw away the
packed-ness, but really through the pointer-to-the-whole-packed-struct.
Packed types indeed should not be considered atomic.

Paolo


Thanks
Laszlo

Join rfc@edk2.groups.io to automatically receive all group messages.