xref: /aosp_15_r20/external/crosvm/third_party/minijail/arch.h (revision 4b9c6d91573e8b3a96609339b46361b5476dd0f9)
1 /* arch.h
2  * Copyright 2014 The ChromiumOS Authors
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  *
6  * MINIJAIL_ARCH_NR #define's.
7  */
8 
9 #ifndef ARCH_H
10 #define ARCH_H
11 
12 #include <linux/audit.h>
13 #include <stdint.h>
14 
15 /* clang-format off */
16 #if defined(__i386__)
17 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_I386
18 #  define MINIJAIL_ARCH_NAME "x86"
19 #elif defined(__x86_64__)
20 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_X86_64
21 #  define MINIJAIL_ARCH_NAME "x86_64"
22 #elif defined(__arm__)
23 /*
24  * <linux/audit.h> includes <linux/elf-em.h>, which does not define EM_ARM.
25  * <linux/elf.h> only includes <asm/elf.h> if we're in the kernel.
26  */
27 #  ifndef EM_ARM
28 #    define EM_ARM 40
29 #  endif
30 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_ARM
31 #  define MINIJAIL_ARCH_NAME "arm"
32 #elif defined(__aarch64__)
33 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_AARCH64
34 #  define MINIJAIL_ARCH_NAME "arm64"
35 #elif defined(__hppa__)
36 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_PARISC
37 #  define MINIJAIL_ARCH_NAME "parisc"
38 #elif defined(__ia64__)
39 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_IA64
40 #  define MINIJAIL_ARCH_NAME "ia64"
41 #elif defined(__mips__)
42 #  if defined(__mips64)
43 #    if defined(__MIPSEB__)
44 #      define MINIJAIL_ARCH_NR AUDIT_ARCH_MIPS64
45 #      define MINIJAIL_ARCH_NAME "mips64"
46 #    else
47 #      define MINIJAIL_ARCH_NR AUDIT_ARCH_MIPSEL64
48 #      define MINIJAIL_ARCH_NAME "mipsel64"
49 #    endif
50 #  else
51 #    if defined(__MIPSEB__)
52 #      define MINIJAIL_ARCH_NR AUDIT_ARCH_MIPS
53 #      define MINIJAIL_ARCH_NAME "mips"
54 #    else
55 #      define MINIJAIL_ARCH_NR AUDIT_ARCH_MIPSEL
56 #      define MINIJAIL_ARCH_NAME "mipsel"
57 #    endif
58 #  endif
59 #elif defined(__powerpc64__)
60 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_PPC64
61 #  define MINIJAIL_ARCH_NAME "ppc64"
62 #elif defined(__powerpc__)
63 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_PPC
64 #  define MINIJAIL_ARCH_NAME "ppc"
65 #elif defined(__riscv)
66 #  if defined(__riscv_xlen)
67 #    if (__riscv_xlen == 64)
68 #      define MINIJAIL_ARCH_NR AUDIT_ARCH_RISCV64
69 #      define MINIJAIL_ARCH_NAME "riscv64"
70 #    else
71 #      error "Only 64bit riscv is supported"
72 #    endif
73 #  else
74 #    error "AUDIT_ARCH value unavailable"
75 #  endif
76 #elif defined(__s390x__)
77 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_S390X
78 #  define MINIJAIL_ARCH_NAME "s390x"
79 #elif defined(__s390__)
80 #  define MINIJAIL_ARCH_NR AUDIT_ARCH_S390
81 #  define MINIJAIL_ARCH_NAME "s390"
82 #elif defined(__sparc__)
83 #  if defined(__arch64__)
84 #    define AUDIT_ARCH_SPARC64
85 #    define MINIJAIL_ARCH_NAME "sparc64"
86 #  else
87 #    define AUDIT_ARCH_SPARC
88 #    define MINIJAIL_ARCH_NAME "sparc"
89 #  endif
90 #else
91 #  error "AUDIT_ARCH value unavailable"
92 #endif
93 /* clang-format on */
94 
95 #define MINIJAIL_ARCH_BITS sizeof(uintptr_t) * 8
96 
97 #endif /* ARCH_H */
98