2013-12-25 16:01:16 +08:00
|
|
|
//===-- sanitizer_procmaps_linux.cc ---------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Information about the process mappings (Linux-specific parts).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_platform.h"
|
2014-08-06 18:16:52 +08:00
|
|
|
#if SANITIZER_LINUX
|
2013-12-25 16:01:16 +08:00
|
|
|
#include "sanitizer_common.h"
|
|
|
|
#include "sanitizer_procmaps.h"
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
2014-08-06 18:16:52 +08:00
|
|
|
void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
|
2017-11-29 06:15:27 +08:00
|
|
|
if (!ReadFileToBuffer("/proc/self/maps", &proc_maps->data,
|
|
|
|
&proc_maps->mmaped_size, &proc_maps->len)) {
|
|
|
|
proc_maps->data = nullptr;
|
|
|
|
proc_maps->mmaped_size = 0;
|
|
|
|
proc_maps->len = 0;
|
|
|
|
}
|
2013-12-25 16:01:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsOneOf(char c, char c1, char c2) {
|
|
|
|
return c == c1 || c == c2;
|
|
|
|
}
|
|
|
|
|
2017-07-12 02:54:00 +08:00
|
|
|
bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
char *last = data_.proc_self_maps.data + data_.proc_self_maps.len;
|
|
|
|
if (data_.current >= last) return false;
|
|
|
|
char *next_line =
|
|
|
|
(char *)internal_memchr(data_.current, '\n', last - data_.current);
|
2013-12-25 16:01:16 +08:00
|
|
|
if (next_line == 0)
|
|
|
|
next_line = last;
|
|
|
|
// Example: 08048000-08056000 r-xp 00000000 03:0c 64593 /foo/bar
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
segment->start = ParseHex(&data_.current);
|
|
|
|
CHECK_EQ(*data_.current++, '-');
|
|
|
|
segment->end = ParseHex(&data_.current);
|
|
|
|
CHECK_EQ(*data_.current++, ' ');
|
|
|
|
CHECK(IsOneOf(*data_.current, '-', 'r'));
|
2017-07-12 02:54:00 +08:00
|
|
|
segment->protection = 0;
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
if (*data_.current++ == 'r') segment->protection |= kProtectionRead;
|
|
|
|
CHECK(IsOneOf(*data_.current, '-', 'w'));
|
|
|
|
if (*data_.current++ == 'w') segment->protection |= kProtectionWrite;
|
|
|
|
CHECK(IsOneOf(*data_.current, '-', 'x'));
|
|
|
|
if (*data_.current++ == 'x') segment->protection |= kProtectionExecute;
|
|
|
|
CHECK(IsOneOf(*data_.current, 's', 'p'));
|
|
|
|
if (*data_.current++ == 's') segment->protection |= kProtectionShared;
|
|
|
|
CHECK_EQ(*data_.current++, ' ');
|
|
|
|
segment->offset = ParseHex(&data_.current);
|
|
|
|
CHECK_EQ(*data_.current++, ' ');
|
|
|
|
ParseHex(&data_.current);
|
|
|
|
CHECK_EQ(*data_.current++, ':');
|
|
|
|
ParseHex(&data_.current);
|
|
|
|
CHECK_EQ(*data_.current++, ' ');
|
|
|
|
while (IsDecimal(*data_.current)) data_.current++;
|
2013-12-25 16:01:16 +08:00
|
|
|
// Qemu may lack the trailing space.
|
2015-12-05 01:50:03 +08:00
|
|
|
// https://github.com/google/sanitizers/issues/160
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
// CHECK_EQ(*data_.current++, ' ');
|
2013-12-25 16:01:16 +08:00
|
|
|
// Skip spaces.
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
while (data_.current < next_line && *data_.current == ' ') data_.current++;
|
2013-12-25 16:01:16 +08:00
|
|
|
// Fill in the filename.
|
2017-07-12 03:40:54 +08:00
|
|
|
if (segment->filename) {
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
uptr len =
|
|
|
|
Min((uptr)(next_line - data_.current), segment->filename_size - 1);
|
|
|
|
internal_strncpy(segment->filename, data_.current, len);
|
2017-07-12 03:40:54 +08:00
|
|
|
segment->filename[len] = 0;
|
2013-12-25 16:01:16 +08:00
|
|
|
}
|
2017-07-12 03:40:54 +08:00
|
|
|
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
data_.current = next_line + 1;
|
2013-12-25 16:01:16 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2014-08-06 18:16:52 +08:00
|
|
|
#endif // SANITIZER_LINUX
|