summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaotian Wu <wuxiaotian@loongson.cn>2021-02-09 15:39:13 +0800
committerPaul Moore <paul@paul-moore.com>2023-02-18 22:07:30 -0500
commit6966ec77b195ac289ae168c7c5646d59a307f33f (patch)
treedaa4e9a4febf1e891195a61c608b6fc0155967ff
parent315f7b9ec6d8992035a2c0f652949ee34843db32 (diff)
downloadlibseccomp-6966ec77b195ac289ae168c7c5646d59a307f33f.tar.gz
arch: Add 64-bit LoongArch support
Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn> Signed-off-by: WANG Xuerui <git@xen0n.name> Acked-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
-rw-r--r--include/seccomp.h.in12
-rw-r--r--src/Makefile.am1
-rw-r--r--src/arch-loongarch64.c42
-rw-r--r--src/arch-loongarch64.h28
-rw-r--r--src/arch-syscall-dump.c4
-rwxr-xr-xsrc/arch-syscall-validate50
-rw-r--r--src/arch.c7
-rw-r--r--src/gen_pfc.c2
-rw-r--r--src/python/libseccomp.pxd1
-rw-r--r--src/python/seccomp.pyx4
-rw-r--r--src/syscalls.h4
-rw-r--r--src/system.c1
-rw-r--r--tools/scmp_arch_detect.c3
-rw-r--r--tools/scmp_bpf_disasm.c2
-rw-r--r--tools/scmp_bpf_sim.c2
-rw-r--r--tools/util.c2
-rw-r--r--tools/util.h11
17 files changed, 176 insertions, 0 deletions
diff --git a/include/seccomp.h.in b/include/seccomp.h.in
index dfbb267..4ab10d9 100644
--- a/include/seccomp.h.in
+++ b/include/seccomp.h.in
@@ -153,6 +153,18 @@ struct scmp_arg_cmp {
#define SCMP_ARCH_AARCH64 AUDIT_ARCH_AARCH64
/**
+ * The LoongArch architecture tokens
+ */
+/* 64-bit LoongArch audit support is upstream as of 5.19-rc1 */
+#ifndef AUDIT_ARCH_LOONGARCH64
+#ifndef EM_LOONGARCH
+#define EM_LOONGARCH 258
+#endif /* EM_LOONGARCH */
+#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#endif /* AUDIT_ARCH_LOONGARCH64 */
+#define SCMP_ARCH_LOONGARCH64 AUDIT_ARCH_LOONGARCH64
+
+/**
* The MIPS architecture tokens
*/
#ifndef __AUDIT_ARCH_CONVENTION_MIPS64_N32
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ff0ee7..8c39d9e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,7 @@ SOURCES_ALL = \
arch-x32.h arch-x32.c \
arch-arm.h arch-arm.c \
arch-aarch64.h arch-aarch64.c \
+ arch-loongarch64.h arch-loongarch64.c \
arch-mips.h arch-mips.c \
arch-mips64.h arch-mips64.c \
arch-mips64n32.h arch-mips64n32.c \
diff --git a/src/arch-loongarch64.c b/src/arch-loongarch64.c
new file mode 100644
index 0000000..8268204
--- /dev/null
+++ b/src/arch-loongarch64.c
@@ -0,0 +1,42 @@
+/**
+ * Enhanced Seccomp 64-bit LoongArch Syscall Table
+ *
+ * Copyright (c) 2021 Xiaotian Wu <wuxiaotian@loongson.cn>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <linux/audit.h>
+
+#include "arch.h"
+#include "arch-loongarch64.h"
+#include "syscalls.h"
+
+ARCH_DEF(loongarch64)
+
+const struct arch_def arch_def_loongarch64 = {
+ .token = SCMP_ARCH_LOONGARCH64,
+ .token_bpf = AUDIT_ARCH_LOONGARCH64,
+ .size = ARCH_SIZE_64,
+ .endian = ARCH_ENDIAN_LITTLE,
+ .syscall_resolve_name_raw = loongarch64_syscall_resolve_name,
+ .syscall_resolve_num_raw = loongarch64_syscall_resolve_num,
+ .syscall_rewrite = NULL,
+ .rule_add = NULL,
+ .syscall_name_kver = loongarch64_syscall_name_kver,
+ .syscall_num_kver = loongarch64_syscall_num_kver,
+};
diff --git a/src/arch-loongarch64.h b/src/arch-loongarch64.h
new file mode 100644
index 0000000..c3c06af
--- /dev/null
+++ b/src/arch-loongarch64.h
@@ -0,0 +1,28 @@
+/**
+ * Enhanced Seccomp 64-bit LoongArch Syscall Table
+ *
+ * Copyright (c) 2021 Xiaotian Wu <wuxiaotian@loongson.cn>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#ifndef _ARCH_LOONGARCH64_H
+#define _ARCH_LOONGARCH64_H
+
+#include "arch.h"
+
+ARCH_DECL(loongarch64)
+
+#endif
diff --git a/src/arch-syscall-dump.c b/src/arch-syscall-dump.c
index 843483b..abc1680 100644
--- a/src/arch-syscall-dump.c
+++ b/src/arch-syscall-dump.c
@@ -34,6 +34,7 @@
#include "arch-x86_64.h"
#include "arch-x32.h"
#include "arch-arm.h"
+#include "arch-loongarch64.h"
#include "arch-mips.h"
#include "arch-mips64.h"
#include "arch-mips64n32.h"
@@ -107,6 +108,9 @@ int main(int argc, char *argv[])
case SCMP_ARCH_AARCH64:
sys = aarch64_syscall_iterate(iter);
break;
+ case SCMP_ARCH_LOONGARCH64:
+ sys = loongarch64_syscall_iterate(iter);
+ break;
case SCMP_ARCH_MIPS:
case SCMP_ARCH_MIPSEL:
sys = mips_syscall_iterate(iter);
diff --git a/src/arch-syscall-validate b/src/arch-syscall-validate
index 0cb4d8f..b2f62c6 100755
--- a/src/arch-syscall-validate
+++ b/src/arch-syscall-validate
@@ -307,6 +307,48 @@ function dump_lib_aarch64() {
}
#
+# Dump the loongarch64 syscall table
+#
+# Arguments:
+# 1 path to the kernel source
+#
+# Dump the architecture's syscall table to stdout.
+#
+function dump_sys_loongarch64() {
+ local sed_filter=""
+
+ sed_filter+='s/__NR3264_fadvise64/223/;'
+ sed_filter+='s/__NR3264_fcntl/25/;'
+ sed_filter+='s/__NR3264_fstatfs/44/;'
+ sed_filter+='s/__NR3264_ftruncate/46/;'
+ sed_filter+='s/__NR3264_lseek/62/;'
+ sed_filter+='s/__NR3264_mmap/222/;'
+ sed_filter+='s/__NR3264_sendfile/71/;'
+ sed_filter+='s/__NR3264_statfs/43/;'
+ sed_filter+='s/__NR3264_truncate/45/;'
+
+ gcc -E -dM -I$1/include/uapi \
+ -D__BITS_PER_LONG=64 \
+ -D__ARCH_WANT_SYS_CLONE \
+ -D__ARCH_WANT_SYS_CLONE3 \
+ $1/arch/loongarch/include/uapi/asm/unistd.h | \
+ grep "^#define __NR_" | \
+ sed '/__NR_syscalls/d' | \
+ sed '/__NR_arch_specific_syscall/d' | \
+ sed 's/#define[ \t]\+__NR_\([^ \t]\+\)[ \t]\+\(.*\)/\1,\2/' | \
+ sed $sed_filter | sort
+}
+
+#
+# Dump the loongarch64 library syscall table
+#
+# Dump the library's syscall table to stdout.
+#
+function dump_lib_loongarch64() {
+ dump_lib_arch loongarch64 | mangle_lib_syscall loongarch64
+}
+
+#
# Dump the mips system syscall table
#
# Arguments:
@@ -619,6 +661,9 @@ function dump_sys() {
aarch64)
dump_sys_aarch64 "$2"
;;
+ loongarch64)
+ dump_sys_loongarch64 "$2"
+ ;;
mips)
dump_sys_mips "$2"
;;
@@ -686,6 +731,9 @@ function dump_lib() {
aarch64)
dump_lib_aarch64
;;
+ loongarch64)
+ dump_lib_loongarch64
+ ;;
mips)
dump_lib_mips
;;
@@ -750,6 +798,7 @@ function gen_csv() {
abi_list=""
abi_list+=" x86 x86_64 x32"
abi_list+=" arm aarch64"
+ abi_list+=" loongarch64"
abi_list+=" mips mips64 mips64n32"
abi_list+=" parisc parisc64"
abi_list+=" ppc ppc64"
@@ -861,6 +910,7 @@ if [[ $opt_arches == "" ]]; then
opt_arches=" \
x86 x86_64 x32 \
arm aarch64 \
+ loongarch64 \
mips mips64 mips64n32 \
parisc parisc64 \
ppc ppc64 \
diff --git a/src/arch.c b/src/arch.c
index 921e455..8c45fa3 100644
--- a/src/arch.c
+++ b/src/arch.c
@@ -35,6 +35,7 @@
#include "arch-x32.h"
#include "arch-arm.h"
#include "arch-aarch64.h"
+#include "arch-loongarch64.h"
#include "arch-mips.h"
#include "arch-mips64.h"
#include "arch-mips64n32.h"
@@ -63,6 +64,8 @@ const struct arch_def *arch_def_native = &arch_def_x86_64;
const struct arch_def *arch_def_native = &arch_def_arm;
#elif __aarch64__
const struct arch_def *arch_def_native = &arch_def_aarch64;
+#elif __loongarch64
+const struct arch_def *arch_def_native = &arch_def_loongarch64;
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32
#if __MIPSEB__
const struct arch_def *arch_def_native = &arch_def_mips;
@@ -141,6 +144,8 @@ const struct arch_def *arch_def_lookup(uint32_t token)
return &arch_def_arm;
case SCMP_ARCH_AARCH64:
return &arch_def_aarch64;
+ case SCMP_ARCH_LOONGARCH64:
+ return &arch_def_loongarch64;
case SCMP_ARCH_MIPS:
return &arch_def_mips;
case SCMP_ARCH_MIPSEL:
@@ -197,6 +202,8 @@ const struct arch_def *arch_def_lookup_name(const char *arch_name)
return &arch_def_arm;
else if (strcmp(arch_name, "aarch64") == 0)
return &arch_def_aarch64;
+ else if (strcmp(arch_name, "loongarch64") == 0)
+ return &arch_def_loongarch64;
else if (strcmp(arch_name, "mips") == 0)
return &arch_def_mips;
else if (strcmp(arch_name, "mipsel") == 0)
diff --git a/src/gen_pfc.c b/src/gen_pfc.c
index 4916055..bb217c8 100644
--- a/src/gen_pfc.c
+++ b/src/gen_pfc.c
@@ -61,6 +61,8 @@ static const char *_pfc_arch(const struct arch_def *arch)
return "arm";
case SCMP_ARCH_AARCH64:
return "aarch64";
+ case SCMP_ARCH_LOONGARCH64:
+ return "loongarch64";
case SCMP_ARCH_MIPS:
return "mips";
case SCMP_ARCH_MIPSEL:
diff --git a/src/python/libseccomp.pxd b/src/python/libseccomp.pxd
index 55f8207..a6bd0b4 100644
--- a/src/python/libseccomp.pxd
+++ b/src/python/libseccomp.pxd
@@ -38,6 +38,7 @@ cdef extern from "seccomp.h":
SCMP_ARCH_X32
SCMP_ARCH_ARM
SCMP_ARCH_AARCH64
+ SCMP_ARCH_LOONGARCH64
SCMP_ARCH_MIPS
SCMP_ARCH_MIPS64
SCMP_ARCH_MIPS64N32
diff --git a/src/python/seccomp.pyx b/src/python/seccomp.pyx
index 5657577..9891d76 100644
--- a/src/python/seccomp.pyx
+++ b/src/python/seccomp.pyx
@@ -206,6 +206,7 @@ cdef class Arch:
X32 - 64-bit x86 using the x32 ABI
ARM - ARM
AARCH64 - 64-bit ARM
+ LOONGARCH64 - 64-bit LoongArch
MIPS - MIPS O32 ABI
MIPS64 - MIPS 64-bit ABI
MIPS64N32 - MIPS N32 ABI
@@ -227,6 +228,7 @@ cdef class Arch:
X32 = libseccomp.SCMP_ARCH_X32
ARM = libseccomp.SCMP_ARCH_ARM
AARCH64 = libseccomp.SCMP_ARCH_AARCH64
+ LOONGARCH64 = libseccomp.SCMP_ARCH_LOONGARCH64
MIPS = libseccomp.SCMP_ARCH_MIPS
MIPS64 = libseccomp.SCMP_ARCH_MIPS64
MIPS64N32 = libseccomp.SCMP_ARCH_MIPS64N32
@@ -264,6 +266,8 @@ cdef class Arch:
self._token = libseccomp.SCMP_ARCH_ARM
elif arch == libseccomp.SCMP_ARCH_AARCH64:
self._token = libseccomp.SCMP_ARCH_AARCH64
+ elif arch == libseccomp.SCMP_ARCH_LOONGARCH64:
+ self._token = libseccomp.SCMP_ARCH_LOONGARCH64
elif arch == libseccomp.SCMP_ARCH_MIPS:
self._token = libseccomp.SCMP_ARCH_MIPS
elif arch == libseccomp.SCMP_ARCH_MIPS64:
diff --git a/src/syscalls.h b/src/syscalls.h
index 3a9e0cb..10b2b7a 100644
--- a/src/syscalls.h
+++ b/src/syscalls.h
@@ -15,6 +15,7 @@
#include "arch-aarch64.h"
#include "arch-arm.h"
#include "arch.h"
+#include "arch-loongarch64.h"
#include "arch-mips64.h"
#include "arch-mips64n32.h"
#include "arch-mips.h"
@@ -51,6 +52,9 @@ struct arch_syscall_table {
int aarch64;
enum scmp_kver aarch64_kver;
+ int loongarch64;
+ enum scmp_kver loongarch64_kver;
+
int mips;
enum scmp_kver mips_kver;
int mips64;
diff --git a/src/system.c b/src/system.c
index 3d10e21..e205de7 100644
--- a/src/system.c
+++ b/src/system.c
@@ -128,6 +128,7 @@ int sys_chk_seccomp_syscall(void)
case SCMP_ARCH_X86_64:
case SCMP_ARCH_ARM:
case SCMP_ARCH_AARCH64:
+ case SCMP_ARCH_LOONGARCH64:
case SCMP_ARCH_PPC64:
case SCMP_ARCH_PPC64LE:
case SCMP_ARCH_S390:
diff --git a/tools/scmp_arch_detect.c b/tools/scmp_arch_detect.c
index b6bd2bb..c23cf7f 100644
--- a/tools/scmp_arch_detect.c
+++ b/tools/scmp_arch_detect.c
@@ -81,6 +81,9 @@ int main(int argc, char *argv[])
case SCMP_ARCH_AARCH64:
printf("aarch64\n");
break;
+ case SCMP_ARCH_LOONGARCH64:
+ printf("loongarch64\n");
+ break;
case SCMP_ARCH_MIPS:
printf("mips\n");
break;
diff --git a/tools/scmp_bpf_disasm.c b/tools/scmp_bpf_disasm.c
index b682de7..4572659 100644
--- a/tools/scmp_bpf_disasm.c
+++ b/tools/scmp_bpf_disasm.c
@@ -484,6 +484,8 @@ int main(int argc, char *argv[])
arch = AUDIT_ARCH_ARM;
else if (strcmp(optarg, "aarch64") == 0)
arch = AUDIT_ARCH_AARCH64;
+ else if (strcmp(optarg, "loongarch64") == 0)
+ arch = AUDIT_ARCH_LOONGARCH64;
else if (strcmp(optarg, "mips") == 0)
arch = AUDIT_ARCH_MIPS;
else if (strcmp(optarg, "mipsel") == 0)
diff --git a/tools/scmp_bpf_sim.c b/tools/scmp_bpf_sim.c
index 04edfbc..7d31d79 100644
--- a/tools/scmp_bpf_sim.c
+++ b/tools/scmp_bpf_sim.c
@@ -259,6 +259,8 @@ int main(int argc, char *argv[])
arch = AUDIT_ARCH_ARM;
else if (strcmp(optarg, "aarch64") == 0)
arch = AUDIT_ARCH_AARCH64;
+ else if (strcmp(optarg, "loongarch64") == 0)
+ arch = AUDIT_ARCH_LOONGARCH64;
else if (strcmp(optarg, "mips") == 0)
arch = AUDIT_ARCH_MIPS;
else if (strcmp(optarg, "mipsel") == 0)
diff --git a/tools/util.c b/tools/util.c
index afea6c9..327fc14 100644
--- a/tools/util.c
+++ b/tools/util.c
@@ -44,6 +44,8 @@
#define ARCH_NATIVE AUDIT_ARCH_ARM
#elif __aarch64__
#define ARCH_NATIVE AUDIT_ARCH_AARCH64
+#elif __loongarch64
+#define ARCH_NATIVE AUDIT_ARCH_LOONGARCH64
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32
#if __MIPSEB__
#define ARCH_NATIVE AUDIT_ARCH_MIPS
diff --git a/tools/util.h b/tools/util.h
index 6c2ca33..24b9ed6 100644
--- a/tools/util.h
+++ b/tools/util.h
@@ -38,6 +38,17 @@
#endif /* AUDIT_ARCH_AARCH64 */
/**
+ * The 64-bit LoongArch architecture tokens
+ */
+/* 64-bit LoongArch audit support is upstream as of 5.19-rc1 */
+#ifndef AUDIT_ARCH_LOONGARCH64
+#ifndef EM_LOONGARCH
+#define EM_LOONGARCH 258
+#endif /* EM_LOONGARCH */
+#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#endif /* AUDIT_ARCH_LOONGARCH64 */
+
+/**
* The MIPS architecture tokens
*/
#ifndef __AUDIT_ARCH_CONVENTION_MIPS64_N32