OpenMPI  0.1.1
vt_libwrap.h
1 /**
2  * VampirTrace
3  * http://www.tu-dresden.de/zih/vampirtrace
4  *
5  * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6  *
7  * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8  * Centre, Federal Republic of Germany
9  *
10  * See the file COPYING in the package base directory for details
11  **/
12 
13 #ifndef _VT_LIBWRAP_H
14 #define _VT_LIBWRAP_H
15 
16 #include <stdlib.h>
17 
18 /* maximum number of shared libraries, which will be searched for the actual
19  library functions */
20 #define VT_LIBWRAP_MAX_SHLIBS 10
21 
22 /* default library wrapper attributes */
23 #define VT_LIBWRAP_ATTR_DEFAULT \
24  { 0, { NULL }, NULL, 0, NULL }
25 
26 /* library wrapper attributes with a pointer to an initializer function */
27 #define VT_LIBWRAP_ATTR_INITIALIZER(_init_func) \
28  { 0, { NULL }, NULL, 0, _init_func }
29 
30 /* miscellaneous constants */
31 #define VT_LIBWRAP_NULL NULL
32 #define VT_LIBWRAP_NOID -1
33 
34 /* initialize a wrapper function
35  It creates the library wrapper object, gets the pointer to the actual
36  library function, and assigns an unique identifier to the function.
37  It declares some additional variables, so it must be called right after
38  the declaration section of a wrapper function.
39  arguments:
40  _lw = library wrapper object
41  (VT_LIBWRAP_NULL indicates whose creation)
42  _lwattr = library wrapper attributes
43  _func = function name
44  _rettype = return type
45  _argtypes = argument types
46  _file = source code location (file)
47  _line = source code location (line) */
48 #define VT_LIBWRAP_FUNC_INIT(_lw, _lwattr, _func, _rettype, _argtypes, \
49  _file, _line) \
50  static _rettype (*VT_LIBWRAP_FUNC_PTR)_argtypes = VT_LIBWRAP_NULL; \
51  static int VT_LIBWRAP_FUNC_ID = VT_LIBWRAP_NOID; \
52  if( _lw == VT_LIBWRAP_NULL ) { \
53  VTLibwrap_create(&_lw, &_lwattr); \
54  } \
55  if( VT_LIBWRAP_FUNC_PTR == VT_LIBWRAP_NULL || \
56  VT_LIBWRAP_FUNC_ID == VT_LIBWRAP_NOID ) { \
57  VTLibwrap_func_init(_lw, _func, _file, _line, \
58  (void**)(&VT_LIBWRAP_FUNC_PTR), &VT_LIBWRAP_FUNC_ID); \
59  }
60 
61 /* The following macros are only available inside a wrapper function after
62  calling VT_LIBWRAP_FUNC_INIT. */
63 
64 /* variable name of pointer to the real function */
65 #define VT_LIBWRAP_FUNC_PTR _vtlw_funcptr
66 /* variable name of function identifier */
67 #define VT_LIBWRAP_FUNC_ID _vtlw_funcid
68 
69 /* trigger a function enter/leave event
70  (similarly to the VampirTrace API calls VT_USER_START/END)
71  argument:
72  _lw = library wrapper object */
73 #define VT_LIBWRAP_FUNC_START(_lw) VTLibwrap_func_start(_lw, VT_LIBWRAP_FUNC_ID)
74 #define VT_LIBWRAP_FUNC_END(_lw) VTLibwrap_func_end(_lw, VT_LIBWRAP_FUNC_ID)
75 
76 /* call the real function
77  arguments:
78  _lw = library wrapper object
79  _args = function arguments */
80 #define VT_LIBWRAP_FUNC_CALL(_lw, _args) (*VT_LIBWRAP_FUNC_PTR)_args
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif /* __cplusplus */
85 
86 /* typedef for "opaque" library wrapper object */
87 typedef struct VTLibwrap_struct VTLibwrap;
88 
89 /* typedef for library wrapper attributes */
90 typedef struct VTLibwrapAttr_struct VTLibwrapAttr;
91 
92 /* typedef for attribute initializer function pointer */
93 typedef void(*VTLibwrapAttrInitFunc)(VTLibwrapAttr*);
94 
95 /* data structure for the library wrapper attributes */
97 {
98  /* Number of shared libraries which will be searched for the actual library
99  functions. If 0 is specified, the addresses of the functions will be
100  searched in the shared libraries linked to the application, in order,
101  starting after the VampirTrace library. */
102  int shlibs_num;
103 
104  /* Array of pathnames to the shared libraries which will be searched for the
105  actual library functions. */
106  char* shlibs[VT_LIBWRAP_MAX_SHLIBS];
107 
108  /* Separate function group which will be assigned to all of the wrapped
109  functions. If no group specified (NULL), each wrapped function will be
110  assigned to the default group 'Application'. */
111  char* func_group;
112 
113  /* Wait for initialization of VampirTrace before generating events by the
114  wrapper functions (1=yes / 0=no) */
115  char wait_for_init;
116 
117  /* Pointer to a function which may be used to initialize the library wrapper
118  attributes above. It is called at the first wrapper event, if it is not
119  set to NULL. */
120  VTLibwrapAttrInitFunc init_func;
121 };
122 
123 /* VampirTrace internal functions */
124 
125 /* initialize library wrapper interface */
126 void vt_libwrap_init(void);
127 /* finalize library wrapper interface */
128 void vt_libwrap_finalize(void);
129 
130 /* load external LIBC and get its handle */
131 void* vt_libwrap_get_libc_handle(void);
132 /* set errno of external LIBC to given value */
133 void vt_libwrap_set_libc_errno(const int value);
134 /* get errno of external LIBC */
135 int vt_libwrap_get_libc_errno(void);
136 
137 /* create a library wrapper object
138  arguments:
139  lw = library wrapper object
140  (must be initialized by VT_LIBWRAP_NULL)
141  lwattr = library wrapper attributes */
142 void VTLibwrap_create(VTLibwrap** lw, VTLibwrapAttr* lwattr);
143 
144 /* delete a library wrapper object
145  arguments:
146  lw = library wrapper object */
147 void VTLibwrap_delete(VTLibwrap** lw);
148 
149 /* delete all library wrapper objects */
150 void VTLibwrap_delete_all(void);
151 
152 /* initialize a wrapper function
153  arguments:
154  lw = library wrapper object
155  func = function name
156  file = function location (file)
157  line = function location (line)
158  funcptr = pointer to real function (return)
159  funcid = function identifier (return) */
160 void VTLibwrap_func_init(const VTLibwrap* lw, const char* func,
161  const char* file, int line,
162  void** funcptr, int* funcid);
163 
164 /* trigger a function enter event
165  arguments:
166  lw = library wrapper object
167  funcid = function identifier */
168 void VTLibwrap_func_start(const VTLibwrap* lw, const int funcid);
169 
170 /* trigger a function leave event
171  arguments:
172  lw = library wrapper object
173  funcid = function identifier */
174 void VTLibwrap_func_end(const VTLibwrap* lw, const int funcid);
175 
176 #ifdef __cplusplus
177 }
178 #endif /* __cplusplus */
179 
180 #endif /* _VT_LIBWRAP_H */
Definition: vt_libwrap.c:43
Definition: vt_libwrap.h:96