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 // Before Solaris 11.4, <procfs.h> doesn't work in a largefile environment.
13 #undef _FILE_OFFSET_BITS
14 #include "sanitizer_platform.h"
16 #include "sanitizer_common.h"
17 #include "sanitizer_procmaps.h"
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;
39 const_cast<prxmap_t
*>(reinterpret_cast<const prxmap_t
*>(data_
.current
));
41 segment
->start
= (uptr
)xmapentry
->pr_vaddr
;
42 segment
->end
= (uptr
)(xmapentry
->pr_vaddr
+ xmapentry
->pr_size
);
43 segment
->offset
= (uptr
)xmapentry
->pr_offset
;
45 segment
->protection
= 0;
46 if ((xmapentry
->pr_mflags
& MA_READ
) != 0)
47 segment
->protection
|= kProtectionRead
;
48 if ((xmapentry
->pr_mflags
& MA_WRITE
) != 0)
49 segment
->protection
|= kProtectionWrite
;
50 if ((xmapentry
->pr_mflags
& MA_EXEC
) != 0)
51 segment
->protection
|= kProtectionExecute
;
53 if (segment
->filename
!= NULL
&& segment
->filename_size
> 0) {
54 char proc_path
[PATH_MAX
+ 1];
56 internal_snprintf(proc_path
, sizeof(proc_path
), "/proc/self/path/%s",
57 xmapentry
->pr_mapname
);
58 ssize_t sz
= internal_readlink(proc_path
, segment
->filename
,
59 segment
->filename_size
- 1);
61 // If readlink failed, the map is anonymous.
63 segment
->filename
[0] = '\0';
64 } else if ((size_t)sz
< segment
->filename_size
)
65 // readlink doesn't NUL-terminate.
66 segment
->filename
[sz
] = '\0';
69 data_
.current
+= sizeof(prxmap_t
);
74 } // namespace __sanitizer
76 #endif // SANITIZER_SOLARIS