aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-10-18 21:18:20 +0200
committerAdrian Kummerlaender2015-10-18 21:18:20 +0200
commit6170e5c2cb4bbcfa6526701cb33cea2e6a02a010 (patch)
tree83584f1d002dda343f899ac0159eaec2099901de /src
parent68b69dfc92daffbe52b4eb7eb317beb2cc764fb0 (diff)
downloadchange-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.tar
change-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.tar.gz
change-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.tar.bz2
change-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.tar.lz
change-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.tar.xz
change-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.tar.zst
change-6170e5c2cb4bbcfa6526701cb33cea2e6a02a010.zip
Implement logging of writable `mmap` creations
Diffstat (limited to 'src')
-rw-r--r--src/change_log.cc18
1 files changed, 18 insertions, 0 deletions
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 <sys/mman.h>
+
#include <memory>
#include <functional>
#include <unordered_set>
@@ -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<void*, void*, size_t, int, int, int, off_t>("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);
+}