summaryrefslogtreecommitdiff
path: root/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
commit53a14668413fab51e500cd3c26eea269e1f09749 (patch)
treec500b628005023a654a988757d375915e366033c /lib/esan/working_set_posix.cpp
parent0573d6c7f326a08eeff6e595fd77045a0210c32a (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271277 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/esan/working_set_posix.cpp')
-rw-r--r--lib/esan/working_set_posix.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/esan/working_set_posix.cpp b/lib/esan/working_set_posix.cpp
index f0191766b..0f36c86fe 100644
--- a/lib/esan/working_set_posix.cpp
+++ b/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);