Backport plain-C IO probes changes from (653526)
authorAnastasia Lyupa <a.lyupa@samsung.com>
Fri, 6 Sep 2013 09:30:07 +0000 (13:30 +0400)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Wed, 18 Sep 2013 07:12:03 +0000 (07:12 +0000)
That this patch actually port logic of commit~653526 in sence
that for IO probes send messages before and after actual call
with fields filled as much as possible.

Change-Id: Ic3a556a99bcea1a30b30314cae25445d84bf1262
See-also: 65352634ef85b4cec1a86ad34157099adc7bef70
Signed-off-by: Anastasia Lyupa <a.lyupa@samsung.com>
helper/addr-tizen.c
include/daprobe.h
probe_file/da_io.h
probe_file/da_io_posix.c
probe_file/da_io_stdc.c

index f4bb065..d791780 100644 (file)
@@ -3,18 +3,18 @@
  *
  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  *
  * Jaewon Lim <jaewon81.lim@samsung.com>
  * Woojin Jung <woojin2.jung@samsung.com>
  * Juyoung Kim <j0.kim@samsung.com>
  * Anastasia Lyupa <a.lyupa@samsung.com>
- * 
+ *
  * This library is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the
  * Free Software Foundation; either version 2.1 of the License, or (at your option)
  * any later version.
- * 
+ *
  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
@@ -27,7 +27,7 @@
  * Contributors:
  * - S-Core Co., Ltd
  * - Samsung RnD Institute Russia
- * 
+ *
  */
 
 #include <dlfcn.h>
@@ -57,4 +57,3 @@ int getExecutableMappingAddress()
 
        return ret;
 }
-
index 8ffc19b..4c56cc6 100644 (file)
@@ -143,7 +143,7 @@ int getBacktraceString(log_t* log, int bufsize);
 // declare variable for standard api (not tizen related api)
 #define DECLARE_VARIABLE_STANDARD              \
                probeInfo_t     probeInfo;                      \
-               int blockresult;                                \
+               int blockresult = 0;                            \
                bool bfiltering = true;                 \
                int olderrno, newerrno;                 \
                int __attribute__((unused)) ret
index 84034ea..92f14ba 100755 (executable)
@@ -37,6 +37,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include "daprobe.h"
 
@@ -69,6 +70,7 @@
                DECLARE_VARIABLE_STANDARD;                                              \
                char* _filepath = "";                                                   \
                int __attribute((unused)) _fd;                                          \
+               ssize_t __attribute((unused)) _filesize;                                \
                int __attribute((unused)) _fstatret = -1;                               \
                struct stat __attribute((unused)) _statbuf
 
        GET_REAL_FUNC(FUNCNAME, LIBNAME);                                               \
        bfiltering = false;                                                             \
        PRE_PROBEBLOCK()
-
 // ==================================================================
 // Additional macro for READ_START and WRITE_START
 // ==================================================================
 
-#define FILE_API_START_BLOCK(API_ID, APITYPE)                                          \
-    PRE_PROBEBLOCK();                                                                  \
-       POST_PACK_PROBEBLOCK_BEGIN();                                                   \
-       PREPARE_LOCAL_BUF();                                                            \
-       PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, "", 0);                           \
-       PACK_COMMON_END(0, 0, 0);                                                       \
-       PACK_RESOURCE(0, 0, APITYPE, 0, _filepath);                                     \
-       FLUSH_LOCAL_BUF();                                                              \
-       POST_PACK_PROBEBLOCK_END()
+#define DEFINE_FILESIZE_FD(fd) _fd = (fd); _filesize = get_fd_filesize(_fd);
+#define DEFINE_FILESIZE_FP(fp) _fd = checked_fileno(fp); _filesize = get_fd_filesize(_fd);
+#define DEFINE_FILESIZE_0() _fd = _filesize = 0;
+
+#define AFTER_PACK_ORIGINAL(API_ID, RVAL, SIZE, ERRNO, FD, FILESIZE, APITYPE, INPUTFORMAT, ...)        \
+       POST_PACK_PROBEBLOCK_BEGIN();                                                           \
+       PREPARE_LOCAL_BUF();                                                                    \
+       PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);                \
+       PACK_COMMON_END(RVAL,ERRNO, blockresult);                                               \
+       PACK_RESOURCE(SIZE, FD, APITYPE, FILESIZE, _filepath);                                  \
+       FLUSH_LOCAL_BUF();                                                                      \
+       POST_PACK_PROBEBLOCK_END();
+
+#define FILE_API_START_BLOCK(API_ID, APITYPE, INPUTFORMAT, ...)                                        \
+       AFTER_PACK_ORIGINAL(API_ID, 0, 0, 0, _fd, _filesize, APITYPE, INPUTFORMAT, __VA_ARGS__)
+
+#define FILE_API_END_BLOCK(API_ID, RVAL, SIZE, APITYPE, INPUTFORMAT,...)                       \
+       blockresult = 0; bfiltering = 1;                                                        \
+       PRE_PROBEBLOCK();                                                                       \
+       AFTER_PACK_ORIGINAL(API_ID,RVAL, SIZE, newerrno, _fd, _filesize, APITYPE, INPUTFORMAT, __VA_ARGS__)
 
 // ==================================================================
 // AFTER_ORIGINAL macro for file
        POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE);                             \
        POST_PACK_PROBEBLOCK_END()
 
+
+
+static inline ssize_t get_fd_filesize(int fd)
+{
+       /**
+        * Calling library function on invalid file descriptiors is okay,
+        * for such cases we assume size == 0
+        * FIXME: Separate empty files and invalid descriptors.
+        **/
+       struct stat buf;
+       int err = fstat(fd, &buf);
+       if (err)
+               return 0;
+       return buf.st_size ?: 0;
+}
+
+static inline int checked_fileno(FILE *fp)
+{
+       assert((fp != NULL) &&
+              "This function (checked_fileno) is only called from probes\n"
+              "on library functions. Passing NULL instead of file pointer\n"
+              "to standart C functions is undefined behavior\n"
+              "and as such fatal error.\n");
+       return fileno(fp);
+}
+
+
 #endif // __DA_IO_H__
index f5607cc..e194243 100755 (executable)
@@ -420,14 +420,12 @@ ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
        ssize_t sret;
 
        BEFORE_ORIGINAL_FILE(pread, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_pread, FD_API_READ_START);
-
+       DEFINE_FILESIZE_FD(fd);
+       FILE_API_START_BLOCK(API_ID_pread,FD_API_READ_START,
+                                "dpxx", fd, buf, nbyte, offset);
        sret = preadp(fd, buf, nbyte, offset);
-
-       AFTER_PACK_ORIGINAL_FD(API_ID_pread,
-                                  sret, (unsigned int)sret, fd, FD_API_READ_END,
-                                  "dpxx", fd, buf, nbyte, offset);
+       FILE_API_END_BLOCK(API_ID_pread, sret, (unsigned int)sret,
+                               FD_API_READ_END, "dpxx", fd, buf, nbyte, offset);
 
        return sret;
 }
@@ -437,14 +435,14 @@ ssize_t read(int fd, void *buf, size_t nbyte)
        ssize_t sret;
 
        BEFORE_ORIGINAL_FILE(read, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_read, FD_API_READ_START);
+       DEFINE_FILESIZE_FD(fd);
+       FILE_API_START_BLOCK(API_ID_read, FD_API_READ_START,
+                                "dpx", fd, buf, nbyte);
 
        sret = readp(fd, buf, nbyte);
 
-       AFTER_PACK_ORIGINAL_FD(API_ID_read,
-                                  sret, (unsigned int)sret, fd, FD_API_READ_END,
-                                  "dpx", fd, buf, nbyte);
+       FILE_API_END_BLOCK(API_ID_read, sret, (unsigned int)sret,
+                               FD_API_READ_END, "dpx", fd, buf, nbyte);
 
        return sret;
 }
@@ -455,14 +453,14 @@ ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
        ssize_t sret;
 
        BEFORE_ORIGINAL_FILE(pwrite, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_pwrite, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FD(fd);
+       FILE_API_START_BLOCK(API_ID_pwrite, FD_API_WRITE_START,
+                                "dpxx", fd, buf, nbyte, offset);
 
        sret = pwritep(fd, buf, nbyte, offset);
 
-       AFTER_PACK_ORIGINAL_FD(API_ID_pwrite,
-                                  sret, (unsigned int)sret, fd, FD_API_WRITE_END,
-                                  "dpxx", fd, buf, nbyte, offset);
+       FILE_API_END_BLOCK(API_ID_pwrite, sret, (unsigned int)sret,
+                              FD_API_WRITE_END, "dpxx", fd, buf, nbyte, offset);
 
        return sret;
 }
@@ -473,14 +471,13 @@ ssize_t write(int fd, const void *buf, size_t nbyte)
        ssize_t sret;
 
        BEFORE_ORIGINAL_FILE(write, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_write, FD_API_WRITE_START);
-
+       DEFINE_FILESIZE_FD(fd);
+       FILE_API_START_BLOCK(API_ID_write, FD_API_WRITE_START,
+                            "dpx", fd, buf, nbyte);
        sret = writep(fd, buf, nbyte);
 
-       AFTER_PACK_ORIGINAL_FD(API_ID_write,
-                                  sret, (unsigned int)sret, fd, FD_API_WRITE_END,
-                                  "dpx", fd, buf, nbyte);
+       FILE_API_END_BLOCK(API_ID_write, sret, (unsigned int)sret,
+                               FD_API_WRITE_END, "dpx", fd, buf, nbyte);
 
        return sret;
 }
@@ -492,14 +489,13 @@ ssize_t readv(int fd, const struct iovec *iov, int iovcnt)
        ssize_t sret;
 
        BEFORE_ORIGINAL_FILE(readv, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_readv, FD_API_READ_START);
-
+       DEFINE_FILESIZE_FD(fd);
+       FILE_API_START_BLOCK(API_ID_readv, FD_API_READ_START,
+                                "dpd", fd, iov, iovcnt);
        sret = readvp(fd,iov,iovcnt);
 
-       AFTER_PACK_ORIGINAL_FD(API_ID_readv,
-                                  sret, (unsigned int)sret, fd, FD_API_READ_END,
-                                  "dpd", fd, iov, iovcnt);
+       FILE_API_END_BLOCK(API_ID_readv, sret, (unsigned int)sret,
+                               FD_API_READ_END, "dpd", fd, iov, iovcnt);
 
        return sret;
 }
index 570eb71..4880bee 100644 (file)
@@ -297,10 +297,12 @@ int vfprintf(FILE* stream, const char* format, va_list arg)
        static int (*vfprintfp)(FILE* stream, const char* format, va_list arg);
 
        BEFORE_ORIGINAL_FILE(vfprintf, LIBC);
-       FILE_API_START_BLOCK(API_ID_vfprintf, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_vfprintf, FD_API_WRITE_START,
+                                "ps", stream, format);
        ret = vfprintfp(stream, format, arg);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_vfprintf,
-                                 ret, ret, stream, FD_API_WRITE_END, "ps", stream, format);
+       FILE_API_END_BLOCK(API_ID_vfprintf, ret, ret,
+                               FD_API_WRITE_END, "ps", stream, format);
        return ret;
 }
 
@@ -309,10 +311,12 @@ int vfscanf(FILE* stream, const char* format, va_list arg)
        static int (*vfscanfp)(FILE* stream, const char* format, va_list arg);
 
        BEFORE_ORIGINAL_FILE(vfscanf, LIBC);
-       FILE_API_START_BLOCK(API_ID_vfscanf, FD_API_READ_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_vfscanf, FD_API_READ_START,
+                                "ps", stream, format);
        ret = vfscanfp(stream, format, arg);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_vfscanf,
-                                 ret, ret, stream, FD_API_READ_END, "ps", stream, format);
+       FILE_API_END_BLOCK(API_ID_vfscanf, ret, ret,
+                               FD_API_READ_END, "ps", stream, format);
        return ret;
 }
 
@@ -321,10 +325,12 @@ int fgetc(FILE* stream)
        static int (*fgetcp)(FILE* stream);
 
        BEFORE_ORIGINAL_FILE(fgetc, LIBC);
-       FILE_API_START_BLOCK(API_ID_fgetc, FD_API_READ_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fgetc, FD_API_READ_START,
+                            "p", stream);
        ret = fgetcp(stream);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fgetc,
-                                 ret, (ret == EOF ? 0 : 1), stream, FD_API_READ_END, "p", stream);
+       FILE_API_END_BLOCK(API_ID_fgetc, ret, (ret != EOF),
+                                 FD_API_READ_END, "p", stream);
        return ret;
 }
 
@@ -336,12 +342,12 @@ char* fgets(char* str, int size, FILE* stream)
 
        BEFORE_ORIGINAL_FILE(fgets, LIBC);
 
-       FILE_API_START_BLOCK(API_ID_fgets, FD_API_READ_START);
+       FILE_API_START_BLOCK(API_ID_fgets, FD_API_READ_START, "sdp", str, size, stream);
        
        cret = fgetsp(str, size, stream);
 
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fgets, cret, (ret == NULL ? 0 : strlen(cret)),
-                       stream, FD_API_READ_END, "sdp", str, size, stream);
+       FILE_API_END_BLOCK(API_ID_fgets, cret, (ret == NULL ? 0 : strlen(cret)),
+                       FD_API_READ_END, "sdp", str, size, stream);
 
        return cret;
 }
@@ -352,11 +358,12 @@ int fputc(int character, FILE* stream)
        static int (*fputcp)(int character, FILE* stream);
 
        BEFORE_ORIGINAL_FILE(fputc, LIBC);
-       FILE_API_START_BLOCK(API_ID_fputc, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fputc, FD_API_WRITE_START,
+                                "dp", character, stream);
        ret = fputcp(character, stream);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fputc,
-                                 ret, (ret == EOF ? 0 : 1), stream, FD_API_WRITE_END,
-                                 "dp", character, stream);
+       FILE_API_END_BLOCK(API_ID_fputc, ret, (ret != EOF),
+                                 FD_API_WRITE_END, "dp", character, stream);
        return ret;
 }
 
@@ -365,10 +372,12 @@ int fputs(const char* str, FILE* stream)
        static int (*fputsp)(const char* str, FILE* stream);
 
        BEFORE_ORIGINAL_FILE(fputs, LIBC);
-       FILE_API_START_BLOCK(API_ID_fputs, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fputs, FD_API_WRITE_START,
+                                "sp", str, stream);
        ret = fputsp(str, stream);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fputs,
-                                 ret, ret, stream, FD_API_WRITE_END, "sp", str, stream);
+       FILE_API_END_BLOCK(API_ID_fputs, ret, ret, FD_API_WRITE_END,
+                               "sp", str, stream);
        return ret;
 }
 
@@ -377,10 +386,12 @@ int getc(FILE* stream)
        static int (*getcp)(FILE* stream);
 
        BEFORE_ORIGINAL_FILE(getc, LIBC);
-       FILE_API_START_BLOCK(API_ID_getc, FD_API_READ_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_getc, FD_API_READ_START,
+                                "p", stream);
        ret = getcp(stream);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_getc,
-                                 ret, (ret == EOF ? 0 : 1), stream, FD_API_READ_END, "p", stream);
+       FILE_API_END_BLOCK(API_ID_getc, ret, (ret != EOF),
+                               FD_API_READ_END, "p", stream);
        return ret;
 }
 
@@ -389,11 +400,12 @@ int putc(int character, FILE* stream)
        static int (*putcp)(int character, FILE* stream);
 
        BEFORE_ORIGINAL_FILE(putc, LIBC);
-       FILE_API_START_BLOCK(API_ID_putc, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_putc, FD_API_WRITE_START,
+                               "dp", character, stream);
        ret = putcp(character, stream);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_putc,
-                                 ret, (ret == EOF ? 0 : 1), stream, FD_API_WRITE_END,
-                                 "dp", character, stream);
+       FILE_API_END_BLOCK(API_ID_putc, ret, (ret != EOF),
+                               FD_API_WRITE_END, "dp", character, stream);
        return ret;
 }
 
@@ -402,9 +414,12 @@ int ungetc(int character, FILE* stream)
        static int (*ungetcp)(int character, FILE* stream);
 
        BEFORE_ORIGINAL_FILE(ungetc, LIBC);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_putc, FD_API_WRITE_START,
+                               "dp", character, stream);
        ret = ungetcp(character, stream);
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_ungetc,
-                                 ret, 0, stream, FD_API_OTHER, "dp", character, stream);
+       FILE_API_END_BLOCK(API_ID_ungetc, ret, 0,
+                               FD_API_OTHER, "dp", character, stream);
        return ret;
 }
 
@@ -414,14 +429,14 @@ size_t fread(void* ptr, size_t size, size_t count, FILE* stream)
        size_t tret;
 
        BEFORE_ORIGINAL_FILE(fread, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_fread, FD_API_READ_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fread, FD_API_READ_START,
+                               "pxxp", ptr, size, count, stream);
 
        tret = freadp(ptr, size, count, stream);
 
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fread,
-                                 tret, 0, stream, FD_API_READ_END,
-                                 "pxxp", ptr, size, count, stream);    
+       FILE_API_END_BLOCK(API_ID_fread, tret, tret*size, FD_API_READ_END,
+                                 "pxxp", ptr, size, count, stream);
 
        return tret;
 }
@@ -432,13 +447,13 @@ size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream)
        size_t tret;
 
        BEFORE_ORIGINAL_FILE(fwrite, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_fwrite, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fwrite, FD_API_WRITE_START,
+                               "pxxp", ptr, size, count, stream);
 
        tret = fwritep(ptr, size, count, stream);
 
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fwrite,
-                                 tret, 0, stream, FD_API_WRITE_END,
+       FILE_API_END_BLOCK(API_ID_fwrite, tret, tret*size, FD_API_WRITE_END,
                                  "pxxp", ptr, size, count, stream);
 
        return tret;
@@ -452,15 +467,16 @@ int fprintf(FILE* stream, const char* format, ...)
        static int (*vfprintfp)(FILE* stream, const char* format, ...);
 
        BEFORE_ORIGINAL_FILE(vfprintf, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_fprintf, FD_API_WRITE_START);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fprintf, FD_API_WRITE_START,
+                                "ps", stream, format);
 
        va_list arg;
        va_start(arg, format);
        ret = vfprintfp(stream, format, arg);
 
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fprintf,
-                                 ret, ret, stream, FD_API_WRITE_END, "ps", stream, format);
+       FILE_API_END_BLOCK(API_ID_fprintf, ret, ret, FD_API_WRITE_END,
+                               "ps", stream, format);
        va_end(arg);
 
        return ret;
@@ -469,17 +485,18 @@ int fprintf(FILE* stream, const char* format, ...)
 int fscanf(FILE* stream, const char* format, ...)
 {
        static int (*vfscanfp)(FILE* stream, const char* format, ...);
-       
-       BEFORE_ORIGINAL_FILE(vfscanf, LIBC);
 
-       FILE_API_START_BLOCK(API_ID_fscanf, FD_API_READ_START);
+       BEFORE_ORIGINAL_FILE(vfscanf, LIBC);
+       DEFINE_FILESIZE_FP(stream);
+       FILE_API_START_BLOCK(API_ID_fscanf, FD_API_READ_START,
+                                "ps", stream, format);
 
        va_list arg;
        va_start(arg, format);
        ret = vfscanfp(stream, format, arg);
 
-       AFTER_PACK_ORIGINAL_FILEP(API_ID_fscanf,
-                                 ret, ret, stream, FD_API_READ_END, "ps", stream, format);
+       FILE_API_END_BLOCK(API_ID_fscanf, ret, ret,
+                               FD_API_READ_END, "ps", stream, format);
        va_end(arg);
 
        return ret;
@@ -489,17 +506,18 @@ int fscanf(FILE* stream, const char* format, ...)
 int printf(const char* format, ...)
 {
        static int (*vprintfp)(const char* format, ...);
-       
-       BEFORE_ORIGINAL_FILE(vprintf, LIBC);
 
-       FILE_API_START_BLOCK(API_ID_printf, FD_API_WRITE_START);
+       BEFORE_ORIGINAL_FILE(vprintf, LIBC);
+       DEFINE_FILESIZE_0();
+       FILE_API_START_BLOCK(API_ID_printf, FD_API_WRITE_START,
+                                "s", format);
 
        va_list arg;
        va_start(arg, format);
        ret = vprintfp(format, arg);
 
-       AFTER_PACK_ORIGINAL_NOFD(API_ID_printf,
-                                ret, ret, FD_API_WRITE_END, "s", format);
+       FILE_API_END_BLOCK(API_ID_printf, ret, ret,
+                               FD_API_WRITE_END, "s", format);
        va_end(arg);
 
        return ret;
@@ -511,15 +529,16 @@ int scanf(const char* format, ...)
        static int (*vscanfp)(const char* format, ...);
 
        BEFORE_ORIGINAL_FILE(vscanf, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_scanf, FD_API_READ_START);
+       DEFINE_FILESIZE_0();
+       FILE_API_START_BLOCK(API_ID_scanf, FD_API_READ_START,
+                                "s", format);
 
        va_list arg;
        va_start(arg, format);
        ret = vscanfp(format, arg);
 
-       AFTER_PACK_ORIGINAL_NOFD(API_ID_scanf,
-                                ret, ret, FD_API_READ_END, "s", format);
+       FILE_API_END_BLOCK(API_ID_scanf, ret, ret,
+                                FD_API_READ_END, "s", format);
        va_end(arg);
 
        return ret;
@@ -530,10 +549,12 @@ int getchar()
        static int (*getcharp)();
 
        BEFORE_ORIGINAL_FILE(getchar, LIBC);
-       FILE_API_START_BLOCK(API_ID_getchar, FD_API_READ_START);
+       DEFINE_FILESIZE_0();
+       FILE_API_START_BLOCK(API_ID_getchar, FD_API_READ_START,
+                            "s", "");
        ret = getcharp();
-       AFTER_PACK_ORIGINAL_NOFD(API_ID_getchar,
-                                ret, (ret == EOF ? 0 : 1), FD_API_READ_END, "s", "");
+       FILE_API_END_BLOCK(API_ID_getchar, ret, (ret != EOF ),
+                               FD_API_READ_END, "", 0);
        return ret;
 }
 
@@ -542,10 +563,12 @@ int putchar(int c)
        static int (*putcharp)(int c);
 
        BEFORE_ORIGINAL_FILE(putchar, LIBC);
-       FILE_API_START_BLOCK(API_ID_putchar, FD_API_WRITE_START);
+       DEFINE_FILESIZE_0();
+       FILE_API_START_BLOCK(API_ID_putchar, FD_API_WRITE_START,
+                                  "d", c);
        ret = putcharp(c);
-       AFTER_PACK_ORIGINAL_NOFD(API_ID_putchar,
-                                ret, (ret == EOF ? 0 : 1), FD_API_WRITE_END, "d", c);
+       FILE_API_END_BLOCK(API_ID_putchar, ret, (ret != EOF),
+                               FD_API_WRITE_END, "d", c);
        return ret;
 }
 
@@ -555,13 +578,14 @@ char* gets(char* str)
        char* cret;
 
        BEFORE_ORIGINAL_FILE(gets, LIBC);
-
-       FILE_API_START_BLOCK(API_ID_gets, FD_API_READ_START);
+       DEFINE_FILESIZE_0();
+       FILE_API_START_BLOCK(API_ID_gets, FD_API_READ_START,
+                                "s", str);
 
        cret = getsp(str);
 
-       AFTER_PACK_ORIGINAL_NOFD(API_ID_gets,
-                                cret, strlen(cret), FD_API_READ_END, "s", str);
+       FILE_API_END_BLOCK(API_ID_gets, cret, strlen(cret),
+                               FD_API_READ_END, "s", str);
 
        return cret;
 }
@@ -572,10 +596,12 @@ int puts(const char* str)
        static int (*putsp)(const char* str);
 
        BEFORE_ORIGINAL_FILE(puts, LIBC);
-       FILE_API_START_BLOCK(API_ID_puts, FD_API_WRITE_START);
+       DEFINE_FILESIZE_0();
+       FILE_API_START_BLOCK(API_ID_puts, FD_API_WRITE_START,
+                            "s", str);
        ret = putsp(str);
-       AFTER_PACK_ORIGINAL_NOFD(API_ID_puts,
-                                ret, ret, FD_API_WRITE_END, "s", str);
+       FILE_API_END_BLOCK(API_ID_puts, ret, ret,
+                               FD_API_WRITE_END, "s", str);
        return ret;
 }
 #endif