clang -cc1 -triple i386-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name scudo_utils.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu i686 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D clang_rt_scudo_minimal_dynamic_i386_EXPORTS -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/projects/compiler-rt/lib/scudo -I /build/llvm-toolchain-snapshot-8~svn350071/projects/compiler-rt/lib/scudo -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/include -I /build/llvm-toolchain-snapshot-8~svn350071/projects/compiler-rt/lib/scudo/.. -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0/32 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/i386-pc-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -Wno-unused-parameter -Wno-variadic-macros -Wno-non-virtual-dtor -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/projects/compiler-rt/lib/scudo -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -fvisibility-inlines-hidden -fno-rtti -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/projects/compiler-rt/lib/scudo/scudo_utils.cpp -faddrsig
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #include "scudo_utils.h" |
15 | |
16 | #if defined(__x86_64__) || defined(__i386__1) |
17 | # include <cpuid.h> |
18 | #elif defined(__arm__) || defined(__aarch64__) |
19 | # include "sanitizer_common/sanitizer_getauxval.h" |
20 | # if SANITIZER_FUCHSIA0 |
21 | # include <zircon/syscalls.h> |
22 | # include <zircon/features.h> |
23 | # elif SANITIZER_POSIX(0 || 1 || 0 || 0 || 0 || 0) |
24 | # include "sanitizer_common/sanitizer_posix.h" |
25 | # include <fcntl.h> |
26 | # endif |
27 | #endif |
28 | |
29 | #include <stdarg.h> |
30 | |
31 | |
32 | |
33 | |
34 | namespace __sanitizer { |
35 | |
36 | extern int VSNPrintf(char *buff, int buff_length, const char *format, |
37 | va_list args); |
38 | |
39 | } |
40 | |
41 | namespace __scudo { |
42 | |
43 | FORMAT(1, 2)__attribute__((format(printf, 1, 2))) void NORETURN__attribute__((noreturn)) dieWithMessage(const char *Format, ...) { |
44 | static const char ScudoError[] = "Scudo ERROR: "; |
45 | static constexpr uptr PrefixSize = sizeof(ScudoError) - 1; |
46 | |
47 | char Message[256]; |
48 | va_list Args; |
49 | va_start(Args, Format)__builtin_va_start(Args, Format); |
50 | internal_memcpy(Message, ScudoError, PrefixSize); |
51 | VSNPrintf(Message + PrefixSize, sizeof(Message) - PrefixSize, Format, Args); |
52 | va_end(Args)__builtin_va_end(Args); |
53 | LogMessageOnPrintf(Message); |
54 | if (common_flags()->abort_on_error) |
55 | SetAbortMessage(Message); |
56 | RawWrite(Message); |
57 | Die(); |
58 | } |
59 | |
60 | #if defined(__x86_64__) || defined(__i386__1) |
61 | |
62 | |
63 | # ifndef bit_SSE4_20x00100000 |
64 | # define bit_SSE4_20x00100000 bit_SSE420x00100000 // clang and gcc have different defines. |
65 | # endif |
66 | bool hasHardwareCRC32() { |
67 | u32 Eax, Ebx, Ecx, Edx; |
| 1 | 'Ebx' declared without an initial value | |
|
68 | __get_cpuid(0, &Eax, &Ebx, &Ecx, &Edx); |
| |
| 3 | | Returning from '__get_cpuid' | |
|
69 | const bool IsIntel = (Ebx == signature_INTEL_ebx0x756e6547) && |
| 4 | | The left operand of '==' is a garbage value |
|
70 | (Edx == signature_INTEL_edx0x49656e69) && |
71 | (Ecx == signature_INTEL_ecx0x6c65746e); |
72 | const bool IsAMD = (Ebx == signature_AMD_ebx0x68747541) && |
73 | (Edx == signature_AMD_edx0x69746e65) && |
74 | (Ecx == signature_AMD_ecx0x444d4163); |
75 | if (!IsIntel && !IsAMD) |
76 | return false; |
77 | __get_cpuid(1, &Eax, &Ebx, &Ecx, &Edx); |
78 | return !!(Ecx & bit_SSE4_20x00100000); |
79 | } |
80 | #elif defined(__arm__) || defined(__aarch64__) |
81 | |
82 | |
83 | # ifndef AT_HWCAP |
84 | # define AT_HWCAP 16 |
85 | # endif |
86 | # ifndef HWCAP_CRC32 |
87 | # define HWCAP_CRC32 (1 << 7) // HWCAP_CRC32 is missing on older platforms. |
88 | # endif |
89 | # if SANITIZER_POSIX(0 || 1 || 0 || 0 || 0 || 0) |
90 | bool hasHardwareCRC32ARMPosix() { |
91 | uptr F = internal_open("/proc/self/auxv", O_RDONLY); |
92 | if (internal_iserror(F)) |
93 | return false; |
94 | struct { uptr Tag; uptr Value; } Entry = { 0, 0 }; |
95 | for (;;) { |
96 | uptr N = internal_read(F, &Entry, sizeof(Entry)); |
97 | if (internal_iserror(N) || N != sizeof(Entry) || |
98 | (Entry.Tag == 0 && Entry.Value == 0) || Entry.Tag == AT_HWCAP) |
99 | break; |
100 | } |
101 | internal_close(F); |
102 | return (Entry.Tag == AT_HWCAP && (Entry.Value & HWCAP_CRC32) != 0); |
103 | } |
104 | # else |
105 | bool hasHardwareCRC32ARMPosix() { return false; } |
106 | # endif // SANITIZER_POSIX |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | extern "C" SANITIZER_WEAK_ATTRIBUTE__attribute__((weak)) char *__progname; |
114 | INLINEinline bool areBionicGlobalsInitialized() { |
115 | return !SANITIZER_ANDROID0 || (&__progname && __progname); |
116 | } |
117 | |
118 | bool hasHardwareCRC32() { |
119 | #if SANITIZER_FUCHSIA0 |
120 | u32 HWCap; |
121 | zx_status_t Status = zx_system_get_features(ZX_FEATURE_KIND_CPU, &HWCap); |
122 | if (Status != ZX_OK || (HWCap & ZX_ARM64_FEATURE_ISA_CRC32) == 0) |
123 | return false; |
124 | return true; |
125 | #else |
126 | if (&getauxval && areBionicGlobalsInitialized()) |
127 | return !!(getauxval(AT_HWCAP) & HWCAP_CRC32); |
128 | return hasHardwareCRC32ARMPosix(); |
129 | #endif // SANITIZER_FUCHSIA |
130 | } |
131 | #else |
132 | bool hasHardwareCRC32() { return false; } |
133 | #endif // defined(__x86_64__) || defined(__i386__) |
134 | |
135 | } |