Re: [PATCH V3 2/3] Implement byte-by-byte memory access facilitators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Sam Ravnborg <sam@xxxxxxxxxxxx>
Date: Mon, 25 Apr 2016 22:48:45 +0200

> A simpler model would be
> #define LOADER(TYPE, addr)                         \
> ({                                                 \
> 	TYPE ret;                                  \
> 	memcpy(&ret, (void *)addr, sizeof(TYPE));  \
> 	ret;                                       \
> })
> 
> I would expect the compiler to optimize this away for archs
> that do not require aligned access.

The compiler is allowed to "look through" void pointer casts and
use the alignment guaranteed by the original types.

That is why memcpy()'s aren't used for unaligned access handling.

Take a look at include/linux/unaligned/packed_struct.h in the kernel
sources, which is in my opinion the most portable and efficient way to
deal with this problem.

That code does the right thing on both architectures where alignment
matters, and where it does not.

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility



[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux