]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
1 //===-- sanitizer_procmaps_test.cc ----------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
13 #if !defined(_WIN32) // There are no /proc/maps on Windows.
15 #include "sanitizer_common/sanitizer_procmaps.h"
16 #include "gtest/gtest.h"
21 extern const char *argv0
;
23 namespace __sanitizer
{
25 #if SANITIZER_LINUX && !SANITIZER_ANDROID
26 TEST(MemoryMappingLayout
, CodeRange
) {
28 bool res
= GetCodeRangeForFile("[vdso]", &start
, &end
);
31 EXPECT_LT(start
, end
);
35 TEST(MemoryMappingLayout
, DumpListOfModules
) {
36 const char *last_slash
= strrchr(argv0
, '/');
37 const char *binary_name
= last_slash
? last_slash
+ 1 : argv0
;
38 MemoryMappingLayout
memory_mapping(false);
39 const uptr kMaxModules
= 100;
40 InternalMmapVector
<LoadedModule
> modules(kMaxModules
);
41 memory_mapping
.DumpListOfModules(&modules
);
42 EXPECT_GT(modules
.size(), 0U);
44 for (uptr i
= 0; i
< modules
.size(); ++i
) {
45 if (modules
[i
].containsAddress((uptr
)&noop
)) {
46 // Verify that the module name is sane.
47 if (strstr(modules
[i
].full_name(), binary_name
) != 0)
55 TEST(MemoryMapping
, LoadedModuleArchAndUUID
) {
57 MemoryMappingLayout
memory_mapping(false);
58 const uptr kMaxModules
= 100;
59 InternalMmapVector
<LoadedModule
> modules(kMaxModules
);
60 memory_mapping
.DumpListOfModules(&modules
);
61 for (uptr i
= 0; i
< modules
.size(); ++i
) {
62 ModuleArch arch
= modules
[i
].arch();
63 // Darwin unit tests are only run on i386/x86_64/x86_64h.
64 if (SANITIZER_WORDSIZE
== 32) {
65 EXPECT_EQ(arch
, kModuleArchI386
);
66 } else if (SANITIZER_WORDSIZE
== 64) {
67 EXPECT_TRUE(arch
== kModuleArchX86_64
|| arch
== kModuleArchX86_64H
);
69 const u8
*uuid
= modules
[i
].uuid();
70 u8 null_uuid
[kModuleUUIDSize
] = {0};
71 EXPECT_NE(memcmp(null_uuid
, uuid
, kModuleUUIDSize
), 0);
76 } // namespace __sanitizer
77 #endif // !defined(_WIN32)