I have found that functions get_unaligned and put_unaligned from unaligned.h
are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze architectures.
And are not hidden on other platforms. But why?
I think that these functions are very useful in user space.
So here is the patch:
diff -purN -U 5 linux-2.6.36/arch/microblaze/include/asm/unaligned.h
linux/arch/microblaze/include/asm/unaligned.h
--- linux-2.6.36/arch/microblaze/include/asm/unaligned.h 2010-10-21
00:30:22.000000000 +0400
+++ linux/arch/microblaze/include/asm/unaligned.h 2010-10-31
18:05:31.513345000 +0300
@@ -8,16 +8,13 @@
*/
#ifndef _ASM_MICROBLAZE_UNALIGNED_H
#define _ASM_MICROBLAZE_UNALIGNED_H
-# ifdef __KERNEL__
-
# include <linux/unaligned/be_struct.h>
# include <linux/unaligned/le_byteshift.h>
# include <linux/unaligned/generic.h>
# define get_unaligned __get_unaligned_be
# define put_unaligned __put_unaligned_be
-# endif /* __KERNEL__ */
#endif /* _ASM_MICROBLAZE_UNALIGNED_H */
diff -purN -U 5 linux-2.6.36/arch/powerpc/include/asm/unaligned.h
linux/arch/powerpc/include/asm/unaligned.h
--- linux-2.6.36/arch/powerpc/include/asm/unaligned.h 2010-10-21
00:30:22.000000000 +0400
+++ linux/arch/powerpc/include/asm/unaligned.h 2010-10-31
18:05:43.968057400 +0300
@@ -1,16 +1,13 @@
#ifndef _ASM_POWERPC_UNALIGNED_H
#define _ASM_POWERPC_UNALIGNED_H
-#ifdef __KERNEL__
-
/*
* The PowerPC can do unaligned accesses itself in big endian mode.
*/
#include <linux/unaligned/access_ok.h>
#include <linux/unaligned/generic.h>
#define get_unaligned __get_unaligned_be
#define put_unaligned __put_unaligned_be
-#endif /* __KERNEL__ */
#endif /* _ASM_POWERPC_UNALIGNED_H */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
> I have found that functions get_unaligned and put_unaligned from unaligned.h
> are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze architectures.
> And are not hidden on other platforms. But why?
Since <asm/unaligned.h> is not an exported header the point is moot.
Andreas.
--
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
And why not to export <asm/unaligned.h>? I think it will be useful to
have unified mechanism
for unaligned memory access in users pace. There are numerous
libraries that deal
with binary file formats with unaligned structure fields. Also there
are some network
protocols with unaligned fields of packets.
I think that unaligned memory access interface are stable, so it can
be safely exported
to user space. We have some other platform-related exported headers,
e.g. <asm/byteorder.h>,
so why not to export <asm/unaligned.h>. Let it be "official" way to
deal with unaligned data
in user space too.
> I think that unaligned memory access interface are stable, so it can
> be safely exported
> to user space. We have some other platform-related exported headers,
> e.g. <asm/byteorder.h>,
> so why not to export <asm/unaligned.h>. Let it be "official" way to
> deal with unaligned data
> in user space too.
There are libraries to deal with stuff like this. The kernel headers
are in no way a portable way to do this and any code that tries to
use them in this way would not even be portable across different
distribution that put the kernel headers in different places or
to architectures that define these functions as extern.
If you need something like get_unaligned, look in places like
http://ccan.ozlabs.org or http://www.gnu.org/software/gnulib/.
You can also use a generic gcc based implementation that uses
attribute((packed)) for unaligned access.
Arnd