[apparmor] [patch] parser: use htoleXX functions instead of testing for endianess

John Johansen john.johansen at canonical.com
Thu Mar 13 23:52:45 UTC 2014


On 03/13/2014 04:42 PM, Steve Beattie wrote:
> This patch applies on top of John's last submission. It makes use of
> the htoleXX() functions (see endian(3)) defined as part of endian.h
> (already included in parser_interface.c), instead of defining a
> function differently based on the detection of endian related macros.
> 
> This fixes a build failure experienced on powerpc with John's patch set
> applied.
> 
> Signed-off-by: Steve Beattie <steve at nxnw.org>

it needs one small change (noted) below and then you can add
Acked-by: John Johansen <john.johansen at canonical.com>

> ---
>  parser/parser.h           |   15 ++++++---------
>  parser/parser_interface.c |    3 ---
>  parser/parser_main.c      |    6 +-----
>  3 files changed, 7 insertions(+), 17 deletions(-)
> 
> Index: b/parser/parser_interface.c
> ===================================================================
> --- a/parser/parser_interface.c
> +++ b/parser/parser_interface.c
> @@ -37,9 +37,6 @@
>  #include <unistd.h>
>  #include <linux/unistd.h>
>  
> -/* only for x86 at the moment */
> -#include <endian.h>
> -#include <byteswap.h>
>  #include <libintl.h>
>  #define _(s) gettext(s)
>  
> Index: b/parser/parser.h
> ===================================================================
> --- a/parser/parser.h
> +++ b/parser/parser.h
> @@ -23,9 +23,11 @@
>  #define __AA_PARSER_H
>  
>  
> +#include <endian.h>
>  #include <string.h>
>  #include <netinet/in.h>
>  #include <sys/resource.h>
> +
>  #include "immunix.h"
>  #include "libapparmor_re/apparmor_re.h"
>  #include "libapparmor_re/aare_rules.h"
> @@ -258,15 +260,10 @@ do {								\
>  #define u16 uint16_t
>  #define u32 uint32_t
>  #define u64 uint64_t
> -#if __BYTE_ORDER == __BIG_ENDIAN
> -#  define cpu_to_le16(x) ((u16)(bswap_16 ((u16) x)))
> -#  define cpu_to_le32(x) ((u32)(bswap_32 ((u32) x)))
> -#  define cpu_to_le64(x) ((u64)(bswap_64 ((u64) x)))
> -#else
> -#  define cpu_to_le16(x) ((u16)(x))
> -#  define cpu_to_le32(x) ((u32)(x))
> -#  define cpu_to_le64(x) ((u64)(x))
> -#endif
> +
> +#define cpu_to_le16(x) ((u16)(htole16 ((u16) x)))
> +#define cpu_to_le32(x) ((u32)(htole32 ((u32) x)))
> +#define cpu_to_le64(x) ((u64)(htole64 ((u64) x)))
>  
>  /* The encoding for kernal abi > 5 is
>   * 28-31: reserved
> Index: b/parser/parser_main.c
> ===================================================================
> --- a/parser/parser_main.c
> +++ b/parser/parser_main.c
> @@ -797,11 +797,7 @@ int test_for_dir_mode(const char *basena
>  	return rc;
>  }
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> -#  define le16_to_cpu(x) ((uint16_t)(bswap_16 (*(uint16_t *) x)))
> -#else
> -#  define le16_to_cpu(x) (*(uint16_t *)(x))
> -#endif
> +#define le16_to_cpu(x) ((uint16_t)(htole16 (*(uint16_t *) x)))
>  
this needs to be le16toh




More information about the AppArmor mailing list