~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to compiler-rt/lib/interception/interception.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
//      int foo(const char *bar, double baz);
36
36
// You'll need to:
37
37
//      1) define INTERCEPTOR(int, foo, const char *bar, double baz) { ... } in
38
 
//         your source file.
 
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.
61
67
 
62
68
// How it works:
63
69
// To replace system functions on Linux we just need to declare functions
81
87
// INTERCEPT_FUNCTION() is effectively a no-op on this system.
82
88
 
83
89
#if defined(__APPLE__)
 
90
#include <sys/cdefs.h>  // For __DARWIN_ALIAS_C().
84
91
 
85
92
// Just a pair of pointers.
86
93
struct interpose_substitution {
174
181
  extern "C" \
175
182
  INTERCEPTOR_ATTRIBUTE \
176
183
  ret_type WRAP(func)(__VA_ARGS__)
 
184
 
 
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__)
 
188
 
177
189
#else  // __APPLE__
178
 
#define INTERCEPTOR(ret_type, func, ...) \
179
 
  extern "C" ret_type func(__VA_ARGS__); \
 
190
 
 
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__)
183
196
 
 
197
#define INTERCEPTOR(ret_type, func, ...) \
 
198
  INTERCEPTOR_ZZZ(/*no symbol variants*/, ret_type, func, __VA_ARGS__)
 
199
 
 
200
#define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
 
201
  INTERCEPTOR_ZZZ(__DARWIN_ALIAS_C(func), ret_type, func, __VA_ARGS__)
 
202
 
184
203
// Override |overridee| with |overrider|.
185
204
#define OVERRIDE_FUNCTION(overridee, overrider) \
186
205
  INTERPOSER_2(overridee, WRAP(overrider))