#include <sys/socket.h>
#include "dahelper.h"
#include "api_id_mapping.h"
+#include "in_handler.h"
#define MSG_PROBE_MEMORY 0x0101
#define MSG_PROBE_UICONTROL 0x0102
#define PROBE_GET_ORIG(pd_p) (pd_p)->orig
#define PROBE_GET_FUNC(pd_p) (pd_p)->func
+#define PASS_PTR(pd) gen_type_t, &pd
+
#define PACK_INT32(val) \
BUF_PTR = pack_int32(BUF_PTR, val);
#define PACK_INT64(val) \
#define FUNC_TA8(t1, n1, ...) t1 n1, FUNC_TA7(__VA_ARGS__)
#define FUNC_TA9(t1, n1, ...) t1 n1, FUNC_TA8(__VA_ARGS__)
#define FUNC_TA10(t1, n1, ...) t1 n1, FUNC_TA9(__VA_ARGS__)
+#define FUNC_TA11(t1, n1, ...) t1 n1, FUNC_TA10(__VA_ARGS__)
+#define FUNC_TA12(t1, n1, ...) t1 n1, FUNC_TA11(__VA_ARGS__)
#define FUNC_TA_V0(...) void
#define FUNC_TA_V1(n1) n1
#define FUNC_TA_V8(t1, n1, ...) t1 n1, FUNC_TA_V7(__VA_ARGS__)
#define FUNC_TA_V9(t1, n1, ...) t1 n1, FUNC_TA_V8(__VA_ARGS__)
#define FUNC_TA_V10(t1, n1, ...) t1 n1, FUNC_TA_V9(__VA_ARGS__)
+#define FUNC_TA_V11(t1, n1, ...) t1 n1, FUNC_TA_V10(__VA_ARGS__)
+#define FUNC_TA_V12(t1, n1, ...) t1 n1, FUNC_TA_V11(__VA_ARGS__)
#define FUNC_TA_H0(...)
#define FUNC_TA_H1(t1, n1, ...) ,t1 n1
#define FUNC_TA_H8(t1, n1, ...) ,t1 n1 FUNC_TA_H7(__VA_ARGS__)
#define FUNC_TA_H9(t1, n1, ...) ,t1 n1 FUNC_TA_H8(__VA_ARGS__)
#define FUNC_TA_H10(t1, n1, ...) ,t1 n1 FUNC_TA_H9(__VA_ARGS__)
+#define FUNC_TA_H11(t1, n1, ...) ,t1 n1 FUNC_TA_H10(__VA_ARGS__)
+#define FUNC_TA_H12(t1, n1, ...) ,t1 n1 FUNC_TA_H11(__VA_ARGS__)
#define FUNC_TA_VAR0(...)
#define FUNC_TA_VAR1(n1) ,va_list args
#define FUNC_TA_VAR8(t1, n1, ...) ,t1 n1 FUNC_TA_VAR7(__VA_ARGS__)
#define FUNC_TA_VAR9(t1, n1, ...) ,t1 n1 FUNC_TA_VAR8(__VA_ARGS__)
#define FUNC_TA_VAR10(t1, n1, ...) ,t1 n1 FUNC_TA_VAR9(__VA_ARGS__)
+#define FUNC_TA_VAR11(t1, n1, ...) ,t1 n1 FUNC_TA_VAR10(__VA_ARGS__)
+#define FUNC_TA_VAR12(t1, n1, ...) ,t1 n1 FUNC_TA_VAR11(__VA_ARGS__)
#define FUNC_ARGS0(...)
-#define FUNC_ARGS1(t1, n1, ...) ,n1
-#define FUNC_ARGS2(t1, n1, ...) ,n1 FUNC_ARGS1(__VA_ARGS__)
-#define FUNC_ARGS3(t1, n1, ...) ,n1 FUNC_ARGS2(__VA_ARGS__)
-#define FUNC_ARGS4(t1, n1, ...) ,n1 FUNC_ARGS3(__VA_ARGS__)
-#define FUNC_ARGS5(t1, n1, ...) ,n1 FUNC_ARGS4(__VA_ARGS__)
-#define FUNC_ARGS6(t1, n1, ...) ,n1 FUNC_ARGS5(__VA_ARGS__)
-#define FUNC_ARGS7(t1, n1, ...) ,n1 FUNC_ARGS6(__VA_ARGS__)
-#define FUNC_ARGS8(t1, n1, ...) ,n1 FUNC_ARGS7(__VA_ARGS__)
-#define FUNC_ARGS9(t1, n1, ...) ,n1 FUNC_ARGS8(__VA_ARGS__)
-#define FUNC_ARGS10(t1, n1, ...) ,n1 FUNC_ARGS9(__VA_ARGS__)
+#define FUNC_ARGS1(t1, n1, ...) n1
+#define FUNC_ARGS2(t1, n1, ...) n1, FUNC_ARGS1(__VA_ARGS__)
+#define FUNC_ARGS3(t1, n1, ...) n1, FUNC_ARGS2(__VA_ARGS__)
+#define FUNC_ARGS4(t1, n1, ...) n1, FUNC_ARGS3(__VA_ARGS__)
+#define FUNC_ARGS5(t1, n1, ...) n1, FUNC_ARGS4(__VA_ARGS__)
+#define FUNC_ARGS6(t1, n1, ...) n1, FUNC_ARGS5(__VA_ARGS__)
+#define FUNC_ARGS7(t1, n1, ...) n1, FUNC_ARGS6(__VA_ARGS__)
+#define FUNC_ARGS8(t1, n1, ...) n1, FUNC_ARGS7(__VA_ARGS__)
+#define FUNC_ARGS9(t1, n1, ...) n1, FUNC_ARGS8(__VA_ARGS__)
+#define FUNC_ARGS10(t1, n1, ...) n1, FUNC_ARGS9(__VA_ARGS__)
+#define FUNC_ARGS11(t1, n1, ...) n1, FUNC_ARGS10(__VA_ARGS__)
+#define FUNC_ARGS12(t1, n1, ...) n1, FUNC_ARGS11(__VA_ARGS__)
#define FUNC_ARGS_VA0(...) args
-#define FUNC_ARGS_VA1(t1, n1, ...) ,n1, FUNC_ARGS_VA0(__VA_ARGS__)
-#define FUNC_ARGS_VA2(t1, n1, ...) ,n1 FUNC_ARGS_VA1(__VA_ARGS__)
-#define FUNC_ARGS_VA3(t1, n1, ...) ,n1 FUNC_ARGS_VA2(__VA_ARGS__)
-#define FUNC_ARGS_VA4(t1, n1, ...) ,n1 FUNC_ARGS_VA3(__VA_ARGS__)
-#define FUNC_ARGS_VA5(t1, n1, ...) ,n1 FUNC_ARGS_VA4(__VA_ARGS__)
-#define FUNC_ARGS_VA6(t1, n1, ...) ,n1 FUNC_ARGS_VA5(__VA_ARGS__)
-#define FUNC_ARGS_VA7(t1, n1, ...) ,n1 FUNC_ARGS_VA6(__VA_ARGS__)
-#define FUNC_ARGS_VA8(t1, n1, ...) ,n1 FUNC_ARGS_VA7(__VA_ARGS__)
-#define FUNC_ARGS_VA9(t1, n1, ...) ,n1 FUNC_ARGS_VA8(__VA_ARGS__)
-#define FUNC_ARGS_VA10(t1, n1, ...) ,n1 FUNC_ARGS_VA9(__VA_ARGS__)
+#define FUNC_ARGS_VA1(t1, n1, ...) n1, FUNC_ARGS_VA0(__VA_ARGS__)
+#define FUNC_ARGS_VA2(t1, n1, ...) n1, FUNC_ARGS_VA1(__VA_ARGS__)
+#define FUNC_ARGS_VA3(t1, n1, ...) n1, FUNC_ARGS_VA2(__VA_ARGS__)
+#define FUNC_ARGS_VA4(t1, n1, ...) n1, FUNC_ARGS_VA3(__VA_ARGS__)
+#define FUNC_ARGS_VA5(t1, n1, ...) n1, FUNC_ARGS_VA4(__VA_ARGS__)
+#define FUNC_ARGS_VA6(t1, n1, ...) n1, FUNC_ARGS_VA5(__VA_ARGS__)
+#define FUNC_ARGS_VA7(t1, n1, ...) n1, FUNC_ARGS_VA6(__VA_ARGS__)
+#define FUNC_ARGS_VA8(t1, n1, ...) n1, FUNC_ARGS_VA7(__VA_ARGS__)
+#define FUNC_ARGS_VA9(t1, n1, ...) n1, FUNC_ARGS_VA8(__VA_ARGS__)
+#define FUNC_ARGS_VA10(t1, n1, ...) n1, FUNC_ARGS_VA9(__VA_ARGS__)
+#define FUNC_ARGS_VA11(t1, n1, ...) n1, FUNC_ARGS_VA10(__VA_ARGS__)
+#define FUNC_ARGS_VA12(t1, n1, ...) n1, FUNC_ARGS_VA11(__VA_ARGS__)
#define FUNC_TA(...) \
CONCAT(FUNC_TA, N_ARG(__VA_ARGS__, C_SEQ_N())(__VA_ARGS__))
CONCAT(FUNC_ARGS_VA, N_ARG(__VA_ARGS__, C_SEQ_N())(__VA_ARGS__))
#define N_ARG(...) ARG_N(__VA_ARGS__)
#define ARG_N(_1n, _1t, _2n, _2t, _3n, _3t, _4n, _4t, _5n, _5t, _6n, _6t, _7n, \
- _7t, _8n, _8t, _9n, _9t, _10n, _10t, N, ...) N
-#define C_SEQ_N() 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0
-#define C_SEQ_NV() 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 0
+ _7t, _8n, _8t, _9n, _9t, _10n, _10t, _11n, _11t, _12n, _12t, N, ...) N
+#define C_SEQ_N() 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0
+#define C_SEQ_NV() 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 0
#define DEF_H(_ret_type, _func_name, ...) \
__pd.call_type = _call_type; \
__pd.orig = __orig; \
__pd.func = (void *)__orig; \
+ __orig_func_p = (orig_t)__orig; \
} while (0)
-#define GOT_DECLARE_VARS \
+#define GOT_DECLARE(_ret_type, ...) \
+ typedef _ret_type (*orig_t)(FUNC_TA(__VA_ARGS__)); \
unsigned long __caller; \
ElfW(Addr) __orig; \
+ orig_t __orig_func_p; \
struct probe_data_t __pd
+#define GOT_RUN_RETURN(_func_name, ...) \
+ if (is_in_handler()) \
+ return __orig_func_p(FUNC_ARGS(__VA_ARGS__)); \
+ else \
+ return CONCAT(_func_name, _handler)(FUNC_ARGS(PASS_PTR(__pd), \
+ __VA_ARGS__))
+
+#define GOT_RUN_RETURN_VA(_ret_name, _varg_param, _func_name, ...) \
+ va_start(args, _varg_param); \
+ if (is_in_handler()) \
+ _ret_name = __orig_func_p(FUNC_ARGS(__VA_ARGS__)); \
+ else \
+ _ret_name = CONCAT(_func_name, _handler)(FUNC_ARGS_VA( \
+ PASS_PTR(__pd),\
+ __VA_ARGS__)); \
+ va_end(args)
+
+#define GOT_RUN_VOID(_func_name, ...) \
+ if (is_in_handler()) \
+ __orig_func_p(FUNC_ARGS(__VA_ARGS__)); \
+ else \
+ CONCAT(_func_name, _handler)(FUNC_ARGS(PASS_PTR(__pd), \
+ __VA_ARGS__))
+
#define PRELOAD_PREPARE_TO_EXEC(_func_name) \
do { \
__func = dlsym(RTLD_DEFAULT, #_func_name); \
\
DEF_W(_ret_type, _func_name, __VA_ARGS__) \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
GOT_PREPARE_TO_EXEC(_feature, _func_name, INTERNAL_CALL); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- return CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ GOT_RUN_RETURN(_func_name, __VA_ARGS__); \
} \
\
DEF_WA(_ret_type, _func_name, __VA_ARGS__) \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
GOT_PREPARE_TO_EXEC(_feature ## _always, _func_name, EXTERNAL_CALL); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- return CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ GOT_RUN_RETURN(_func_name, __VA_ARGS__); \
} \
\
/* Wrapper to be called from kernel. Takes ret type, func name and args */ \
PRELOAD_DECLARE_VARS; \
PRELOAD_PREPARE_TO_EXEC(_func_name); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- return CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ return CONCAT(_func_name, _handler)(FUNC_ARGS(PASS_PTR(__pd), \
+ __VA_ARGS__)); \
} \
\
DEF_H(_ret_type, _func_name, __VA_ARGS__)
\
DEF_W(_ret_type, _func_name, __VA_ARGS__) \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
GOT_PREPARE_TO_EXEC(_feature, _func_name, INTERNAL_CALL); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ GOT_RUN_VOID(_func_name, __VA_ARGS__); \
} \
\
DEF_WA(_ret_type, _func_name, __VA_ARGS__) \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
GOT_PREPARE_TO_EXEC(_feature ## _always, _func_name, EXTERNAL_CALL); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ GOT_RUN_VOID(_func_name, __VA_ARGS__); \
} \
\
/* Wrapper to be called from kernel. Takes ret type, func name and args */ \
PRELOAD_DECLARE_VARS; \
PRELOAD_PREPARE_TO_EXEC(_func_name); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ CONCAT(_func_name, _handler)(FUNC_ARGS(PASS_PTR(__pd), __VA_ARGS__)); \
} \
\
DEF_H(_ret_type, _func_name, __VA_ARGS__)
\
DEF_WV(_ret_type, _func_name, __VA_ARGS__) \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
va_list args; \
_ret_type ret; \
\
GOT_PREPARE_TO_EXEC(_feature, _func_name, INTERNAL_CALL); \
- \
- va_start(args, _varg_param); \
- /* It is important not to have comma before FUNC_ARGS_VA macro */ \
- ret = CONCAT(_func_name, _handler)(&__pd FUNC_ARGS_VA(__VA_ARGS__)); \
- va_end(args); \
+ GOT_RUN_RETURN_VA(ret, _varg_param, _func_name, __VA_ARGS__); \
\
return ret; \
} \
\
DEF_WAV(_ret_type, _func_name, __VA_ARGS__) \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
va_list args; \
_ret_type ret; \
\
GOT_PREPARE_TO_EXEC(_feature ## _always, _func_name, EXTERNAL_CALL); \
- \
- va_start(args, _varg_param); \
- /* It is important not to have comma before FUNC_ARGS_VA macro */ \
- ret = CONCAT(_func_name, _handler)(&__pd FUNC_ARGS_VA(__VA_ARGS__)); \
- va_end(args); \
+ GOT_RUN_RETURN_VA(ret, _varg_param, _func_name, __VA_ARGS__); \
\
return ret; \
} \
PRELOAD_PREPARE_TO_EXEC(_func_name); \
\
va_start(args, _varg_param); \
- /* It is important not to have comma before FUNC_ARGS_VA macro */ \
- ret = CONCAT(_func_name, _handler)(&__pd FUNC_ARGS_VA(__VA_ARGS__)); \
+ ret = CONCAT(_func_name, _handler)(FUNC_ARGS_VA(PASS_PTR(__pd), \
+ __VA_ARGS__)); \
va_end(args); \
\
return ret; \
\
DEF_W(_ret_type, _func_name, __VA_ARGS__) throw _throw \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
GOT_PREPARE_TO_EXEC(_feature, _func_name, INTERNAL_CALL); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- return CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ GOT_RUN_RETURN(_func_name, __VA_ARGS__); \
} \
\
DEF_WA(_ret_type, _func_name, __VA_ARGS__) throw _throw \
{ \
- GOT_DECLARE_VARS; \
+ GOT_DECLARE(_ret_type, __VA_ARGS__); \
GOT_PREPARE_TO_EXEC(_feature ## _always, _func_name, EXTERNAL_CALL); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- return CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ GOT_RUN_RETURN(_func_name, __VA_ARGS__); \
} \
\
/* Wrapper to be called from kernel. Takes ret type, func name and args */ \
PRELOAD_DECLARE_VARS; \
PRELOAD_PREPARE_TO_EXEC(_func_name); \
\
- /* It is important not to have comma before FUNC_ARGS macro */ \
- return CONCAT(_func_name, _handler)(&__pd FUNC_ARGS(__VA_ARGS__)); \
+ return CONCAT(_func_name, _handler)(FUNC_ARGS(PASS_PTR(__pd), \
+ __VA_ARGS__)); \
} \
\
DEF_H(_ret_type, _func_name, __VA_ARGS__) throw _throw