Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions capio-posix/handlers/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(arg0));
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
START_LOG(tid, "call()");
if (!is_capio_path(pathname)) {
LOG("Path %s is forbidden: skip", pathname.data());
Expand All @@ -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<int>(arg0);
const std::string_view pathname(reinterpret_cast<const char *>(arg1));
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
START_LOG(tid, "call()");

if (!is_capio_path(pathname)) {
Expand Down
5 changes: 2 additions & 3 deletions capio-posix/handlers/chdir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(arg0));
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

START_LOG(tid, "call(path=%s)", pathname.data());

syscall_no_intercept_flag = true;
Expand Down
6 changes: 3 additions & 3 deletions capio-posix/handlers/close.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(arg0);
auto tid = static_cast<pid_t>(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<int>(arg0);
START_LOG(tid, "call(fd=%ld)", fd);

if (exists_capio_fd(fd)) {
Expand Down
6 changes: 3 additions & 3 deletions capio-posix/handlers/copy_file_range.hpp
Original file line number Diff line number Diff line change
@@ -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<pid_t>(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<int>(arg0);
auto off_in = static_cast<capio_off64_t>(arg1);

Expand Down
14 changes: 7 additions & 7 deletions capio-posix/handlers/dup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pid_t>(syscall_no_intercept(SYS_gettid));
int fd = static_cast<int>(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<int>(arg0);
START_LOG(tid, "call(fd=%d)", fd);

if (exists_capio_fd(fd)) {
Expand All @@ -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<pid_t>(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<int>(arg0);
auto fd2 = static_cast<int>(arg1);

Expand All @@ -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<pid_t>(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<int>(arg0);
int fd2 = static_cast<int>(arg1);
int flags = static_cast<int>(arg2);
Expand Down
4 changes: 2 additions & 2 deletions capio-posix/handlers/execve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pid_t>(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);
Expand Down
4 changes: 2 additions & 2 deletions capio-posix/handlers/exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pid_t>(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;
Expand Down
7 changes: 4 additions & 3 deletions capio-posix/handlers/fchmod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(arg0);
auto tid = static_cast<pid_t>(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<int>(arg0);

START_LOG(syscall_no_intercept(SYS_gettid), "call(fd=%d)", fd);

if (!exists_capio_fd(fd)) {
Expand Down
7 changes: 4 additions & 3 deletions capio-posix/handlers/fchown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(arg0);
auto tid = static_cast<pid_t>(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<int>(arg0);

START_LOG(syscall_no_intercept(SYS_gettid), "call(fd=%d)", fd);

if (!exists_capio_fd(fd)) {
Expand Down
5 changes: 2 additions & 3 deletions capio-posix/handlers/fcntl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(arg0);
auto cmd = static_cast<int>(arg1);
auto arg = static_cast<int>(arg2);
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

START_LOG(tid, "call(fd=%d, cmd=%d, arg=%d)", fd, cmd, arg);

if (exists_capio_fd(fd)) {
Expand Down
5 changes: 2 additions & 3 deletions capio-posix/handlers/fgetxattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(arg1));
auto *value = reinterpret_cast<void *>(arg2);
auto size = static_cast<size_t>(arg3);
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
auto fd = static_cast<int>(arg0);
START_LOG(tid, "call(name=%s, value=0x%08x, size=%ld)", name.c_str(), value, size);

Expand Down
9 changes: 5 additions & 4 deletions capio-posix/handlers/fork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pid_t>(syscall_no_intercept(SYS_fork));

START_LOG(parent_tid, "call(pid=%ld)", pid);

if (pid == 0) {
// child
const auto child_tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
init_process(child_tid);
capio_current_thread_id = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
init_process(capio_current_thread_id);
*result = 0;
return posix_return_value(0, result);
}
Expand Down
5 changes: 3 additions & 2 deletions capio-posix/handlers/getcwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(arg0);
auto size = static_cast<size_t>(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;
}
Expand Down
4 changes: 2 additions & 2 deletions capio-posix/handlers/ioctl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(arg0);
auto request = static_cast<unsigned long>(arg1);
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
START_LOG(tid, "call(fd=%d, request=%ld)", fd, request, tid);

if (exists_capio_fd(fd)) {
Expand Down
4 changes: 2 additions & 2 deletions capio-posix/handlers/lseek.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(arg0);
auto offset = static_cast<capio_off64_t>(arg1);
int whence = static_cast<int>(arg2);
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

START_LOG(tid, "call(fd=%d, offset=%ld, whence=%d)", fd, offset, whence);
if (exists_capio_fd(fd)) {
Expand Down
13 changes: 6 additions & 7 deletions capio-posix/handlers/mkdir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(arg0));
auto mode = static_cast<mode_t>(arg1);
auto tid = static_cast<pid_t>(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<int>(arg0);
const std::string_view pathname(reinterpret_cast<const char *>(arg1));
auto mode = static_cast<mode_t>(arg2);
auto tid = static_cast<pid_t>(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<const char *>(arg0));
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

return posix_return_value(capio_rmdir(pathname, tid), result);
}
Expand Down
15 changes: 8 additions & 7 deletions capio-posix/handlers/open.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<const char *>(arg0));
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
int flags = O_CREAT | O_WRONLY | O_TRUNC;
mode_t mode = static_cast<int>(arg2);
START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode);
Expand Down Expand Up @@ -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<const char *>(arg0));
int flags = static_cast<int>(arg1);
mode_t mode = static_cast<int>(arg2);
auto tid = static_cast<pid_t>(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);
Expand Down Expand Up @@ -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<int>(arg0);
std::string pathname(reinterpret_cast<const char *>(arg1));
int flags = static_cast<int>(arg2);
mode_t mode = static_cast<int>(arg3);
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

START_LOG(tid, "call(dirfd=%ld, path=%s, flags=%d, mode=%d)", dirfd, pathname.data(), flags,
mode);

Expand Down
18 changes: 9 additions & 9 deletions capio-posix/handlers/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ 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);
}
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}

#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<int>(arg0);
auto count = static_cast<capio_off64_t>(arg2);
auto buffer = reinterpret_cast<void *>(arg1);
auto tid = static_cast<pid_t>(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);
Expand All @@ -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<int>(arg0);
auto iovcnt = static_cast<int>(arg2);
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

if (exists_capio_fd(fd)) {
auto computed_offset = get_capio_fd_offset(fd) + iovcnt * sizeof(iovec);
Expand Down
Loading
Loading