@@ -37,10 +37,12 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
3737 .uuid = {}
3838 };
3939
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+
4143 static constexpr dylib_command mock_dylib_command = {
4244 .cmd = LC_LOAD_DYLIB,
43- .cmdsize = sizeof (dylib_command) + sizeof (dylib_name ),
45+ .cmdsize = sizeof (dylib_command) + sizeof (libclang_rt_dylib_name ),
4446 .dylib = {
4547 .name = {
4648 .offset = sizeof (dylib_command)
@@ -59,7 +61,7 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
5961 std::vector<unsigned char > mock_header;
6062
6163public:
62- MemoryMappingLayoutMock (): MemoryMappingLayout(false ) {
64+ MemoryMappingLayoutMock (bool instrumented ): MemoryMappingLayout(false ) {
6365 EXPECT_EQ (mock_uuid_command.cmdsize % 8 , 0u );
6466 EXPECT_EQ (mock_dylib_command.cmdsize % 8 , 0u );
6567
@@ -89,6 +91,7 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
8991 copy ((unsigned char *)&mock_dylib_command,
9092 ((unsigned char *)&mock_dylib_command) + sizeof (dylib_command), // as mock_dylib_command.cmdsize contains the following string
9193 back_inserter (mock_header));
94+ const char (&dylib_name)[16 ] = instrumented ? libclang_rt_dylib_name : uninstrumented_dylib_name;
9295 copy ((unsigned char *)dylib_name,
9396 ((unsigned char *)dylib_name) + sizeof (dylib_name),
9497 back_inserter (mock_header));
@@ -120,8 +123,20 @@ class MemoryMappingLayoutMock final : public MemoryMappingLayout {
120123 }
121124};
122125
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 (true );
125140 __sanitizer::MemoryMappedSegment segment;
126141 size_t size = memory_mapping.SizeOfLoadCommands ();
127142 while (memory_mapping.Next (&segment)) {
0 commit comments