| 1 |
/** |
| 2 |
* Tool utility functions |
| 3 |
* |
| 4 |
* Copyright (c) 2014 Red Hat <[email protected]> |
| 5 |
* Author: Paul Moore <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* This library is free software; you can redistribute it and/or modify it |
| 10 |
* under the terms of version 2.1 of the GNU Lesser General Public License as |
| 11 |
* published by the Free Software Foundation. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, but WITHOUT |
| 14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 16 |
* for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with this library; if not, see <http://www.gnu.org/licenses>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef _UTIL_H |
| 23 |
#define _UTIL_H |
| 24 |
|
| 25 |
#include <elf.h> |
| 26 |
#include <inttypes.h> |
| 27 |
#include <linux/audit.h> |
| 28 |
|
| 29 |
/** |
| 30 |
* The ARM architecture tokens |
| 31 |
*/ |
| 32 |
/* AArch64 support for audit was merged in 3.17-rc1 */ |
| 33 |
#ifndef AUDIT_ARCH_AARCH64 |
| 34 |
#ifndef EM_AARCH64 |
| 35 |
#define EM_AARCH64 183 |
| 36 |
#endif /* EM_AARCH64 */ |
| 37 |
#define AUDIT_ARCH_AARCH64 (EM_AARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 38 |
#endif /* AUDIT_ARCH_AARCH64 */ |
| 39 |
|
| 40 |
/** |
| 41 |
* The 64-bit LoongArch architecture tokens |
| 42 |
*/ |
| 43 |
/* 64-bit LoongArch audit support is upstream as of 5.19-rc1 */ |
| 44 |
#ifndef AUDIT_ARCH_LOONGARCH64 |
| 45 |
#ifndef EM_LOONGARCH |
| 46 |
#define EM_LOONGARCH 258 |
| 47 |
#endif /* EM_LOONGARCH */ |
| 48 |
#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 49 |
#endif /* AUDIT_ARCH_LOONGARCH64 */ |
| 50 |
|
| 51 |
/** |
| 52 |
* The MIPS architecture tokens |
| 53 |
*/ |
| 54 |
#ifndef __AUDIT_ARCH_CONVENTION_MIPS64_N32 |
| 55 |
#define __AUDIT_ARCH_CONVENTION_MIPS64_N32 0x20000000 |
| 56 |
#endif |
| 57 |
#ifndef EM_MIPS |
| 58 |
#define EM_MIPS 8 |
| 59 |
#endif |
| 60 |
#ifndef AUDIT_ARCH_MIPS |
| 61 |
#define AUDIT_ARCH_MIPS (EM_MIPS) |
| 62 |
#endif |
| 63 |
#ifndef AUDIT_ARCH_MIPS64 |
| 64 |
#define AUDIT_ARCH_MIPS64 (EM_MIPS|__AUDIT_ARCH_64BIT) |
| 65 |
#endif |
| 66 |
/* MIPS64N32 support was merged in 3.15 */ |
| 67 |
#ifndef AUDIT_ARCH_MIPS64N32 |
| 68 |
#define AUDIT_ARCH_MIPS64N32 (EM_MIPS|__AUDIT_ARCH_64BIT|\ |
| 69 |
__AUDIT_ARCH_CONVENTION_MIPS64_N32) |
| 70 |
#endif |
| 71 |
/* MIPSEL64N32 support was merged in 3.15 */ |
| 72 |
#ifndef AUDIT_ARCH_MIPSEL64N32 |
| 73 |
#define AUDIT_ARCH_MIPSEL64N32 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE|\ |
| 74 |
__AUDIT_ARCH_CONVENTION_MIPS64_N32) |
| 75 |
#endif |
| 76 |
|
| 77 |
#ifndef AUDIT_ARCH_AARCH64 |
| 78 |
/* AArch64 support for audit was merged in 3.17-rc1 */ |
| 79 |
#define AUDIT_ARCH_AARCH64 (EM_AARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 80 |
#endif |
| 81 |
|
| 82 |
#ifndef AUDIT_ARCH_PPC64LE |
| 83 |
#define AUDIT_ARCH_PPC64LE (EM_PPC64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 84 |
#endif |
| 85 |
|
| 86 |
#ifndef AUDIT_ARCH_RISCV64 |
| 87 |
#ifndef EM_RISCV |
| 88 |
#define EM_RISCV 243 |
| 89 |
#endif /* EM_RISCV */ |
| 90 |
#define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 91 |
#endif /* AUDIT_ARCH_RISCV64 */ |
| 92 |
|
| 93 |
extern uint32_t arch; |
| 94 |
|
| 95 |
uint16_t ttoh16(uint32_t arch, uint16_t val); |
| 96 |
uint32_t ttoh32(uint32_t arch, uint32_t val); |
| 97 |
|
| 98 |
uint32_t htot32(uint32_t arch, uint32_t val); |
| 99 |
uint64_t htot64(uint32_t arch, uint64_t val); |
| 100 |
|
| 101 |
#endif |