Commit 7e1c7cce authored by Julius Athenstaedt's avatar Julius Athenstaedt Committed by sevenuz
Browse files

use GSL to narrow down syscalls in hooks.cpp

parent e2cbd043
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -261,6 +261,14 @@ if (GKFS_ENABLE_CLIENT_METRICS)
    )
endif ()

### GSL: Guidelines Support Library
include_from_source(gsl
	MESSAGE "[${PROJECT_NAME}] Searching for GSL"
	SOURCE_DIR ${GKFS_DEPENDENCIES_PATH}/GSL
  GIT_REPOSITORY https://github.com/microsoft/GSL
  GIT_TAG v4.0.0
)

################################################################################
## Check configured variables/options and act accordingly
################################################################################
+2 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ target_link_libraries(
    fmt::fmt
    Threads::Threads
    Syscall_intercept::Syscall_intercept
    Microsoft::GSL
)
# Enable MSGPack metrics for intercept only
if (GKFS_ENABLE_CLIENT_METRICS)
@@ -116,6 +117,7 @@ target_link_libraries(
    hermes
    fmt::fmt
    Threads::Threads
    Microsoft::GSL
)

install(
+4 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <client/open_dir.hpp>

#include <common/path_util.hpp>
#include <gsl/gsl>

#include <memory>

@@ -239,7 +240,7 @@ hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos) {
    }
    /* Since kernel 2.6: pread() became pread64(), and pwrite() became
     * pwrite64(). */
    return syscall_no_intercept_wrapper(SYS_pread64, fd, buf, count, pos);
    return gsl::narrow<int>(syscall_no_intercept_wrapper(SYS_pread64, fd, buf, count, pos));
}

int
@@ -293,7 +294,7 @@ hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos) {
    }
    /* Since kernel 2.6: pread() became pread64(), and pwrite() became
     * pwrite64(). */
    return syscall_no_intercept_wrapper(SYS_pwrite64, fd, buf, count, pos);
    return gsl::narrow<int>(syscall_no_intercept_wrapper(SYS_pwrite64, fd, buf, count, pos));
}

int
@@ -595,7 +596,7 @@ hook_getdents64(unsigned int fd, struct linux_dirent64* dirp,
    if(CTX->file_map()->exist(fd)) {
        return with_errno(gkfs::syscall::gkfs_getdents64(fd, dirp, count));
    }
    return syscall_no_intercept_wrapper(SYS_getdents64, fd, dirp, count);
    return gsl::narrow<int>(syscall_no_intercept_wrapper(SYS_getdents64, fd, dirp, count));
}