Loading src/eval.cpp +10 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,10 @@ 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() { return 42; } inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { Loading @@ -26,6 +30,9 @@ inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, reinterpret_cast<const char *>(arg1), static_cast<int>(arg2), static_cast<mode_t>(arg3)); break; case SYS_getpid: *result = hook_getpid(); 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 @@ -46,7 +53,9 @@ int hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, 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); return was_hooked; } Loading src/opendevnull.cpp +54 −26 Original line number Diff line number Diff line Loading @@ -4,11 +4,27 @@ #include <sys/syscall.h> #include <unistd.h> int main() { int main(int argc, char* argv[]) { // Check if the correct number of arguments is provided if (argc != 3) { std::cerr << "Usage: " << argv[0] << " --syscall <open|getpid>" << std::endl; return 1; } // measure time to run in microseconds std::string option = argv[1]; std::string syscall = argv[2]; double reps = 1000.0*100000.0; // Handle the --syscall option if (option == "--syscall") { if (syscall == "open") { struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); // open /dev/null 100000 times for (int j = 0; j < 1000; j++) { for (int i = 0; i < 100000; i++) { Loading @@ -20,20 +36,32 @@ int main() { clock_gettime(CLOCK_MONOTONIC, &end); double time_taken = (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_nsec - start.tv_nsec) / 1e3; std::cout << "Time taken: " << time_taken << " microseconds" << std::endl; // mean of the time for a syscall (10000000) std::cout << "Mean time taken: " << time_taken / 100000000.0 << " microseconds" std::cout << "Mean time taken: " << time_taken / reps << " microseconds" << std::endl; // Calculate single syscall () } else if (syscall == "getpid") { struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); int fd = openat(AT_FDCWD, "/dev/null", O_RDWR, 0); close(fd); for (int j = 0; j < 1000; j++) { for (int i = 0; i < 100000; i++) { int ret = getpid(); } } clock_gettime(CLOCK_MONOTONIC, &end); std::cout << "Time taken for single syscall: " << (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_nsec - start.tv_nsec) / 1e3 << " microseconds" << std::endl; double time_taken = (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_nsec - start.tv_nsec) / 1e3; std::cout << "Mean time taken: " << time_taken / reps << " microseconds" << std::endl; } return 0; } Loading
src/eval.cpp +10 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,10 @@ 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() { return 42; } inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { Loading @@ -26,6 +30,9 @@ inline int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, reinterpret_cast<const char *>(arg1), static_cast<int>(arg2), static_cast<mode_t>(arg3)); break; case SYS_getpid: *result = hook_getpid(); 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 @@ -46,7 +53,9 @@ int hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, 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); return was_hooked; } Loading
src/opendevnull.cpp +54 −26 Original line number Diff line number Diff line Loading @@ -4,11 +4,27 @@ #include <sys/syscall.h> #include <unistd.h> int main() { int main(int argc, char* argv[]) { // Check if the correct number of arguments is provided if (argc != 3) { std::cerr << "Usage: " << argv[0] << " --syscall <open|getpid>" << std::endl; return 1; } // measure time to run in microseconds std::string option = argv[1]; std::string syscall = argv[2]; double reps = 1000.0*100000.0; // Handle the --syscall option if (option == "--syscall") { if (syscall == "open") { struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); // open /dev/null 100000 times for (int j = 0; j < 1000; j++) { for (int i = 0; i < 100000; i++) { Loading @@ -20,20 +36,32 @@ int main() { clock_gettime(CLOCK_MONOTONIC, &end); double time_taken = (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_nsec - start.tv_nsec) / 1e3; std::cout << "Time taken: " << time_taken << " microseconds" << std::endl; // mean of the time for a syscall (10000000) std::cout << "Mean time taken: " << time_taken / 100000000.0 << " microseconds" std::cout << "Mean time taken: " << time_taken / reps << " microseconds" << std::endl; // Calculate single syscall () } else if (syscall == "getpid") { struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); int fd = openat(AT_FDCWD, "/dev/null", O_RDWR, 0); close(fd); for (int j = 0; j < 1000; j++) { for (int i = 0; i < 100000; i++) { int ret = getpid(); } } clock_gettime(CLOCK_MONOTONIC, &end); std::cout << "Time taken for single syscall: " << (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_nsec - start.tv_nsec) / 1e3 << " microseconds" << std::endl; double time_taken = (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_nsec - start.tv_nsec) / 1e3; std::cout << "Mean time taken: " << time_taken / reps << " microseconds" << std::endl; } return 0; }