1 
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _ITTNOTIFY_CONFIG_H_
11 #define _ITTNOTIFY_CONFIG_H_
12 
13 /** @cond exclude_from_documentation */
14 #ifndef ITT_OS_WIN
15 #define ITT_OS_WIN 1
16 #endif /* ITT_OS_WIN */
17 
18 #ifndef ITT_OS_LINUX
19 #define ITT_OS_LINUX 2
20 #endif /* ITT_OS_LINUX */
21 
22 #ifndef ITT_OS_MAC
23 #define ITT_OS_MAC 3
24 #endif /* ITT_OS_MAC */
25 
26 #ifndef ITT_OS_FREEBSD
27 #define ITT_OS_FREEBSD 4
28 #endif /* ITT_OS_FREEBSD */
29 
30 #ifndef ITT_OS
31 #if defined WIN32 || defined _WIN32
32 #define ITT_OS ITT_OS_WIN
33 #elif defined(__APPLE__) && defined(__MACH__)
34 #define ITT_OS ITT_OS_MAC
35 #elif defined(__FreeBSD__)
36 #define ITT_OS ITT_OS_FREEBSD
37 #else
38 #define ITT_OS ITT_OS_LINUX
39 #endif
40 #endif /* ITT_OS */
41 
42 #ifndef ITT_PLATFORM_WIN
43 #define ITT_PLATFORM_WIN 1
44 #endif /* ITT_PLATFORM_WIN */
45 
46 #ifndef ITT_PLATFORM_POSIX
47 #define ITT_PLATFORM_POSIX 2
48 #endif /* ITT_PLATFORM_POSIX */
49 
50 #ifndef ITT_PLATFORM_MAC
51 #define ITT_PLATFORM_MAC 3
52 #endif /* ITT_PLATFORM_MAC */
53 
54 #ifndef ITT_PLATFORM_FREEBSD
55 #define ITT_PLATFORM_FREEBSD 4
56 #endif /* ITT_PLATFORM_FREEBSD */
57 
58 #ifndef ITT_PLATFORM
59 #if ITT_OS == ITT_OS_WIN
60 #define ITT_PLATFORM ITT_PLATFORM_WIN
61 #elif ITT_OS == ITT_OS_MAC
62 #define ITT_PLATFORM ITT_PLATFORM_MAC
63 #elif ITT_OS == ITT_OS_FREEBSD
64 #define ITT_PLATFORM ITT_PLATFORM_FREEBSD
65 #else
66 #define ITT_PLATFORM ITT_PLATFORM_POSIX
67 #endif
68 #endif /* ITT_PLATFORM */
69 
70 #if defined(_UNICODE) && !defined(UNICODE)
71 #define UNICODE
72 #endif
73 
74 #include <stddef.h>
75 #if ITT_PLATFORM == ITT_PLATFORM_WIN
76 #include <tchar.h>
77 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
78 #include <stdint.h>
79 #if defined(UNICODE) || defined(_UNICODE)
80 #include <wchar.h>
81 #endif /* UNICODE || _UNICODE */
82 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
83 
84 #ifndef ITTAPI_CDECL
85 #if ITT_PLATFORM == ITT_PLATFORM_WIN
86 #define ITTAPI_CDECL __cdecl
87 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
88 #if defined _M_IX86 || defined __i386__
89 #define ITTAPI_CDECL __attribute__((cdecl))
90 #else /* _M_IX86 || __i386__ */
91 #define ITTAPI_CDECL /* actual only on x86 platform */
92 #endif /* _M_IX86 || __i386__ */
93 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
94 #endif /* ITTAPI_CDECL */
95 
96 #ifndef STDCALL
97 #if ITT_PLATFORM == ITT_PLATFORM_WIN
98 #define STDCALL __stdcall
99 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
100 #if defined _M_IX86 || defined __i386__
101 #define STDCALL __attribute__((stdcall))
102 #else /* _M_IX86 || __i386__ */
103 #define STDCALL /* supported only on x86 platform */
104 #endif /* _M_IX86 || __i386__ */
105 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
106 #endif /* STDCALL */
107 
108 #define ITTAPI ITTAPI_CDECL
109 #define LIBITTAPI ITTAPI_CDECL
110 
111 /* TODO: Temporary for compatibility! */
112 #define ITTAPI_CALL ITTAPI_CDECL
113 #define LIBITTAPI_CALL ITTAPI_CDECL
114 
115 #if ITT_PLATFORM == ITT_PLATFORM_WIN
116 /* use __forceinline (VC++ specific) */
117 #define ITT_INLINE __forceinline
118 #define ITT_INLINE_ATTRIBUTE /* nothing */
119 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
120 /*
121  * Generally, functions are not inlined unless optimization is specified.
122  * For functions declared inline, this attribute inlines the function even
123  * if no optimization level was specified.
124  */
125 #ifdef __STRICT_ANSI__
126 #define ITT_INLINE static
127 #define ITT_INLINE_ATTRIBUTE __attribute__((unused))
128 #else /* __STRICT_ANSI__ */
129 #define ITT_INLINE static inline
130 #define ITT_INLINE_ATTRIBUTE __attribute__((always_inline, unused))
131 #endif /* __STRICT_ANSI__ */
132 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
133 /** @endcond */
134 
135 #ifndef ITT_ARCH_IA32
136 #define ITT_ARCH_IA32 1
137 #endif /* ITT_ARCH_IA32 */
138 
139 #ifndef ITT_ARCH_IA32E
140 #define ITT_ARCH_IA32E 2
141 #endif /* ITT_ARCH_IA32E */
142 
143 /* Was there a magical reason we didn't have 3 here before? */
144 #ifndef ITT_ARCH_AARCH64
145 #define ITT_ARCH_AARCH64 3
146 #endif /* ITT_ARCH_AARCH64 */
147 
148 #ifndef ITT_ARCH_ARM
149 #define ITT_ARCH_ARM 4
150 #endif /* ITT_ARCH_ARM */
151 
152 #ifndef ITT_ARCH_PPC64
153 #define ITT_ARCH_PPC64 5
154 #endif /* ITT_ARCH_PPC64 */
155 
156 #ifndef ITT_ARCH_MIPS
157 #define ITT_ARCH_MIPS 6
158 #endif /* ITT_ARCH_MIPS */
159 
160 #ifndef ITT_ARCH_MIPS64
161 #define ITT_ARCH_MIPS64 6
162 #endif /* ITT_ARCH_MIPS64 */
163 
164 #ifndef ITT_ARCH_RISCV64
165 #define ITT_ARCH_RISCV64 7
166 #endif /* ITT_ARCH_RISCV64 */
167 
168 #ifndef ITT_ARCH
169 #if defined _M_IX86 || defined __i386__
170 #define ITT_ARCH ITT_ARCH_IA32
171 #elif defined _M_X64 || defined _M_AMD64 || defined __x86_64__
172 #define ITT_ARCH ITT_ARCH_IA32E
173 #elif defined _M_IA64 || defined __ia64__
174 #define ITT_ARCH ITT_ARCH_IA64
175 #elif defined _M_ARM || defined __arm__
176 #define ITT_ARCH ITT_ARCH_ARM
177 #elif defined __powerpc64__
178 #define ITT_ARCH ITT_ARCH_PPC64
179 #elif defined __aarch64__
180 #define ITT_ARCH ITT_ARCH_AARCH64
181 #elif defined __mips__ && !defined __mips64
182 #define ITT_ARCH ITT_ARCH_MIPS
183 #elif defined __mips__ && defined __mips64
184 #define ITT_ARCH ITT_ARCH_MIPS64
185 #elif defined __riscv && __riscv_xlen == 64
186 #define ITT_ARCH ITT_ARCH_RISCV64
187 #endif
188 #endif
189 
190 #ifdef __cplusplus
191 #define ITT_EXTERN_C extern "C"
192 #define ITT_EXTERN_C_BEGIN extern "C" {
193 #define ITT_EXTERN_C_END }
194 #else
195 #define ITT_EXTERN_C /* nothing */
196 #define ITT_EXTERN_C_BEGIN /* nothing */
197 #define ITT_EXTERN_C_END /* nothing */
198 #endif /* __cplusplus */
199 
200 #define ITT_TO_STR_AUX(x) #x
201 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
202 
203 #define __ITT_BUILD_ASSERT(expr, suffix)                                       \
204   do {                                                                         \
205     static char __itt_build_check_##suffix[(expr) ? 1 : -1];                   \
206     __itt_build_check_##suffix[0] = 0;                                         \
207   } while (0)
208 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
209 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
210 
211 #define ITT_MAGIC                                                              \
212   { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
213 
214 /* Replace with snapshot date YYYYMMDD for promotion build. */
215 #define API_VERSION_BUILD 20151119
216 
217 #ifndef API_VERSION_NUM
218 #define API_VERSION_NUM 0.0.0
219 #endif /* API_VERSION_NUM */
220 
221 #define API_VERSION                                                            \
222   "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) " (" ITT_TO_STR(              \
223       API_VERSION_BUILD) ")"
224 
225 /* OS communication functions */
226 #if ITT_PLATFORM == ITT_PLATFORM_WIN
227 #include <windows.h>
228 typedef HMODULE lib_t;
229 typedef DWORD TIDT;
230 typedef CRITICAL_SECTION mutex_t;
231 #define MUTEX_INITIALIZER                                                      \
232   { 0 }
233 #define strong_alias(name, aliasname) /* empty for Windows */
234 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
235 #include <dlfcn.h>
236 #if defined(UNICODE) || defined(_UNICODE)
237 #include <wchar.h>
238 #endif /* UNICODE */
239 #ifndef _GNU_SOURCE
240 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
241 #endif /* _GNU_SOURCE */
242 #ifndef __USE_UNIX98
243 #define __USE_UNIX98                                                           \
244   1 /* need for PTHREAD_MUTEX_RECURSIVE, on SLES11.1 with gcc 4.3.4 wherein    \
245        pthread.h missing dependency on __USE_XOPEN2K8 */
246 #endif /*__USE_UNIX98*/
247 #include <pthread.h>
248 typedef void *lib_t;
249 typedef pthread_t TIDT;
250 typedef pthread_mutex_t mutex_t;
251 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
252 #define _strong_alias(name, aliasname)                                         \
253   extern __typeof(name) aliasname __attribute__((alias(#name)));
254 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
255 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
256 
257 #if ITT_PLATFORM == ITT_PLATFORM_WIN
258 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
259 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
260 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
261 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
262 #define __itt_load_lib(name) LoadLibraryA(name)
263 #define __itt_unload_lib(handle) FreeLibrary(handle)
264 #define __itt_system_error() (int)GetLastError()
265 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
266 #define __itt_fstrnlen(s, l) strnlen_s(s, l)
267 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
268 #define __itt_fstrdup(s) _strdup(s)
269 #define __itt_thread_id() GetCurrentThreadId()
270 #define __itt_thread_yield() SwitchToThread()
271 #ifndef ITT_SIMPLE_INIT
272 ITT_INLINE long
273 __itt_interlocked_increment(volatile long *ptr) ITT_INLINE_ATTRIBUTE;
274 ITT_INLINE long __itt_interlocked_increment(volatile long *ptr) {
275   return InterlockedIncrement(ptr);
276 }
277 #endif /* ITT_SIMPLE_INIT */
278 
279 #define DL_SYMBOLS (1)
280 #define PTHREAD_SYMBOLS (1)
281 
282 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
283 #define __itt_get_proc(lib, name) dlsym(lib, name)
284 #define __itt_mutex_init(mutex)                                                \
285   {                                                                            \
286     pthread_mutexattr_t mutex_attr;                                            \
287     int error_code = pthread_mutexattr_init(&mutex_attr);                      \
288     if (error_code)                                                            \
289       __itt_report_error(__itt_error_system, "pthread_mutexattr_init",         \
290                          error_code);                                          \
291     error_code =                                                               \
292         pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);       \
293     if (error_code)                                                            \
294       __itt_report_error(__itt_error_system, "pthread_mutexattr_settype",      \
295                          error_code);                                          \
296     error_code = pthread_mutex_init(mutex, &mutex_attr);                       \
297     if (error_code)                                                            \
298       __itt_report_error(__itt_error_system, "pthread_mutex_init",             \
299                          error_code);                                          \
300     error_code = pthread_mutexattr_destroy(&mutex_attr);                       \
301     if (error_code)                                                            \
302       __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy",      \
303                          error_code);                                          \
304   }
305 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
306 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
307 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
308 #define __itt_unload_lib(handle) dlclose(handle)
309 #define __itt_system_error() errno
310 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
311 
312 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
313 #ifdef SDL_STRNLEN_S
314 #define __itt_fstrnlen(s, l) SDL_STRNLEN_S(s, l)
315 #else
316 #define __itt_fstrnlen(s, l) strlen(s)
317 #endif /* SDL_STRNLEN_S */
318 #ifdef SDL_STRNCPY_S
319 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
320 #else
321 #define __itt_fstrcpyn(s1, b, s2, l) strncpy(s1, s2, l)
322 #endif /* SDL_STRNCPY_S */
323 
324 #define __itt_fstrdup(s) strdup(s)
325 #define __itt_thread_id() pthread_self()
326 #define __itt_thread_yield() sched_yield()
327 #if ITT_ARCH == ITT_ARCH_IA64
328 #ifdef __INTEL_COMPILER
329 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
330 #else /* __INTEL_COMPILER */
331 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
332 #endif /* __INTEL_COMPILER */
333 #elif ITT_ARCH == ITT_ARCH_IA32 ||                                             \
334     ITT_ARCH == ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
335 ITT_INLINE long __TBB_machine_fetchadd4(volatile void *ptr,
336                                         long addend) ITT_INLINE_ATTRIBUTE;
337 ITT_INLINE long __TBB_machine_fetchadd4(volatile void *ptr, long addend) {
338   long result;
339   __asm__ __volatile__("lock\nxadd %0,%1"
340                        : "=r"(result), "=m"(*(volatile int *)ptr)
341                        : "0"(addend), "m"(*(volatile int *)ptr)
342                        : "memory");
343   return result;
344 }
345 #elif ITT_ARCH == ITT_ARCH_ARM || ITT_ARCH == ITT_ARCH_PPC64 ||                \
346     ITT_ARCH == ITT_ARCH_AARCH64 || ITT_ARCH == ITT_ARCH_MIPS ||               \
347     ITT_ARCH == ITT_ARCH_MIPS64 || ITT_ARCH == ITT_ARCH_RISCV64
348 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
349 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
350 #ifndef ITT_SIMPLE_INIT
351 ITT_INLINE long
352 __itt_interlocked_increment(volatile long *ptr) ITT_INLINE_ATTRIBUTE;
353 ITT_INLINE long __itt_interlocked_increment(volatile long *ptr) {
354   return __TBB_machine_fetchadd4(ptr, 1) + 1L;
355 }
356 #endif /* ITT_SIMPLE_INIT */
357 
358 void *dlopen(const char *, int) __attribute__((weak));
359 void *dlsym(void *, const char *) __attribute__((weak));
360 int dlclose(void *) __attribute__((weak));
361 #define DL_SYMBOLS (dlopen && dlsym && dlclose)
362 
363 int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *)
364     __attribute__((weak));
365 int pthread_mutex_lock(pthread_mutex_t *) __attribute__((weak));
366 int pthread_mutex_unlock(pthread_mutex_t *) __attribute__((weak));
367 int pthread_mutex_destroy(pthread_mutex_t *) __attribute__((weak));
368 int pthread_mutexattr_init(pthread_mutexattr_t *) __attribute__((weak));
369 int pthread_mutexattr_settype(pthread_mutexattr_t *, int) __attribute__((weak));
370 int pthread_mutexattr_destroy(pthread_mutexattr_t *) __attribute__((weak));
371 pthread_t pthread_self(void) __attribute__((weak));
372 #define PTHREAD_SYMBOLS                                                        \
373   (pthread_mutex_init && pthread_mutex_lock && pthread_mutex_unlock &&         \
374    pthread_mutex_destroy && pthread_mutexattr_init &&                          \
375    pthread_mutexattr_settype && pthread_mutexattr_destroy && pthread_self)
376 
377 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
378 
379 typedef enum {
380   __itt_collection_normal = 0,
381   __itt_collection_paused = 1
382 } __itt_collection_state;
383 
384 typedef enum {
385   __itt_thread_normal = 0,
386   __itt_thread_ignored = 1
387 } __itt_thread_state;
388 
389 #pragma pack(push, 8)
390 
391 typedef struct ___itt_thread_info {
392   const char *nameA; /*!< Copy of original name in ASCII. */
393 #if defined(UNICODE) || defined(_UNICODE)
394   const wchar_t *nameW; /*!< Copy of original name in UNICODE. */
395 #else /* UNICODE || _UNICODE */
396   void *nameW;
397 #endif /* UNICODE || _UNICODE */
398   TIDT tid;
399   __itt_thread_state state; /*!< Thread state (paused or normal) */
400   int extra1; /*!< Reserved to the runtime */
401   void *extra2; /*!< Reserved to the runtime */
402   struct ___itt_thread_info *next;
403 } __itt_thread_info;
404 
405 #include "ittnotify_types.h" /* For __itt_group_id definition */
406 
407 typedef struct ___itt_api_info_20101001 {
408   const char *name;
409   void **func_ptr;
410   void *init_func;
411   __itt_group_id group;
412 } __itt_api_info_20101001;
413 
414 typedef struct ___itt_api_info {
415   const char *name;
416   void **func_ptr;
417   void *init_func;
418   void *null_func;
419   __itt_group_id group;
420 } __itt_api_info;
421 
422 typedef struct __itt_counter_info {
423   const char *nameA; /*!< Copy of original name in ASCII. */
424 #if defined(UNICODE) || defined(_UNICODE)
425   const wchar_t *nameW; /*!< Copy of original name in UNICODE. */
426 #else /* UNICODE || _UNICODE */
427   void *nameW;
428 #endif /* UNICODE || _UNICODE */
429   const char *domainA; /*!< Copy of original name in ASCII. */
430 #if defined(UNICODE) || defined(_UNICODE)
431   const wchar_t *domainW; /*!< Copy of original name in UNICODE. */
432 #else /* UNICODE || _UNICODE */
433   void *domainW;
434 #endif /* UNICODE || _UNICODE */
435   int type;
436   long index;
437   int extra1; /*!< Reserved to the runtime */
438   void *extra2; /*!< Reserved to the runtime */
439   struct __itt_counter_info *next;
440 } __itt_counter_info_t;
441 
442 struct ___itt_domain;
443 struct ___itt_string_handle;
444 
445 typedef struct ___itt_global {
446   unsigned char magic[8];
447   unsigned long version_major;
448   unsigned long version_minor;
449   unsigned long version_build;
450   volatile long api_initialized;
451   volatile long mutex_initialized;
452   volatile long atomic_counter;
453   mutex_t mutex;
454   lib_t lib;
455   void *error_handler;
456   const char **dll_path_ptr;
457   __itt_api_info *api_list_ptr;
458   struct ___itt_global *next;
459   /* Joinable structures below */
460   __itt_thread_info *thread_list;
461   struct ___itt_domain *domain_list;
462   struct ___itt_string_handle *string_list;
463   __itt_collection_state state;
464   __itt_counter_info_t *counter_list;
465 } __itt_global;
466 
467 #pragma pack(pop)
468 
469 #define NEW_THREAD_INFO_W(gptr, h, h_tail, t, s, n)                            \
470   {                                                                            \
471     h = (__itt_thread_info *)malloc(sizeof(__itt_thread_info));                \
472     if (h != NULL) {                                                           \
473       h->tid = t;                                                              \
474       h->nameA = NULL;                                                         \
475       h->nameW = n ? _wcsdup(n) : NULL;                                        \
476       h->state = s;                                                            \
477       h->extra1 = 0; /* reserved */                                            \
478       h->extra2 = NULL; /* reserved */                                         \
479       h->next = NULL;                                                          \
480       if (h_tail == NULL)                                                      \
481         (gptr)->thread_list = h;                                               \
482       else                                                                     \
483         h_tail->next = h;                                                      \
484     }                                                                          \
485   }
486 
487 #define NEW_THREAD_INFO_A(gptr, h, h_tail, t, s, n)                            \
488   {                                                                            \
489     h = (__itt_thread_info *)malloc(sizeof(__itt_thread_info));                \
490     if (h != NULL) {                                                           \
491       h->tid = t;                                                              \
492       h->nameA = n ? __itt_fstrdup(n) : NULL;                                  \
493       h->nameW = NULL;                                                         \
494       h->state = s;                                                            \
495       h->extra1 = 0; /* reserved */                                            \
496       h->extra2 = NULL; /* reserved */                                         \
497       h->next = NULL;                                                          \
498       if (h_tail == NULL)                                                      \
499         (gptr)->thread_list = h;                                               \
500       else                                                                     \
501         h_tail->next = h;                                                      \
502     }                                                                          \
503   }
504 
505 #define NEW_DOMAIN_W(gptr, h, h_tail, name)                                    \
506   {                                                                            \
507     h = (__itt_domain *)malloc(sizeof(__itt_domain));                          \
508     if (h != NULL) {                                                           \
509       h->flags = 1; /* domain is enabled by default */                         \
510       h->nameA = NULL;                                                         \
511       h->nameW = name ? _wcsdup(name) : NULL;                                  \
512       h->extra1 = 0; /* reserved */                                            \
513       h->extra2 = NULL; /* reserved */                                         \
514       h->next = NULL;                                                          \
515       if (h_tail == NULL)                                                      \
516         (gptr)->domain_list = h;                                               \
517       else                                                                     \
518         h_tail->next = h;                                                      \
519     }                                                                          \
520   }
521 
522 #define NEW_DOMAIN_A(gptr, h, h_tail, name)                                    \
523   {                                                                            \
524     h = (__itt_domain *)malloc(sizeof(__itt_domain));                          \
525     if (h != NULL) {                                                           \
526       h->flags = 1; /* domain is enabled by default */                         \
527       h->nameA = name ? __itt_fstrdup(name) : NULL;                            \
528       h->nameW = NULL;                                                         \
529       h->extra1 = 0; /* reserved */                                            \
530       h->extra2 = NULL; /* reserved */                                         \
531       h->next = NULL;                                                          \
532       if (h_tail == NULL)                                                      \
533         (gptr)->domain_list = h;                                               \
534       else                                                                     \
535         h_tail->next = h;                                                      \
536     }                                                                          \
537   }
538 
539 #define NEW_STRING_HANDLE_W(gptr, h, h_tail, name)                             \
540   {                                                                            \
541     h = (__itt_string_handle *)malloc(sizeof(__itt_string_handle));            \
542     if (h != NULL) {                                                           \
543       h->strA = NULL;                                                          \
544       h->strW = name ? _wcsdup(name) : NULL;                                   \
545       h->extra1 = 0; /* reserved */                                            \
546       h->extra2 = NULL; /* reserved */                                         \
547       h->next = NULL;                                                          \
548       if (h_tail == NULL)                                                      \
549         (gptr)->string_list = h;                                               \
550       else                                                                     \
551         h_tail->next = h;                                                      \
552     }                                                                          \
553   }
554 
555 #define NEW_STRING_HANDLE_A(gptr, h, h_tail, name)                             \
556   {                                                                            \
557     h = (__itt_string_handle *)malloc(sizeof(__itt_string_handle));            \
558     if (h != NULL) {                                                           \
559       h->strA = name ? __itt_fstrdup(name) : NULL;                             \
560       h->strW = NULL;                                                          \
561       h->extra1 = 0; /* reserved */                                            \
562       h->extra2 = NULL; /* reserved */                                         \
563       h->next = NULL;                                                          \
564       if (h_tail == NULL)                                                      \
565         (gptr)->string_list = h;                                               \
566       else                                                                     \
567         h_tail->next = h;                                                      \
568     }                                                                          \
569   }
570 
571 #define NEW_COUNTER_W(gptr, h, h_tail, name, domain, type)                     \
572   {                                                                            \
573     h = (__itt_counter_info_t *)malloc(sizeof(__itt_counter_info_t));          \
574     if (h != NULL) {                                                           \
575       h->nameA = NULL;                                                         \
576       h->nameW = name ? _wcsdup(name) : NULL;                                  \
577       h->domainA = NULL;                                                       \
578       h->domainW = name ? _wcsdup(domain) : NULL;                              \
579       h->type = type;                                                          \
580       h->index = 0;                                                            \
581       h->next = NULL;                                                          \
582       if (h_tail == NULL)                                                      \
583         (gptr)->counter_list = h;                                              \
584       else                                                                     \
585         h_tail->next = h;                                                      \
586     }                                                                          \
587   }
588 
589 #define NEW_COUNTER_A(gptr, h, h_tail, name, domain, type)                     \
590   {                                                                            \
591     h = (__itt_counter_info_t *)malloc(sizeof(__itt_counter_info_t));          \
592     if (h != NULL) {                                                           \
593       h->nameA = name ? __itt_fstrdup(name) : NULL;                            \
594       h->nameW = NULL;                                                         \
595       h->domainA = domain ? __itt_fstrdup(domain) : NULL;                      \
596       h->domainW = NULL;                                                       \
597       h->type = type;                                                          \
598       h->index = 0;                                                            \
599       h->next = NULL;                                                          \
600       if (h_tail == NULL)                                                      \
601         (gptr)->counter_list = h;                                              \
602       else                                                                     \
603         h_tail->next = h;                                                      \
604     }                                                                          \
605   }
606 
607 #endif /* _ITTNOTIFY_CONFIG_H_ */
608