* Why get/put_unaligned are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze?
@ 2010-10-31 15:13 Igor Zhbanov
2010-10-31 15:27 ` Andreas Schwab
0 siblings, 1 reply; 4+ messages in thread
From: Igor Zhbanov @ 2010-10-31 15:13 UTC (permalink / raw)
To: linux-kernel
Hello!
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 */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why get/put_unaligned are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze?
2010-10-31 15:13 Why get/put_unaligned are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze? Igor Zhbanov
@ 2010-10-31 15:27 ` Andreas Schwab
2010-10-31 16:10 ` Igor Zhbanov
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2010-10-31 15:27 UTC (permalink / raw)
To: Igor Zhbanov; +Cc: linux-kernel
Igor Zhbanov <izh1979@gmail.com> writes:
> 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, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why get/put_unaligned are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze?
2010-10-31 15:27 ` Andreas Schwab
@ 2010-10-31 16:10 ` Igor Zhbanov
2010-10-31 17:45 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Igor Zhbanov @ 2010-10-31 16:10 UTC (permalink / raw)
To: linux-kernel
2010/10/31 Andreas Schwab <schwab@linux-m68k.org>:
>
> Since <asm/unaligned.h> is not an exported header the point is moot.
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why get/put_unaligned are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze?
2010-10-31 16:10 ` Igor Zhbanov
@ 2010-10-31 17:45 ` Arnd Bergmann
0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2010-10-31 17:45 UTC (permalink / raw)
To: Igor Zhbanov; +Cc: linux-kernel
On Sunday 31 October 2010, Igor Zhbanov wrote:
> 2010/10/31 Andreas Schwab <schwab@linux-m68k.org>:
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-31 17:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-31 15:13 Why get/put_unaligned are hidden behind #ifdef __KERNEL__ on PowerPC and Microblaze? Igor Zhbanov
2010-10-31 15:27 ` Andreas Schwab
2010-10-31 16:10 ` Igor Zhbanov
2010-10-31 17:45 ` Arnd Bergmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.