Skip to content

Commit 49096f7

Browse files
committed
arch: Add riscv32 architecture support
Support for rv32 was upstreamed into 5.4+ kernel Signed-off-by: Khem Raj <raj.khem@gmail.com>
1 parent 5822e50 commit 49096f7

32 files changed

Lines changed: 198 additions & 7 deletions

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
3333
Jonah Petri <jonah@petri.us>
3434
Justin Cormack <justin.cormack@docker.com>
3535
Kees Cook <keescook@chromium.org>
36+
Khem Raj <raj.khem@gmail.com>
3637
Kyle R. Conway <kyle.r.conway@gmail.com>
3738
Kenta Tada <Kenta.Tada@sony.com>
3839
Luca Bruno <lucab@debian.org>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The libseccomp library currently supports the architectures listed below:
5454
* 32-bit s390 (s390)
5555
* 64-bit s390x (s390x)
5656
* 64-bit RISC-V (riscv64)
57+
* 32-bit RISC-V (riscv32)
5758
* 32-bit SuperH big endian (sheb)
5859
* 32-bit SuperH (sh)
5960

doc/man/man1/scmp_sys_resolver.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The architecture to use for resolving the system call. Valid
3636
.I ARCH
3737
values are "x86", "x86_64", "x32", "arm", "aarch64", "mips", "mipsel", "mips64",
3838
"mipsel64", "mips64n32", "mipsel64n32", "parisc", "parisc64", "ppc", "ppc64",
39-
"ppc64le", "s390", "s390x", "sheb" and "sh".
39+
"ppc64le", "riscv32", "s390", "s390x", "sheb" and "sh".
4040
.TP
4141
.B \-t
4242
If necessary, translate the system call name to the proper system call number,

doc/man/man3/seccomp_arch_add.3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ seccomp_arch_add, seccomp_arch_remove, seccomp_arch_exist, seccomp_arch_native \
3030
.B #define SCMP_ARCH_S390X
3131
.B #define SCMP_ARCH_PARISC
3232
.B #define SCMP_ARCH_PARISC64
33+
.B #define SCMP_ARCH_RISCV32
3334
.B #define SCMP_ARCH_RISCV64
3435
.sp
3536
.BI "uint32_t seccomp_arch_resolve_name(const char *" arch_name ");"

include/seccomp-syscalls.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@
275275
#define __PNR_ppoll -10241
276276
#define __PNR_renameat -10242
277277
#define __PNR_riscv_flush_icache -10243
278+
#define __PNR_fstat -10244
279+
#define __PNR_futex -10245
280+
#define __PNR_nanosleep -10246
281+
#define __PNR_lseek -10247
282+
#define __PNR_clock_gettime -10248
278283

279284
/*
280285
* libseccomp syscall definitions
@@ -442,7 +447,11 @@
442447
#define __SNR_clock_getres_time64 __PNR_clock_getres_time64
443448
#endif
444449

450+
#ifdef __NR_clock_gettime
445451
#define __SNR_clock_gettime __NR_clock_gettime
452+
#else
453+
#define __SNR_clock_gettime __PNR_clock_gettime
454+
#endif
446455

447456
#ifdef __NR_clock_gettime64
448457
#define __SNR_clock_gettime64 __NR_clock_gettime64
@@ -710,7 +719,11 @@
710719
#define __SNR_ftruncate64 __PNR_ftruncate64
711720
#endif
712721

722+
#ifdef __NR_futex
713723
#define __SNR_futex __NR_futex
724+
#else
725+
#define __SNR_futex __PNR_futex
726+
#endif
714727

715728
#ifdef __NR_futex_time64
716729
#define __SNR_futex_time64 __NR_futex_time64
@@ -1046,7 +1059,11 @@
10461059

10471060
#define __SNR_lremovexattr __NR_lremovexattr
10481061

1062+
#ifdef __NR_lseek
10491063
#define __SNR_lseek __NR_lseek
1064+
#else
1065+
#define __SNR_lseek __PNR_lseek
1066+
#endif
10501067

10511068
#define __SNR_lsetxattr __NR_lsetxattr
10521069

@@ -1218,7 +1235,11 @@
12181235

12191236
#define __SNR_name_to_handle_at __NR_name_to_handle_at
12201237

1238+
#ifdef __NR_nanosleep
12211239
#define __SNR_nanosleep __NR_nanosleep
1240+
#else
1241+
#define __SNR_nanosleep __PNR_nanosleep
1242+
#endif
12221243

12231244
#ifdef __NR_newfstatat
12241245
#define __SNR_newfstatat __NR_newfstatat

include/seccomp.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,16 @@ struct scmp_arg_cmp {
214214
#endif /* EM_RISCV */
215215
#define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
216216
#endif /* AUDIT_ARCH_RISCV64 */
217+
218+
#ifndef AUDIT_ARCH_RISCV32
219+
#ifndef EM_RISCV
220+
#define EM_RISCV 243
221+
#endif /* EM_RISCV */
222+
#define AUDIT_ARCH_RISCV32 (EM_RISCV|__AUDIT_ARCH_LE)
223+
#endif /* AUDIT_ARCH_RISCV32 */
224+
217225
#define SCMP_ARCH_RISCV64 AUDIT_ARCH_RISCV64
226+
#define SCMP_ARCH_RISCV32 AUDIT_ARCH_RISCV32
218227

219228
/**
220229
* The SuperH architecture tokens

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SOURCES_ALL = \
4444
arch-ppc.h arch-ppc.c \
4545
arch-ppc64.h arch-ppc64.c \
4646
arch-riscv64.h arch-riscv64.c \
47+
arch-riscv32.h arch-riscv32.c \
4748
arch-s390.h arch-s390.c \
4849
arch-s390x.h arch-s390x.c \
4950
arch-sh.h arch-sh.c \

src/arch-riscv32.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This library is free software; you can redistribute it and/or modify it
3+
* under the terms of version 2.1 of the GNU Lesser General Public License as
4+
* published by the Free Software Foundation.
5+
*
6+
* This library is distributed in the hope that it will be useful, but WITHOUT
7+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9+
* for more details.
10+
*
11+
* You should have received a copy of the GNU Lesser General Public License
12+
* along with this library; if not, see <http://www.gnu.org/licenses>.
13+
*/
14+
15+
#include <stdlib.h>
16+
#include <errno.h>
17+
#include <linux/audit.h>
18+
19+
#include "arch.h"
20+
#include "arch-riscv32.h"
21+
22+
const struct arch_def arch_def_riscv32 = {
23+
.token = SCMP_ARCH_RISCV32,
24+
.token_bpf = AUDIT_ARCH_RISCV32,
25+
.size = ARCH_SIZE_32,
26+
.endian = ARCH_ENDIAN_LITTLE,
27+
.syscall_resolve_name = riscv32_syscall_resolve_name,
28+
.syscall_resolve_num = riscv32_syscall_resolve_num,
29+
.syscall_rewrite = NULL,
30+
.rule_add = NULL,
31+
};

src/arch-riscv32.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* This library is free software; you can redistribute it and/or modify it
3+
* under the terms of version 2.1 of the GNU Lesser General Public License as
4+
* published by the Free Software Foundation.
5+
*
6+
* This library is distributed in the hope that it will be useful, but WITHOUT
7+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9+
* for more details.
10+
*
11+
* You should have received a copy of the GNU Lesser General Public License
12+
* along with this library; if not, see <http://www.gnu.org/licenses>.
13+
*/
14+
15+
#ifndef _ARCH_RISCV32_H
16+
#define _ARCH_RISCV32_H
17+
18+
#include "arch.h"
19+
20+
ARCH_DECL(riscv32)
21+
22+
#endif

src/arch-syscall-dump.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "arch-ppc.h"
4444
#include "arch-ppc64.h"
4545
#include "arch-riscv64.h"
46+
#include "arch-riscv32.h"
4647
#include "arch-s390.h"
4748
#include "arch-s390x.h"
4849
#include "arch-sh.h"
@@ -135,6 +136,9 @@ int main(int argc, char *argv[])
135136
case SCMP_ARCH_RISCV64:
136137
sys = riscv64_syscall_iterate(iter);
137138
break;
139+
case SCMP_ARCH_RISCV32:
140+
sys = riscv32_syscall_iterate(iter);
141+
break;
138142
case SCMP_ARCH_S390:
139143
sys = s390_syscall_iterate(iter);
140144
break;

0 commit comments

Comments
 (0)