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