[PATCH 2/5] mmap_cache: use the mmap_notify subsystem

Masatake YAMATO yamato at redhat.com
Sun Apr 29 21:45:37 UTC 2018


* syscall.c: Include mmap_notify.h instead of mmap_cache.h.
(syscall_exiting_decode): Call mmap_notify_report instead
of mmap_cache_invalidate.

* mmap_cache.c: Include mmap_notify.h.
(mmap_cache_enable): Call mmap_notify_register_client to use
the mmap_notify subsystem. mmap_cache_invalidate is passed to
know the change of the memory mapping.
(mmap_cache_invalidate): Make the function file private.

* mmap_cache.h: Remove the declaration for mmap_cache_invalidate.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 mmap_cache.c | 36 ++++++++++++++++++++----------------
 mmap_cache.h |  3 ---
 syscall.c    |  8 +++-----
 3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/mmap_cache.c b/mmap_cache.c
index 19f88abe..402e6c3c 100644
--- a/mmap_cache.c
+++ b/mmap_cache.c
@@ -30,13 +30,33 @@
 
 #include "largefile_wrappers.h"
 #include "mmap_cache.h"
+#include "mmap_notify.h"
 #include "xstring.h"
 
 static unsigned int mmap_cache_generation;
 static bool use_mmap_cache;
 
+static void
+mmap_cache_invalidate(struct tcb *tcp, void *nouse)
+{
+#if SUPPORTED_PERSONALITIES > 1
+	if (tcp->currpers != DEFAULT_PERSONALITY) {
+		/* disable stack trace */
+		return;
+	}
+#endif
+	mmap_cache_generation++;
+	debug_func_msg("tgen=%u, ggen=%u, tcp=%p, cache=%p",
+		       tcp->mmap_cache_generation,
+		       mmap_cache_generation,
+		       tcp, tcp->mmap_cache);
+}
+
 extern void mmap_cache_enable(void)
 {
+	if (!use_mmap_cache)
+		mmap_notify_register_client(mmap_cache_invalidate,
+					    NULL);
 	use_mmap_cache = true;
 }
 
@@ -193,22 +213,6 @@ mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller)
 	return r;
 }
 
-void
-mmap_cache_invalidate(struct tcb *tcp)
-{
-#if SUPPORTED_PERSONALITIES > 1
-	if (tcp->currpers != DEFAULT_PERSONALITY) {
-		/* disable stack trace */
-		return;
-	}
-#endif
-	mmap_cache_generation++;
-	debug_func_msg("tgen=%u, ggen=%u, tcp=%p, cache=%p",
-		       tcp->mmap_cache_generation,
-		       mmap_cache_generation,
-		       tcp, tcp->mmap_cache);
-}
-
 struct mmap_cache_t *
 mmap_cache_search(struct tcb *tcp, unsigned long ip)
 {
diff --git a/mmap_cache.h b/mmap_cache.h
index 265f8ec2..644ade33 100644
--- a/mmap_cache.h
+++ b/mmap_cache.h
@@ -71,9 +71,6 @@ mmap_cache_enable(void);
 extern bool
 mmap_cache_is_enabled(void);
 
-extern void
-mmap_cache_invalidate(struct tcb *);
-
 extern void
 mmap_cache_delete(struct tcb *, const char *caller);
 
diff --git a/syscall.c b/syscall.c
index 10cf4b1a..c9261968 100644
--- a/syscall.c
+++ b/syscall.c
@@ -33,7 +33,7 @@
  */
 
 #include "defs.h"
-#include "mmap_cache.h"
+#include "mmap_notify.h"
 #include "native_defs.h"
 #include "ptrace.h"
 #include "nsig.h"
@@ -744,10 +744,8 @@ syscall_exiting_decode(struct tcb *tcp, struct timespec *pts)
 	if ((Tflag || cflag) && !(filtered(tcp) || hide_log(tcp)))
 		clock_gettime(CLOCK_MONOTONIC, pts);
 
-	if (mmap_cache_is_enabled()) {
-		if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
-			mmap_cache_invalidate(tcp);
-	}
+	if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
+		mmap_notify_report(tcp);
 
 	if (filtered(tcp) || hide_log(tcp))
 		return 0;
-- 
2.14.3



More information about the Strace-devel mailing list