Loading src/client/gkfs_libc.cpp +63 −13 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ #include <linux/const.h> #include <client/logging.hpp> #include <sstream> #include <aio.h> #include <signal.h> std::atomic<bool> activated{false}; std::atomic<bool> initializing{false}; Loading Loading @@ -307,18 +309,7 @@ DLSYM_WRAPPER(long, telldir, (DIR * dirp), (dirp), "telldir") static pid_t (*real_fork)(void) = NULL; static pid_t (*real_vfork)(void) = NULL; static pid_t (*real_clone)(int (*fn)(void*), void*, int, void*, ...) = NULL; /*pid_t fork(void) { if (!real_fork) reinterpret_cast<int (*)(void)>(dlsym(((void*) -1l), "fork")); destroy_libc(); pid_t pid = real_fork(); (pid == 0) ? init_libc() : init_libc(); return pid; }*/ /* pid_t vfork(void) { if(!real_vfork) Loading @@ -342,6 +333,7 @@ clone(int (*fn)(void*), void* stack, int flags, void* arg, ...) { real_clone = reinterpret_cast<decltype(&::clone)>(dlsym(RTLD_NEXT, "clone")); // Only handle process-creation clones if(flags & (SIGCHLD | CLONE_VFORK)) { destroy_libc(); Loading @@ -354,7 +346,7 @@ clone(int (*fn)(void*), void* stack, int flags, void* arg, ...) { } return pid; } */ DLSYM_WRAPPER(int, pipe, (int pipefd[2]), (pipefd), "pipe") DLSYM_WRAPPER(int, dup, (int fd), (fd), "dup") Loading Loading @@ -842,6 +834,7 @@ pread(int fd, void* buf, size_t count, off_t offset) { ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { initializeGekko(); DEBUG_INFO("[GKFS] PWRITE BEFORE {}", fd); GKFS_OPERATION(pwrite, fd, buf, count, offset); GKFS_FALLBACK(pwrite, fd, buf, count, offset); } Loading Loading @@ -2243,3 +2236,60 @@ pwritev2(int fd, const struct iovec* iov, int iovcnt, off_t offset, int flags) { GKFS_OPERATION(pwritev, fd, iov, iovcnt, offset) GKFS_FALLBACK(pwritev2, fd, iov, iovcnt, offset, flags) } // aio Operations (write) // /* // #include <aiocb.h> // struct aiocb { // int aio_fildes; /* File descriptor */ // off_t aio_offset; /* File offset */ // volatile void *aio_buf; /* Location of buffer */ // size_t aio_nbytes; /* Length of transfer */ // int aio_reqprio; /* Request priority */ // struct sigevent aio_sigevent; /* Notification method */ // int aio_lio_opcode; /* Operation to be performed; // lio_listio() only */ // /* Various implementation-internal fields not shown */ // }; // /* Operation codes for 'aio_lio_opcode': */ // enum { LIO_READ, LIO_WRITE, LIO_NOP }; // Possible values for aio_sigevent.sigev_notify are SIGEV_NONE, SIGEV_SIGNAL, // and SIGEV_THREAD. See sigevent(3type) for further de‐ // tails. // */ DLSYM_WRAPPER(int, aio_write, (struct aiocb * aiocbp), (aiocbp), "aio_write"); int aio_write(struct aiocb* aiocbp) { initializeGekko(); if(gkfs::preload::PreloadContext::getInstance()->interception_enabled() && is_gkfs_fd(fd)) { auto res = gkfs::syscall::gkfs_write( aiocbp->aio_fildes, (const void*)aiocbp->aio_buf, aiocbp->aio_nbytes); /* if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL){ // send signal of completation sigaction(aiocbp->aio_sigevent.sigev_signo, NULL, NULL); } else if (aiocbp->aio_sigevent.sigev_notify == SIGEV_THREAD){ aiocbp->aio_sigevent.sigev_notify_function(aiocbp->aio_sigevent.sigev_value); } else if (aiocbp->aio_sigevent.sigev_notify == SIGEV_NONE){ } */ // TODO : SIGNALING IS WRONG // return res; } GKFS_FALLBACK(aio_write, aiocbp) } Loading
src/client/gkfs_libc.cpp +63 −13 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ #include <linux/const.h> #include <client/logging.hpp> #include <sstream> #include <aio.h> #include <signal.h> std::atomic<bool> activated{false}; std::atomic<bool> initializing{false}; Loading Loading @@ -307,18 +309,7 @@ DLSYM_WRAPPER(long, telldir, (DIR * dirp), (dirp), "telldir") static pid_t (*real_fork)(void) = NULL; static pid_t (*real_vfork)(void) = NULL; static pid_t (*real_clone)(int (*fn)(void*), void*, int, void*, ...) = NULL; /*pid_t fork(void) { if (!real_fork) reinterpret_cast<int (*)(void)>(dlsym(((void*) -1l), "fork")); destroy_libc(); pid_t pid = real_fork(); (pid == 0) ? init_libc() : init_libc(); return pid; }*/ /* pid_t vfork(void) { if(!real_vfork) Loading @@ -342,6 +333,7 @@ clone(int (*fn)(void*), void* stack, int flags, void* arg, ...) { real_clone = reinterpret_cast<decltype(&::clone)>(dlsym(RTLD_NEXT, "clone")); // Only handle process-creation clones if(flags & (SIGCHLD | CLONE_VFORK)) { destroy_libc(); Loading @@ -354,7 +346,7 @@ clone(int (*fn)(void*), void* stack, int flags, void* arg, ...) { } return pid; } */ DLSYM_WRAPPER(int, pipe, (int pipefd[2]), (pipefd), "pipe") DLSYM_WRAPPER(int, dup, (int fd), (fd), "dup") Loading Loading @@ -842,6 +834,7 @@ pread(int fd, void* buf, size_t count, off_t offset) { ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { initializeGekko(); DEBUG_INFO("[GKFS] PWRITE BEFORE {}", fd); GKFS_OPERATION(pwrite, fd, buf, count, offset); GKFS_FALLBACK(pwrite, fd, buf, count, offset); } Loading Loading @@ -2243,3 +2236,60 @@ pwritev2(int fd, const struct iovec* iov, int iovcnt, off_t offset, int flags) { GKFS_OPERATION(pwritev, fd, iov, iovcnt, offset) GKFS_FALLBACK(pwritev2, fd, iov, iovcnt, offset, flags) } // aio Operations (write) // /* // #include <aiocb.h> // struct aiocb { // int aio_fildes; /* File descriptor */ // off_t aio_offset; /* File offset */ // volatile void *aio_buf; /* Location of buffer */ // size_t aio_nbytes; /* Length of transfer */ // int aio_reqprio; /* Request priority */ // struct sigevent aio_sigevent; /* Notification method */ // int aio_lio_opcode; /* Operation to be performed; // lio_listio() only */ // /* Various implementation-internal fields not shown */ // }; // /* Operation codes for 'aio_lio_opcode': */ // enum { LIO_READ, LIO_WRITE, LIO_NOP }; // Possible values for aio_sigevent.sigev_notify are SIGEV_NONE, SIGEV_SIGNAL, // and SIGEV_THREAD. See sigevent(3type) for further de‐ // tails. // */ DLSYM_WRAPPER(int, aio_write, (struct aiocb * aiocbp), (aiocbp), "aio_write"); int aio_write(struct aiocb* aiocbp) { initializeGekko(); if(gkfs::preload::PreloadContext::getInstance()->interception_enabled() && is_gkfs_fd(fd)) { auto res = gkfs::syscall::gkfs_write( aiocbp->aio_fildes, (const void*)aiocbp->aio_buf, aiocbp->aio_nbytes); /* if (aiocbp->aio_sigevent.sigev_notify == SIGEV_SIGNAL){ // send signal of completation sigaction(aiocbp->aio_sigevent.sigev_signo, NULL, NULL); } else if (aiocbp->aio_sigevent.sigev_notify == SIGEV_THREAD){ aiocbp->aio_sigevent.sigev_notify_function(aiocbp->aio_sigevent.sigev_value); } else if (aiocbp->aio_sigevent.sigev_notify == SIGEV_NONE){ } */ // TODO : SIGNALING IS WRONG // return res; } GKFS_FALLBACK(aio_write, aiocbp) }