]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc
1 //===-- sanitizer_procmaps_linux.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 // Information about the process mappings (Linux-specific parts).
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_platform.h"
15 #include "sanitizer_common.h"
16 #include "sanitizer_procmaps.h"
18 namespace __sanitizer
{
20 void ReadProcMaps(ProcSelfMapsBuff
*proc_maps
) {
21 CHECK(ReadFileToBuffer("/proc/self/maps", &proc_maps
->data
,
22 &proc_maps
->mmaped_size
, &proc_maps
->len
));
25 static bool IsOneOf(char c
, char c1
, char c2
) {
26 return c
== c1
|| c
== c2
;
29 bool MemoryMappingLayout::Next(uptr
*start
, uptr
*end
, uptr
*offset
,
30 char filename
[], uptr filename_size
,
31 uptr
*protection
, ModuleArch
*arch
, u8
*uuid
) {
32 CHECK(!arch
&& "not implemented");
33 CHECK(!uuid
&& "not implemented");
34 char *last
= proc_self_maps_
.data
+ proc_self_maps_
.len
;
35 if (current_
>= last
) return false;
37 if (!start
) start
= &dummy
;
38 if (!end
) end
= &dummy
;
39 if (!offset
) offset
= &dummy
;
40 if (!protection
) protection
= &dummy
;
41 char *next_line
= (char*)internal_memchr(current_
, '\n', last
- current_
);
44 // Example: 08048000-08056000 r-xp 00000000 03:0c 64593 /foo/bar
45 *start
= ParseHex(¤t_
);
46 CHECK_EQ(*current_
++, '-');
47 *end
= ParseHex(¤t_
);
48 CHECK_EQ(*current_
++, ' ');
49 CHECK(IsOneOf(*current_
, '-', 'r'));
51 if (*current_
++ == 'r')
52 *protection
|= kProtectionRead
;
53 CHECK(IsOneOf(*current_
, '-', 'w'));
54 if (*current_
++ == 'w')
55 *protection
|= kProtectionWrite
;
56 CHECK(IsOneOf(*current_
, '-', 'x'));
57 if (*current_
++ == 'x')
58 *protection
|= kProtectionExecute
;
59 CHECK(IsOneOf(*current_
, 's', 'p'));
60 if (*current_
++ == 's')
61 *protection
|= kProtectionShared
;
62 CHECK_EQ(*current_
++, ' ');
63 *offset
= ParseHex(¤t_
);
64 CHECK_EQ(*current_
++, ' ');
66 CHECK_EQ(*current_
++, ':');
68 CHECK_EQ(*current_
++, ' ');
69 while (IsDecimal(*current_
))
71 // Qemu may lack the trailing space.
72 // https://github.com/google/sanitizers/issues/160
73 // CHECK_EQ(*current_++, ' ');
75 while (current_
< next_line
&& *current_
== ' ')
77 // Fill in the filename.
79 while (current_
< next_line
) {
80 if (filename
&& i
< filename_size
- 1)
81 filename
[i
++] = *current_
;
84 if (filename
&& i
< filename_size
)
86 current_
= next_line
+ 1;
90 } // namespace __sanitizer
92 #endif // SANITIZER_LINUX