Skip to content
Open
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
15 changes: 7 additions & 8 deletions capio/posix/handlers/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inline off64_t capio_faccessat(int dirfd, const std::string_view &pathname, mode
std::filesystem::path path(pathname);
if (path.is_relative()) {
if (dirfd == AT_FDCWD) {
path = capio_posix_realpath(pathname);
path = capio_posix_realpath(tid, pathname);
if (path.empty()) {
errno = ENONET;
return CAPIO_POSIX_SYSCALL_ERRNO;
Expand All @@ -29,7 +29,7 @@ inline off64_t capio_faccessat(int dirfd, const std::string_view &pathname, mode
LOG("dirfd does not point to a directory");
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}
const std::filesystem::path dir_path = get_dir_path(dirfd);
const std::filesystem::path dir_path = get_dir_path(tid, dirfd);
if (dir_path.empty()) {
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}
Expand All @@ -45,23 +45,22 @@ inline off64_t capio_faccessat(int dirfd, const std::string_view &pathname, mode
}
}

int access_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int access_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
const std::string_view pathname(reinterpret_cast<const char *>(arg0));
auto mode = static_cast<mode_t>(arg1);
long tid = syscall_no_intercept(SYS_gettid);

return posix_return_value(capio_faccessat(AT_FDCWD, pathname, mode, 0, tid), result);
return posix_return_value(tid, capio_faccessat(AT_FDCWD, pathname, mode, 0, tid), result);
}

int faccessat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
int faccessat_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
auto dirfd = static_cast<int>(arg0);
const std::string_view pathname(reinterpret_cast<const char *>(arg1));
auto mode = static_cast<mode_t>(arg2);
auto flags = static_cast<int>(arg3);
long tid = syscall_no_intercept(SYS_gettid);

return posix_return_value(capio_faccessat(dirfd, pathname, mode, flags, tid), result);
return posix_return_value(tid, capio_faccessat(dirfd, pathname, mode, flags, tid), result);
}

#endif // SYS_access || SYS_faccessat || SYS_faccessat2
Expand Down
6 changes: 3 additions & 3 deletions capio/posix/handlers/chdir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* to the kernel.
*/

int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int chdir_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
const std::string_view pathname(reinterpret_cast<const char *>(arg0));
long tid = syscall_no_intercept(SYS_gettid);

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

Expand All @@ -24,7 +24,7 @@ int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar

std::filesystem::path path(pathname);
if (path.is_relative()) {
path = capio_posix_realpath(path);
path = capio_posix_realpath(tid, path);
if (path.empty()) {
*result = -errno;
return CAPIO_POSIX_SYSCALL_SUCCESS;
Expand Down
10 changes: 5 additions & 5 deletions capio/posix/handlers/close.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

#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);
long tid = syscall_no_intercept(SYS_gettid);
int close_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);
START_LOG(tid, "call(fd=%ld)", fd);

if (exists_capio_fd(fd)) {
write_cache->flush();
if (exists_capio_fd(tid, fd)) {
write_cache->flush(tid);
close_request(fd, tid);
delete_capio_fd(fd);
*result = 0;
Expand Down
24 changes: 12 additions & 12 deletions capio/posix/handlers/dup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "common/syscall.hpp"
#include "utils/requests.hpp"

int dup_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
long tid = syscall_no_intercept(SYS_gettid);
int fd = static_cast<int>(arg0);
int dup_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);

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

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
int res = open("/dev/null", O_WRONLY);
if (res == -1) {
*result = -errno;
Expand All @@ -28,14 +28,14 @@ int dup_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5
}

#ifdef SYS_dup2
int dup2_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
long tid = syscall_no_intercept(SYS_gettid);
int fd = static_cast<int>(arg0);
int fd2 = static_cast<int>(arg1);
int dup2_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);
int fd2 = static_cast<int>(arg1);

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

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
int res = static_cast<int>(syscall_no_intercept(SYS_dup2, fd, fd2));
if (res == -1) {
*result = -errno;
Expand All @@ -52,8 +52,8 @@ int dup2_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
}
#endif

int dup3_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
long tid = syscall_no_intercept(SYS_gettid);
int dup3_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);
int fd2 = static_cast<int>(arg1);
int flags = static_cast<int>(arg2);
Expand All @@ -62,7 +62,7 @@ int dup3_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg

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

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
if (fd == fd2) {
errno = EINVAL;
*result = -errno;
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) {
long tid = syscall_no_intercept(SYS_gettid);
int execve_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
START_LOG(tid, "call()");

create_snapshot(tid);
Expand Down
8 changes: 4 additions & 4 deletions capio/posix/handlers/exit_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* with CAPIO
*/

int exit_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
long tid = syscall_no_intercept(SYS_gettid);
int exit_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
START_LOG(tid, "call()");

LOG("Thread %d is a CAPIO thread: clean up", tid);
read_cache->flush();
write_cache->flush();
read_cache->flush(tid);
write_cache->flush(tid);
exit_group_request(tid);

return CAPIO_POSIX_SYSCALL_SKIP;
Expand Down
7 changes: 4 additions & 3 deletions capio/posix/handlers/fchmod.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#ifndef CAPIO_POSIX_HANDLERS_FCHMOD_HPP
#define CAPIO_POSIX_HANDLERS_FCHMOD_HPP

int fchmod_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int fchmod_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);
START_LOG(syscall_no_intercept(SYS_gettid), "call(fd=%d)", fd);
START_LOG(tid, "call(fd=%d)", fd);

// TODO: Handle mode provided bt arg1

if (!exists_capio_fd(fd)) {
if (!exists_capio_fd(tid, fd)) {
LOG("Syscall refers to file not handled by capio. Skipping it!");
return CAPIO_POSIX_SYSCALL_SKIP;
}
Expand Down
7 changes: 4 additions & 3 deletions capio/posix/handlers/fchown.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef CAPIO_POSIX_HANDLERS_FCHOWN_HPP
#define CAPIO_POSIX_HANDLERS_FCHOWN_HPP

int fchown_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int fchown_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);
START_LOG(syscall_no_intercept(SYS_gettid), "call(fd=%d)", fd);
START_LOG(tid, "call(fd=%d)", fd);

if (!exists_capio_fd(fd)) {
if (!exists_capio_fd(tid, fd)) {
LOG("Syscall refers to file not handled by capio. Skipping it!");
return CAPIO_POSIX_SYSCALL_SKIP;
}
Expand Down
6 changes: 3 additions & 3 deletions capio/posix/handlers/fcntl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

#include "utils/requests.hpp"

int fcntl_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int fcntl_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
auto fd = static_cast<int>(arg0);
auto cmd = static_cast<int>(arg1);
auto arg = static_cast<int>(arg2);
long tid = syscall_no_intercept(SYS_gettid);

// int res = capio_fcntl(fd, cmd, arg, tid);

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

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
switch (cmd) {
case F_GETFD: {
*result = get_capio_fd_cloexec(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,16 +3,15 @@

#if defined(SYS_fgetxattr)

int fgetxattr_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
int fgetxattr_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
std::string name(reinterpret_cast<const char *>(arg1));
auto *value = reinterpret_cast<void *>(arg2);
auto size = static_cast<size_t>(arg3);
long tid = 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);

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
if (std::equal(name.begin(), name.end(), "system.posix_acl_access")) {
errno = ENODATA;
*result = -errno;
Expand Down
3 changes: 2 additions & 1 deletion capio/posix/handlers/fork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#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) {
int fork_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
auto pid = static_cast<pid_t>(syscall_no_intercept(SYS_fork));
START_LOG(syscall_no_intercept(SYS_gettid), "call(pid=%ld)", pid);

Expand Down
4 changes: 2 additions & 2 deletions capio/posix/handlers/getcwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#if defined(SYS_getcwd)

int getcwd_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int getcwd_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
auto buf = reinterpret_cast<char *>(arg0);
auto size = static_cast<size_t>(arg1);
long tid = syscall_no_intercept(SYS_gettid);

START_LOG(tid, "call(buf=0x%08x, size=%ld)", buf, size);

Expand Down
28 changes: 14 additions & 14 deletions capio/posix/handlers/getdents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
#include "utils/data.hpp"

// TODO: too similar to capio_read, refactoring needed
inline int getdents_handler_impl(long arg0, long arg1, long arg2, long *result, bool is64bit) {
inline int getdents_handler_impl(pid_t tid, long arg0, long arg1, long arg2, long *result,
bool is64bit) {
auto fd = static_cast<int>(arg0);
auto *buffer = reinterpret_cast<struct linux_dirent64 *>(arg1);
auto count = static_cast<off64_t>(arg2);
long tid = syscall_no_intercept(SYS_gettid);

START_LOG(tid, "call(fd=%d, dirp=0x%08x, count=%ld, is64bit=%s)", fd, buffer, count,
is64bit ? "true" : "false");

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
LOG("fd=%d, is a capio file descriptor", fd);

if (count >= SSIZE_MAX) {
ERR_EXIT("src does not support read bigger than SSIZE_MAX yet");
}
write_cache->flush();
*result = read_cache->read(fd, buffer, count, true, is64bit);
write_cache->flush(tid);
*result = read_cache->read(tid, fd, buffer, count, true, is64bit);

DBG(tid, [](char *buf, off64_t count) {
START_LOG(syscall_no_intercept(SYS_gettid), "call (count=%ld)", count);
DBG(tid, [](pid_t tid, char *buf, off64_t count) {
START_LOG(tid, "call (count=%ld)", count);
struct linux_dirent64 *d;
LOG("%25s %12s %13s %15s %s", "INODE", "TYPE", "RECORD_LENGTH", "OFFSET", "NAME");
for (off64_t bpos = 0, i = 0; bpos < count && i < 10; i++) {
Expand All @@ -44,7 +44,7 @@ inline int getdents_handler_impl(long arg0, long arg1, long arg2, long *result,
d->d_reclen, d->d_off, d->d_name);
bpos += d->d_reclen;
}
}(reinterpret_cast<char *>(buffer), *result));
}(tid, reinterpret_cast<char *>(buffer), *result));

return CAPIO_POSIX_SYSCALL_SUCCESS;
} else {
Expand All @@ -53,14 +53,14 @@ inline int getdents_handler_impl(long arg0, long arg1, long arg2, long *result,
return CAPIO_POSIX_SYSCALL_SKIP;
}

inline int getdents_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
return getdents_handler_impl(arg0, arg1, arg2, result, false);
inline int getdents_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4,
long arg5, long *result) {
return getdents_handler_impl(tid, arg0, arg1, arg2, result, false);
}

inline int getdents64_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
return getdents_handler_impl(arg0, arg1, arg2, result, true);
inline int getdents64_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4,
long arg5, long *result) {
return getdents_handler_impl(tid, arg0, arg1, arg2, result, true);
}

#endif // SYS_getdents || SYS_getdents64
Expand Down
6 changes: 3 additions & 3 deletions capio/posix/handlers/ioctl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

#if defined(SYS_ioctl)

int ioctl_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int ioctl_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
auto fd = static_cast<int>(arg0);
auto request = static_cast<unsigned long>(arg1);
long tid = syscall_no_intercept(SYS_gettid);
START_LOG(tid, "call(fd=%d, request=%ld)", fd, request, tid);

if (exists_capio_fd(fd)) {
if (exists_capio_fd(tid, fd)) {
errno = ENOTTY;
*result = -errno;
return CAPIO_POSIX_SYSCALL_SUCCESS;
Expand Down
14 changes: 7 additions & 7 deletions capio/posix/handlers/lseek.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include "utils/common.hpp"

// TODO: EOVERFLOW is not addressed
inline off64_t capio_lseek(int fd, off64_t offset, int whence, long tid) {
inline off64_t capio_lseek(int fd, off64_t offset, int whence, pid_t tid) {
START_LOG(tid, "call(fd=%d, offset=%ld, whence=%d)", fd, offset, whence);

if (exists_capio_fd(fd)) {
read_cache->flush();
write_cache->flush();
if (exists_capio_fd(tid, fd)) {
read_cache->flush(tid);
write_cache->flush(tid);
off64_t file_offset = get_capio_fd_offset(fd);
if (whence == SEEK_SET) {
LOG("whence %d is SEEK_SET", whence);
Expand Down Expand Up @@ -65,13 +65,13 @@ inline off64_t capio_lseek(int fd, off64_t offset, int whence, long tid) {
}
}

int lseek_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
int lseek_handler(pid_t tid, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5,
long *result) {
int fd = static_cast<int>(arg0);
auto offset = static_cast<off64_t>(arg1);
int whence = static_cast<int>(arg2);
long tid = syscall_no_intercept(SYS_gettid);

return posix_return_value(capio_lseek(fd, offset, whence, tid), result);
return posix_return_value(tid, capio_lseek(fd, offset, whence, tid), result);
}

#endif // SYS_lseek
Expand Down
Loading
Loading