Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 1 | From e99b00a78acaf80236cba8b3fabaebdb3ef1987b Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Tue, 8 Jun 2021 19:45:34 -0700 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 4 | Subject: [PATCH 1/4] arch: Add riscv32 architecture support |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 5 | |
| 6 | Support for rv32 was upstreamed into 5.4+ kernel |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 7 | Upstream-Status: Submitted [https://github.com/seccomp/libseccomp/pull/327] |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 8 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 10 | --- |
| 11 | CREDITS | 1 + |
| 12 | README.md | 1 + |
| 13 | doc/man/man1/scmp_sys_resolver.1 | 2 +- |
| 14 | doc/man/man3/seccomp_arch_add.3 | 1 + |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 15 | include/seccomp-syscalls.h | 32 +++++++++++++++++++ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 16 | include/seccomp.h.in | 9 ++++++ |
| 17 | src/Makefile.am | 1 + |
| 18 | src/arch-riscv32.c | 31 ++++++++++++++++++ |
| 19 | src/arch-riscv32.h | 22 +++++++++++++ |
| 20 | src/arch-syscall-dump.c | 4 +++ |
| 21 | src/arch-syscall-validate | 51 +++++++++++++++++++++++++++++- |
| 22 | src/arch.c | 11 ++++++- |
| 23 | src/gen_pfc.c | 2 ++ |
| 24 | src/python/libseccomp.pxd | 1 + |
| 25 | src/python/seccomp.pyx | 2 ++ |
| 26 | src/syscalls.c | 1 + |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 27 | src/syscalls.h | 2 ++ |
| 28 | src/system.c | 1 + |
| 29 | tests/15-basic-resolver.c | 1 + |
| 30 | tests/16-sim-arch_basic.c | 6 ++++ |
| 31 | tests/16-sim-arch_basic.py | 1 + |
| 32 | tests/23-sim-arch_all_le_basic.c | 3 ++ |
| 33 | tests/23-sim-arch_all_le_basic.py | 1 + |
| 34 | tests/56-basic-iterate_syscalls.c | 1 + |
| 35 | tests/56-basic-iterate_syscalls.py | 1 + |
| 36 | tests/regression | 5 +-- |
| 37 | tools/scmp_arch_detect.c | 3 ++ |
| 38 | tools/scmp_bpf_disasm.c | 2 ++ |
| 39 | tools/scmp_bpf_sim.c | 2 ++ |
| 40 | tools/util.c | 6 +++- |
| 41 | tools/util.h | 7 ++++ |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 42 | 31 files changed, 208 insertions(+), 6 deletions(-) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 43 | create mode 100644 src/arch-riscv32.c |
| 44 | create mode 100644 src/arch-riscv32.h |
| 45 | |
| 46 | diff --git a/CREDITS b/CREDITS |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 47 | index b685712..c1ffdb3 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 48 | --- a/CREDITS |
| 49 | +++ b/CREDITS |
| 50 | @@ -33,6 +33,7 @@ John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> |
| 51 | Jonah Petri <jonah@petri.us> |
| 52 | Justin Cormack <justin.cormack@docker.com> |
| 53 | Kees Cook <keescook@chromium.org> |
| 54 | +Khem Raj <raj.khem@gmail.com> |
| 55 | Kyle R. Conway <kyle.r.conway@gmail.com> |
| 56 | Kenta Tada <Kenta.Tada@sony.com> |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 57 | Kir Kolyshkin <kolyshkin@gmail.com> |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 58 | diff --git a/README.md b/README.md |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 59 | index 579f226..8199a71 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 60 | --- a/README.md |
| 61 | +++ b/README.md |
| 62 | @@ -54,6 +54,7 @@ The libseccomp library currently supports the architectures listed below: |
| 63 | * 32-bit s390 (s390) |
| 64 | * 64-bit s390x (s390x) |
| 65 | * 64-bit RISC-V (riscv64) |
| 66 | +* 32-bit RISC-V (riscv32) |
| 67 | * 32-bit SuperH big endian (sheb) |
| 68 | * 32-bit SuperH (sh) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 69 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 70 | diff --git a/doc/man/man1/scmp_sys_resolver.1 b/doc/man/man1/scmp_sys_resolver.1 |
| 71 | index 267187b..fc68d18 100644 |
| 72 | --- a/doc/man/man1/scmp_sys_resolver.1 |
| 73 | +++ b/doc/man/man1/scmp_sys_resolver.1 |
| 74 | @@ -36,7 +36,7 @@ The architecture to use for resolving the system call. Valid |
| 75 | .I ARCH |
| 76 | values are "x86", "x86_64", "x32", "arm", "aarch64", "mips", "mipsel", "mips64", |
| 77 | "mipsel64", "mips64n32", "mipsel64n32", "parisc", "parisc64", "ppc", "ppc64", |
| 78 | -"ppc64le", "s390", "s390x", "sheb" and "sh". |
| 79 | +"ppc64le", "riscv32", "s390", "s390x", "sheb" and "sh". |
| 80 | .TP |
| 81 | .B \-t |
| 82 | If necessary, translate the system call name to the proper system call number, |
| 83 | diff --git a/doc/man/man3/seccomp_arch_add.3 b/doc/man/man3/seccomp_arch_add.3 |
| 84 | index 7baa21e..8966b3a 100644 |
| 85 | --- a/doc/man/man3/seccomp_arch_add.3 |
| 86 | +++ b/doc/man/man3/seccomp_arch_add.3 |
| 87 | @@ -30,6 +30,7 @@ seccomp_arch_add, seccomp_arch_remove, seccomp_arch_exist, seccomp_arch_native \ |
| 88 | .B #define SCMP_ARCH_S390X |
| 89 | .B #define SCMP_ARCH_PARISC |
| 90 | .B #define SCMP_ARCH_PARISC64 |
| 91 | +.B #define SCMP_ARCH_RISCV32 |
| 92 | .B #define SCMP_ARCH_RISCV64 |
| 93 | .sp |
| 94 | .BI "uint32_t seccomp_arch_resolve_name(const char *" arch_name ");" |
| 95 | diff --git a/include/seccomp-syscalls.h b/include/seccomp-syscalls.h |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 96 | index 476f953..4ff814c 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 97 | --- a/include/seccomp-syscalls.h |
| 98 | +++ b/include/seccomp-syscalls.h |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 99 | @@ -276,6 +276,14 @@ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 100 | #define __PNR_renameat -10242 |
| 101 | #define __PNR_riscv_flush_icache -10243 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 102 | #define __PNR_memfd_secret -10244 |
| 103 | +#define __PNR_fstat -10245 |
| 104 | +#define __PNR_futex -10246 |
| 105 | +#define __PNR_nanosleep -10247 |
| 106 | +#define __PNR_lseek -10248 |
| 107 | +#define __PNR_clock_gettime -10249 |
| 108 | +#define __PNR_clock_nanosleep -10250 |
| 109 | +#define __PNR_gettimeofday -10251 |
| 110 | +#define __PNR_fcntl -10252 |
| 111 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 112 | /* |
| 113 | * libseccomp syscall definitions |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 114 | @@ -443,7 +451,11 @@ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 115 | #define __SNR_clock_getres_time64 __PNR_clock_getres_time64 |
| 116 | #endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 117 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 118 | +#ifdef __NR_clock_gettime |
| 119 | #define __SNR_clock_gettime __NR_clock_gettime |
| 120 | +#else |
| 121 | +#define __SNR_clock_gettime __PNR_clock_gettime |
| 122 | +#endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 123 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 124 | #ifdef __NR_clock_gettime64 |
| 125 | #define __SNR_clock_gettime64 __NR_clock_gettime64 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 126 | @@ -451,7 +463,11 @@ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 127 | #define __SNR_clock_gettime64 __PNR_clock_gettime64 |
| 128 | #endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 129 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 130 | +#ifdef __NR_clock_nanosleep |
| 131 | #define __SNR_clock_nanosleep __NR_clock_nanosleep |
| 132 | +#else |
| 133 | +#define __SNR_clock_nanosleep __PNR_clock_nanosleep |
| 134 | +#endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 135 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 136 | #ifdef __NR_clock_nanosleep_time64 |
| 137 | #define __SNR_clock_nanosleep_time64 __NR_clock_nanosleep_time64 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 138 | @@ -713,7 +729,11 @@ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 139 | #define __SNR_ftruncate64 __PNR_ftruncate64 |
| 140 | #endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 141 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 142 | +#ifdef __NR_futex |
| 143 | #define __SNR_futex __NR_futex |
| 144 | +#else |
| 145 | +#define __SNR_futex __PNR_futex |
| 146 | +#endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 147 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 148 | #ifdef __NR_futex_time64 |
| 149 | #define __SNR_futex_time64 __NR_futex_time64 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 150 | @@ -899,7 +919,11 @@ |
| 151 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 152 | #define __SNR_gettid __NR_gettid |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 153 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 154 | +#ifdef __NR_gettimeofday |
| 155 | #define __SNR_gettimeofday __NR_gettimeofday |
| 156 | +#else |
| 157 | +#define __SNR_gettimeofday __PNR_gettimeofday |
| 158 | +#endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 159 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 160 | #ifdef __NR_getuid |
| 161 | #define __SNR_getuid __NR_getuid |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 162 | @@ -1049,7 +1073,11 @@ |
| 163 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 164 | #define __SNR_lremovexattr __NR_lremovexattr |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 165 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 166 | +#ifdef __NR_lseek |
| 167 | #define __SNR_lseek __NR_lseek |
| 168 | +#else |
| 169 | +#define __SNR_lseek __PNR_lseek |
| 170 | +#endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 171 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 172 | #define __SNR_lsetxattr __NR_lsetxattr |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 173 | |
| 174 | @@ -1227,7 +1255,11 @@ |
| 175 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 176 | #define __SNR_name_to_handle_at __NR_name_to_handle_at |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 177 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 178 | +#ifdef __NR_nanosleep |
| 179 | #define __SNR_nanosleep __NR_nanosleep |
| 180 | +#else |
| 181 | +#define __SNR_nanosleep __PNR_nanosleep |
| 182 | +#endif |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 183 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 184 | #ifdef __NR_newfstatat |
| 185 | #define __SNR_newfstatat __NR_newfstatat |
| 186 | diff --git a/include/seccomp.h.in b/include/seccomp.h.in |
| 187 | index 333a89c..2e911db 100644 |
| 188 | --- a/include/seccomp.h.in |
| 189 | +++ b/include/seccomp.h.in |
| 190 | @@ -214,7 +214,16 @@ struct scmp_arg_cmp { |
| 191 | #endif /* EM_RISCV */ |
| 192 | #define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 193 | #endif /* AUDIT_ARCH_RISCV64 */ |
| 194 | + |
| 195 | +#ifndef AUDIT_ARCH_RISCV32 |
| 196 | +#ifndef EM_RISCV |
| 197 | +#define EM_RISCV 243 |
| 198 | +#endif /* EM_RISCV */ |
| 199 | +#define AUDIT_ARCH_RISCV32 (EM_RISCV|__AUDIT_ARCH_LE) |
| 200 | +#endif /* AUDIT_ARCH_RISCV32 */ |
| 201 | + |
| 202 | #define SCMP_ARCH_RISCV64 AUDIT_ARCH_RISCV64 |
| 203 | +#define SCMP_ARCH_RISCV32 AUDIT_ARCH_RISCV32 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 204 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 205 | /** |
| 206 | * The SuperH architecture tokens |
| 207 | diff --git a/src/Makefile.am b/src/Makefile.am |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 208 | index 04e7ba5..a30bbc0 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 209 | --- a/src/Makefile.am |
| 210 | +++ b/src/Makefile.am |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 211 | @@ -40,6 +40,7 @@ SOURCES_ALL = \ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 212 | arch-ppc.h arch-ppc.c \ |
| 213 | arch-ppc64.h arch-ppc64.c \ |
| 214 | arch-riscv64.h arch-riscv64.c \ |
| 215 | + arch-riscv32.h arch-riscv32.c \ |
| 216 | arch-s390.h arch-s390.c \ |
| 217 | arch-s390x.h arch-s390x.c \ |
| 218 | arch-sh.h arch-sh.c \ |
| 219 | diff --git a/src/arch-riscv32.c b/src/arch-riscv32.c |
| 220 | new file mode 100644 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 221 | index 0000000..10418f4 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 222 | --- /dev/null |
| 223 | +++ b/src/arch-riscv32.c |
| 224 | @@ -0,0 +1,31 @@ |
| 225 | +/* |
| 226 | + * This library is free software; you can redistribute it and/or modify it |
| 227 | + * under the terms of version 2.1 of the GNU Lesser General Public License as |
| 228 | + * published by the Free Software Foundation. |
| 229 | + * |
| 230 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
| 231 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 232 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 233 | + * for more details. |
| 234 | + * |
| 235 | + * You should have received a copy of the GNU Lesser General Public License |
| 236 | + * along with this library; if not, see <http://www.gnu.org/licenses>. |
| 237 | + */ |
| 238 | + |
| 239 | +#include <stdlib.h> |
| 240 | +#include <errno.h> |
| 241 | +#include <linux/audit.h> |
| 242 | + |
| 243 | +#include "arch.h" |
| 244 | +#include "arch-riscv32.h" |
| 245 | + |
| 246 | +const struct arch_def arch_def_riscv32 = { |
| 247 | + .token = SCMP_ARCH_RISCV32, |
| 248 | + .token_bpf = AUDIT_ARCH_RISCV32, |
| 249 | + .size = ARCH_SIZE_32, |
| 250 | + .endian = ARCH_ENDIAN_LITTLE, |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 251 | + .syscall_resolve_name_raw = riscv32_syscall_resolve_name, |
| 252 | + .syscall_resolve_num_raw = riscv32_syscall_resolve_num, |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 253 | + .syscall_rewrite = NULL, |
| 254 | + .rule_add = NULL, |
| 255 | +}; |
| 256 | diff --git a/src/arch-riscv32.h b/src/arch-riscv32.h |
| 257 | new file mode 100644 |
| 258 | index 0000000..082a77d |
| 259 | --- /dev/null |
| 260 | +++ b/src/arch-riscv32.h |
| 261 | @@ -0,0 +1,22 @@ |
| 262 | +/* |
| 263 | + * This library is free software; you can redistribute it and/or modify it |
| 264 | + * under the terms of version 2.1 of the GNU Lesser General Public License as |
| 265 | + * published by the Free Software Foundation. |
| 266 | + * |
| 267 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
| 268 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 269 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 270 | + * for more details. |
| 271 | + * |
| 272 | + * You should have received a copy of the GNU Lesser General Public License |
| 273 | + * along with this library; if not, see <http://www.gnu.org/licenses>. |
| 274 | + */ |
| 275 | + |
| 276 | +#ifndef _ARCH_RISCV32_H |
| 277 | +#define _ARCH_RISCV32_H |
| 278 | + |
| 279 | +#include "arch.h" |
| 280 | + |
| 281 | +ARCH_DECL(riscv32) |
| 282 | + |
| 283 | +#endif |
| 284 | diff --git a/src/arch-syscall-dump.c b/src/arch-syscall-dump.c |
| 285 | index 843483b..c6ab57d 100644 |
| 286 | --- a/src/arch-syscall-dump.c |
| 287 | +++ b/src/arch-syscall-dump.c |
| 288 | @@ -43,6 +43,7 @@ |
| 289 | #include "arch-ppc.h" |
| 290 | #include "arch-ppc64.h" |
| 291 | #include "arch-riscv64.h" |
| 292 | +#include "arch-riscv32.h" |
| 293 | #include "arch-s390.h" |
| 294 | #include "arch-s390x.h" |
| 295 | #include "arch-sh.h" |
| 296 | @@ -135,6 +136,9 @@ int main(int argc, char *argv[]) |
| 297 | case SCMP_ARCH_RISCV64: |
| 298 | sys = riscv64_syscall_iterate(iter); |
| 299 | break; |
| 300 | + case SCMP_ARCH_RISCV32: |
| 301 | + sys = riscv32_syscall_iterate(iter); |
| 302 | + break; |
| 303 | case SCMP_ARCH_S390: |
| 304 | sys = s390_syscall_iterate(iter); |
| 305 | break; |
| 306 | diff --git a/src/arch-syscall-validate b/src/arch-syscall-validate |
| 307 | index 68bebef..85c7f3d 100755 |
| 308 | --- a/src/arch-syscall-validate |
| 309 | +++ b/src/arch-syscall-validate |
| 310 | @@ -519,6 +519,49 @@ function dump_lib_riscv64() { |
| 311 | dump_lib_arch riscv64 | mangle_lib_syscall riscv64 |
| 312 | } |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 313 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 314 | +# |
| 315 | +# Dump the riscv32 system syscall table |
| 316 | +# |
| 317 | +# Arguments: |
| 318 | +# 1 path to the kernel source |
| 319 | +# |
| 320 | +# Dump the architecture's syscall table to stdout. |
| 321 | +# |
| 322 | +function dump_sys_riscv32() { |
| 323 | + local sed_filter="" |
| 324 | + |
| 325 | + sed_filter+='s/__NR3264_fadvise64/223/;' |
| 326 | + sed_filter+='s/__NR3264_fcntl/25/;' |
| 327 | + sed_filter+='s/__NR3264_fstatat/79/;' |
| 328 | + sed_filter+='s/__NR3264_fstatfs/44/;' |
| 329 | + sed_filter+='s/__NR3264_ftruncate/46/;' |
| 330 | + sed_filter+='s/__NR3264_lseek/62/;' |
| 331 | + sed_filter+='s/__NR3264_mmap/222/;' |
| 332 | + sed_filter+='s/__NR3264_sendfile/71/;' |
| 333 | + sed_filter+='s/__NR3264_statfs/43/;' |
| 334 | + sed_filter+='s/__NR3264_truncate/45/;' |
| 335 | + sed_filter+='s/__NR3264_fstat/80/;' |
| 336 | + |
| 337 | + gcc -E -dM -I$1/include/uapi \ |
| 338 | + -D__BITS_PER_LONG=32 \ |
| 339 | + $1/arch/riscv/include/uapi/asm/unistd.h | \ |
| 340 | + grep "^#define __NR_" | \ |
| 341 | + sed '/__NR_syscalls/d' | \ |
| 342 | + sed 's/(__NR_arch_specific_syscall + 15)/259/' | \ |
| 343 | + sed '/__NR_arch_specific_syscall/d' | \ |
| 344 | + sed 's/#define[ \t]\+__NR_\([^ \t]\+\)[ \t]\+\(.*\)/\1,\2/' | \ |
| 345 | + sed $sed_filter | sort |
| 346 | +} |
| 347 | + |
| 348 | +# |
| 349 | +# Dump the riscv32 library syscall table |
| 350 | +# |
| 351 | +# Dump the library's syscall table to stdout. |
| 352 | +# |
| 353 | +function dump_lib_riscv32() { |
| 354 | + dump_lib_arch riscv32 | mangle_lib_syscall riscv32 |
| 355 | +} |
| 356 | + |
| 357 | # |
| 358 | # Dump the s390 system syscall table |
| 359 | # |
| 360 | @@ -639,6 +682,9 @@ function dump_sys() { |
| 361 | ppc64) |
| 362 | dump_sys_ppc64 "$2" |
| 363 | ;; |
| 364 | + riscv32) |
| 365 | + dump_sys_riscv32 "$2" |
| 366 | + ;; |
| 367 | riscv64) |
| 368 | dump_sys_riscv64 "$2" |
| 369 | ;; |
| 370 | @@ -706,6 +752,9 @@ function dump_lib() { |
| 371 | ppc64) |
| 372 | dump_lib_ppc64 |
| 373 | ;; |
| 374 | + riscv32) |
| 375 | + dump_lib_riscv32 |
| 376 | + ;; |
| 377 | riscv64) |
| 378 | dump_lib_riscv64 |
| 379 | ;; |
| 380 | @@ -751,7 +800,7 @@ function gen_csv() { |
| 381 | abi_list+=" mips mips64 mips64n32" |
| 382 | abi_list+=" parisc parisc64" |
| 383 | abi_list+=" ppc ppc64" |
| 384 | - abi_list+=" riscv64" |
| 385 | + abi_list+=" riscv32 riscv64" |
| 386 | abi_list+=" s390 s390x" |
| 387 | abi_list+=" sh" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 388 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 389 | diff --git a/src/arch.c b/src/arch.c |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 390 | index 921e455..07935a9 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 391 | --- a/src/arch.c |
| 392 | +++ b/src/arch.c |
| 393 | @@ -43,6 +43,7 @@ |
| 394 | #include "arch-ppc.h" |
| 395 | #include "arch-ppc64.h" |
| 396 | #include "arch-riscv64.h" |
| 397 | +#include "arch-riscv32.h" |
| 398 | #include "arch-s390.h" |
| 399 | #include "arch-s390x.h" |
| 400 | #include "arch-sh.h" |
| 401 | @@ -97,8 +98,12 @@ const struct arch_def *arch_def_native = &arch_def_ppc; |
| 402 | const struct arch_def *arch_def_native = &arch_def_s390x; |
| 403 | #elif __s390__ |
| 404 | const struct arch_def *arch_def_native = &arch_def_s390; |
| 405 | -#elif __riscv && __riscv_xlen == 64 |
| 406 | +#elif __riscv |
| 407 | +#if __riscv_xlen == 64 |
| 408 | const struct arch_def *arch_def_native = &arch_def_riscv64; |
| 409 | +#elif __riscv_xlen == 32 |
| 410 | +const struct arch_def *arch_def_native = &arch_def_riscv32; |
| 411 | +#endif |
| 412 | #elif __sh__ |
| 413 | #ifdef __BIG_ENDIAN__ |
| 414 | const struct arch_def *arch_def_native = &arch_def_sheb; |
| 415 | @@ -167,6 +172,8 @@ const struct arch_def *arch_def_lookup(uint32_t token) |
| 416 | return &arch_def_s390; |
| 417 | case SCMP_ARCH_S390X: |
| 418 | return &arch_def_s390x; |
| 419 | + case SCMP_ARCH_RISCV32: |
| 420 | + return &arch_def_riscv32; |
| 421 | case SCMP_ARCH_RISCV64: |
| 422 | return &arch_def_riscv64; |
| 423 | case SCMP_ARCH_SHEB: |
| 424 | @@ -223,6 +230,8 @@ const struct arch_def *arch_def_lookup_name(const char *arch_name) |
| 425 | return &arch_def_s390; |
| 426 | else if (strcmp(arch_name, "s390x") == 0) |
| 427 | return &arch_def_s390x; |
| 428 | + else if (strcmp(arch_name, "riscv32") == 0) |
| 429 | + return &arch_def_riscv32; |
| 430 | else if (strcmp(arch_name, "riscv64") == 0) |
| 431 | return &arch_def_riscv64; |
| 432 | else if (strcmp(arch_name, "sheb") == 0) |
| 433 | diff --git a/src/gen_pfc.c b/src/gen_pfc.c |
| 434 | index c7fb536..d45e181 100644 |
| 435 | --- a/src/gen_pfc.c |
| 436 | +++ b/src/gen_pfc.c |
| 437 | @@ -87,6 +87,8 @@ static const char *_pfc_arch(const struct arch_def *arch) |
| 438 | return "s390x"; |
| 439 | case SCMP_ARCH_S390: |
| 440 | return "s390"; |
| 441 | + case SCMP_ARCH_RISCV32: |
| 442 | + return "riscv32"; |
| 443 | case SCMP_ARCH_RISCV64: |
| 444 | return "riscv64"; |
| 445 | case SCMP_ARCH_SHEB: |
| 446 | diff --git a/src/python/libseccomp.pxd b/src/python/libseccomp.pxd |
| 447 | index 0629bf1..000d503 100644 |
| 448 | --- a/src/python/libseccomp.pxd |
| 449 | +++ b/src/python/libseccomp.pxd |
| 450 | @@ -51,6 +51,7 @@ cdef extern from "seccomp.h": |
| 451 | SCMP_ARCH_PPC64LE |
| 452 | SCMP_ARCH_S390 |
| 453 | SCMP_ARCH_S390X |
| 454 | + SCMP_ARCH_RISCV32 |
| 455 | SCMP_ARCH_RISCV64 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 456 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 457 | cdef enum scmp_filter_attr: |
| 458 | diff --git a/src/python/seccomp.pyx b/src/python/seccomp.pyx |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 459 | index 2eeabc1..2895d78 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 460 | --- a/src/python/seccomp.pyx |
| 461 | +++ b/src/python/seccomp.pyx |
| 462 | @@ -214,6 +214,7 @@ cdef class Arch: |
| 463 | PARISC64 - 64-bit PA-RISC |
| 464 | PPC64 - 64-bit PowerPC |
| 465 | PPC - 32-bit PowerPC |
| 466 | + RISCV32 - 32-bit RISC-V |
| 467 | RISCV64 - 64-bit RISC-V |
| 468 | """ |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 469 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 470 | @@ -238,6 +239,7 @@ cdef class Arch: |
| 471 | PPC64LE = libseccomp.SCMP_ARCH_PPC64LE |
| 472 | S390 = libseccomp.SCMP_ARCH_S390 |
| 473 | S390X = libseccomp.SCMP_ARCH_S390X |
| 474 | + RISCV32 = libseccomp.SCMP_ARCH_RISCV32 |
| 475 | RISCV64 = libseccomp.SCMP_ARCH_RISCV64 |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 476 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 477 | def __cinit__(self, arch=libseccomp.SCMP_ARCH_NATIVE): |
| 478 | diff --git a/src/syscalls.c b/src/syscalls.c |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 479 | index faddff0..15952ce 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 480 | --- a/src/syscalls.c |
| 481 | +++ b/src/syscalls.c |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 482 | @@ -59,6 +59,7 @@ ARCH_DEF(sh) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 483 | ARCH_DEF(x32) |
| 484 | ARCH_DEF(x86) |
| 485 | ARCH_DEF(riscv64) |
| 486 | +ARCH_DEF(riscv32) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 487 | |
| 488 | /** |
| 489 | * Resolve a syscall name to a number |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 490 | diff --git a/src/syscalls.h b/src/syscalls.h |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 491 | index 58a788c..c6b5db5 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 492 | --- a/src/syscalls.h |
| 493 | +++ b/src/syscalls.h |
| 494 | @@ -28,6 +28,7 @@ |
| 495 | #include "arch-x86.h" |
| 496 | #include "arch-x86.h" |
| 497 | #include "arch-riscv64.h" |
| 498 | +#include "arch-riscv32.h" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 499 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 500 | /* NOTE: changes to the arch_syscall_table layout may require changes to the |
| 501 | * generate_syscalls_perf.sh and arch-syscall-validate scripts */ |
| 502 | @@ -49,6 +50,7 @@ struct arch_syscall_table { |
| 503 | int parisc64; |
| 504 | int ppc; |
| 505 | int ppc64; |
| 506 | + int riscv32; |
| 507 | int riscv64; |
| 508 | int s390; |
| 509 | int s390x; |
| 510 | diff --git a/src/system.c b/src/system.c |
| 511 | index ae445bf..063e6be 100644 |
| 512 | --- a/src/system.c |
| 513 | +++ b/src/system.c |
| 514 | @@ -130,6 +130,7 @@ int sys_chk_seccomp_syscall(void) |
| 515 | case SCMP_ARCH_PPC64LE: |
| 516 | case SCMP_ARCH_S390: |
| 517 | case SCMP_ARCH_S390X: |
| 518 | + case SCMP_ARCH_RISCV32: |
| 519 | case SCMP_ARCH_RISCV64: |
| 520 | break; |
| 521 | default: |
| 522 | diff --git a/tests/15-basic-resolver.c b/tests/15-basic-resolver.c |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 523 | index c759dd1..fd94dbf 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 524 | --- a/tests/15-basic-resolver.c |
| 525 | +++ b/tests/15-basic-resolver.c |
| 526 | @@ -45,6 +45,7 @@ unsigned int arch_list[] = { |
| 527 | SCMP_ARCH_S390X, |
| 528 | SCMP_ARCH_PARISC, |
| 529 | SCMP_ARCH_PARISC64, |
| 530 | + SCMP_ARCH_RISCV32, |
| 531 | SCMP_ARCH_RISCV64, |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 532 | SCMP_ARCH_SH, |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 533 | -1 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 534 | diff --git a/tests/16-sim-arch_basic.c b/tests/16-sim-arch_basic.c |
| 535 | index 4fcbb5c..662e081 100644 |
| 536 | --- a/tests/16-sim-arch_basic.c |
| 537 | +++ b/tests/16-sim-arch_basic.c |
| 538 | @@ -90,6 +90,9 @@ int main(int argc, char *argv[]) |
| 539 | if (rc != 0) |
| 540 | goto out; |
| 541 | rc = seccomp_arch_add(ctx, SCMP_ARCH_PPC64LE); |
| 542 | + if (rc != 0) |
| 543 | + goto out; |
| 544 | + rc = seccomp_arch_add(ctx, SCMP_ARCH_RISCV32); |
| 545 | if (rc != 0) |
| 546 | goto out; |
| 547 | rc = seccomp_arch_add(ctx, SCMP_ARCH_RISCV64); |
| 548 | @@ -160,6 +163,9 @@ int main(int argc, char *argv[]) |
| 549 | if (rc != 0) |
| 550 | goto out; |
| 551 | rc = seccomp_arch_remove(ctx, SCMP_ARCH_PPC64LE); |
| 552 | + if (rc != 0) |
| 553 | + goto out; |
| 554 | + rc = seccomp_arch_remove(ctx, SCMP_ARCH_RISCV32); |
| 555 | if (rc != 0) |
| 556 | goto out; |
| 557 | rc = seccomp_arch_remove(ctx, SCMP_ARCH_RISCV64); |
| 558 | diff --git a/tests/16-sim-arch_basic.py b/tests/16-sim-arch_basic.py |
| 559 | index f22c985..d5e93a2 100755 |
| 560 | --- a/tests/16-sim-arch_basic.py |
| 561 | +++ b/tests/16-sim-arch_basic.py |
| 562 | @@ -44,6 +44,7 @@ def test(args): |
| 563 | f.add_arch(Arch("mipsel64")) |
| 564 | f.add_arch(Arch("mipsel64n32")) |
| 565 | f.add_arch(Arch("ppc64le")) |
| 566 | + f.add_arch(Arch("riscv32")) |
| 567 | f.add_arch(Arch("riscv64")) |
| 568 | f.add_arch(Arch("sh")) |
| 569 | f.add_rule(ALLOW, "read", Arg(0, EQ, sys.stdin.fileno())) |
| 570 | diff --git a/tests/23-sim-arch_all_le_basic.c b/tests/23-sim-arch_all_le_basic.c |
| 571 | index 08f030c..ec73224 100644 |
| 572 | --- a/tests/23-sim-arch_all_le_basic.c |
| 573 | +++ b/tests/23-sim-arch_all_le_basic.c |
| 574 | @@ -75,6 +75,9 @@ int main(int argc, char *argv[]) |
| 575 | if (rc != 0) |
| 576 | goto out; |
| 577 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("sh")); |
| 578 | + if (rc != 0) |
| 579 | + goto out; |
| 580 | + rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("riscv32")); |
| 581 | if (rc != 0) |
| 582 | goto out; |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 583 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 584 | diff --git a/tests/23-sim-arch_all_le_basic.py b/tests/23-sim-arch_all_le_basic.py |
| 585 | index 12bb243..1eebc20 100755 |
| 586 | --- a/tests/23-sim-arch_all_le_basic.py |
| 587 | +++ b/tests/23-sim-arch_all_le_basic.py |
| 588 | @@ -40,6 +40,7 @@ def test(args): |
| 589 | f.add_arch(Arch("mipsel64")) |
| 590 | f.add_arch(Arch("mipsel64n32")) |
| 591 | f.add_arch(Arch("ppc64le")) |
| 592 | + f.add_arch(Arch("riscv32")) |
| 593 | f.add_arch(Arch("riscv64")) |
| 594 | f.add_arch(Arch("sh")) |
| 595 | f.add_rule(ALLOW, "read", Arg(0, EQ, sys.stdin.fileno())) |
| 596 | diff --git a/tests/56-basic-iterate_syscalls.c b/tests/56-basic-iterate_syscalls.c |
| 597 | index 5e7ab67..c11ca8c 100644 |
| 598 | --- a/tests/56-basic-iterate_syscalls.c |
| 599 | +++ b/tests/56-basic-iterate_syscalls.c |
| 600 | @@ -46,6 +46,7 @@ unsigned int arch_list[] = { |
| 601 | SCMP_ARCH_S390X, |
| 602 | SCMP_ARCH_PARISC, |
| 603 | SCMP_ARCH_PARISC64, |
| 604 | + SCMP_ARCH_RISCV32, |
| 605 | SCMP_ARCH_RISCV64, |
| 606 | -1 |
| 607 | }; |
| 608 | diff --git a/tests/56-basic-iterate_syscalls.py b/tests/56-basic-iterate_syscalls.py |
| 609 | index 77a5b89..2e860bf 100755 |
| 610 | --- a/tests/56-basic-iterate_syscalls.py |
| 611 | +++ b/tests/56-basic-iterate_syscalls.py |
| 612 | @@ -37,6 +37,7 @@ arch_list = ["x86", |
| 613 | "mipsel64", |
| 614 | "mipsel64n32", |
| 615 | "ppc64le", |
| 616 | + "riscv32", |
| 617 | "riscv64"] |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 618 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 619 | def test_arch(arch, init): |
| 620 | diff --git a/tests/regression b/tests/regression |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 621 | index d28b848..057ff67 100755 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 622 | --- a/tests/regression |
| 623 | +++ b/tests/regression |
| 624 | @@ -26,7 +26,7 @@ GLBL_ARCH_LE_SUPPORT=" \ |
| 625 | arm aarch64 \ |
| 626 | mipsel mipsel64 mipsel64n32 \ |
| 627 | ppc64le \ |
| 628 | - riscv64 \ |
| 629 | + riscv32 riscv64 \ |
| 630 | sh" |
| 631 | GLBL_ARCH_BE_SUPPORT=" \ |
| 632 | mips mips64 mips64n32 \ |
| 633 | @@ -41,6 +41,7 @@ GLBL_ARCH_32B_SUPPORT=" \ |
| 634 | mips mipsel mips64n32 mipsel64n32 \ |
| 635 | parisc \ |
| 636 | ppc \ |
| 637 | + riscv32 \ |
| 638 | s390 \ |
| 639 | sheb sh" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 640 | |
| 641 | @@ -801,7 +802,7 @@ function run_test_live() { |
| 642 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 643 | # setup the arch specific return values |
| 644 | case "$arch" in |
| 645 | - x86|x86_64|x32|arm|aarch64|parisc|parisc64|ppc|ppc64|ppc64le|ppc|s390|s390x|riscv64|sh|sheb) |
| 646 | + x86|x86_64|x32|arm|aarch64|parisc|parisc64|ppc|ppc64|ppc64le|ppc|s390|s390x|riscv32|riscv64|sh|sheb) |
| 647 | rc_kill_process=159 |
| 648 | rc_kill=159 |
| 649 | rc_allow=160 |
| 650 | diff --git a/tools/scmp_arch_detect.c b/tools/scmp_arch_detect.c |
| 651 | index b6bd2bb..7789970 100644 |
| 652 | --- a/tools/scmp_arch_detect.c |
| 653 | +++ b/tools/scmp_arch_detect.c |
| 654 | @@ -129,6 +129,9 @@ int main(int argc, char *argv[]) |
| 655 | case SCMP_ARCH_SH: |
| 656 | printf("sh\n"); |
| 657 | break; |
| 658 | + case SCMP_ARCH_RISCV32: |
| 659 | + printf("riscv32\n"); |
| 660 | + break; |
| 661 | default: |
| 662 | printf("unknown\n"); |
| 663 | } |
| 664 | diff --git a/tools/scmp_bpf_disasm.c b/tools/scmp_bpf_disasm.c |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 665 | index b682de7..4f759fc 100644 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 666 | --- a/tools/scmp_bpf_disasm.c |
| 667 | +++ b/tools/scmp_bpf_disasm.c |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 668 | @@ -508,6 +508,8 @@ int main(int argc, char *argv[]) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 669 | arch = AUDIT_ARCH_S390X; |
| 670 | else if (strcmp(optarg, "riscv64") == 0) |
| 671 | arch = AUDIT_ARCH_RISCV64; |
| 672 | + else if (strcmp(optarg, "riscv32") == 0) |
| 673 | + arch = AUDIT_ARCH_RISCV32; |
| 674 | else |
| 675 | exit_usage(argv[0]); |
| 676 | break; |
| 677 | diff --git a/tools/scmp_bpf_sim.c b/tools/scmp_bpf_sim.c |
| 678 | index 04edfbc..53e6575 100644 |
| 679 | --- a/tools/scmp_bpf_sim.c |
| 680 | +++ b/tools/scmp_bpf_sim.c |
| 681 | @@ -285,6 +285,8 @@ int main(int argc, char *argv[]) |
| 682 | arch = AUDIT_ARCH_S390; |
| 683 | else if (strcmp(optarg, "s390x") == 0) |
| 684 | arch = AUDIT_ARCH_S390X; |
| 685 | + else if (strcmp(optarg, "riscv32") == 0) |
| 686 | + arch = AUDIT_ARCH_RISCV32; |
| 687 | else if (strcmp(optarg, "riscv64") == 0) |
| 688 | arch = AUDIT_ARCH_RISCV64; |
| 689 | else if (strcmp(optarg, "sheb") == 0) |
| 690 | diff --git a/tools/util.c b/tools/util.c |
| 691 | index afea6c9..1fc1f62 100644 |
| 692 | --- a/tools/util.c |
| 693 | +++ b/tools/util.c |
| 694 | @@ -78,8 +78,12 @@ |
| 695 | #define ARCH_NATIVE AUDIT_ARCH_S390X |
| 696 | #elif __s390__ |
| 697 | #define ARCH_NATIVE AUDIT_ARCH_S390 |
| 698 | -#elif __riscv && __riscv_xlen == 64 |
| 699 | +#elif __riscv |
| 700 | +#if __riscv_xlen == 64 |
| 701 | #define ARCH_NATIVE AUDIT_ARCH_RISCV64 |
| 702 | +#elif __riscv_xlen == 32 |
| 703 | +#define ARCH_NATIVE AUDIT_ARCH_RISCV32 |
| 704 | +#endif |
| 705 | #elif __sh__ |
| 706 | #ifdef __BIG_ENDIAN__ |
| 707 | #define ARCH_NATIVE AUDIT_ARCH_SH |
| 708 | diff --git a/tools/util.h b/tools/util.h |
| 709 | index 6c2ca33..4d16e38 100644 |
| 710 | --- a/tools/util.h |
| 711 | +++ b/tools/util.h |
| 712 | @@ -79,6 +79,13 @@ |
| 713 | #define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 714 | #endif /* AUDIT_ARCH_RISCV64 */ |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 715 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 716 | +#ifndef AUDIT_ARCH_RISCV32 |
| 717 | +#ifndef EM_RISCV |
| 718 | +#define EM_RISCV 243 |
| 719 | +#endif /* EM_RISCV */ |
| 720 | +#define AUDIT_ARCH_RISCV32 (EM_RISCV|__AUDIT_ARCH_LE) |
| 721 | +#endif /* AUDIT_ARCH_RISCV32 */ |
| 722 | + |
| 723 | extern uint32_t arch; |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 724 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 725 | uint16_t ttoh16(uint32_t arch, uint16_t val); |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 726 | -- |
| 727 | 2.33.0 |
| 728 | |