lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1402441994-16780-5-git-send-email-hpa@zytor.com>
Date:	Tue, 10 Jun 2014 16:13:08 -0700
From:	"H. Peter Anvin" <hpa@...or.com>
To:	Sam Ravnborg <sam@...nborg.org>, linux-kernel@...r.kernel.org,
	linux-kbuild@...r.kernel.org, linux-arch@...r.kernel.org
Cc:	Andy Lutomirski <luto@...capital.net>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Ingo Molnar <mingo@...nel.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	"H. Peter Anvin" <hpa@...or.com>
Subject: [PATCH RFC 04/10] tools: Add packed struct method for unaligned references

gcc can generate code for unaligned references using a packed struct
on nearly all architectures.

Signed-off-by: H. Peter Anvin <hpa@...or.com>
---
 tools/include/tools/unaligned/be_struct.h | 60 +++++++++++++++++++++++++++++++
 tools/include/tools/unaligned/le_struct.h | 60 +++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 tools/include/tools/unaligned/be_struct.h
 create mode 100644 tools/include/tools/unaligned/le_struct.h

diff --git a/tools/include/tools/unaligned/be_struct.h b/tools/include/tools/unaligned/be_struct.h
new file mode 100644
index 000000000000..27b73bdf5a86
--- /dev/null
+++ b/tools/include/tools/unaligned/be_struct.h
@@ -0,0 +1,60 @@
+#ifndef _TOOLS_BE_STRUCT_H
+#define _TOOLS_BE_STRUCT_H
+
+#include <stdint.h>
+
+struct _packed_u16_struct {
+	uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+	uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+	uint64_t v;
+} __attribute__((packed));
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+	const struct _packed_u16_struct *p = _p;
+
+	return p->v;
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+	const struct _packed_u32_struct *p = _p;
+
+	return p->v;
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+	const struct _packed_u64_struct *p = _p;
+
+	return p->v;
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+	struct _packed_u16_struct *p = _p;
+
+	p->v = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+	struct _packed_u32_struct *p = _p;
+
+	p->v = val;
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+	struct _packed_u64_struct *p = _p;
+
+	p->v = val;
+}
+
+#endif /* _TOOLS_BE_STRUCT_H */
diff --git a/tools/include/tools/unaligned/le_struct.h b/tools/include/tools/unaligned/le_struct.h
new file mode 100644
index 000000000000..281b03b8f316
--- /dev/null
+++ b/tools/include/tools/unaligned/le_struct.h
@@ -0,0 +1,60 @@
+#ifndef _TOOLS_LE_STRUCT_H
+#define _TOOLS_LE_STRUCT_H
+
+#include <stdint.h>
+
+struct _packed_u16_struct {
+	uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+	uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+	uint64_t v;
+} __attribute__((packed));
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+	const struct _packed_u16_struct *p = _p;
+
+	return p->v;
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+	const struct _packed_u32_struct *p = _p;
+
+	return p->v;
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+	const struct _packed_u64_struct *p = _p;
+
+	return p->v;
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+	struct _packed_u16_struct *p = _p;
+
+	p->v = val;
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+	struct _packed_u32_struct *p = _p;
+
+	p->v = val;
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+	struct _packed_u64_struct *p = _p;
+
+	p->v = val;
+}
+
+#endif /* _TOOLS_LE_STRUCT_H */
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ