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

[Xen-changelog] [xen-unstable] Clean up libelf endian macros and includes.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxxx
# Date 1170010920 0
# Node ID f8ddcb7581173f1b3a756a1cb96491ec1ff65403
# Parent  bef8a8b1e400c89f68d498c204f2500e5e9dc11b
Clean up libelf endian macros and includes.
Based on a patch from John Levon <john.levon@xxxxxxx>
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 xen/common/libelf/libelf-private.h |   36 ++++++++++++++++++++----------------
 xen/common/libelf/libelf-tools.c   |    4 ++--
 xen/include/public/libelf.h        |   33 ++++++++-------------------------
 3 files changed, 30 insertions(+), 43 deletions(-)

diff -r bef8a8b1e400 -r f8ddcb758117 xen/common/libelf/libelf-private.h
--- a/xen/common/libelf/libelf-private.h        Sun Jan 28 18:45:04 2007 +0000
+++ b/xen/common/libelf/libelf-private.h        Sun Jan 28 19:02:00 2007 +0000
@@ -1,7 +1,13 @@
+#ifndef __LIBELF_PRIVATE_H__
+#define __LIBELF_PRIVATE_H_
+
 #ifdef __XEN__
 
+#include <xen/config.h>
+#include <xen/types.h>
 #include <xen/string.h>
 #include <xen/lib.h>
+#include <asm/byteorder.h>
 #include <public/elfnote.h>
 #include <public/libelf.h>
 
@@ -11,29 +17,25 @@
        printk(fmt, ## args )
 
 #define strtoull(str, end, base) simple_strtoull(str, end, base)
-#define bswap_16(x) \
-     ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
-#define bswap_32(x) \
-     (  (((x) & 0xff000000) >> 24)  \
-      | (((x) & 0x00ff0000) >>  8)  \
-      | (((x) & 0x0000ff00) <<  8)  \
-      | (((x) & 0x000000ff) << 24))
-#define bswap_64(x) \
-     (  (((x) & 0xff00000000000000ull) >> 56)  \
-      | (((x) & 0x00ff000000000000ull) >> 40)  \
-      | (((x) & 0x0000ff0000000000ull) >> 24)  \
-      | (((x) & 0x000000ff00000000ull) >> 8)   \
-      | (((x) & 0x00000000ff000000ull) << 8)   \
-      | (((x) & 0x0000000000ff0000ull) << 24)  \
-      | (((x) & 0x000000000000ff00ull) << 40)  \
-      | (((x) & 0x00000000000000ffull) << 56))
+#define bswap_16(x) swab16(x)
+#define bswap_32(x) swab32(x)
+#define bswap_64(x) swab64(x)
 
 #else /* !__XEN__ */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stddef.h>
+#include <inttypes.h>
+#ifdef __sun__
+#include <sys/byteorder.h>
+#define bswap_16(x) BSWAP_16(x)
+#define bswap_32(x) BSWAP_32(x)
+#define bswap_64(x) BSWAP_64(x)
+#else
 #include <byteswap.h>
+#endif
 #include <xen/elfnote.h>
 #include <xen/libelf.h>
 
@@ -49,3 +51,5 @@
        } while (0)
 
 #endif
+
+#endif /* __LIBELF_PRIVATE_H_ */
diff -r bef8a8b1e400 -r f8ddcb758117 xen/common/libelf/libelf-tools.c
--- a/xen/common/libelf/libelf-tools.c  Sun Jan 28 18:45:04 2007 +0000
+++ b/xen/common/libelf/libelf-tools.c  Sun Jan 28 19:02:00 2007 +0000
@@ -7,7 +7,7 @@
 /* ------------------------------------------------------------------------ */
 
 uint64_t elf_access_unsigned(struct elf_binary * elf, const void *ptr,
-                            off_t offset, size_t size)
+                            uint64_t offset, size_t size)
 {
     int need_swap = elf_swap(elf);
     const uint8_t *u8;
@@ -35,7 +35,7 @@ uint64_t elf_access_unsigned(struct elf_
 }
 
 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
-                         off_t offset, size_t size)
+                         uint64_t offset, size_t size)
 {
     int need_swap = elf_swap(elf);
     const int8_t *s8;
diff -r bef8a8b1e400 -r f8ddcb758117 xen/include/public/libelf.h
--- a/xen/include/public/libelf.h       Sun Jan 28 18:45:04 2007 +0000
+++ b/xen/include/public/libelf.h       Sun Jan 28 19:02:00 2007 +0000
@@ -1,25 +1,12 @@
 #ifndef __XC_LIBELF__
 #define __XC_LIBELF__ 1
 
-#ifdef __XEN__
-
-#include <xen/inttypes.h>
-#include <public/features.h>
-typedef uint64_t off_t;
-
-#define LITTLE_ENDIAN 1234
-#define BIG_ENDIAN    4321
 #if defined(__i386__) || defined(__x86_64) || defined(__ia64__)
-#define BYTE_ORDER LITTLE_ENDIAN
+#define XEN_ELF_LITTLE_ENDIAN
 #elif defined(__powerpc__)
-#define BYTE_ORDER BIG_ENDIAN
-#endif
-
-#else /* !__XEN__ */
-
-#include <stddef.h>
-#include <inttypes.h>
-
+#define XEN_ELF_BIG_ENDIAN
+#else
+#error define architectural endianness
 #endif
 
 #undef ELFSIZE
@@ -91,14 +78,10 @@ struct elf_binary {
 /* ------------------------------------------------------------------------ */
 /* accessing elf header fields                                              */
 
-#if !defined(BYTE_ORDER)
-# error BYTE_ORDER not defined
-#elif BYTE_ORDER == BIG_ENDIAN
+#ifdef XEN_ELF_BIG_ENDIAN
 # define NATIVE_ELFDATA ELFDATA2MSB
-#elif BYTE_ORDER == LITTLE_ENDIAN
+#else
 # define NATIVE_ELFDATA ELFDATA2LSB
-#else
-# error BYTE_ORDER unknown
 #endif
 
 #define elf_32bit(elf) (ELFCLASS32 == (elf)->class)
@@ -131,9 +114,9 @@ struct elf_binary {
        : sizeof((str)->e32))
 
 uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr,
-                            off_t offset, size_t size);
+                            uint64_t offset, size_t size);
 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
-                         off_t offset, size_t size);
+                         uint64_t offset, size_t size);
 
 uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.