Loading ifs/include/preload/passthrough.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,11 @@ extern void* libc_setvbuf; extern void* libc_putc; extern void* libc_fputc; extern void* libc_fputs; extern void* libc_getc; extern void* libc_fgetc; extern void* libc_fgets; extern void* libc_ungetc; extern void* libc_mkdir; extern void* libc_mkdirat; Loading ifs/src/preload/intcp_functions.cpp +80 −2 Original line number Diff line number Diff line Loading @@ -377,7 +377,7 @@ int putc(int c, FILE *stream) { return EOF; } } return (reinterpret_cast<decltype(&putc)>(libc_putc))(c, stream); return LIBC_FUNC(putc, c, stream); } int fputc(int c, FILE *stream) { Loading @@ -390,7 +390,85 @@ int fputc(int c, FILE *stream) { return EOF; } } return (reinterpret_cast<decltype(&fputc)>(libc_fputc))(c, stream); return LIBC_FUNC(fputc, c, stream); } int fputs(const char *s, FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(fputs, s, stream); } int getc(FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(getc, stream); } int fgetc(FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(fgetc, stream); } char* fgets(char* s, int size, FILE* stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->trace("{}() [fd: {}, size: {}]", __func__, fd, size); auto ret = adafs_read(fd, s, size - 1); CTX->log()->debug("{}() read {} bytes", __func__, ret); if(ret > 0) { char* nl_ptr = static_cast<char*>(memchr(s, '\n', size - 1)); assert((nl_ptr - s) < size); if(nl_ptr != nullptr) { CTX->log()->debug("{}() found new line char at {}", __func__, (nl_ptr - s)); nl_ptr[1] = '\0'; } else { s[size - 1] = '\0'; } return s; } else { return nullptr; } } } return LIBC_FUNC(fgets, s, size, stream); } int ungetc(int c, FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(ungetc, c, stream); } /****** FILE OPS ******/ Loading ifs/src/preload/passthrough.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,11 @@ void* libc_setvbuf; void* libc_putc; void* libc_fputc; void* libc_fputs; void* libc_getc; void* libc_fgetc; void* libc_fgets; void* libc_ungetc; void* libc_mkdir; void* libc_mkdirat; Loading Loading @@ -141,6 +146,11 @@ void init_passthrough_() { libc_putc = dlsym(libc, "putc"); libc_fputc = dlsym(libc, "fputc"); libc_fputs = dlsym(libc, "fputs"); libc_getc = dlsym(libc, "getc"); libc_fgetc = dlsym(libc, "fgetc"); libc_fgets = dlsym(libc, "fgets"); libc_ungetc = dlsym(libc, "ungetc"); libc_mkdir = dlsym(libc, "mkdir"); libc_mkdirat = dlsym(libc, "mkdirat"); Loading Loading
ifs/include/preload/passthrough.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,11 @@ extern void* libc_setvbuf; extern void* libc_putc; extern void* libc_fputc; extern void* libc_fputs; extern void* libc_getc; extern void* libc_fgetc; extern void* libc_fgets; extern void* libc_ungetc; extern void* libc_mkdir; extern void* libc_mkdirat; Loading
ifs/src/preload/intcp_functions.cpp +80 −2 Original line number Diff line number Diff line Loading @@ -377,7 +377,7 @@ int putc(int c, FILE *stream) { return EOF; } } return (reinterpret_cast<decltype(&putc)>(libc_putc))(c, stream); return LIBC_FUNC(putc, c, stream); } int fputc(int c, FILE *stream) { Loading @@ -390,7 +390,85 @@ int fputc(int c, FILE *stream) { return EOF; } } return (reinterpret_cast<decltype(&fputc)>(libc_fputc))(c, stream); return LIBC_FUNC(fputc, c, stream); } int fputs(const char *s, FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(fputs, s, stream); } int getc(FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(getc, stream); } int fgetc(FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(fgetc, stream); } char* fgets(char* s, int size, FILE* stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->trace("{}() [fd: {}, size: {}]", __func__, fd, size); auto ret = adafs_read(fd, s, size - 1); CTX->log()->debug("{}() read {} bytes", __func__, ret); if(ret > 0) { char* nl_ptr = static_cast<char*>(memchr(s, '\n', size - 1)); assert((nl_ptr - s) < size); if(nl_ptr != nullptr) { CTX->log()->debug("{}() found new line char at {}", __func__, (nl_ptr - s)); nl_ptr[1] = '\0'; } else { s[size - 1] = '\0'; } return s; } else { return nullptr; } } } return LIBC_FUNC(fgets, s, size, stream); } int ungetc(int c, FILE *stream) { init_passthrough_if_needed(); if(CTX->initialized() && (stream != nullptr)) { auto fd = file_to_fd(stream); if(CTX->file_map()->exist(fd)) { CTX->log()->error("{}() NOT SUPPORTED", __func__); errno = ENOTSUP; return EOF; } } return LIBC_FUNC(ungetc, c, stream); } /****** FILE OPS ******/ Loading
ifs/src/preload/passthrough.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,11 @@ void* libc_setvbuf; void* libc_putc; void* libc_fputc; void* libc_fputs; void* libc_getc; void* libc_fgetc; void* libc_fgets; void* libc_ungetc; void* libc_mkdir; void* libc_mkdirat; Loading Loading @@ -141,6 +146,11 @@ void init_passthrough_() { libc_putc = dlsym(libc, "putc"); libc_fputc = dlsym(libc, "fputc"); libc_fputs = dlsym(libc, "fputs"); libc_getc = dlsym(libc, "getc"); libc_fgetc = dlsym(libc, "fgetc"); libc_fgets = dlsym(libc, "fgets"); libc_ungetc = dlsym(libc, "ungetc"); libc_mkdir = dlsym(libc, "mkdir"); libc_mkdirat = dlsym(libc, "mkdirat"); Loading