summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/esan/working_set_posix.cpp
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-05-31 13:41:07 +0000
committerDerek Bruening <bruening@google.com>2016-05-31 13:41:07 +0000
commit8ef3f0fa5b12b0903b4f331ee477efeb5df125d2 (patch)
treebc07f947397bf55a8028ef334bd1af2057531339 /compiler-rt/lib/esan/working_set_posix.cpp
parent659afd55fa09a1ce668a2483c23acdaf200cc6b9 (diff)
downloadbcm5719-llvm-8ef3f0fa5b12b0903b4f331ee477efeb5df125d2.tar.gz
bcm5719-llvm-8ef3f0fa5b12b0903b4f331ee477efeb5df125d2.zip
[esan|wset] Iterate all memory to compute the total working set
Summary: Adds iteration of all application memory in an efficient manner using shadow faults. Shadow memory starts out inaccessible and we mark it writable one page at a time on each fault when the instrumentation touches it. This allows iteration over just the mapped shadow memory, saving significant time. Adds a process-end iteration and pretty-printing of the final result. Adds a new test and updates the existing tests. Reviewers: aizatsky, filcab Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D20578 llvm-svn: 271277
Diffstat (limited to 'compiler-rt/lib/esan/working_set_posix.cpp')
-rw-r--r--compiler-rt/lib/esan/working_set_posix.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler-rt/lib/esan/working_set_posix.cpp b/compiler-rt/lib/esan/working_set_posix.cpp
index f0191766bb9..0f36c86fe9a 100644
--- a/compiler-rt/lib/esan/working_set_posix.cpp
+++ b/compiler-rt/lib/esan/working_set_posix.cpp
@@ -68,10 +68,16 @@ static void reinstateDefaultHandler(int SigNum) {
// app to handle it just as the app would do without our tool in place.
static void handleMemoryFault(int SigNum, void *Info, void *Ctx) {
if (SigNum == SIGSEGV) {
-
- // TODO: Add shadow memory fault detection and handling.
-
- if (AppSigAct.sigaction) {
+ // We rely on si_addr being filled in (thus we do not support old kernels).
+ siginfo_t *SigInfo = (siginfo_t *)Info;
+ uptr Addr = (uptr)SigInfo->si_addr;
+ if (isShadowMem(Addr)) {
+ VPrintf(3, "Shadow fault @%p\n", Addr);
+ uptr PageSize = GetPageSizeCached();
+ int Res = internal_mprotect((void *)RoundDownTo(Addr, PageSize),
+ PageSize, PROT_READ|PROT_WRITE);
+ CHECK(Res == 0);
+ } else if (AppSigAct.sigaction) {
// FIXME: For simplicity we ignore app options including its signal stack
// (we just use ours) and all the delivery flags.
AppSigAct.sigaction(SigNum, Info, Ctx);
OpenPOWER on IntegriCloud