Remove redundant std::move on const object
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_procmaps_linux.cc
blobb97d5f62dd2ce28aff1762e760eac4b98f51ecfd
1 //===-- sanitizer_procmaps_linux.cc ---------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Information about the process mappings (Linux-specific parts).
9 //===----------------------------------------------------------------------===//
11 #include "sanitizer_platform.h"
12 #if SANITIZER_LINUX
13 #include "sanitizer_common.h"
14 #include "sanitizer_procmaps.h"
16 namespace __sanitizer {
18 void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
19 ReadFileToBuffer("/proc/self/maps", &proc_maps->data, &proc_maps->mmaped_size,
20 &proc_maps->len);
23 static bool IsOneOf(char c, char c1, char c2) {
24 return c == c1 || c == c2;
27 bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
28 char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
29 if (data_.current >= last) return false;
30 char *next_line =
31 (char *)internal_memchr(data_.current, '\n', last - data_.current);
32 if (next_line == 0)
33 next_line = last;
34 // Example: 08048000-08056000 r-xp 00000000 03:0c 64593 /foo/bar
35 segment->start = ParseHex(&data_.current);
36 CHECK_EQ(*data_.current++, '-');
37 segment->end = ParseHex(&data_.current);
38 CHECK_EQ(*data_.current++, ' ');
39 CHECK(IsOneOf(*data_.current, '-', 'r'));
40 segment->protection = 0;
41 if (*data_.current++ == 'r') segment->protection |= kProtectionRead;
42 CHECK(IsOneOf(*data_.current, '-', 'w'));
43 if (*data_.current++ == 'w') segment->protection |= kProtectionWrite;
44 CHECK(IsOneOf(*data_.current, '-', 'x'));
45 if (*data_.current++ == 'x') segment->protection |= kProtectionExecute;
46 CHECK(IsOneOf(*data_.current, 's', 'p'));
47 if (*data_.current++ == 's') segment->protection |= kProtectionShared;
48 CHECK_EQ(*data_.current++, ' ');
49 segment->offset = ParseHex(&data_.current);
50 CHECK_EQ(*data_.current++, ' ');
51 ParseHex(&data_.current);
52 CHECK_EQ(*data_.current++, ':');
53 ParseHex(&data_.current);
54 CHECK_EQ(*data_.current++, ' ');
55 while (IsDecimal(*data_.current)) data_.current++;
56 // Qemu may lack the trailing space.
57 // https://github.com/google/sanitizers/issues/160
58 // CHECK_EQ(*data_.current++, ' ');
59 // Skip spaces.
60 while (data_.current < next_line && *data_.current == ' ') data_.current++;
61 // Fill in the filename.
62 if (segment->filename) {
63 uptr len =
64 Min((uptr)(next_line - data_.current), segment->filename_size - 1);
65 internal_strncpy(segment->filename, data_.current, len);
66 segment->filename[len] = 0;
69 data_.current = next_line + 1;
70 return true;
73 } // namespace __sanitizer
75 #endif // SANITIZER_LINUX