]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
MFV r337167: 9442 decrease indirect block size of spacemaps
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_procmaps_solaris.cc
1 //===-- sanitizer_procmaps_solaris.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 (Solaris-specific parts).
9 //===----------------------------------------------------------------------===//
10
11 #include "sanitizer_platform.h"
12 #if SANITIZER_SOLARIS
13 #include "sanitizer_common.h"
14 #include "sanitizer_procmaps.h"
15
16 #include <procfs.h>
17 #include <limits.h>
18
19 namespace __sanitizer {
20
21 void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
22   ReadFileToBuffer("/proc/self/xmap", &proc_maps->data, &proc_maps->mmaped_size,
23                    &proc_maps->len);
24 }
25
26 bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
27   char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
28   if (data_.current >= last) return false;
29
30   prxmap_t *xmapentry = (prxmap_t*)data_.current;
31
32   segment->start = (uptr)xmapentry->pr_vaddr;
33   segment->end = (uptr)(xmapentry->pr_vaddr + xmapentry->pr_size);
34   segment->offset = (uptr)xmapentry->pr_offset;
35
36   segment->protection = 0;
37   if ((xmapentry->pr_mflags & MA_READ) != 0)
38     segment->protection |= kProtectionRead;
39   if ((xmapentry->pr_mflags & MA_WRITE) != 0)
40     segment->protection |= kProtectionWrite;
41   if ((xmapentry->pr_mflags & MA_EXEC) != 0)
42     segment->protection |= kProtectionExecute;
43
44   if (segment->filename != NULL && segment->filename_size > 0) {
45     internal_snprintf(segment->filename,
46                       Min(segment->filename_size, (uptr)PATH_MAX), "%s",
47                       xmapentry->pr_mapname);
48   }
49
50   data_.current += sizeof(prxmap_t);
51
52   return true;
53 }
54
55 }  // namespace __sanitizer
56
57 #endif  // SANITIZER_SOLARIS