diff --git a/capio-posix/handlers/access.hpp b/capio-posix/handlers/access.hpp index 33a312f4b..d030f31ff 100644 --- a/capio-posix/handlers/access.hpp +++ b/capio-posix/handlers/access.hpp @@ -5,9 +5,9 @@ #include "utils/filesystem.hpp" #if defined(SYS_access) -int access_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int access_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg0)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call()"); if (!is_capio_path(pathname)) { LOG("Path %s is forbidden: skip", pathname.data()); @@ -25,11 +25,10 @@ int access_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a #endif // SYS_access #if defined(SYS_faccessat) || defined(SYS_faccessat2) -int faccessat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { +inline int faccessat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto dirfd = static_cast(arg0); const std::string_view pathname(reinterpret_cast(arg1)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call()"); if (!is_capio_path(pathname)) { diff --git a/capio-posix/handlers/chdir.hpp b/capio-posix/handlers/chdir.hpp index 52f542ed7..5e01fa0cf 100644 --- a/capio-posix/handlers/chdir.hpp +++ b/capio-posix/handlers/chdir.hpp @@ -6,10 +6,9 @@ #include "utils/filesystem.hpp" -int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg0)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); - START_LOG(tid, "call(path=%s)", pathname.data()); syscall_no_intercept_flag = true; diff --git a/capio-posix/handlers/close.hpp b/capio-posix/handlers/close.hpp index d04608ecc..a03bbbd93 100644 --- a/capio-posix/handlers/close.hpp +++ b/capio-posix/handlers/close.hpp @@ -5,9 +5,9 @@ #include "utils/requests.hpp" -int close_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - int fd = static_cast(arg0); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int close_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { + const int fd = static_cast(arg0); START_LOG(tid, "call(fd=%ld)", fd); if (exists_capio_fd(fd)) { diff --git a/capio-posix/handlers/copy_file_range.hpp b/capio-posix/handlers/copy_file_range.hpp index 01e4d4fce..7669c1fb6 100644 --- a/capio-posix/handlers/copy_file_range.hpp +++ b/capio-posix/handlers/copy_file_range.hpp @@ -1,9 +1,9 @@ #ifndef CAPIO_COPY_FILE_RANGE_HPP #define CAPIO_COPY_FILE_RANGE_HPP -int copy_file_range_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int copy_file_range_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { + auto fd_in = static_cast(arg0); auto off_in = static_cast(arg1); diff --git a/capio-posix/handlers/dup.hpp b/capio-posix/handlers/dup.hpp index 17f1a371d..926dbd6ca 100644 --- a/capio-posix/handlers/dup.hpp +++ b/capio-posix/handlers/dup.hpp @@ -5,10 +5,10 @@ #include "utils/requests.hpp" #if defined(SYS_dup) -int dup_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); - int fd = static_cast(arg0); +inline int dup_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { + const int fd = static_cast(arg0); START_LOG(tid, "call(fd=%d)", fd); if (exists_capio_fd(fd)) { @@ -26,8 +26,8 @@ int dup_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5 #endif // SYS_dup #if defined(SYS_dup2) -int dup2_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int dup2_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto fd = static_cast(arg0); auto fd2 = static_cast(arg1); @@ -50,8 +50,8 @@ int dup2_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg #endif // SYS_dup2 #if defined(SYS_dup3) -int dup3_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int dup3_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { int fd = static_cast(arg0); int fd2 = static_cast(arg1); int flags = static_cast(arg2); diff --git a/capio-posix/handlers/execve.hpp b/capio-posix/handlers/execve.hpp index 47c526a70..961d877d7 100644 --- a/capio-posix/handlers/execve.hpp +++ b/capio-posix/handlers/execve.hpp @@ -5,8 +5,8 @@ #include "utils/snapshot.hpp" -int execve_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int execve_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { START_LOG(tid, "call()"); create_snapshot(tid); diff --git a/capio-posix/handlers/exit.hpp b/capio-posix/handlers/exit.hpp index c966035fc..65423c9a2 100644 --- a/capio-posix/handlers/exit.hpp +++ b/capio-posix/handlers/exit.hpp @@ -14,8 +14,8 @@ * with CAPIO */ -int exit_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int exit_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { START_LOG(tid, "call()"); syscall_no_intercept_flag = true; diff --git a/capio-posix/handlers/fchmod.hpp b/capio-posix/handlers/fchmod.hpp index cc9e926f5..95dd1de22 100644 --- a/capio-posix/handlers/fchmod.hpp +++ b/capio-posix/handlers/fchmod.hpp @@ -3,9 +3,10 @@ #if defined(SYS_chmod) || defined(SYS_fchmod) -int fchmod_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - int fd = static_cast(arg0); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int fchmod_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { + const int fd = static_cast(arg0); + START_LOG(syscall_no_intercept(SYS_gettid), "call(fd=%d)", fd); if (!exists_capio_fd(fd)) { diff --git a/capio-posix/handlers/fchown.hpp b/capio-posix/handlers/fchown.hpp index b40398c0b..bf6e9e2c8 100644 --- a/capio-posix/handlers/fchown.hpp +++ b/capio-posix/handlers/fchown.hpp @@ -4,9 +4,10 @@ #if defined(SYS_chown) || defined(SYS_fchown) -int fchown_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - int fd = static_cast(arg0); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int fchown_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { + int fd = static_cast(arg0); + START_LOG(syscall_no_intercept(SYS_gettid), "call(fd=%d)", fd); if (!exists_capio_fd(fd)) { diff --git a/capio-posix/handlers/fcntl.hpp b/capio-posix/handlers/fcntl.hpp index 2780f8856..eb912e9d1 100644 --- a/capio-posix/handlers/fcntl.hpp +++ b/capio-posix/handlers/fcntl.hpp @@ -6,12 +6,11 @@ #include "utils/requests.hpp" #if defined(SYS_fcntl) || defined(SYS_fcntl64) -int fcntl_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int fcntl_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto fd = static_cast(arg0); auto cmd = static_cast(arg1); auto arg = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); - START_LOG(tid, "call(fd=%d, cmd=%d, arg=%d)", fd, cmd, arg); if (exists_capio_fd(fd)) { diff --git a/capio-posix/handlers/fgetxattr.hpp b/capio-posix/handlers/fgetxattr.hpp index 3554d799e..3db762c6b 100644 --- a/capio-posix/handlers/fgetxattr.hpp +++ b/capio-posix/handlers/fgetxattr.hpp @@ -3,12 +3,11 @@ #if defined(SYS_fgetxattr) -int fgetxattr_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { +inline int fgetxattr_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { std::string name(reinterpret_cast(arg1)); auto *value = reinterpret_cast(arg2); auto size = static_cast(arg3); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); auto fd = static_cast(arg0); START_LOG(tid, "call(name=%s, value=0x%08x, size=%ld)", name.c_str(), value, size); diff --git a/capio-posix/handlers/fork.hpp b/capio-posix/handlers/fork.hpp index e707c0994..4d5666083 100644 --- a/capio-posix/handlers/fork.hpp +++ b/capio-posix/handlers/fork.hpp @@ -6,16 +6,17 @@ #include "utils/clone.hpp" #include "utils/requests.hpp" -int fork_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { - long parent_tid = syscall_no_intercept(SYS_gettid); +inline int fork_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { + long parent_tid = tid; auto pid = static_cast(syscall_no_intercept(SYS_fork)); START_LOG(parent_tid, "call(pid=%ld)", pid); if (pid == 0) { // child - const auto child_tid = static_cast(syscall_no_intercept(SYS_gettid)); - init_process(child_tid); + capio_current_thread_id = static_cast(syscall_no_intercept(SYS_gettid)); + init_process(capio_current_thread_id); *result = 0; return posix_return_value(0, result); } diff --git a/capio-posix/handlers/getcwd.hpp b/capio-posix/handlers/getcwd.hpp index 2431d73ed..ecf61ea59 100644 --- a/capio-posix/handlers/getcwd.hpp +++ b/capio-posix/handlers/getcwd.hpp @@ -3,11 +3,12 @@ #if defined(SYS_getcwd) -int getcwd_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int getcwd_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto buf = reinterpret_cast(arg0); auto size = static_cast(arg1); - START_LOG(syscall_no_intercept(SYS_gettid), "call(buf=0x%08x, size=%ld)", buf, size); + START_LOG(tid, "call(buf=0x%08x, size=%ld)", buf, size); return CAPIO_POSIX_SYSCALL_SKIP; } diff --git a/capio-posix/handlers/ioctl.hpp b/capio-posix/handlers/ioctl.hpp index 86d192f7d..9daf638f2 100644 --- a/capio-posix/handlers/ioctl.hpp +++ b/capio-posix/handlers/ioctl.hpp @@ -3,10 +3,10 @@ #if defined(SYS_ioctl) -int ioctl_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int ioctl_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto fd = static_cast(arg0); auto request = static_cast(arg1); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call(fd=%d, request=%ld)", fd, request, tid); if (exists_capio_fd(fd)) { diff --git a/capio-posix/handlers/lseek.hpp b/capio-posix/handlers/lseek.hpp index 814dd6b4d..da94e6f3c 100644 --- a/capio-posix/handlers/lseek.hpp +++ b/capio-posix/handlers/lseek.hpp @@ -5,11 +5,11 @@ #include "utils/common.hpp" -int lseek_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int lseek_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { int fd = static_cast(arg0); auto offset = static_cast(arg1); int whence = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call(fd=%d, offset=%ld, whence=%d)", fd, offset, whence); if (exists_capio_fd(fd)) { diff --git a/capio-posix/handlers/mkdir.hpp b/capio-posix/handlers/mkdir.hpp index c7303f958..1ad80d5ce 100644 --- a/capio-posix/handlers/mkdir.hpp +++ b/capio-posix/handlers/mkdir.hpp @@ -44,31 +44,30 @@ inline off64_t capio_rmdir(const std::string_view &pathname, pid_t tid) { } #if defined(SYS_mkdir) -int mkdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int mkdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg0)); auto mode = static_cast(arg1); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_mkdirat(AT_FDCWD, pathname, mode, tid), result); } #endif // SYS_mkdir #if defined(SYS_mkdirat) -int mkdirat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { +inline int mkdirat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { int dirfd = static_cast(arg0); const std::string_view pathname(reinterpret_cast(arg1)); auto mode = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_mkdirat(dirfd, pathname, mode, tid), result); } #endif // SYS_mkdirat #if defined(SYS_rmdir) -int rmdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int rmdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg0)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_rmdir(pathname, tid), result); } diff --git a/capio-posix/handlers/open.hpp b/capio-posix/handlers/open.hpp index 4038b1fe5..dd65e8d3c 100644 --- a/capio-posix/handlers/open.hpp +++ b/capio-posix/handlers/open.hpp @@ -4,7 +4,7 @@ #include "utils/common.hpp" #include "utils/filesystem.hpp" -std::string compute_abs_path(char *pathname, int dirfd) { +inline std::string compute_abs_path(char *pathname, int dirfd) { START_LOG(syscall_no_intercept(SYS_gettid), "call(pathname=%s, dirfd=%d)", pathname, dirfd); std::filesystem::path path(pathname); if (path.is_relative()) { @@ -33,9 +33,9 @@ std::string compute_abs_path(char *pathname, int dirfd) { } #if defined(SYS_creat) -int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { std::string pathname(reinterpret_cast(arg0)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); int flags = O_CREAT | O_WRONLY | O_TRUNC; mode_t mode = static_cast(arg2); START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode); @@ -71,11 +71,11 @@ int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar #endif // SYS_creat #if defined(SYS_open) -int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { std::string pathname(reinterpret_cast(arg0)); int flags = static_cast(arg1); mode_t mode = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode); std::string path = compute_abs_path(pathname.data(), -1); @@ -112,12 +112,13 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg #endif // SYS_open #if defined(SYS_openat) -int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { int dirfd = static_cast(arg0); std::string pathname(reinterpret_cast(arg1)); int flags = static_cast(arg2); mode_t mode = static_cast(arg3); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); + START_LOG(tid, "call(dirfd=%ld, path=%s, flags=%d, mode=%d)", dirfd, pathname.data(), flags, mode); diff --git a/capio-posix/handlers/read.hpp b/capio-posix/handlers/read.hpp index 684d9f8da..43f38e7df 100644 --- a/capio-posix/handlers/read.hpp +++ b/capio-posix/handlers/read.hpp @@ -16,15 +16,15 @@ inline off64_t capio_read_fs(int fd, size_t count, pid_t tid) { return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } -inline off64_t capio_read_mem(int fd, size_t count, void *buffer, long *result) { - START_LOG(capio_syscall(SYS_gettid), "call(fd=%d, count=%ld)", fd, count); +inline off64_t capio_read_mem(int fd, size_t count, void *buffer, long *result, pid_t tid) { + START_LOG(tid, "call(fd=%d, count=%ld)", fd, count); if (exists_capio_fd(fd)) { const auto computed_offset = get_capio_fd_offset(fd) + count; LOG("Handling read on file %s up to byte %ld", get_capio_fd_path(fd).c_str(), computed_offset); - const auto res = read_request_cache_mem->read(fd, buffer, count); + const auto res = read_request_cache_mem->read(fd, buffer, count, tid); LOG("Result of read is %lu", res); return posix_return_value(res, result); } @@ -32,16 +32,16 @@ inline off64_t capio_read_mem(int fd, size_t count, void *buffer, long *result) } #if defined(SYS_read) -int read_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +int read_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { int fd = static_cast(arg0); auto count = static_cast(arg2); auto buffer = reinterpret_cast(arg1); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); - START_LOG(capio_syscall(SYS_gettid), "call(fd=%d, tid=%d, count=%ld)", fd, tid, count); + START_LOG(tid, "call(fd=%d, tid=%d, count=%ld)", fd, tid, count); if (exists_capio_fd(fd)) { auto read_result = store_file_in_memory(get_capio_fd_path(fd), tid) - ? capio_read_mem(fd, count, buffer, result) + ? capio_read_mem(fd, count, buffer, result, tid) : capio_read_fs(fd, count, tid); LOG("read result: %ld", read_result); @@ -53,10 +53,10 @@ int read_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg #endif // SYS_read #if defined(SYS_readv) -int readv_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +int readv_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { auto fd = static_cast(arg0); auto iovcnt = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); if (exists_capio_fd(fd)) { auto computed_offset = get_capio_fd_offset(fd) + iovcnt * sizeof(iovec); diff --git a/capio-posix/handlers/rename.hpp b/capio-posix/handlers/rename.hpp index 4c61e8a5d..4b02979f0 100644 --- a/capio-posix/handlers/rename.hpp +++ b/capio-posix/handlers/rename.hpp @@ -5,10 +5,11 @@ #include "utils/filesystem.hpp" -int rename_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +int rename_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { std::filesystem::path oldpath(reinterpret_cast(arg0)); std::filesystem::path newpath(reinterpret_cast(arg1)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); + START_LOG(tid, "call(oldpath=%s, newpath=%s)", oldpath.c_str(), newpath.c_str()); LOG("Compute paths"); auto oldpath_abs = capio_absolute(oldpath); diff --git a/capio-posix/handlers/stat.hpp b/capio-posix/handlers/stat.hpp index a7f9028cb..3c63c75a6 100644 --- a/capio-posix/handlers/stat.hpp +++ b/capio-posix/handlers/stat.hpp @@ -88,43 +88,42 @@ inline int capio_fstatat(int dirfd, const std::string_view &pathname, struct sta } #if defined(SYS_fstat) || defined(SYS_fstat64) -int fstat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int fstat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto fd = static_cast(arg0); auto *buf = reinterpret_cast(arg1); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_fstat(fd, buf, tid), result); } #endif // SYS_fstat || SYS_fstat64 #if defined(SYS_fstatat) || defined(SYS_newfstatat) || defined(SYS_fstatat64) -int fstatat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { +inline int fstatat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto dirfd = static_cast(arg0); const std::string_view pathname(reinterpret_cast(arg1)); auto *statbuf = reinterpret_cast(arg2); auto flags = static_cast(arg3); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_fstatat(dirfd, pathname, statbuf, flags, tid), result); } #endif // SYS_fstatat || SYS_newfstatat || SYS_fstatat64 #if defined(SYS_lstat) || defined(SYS_lstat64) -int lstat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int lstat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg0)); auto *buf = reinterpret_cast(arg1); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_lstat_wrapper(pathname, buf, tid), result); } #endif // SYS_lstat || SYS_lstat64 #if defined(SYS_stat) || defined(SYS_stat64) -int stat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int stat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg0)); auto *buf = reinterpret_cast(arg1); - long tid = syscall_no_intercept(SYS_gettid); return posix_return_value(capio_lstat_wrapper(pathname, buf, tid), result); } diff --git a/capio-posix/handlers/statfs.hpp b/capio-posix/handlers/statfs.hpp index 7c4488ff3..ebed261f0 100644 --- a/capio-posix/handlers/statfs.hpp +++ b/capio-posix/handlers/statfs.hpp @@ -3,10 +3,9 @@ #if defined(SYS_fstatfs) || defined(SYS_fstatfs64) -int fstatfs_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { - auto fd = static_cast(arg0); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); +inline int fstatfs_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { + auto fd = static_cast(arg0); START_LOG(tid, "call(fd=%d)", fd); diff --git a/capio-posix/handlers/statx.hpp b/capio-posix/handlers/statx.hpp index ba7d5bc2c..c0a098ec0 100644 --- a/capio-posix/handlers/statx.hpp +++ b/capio-posix/handlers/statx.hpp @@ -20,13 +20,13 @@ inline int capio_statx(int dirfd, const std::string_view &pathname, int flags, i return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } -int statx_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +int statx_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result, + const pid_t tid) { auto dirfd = static_cast(arg0); const std::string_view pathname(reinterpret_cast(arg1)); auto flags = static_cast(arg2); auto mask = static_cast(arg3); auto *buf = reinterpret_cast(arg4); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); return posix_return_value(capio_statx(dirfd, pathname, flags, mask, buf, tid), result); } diff --git a/capio-posix/handlers/unlink.hpp b/capio-posix/handlers/unlink.hpp index 58e5cbba1..93f497137 100644 --- a/capio-posix/handlers/unlink.hpp +++ b/capio-posix/handlers/unlink.hpp @@ -4,9 +4,9 @@ #include "utils/common.hpp" #if defined(SYS_unlink) -int unlink_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int unlink_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { std::string_view pathname(reinterpret_cast(arg0)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call(path=%s)", pathname.data()); @@ -20,10 +20,9 @@ int unlink_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a #endif // SYS_unlink #if defined(SYS_unlinkat) -int unlinkat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { +inline int unlinkat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { const std::string_view pathname(reinterpret_cast(arg1)); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call(path=%s)", pathname.data()); auto path = capio_posix_realpath(pathname); diff --git a/capio-posix/handlers/write.hpp b/capio-posix/handlers/write.hpp index 6d2aa6702..aeb97a0b6 100644 --- a/capio-posix/handlers/write.hpp +++ b/capio-posix/handlers/write.hpp @@ -27,11 +27,12 @@ inline off64_t capio_write_mem(int fd, char *buffer, capio_off64_t count, pid_t } #if defined(SYS_write) -int write_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int write_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto fd = static_cast(arg0); auto buffer = reinterpret_cast(arg1); auto count = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); + START_LOG(tid, "call(fd=%d, buffer=%p, count=%ld, id=%ld)", fd, buffer, count, tid); if (!exists_capio_fd(fd)) { LOG("FD %d is not handled by capio... skipping syscall", fd); @@ -49,11 +50,12 @@ int write_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar #endif // SYS_write #if defined(SYS_writev) -int writev_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) { +inline int writev_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, + long *result, const pid_t tid) { auto fd = static_cast(arg0); auto io_vec = reinterpret_cast(arg1); auto iovcnt = static_cast(arg2); - long tid = syscall_no_intercept(SYS_gettid); + START_LOG(tid, "call(fd=%d, buffer=%p, count=%ld, pid=%ld)", fd, io_vec->iov_base, io_vec->iov_len, tid); if (!exists_capio_fd(fd)) { diff --git a/capio-posix/libcapio_posix.cpp b/capio-posix/libcapio_posix.cpp index 57ad15ce2..4b8e48062 100644 --- a/capio-posix/libcapio_posix.cpp +++ b/capio-posix/libcapio_posix.cpp @@ -3,10 +3,11 @@ * if -1, and capio logging is enable everything is logged, otherwise, only * logs up to CAPIO_MAX_LOG_LEVEL function calls */ - #include #include +thread_local pid_t capio_current_thread_id = -1; + #include "capio/syscall.hpp" #include "utils/clone.hpp" @@ -19,7 +20,7 @@ * Handler for syscall not handled and interrupt syscall_intercept */ static int not_handled_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { + long *result, pid_t pid) { return 1; } @@ -28,7 +29,7 @@ static int not_handled_handler(long arg0, long arg1, long arg2, long arg3, long * syscall_intercept */ static int not_implemented_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { + long *result, pid_t pid) { errno = ENOTSUP; *result = -errno; return 0; @@ -383,6 +384,10 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, } #endif + if (syscall_number == SYS_vfork) { + return 0; + } + // If the flag is set to true, CAPIO will not // intercept the system calls if (syscall_no_intercept_flag) { @@ -395,6 +400,17 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, START_LOG(syscall_no_intercept(SYS_gettid), "call(syscall_number=%ld)", syscall_number); + if (syscall_number == SYS_clone) { + std::string flags; + APPEND_CLONE_FLAGS(flags, arg0); + APPEND_CLONE_FLAGS(flags, arg1); + APPEND_CLONE_FLAGS(flags, arg2); + APPEND_CLONE_FLAGS(flags, arg3); + APPEND_CLONE_FLAGS(flags, arg4); + APPEND_CLONE_FLAGS(flags, arg5); + LOG("clone flags = %s", flags.c_str()); + } + // If the syscall_number is higher than the maximum // syscall captured by CAPIO, simply return if (syscall_number >= CAPIO_NR_SYSCALLS) { @@ -410,7 +426,8 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, LOG("Handling syscall NO %ld (max num is %ld)", syscall_number, CAPIO_NR_SYSCALLS); try { - return syscallTable[syscall_number](arg0, arg1, arg2, arg3, arg4, arg5, result); + return syscallTable[syscall_number](arg0, arg1, arg2, arg3, arg4, arg5, result, + capio_current_thread_id); } catch (const std::exception &exception) { syscall_no_intercept_flag = true; @@ -455,7 +472,7 @@ static register_capio_tid(tid); // TODO: use var to set cache size - init_caches(); + init_caches(tid); intercept_hook_point_clone_child = hook_clone_child; intercept_hook_point_clone_parent = hook_clone_parent; diff --git a/capio-posix/syscall_intercept/CMakeLists.txt b/capio-posix/syscall_intercept/CMakeLists.txt index 6215c0dde..2e2f72284 100644 --- a/capio-posix/syscall_intercept/CMakeLists.txt +++ b/capio-posix/syscall_intercept/CMakeLists.txt @@ -15,7 +15,7 @@ include(ExternalProject) ##################################### ExternalProject_Add(syscall_intercept GIT_REPOSITORY https://github.com/alpha-unito/syscall_intercept.git - GIT_TAG b05ff8037de2eb7b44dfb7fa372cfe08d565ba84 + GIT_TAG 35f494a078de327a2d488d49f0e02ee506dd78dd PREFIX ${CMAKE_CURRENT_BINARY_DIR} CMAKE_ARGS -DSTATIC_CAPSTONE=ON diff --git a/capio-posix/utils/cache.hpp b/capio-posix/utils/cache.hpp index 67e07977f..d01e01a16 100644 --- a/capio-posix/utils/cache.hpp +++ b/capio-posix/utils/cache.hpp @@ -15,13 +15,13 @@ inline thread_local WriteRequestCacheFS *write_request_cache_fs; inline thread_local WriteRequestCacheMEM *write_request_cache_mem; inline thread_local ReadRequestCacheMEM *read_request_cache_mem; -inline void init_caches() { +inline void init_caches(pid_t tid) { START_LOG(capio_syscall(SYS_gettid), "call()"); write_request_cache_fs = new WriteRequestCacheFS(); read_request_cache_fs = new ReadRequestCacheFS(); consent_request_cache_fs = new ConsentRequestCache(); write_request_cache_mem = new WriteRequestCacheMEM(); - read_request_cache_mem = new ReadRequestCacheMEM(); + read_request_cache_mem = new ReadRequestCacheMEM(tid); } inline void delete_caches() { diff --git a/capio-posix/utils/cache/consent_request_cache.hpp b/capio-posix/utils/cache/consent_request_cache.hpp index 54a8d6c83..8b7f130ec 100644 --- a/capio-posix/utils/cache/consent_request_cache.hpp +++ b/capio-posix/utils/cache/consent_request_cache.hpp @@ -8,8 +8,8 @@ class ConsentRequestCache { static capio_off64_t _consent_to_proceed_request(const std::filesystem::path &path, const long tid, const std::string &source_func) { - START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld, source_func=%s)", path.c_str(), - tid, source_func.c_str()); + START_LOG(tid, "call(path=%s, tid=%ld, source_func=%s)", path.c_str(), tid, + source_func.c_str()); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld %s %s", CAPIO_REQUEST_CONSENT, tid, path.c_str(), source_func.c_str()); @@ -25,14 +25,13 @@ class ConsentRequestCache { }; ~ConsentRequestCache() { - START_LOG(capio_syscall(SYS_gettid), "call()"); + START_LOG(capio_current_thread_id, "call()"); delete available_consent; }; void consent_request(const std::filesystem::path &path, long tid, const std::string &source_func) const { - START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld, source=%s)", path.c_str(), tid, - source_func.c_str()); + START_LOG(tid, "call(path=%s, tid=%ld, source=%s)", path.c_str(), tid, source_func.c_str()); const auto resolved_path = resolve_possible_symlink(path); diff --git a/capio-posix/utils/cache/read_request_cache_fs.hpp b/capio-posix/utils/cache/read_request_cache_fs.hpp index a82130a40..ea01f778d 100644 --- a/capio-posix/utils/cache/read_request_cache_fs.hpp +++ b/capio-posix/utils/cache/read_request_cache_fs.hpp @@ -11,8 +11,8 @@ class ReadRequestCacheFS { // return amount of readable bytes static capio_off64_t _read_request(const std::filesystem::path &path, const off64_t end_of_Read, const long tid, const long fd) { - START_LOG(capio_syscall(SYS_gettid), "call(path=%s, end_of_Read=%ld, tid=%ld, fd=%ld)", - path.c_str(), end_of_Read, tid, fd); + START_LOG(tid, "call(path=%s, end_of_Read=%ld, tid=%ld, fd=%ld)", path.c_str(), end_of_Read, + tid, fd); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld %ld %s %ld", CAPIO_REQUEST_READ, tid, fd, path.c_str(), end_of_Read); LOG("Sending read request %s", req); @@ -28,13 +28,13 @@ class ReadRequestCacheFS { }; ~ReadRequestCacheFS() { - START_LOG(capio_syscall(SYS_gettid), "call()"); + START_LOG(capio_current_thread_id, "call()"); delete available_read_cache; }; void read_request(std::filesystem::path path, const long end_of_read, int tid, const int fd) { - START_LOG(capio_syscall(SYS_gettid), "[cache] call(path=%s, end_of_read=%ld, tid=%ld)", - path.c_str(), end_of_read, tid); + START_LOG(tid, "[cache] call(path=%s, end_of_read=%ld, tid=%ld)", path.c_str(), end_of_read, + tid); if (fd != current_fd || path.compare(current_path) != 0) { LOG("[cache] %s changed from previous state. updating", fd != current_fd ? "File descriptor" : "File path"); diff --git a/capio-posix/utils/cache/read_request_cache_mem.hpp b/capio-posix/utils/cache/read_request_cache_mem.hpp index 5fbc8da8d..f027d9846 100644 --- a/capio-posix/utils/cache/read_request_cache_mem.hpp +++ b/capio-posix/utils/cache/read_request_cache_mem.hpp @@ -14,8 +14,8 @@ class ReadRequestCacheMEM { * @param buffer * @param count */ - void _read(void *buffer, capio_off64_t count) { - START_LOG(capio_syscall(SYS_gettid), "call(count=%ld)", count); + void _read(void *buffer, capio_off64_t count, pid_t tid) { + START_LOG(tid, "call(count=%ld)", count); if (count > 0) { memcpy(buffer, _cache + _cache_offset, count); @@ -27,8 +27,8 @@ class ReadRequestCacheMEM { protected: [[nodiscard]] capio_off64_t read_request(const int fd, const capio_off64_t count, const long tid, bool use_cache = true) { - START_LOG(capio_syscall(SYS_gettid), "call(fd=%ld, count=%llu, tid=%ld, load_data=%s)", fd, - count, tid, use_cache ? "true" : "false"); + START_LOG(tid, "call(fd=%ld, count=%llu, tid=%ld, load_data=%s)", fd, count, tid, + use_cache ? "true" : "false"); char req[CAPIO_REQ_MAX_SIZE]; // send as the last parameter to the server the maximum amount of data that can be read into @@ -65,19 +65,19 @@ class ReadRequestCacheMEM { } public: - explicit ReadRequestCacheMEM(const long line_size = get_posix_read_cache_line_size()) - : _cache(nullptr), _tid(capio_syscall(SYS_gettid)), _fd(-1), _max_line_size(line_size), - _actual_size(0), _cache_offset(0), _last_read_end(-1) { + explicit ReadRequestCacheMEM(pid_t tid, const long line_size = get_posix_read_cache_line_size()) + : _cache(nullptr), _tid(tid), _fd(-1), _max_line_size(line_size), _actual_size(0), + _cache_offset(0), _last_read_end(-1) { _cache = new char[_max_line_size]; } ~ReadRequestCacheMEM() { - START_LOG(capio_syscall(SYS_gettid), "call()"); + START_LOG(capio_current_thread_id, "call()"); delete[] _cache; } void flush() { - START_LOG(capio_syscall(SYS_gettid), "call()"); + START_LOG(capio_current_thread_id, "call()"); if (_cache_offset != _actual_size) { _actual_size = _cache_offset = 0; } @@ -85,8 +85,8 @@ class ReadRequestCacheMEM { _real_file_size_commmitted = -1; } - long read(const int fd, void *buffer, capio_off64_t count) { - START_LOG(capio_syscall(SYS_gettid), "call(fd=%d, count=%ld)", fd, count); + long read(const int fd, void *buffer, capio_off64_t count, pid_t tid) { + START_LOG(tid, "call(fd=%d, count=%ld)", fd, count); long actual_read_size = 0; @@ -137,7 +137,7 @@ class ReadRequestCacheMEM { if (count <= _max_line_size - _cache_offset) { // There is enough data to perform a read LOG("The requested amount of data can be served without performing a request"); - _read(buffer, count); + _read(buffer, count, tid); actual_read_size = count; _last_read_end = get_capio_fd_offset(_fd) + count; set_capio_fd_offset(fd, _last_read_end); @@ -152,7 +152,7 @@ class ReadRequestCacheMEM { " std::min(_actual_size(%llu) - _cache_offset(%llu), count(%llu) = %ld", _actual_size, _cache_offset, count, first_copy_size); - _read(buffer, first_copy_size); + _read(buffer, first_copy_size, tid); _last_read_end = get_capio_fd_offset(_fd) + first_copy_size; set_capio_fd_offset(fd, get_capio_fd_offset(fd) + first_copy_size); actual_read_size = first_copy_size; @@ -178,7 +178,7 @@ class ReadRequestCacheMEM { remaining_size < _actual_size ? remaining_size : _actual_size; LOG("Sending %ld of data to posix application", size_to_send_to_client); - _read(static_cast(buffer) + copy_offset, size_to_send_to_client); + _read(static_cast(buffer) + copy_offset, size_to_send_to_client, tid); actual_read_size += size_to_send_to_client; LOG("actual_read_size incremented to: %ld", actual_read_size); diff --git a/capio-posix/utils/clone.hpp b/capio-posix/utils/clone.hpp index 650ddc317..07f89bb20 100644 --- a/capio-posix/utils/clone.hpp +++ b/capio-posix/utils/clone.hpp @@ -31,6 +31,56 @@ inline void remove_capio_tid(const pid_t tid) { } } +#define APPEND_CLONE_FLAGS(str, val) \ + do { \ + if ((val) & CLONE_VM) \ + (str) += "CLONE_VM "; \ + if ((val) & CLONE_FS) \ + (str) += "CLONE_FS "; \ + if ((val) & CLONE_FILES) \ + (str) += "CLONE_FILES "; \ + if ((val) & CLONE_SIGHAND) \ + (str) += "CLONE_SIGHAND "; \ + if ((val) & CLONE_PTRACE) \ + (str) += "CLONE_PTRACE "; \ + if ((val) & CLONE_VFORK) \ + (str) += "CLONE_VFORK "; \ + if ((val) & CLONE_PARENT) \ + (str) += "CLONE_PARENT "; \ + if ((val) & CLONE_THREAD) \ + (str) += "CLONE_THREAD "; \ + if ((val) & CLONE_NEWNS) \ + (str) += "CLONE_NEWNS "; \ + if ((val) & CLONE_SYSVSEM) \ + (str) += "CLONE_SYSVSEM "; \ + if ((val) & CLONE_SETTLS) \ + (str) += "CLONE_SETTLS "; \ + if ((val) & CLONE_PARENT_SETTID) \ + (str) += "CLONE_PARENT_SETTID "; \ + if ((val) & CLONE_CHILD_CLEARTID) \ + (str) += "CLONE_CHILD_CLEARTID "; \ + if ((val) & CLONE_DETACHED) \ + (str) += "CLONE_DETACHED "; \ + if ((val) & CLONE_UNTRACED) \ + (str) += "CLONE_UNTRACED "; \ + if ((val) & CLONE_CHILD_SETTID) \ + (str) += "CLONE_CHILD_SETTID "; \ + if ((val) & CLONE_NEWCGROUP) \ + (str) += "CLONE_NEWCGROUP "; \ + if ((val) & CLONE_NEWUTS) \ + (str) += "CLONE_NEWUTS "; \ + if ((val) & CLONE_NEWIPC) \ + (str) += "CLONE_NEWIPC "; \ + if ((val) & CLONE_NEWUSER) \ + (str) += "CLONE_NEWUSER "; \ + if ((val) & CLONE_NEWPID) \ + (str) += "CLONE_NEWPID "; \ + if ((val) & CLONE_NEWNET) \ + (str) += "CLONE_NEWNET "; \ + if ((val) & CLONE_IO) \ + (str) += "CLONE_IO "; \ + } while (0) + inline void init_threading_support() { tids = new std::unordered_set{}; } inline void init_process(pid_t tid) { @@ -94,7 +144,7 @@ inline void hook_clone_child() { init_process(tid); LOG("Child thread %d initialized", tid); LOG("Starting child thread %d", tid); - init_caches(); + init_caches(tid); #ifdef __CAPIO_POSIX syscall_no_intercept_flag = false; #endif diff --git a/capio-posix/utils/requests.hpp b/capio-posix/utils/requests.hpp index 1e7dd531d..739e7fcb8 100644 --- a/capio-posix/utils/requests.hpp +++ b/capio-posix/utils/requests.hpp @@ -38,7 +38,7 @@ inline void init_client() { * @param app_name */ inline void handshake_request(const long tid, const long pid, const std::string &app_name) { - START_LOG(capio_syscall(SYS_gettid), "call(tid=%ld, pid=%ld, app_name=%s)", tid, pid, + START_LOG(tid, "call(tid=%ld, pid=%ld, app_name=%s)", tid, pid, app_name.c_str()); cts_queue = new SPSCQueue("queue-" + std::to_string(tid) + ".cts", get_cache_lines(), @@ -64,7 +64,7 @@ inline void handshake_request(const long tid, const long pid, const std::string * @return */ inline std::vector *file_in_memory_request(const long pid) { - START_LOG(capio_syscall(SYS_gettid), "call(pid=%ld)", pid); + START_LOG(pid, "call(pid=%ld)", pid); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld ", CAPIO_REQUEST_QUERY_MEM_FILE, pid); @@ -96,7 +96,7 @@ inline std::vector *file_in_memory_request(const long pid) { inline capio_off64_t posix_directory_committed_request(const long pid, const std::filesystem::path &path, char *token_path) { - START_LOG(capio_syscall(SYS_gettid), "call(path=%s)", path.c_str()); + START_LOG(pid, "call(path=%s)", path.c_str()); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld %s ", CAPIO_REQUEST_POSIX_DIR_COMMITTED, pid, path.c_str()); @@ -111,17 +111,17 @@ inline capio_off64_t posix_directory_committed_request(const long pid, } // non blocking -inline void close_request(const std::filesystem::path &path, const long tid) { - START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld)", path.c_str(), tid); +inline void close_request(const std::filesystem::path &path, pid_t tid) { + START_LOG(tid, "call(path=%s, tid=%ld)", path.c_str(), tid); write_request_cache_fs->flush(tid); char req[CAPIO_REQ_MAX_SIZE]; - sprintf(req, "%04d %ld %s", CAPIO_REQUEST_CLOSE, tid, path.c_str()); + sprintf(req, "%04d %d %s", CAPIO_REQUEST_CLOSE, tid, path.c_str()); buf_requests->write(req, CAPIO_REQ_MAX_SIZE); } // non blocking inline void create_request(const int fd, const std::filesystem::path &path, const long tid) { - START_LOG(capio_syscall(SYS_gettid), "call(fd=%ld, path=%s, tid=%ld)", fd, path.c_str(), tid); + START_LOG(tid, "call(fd=%ld, path=%s, tid=%ld)", fd, path.c_str(), tid); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld %d %s", CAPIO_REQUEST_CREATE, tid, fd, path.c_str()); buf_requests->write(req, CAPIO_REQ_MAX_SIZE); @@ -129,7 +129,7 @@ inline void create_request(const int fd, const std::filesystem::path &path, cons // non blocking inline void exit_group_request(const long tid) { - START_LOG(capio_syscall(SYS_gettid), "call(tid=%ld)", tid); + START_LOG(tid, "call(tid=%ld)", tid); write_request_cache_fs->flush(tid); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld", CAPIO_REQUEST_EXIT_GROUP, tid); @@ -139,7 +139,7 @@ inline void exit_group_request(const long tid) { // block until open is possible [[nodiscard]] inline capio_off64_t open_request(const int fd, const std::filesystem::path &path, const long tid) { - START_LOG(capio_syscall(SYS_gettid), "call(fd=%ld, path=%s, tid=%ld)", fd, path.c_str(), tid); + START_LOG(tid, "call(fd=%ld, path=%s, tid=%ld)", fd, path.c_str(), tid); write_request_cache_fs->flush(tid); char req[CAPIO_REQ_MAX_SIZE]; @@ -153,7 +153,7 @@ inline void exit_group_request(const long tid) { // non blocking inline void rename_request(const std::filesystem::path &old_path, const std::filesystem::path &new_path, const long tid) { - START_LOG(capio_syscall(SYS_gettid), "call(old=%s, new=%s, tid=%ld)", old_path.c_str(), + START_LOG(tid, "call(old=%s, new=%s, tid=%ld)", old_path.c_str(), new_path.c_str(), tid); char req[CAPIO_REQ_MAX_SIZE]; sprintf(req, "%04d %ld %s %s", CAPIO_REQUEST_RENAME, tid, old_path.c_str(), new_path.c_str()); diff --git a/capio-posix/utils/types.hpp b/capio-posix/utils/types.hpp index ba0e6e3a6..a51c8c708 100644 --- a/capio-posix/utils/types.hpp +++ b/capio-posix/utils/types.hpp @@ -13,6 +13,6 @@ typedef std::unordered_map *> CPBufResponse_ typedef std::unordered_map CPFileDescriptors_t; typedef std::unordered_map> CPFilesPaths_t; -typedef int (*CPHandler_t)(long, long, long, long, long, long, long *); +typedef int (*CPHandler_t)(long, long, long, long, long, long, long *, pid_t); #endif // CAPIO_POSIX_UTILS_TYPES_HPP \ No newline at end of file diff --git a/capio-tests/unit/server/src/CapioCacheSPSCQueueTests.hpp b/capio-tests/unit/server/src/CapioCacheSPSCQueueTests.hpp index f65f8f385..b42f3d552 100644 --- a/capio-tests/unit/server/src/CapioCacheSPSCQueueTests.hpp +++ b/capio-tests/unit/server/src/CapioCacheSPSCQueueTests.hpp @@ -40,7 +40,7 @@ std::string test_file_name = "test.dat"; void init_server_data_structures() { writeCache = new WriteRequestCacheMEM(); - readCache = new ReadRequestCacheMEM(); + readCache = new ReadRequestCacheMEM(gettid()); bufs_response = new std::unordered_map(); files = new CPFiles_t(); capio_files_descriptors = new CPFileDescriptors_t(); @@ -298,7 +298,7 @@ TEST(CapioCacheSPSCQueue, TestReadCacheWithSpscQueueRead) { } }); - readCache->read(test_fd, tmp_buf->get(), long_test_length); + readCache->read(test_fd, tmp_buf->get(), long_test_length, gettid()); auto result = strncmp(SOURCE_TEST_TEXT, tmp_buf->get(), long_test_length); EXPECT_EQ(result, 0); server_thread.join(); @@ -348,7 +348,7 @@ TEST(CapioCacheSPSCQueue, TestReadCacheWithSpscQueueReadWithCapioFile) { } }); - readCache->read(test_fd, tmp_buf->get(), long_test_length); + readCache->read(test_fd, tmp_buf->get(), long_test_length, gettid()); auto result = strncmp(SOURCE_TEST_TEXT, tmp_buf->get(), long_test_length); EXPECT_EQ(result, 0); server_thread.join(); @@ -407,7 +407,7 @@ TEST(CapioCacheSPSCQueue, TestReadCacheWithSpscQueueReadWithCapioFileAndSeek) { auto tmp_buf_ptr = tmp_buf->get(); - readCache->read(test_fd, tmp_buf_ptr, 1000); + readCache->read(test_fd, tmp_buf_ptr, 1000, gettid()); EXPECT_EQ(strncmp(SOURCE_TEST_TEXT, tmp_buf->get(), 1000), 0); // emulate seek @@ -415,7 +415,7 @@ TEST(CapioCacheSPSCQueue, TestReadCacheWithSpscQueueReadWithCapioFileAndSeek) { set_capio_fd_offset(test_fd, new_offset); tmp_buf_ptr += new_offset; - readCache->read(test_fd, tmp_buf_ptr, 1000); + readCache->read(test_fd, tmp_buf_ptr, 1000, gettid()); // checkStringEquality(SOURCE_TEST_TEXT + new_offset, tmp_buf->get() + new_offset); EXPECT_EQ(strncmp(SOURCE_TEST_TEXT + new_offset, tmp_buf->get() + new_offset, 1000), 0); diff --git a/capio-tests/unit/server/src/main.cpp b/capio-tests/unit/server/src/main.cpp index d1e53045d..7899efa06 100644 --- a/capio-tests/unit/server/src/main.cpp +++ b/capio-tests/unit/server/src/main.cpp @@ -2,6 +2,7 @@ #include #define syscall_no_intercept syscall +pid_t capio_current_thread_id = gettid(); std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME;