Skip to content

Commit d8d82b1

Browse files
committed
Add riscv64 support
This commit does the following things: - Support the riscv64 by reusing the aarch64 syscalls - Disable link time relaxation of riscv64 to reduce link time - Fetch the correct rootfs in build script Closed #18 Change-Id: I271ce08e569f5947acbd75626c54b7fae9f0ce39
1 parent 0c29e03 commit d8d82b1

File tree

8 files changed

+22
-6
lines changed

8 files changed

+22
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ See `docs/gdb-workflow.md` for the full workflow.
235235

236236
- x86_64
237237
- aarch64
238+
- riscv64
238239

239240
## License
240241
`kbox` is available under a permissive MIT-style license.

mk/toolchain.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ CFLAGS += -std=gnu11 -D_GNU_SOURCE -Wall -Wextra -Wpedantic -Wshadow
2828
CFLAGS += -Wno-unused-parameter
2929
CFLAGS += -Iinclude -Isrc
3030

31+
# Disable link relaxation of riscv64 architecture to prevent long link time
32+
ifeq ($(ARCH),riscv64)
33+
LDFLAGS += -Wl,--no-relax
34+
endif
35+
3136
# Build mode from Kconfig (fallback to BUILD= for unconfigured builds)
3237
ifeq ($(CONFIG_BUILD_RELEASE),y)
3338
CFLAGS += -O2 -DNDEBUG

scripts/alpine-sha256.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
55ea3e5a7c2c35e6268c5dcbb8e45a9cd5b0e372e7b4e798499a526834f7ed90 alpine-minirootfs-3.21.0-x86_64.tar.gz
22
f31202c4070c4ef7de9e157e1bd01cb4da3a2150035d74ea5372c5e86f1efac1 alpine-minirootfs-3.21.0-aarch64.tar.gz
3+
b2c5ed2be586aebd2da5dd13dbc96bc8cc41b72e517d0726dfbbb0a9810e66d6 alpine-minirootfs-3.21.0-riscv64.tar.gz

scripts/fetch-lkl.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set -eu
1717
case "${1:-$(uname -m)}" in
1818
x86_64 | amd64) ARCH="x86_64" ;;
1919
aarch64 | arm64) ARCH="aarch64" ;;
20+
riscv64) ARCH="riscv64" ;;
2021
*)
2122
echo "error: unsupported architecture: ${1:-$(uname -m)}" >&2
2223
exit 1

scripts/mkrootfs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if [ -z "${ALPINE_ARCH:-}" ]; then
2727
case "$(uname -m)" in
2828
aarch64 | arm64) ALPINE_ARCH="aarch64" ;;
2929
x86_64 | amd64) ALPINE_ARCH="x86_64" ;;
30+
riscv64) ALPINE_ARCH="riscv64" ;;
3031
*) die "Unsupported host architecture: $(uname -m). Set ALPINE_ARCH explicitly." ;;
3132
esac
3233
fi

src/seccomp-bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static const int deny_nrs[] = {
138138
153, /* vhangup */
139139
};
140140

141-
#elif defined(__aarch64__)
141+
#elif defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
142142
static const int deny_nrs[] = {
143143
/* Seccomp manipulation */
144144
277, /* seccomp */

src/seccomp-defs.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define KBOX_AUDIT_ARCH_CURRENT 0xc000003eU
2929
#elif defined(__aarch64__)
3030
#define KBOX_AUDIT_ARCH_CURRENT 0xc00000b7U
31+
#elif defined(__riscv) && __riscv_xlen == 64
32+
#define KBOX_AUDIT_ARCH_CURRENT 0xc00000f3U
3133
#else
3234
#error "unsupported architecture"
3335
#endif
@@ -44,11 +46,16 @@ struct kbox_sock_fprog {
4446
struct kbox_sock_filter *filter;
4547
};
4648

47-
#define KBOX_BPF_STMT(c, val) {(unsigned short) (c), 0, 0, (unsigned int) (val)}
49+
#define KBOX_BPF_STMT(c, val) \
50+
{ \
51+
(unsigned short) (c), 0, 0, (unsigned int) (val) \
52+
}
4853

49-
#define KBOX_BPF_JUMP(c, val, t, f) \
50-
{(unsigned short) (c), (unsigned char) (t), (unsigned char) (f), \
51-
(unsigned int) (val)}
54+
#define KBOX_BPF_JUMP(c, val, t, f) \
55+
{ \
56+
(unsigned short) (c), (unsigned char) (t), (unsigned char) (f), \
57+
(unsigned int) (val) \
58+
}
5259

5360
struct kbox_seccomp_notif {
5461
uint64_t id;

src/seccomp-supervisor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ int kbox_run_supervisor(const struct kbox_sysnrs *sysnrs,
369369
/* Architecture-specific host syscall numbers for the BPF filter. */
370370
#if defined(__x86_64__)
371371
const struct kbox_host_nrs *host_nrs = &HOST_NRS_X86_64;
372-
#elif defined(__aarch64__)
372+
#elif defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
373373
const struct kbox_host_nrs *host_nrs = &HOST_NRS_AARCH64;
374374
#else
375375
#error "Unsupported architecture"

0 commit comments

Comments
 (0)