jail/seccomp: add support for loongarch64
authorWeijie Gao <hackpascal@gmail.com>
Sun, 22 Dec 2024 10:28:12 +0000 (18:28 +0800)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 22 Dec 2024 16:04:11 +0000 (17:04 +0100)
Add support for loongarch64 in utrace and ujail.

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
jail/seccomp-bpf.h
jail/seccomp-oci.c
trace/trace.c

index 077483f3bf10524306a5343fd5b0135fb591b3bb..e6384dbaf70b9cf72a50564b7e17e3cd092d4a13 100644 (file)
@@ -80,6 +80,9 @@ struct seccomp_data {
 #elif defined(__i386__)
 # define REG_SYSCALL   REG_EAX
 # define ARCH_NR       AUDIT_ARCH_I386
+#elif defined(__loongarch_lp64)
+# define REG_SYSCALL   regs[11]
+# define ARCH_NR       AUDIT_ARCH_LOONGARCH64
 #elif defined(__mips__)
 # define REG_SYSCALL   regs[2]
 # if __BYTE_ORDER == __LITTLE_ENDIAN
index f089ac6cc75eb54bdb902106a82046b71173b213..9ef43d111dcd2da648923025c711ca77e3bf6c4b 100644 (file)
@@ -119,6 +119,8 @@ static uint32_t resolve_architecture(char *archname)
                return AUDIT_ARCH_ARM;
        else if (!strcmp(archname, "SCMP_ARCH_AARCH64"))
                return AUDIT_ARCH_AARCH64;
+       else if (!strcmp(archname, "SCMP_ARCH_LOONGARCH64"))
+               return AUDIT_ARCH_LOONGARCH64;
        else if (!strcmp(archname, "SCMP_ARCH_MIPS"))
                return AUDIT_ARCH_MIPS;
        else if (!strcmp(archname, "SCMP_ARCH_MIPS64"))
index e257d89c00c891b0ee8b9836bab4d1ae73dd8707..47c2fefc433cc04412c9966aad2808bd61603b25 100644 (file)
@@ -48,7 +48,7 @@
 #define _offsetof(a, b) __builtin_offsetof(a,b)
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-#if defined (__aarch64__)
+#if defined (__aarch64__) || defined(__loongarch_lp64)
 #include <linux/ptrace.h>
 #elif defined(__amd64__)
 #define reg_syscall_nr _offsetof(struct user, regs.orig_rax)
@@ -226,7 +226,7 @@ static void tracer_cb(struct uloop_process *c, int ret)
        if (WIFSTOPPED(ret) || (ret >> 16)) {
                if (WSTOPSIG(ret) & 0x80) {
                        if (!tracee->in_syscall) {
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__loongarch_lp64)
                                int syscall = -1;
                                struct ptrace_syscall_info ptsi = {.op=PTRACE_SYSCALL_INFO_ENTRY};
                                if (ptrace(PTRACE_GET_SYSCALL_INFO, c->pid, sizeof(ptsi), &ptsi) != -1)
@@ -260,7 +260,7 @@ static void tracer_cb(struct uloop_process *c, int ret)
                } else if ((ret >> 16) == PTRACE_EVENT_STOP) {
                        /* Nothing special to do here */
                } else if ((ret >> 8) == (SIGTRAP | (PTRACE_EVENT_SECCOMP << 8))) {
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__loongarch_lp64)
                        int syscall = -1;
                        struct ptrace_syscall_info ptsi = {.op=PTRACE_SYSCALL_INFO_SECCOMP};
                        if (ptrace(PTRACE_GET_SYSCALL_INFO, c->pid, sizeof(ptsi), &ptsi) != -1)