|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 09/23] lz4: add support for OSes that don't have asm/unaligned.h
Add a configure check for asm/unaligned.h presence, and if it's not
available open-code the necessary functions for lz4.
Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
tools/config.h.in | 3 +++
tools/configure.ac | 2 +-
xen/common/lz4/defs.h | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/tools/config.h.in b/tools/config.h.in
index 283cee7..709a51d 100644
--- a/tools/config.h.in
+++ b/tools/config.h.in
@@ -57,6 +57,9 @@
/* Define to 1 if you have the <sys/endian.h> header file. */
#undef HAVE_SYS_ENDIAN_H
+/* Define to 1 if you have the <asm/unaligned.h> header file. */
+#undef HAVE_ASM_UNALIGNED_H
+
/* Define curses header to use */
#undef INCLUDE_CURSES_H
diff --git a/tools/configure.ac b/tools/configure.ac
index 3b8db0a..cf30254 100644
--- a/tools/configure.ac
+++ b/tools/configure.ac
@@ -247,7 +247,7 @@ AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could
not find libfdt])])
esac
# Checks for header files.
-AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h endian.h sys/endian.h])
+AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h endian.h sys/endian.h
asm/unaligned.h])
AC_OUTPUT()
diff --git a/xen/common/lz4/defs.h b/xen/common/lz4/defs.h
index f46df08..f4b810a 100644
--- a/xen/common/lz4/defs.h
+++ b/xen/common/lz4/defs.h
@@ -23,7 +23,49 @@ static inline u32 INIT get_unaligned_le32(const void *p)
return le32_to_cpup(p);
}
#else
+#ifdef HAVE_ASM_UNALIGNED_H
#include <asm/unaligned.h>
+#else
+
+#if defined(HAVE_ENDIAN_H)
+#include <endian.h>
+#elif defined(HAVE_SYS_ENDIAN_H)
+#include <sys/endian.h>
+#endif
+
+#define le16_to_cpu(x) le16toh(x)
+#define le32_to_cpu(x) le32toh(x)
+
+extern void bad_unaligned_access_length(void) __attribute__((noreturn));
+
+struct __una_u32 { uint32_t x __attribute__((packed)); };
+struct __una_u16 { uint16_t x __attribute__((packed)); };
+
+static inline uint16_t __uldw(const uint16_t *addr)
+{
+ const struct __una_u16 *ptr = (const struct __una_u16 *) addr;
+ return ptr->x;
+}
+static inline uint32_t __uldl(const uint32_t *addr)
+{
+ const struct __una_u32 *ptr = (const struct __una_u32 *) addr;
+ return ptr->x;
+}
+#define __get_unaligned(ptr, size) ({ \
+ uint64_t __val; \
+ switch (size) { \
+ case 2: \
+ __val = __uldw(ptr); \
+ break; \
+ case 4: \
+ __val = __uldl(ptr); \
+ break; \
+ default: \
+ bad_unaligned_access_length(); \
+ }; \
+ __val; \
+})
+#endif /* !HAVE_ASM_UNALIGNED_H */
static inline u16 INIT get_unaligned_le16(const void *p)
{
--
1.7.7.5 (Apple Git-26)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |