From 6170e5c2cb4bbcfa6526701cb33cea2e6a02a010 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 18 Oct 2015 21:18:20 +0200 Subject: Implement logging of writable `mmap` creations --- src/change_log.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/change_log.cc b/src/change_log.cc index 5ca0e8e..180804f 100644 --- a/src/change_log.cc +++ b/src/change_log.cc @@ -2,6 +2,8 @@ #define _GNU_SOURCE #endif +#include + #include #include #include @@ -102,3 +104,19 @@ int unlinkat(int dirfd, const char* path, int flags) { return real_unlinkat(dirfd, path, flags); } + +void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) { + static auto real_mmap = get_real_function("mmap"); + + if ( ( prot & PROT_WRITE ) && io::is_regular_file(fd) ) { + const std::string file_name{ io::get_file_name(fd) }; + + if ( !is_tracked_file(file_name) ) { + track_file(file_name); + + log->append("mmap '" + file_name + "'"); + } + } + + return real_mmap(addr, length, prot, flags, fd, offset); +} -- cgit v1.2.3