1 //===-- sanitizer_procmaps_solaris.cpp ------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Information about the process mappings (Solaris-specific parts).
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_platform.h"
14 #include "sanitizer_common.h"
15 #include "sanitizer_procmaps.h"
17 // Before Solaris 11.4, <procfs.h> doesn't work in a largefile environment.
18 #undef _FILE_OFFSET_BITS
22 namespace __sanitizer
{
24 void ReadProcMaps(ProcSelfMapsBuff
*proc_maps
) {
25 if (!ReadFileToBuffer("/proc/self/xmap", &proc_maps
->data
,
26 &proc_maps
->mmaped_size
, &proc_maps
->len
)) {
27 proc_maps
->data
= nullptr;
28 proc_maps
->mmaped_size
= 0;
33 bool MemoryMappingLayout::Next(MemoryMappedSegment
*segment
) {
34 if (Error()) return false; // simulate empty maps
35 char *last
= data_
.proc_self_maps
.data
+ data_
.proc_self_maps
.len
;
36 if (data_
.current
>= last
) return false;
38 prxmap_t
*xmapentry
= (prxmap_t
*)data_
.current
;
40 segment
->start
= (uptr
)xmapentry
->pr_vaddr
;
41 segment
->end
= (uptr
)(xmapentry
->pr_vaddr
+ xmapentry
->pr_size
);
42 segment
->offset
= (uptr
)xmapentry
->pr_offset
;
44 segment
->protection
= 0;
45 if ((xmapentry
->pr_mflags
& MA_READ
) != 0)
46 segment
->protection
|= kProtectionRead
;
47 if ((xmapentry
->pr_mflags
& MA_WRITE
) != 0)
48 segment
->protection
|= kProtectionWrite
;
49 if ((xmapentry
->pr_mflags
& MA_EXEC
) != 0)
50 segment
->protection
|= kProtectionExecute
;
52 if (segment
->filename
!= NULL
&& segment
->filename_size
> 0) {
53 char proc_path
[PATH_MAX
+ 1];
55 internal_snprintf(proc_path
, sizeof(proc_path
), "/proc/self/path/%s",
56 xmapentry
->pr_mapname
);
57 internal_readlink(proc_path
, segment
->filename
, segment
->filename_size
);
60 data_
.current
+= sizeof(prxmap_t
);
65 } // namespace __sanitizer
67 #endif // SANITIZER_SOLARIS