35
35
// int foo(const char *bar, double baz);
37
37
// 1) define INTERCEPTOR(int, foo, const char *bar, double baz) { ... } in
38
// your source file. See the notes below for cases when
39
// INTERCEPTOR_WITH_SUFFIX(...) should be used instead.
39
40
// 2) Call "INTERCEPT_FUNCTION(foo)" prior to the first call of "foo".
40
41
// INTERCEPT_FUNCTION(foo) evaluates to "true" iff the function was
41
42
// intercepted successfully.
58
59
// but instead you'll have to add
59
60
// DECLARE_REAL(int, foo, const char *bar, double baz) in your
60
61
// source file (to define a pointer to overriden function).
62
// 3. Some Mac functions have symbol variants discriminated by
63
// additional suffixes, e.g. _$UNIX2003 (see
64
// https://developer.apple.com/library/mac/#releasenotes/Darwin/SymbolVariantsRelNotes/index.html
65
// for more details). To intercept such functions you need to use the
66
// INTERCEPTOR_WITH_SUFFIX(...) macro.
63
69
// To replace system functions on Linux we just need to declare functions
175
182
INTERCEPTOR_ATTRIBUTE \
176
183
ret_type WRAP(func)(__VA_ARGS__)
185
// We don't need INTERCEPTOR_WITH_SUFFIX on non-Darwin for now.
186
#define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
187
INTERCEPTOR(ret_type, func, __VA_ARGS__)
177
189
#else // __APPLE__
178
#define INTERCEPTOR(ret_type, func, ...) \
179
extern "C" ret_type func(__VA_ARGS__); \
191
#define INTERCEPTOR_ZZZ(suffix, ret_type, func, ...) \
192
extern "C" ret_type func(__VA_ARGS__) suffix; \
180
193
extern "C" ret_type WRAP(func)(__VA_ARGS__); \
181
194
INTERPOSER(func); \
182
195
extern "C" INTERCEPTOR_ATTRIBUTE ret_type WRAP(func)(__VA_ARGS__)
197
#define INTERCEPTOR(ret_type, func, ...) \
198
INTERCEPTOR_ZZZ(/*no symbol variants*/, ret_type, func, __VA_ARGS__)
200
#define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
201
INTERCEPTOR_ZZZ(__DARWIN_ALIAS_C(func), ret_type, func, __VA_ARGS__)
184
203
// Override |overridee| with |overrider|.
185
204
#define OVERRIDE_FUNCTION(overridee, overrider) \
186
205
INTERPOSER_2(overridee, WRAP(overrider))