@@ -37,10 +37,12 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
37
37
.uuid = {}
38
38
};
39
39
40
- static constexpr char dylib_name[] = " libclang_rt.\0\0\0 " ; // 8 bytes aligned, padded with zeros per loader.h
40
+ static constexpr char libclang_rt_dylib_name[] = " libclang_rt.\0\0\0 " ; // 8 bytes aligned, padded with zeros per loader.h
41
+ static constexpr char uninstrumented_dylib_name[] = " uninst___rt.\0\0\0 " ; // 8 bytes aligned, padded with zeros per loader.h
42
+
41
43
static constexpr dylib_command mock_dylib_command = {
42
44
.cmd = LC_LOAD_DYLIB,
43
- .cmdsize = sizeof (dylib_command) + sizeof (dylib_name ),
45
+ .cmdsize = sizeof (dylib_command) + sizeof (libclang_rt_dylib_name ),
44
46
.dylib = {
45
47
.name = {
46
48
.offset = sizeof (dylib_command)
@@ -59,7 +61,7 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
59
61
std::vector<unsigned char > mock_header;
60
62
61
63
public:
62
- MemoryMappingLayoutMock (): MemoryMappingLayout(false ) {
64
+ MemoryMappingLayoutMock (bool instrumented ): MemoryMappingLayout(false ) {
63
65
EXPECT_EQ (mock_uuid_command.cmdsize % 8 , 0u );
64
66
EXPECT_EQ (mock_dylib_command.cmdsize % 8 , 0u );
65
67
@@ -89,6 +91,7 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
89
91
copy ((unsigned char *)&mock_dylib_command,
90
92
((unsigned char *)&mock_dylib_command) + sizeof (dylib_command), // as mock_dylib_command.cmdsize contains the following string
91
93
back_inserter (mock_header));
94
+ const char (&dylib_name)[16 ] = instrumented ? libclang_rt_dylib_name : uninstrumented_dylib_name;
92
95
copy ((unsigned char *)dylib_name,
93
96
((unsigned char *)dylib_name) + sizeof (dylib_name),
94
97
back_inserter (mock_header));
@@ -120,8 +123,20 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
120
123
}
121
124
};
122
125
123
- TEST (MemoryMappingLayout, Next) {
124
- __sanitizer::MemoryMappingLayoutMock memory_mapping;
126
+ TEST (MemoryMappingLayout, NextInstrumented) {
127
+ __sanitizer::MemoryMappingLayoutMock memory_mapping (true );
128
+ __sanitizer::MemoryMappedSegment segment;
129
+ size_t size = memory_mapping.SizeOfLoadCommands ();
130
+ while (memory_mapping.Next (&segment)) {
131
+ size_t offset = memory_mapping.CurrentLoadCommandOffset ();
132
+ EXPECT_LE (offset, size);
133
+ }
134
+ size_t final_offset = memory_mapping.CurrentLoadCommandOffset ();
135
+ EXPECT_EQ (final_offset, size); // All commands processed, no more, no less
136
+ }
137
+
138
+ TEST (MemoryMappingLayout, NextUnInstrumented) {
139
+ __sanitizer::MemoryMappingLayoutMock memory_mapping (false );
125
140
__sanitizer::MemoryMappedSegment segment;
126
141
size_t size = memory_mapping.SizeOfLoadCommands ();
127
142
while (memory_mapping.Next (&segment)) {
0 commit comments