2019-08-14 10:47:11 +02:00
|
|
|
//===-- sanitizer_procmaps_solaris.cpp ------------------------------------===//
|
2018-10-31 12:14:23 +01:00
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-10-31 12:14:23 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Information about the process mappings (Solaris-specific parts).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_platform.h"
|
|
|
|
#if SANITIZER_SOLARIS
|
|
|
|
#include "sanitizer_common.h"
|
|
|
|
#include "sanitizer_procmaps.h"
|
|
|
|
|
2018-11-06 11:42:05 +01:00
|
|
|
// Before Solaris 11.4, <procfs.h> doesn't work in a largefile environment.
|
|
|
|
#undef _FILE_OFFSET_BITS
|
2018-10-31 12:14:23 +01:00
|
|
|
#include <procfs.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
|
2019-08-14 10:47:11 +02:00
|
|
|
if (!ReadFileToBuffer("/proc/self/xmap", &proc_maps->data,
|
|
|
|
&proc_maps->mmaped_size, &proc_maps->len)) {
|
|
|
|
proc_maps->data = nullptr;
|
|
|
|
proc_maps->mmaped_size = 0;
|
|
|
|
proc_maps->len = 0;
|
|
|
|
}
|
2018-10-31 12:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
|
2019-08-14 10:47:11 +02:00
|
|
|
if (Error()) return false; // simulate empty maps
|
2018-10-31 12:14:23 +01:00
|
|
|
char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
|
|
|
|
if (data_.current >= last) return false;
|
|
|
|
|
|
|
|
prxmap_t *xmapentry = (prxmap_t*)data_.current;
|
|
|
|
|
|
|
|
segment->start = (uptr)xmapentry->pr_vaddr;
|
|
|
|
segment->end = (uptr)(xmapentry->pr_vaddr + xmapentry->pr_size);
|
|
|
|
segment->offset = (uptr)xmapentry->pr_offset;
|
|
|
|
|
|
|
|
segment->protection = 0;
|
|
|
|
if ((xmapentry->pr_mflags & MA_READ) != 0)
|
|
|
|
segment->protection |= kProtectionRead;
|
|
|
|
if ((xmapentry->pr_mflags & MA_WRITE) != 0)
|
|
|
|
segment->protection |= kProtectionWrite;
|
|
|
|
if ((xmapentry->pr_mflags & MA_EXEC) != 0)
|
|
|
|
segment->protection |= kProtectionExecute;
|
|
|
|
|
|
|
|
if (segment->filename != NULL && segment->filename_size > 0) {
|
2019-08-14 10:47:11 +02:00
|
|
|
char proc_path[PATH_MAX + 1];
|
|
|
|
|
|
|
|
internal_snprintf(proc_path, sizeof(proc_path), "/proc/self/path/%s",
|
2018-10-31 12:14:23 +01:00
|
|
|
xmapentry->pr_mapname);
|
2019-08-14 10:47:11 +02:00
|
|
|
internal_readlink(proc_path, segment->filename, segment->filename_size);
|
2018-10-31 12:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data_.current += sizeof(prxmap_t);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_SOLARIS
|