-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
utils.h
99 lines (88 loc) · 2.7 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#ifndef HAVE_MINIPAL_UTILS_H
#define HAVE_MINIPAL_UTILS_H
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
// Number of characters in a string literal. Excludes terminating NULL.
#define STRING_LENGTH(str) (ARRAY_SIZE(str) - 1)
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifdef __cplusplus
# ifndef __has_cpp_attribute
# define __has_cpp_attribute(x) 0
# endif
# if __has_cpp_attribute(fallthrough)
# define FALLTHROUGH [[fallthrough]]
# else
# define FALLTHROUGH
# endif
#elif __has_attribute(fallthrough)
# define FALLTHROUGH __attribute__((fallthrough))
#else
# define FALLTHROUGH
#endif
#if defined(_MSC_VER)
#define LIBC_CALLBACK __cdecl
#else
#define LIBC_CALLBACK
#endif
#if defined(_MSC_VER)
# if defined(__SANITIZE_ADDRESS__)
# define HAS_ADDRESS_SANITIZER
# define DISABLE_ASAN __declspec(no_sanitize_address)
# else
# define DISABLE_ASAN
# endif
#elif defined(__has_feature)
# if __has_feature(address_sanitizer)
# define HAS_ADDRESS_SANITIZER
# define DISABLE_ASAN __attribute__((no_sanitize("address")))
# else
# define DISABLE_ASAN
# endif
#else
# define DISABLE_ASAN
#endif
#if defined(_MSC_VER)
# ifdef SANITIZER_SHARED_RUNTIME
# define SANITIZER_CALLBACK_CALLCONV __declspec(dllexport no_sanitize_address) __cdecl
# define SANITIZER_INTERFACE_CALLCONV __declspec(dllimport) __cdecl
# else
# define SANITIZER_CALLBACK_CALLCONV __declspec(no_sanitize_address) __cdecl
# define SANITIZER_INTERFACE_CALLCONV __cdecl
# endif
#else
# ifdef SANITIZER_SHARED_RUNTIME
# define SANITIZER_CALLBACK_CALLCONV __attribute__((no_address_safety_analysis)) __attribute__((visibility("default")))
# else
# define SANITIZER_CALLBACK_CALLCONV __attribute__((no_address_safety_analysis))
# endif
# define SANITIZER_INTERFACE_CALLCONV
#endif
#if defined(HAS_ADDRESS_SANITIZER)
# ifdef __cplusplus
extern "C"
{
# endif
void SANITIZER_INTERFACE_CALLCONV __asan_handle_no_return(void);
# ifdef __cplusplus
}
# endif
#elif defined(__llvm__)
# pragma clang diagnostic push
# ifdef COMPILER_SUPPORTS_W_RESERVED_IDENTIFIER
# pragma clang diagnostic ignored "-Wreserved-identifier"
# endif
// Stub out a dummy implmentation when asan isn't enabled.
inline void __asan_handle_no_return(void);
inline void __asan_handle_no_return(void){}
# pragma clang diagnostic pop
#else
// Use a macro for GCC since __asan_handle_no_return is always available as a built-in on GCC
#define __asan_handle_no_return()
#endif
#endif // HAVE_MINIPAL_UTILS_H