From c771f540696f04599001b36055a04ee8808c9ec0 Mon Sep 17 00:00:00 2001 From: Vitaliy Cherepanov Date: Tue, 16 Sep 2014 11:35:36 +0400 Subject: [PATCH] [PROTO] add FD_API_RELEASE event now: 14)FD_API_LOCK_START event before original lock call 15)FD_API_LOCK_END event after original lock call 16)FD_API_LOCK_RELEASE event after original unlock call Change-Id: I8a44a8668fef77879b3af7b5eac1aba3af881766 Signed-off-by: Vitaliy Cherepanov --- helper/libdaprobe.c | 3 +++ include/binproto.h | 6 ++++++ include/daprobe.h | 2 +- include/probeinfo.h | 1 + probe_file/da_io.h | 40 ++++++++++++++++++++++++++++++++-------- probe_file/da_io_posix.c | 34 ++++++++++++++++++++++++++-------- 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/helper/libdaprobe.c b/helper/libdaprobe.c index bad63c8..5c57af2 100755 --- a/helper/libdaprobe.c +++ b/helper/libdaprobe.c @@ -780,6 +780,9 @@ int preBlockBegin(const void *caller, bool bFiltering, enum DaOptions option) { bool opt_nofilt; + if (gTraceInfo.socket.daemonSock == -1) + return 0; + if(gProbeBlockCount != 0 || gProbeDepth != 0) return 0; diff --git a/include/binproto.h b/include/binproto.h index d3be6d1..a1864ca 100644 --- a/include/binproto.h +++ b/include/binproto.h @@ -512,6 +512,12 @@ static char __attribute__((used)) *pack_ret(char *to, char ret_type, ...) } \ errno = (newerrno != 0) ? newerrno : olderrno +#define POST_PACK_PROBEBLOCK_ADD_END() \ + preBlockEnd(); \ + } \ + errno = (newerrno != 0) ? newerrno : olderrno + + /* int main(int argc, char **argv) */ /* { */ /* char buf[1024]; */ diff --git a/include/daprobe.h b/include/daprobe.h index a16d3bd..552ab42 100644 --- a/include/daprobe.h +++ b/include/daprobe.h @@ -188,7 +188,7 @@ typedef struct { int blockresult = 0; \ bool bfiltering = true; \ DECLARE_ERRNO_VARS; \ - int __attribute__((unused)) ret + int __attribute__((unused)) ret = 0 // declare variable for standard api (not tizen related api) without ret #define DECLARE_VARIABLE_STANDARD_NORET \ diff --git a/include/probeinfo.h b/include/probeinfo.h index 5700442..acb2a93 100755 --- a/include/probeinfo.h +++ b/include/probeinfo.h @@ -88,6 +88,7 @@ extern "C"{ #define FD_API_MANAGE 12 #define FD_API_LOCK_START 14 #define FD_API_LOCK_END 15 +#define FD_API_LOCK_RELEASE 16 #define SOCKET_API_FD_OPEN 0 diff --git a/probe_file/da_io.h b/probe_file/da_io.h index 2fe8264..06c9a88 100755 --- a/probe_file/da_io.h +++ b/probe_file/da_io.h @@ -122,6 +122,7 @@ * Watch out when reusing it somewhere else */ #define AFTER_PACK_ORIGINAL_FD(API_ID, RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...) \ +do { \ POST_PACK_PROBEBLOCK_BEGIN(); \ _fstatret = fstat(FD, &_statbuf); \ if (stat_regular_or_socket_p(&_statbuf)) { \ @@ -130,17 +131,34 @@ PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE); \ } \ - POST_PACK_PROBEBLOCK_END() + POST_PACK_PROBEBLOCK_END(); \ +} while(0) + +#define AFTER_PACK_ORIGINAL_FD_MIDDLE(API_ID, RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...) \ +do { \ + POST_PACK_PROBEBLOCK_BEGIN(); \ + _fstatret = fstat(FD, &_statbuf); \ + if (stat_regular_or_socket_p(&_statbuf)) { \ + PREPARE_LOCAL_BUF(); \ + PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__); \ + PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ + POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE); \ + } \ + POST_PACK_PROBEBLOCK_ADD_END(); \ +} while(0) #define AFTER_PACK_ORIGINAL_NOFD(API_ID, RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...) \ +do { \ POST_PACK_PROBEBLOCK_BEGIN(); \ PREPARE_LOCAL_BUF(); \ PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__); \ PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ POST_PACK_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE); \ - POST_PACK_PROBEBLOCK_END() + POST_PACK_PROBEBLOCK_END(); \ +} while(0) #define AFTER_PACK_ORIGINAL_FILEP(API_ID, RTYPE, RVAL, SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \ +do { \ POST_PACK_PROBEBLOCK_BEGIN(); \ GET_FD_FROM_FILEP(FILEP); \ if(_fd != -1) { \ @@ -150,7 +168,8 @@ PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__); \ PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE); \ - POST_PACK_PROBEBLOCK_END() + POST_PACK_PROBEBLOCK_END(); \ +} while(0) /*! * Macros {BEFORE,AFTER}_ORIGINAL_START_END_FD only used in {p,v,}{read,write} @@ -175,10 +194,10 @@ static inline bool stat_regular_or_socket_p(struct stat *buf) PACK_RESOURCE(0, FD, APITYPE, _filesize, _filepath); \ FLUSH_LOCAL_BUF(); \ } \ - PRE_PROBEBLOCK_END(); - + PRE_PROBEBLOCK_END(); \ #define AFTER_ORIGINAL_START_END_FD(API_ID, RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...) \ +do { \ POST_PACK_PROBEBLOCK_BEGIN(); \ setProbePoint(&probeInfo); \ _fstatret = fstat(FD, &_statbuf); \ @@ -189,7 +208,8 @@ static inline bool stat_regular_or_socket_p(struct stat *buf) PACK_RESOURCE(SIZE, FD, APITYPE, _filesize, _filepath); \ FLUSH_LOCAL_BUF(); \ } \ - POST_PACK_PROBEBLOCK_END(); + POST_PACK_PROBEBLOCK_END(); \ +} while(0) @@ -219,15 +239,18 @@ static inline bool stat_regular_or_socket_p(struct stat *buf) PRE_PROBEBLOCK_END() #define AFTER_ORIGINAL_START_END_NOFD(API_ID, RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...) \ +do { \ POST_PACK_PROBEBLOCK_BEGIN(); \ setProbePoint(&probeInfo); \ PREPARE_LOCAL_BUF(); \ PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__); \ PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ POST_PACK_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE); \ - POST_PACK_PROBEBLOCK_END() + POST_PACK_PROBEBLOCK_END(); \ +} while(0) #define AFTER_ORIGINAL_START_END_FILEP(API_ID, RTYPE, RVAL, SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \ +do { \ POST_PACK_PROBEBLOCK_BEGIN(); \ setProbePoint(&probeInfo); \ GET_FD_FROM_FILEP(FILEP); \ @@ -238,7 +261,8 @@ static inline bool stat_regular_or_socket_p(struct stat *buf) PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__); \ PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE); \ - POST_PACK_PROBEBLOCK_END() + POST_PACK_PROBEBLOCK_END(); \ +} while(0) static inline ssize_t get_fd_filesize(int fd) diff --git a/probe_file/da_io_posix.c b/probe_file/da_io_posix.c index ae10dad..7b7b675 100755 --- a/probe_file/da_io_posix.c +++ b/probe_file/da_io_posix.c @@ -400,11 +400,14 @@ ssize_t writev(int fd, const struct iovec *iov, int iovcnt) // ***************************************************************** // File Attributes APIs // ***************************************************************** - int fcntl(int fd, int cmd, ...) { static int (*fcntlp)(int fd, int cmd, ...); int arg = 0, api_type = FD_API_OTHER; + int64_t start = 0; + int64_t len = 0; + int type = 0; + int whence = 0; BEFORE_ORIGINAL_FILE(fcntl, LIBC); @@ -413,14 +416,12 @@ int fcntl(int fd, int cmd, ...) arg = va_arg(argl, int); va_end(argl); - ret = fcntlp(fd, cmd, arg); - if (cmd == F_SETLK || cmd == F_SETLKW) { struct flock *flock = (struct flock *)arg; - int type = flock->l_type; - int whence = flock->l_whence; - int64_t /*off_t*/ start = flock->l_start; - int64_t /*off_t*/ len = flock->l_len; + type = flock->l_type; + whence = flock->l_whence; + start = flock->l_start; + len = flock->l_len; switch (type) { case F_RDLCK: @@ -428,15 +429,32 @@ int fcntl(int fd, int cmd, ...) api_type = FD_API_LOCK_START; break; case F_UNLCK: - api_type = FD_API_LOCK_END; + api_type = FD_API_LOCK_RELEASE; break; } + } + /* before lock event */ + if (api_type == FD_API_LOCK_START) + AFTER_PACK_ORIGINAL_FD_MIDDLE(API_ID_fcntl, + 'd', ret, 0, fd, api_type, + "ddddxx", fd, cmd, type, + whence, start, len); + + /* call original lock function */ + ret = fcntlp(fd, cmd, arg); + + /* after lock event */ + if (api_type != FD_API_OTHER) { + if (api_type == FD_API_LOCK_START) + api_type = FD_API_LOCK_END; + /* pack FD_API_LOCK_END or FD_API_UNLOCK events */ AFTER_PACK_ORIGINAL_FD(API_ID_fcntl, 'd', ret, 0, fd, api_type, "ddddxx", fd, cmd, type, whence, start, len); } else { + /* pack FD_API_OTHER */ AFTER_PACK_ORIGINAL_FD(API_ID_fcntl, 'd', ret, 0, fd, api_type, "ddd", fd, cmd, arg); -- 2.7.4