Skip to content
Merged
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
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
option(CAPIO_BUILD_TESTS "Build CAPIO test suite" FALSE)
option(CAPIO_LOG "Enable capio debug logging" FALSE)
option(ENABLE_COVERAGE "Enable code coverage collection" FALSE)
option(CAPIO_BUILD_SERVER "Build CAPIO server component" TRUE)
option(CAPIO_BUILD_POSIX "Build CAPIO posix component" TRUE)

#####################################
# CMake module imports
Expand Down Expand Up @@ -82,8 +84,16 @@ FetchContent_Declare(
#####################################
# Targets
#####################################
add_subdirectory(capio/posix)
add_subdirectory(capio/server)

IF(CAPIO_BUILD_POSIX)
message(STATUS "Adding CAPIO posix component")
add_subdirectory(capio/posix)
ENDIF()

IF(CAPIO_BUILD_SERVER)
message(STATUS "Adding CAPIO server component")
add_subdirectory(capio/server)
ENDIF()

IF (CAPIO_BUILD_TESTS)
message(STATUS "Building CAPIO test suite")
Expand Down
14 changes: 3 additions & 11 deletions capio/common/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,13 @@ class Logger {
setup_posix_log_filename();
current_log_level =
0; // reset log level after clone, avoiding propagation to child threads
#if defined(SYS_mkdir)
capio_syscall(SYS_mkdir, get_log_dir(), 0755);
capio_syscall(SYS_mkdir, get_posix_log_dir(), 0755);
capio_syscall(SYS_mkdir, get_host_log_dir(), 0755);
#elif defined(SYS_mkdirat)

capio_syscall(SYS_mkdirat, AT_FDCWD, get_log_dir(), 0755);
capio_syscall(SYS_mkdirat, AT_FDCWD, get_posix_log_dir(), 0755);
capio_syscall(SYS_mkdirat, AT_FDCWD, get_host_log_dir(), 0755);
#endif
#if defined(SYS_open)
logfileFD = capio_syscall(SYS_open, logfile_path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
#elif defined(SYS_openat)

logfileFD = capio_syscall(SYS_openat, AT_FDCWD, logfile_path,
O_CREAT | O_WRONLY | O_TRUNC, 0644);
#endif

if (logfileFD == -1) {
capio_syscall(SYS_write, fileno(stdout),
Expand Down Expand Up @@ -264,7 +256,7 @@ class Logger {

auto buf1 = reinterpret_cast<char *>(capio_syscall(
SYS_mmap, nullptr, 50, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
sprintf(buf1, CAPIO_LOG_POSIX_SYSCALL_START, sys_num_to_string(syscallNumber),
sprintf(buf1, CAPIO_LOG_POSIX_SYSCALL_START, sys_num_to_string(syscallNumber).c_str(),
syscallNumber);
log_write_to(buf1, strlen(buf1));
capio_syscall(SYS_munmap, buf1, 50);
Expand Down
4 changes: 2 additions & 2 deletions capio/posix/handlers/dup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ int dup_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5
return CAPIO_POSIX_SYSCALL_SKIP;
}

#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 res = capio_dup2(fd, fd2, tid);

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

if (exists_capio_fd(fd)) {
Expand All @@ -51,6 +50,7 @@ int dup2_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
}
return CAPIO_POSIX_SYSCALL_SKIP;
}
#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);
Expand Down
5 changes: 2 additions & 3 deletions capio/posix/handlers/fchmod.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef CAPIO_POSIX_HANDLERS_FCHMOD_HPP
#define CAPIO_POSIX_HANDLERS_FCHMOD_HPP

#if defined(SYS_chmod)

int fchmod_handler(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);

// TODO: Handle mode provided bt arg1

if (!exists_capio_fd(fd)) {
LOG("Syscall refers to file not handled by capio. Skipping it!");
return CAPIO_POSIX_SYSCALL_SKIP;
Expand All @@ -20,5 +20,4 @@ int fchmod_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
return CAPIO_POSIX_SYSCALL_SUCCESS;
}

#endif // SYS_chmod
#endif // CAPIO_POSIX_HANDLERS_FCHMOD_HPP
5 changes: 0 additions & 5 deletions capio/posix/handlers/fchown.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef CAPIO_POSIX_HANDLERS_FCHOWN_HPP
#define CAPIO_POSIX_HANDLERS_FCHOWN_HPP

#if defined(SYS_chown)

int fchown_handler(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);
Expand All @@ -18,8 +16,5 @@ int fchown_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
*result = 0;
LOG("File is present in capio. Ignoring fchmod operation");
return CAPIO_POSIX_SYSCALL_SUCCESS;
return CAPIO_POSIX_SYSCALL_SUCCESS;
}

#endif // SYS_chown
#endif // CAPIO_POSIX_HANDLERS_FCHOWN_HPP
3 changes: 2 additions & 1 deletion capio/posix/handlers/open.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ inline int capio_openat(int dirfd, const std::string_view &pathname, int flags,
}

if (is_capio_path(path)) {
int fd = static_cast<int>(syscall_no_intercept(SYS_open, "/dev/null", O_RDONLY));
int fd =
static_cast<int>(syscall_no_intercept(SYS_openat, AT_FDCWD, "/dev/null", O_RDONLY));
if (fd == -1) {
ERR_EXIT("capio_open, /dev/null opening");
}
Expand Down
2 changes: 1 addition & 1 deletion capio/posix/utils/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ std::filesystem::path get_dir_path(int dirfd) {
char proclnk[128];
char dir_pathname[PATH_MAX];
sprintf(proclnk, "/proc/self/fd/%d", dirfd);
if (syscall_no_intercept(SYS_readlink, proclnk, dir_pathname, PATH_MAX) < 0) {
if (syscall_no_intercept(SYS_readlinkat, AT_FDCWD, proclnk, dir_pathname, PATH_MAX) < 0) {
LOG("failed to readlink\n");
return {};
}
Expand Down
Loading