#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/audit.h>
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#include <endian.h>
#include "util.h"
#if __i386__
#define ARCH_NATIVE AUDIT_ARCH_I386
#elif __x86_64__
#ifdef __ILP32__
#define ARCH_NATIVE AUDIT_ARCH_X86_64
#else
#define ARCH_NATIVE AUDIT_ARCH_X86_64
#endif
#elif __arm__
#define ARCH_NATIVE AUDIT_ARCH_ARM
#elif __aarch64__
#define ARCH_NATIVE AUDIT_ARCH_AARCH64
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32
#if __MIPSEB__
#define ARCH_NATIVE AUDIT_ARCH_MIPS
#elif __MIPSEL__
#define ARCH_NATIVE AUDIT_ARCH_MIPSEL
#endif
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI64
#if __MIPSEB__
#define ARCH_NATIVE AUDIT_ARCH_MIPS64
#elif __MIPSEL__
#define ARCH_NATIVE AUDIT_ARCH_MIPSEL64
#endif
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_NABI32
#if __MIPSEB__
#define ARCH_NATIVE AUDIT_ARCH_MIPS64N32
#elif __MIPSEL__
#define ARCH_NATIVE AUDIT_ARCH_MIPSEL64N32
#endif
#elif __hppa64__
#define ARCH_NATIVE AUDIT_ARCH_PARISC64
#elif __hppa__
#define ARCH_NATIVE AUDIT_ARCH_PARISC
#elif __PPC64__
#ifdef __BIG_ENDIAN__
#define ARCH_NATIVE AUDIT_ARCH_PPC64
#else
#define ARCH_NATIVE AUDIT_ARCH_PPC64LE
#endif
#elif __PPC__
#define ARCH_NATIVE AUDIT_ARCH_PPC
#elif __s390x__
#define ARCH_NATIVE AUDIT_ARCH_S390X
#elif __s390__
#define ARCH_NATIVE AUDIT_ARCH_S390
#elif __riscv && __riscv_xlen == 64
#define ARCH_NATIVE AUDIT_ARCH_RISCV64
#else
#error the simulator code needs to know about your machine type
#endif
uint32_t arch = ARCH_NATIVE;
uint16_t ttoh16(uint32_t arch_token, uint16_t val)
{
if (arch_token & __AUDIT_ARCH_LE)
return le16toh(val);
else
return be16toh(val);
}
uint32_t ttoh32(uint32_t arch_token, uint32_t val)
{
if (arch_token & __AUDIT_ARCH_LE)
return le32toh(val);
else
return be32toh(val);
}
uint32_t htot32(uint32_t arch_token, uint32_t val)
{
if (arch_token & __AUDIT_ARCH_LE)
return htole32(val);
else
return htobe32(val);
}
uint64_t htot64(uint32_t arch_token, uint64_t val)
{
if (arch_token & __AUDIT_ARCH_LE)
return htole64(val);
else
return htobe64(val);
}