Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
Signed-off-by: yzewei <[email protected]>
  • Loading branch information
yzewei committed Apr 18, 2024
1 parent 2239ca3 commit 0ee6017
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ else()
set(kmod_min_kver_map_s390x 2.6)
set(kmod_min_kver_map_riscv64 5.0)
set(kmod_min_kver_map_ppc64le 2.6)
set(kmod_min_kver_map_loongarch64 5.19)
set(kmod_min_kver_map_loongarch64 5.10)

if (LINUX_KERNEL_VERSION VERSION_LESS ${kmod_min_kver_map_${TARGET_ARCH}})
message(WARNING "[KMOD] To run this driver you need a Linux kernel version >= ${kmod_min_kver_map_${TARGET_ARCH}} but actual kernel version is: ${UNAME_RESULT}")
Expand Down
6 changes: 3 additions & 3 deletions driver/feature_gates.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ or GPL2.txt for full copies of the license.
// CAPTURE_SCHED_PROC_FORK
///////////////////////////////

#if defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_s390) || defined(__TARGET_ARCH_riscv) || defined(__TARGET_ARCH_loongarch)
#if defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_s390) || defined(__TARGET_ARCH_riscv) || defined(__TARGET_ARCH_loongarch64)
#define CAPTURE_SCHED_PROC_FORK
#endif

Expand All @@ -178,7 +178,7 @@ or GPL2.txt for full copies of the license.
// CAPTURE_64BIT_ARGS_SINGLE_REGISTER
///////////////////////////////

#if defined(__x86_64__) || defined(__aarch64__)
#if defined(__x86_64__) || defined(__aarch64__) || defined(__loongarch64)
#define CAPTURE_64BIT_ARGS_SINGLE_REGISTER
#endif

Expand Down Expand Up @@ -206,7 +206,7 @@ or GPL2.txt for full copies of the license.
// CAPTURE_SCHED_PROC_FORK
///////////////////////////////

#if defined(__aarch64__) || defined(__s390x__) || defined(__riscv) || defined(__loongarch__)
#if defined(__aarch64__) || defined(__s390x__) || defined(__riscv) || defined(__loongarch64)
#define CAPTURE_SCHED_PROC_FORK
#endif

Expand Down
6 changes: 0 additions & 6 deletions driver/syscall_compat_loongarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ or GPL2.txt for full copies of the license.
#ifndef __NR_readlinkat
#define __NR_readlinkat 78
#endif
#ifndef __NR_fstat
#define __NR_fstat 80
#endif
#ifndef __NR_sync
#define __NR_sync 81
#endif
Expand Down Expand Up @@ -494,9 +491,6 @@ or GPL2.txt for full copies of the license.
#ifndef __NR_setdomainname
#define __NR_setdomainname 162
#endif
#ifndef __NR_setrlimit
#define __NR_setrlimit 164
#endif
#ifndef __NR_getrusage
#define __NR_getrusage 165
#endif
Expand Down
4 changes: 4 additions & 0 deletions driver/syscall_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const struct syscall_evt_pair g_syscall_table[SYSCALL_TABLE_SIZE] = {
#ifdef __NR_lstat
[__NR_lstat - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_LSTAT_E, PPME_SYSCALL_LSTAT_X, PPM_SC_LSTAT},
#endif
#ifdef __NR_fstat
[__NR_fstat - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_FSTAT_E, PPME_SYSCALL_FSTAT_X, PPM_SC_FSTAT},
#endif
#ifdef __NR_epoll_wait
[__NR_epoll_wait - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_EPOLLWAIT_E, PPME_SYSCALL_EPOLLWAIT_X, PPM_SC_EPOLL_WAIT},
#endif
Expand Down Expand Up @@ -126,7 +128,9 @@ const struct syscall_evt_pair g_syscall_table[SYSCALL_TABLE_SIZE] = {
#ifdef __NR_getrlimit
[__NR_getrlimit - SYSCALL_TABLE_ID0] = {UF_USED, PPME_SYSCALL_GETRLIMIT_E, PPME_SYSCALL_GETRLIMIT_X, PPM_SC_GETRLIMIT},
#endif
#ifdef __NR_setrlimit
[__NR_setrlimit - SYSCALL_TABLE_ID0] = {UF_USED | UF_NEVER_DROP, PPME_SYSCALL_SETRLIMIT_E, PPME_SYSCALL_SETRLIMIT_X, PPM_SC_SETRLIMIT},
#endif
#ifdef __NR_prlimit64
[__NR_prlimit64 - SYSCALL_TABLE_ID0] = {UF_USED | UF_NEVER_DROP, PPME_SYSCALL_PRLIMIT_E, PPME_SYSCALL_PRLIMIT_X, PPM_SC_PRLIMIT64},
#endif
Expand Down
2 changes: 1 addition & 1 deletion driver/syscall_table64.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ or GPL2.txt for full copies of the license.
#include "syscall_compat_ppc64le.h"
#elif defined(__riscv)
#include "syscall_compat_riscv64.h"
#elif defined(__loongarch__)
#elif defined(__loongarch64)
#include "syscall_compat_loongarch64.h"
#endif /* __x86_64__ */
#elif defined(_MSC_VER) || defined(__EMSCRIPTEN__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ TEST(GenericTracepoints, sched_proc_fork_case_clone)

#ifdef __s390x__
ret_pid = syscall(__NR_clone, newsp, clone_flags, &parent_tid, &child_tid, tls);
#elif defined(__aarch64__) || defined(__riscv)
#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64) /*kernel clone.S*/
ret_pid = syscall(__NR_clone, clone_flags, newsp, &parent_tid, tls, &child_tid);
#else
ret_pid = syscall(__NR_clone, clone_flags, newsp, &parent_tid, &child_tid, tls);
Expand Down
2 changes: 1 addition & 1 deletion test/drivers/test_suites/syscall_enter_suite/clone_e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST(SyscallEnter, cloneE)
*/
#ifdef __s390x__
assert_syscall_state(SYSCALL_FAILURE, "clone", syscall(__NR_clone, newsp, clone_flags, &parent_tid, &child_tid, tls));
#elif defined(__aarch64__) || defined(__riscv)
#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64)
assert_syscall_state(SYSCALL_FAILURE, "clone", syscall(__NR_clone, clone_flags, newsp, &parent_tid, tls, &child_tid));
#else
assert_syscall_state(SYSCALL_FAILURE, "clone", syscall(__NR_clone, clone_flags, newsp, &parent_tid, &child_tid, tls));
Expand Down
4 changes: 2 additions & 2 deletions test/drivers/test_suites/syscall_exit_suite/clone_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(SyscallExit, cloneX_father)
*/
#ifdef __s390x__
ret_pid = syscall(__NR_clone, newsp, test_clone_flags, &parent_tid, &child_tid, tls);
#elif defined(__aarch64__) || defined(__riscv)
#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64)
ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, tls, &child_tid);
#else
ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, &child_tid, tls);
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST(SyscallExit, cloneX_child)

#ifdef __s390x__
ret_pid = syscall(__NR_clone, newsp, test_clone_flags, &parent_tid, &child_tid, tls);
#elif defined(__aarch64__) || defined(__riscv)
#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64)
ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, tls, &child_tid);
#else
ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, &child_tid, tls);
Expand Down
6 changes: 3 additions & 3 deletions test/drivers/test_suites/syscall_exit_suite/execveat_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ TEST(SyscallExit, execveatX_correct_exit)

evt_test->disable_capture();

#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__)
#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) || defined(__loongarch64)
/* We search for a child event. */
evt_test->assert_event_presence(ret_pid);

Expand Down Expand Up @@ -338,7 +338,7 @@ TEST(SyscallExit, execveatX_execve_exit)
evt_test->disable_capture();

/* `s390x` returns an `EXECVEAT_X` event while other architectures retun an `EXECVE_X` */
#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__)
#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) || defined(__loongarch64)
/* We search for a child event. */
evt_test->assert_event_absence(ret_pid, PPME_SYSCALL_EXECVE_19_X);
#else
Expand Down Expand Up @@ -494,7 +494,7 @@ TEST(SyscallExit, execveatX_success_memfd)

evt_test->disable_capture();

#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__)
#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) || defined(__loongarch64)
/* We search for a child event. */
evt_test->assert_event_presence(ret_pid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ void do___open_by_handle_atX_success(int *open_by_handle_fd, int *dirfd, char *f
* 6. Get dev and ino.
*/
struct stat file_stat;
#if defined(__loongarch64)
#else
assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, *open_by_handle_fd, &file_stat), NOT_EQUAL, -1);
*dev = (uint32_t)file_stat.st_dev;
*inode = file_stat.st_ino;

#endif
/*
* 7. Cleaning phase.
*/
Expand Down Expand Up @@ -187,11 +189,14 @@ TEST(SyscallExit, open_by_handle_atX_success)
/* Parameter 4: path (type: PT_FSPATH) */
evt_test->assert_charbuf_param(4, fspath);

#if defined(__loongarch64)
#elif
/* Parameter 5: dev (type: PT_UINT32) */
evt_test->assert_numeric_param(5, dev);

/* Parameter 6: ino (type: PT_UINT64) */
evt_test->assert_numeric_param(6, inode);
#endif

/*=============================== ASSERT PARAMETERS ===========================*/

Expand Down Expand Up @@ -243,11 +248,14 @@ TEST(SyscallExit, open_by_handle_atX_success_mp)
/* Parameter 4: path (type: PT_FSPATH) */
evt_test->assert_charbuf_param(4, fspath);

#if defined(__loongarch64)
#elif
/* Parameter 5: dev (type: PT_UINT32) */
evt_test->assert_numeric_param(5, dev);

/* Parameter 6: ino (type: PT_UINT64) */
evt_test->assert_numeric_param(6, inode);
#endif

/*=============================== ASSERT PARAMETERS ===========================*/

Expand Down
20 changes: 16 additions & 4 deletions test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ TEST(SyscallExit, openat2X_success)
how.resolve = RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS;
int32_t fd = syscall(__NR_openat2, dirfd, pathname, &how, sizeof(struct open_how));
assert_syscall_state(SYSCALL_SUCCESS, "openat2", fd, NOT_EQUAL, -1);


#if defined(__loongarch64)
#elif
/* Call `fstat` to retrieve the `dev` and `ino`. */
struct stat file_stat;
assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, fd, &file_stat), NOT_EQUAL, -1);
uint32_t dev = (uint32_t)file_stat.st_dev;
uint64_t inode = file_stat.st_ino;
#endif
close(fd);

/*=============================== TRIGGER SYSCALL ===========================*/
Expand Down Expand Up @@ -66,12 +69,15 @@ TEST(SyscallExit, openat2X_success)
/* Parameter 6: resolve (type: PT_FLAGS32) */
evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS);

#if defined(__loongarch64)
#elif
/* Parameter 7: dev (type: PT_UINT32) */
evt_test->assert_numeric_param(7, dev);

/* Parameter 8: ino (type: PT_UINT64) */
evt_test->assert_numeric_param(8, inode);

#endif

/*=============================== ASSERT PARAMETERS ===========================*/

evt_test->assert_num_params_pushed(8);
Expand Down Expand Up @@ -164,12 +170,15 @@ TEST(SyscallExit, openat2X_create_success)
syscall(__NR_unlinkat, AT_FDCWD, pathname, 0); /* remove file before creating it */
int32_t fd = syscall(__NR_openat2, dirfd, pathname, &how, sizeof(struct open_how));
assert_syscall_state(SYSCALL_SUCCESS, "openat2", fd, NOT_EQUAL, -1);


#if defined(__loongarch64)
#elif
/* Call `fstat` to retrieve the `dev` and `ino`. */
struct stat file_stat;
assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, fd, &file_stat), NOT_EQUAL, -1);
uint32_t dev = (uint32_t)file_stat.st_dev;
uint64_t inode = file_stat.st_ino;
#endif
close(fd);

/*=============================== TRIGGER SYSCALL ===========================*/
Expand Down Expand Up @@ -207,12 +216,15 @@ TEST(SyscallExit, openat2X_create_success)
/* Parameter 6: resolve (type: PT_FLAGS32) */
evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS);

#if defined(__loongarch64)
#elif
/* Parameter 7: dev (type: PT_UINT32) */
evt_test->assert_numeric_param(7, dev);

/* Parameter 8: ino (type: PT_UINT64) */
evt_test->assert_numeric_param(8, inode);

#endif

/*=============================== ASSERT PARAMETERS ===========================*/

evt_test->assert_num_params_pushed(8);
Expand Down
2 changes: 2 additions & 0 deletions test/libscap/test_suites/engines/gvisor/gvisor_parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ limitations under the License.
#include "../../driver/syscall_compat_aarch64.h"
#elif __s390x__
#include "../../driver/syscall_compat_s390x.h"
#elif __loongarch64
#include "../../driver/syscall_compat_loongarch64.h"
#endif /* __x86_64__ */

template<class T>
Expand Down
2 changes: 2 additions & 0 deletions userspace/libscap/engine/gvisor/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ limitations under the License.
#include <driver/syscall_compat_ppc64le.h>
#elif __riscv
#include <driver/syscall_compat_riscv64.h>
#elif __loongarch64
#include "../../driver/syscall_compat_loongarch64.h"
#endif /* __x86_64__ */

#include <functional>
Expand Down

0 comments on commit 0ee6017

Please sign in to comment.