ittnotify_static.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. /* <copyright>
  2. This file is provided under a dual BSD/GPLv2 license. When using or
  3. redistributing this file, you may do so under either license.
  4. GPL LICENSE SUMMARY
  5. Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License as
  8. published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. The full GNU General Public License is included in this distribution
  17. in the file called LICENSE.GPL.
  18. Contact Information:
  19. http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
  20. BSD LICENSE
  21. Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
  22. All rights reserved.
  23. Redistribution and use in source and binary forms, with or without
  24. modification, are permitted provided that the following conditions
  25. are met:
  26. * Redistributions of source code must retain the above copyright
  27. notice, this list of conditions and the following disclaimer.
  28. * Redistributions in binary form must reproduce the above copyright
  29. notice, this list of conditions and the following disclaimer in
  30. the documentation and/or other materials provided with the
  31. distribution.
  32. * Neither the name of Intel Corporation nor the names of its
  33. contributors may be used to endorse or promote products derived
  34. from this software without specific prior written permission.
  35. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  36. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  37. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  38. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  39. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  42. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  43. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  45. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. </copyright> */
  47. #include "ittnotify_config.h"
  48. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  49. #define PATH_MAX 512
  50. #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
  51. #include <limits.h>
  52. #include <dlfcn.h>
  53. #include <errno.h>
  54. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57. #include <stdarg.h>
  58. #include <string.h>
  59. #define INTEL_NO_MACRO_BODY
  60. #define INTEL_ITTNOTIFY_API_PRIVATE
  61. #include "ittnotify.h"
  62. #include "legacy/ittnotify.h"
  63. #include "disable_warnings.h"
  64. static const char api_version[] = API_VERSION "\0\n@(#) $Revision: 422936 $\n";
  65. #define _N_(n) ITT_JOIN(INTEL_ITTNOTIFY_PREFIX,n)
  66. #if ITT_OS==ITT_OS_WIN
  67. static const char* ittnotify_lib_name = "libittnotify.dll";
  68. #elif ITT_OS==ITT_OS_LINUX || ITT_OS==ITT_OS_FREEBSD
  69. static const char* ittnotify_lib_name = "libittnotify.so";
  70. #elif ITT_OS==ITT_OS_MAC
  71. static const char* ittnotify_lib_name = "libittnotify.dylib";
  72. #else
  73. #error Unsupported or unknown OS.
  74. #endif
  75. #ifdef __ANDROID__
  76. #include <android/log.h>
  77. #include <stdio.h>
  78. #include <unistd.h>
  79. #include <sys/types.h>
  80. #include <sys/stat.h>
  81. #include <fcntl.h>
  82. #include <linux/limits.h>
  83. #ifdef ITT_ANDROID_LOG
  84. #define ITT_ANDROID_LOG_TAG "INTEL_VTUNE_USERAPI"
  85. #define ITT_ANDROID_LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, ITT_ANDROID_LOG_TAG, __VA_ARGS__))
  86. #define ITT_ANDROID_LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, ITT_ANDROID_LOG_TAG, __VA_ARGS__))
  87. #define ITT_ANDROID_LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,ITT_ANDROID_LOG_TAG, __VA_ARGS__))
  88. #define ITT_ANDROID_LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG,ITT_ANDROID_LOG_TAG, __VA_ARGS__))
  89. #else
  90. #define ITT_ANDROID_LOGI(...)
  91. #define ITT_ANDROID_LOGW(...)
  92. #define ITT_ANDROID_LOGE(...)
  93. #define ITT_ANDROID_LOGD(...)
  94. #endif
  95. /* default location of userapi collector on Android */
  96. #define ANDROID_ITTNOTIFY_DEFAULT_PATH_MASK(x) "/data/data/com.intel.vtune/perfrun/lib" \
  97. #x "/runtime/libittnotify.so"
  98. #if ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_ARM
  99. #define ANDROID_ITTNOTIFY_DEFAULT_PATH ANDROID_ITTNOTIFY_DEFAULT_PATH_MASK(32)
  100. #else
  101. #define ANDROID_ITTNOTIFY_DEFAULT_PATH ANDROID_ITTNOTIFY_DEFAULT_PATH_MASK(64)
  102. #endif
  103. #endif
  104. #ifndef LIB_VAR_NAME
  105. #if ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_ARM
  106. #define LIB_VAR_NAME INTEL_LIBITTNOTIFY32
  107. #else
  108. #define LIB_VAR_NAME INTEL_LIBITTNOTIFY64
  109. #endif
  110. #endif /* LIB_VAR_NAME */
  111. #define ITT_MUTEX_INIT_AND_LOCK(p) { \
  112. if (!p.mutex_initialized) \
  113. { \
  114. if (__itt_interlocked_increment(&p.atomic_counter) == 1) \
  115. { \
  116. __itt_mutex_init(&p.mutex); \
  117. p.mutex_initialized = 1; \
  118. } \
  119. else \
  120. while (!p.mutex_initialized) \
  121. __itt_thread_yield(); \
  122. } \
  123. __itt_mutex_lock(&p.mutex); \
  124. }
  125. const int _N_(err) = 0;
  126. typedef int (__itt_init_ittlib_t)(const char*, __itt_group_id);
  127. /* this define used to control initialization function name. */
  128. #ifndef __itt_init_ittlib_name
  129. ITT_EXTERN_C int _N_(init_ittlib)(const char*, __itt_group_id);
  130. static __itt_init_ittlib_t* __itt_init_ittlib_ptr = _N_(init_ittlib);
  131. #define __itt_init_ittlib_name __itt_init_ittlib_ptr
  132. #endif /* __itt_init_ittlib_name */
  133. typedef void (__itt_fini_ittlib_t)(void);
  134. /* this define used to control finalization function name. */
  135. #ifndef __itt_fini_ittlib_name
  136. ITT_EXTERN_C void _N_(fini_ittlib)(void);
  137. static __itt_fini_ittlib_t* __itt_fini_ittlib_ptr = _N_(fini_ittlib);
  138. #define __itt_fini_ittlib_name __itt_fini_ittlib_ptr
  139. #endif /* __itt_fini_ittlib_name */
  140. /* building pointers to imported funcs */
  141. #undef ITT_STUBV
  142. #undef ITT_STUB
  143. #define ITT_STUB(api,type,name,args,params,ptr,group,format) \
  144. static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\
  145. typedef type api ITT_JOIN(_N_(name),_t) args; \
  146. ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END \
  147. static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args \
  148. { \
  149. __itt_init_ittlib_name(NULL, __itt_group_all); \
  150. if (ITTNOTIFY_NAME(name) && ITTNOTIFY_NAME(name) != ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init))) \
  151. return ITTNOTIFY_NAME(name) params; \
  152. else \
  153. return (type)0; \
  154. }
  155. #define ITT_STUBV(api,type,name,args,params,ptr,group,format) \
  156. static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\
  157. typedef type api ITT_JOIN(_N_(name),_t) args; \
  158. ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END \
  159. static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args \
  160. { \
  161. __itt_init_ittlib_name(NULL, __itt_group_all); \
  162. if (ITTNOTIFY_NAME(name) && ITTNOTIFY_NAME(name) != ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init))) \
  163. ITTNOTIFY_NAME(name) params; \
  164. else \
  165. return; \
  166. }
  167. #undef __ITT_INTERNAL_INIT
  168. #include "ittnotify_static.h"
  169. #undef ITT_STUB
  170. #undef ITT_STUBV
  171. #define ITT_STUB(api,type,name,args,params,ptr,group,format) \
  172. static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\
  173. typedef type api ITT_JOIN(_N_(name),_t) args; \
  174. ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END
  175. #define ITT_STUBV(api,type,name,args,params,ptr,group,format) \
  176. static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\
  177. typedef type api ITT_JOIN(_N_(name),_t) args; \
  178. ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END
  179. #define __ITT_INTERNAL_INIT
  180. #include "ittnotify_static.h"
  181. #undef __ITT_INTERNAL_INIT
  182. ITT_GROUP_LIST(group_list);
  183. #pragma pack(push, 8)
  184. typedef struct ___itt_group_alias
  185. {
  186. const char* env_var;
  187. __itt_group_id groups;
  188. } __itt_group_alias;
  189. static __itt_group_alias group_alias[] = {
  190. { "KMP_FOR_TPROFILE", (__itt_group_id)(__itt_group_control | __itt_group_thread | __itt_group_sync | __itt_group_mark) },
  191. { "KMP_FOR_TCHECK", (__itt_group_id)(__itt_group_control | __itt_group_thread | __itt_group_sync | __itt_group_fsync | __itt_group_mark | __itt_group_suppress) },
  192. { NULL, (__itt_group_none) },
  193. { api_version, (__itt_group_none) } /* !!! Just to avoid unused code elimination !!! */
  194. };
  195. #pragma pack(pop)
  196. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  197. #pragma warning(push)
  198. #pragma warning(disable: 4054) /* warning C4054: 'type cast' : from function pointer 'XXX' to data pointer 'void *' */
  199. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  200. static __itt_api_info api_list[] = {
  201. /* Define functions with static implementation */
  202. #undef ITT_STUB
  203. #undef ITT_STUBV
  204. #define ITT_STUB(api,type,name,args,params,nameindll,group,format) { ITT_TO_STR(ITT_JOIN(__itt_,nameindll)), (void**)(void*)&ITTNOTIFY_NAME(name), (void*)(size_t)&ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)), (void*)(size_t)&ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)), (__itt_group_id)(group)},
  205. #define ITT_STUBV ITT_STUB
  206. #define __ITT_INTERNAL_INIT
  207. #include "ittnotify_static.h"
  208. #undef __ITT_INTERNAL_INIT
  209. /* Define functions without static implementation */
  210. #undef ITT_STUB
  211. #undef ITT_STUBV
  212. #define ITT_STUB(api,type,name,args,params,nameindll,group,format) {ITT_TO_STR(ITT_JOIN(__itt_,nameindll)), (void**)(void*)&ITTNOTIFY_NAME(name), (void*)(size_t)&ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)), NULL, (__itt_group_id)(group)},
  213. #define ITT_STUBV ITT_STUB
  214. #include "ittnotify_static.h"
  215. {NULL, NULL, NULL, NULL, __itt_group_none}
  216. };
  217. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  218. #pragma warning(pop)
  219. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  220. static const char dll_path[PATH_MAX] = { 0 };
  221. /* static part descriptor which handles. all notification api attributes. */
  222. __itt_global _N_(_ittapi_global) = {
  223. ITT_MAGIC, /* identification info */
  224. ITT_MAJOR, ITT_MINOR, API_VERSION_BUILD, /* version info */
  225. 0, /* api_initialized */
  226. 0, /* mutex_initialized */
  227. 0, /* atomic_counter */
  228. MUTEX_INITIALIZER, /* mutex */
  229. NULL, /* dynamic library handle */
  230. NULL, /* error_handler */
  231. (const char**)&dll_path, /* dll_path_ptr */
  232. (__itt_api_info*)&api_list, /* api_list_ptr */
  233. NULL, /* next __itt_global */
  234. NULL, /* thread_list */
  235. NULL, /* domain_list */
  236. NULL, /* string_list */
  237. __itt_collection_normal /* collection state */
  238. };
  239. ITT_EXTERN_C __itt_global* _N_(get_ittapi_global)(void) { return &_N_(_ittapi_global); }
  240. typedef void (__itt_api_init_t)(__itt_global*, __itt_group_id);
  241. typedef void (__itt_api_fini_t)(__itt_global*);
  242. /* ========================================================================= */
  243. #ifdef ITT_NOTIFY_EXT_REPORT
  244. ITT_EXTERN_C void _N_(error_handler)(__itt_error_code, va_list args);
  245. #endif /* ITT_NOTIFY_EXT_REPORT */
  246. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  247. #pragma warning(push)
  248. #pragma warning(disable: 4055) /* warning C4055: 'type cast' : from data pointer 'void *' to function pointer 'XXX' */
  249. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  250. static void __itt_report_error(__itt_error_code code, ...)
  251. {
  252. va_list args;
  253. va_start(args, code);
  254. if (_N_(_ittapi_global).error_handler != NULL)
  255. {
  256. __itt_error_handler_t* handler = (__itt_error_handler_t*)(size_t)_N_(_ittapi_global).error_handler;
  257. handler(code, args);
  258. }
  259. #ifdef ITT_NOTIFY_EXT_REPORT
  260. _N_(error_handler)(code, args);
  261. #endif /* ITT_NOTIFY_EXT_REPORT */
  262. va_end(args);
  263. }
  264. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  265. #pragma warning(pop)
  266. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  267. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  268. static __itt_domain* ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(domain_createW),_init))(const wchar_t* name)
  269. {
  270. __itt_domain *h_tail = NULL, *h = NULL;
  271. if (name == NULL)
  272. {
  273. return NULL;
  274. }
  275. ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
  276. if (_N_(_ittapi_global).api_initialized)
  277. {
  278. if (ITTNOTIFY_NAME(domain_createW) && ITTNOTIFY_NAME(domain_createW) != ITT_VERSIONIZE(ITT_JOIN(_N_(domain_createW),_init)))
  279. {
  280. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  281. return ITTNOTIFY_NAME(domain_createW)(name);
  282. }
  283. }
  284. for (h_tail = NULL, h = _N_(_ittapi_global).domain_list; h != NULL; h_tail = h, h = h->next)
  285. {
  286. if (h->nameW != NULL && !wcscmp(h->nameW, name)) break;
  287. }
  288. if (h == NULL)
  289. {
  290. NEW_DOMAIN_W(&_N_(_ittapi_global),h,h_tail,name);
  291. }
  292. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  293. return h;
  294. }
  295. static __itt_domain* ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(domain_createA),_init))(const char* name)
  296. #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
  297. static __itt_domain* ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(domain_create),_init))(const char* name)
  298. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  299. {
  300. __itt_domain *h_tail = NULL, *h = NULL;
  301. if (name == NULL)
  302. {
  303. return NULL;
  304. }
  305. ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
  306. if (_N_(_ittapi_global).api_initialized)
  307. {
  308. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  309. if (ITTNOTIFY_NAME(domain_createA) && ITTNOTIFY_NAME(domain_createA) != ITT_VERSIONIZE(ITT_JOIN(_N_(domain_createA),_init)))
  310. {
  311. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  312. return ITTNOTIFY_NAME(domain_createA)(name);
  313. }
  314. #else
  315. if (ITTNOTIFY_NAME(domain_create) && ITTNOTIFY_NAME(domain_create) != ITT_VERSIONIZE(ITT_JOIN(_N_(domain_create),_init)))
  316. {
  317. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  318. return ITTNOTIFY_NAME(domain_create)(name);
  319. }
  320. #endif
  321. }
  322. for (h_tail = NULL, h = _N_(_ittapi_global).domain_list; h != NULL; h_tail = h, h = h->next)
  323. {
  324. if (h->nameA != NULL && !__itt_fstrcmp(h->nameA, name)) break;
  325. }
  326. if (h == NULL)
  327. {
  328. NEW_DOMAIN_A(&_N_(_ittapi_global),h,h_tail,name);
  329. }
  330. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  331. return h;
  332. }
  333. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  334. static __itt_string_handle* ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(string_handle_createW),_init))(const wchar_t* name)
  335. {
  336. __itt_string_handle *h_tail = NULL, *h = NULL;
  337. if (name == NULL)
  338. {
  339. return NULL;
  340. }
  341. ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
  342. if (_N_(_ittapi_global).api_initialized)
  343. {
  344. if (ITTNOTIFY_NAME(string_handle_createW) && ITTNOTIFY_NAME(string_handle_createW) != ITT_VERSIONIZE(ITT_JOIN(_N_(string_handle_createW),_init)))
  345. {
  346. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  347. return ITTNOTIFY_NAME(string_handle_createW)(name);
  348. }
  349. }
  350. for (h_tail = NULL, h = _N_(_ittapi_global).string_list; h != NULL; h_tail = h, h = h->next)
  351. {
  352. if (h->strW != NULL && !wcscmp(h->strW, name)) break;
  353. }
  354. if (h == NULL)
  355. {
  356. NEW_STRING_HANDLE_W(&_N_(_ittapi_global),h,h_tail,name);
  357. }
  358. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  359. return h;
  360. }
  361. static __itt_string_handle* ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(string_handle_createA),_init))(const char* name)
  362. #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
  363. static __itt_string_handle* ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(string_handle_create),_init))(const char* name)
  364. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  365. {
  366. __itt_string_handle *h_tail = NULL, *h = NULL;
  367. if (name == NULL)
  368. {
  369. return NULL;
  370. }
  371. ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
  372. if (_N_(_ittapi_global).api_initialized)
  373. {
  374. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  375. if (ITTNOTIFY_NAME(string_handle_createA) && ITTNOTIFY_NAME(string_handle_createA) != ITT_VERSIONIZE(ITT_JOIN(_N_(string_handle_createA),_init)))
  376. {
  377. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  378. return ITTNOTIFY_NAME(string_handle_createA)(name);
  379. }
  380. #else
  381. if (ITTNOTIFY_NAME(string_handle_create) && ITTNOTIFY_NAME(string_handle_create) != ITT_VERSIONIZE(ITT_JOIN(_N_(string_handle_create),_init)))
  382. {
  383. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  384. return ITTNOTIFY_NAME(string_handle_create)(name);
  385. }
  386. #endif
  387. }
  388. for (h_tail = NULL, h = _N_(_ittapi_global).string_list; h != NULL; h_tail = h, h = h->next)
  389. {
  390. if (h->strA != NULL && !__itt_fstrcmp(h->strA, name)) break;
  391. }
  392. if (h == NULL)
  393. {
  394. NEW_STRING_HANDLE_A(&_N_(_ittapi_global),h,h_tail,name);
  395. }
  396. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  397. return h;
  398. }
  399. /* -------------------------------------------------------------------------- */
  400. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(pause),_init))(void)
  401. {
  402. if (!_N_(_ittapi_global).api_initialized && _N_(_ittapi_global).thread_list == NULL)
  403. {
  404. __itt_init_ittlib_name(NULL, __itt_group_all);
  405. }
  406. if (ITTNOTIFY_NAME(pause) && ITTNOTIFY_NAME(pause) != ITT_VERSIONIZE(ITT_JOIN(_N_(pause),_init)))
  407. {
  408. ITTNOTIFY_NAME(pause)();
  409. }
  410. else
  411. {
  412. _N_(_ittapi_global).state = __itt_collection_paused;
  413. }
  414. }
  415. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(resume),_init))(void)
  416. {
  417. if (!_N_(_ittapi_global).api_initialized && _N_(_ittapi_global).thread_list == NULL)
  418. {
  419. __itt_init_ittlib_name(NULL, __itt_group_all);
  420. }
  421. if (ITTNOTIFY_NAME(resume) && ITTNOTIFY_NAME(resume) != ITT_VERSIONIZE(ITT_JOIN(_N_(resume),_init)))
  422. {
  423. ITTNOTIFY_NAME(resume)();
  424. }
  425. else
  426. {
  427. _N_(_ittapi_global).state = __itt_collection_normal;
  428. }
  429. }
  430. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  431. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameW),_init))(const wchar_t* name)
  432. {
  433. if (!_N_(_ittapi_global).api_initialized && _N_(_ittapi_global).thread_list == NULL)
  434. {
  435. __itt_init_ittlib_name(NULL, __itt_group_all);
  436. }
  437. if (ITTNOTIFY_NAME(thread_set_nameW) && ITTNOTIFY_NAME(thread_set_nameW) != ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameW),_init)))
  438. {
  439. ITTNOTIFY_NAME(thread_set_nameW)(name);
  440. }
  441. }
  442. static int ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thr_name_setW),_init))(const wchar_t* name, int namelen)
  443. {
  444. (void)namelen;
  445. ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameW),_init))(name);
  446. return 0;
  447. }
  448. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameA),_init))(const char* name)
  449. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  450. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_name),_init))(const char* name)
  451. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  452. {
  453. if (!_N_(_ittapi_global).api_initialized && _N_(_ittapi_global).thread_list == NULL)
  454. {
  455. __itt_init_ittlib_name(NULL, __itt_group_all);
  456. }
  457. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  458. if (ITTNOTIFY_NAME(thread_set_nameA) && ITTNOTIFY_NAME(thread_set_nameA) != ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameA),_init)))
  459. {
  460. ITTNOTIFY_NAME(thread_set_nameA)(name);
  461. }
  462. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  463. if (ITTNOTIFY_NAME(thread_set_name) && ITTNOTIFY_NAME(thread_set_name) != ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_name),_init)))
  464. {
  465. ITTNOTIFY_NAME(thread_set_name)(name);
  466. }
  467. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  468. }
  469. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  470. static int ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thr_name_setA),_init))(const char* name, int namelen)
  471. {
  472. (void)namelen;
  473. ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameA),_init))(name);
  474. return 0;
  475. }
  476. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  477. static int ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thr_name_set),_init))(const char* name, int namelen)
  478. {
  479. (void)namelen;
  480. ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_name),_init))(name);
  481. return 0;
  482. }
  483. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  484. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thread_ignore),_init))(void)
  485. {
  486. if (!_N_(_ittapi_global).api_initialized && _N_(_ittapi_global).thread_list == NULL)
  487. {
  488. __itt_init_ittlib_name(NULL, __itt_group_all);
  489. }
  490. if (ITTNOTIFY_NAME(thread_ignore) && ITTNOTIFY_NAME(thread_ignore) != ITT_VERSIONIZE(ITT_JOIN(_N_(thread_ignore),_init)))
  491. {
  492. ITTNOTIFY_NAME(thread_ignore)();
  493. }
  494. }
  495. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thr_ignore),_init))(void)
  496. {
  497. ITT_VERSIONIZE(ITT_JOIN(_N_(thread_ignore),_init))();
  498. }
  499. static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(enable_attach),_init))(void)
  500. {
  501. #ifdef __ANDROID__
  502. /*
  503. * if LIB_VAR_NAME env variable were set before then stay previous value
  504. * else set default path
  505. */
  506. setenv(ITT_TO_STR(LIB_VAR_NAME), ANDROID_ITTNOTIFY_DEFAULT_PATH, 0);
  507. #endif
  508. }
  509. /* -------------------------------------------------------------------------- */
  510. static const char* __itt_fsplit(const char* s, const char* sep, const char** out, int* len)
  511. {
  512. int i;
  513. int j;
  514. if (!s || !sep || !out || !len)
  515. return NULL;
  516. for (i = 0; s[i]; i++)
  517. {
  518. int b = 0;
  519. for (j = 0; sep[j]; j++)
  520. if (s[i] == sep[j])
  521. {
  522. b = 1;
  523. break;
  524. }
  525. if (!b)
  526. break;
  527. }
  528. if (!s[i])
  529. return NULL;
  530. *len = 0;
  531. *out = &s[i];
  532. for (; s[i]; i++, (*len)++)
  533. {
  534. int b = 0;
  535. for (j = 0; sep[j]; j++)
  536. if (s[i] == sep[j])
  537. {
  538. b = 1;
  539. break;
  540. }
  541. if (b)
  542. break;
  543. }
  544. for (; s[i]; i++)
  545. {
  546. int b = 0;
  547. for (j = 0; sep[j]; j++)
  548. if (s[i] == sep[j])
  549. {
  550. b = 1;
  551. break;
  552. }
  553. if (!b)
  554. break;
  555. }
  556. return &s[i];
  557. }
  558. /* This function return value of env variable that placed into static buffer.
  559. * !!! The same static buffer is used for subsequent calls. !!!
  560. * This was done to aviod dynamic allocation for few calls.
  561. * Actually we need this function only four times.
  562. */
  563. static const char* __itt_get_env_var(const char* name)
  564. {
  565. #define MAX_ENV_VALUE_SIZE 4086
  566. static char env_buff[MAX_ENV_VALUE_SIZE];
  567. static char* env_value = (char*)env_buff;
  568. if (name != NULL)
  569. {
  570. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  571. size_t max_len = MAX_ENV_VALUE_SIZE - (size_t)(env_value - env_buff);
  572. DWORD rc = GetEnvironmentVariableA(name, env_value, (DWORD)max_len);
  573. if (rc >= max_len)
  574. __itt_report_error(__itt_error_env_too_long, name, (size_t)rc - 1, (size_t)(max_len - 1));
  575. else if (rc > 0)
  576. {
  577. const char* ret = (const char*)env_value;
  578. env_value += rc + 1;
  579. return ret;
  580. }
  581. else
  582. {
  583. /* If environment variable is empty, GetEnvirornmentVariables()
  584. * returns zero (number of characters (not including terminating null),
  585. * and GetLastError() returns ERROR_SUCCESS. */
  586. DWORD err = GetLastError();
  587. if (err == ERROR_SUCCESS)
  588. return env_value;
  589. if (err != ERROR_ENVVAR_NOT_FOUND)
  590. __itt_report_error(__itt_error_cant_read_env, name, (int)err);
  591. }
  592. #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
  593. char* env = getenv(name);
  594. if (env != NULL)
  595. {
  596. size_t len = __itt_fstrnlen(env, MAX_ENV_VALUE_SIZE);
  597. size_t max_len = MAX_ENV_VALUE_SIZE - (size_t)(env_value - env_buff);
  598. if (len < max_len)
  599. {
  600. const char* ret = (const char*)env_value;
  601. __itt_fstrcpyn(env_value, max_len, env, len + 1);
  602. env_value += len + 1;
  603. return ret;
  604. } else
  605. __itt_report_error(__itt_error_env_too_long, name, (size_t)len, (size_t)(max_len - 1));
  606. }
  607. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  608. }
  609. return NULL;
  610. }
  611. static const char* __itt_get_lib_name(void)
  612. {
  613. const char* lib_name = __itt_get_env_var(ITT_TO_STR(LIB_VAR_NAME));
  614. #ifdef __ANDROID__
  615. if (lib_name == NULL)
  616. {
  617. #if ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_ARM
  618. const char* const marker_filename = "com.intel.itt.collector_lib_32";
  619. #else
  620. const char* const marker_filename = "com.intel.itt.collector_lib_64";
  621. #endif
  622. char system_wide_marker_filename[PATH_MAX] = {0};
  623. int itt_marker_file_fd = -1;
  624. ssize_t res = 0;
  625. res = snprintf(system_wide_marker_filename, PATH_MAX - 1, "%s%s", "/data/local/tmp/", marker_filename);
  626. if (res < 0)
  627. {
  628. ITT_ANDROID_LOGE("Unable to concatenate marker file string.");
  629. return lib_name;
  630. }
  631. itt_marker_file_fd = open(system_wide_marker_filename, O_RDONLY);
  632. if (itt_marker_file_fd == -1)
  633. {
  634. const pid_t my_pid = getpid();
  635. char cmdline_path[PATH_MAX] = {0};
  636. char package_name[PATH_MAX] = {0};
  637. char app_sandbox_file[PATH_MAX] = {0};
  638. int cmdline_fd = 0;
  639. ITT_ANDROID_LOGI("Unable to open system-wide marker file.");
  640. res = snprintf(cmdline_path, PATH_MAX - 1, "/proc/%d/cmdline", my_pid);
  641. if (res < 0)
  642. {
  643. ITT_ANDROID_LOGE("Unable to get cmdline path string.");
  644. return lib_name;
  645. }
  646. ITT_ANDROID_LOGI("CMD file: %s\n", cmdline_path);
  647. cmdline_fd = open(cmdline_path, O_RDONLY);
  648. if (cmdline_fd == -1)
  649. {
  650. ITT_ANDROID_LOGE("Unable to open %s file!", cmdline_path);
  651. return lib_name;
  652. }
  653. res = read(cmdline_fd, package_name, PATH_MAX - 1);
  654. if (res == -1)
  655. {
  656. ITT_ANDROID_LOGE("Unable to read %s file!", cmdline_path);
  657. res = close(cmdline_fd);
  658. if (res == -1)
  659. {
  660. ITT_ANDROID_LOGE("Unable to close %s file!", cmdline_path);
  661. }
  662. return lib_name;
  663. }
  664. res = close(cmdline_fd);
  665. if (res == -1)
  666. {
  667. ITT_ANDROID_LOGE("Unable to close %s file!", cmdline_path);
  668. return lib_name;
  669. }
  670. ITT_ANDROID_LOGI("Package name: %s\n", package_name);
  671. res = snprintf(app_sandbox_file, PATH_MAX - 1, "/data/data/%s/%s", package_name, marker_filename);
  672. if (res < 0)
  673. {
  674. ITT_ANDROID_LOGE("Unable to concatenate marker file string.");
  675. return lib_name;
  676. }
  677. ITT_ANDROID_LOGI("Lib marker file name: %s\n", app_sandbox_file);
  678. itt_marker_file_fd = open(app_sandbox_file, O_RDONLY);
  679. if (itt_marker_file_fd == -1)
  680. {
  681. ITT_ANDROID_LOGE("Unable to open app marker file!");
  682. return lib_name;
  683. }
  684. }
  685. {
  686. char itt_lib_name[PATH_MAX] = {0};
  687. res = read(itt_marker_file_fd, itt_lib_name, PATH_MAX - 1);
  688. if (res == -1)
  689. {
  690. ITT_ANDROID_LOGE("Unable to read %s file!", itt_marker_file_fd);
  691. res = close(itt_marker_file_fd);
  692. if (res == -1)
  693. {
  694. ITT_ANDROID_LOGE("Unable to close %s file!", itt_marker_file_fd);
  695. }
  696. return lib_name;
  697. }
  698. ITT_ANDROID_LOGI("ITT Lib path: %s", itt_lib_name);
  699. res = close(itt_marker_file_fd);
  700. if (res == -1)
  701. {
  702. ITT_ANDROID_LOGE("Unable to close %s file!", itt_marker_file_fd);
  703. return lib_name;
  704. }
  705. ITT_ANDROID_LOGI("Set env %s to %s", ITT_TO_STR(LIB_VAR_NAME), itt_lib_name);
  706. res = setenv(ITT_TO_STR(LIB_VAR_NAME), itt_lib_name, 0);
  707. if (res == -1)
  708. {
  709. ITT_ANDROID_LOGE("Unable to set env var!");
  710. return lib_name;
  711. }
  712. lib_name = __itt_get_env_var(ITT_TO_STR(LIB_VAR_NAME));
  713. ITT_ANDROID_LOGI("ITT Lib path from env: %s", lib_name);
  714. }
  715. }
  716. #endif
  717. return lib_name;
  718. }
  719. #ifndef min
  720. #define min(a,b) (a) < (b) ? (a) : (b)
  721. #endif /* min */
  722. static __itt_group_id __itt_get_groups(void)
  723. {
  724. register int i;
  725. __itt_group_id res = __itt_group_none;
  726. const char* var_name = "INTEL_ITTNOTIFY_GROUPS";
  727. const char* group_str = __itt_get_env_var(var_name);
  728. if (group_str != NULL)
  729. {
  730. unsigned int len;
  731. char gr[255];
  732. const char* chunk;
  733. while ((group_str = __itt_fsplit(group_str, ",; ", &chunk, (int *)&len)) != NULL)
  734. {
  735. unsigned int min_len = min(len, (int)(sizeof(gr) - 1));
  736. __itt_fstrcpyn(gr, sizeof(gr) - 1, chunk, min_len);
  737. gr[min_len] = 0;
  738. for (i = 0; group_list[i].name != NULL; i++)
  739. {
  740. if (!__itt_fstrcmp(gr, group_list[i].name))
  741. {
  742. res = (__itt_group_id)(res | group_list[i].id);
  743. break;
  744. }
  745. }
  746. }
  747. /* TODO: !!! Workaround for bug with warning for unknown group !!!
  748. * Should be fixed in new initialization scheme.
  749. * Now the following groups should be set always. */
  750. for (i = 0; group_list[i].id != __itt_group_none; i++)
  751. if (group_list[i].id != __itt_group_all &&
  752. group_list[i].id > __itt_group_splitter_min &&
  753. group_list[i].id < __itt_group_splitter_max)
  754. res = (__itt_group_id)(res | group_list[i].id);
  755. return res;
  756. }
  757. else
  758. {
  759. for (i = 0; group_alias[i].env_var != NULL; i++)
  760. if (__itt_get_env_var(group_alias[i].env_var) != NULL)
  761. return group_alias[i].groups;
  762. }
  763. return res;
  764. }
  765. static int __itt_lib_version(lib_t lib)
  766. {
  767. if (lib == NULL)
  768. return 0;
  769. if (__itt_get_proc(lib, "__itt_api_init"))
  770. return 2;
  771. if (__itt_get_proc(lib, "__itt_api_version"))
  772. return 1;
  773. return 0;
  774. }
  775. /* It's not used right now! Comment it out to avoid warnings.
  776. static void __itt_reinit_all_pointers(void)
  777. {
  778. register int i;
  779. // Fill all pointers with initial stubs
  780. for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
  781. *_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].init_func;
  782. }
  783. */
  784. static void __itt_nullify_all_pointers(void)
  785. {
  786. register int i;
  787. /* Nulify all pointers except domain_create and string_handle_create */
  788. for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
  789. *_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].null_func;
  790. }
  791. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  792. #pragma warning(push)
  793. #pragma warning(disable: 4054) /* warning C4054: 'type cast' : from function pointer 'XXX' to data pointer 'void *' */
  794. #pragma warning(disable: 4055) /* warning C4055: 'type cast' : from data pointer 'void *' to function pointer 'XXX' */
  795. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  796. ITT_EXTERN_C void _N_(fini_ittlib)(void)
  797. {
  798. __itt_api_fini_t* __itt_api_fini_ptr = NULL;
  799. static volatile TIDT current_thread = 0;
  800. if (_N_(_ittapi_global).api_initialized)
  801. {
  802. __itt_mutex_lock(&_N_(_ittapi_global).mutex);
  803. if (_N_(_ittapi_global).api_initialized)
  804. {
  805. if (current_thread == 0)
  806. {
  807. current_thread = __itt_thread_id();
  808. if (_N_(_ittapi_global).lib != NULL)
  809. {
  810. __itt_api_fini_ptr = (__itt_api_fini_t*)(size_t)__itt_get_proc(_N_(_ittapi_global).lib, "__itt_api_fini");
  811. }
  812. if (__itt_api_fini_ptr)
  813. {
  814. __itt_api_fini_ptr(&_N_(_ittapi_global));
  815. }
  816. __itt_nullify_all_pointers();
  817. /* TODO: !!! not safe !!! don't support unload so far.
  818. * if (_N_(_ittapi_global).lib != NULL)
  819. * __itt_unload_lib(_N_(_ittapi_global).lib);
  820. * _N_(_ittapi_global).lib = NULL;
  821. */
  822. _N_(_ittapi_global).api_initialized = 0;
  823. current_thread = 0;
  824. }
  825. }
  826. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  827. }
  828. }
  829. ITT_EXTERN_C int _N_(init_ittlib)(const char* lib_name, __itt_group_id init_groups)
  830. {
  831. register int i;
  832. __itt_group_id groups;
  833. #ifdef ITT_COMPLETE_GROUP
  834. __itt_group_id zero_group = __itt_group_none;
  835. #endif /* ITT_COMPLETE_GROUP */
  836. static volatile TIDT current_thread = 0;
  837. if (!_N_(_ittapi_global).api_initialized)
  838. {
  839. #ifndef ITT_SIMPLE_INIT
  840. ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
  841. #endif /* ITT_SIMPLE_INIT */
  842. if (!_N_(_ittapi_global).api_initialized)
  843. {
  844. if (current_thread == 0)
  845. {
  846. current_thread = __itt_thread_id();
  847. if (lib_name == NULL)
  848. {
  849. lib_name = __itt_get_lib_name();
  850. }
  851. groups = __itt_get_groups();
  852. if (groups != __itt_group_none || lib_name != NULL)
  853. {
  854. _N_(_ittapi_global).lib = __itt_load_lib((lib_name == NULL) ? ittnotify_lib_name : lib_name);
  855. if (_N_(_ittapi_global).lib != NULL)
  856. {
  857. __itt_api_init_t* __itt_api_init_ptr;
  858. int lib_version = __itt_lib_version(_N_(_ittapi_global).lib);
  859. switch (lib_version) {
  860. case 0:
  861. groups = __itt_group_legacy;
  862. case 1:
  863. /* Fill all pointers from dynamic library */
  864. for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
  865. {
  866. if (_N_(_ittapi_global).api_list_ptr[i].group & groups & init_groups)
  867. {
  868. *_N_(_ittapi_global).api_list_ptr[i].func_ptr = (void*)__itt_get_proc(_N_(_ittapi_global).lib, _N_(_ittapi_global).api_list_ptr[i].name);
  869. if (*_N_(_ittapi_global).api_list_ptr[i].func_ptr == NULL)
  870. {
  871. /* Restore pointers for function with static implementation */
  872. *_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].null_func;
  873. __itt_report_error(__itt_error_no_symbol, lib_name, _N_(_ittapi_global).api_list_ptr[i].name);
  874. #ifdef ITT_COMPLETE_GROUP
  875. zero_group = (__itt_group_id)(zero_group | _N_(_ittapi_global).api_list_ptr[i].group);
  876. #endif /* ITT_COMPLETE_GROUP */
  877. }
  878. }
  879. else
  880. *_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].null_func;
  881. }
  882. if (groups == __itt_group_legacy)
  883. {
  884. /* Compatibility with legacy tools */
  885. ITTNOTIFY_NAME(thread_ignore) = ITTNOTIFY_NAME(thr_ignore);
  886. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  887. ITTNOTIFY_NAME(sync_createA) = ITTNOTIFY_NAME(sync_set_nameA);
  888. ITTNOTIFY_NAME(sync_createW) = ITTNOTIFY_NAME(sync_set_nameW);
  889. #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
  890. ITTNOTIFY_NAME(sync_create) = ITTNOTIFY_NAME(sync_set_name);
  891. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  892. ITTNOTIFY_NAME(sync_prepare) = ITTNOTIFY_NAME(notify_sync_prepare);
  893. ITTNOTIFY_NAME(sync_cancel) = ITTNOTIFY_NAME(notify_sync_cancel);
  894. ITTNOTIFY_NAME(sync_acquired) = ITTNOTIFY_NAME(notify_sync_acquired);
  895. ITTNOTIFY_NAME(sync_releasing) = ITTNOTIFY_NAME(notify_sync_releasing);
  896. }
  897. #ifdef ITT_COMPLETE_GROUP
  898. for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
  899. if (_N_(_ittapi_global).api_list_ptr[i].group & zero_group)
  900. *_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].null_func;
  901. #endif /* ITT_COMPLETE_GROUP */
  902. break;
  903. case 2:
  904. __itt_api_init_ptr = (__itt_api_init_t*)(size_t)__itt_get_proc(_N_(_ittapi_global).lib, "__itt_api_init");
  905. if (__itt_api_init_ptr)
  906. __itt_api_init_ptr(&_N_(_ittapi_global), init_groups);
  907. break;
  908. }
  909. }
  910. else
  911. {
  912. __itt_nullify_all_pointers();
  913. __itt_report_error(__itt_error_no_module, lib_name,
  914. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  915. __itt_system_error()
  916. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  917. dlerror()
  918. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  919. );
  920. }
  921. }
  922. else
  923. {
  924. __itt_nullify_all_pointers();
  925. }
  926. _N_(_ittapi_global).api_initialized = 1;
  927. current_thread = 0;
  928. /* !!! Just to avoid unused code elimination !!! */
  929. if (__itt_fini_ittlib_ptr == _N_(fini_ittlib)) current_thread = 0;
  930. }
  931. }
  932. #ifndef ITT_SIMPLE_INIT
  933. __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
  934. #endif /* ITT_SIMPLE_INIT */
  935. }
  936. /* Evaluating if any function ptr is non empty and it's in init_groups */
  937. for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
  938. {
  939. if (*_N_(_ittapi_global).api_list_ptr[i].func_ptr != _N_(_ittapi_global).api_list_ptr[i].null_func &&
  940. _N_(_ittapi_global).api_list_ptr[i].group & init_groups)
  941. {
  942. return 1;
  943. }
  944. }
  945. return 0;
  946. }
  947. ITT_EXTERN_C __itt_error_handler_t* _N_(set_error_handler)(__itt_error_handler_t* handler)
  948. {
  949. __itt_error_handler_t* prev = (__itt_error_handler_t*)(size_t)_N_(_ittapi_global).error_handler;
  950. _N_(_ittapi_global).error_handler = (void*)(size_t)handler;
  951. return prev;
  952. }
  953. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  954. #pragma warning(pop)
  955. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */