Loading .gitlab-ci.yml +3 −1 Original line number Diff line number Diff line Loading @@ -56,9 +56,11 @@ unit-test-job: # This job runs in the test stage. image: gekkofs/deps:0.9.4-dev needs: ['build-job'] script: - ls -ltrh ${INSTALL_PATH} - ${BUILD_PATH}/opendevnull --syscall getpid --reps 1 --verbose - LD_PRELOAD=${BUILD_PATH}/libeval_intercept.so ${BUILD_PATH}/opendevnull --syscall getpid --reps 1 --verbose - ${BUILD_PATH}/opendevnull --syscall kill --reps 1 --verbose - LD_PRELOAD=${BUILD_PATH}/libeval_intercept.so ${BUILD_PATH}/opendevnull --syscall kill --reps 1 --verbose - LD_PRELOAD=${BUILD_PATH}/libeval_intercept.so ${BUILD_PATH}/opendevnull --syscall kill --reps 1 --verbose --always_syscall artifacts: expire_in: 1 week when: always Loading src/eval.cpp +61 −47 Original line number Diff line number Diff line Loading @@ -2,37 +2,52 @@ #include <libsyscall_intercept_hook_point.h> #include <sys/syscall.h> #include <sys/types.h> void start_interception() __attribute__((constructor)); void stop_interception() __attribute__((destructor)); void start_interception() __attribute__((constructor)); void stop_interception() __attribute__((destructor)); int hook_openat(int dirfd, const char *cpath, int flags, mode_t mode) { int hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { return syscall_no_intercept(SYS_openat, dirfd, cpath, flags, mode); } int hook_getpid() { int hook_getpid() { return 42; } inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { int hook_kill(int pid, int sig) { return 42; } inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long* result) { switch(syscall_number) { #ifdef SYS_open case SYS_open: *result = hook_openat(AT_FDCWD, reinterpret_cast<char*>(arg0), static_cast<int>(arg1), static_cast<mode_t>(arg2)); static_cast<int>(arg1), static_cast<mode_t>(arg2)); break; #endif case SYS_openat: *result = hook_openat(static_cast<int>(arg0), reinterpret_cast<const char *>(arg1), *result = hook_openat( static_cast<int>(arg0), reinterpret_cast<const char*>(arg1), static_cast<int>(arg2), static_cast<mode_t>(arg3)); break; case SYS_getpid: *result = hook_getpid(); break; case SYS_kill: *result = hook_kill(static_cast<int>(arg0), static_cast<int>(arg1)); break; default: // ignore any other syscalls, i.e.: pass them on to the kernel // (syscalls forwarded to the kernel that return are logged in Loading @@ -44,29 +59,28 @@ inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, return 0; } int hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, int hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long* syscall_return_value) { int was_hooked = 1; if (syscall_number == SYS_openat) was_hooked = hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); else if (syscall_number == SYS_getpid) was_hooked = hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); if (syscall_number == SYS_openat || syscall_number == SYS_getpid || syscall_number == SYS_kill) { was_hooked = hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); } return was_hooked; } void start_interception() { void start_interception() { // Set up the callback function pointer intercept_hook_point = hook_guard_wrapper; } void stop_interception() { void stop_interception() { // Reset callback function pointer intercept_hook_point = nullptr; Loading src/opendevnull.cpp +41 −22 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ #include <cmath> #include <sys/syscall.h> #include <unistd.h> #include <signal.h> #include <libsyscall_intercept_hook_point.h> Loading Loading @@ -56,7 +57,8 @@ main(int argc, char* argv[]) { if(i + 1 < argc) { syscall = argv[++i]; } else { std::cerr << "Error: --syscall requires an argument" std::cerr << "Error: --syscall requires an argument (open|getpid|kill)" << std::endl; return 1; } Loading Loading @@ -117,20 +119,37 @@ main(int argc, char* argv[]) { auto post_getpid = [](int) { }; auto pre_kill = []() { int ret = kill(-1, 0); if(verbose) { std::cout << "kill() returned " << ret << std::endl; } if(always_syscall) { syscall_no_intercept(SYS_kill, -1, 0); } return ret; }; auto post_kill = [](int) { }; double time_taken = 0.0; if(syscall == "open") { time_taken = measure_syscall_time(pre_open, post_open, reps); } else if(syscall == "getpid") { time_taken = measure_syscall_time(pre_getpid, post_getpid, reps); } else if(syscall == "kill") { time_taken = measure_syscall_time(pre_kill, post_kill, reps); } else { std::cerr << "Error: Unsupported syscall '" << syscall << "'" << std::endl; std::cerr << "Error: Unsupported syscall '" << syscall << "'" << std::endl; return 1; } std::cout << "Mean time taken: " << time_taken / reps << " microseconds" << std::endl; } return 0; } Loading
.gitlab-ci.yml +3 −1 Original line number Diff line number Diff line Loading @@ -56,9 +56,11 @@ unit-test-job: # This job runs in the test stage. image: gekkofs/deps:0.9.4-dev needs: ['build-job'] script: - ls -ltrh ${INSTALL_PATH} - ${BUILD_PATH}/opendevnull --syscall getpid --reps 1 --verbose - LD_PRELOAD=${BUILD_PATH}/libeval_intercept.so ${BUILD_PATH}/opendevnull --syscall getpid --reps 1 --verbose - ${BUILD_PATH}/opendevnull --syscall kill --reps 1 --verbose - LD_PRELOAD=${BUILD_PATH}/libeval_intercept.so ${BUILD_PATH}/opendevnull --syscall kill --reps 1 --verbose - LD_PRELOAD=${BUILD_PATH}/libeval_intercept.so ${BUILD_PATH}/opendevnull --syscall kill --reps 1 --verbose --always_syscall artifacts: expire_in: 1 week when: always Loading
src/eval.cpp +61 −47 Original line number Diff line number Diff line Loading @@ -2,37 +2,52 @@ #include <libsyscall_intercept_hook_point.h> #include <sys/syscall.h> #include <sys/types.h> void start_interception() __attribute__((constructor)); void stop_interception() __attribute__((destructor)); void start_interception() __attribute__((constructor)); void stop_interception() __attribute__((destructor)); int hook_openat(int dirfd, const char *cpath, int flags, mode_t mode) { int hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { return syscall_no_intercept(SYS_openat, dirfd, cpath, flags, mode); } int hook_getpid() { int hook_getpid() { return 42; } inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { int hook_kill(int pid, int sig) { return 42; } inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long* result) { switch(syscall_number) { #ifdef SYS_open case SYS_open: *result = hook_openat(AT_FDCWD, reinterpret_cast<char*>(arg0), static_cast<int>(arg1), static_cast<mode_t>(arg2)); static_cast<int>(arg1), static_cast<mode_t>(arg2)); break; #endif case SYS_openat: *result = hook_openat(static_cast<int>(arg0), reinterpret_cast<const char *>(arg1), *result = hook_openat( static_cast<int>(arg0), reinterpret_cast<const char*>(arg1), static_cast<int>(arg2), static_cast<mode_t>(arg3)); break; case SYS_getpid: *result = hook_getpid(); break; case SYS_kill: *result = hook_kill(static_cast<int>(arg0), static_cast<int>(arg1)); break; default: // ignore any other syscalls, i.e.: pass them on to the kernel // (syscalls forwarded to the kernel that return are logged in Loading @@ -44,29 +59,28 @@ inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, return 0; } int hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, int hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long* syscall_return_value) { int was_hooked = 1; if (syscall_number == SYS_openat) was_hooked = hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); else if (syscall_number == SYS_getpid) was_hooked = hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); if (syscall_number == SYS_openat || syscall_number == SYS_getpid || syscall_number == SYS_kill) { was_hooked = hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); } return was_hooked; } void start_interception() { void start_interception() { // Set up the callback function pointer intercept_hook_point = hook_guard_wrapper; } void stop_interception() { void stop_interception() { // Reset callback function pointer intercept_hook_point = nullptr; Loading
src/opendevnull.cpp +41 −22 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ #include <cmath> #include <sys/syscall.h> #include <unistd.h> #include <signal.h> #include <libsyscall_intercept_hook_point.h> Loading Loading @@ -56,7 +57,8 @@ main(int argc, char* argv[]) { if(i + 1 < argc) { syscall = argv[++i]; } else { std::cerr << "Error: --syscall requires an argument" std::cerr << "Error: --syscall requires an argument (open|getpid|kill)" << std::endl; return 1; } Loading Loading @@ -117,20 +119,37 @@ main(int argc, char* argv[]) { auto post_getpid = [](int) { }; auto pre_kill = []() { int ret = kill(-1, 0); if(verbose) { std::cout << "kill() returned " << ret << std::endl; } if(always_syscall) { syscall_no_intercept(SYS_kill, -1, 0); } return ret; }; auto post_kill = [](int) { }; double time_taken = 0.0; if(syscall == "open") { time_taken = measure_syscall_time(pre_open, post_open, reps); } else if(syscall == "getpid") { time_taken = measure_syscall_time(pre_getpid, post_getpid, reps); } else if(syscall == "kill") { time_taken = measure_syscall_time(pre_kill, post_kill, reps); } else { std::cerr << "Error: Unsupported syscall '" << syscall << "'" << std::endl; std::cerr << "Error: Unsupported syscall '" << syscall << "'" << std::endl; return 1; } std::cout << "Mean time taken: " << time_taken / reps << " microseconds" << std::endl; } return 0; }