[PATCH 1/4] mmap_cache: add customizable search function

Masatake YAMATO yamato at redhat.com
Mon May 7 11:26:01 UTC 2018


* mmap_cache.c (mmap_cache_search_custom): New function.
* mmap_cache.h (mmap_cache_search_fn): New type.
(mmap_cache_search_custom): New function prototype.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 mmap_cache.c | 12 ++++++++++++
 mmap_cache.h |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/mmap_cache.c b/mmap_cache.c
index 631133b5..3ac1853e 100644
--- a/mmap_cache.c
+++ b/mmap_cache.c
@@ -235,3 +235,15 @@ mmap_cache_search(struct tcb *tcp, unsigned long ip)
 	}
 	return NULL;
 }
+
+struct mmap_cache_entry_t *
+mmap_cache_search_custom(struct tcb *tcp, mmap_cache_search_fn search_fn, void *data)
+{
+	unsigned int i;
+
+	for (i = 0; i <= tcp->mmap_cache->size; i++) {
+		if (search_fn (tcp->mmap_cache->entry + i, data))
+			return tcp->mmap_cache->entry + i;
+	}
+	return NULL;
+}
diff --git a/mmap_cache.h b/mmap_cache.h
index 90a939f3..e03b8876 100644
--- a/mmap_cache.h
+++ b/mmap_cache.h
@@ -73,6 +73,8 @@ enum mmap_cache_rebuild_result {
 	MMAP_CACHE_REBUILD_RENEWED,
 };
 
+typedef bool (*mmap_cache_search_fn)(struct mmap_cache_entry_t *, void *);
+
 extern void
 mmap_cache_enable(void);
 
@@ -82,4 +84,7 @@ mmap_cache_rebuild_if_invalid(struct tcb *, const char *caller);
 extern struct mmap_cache_entry_t *
 mmap_cache_search(struct tcb *, unsigned long ip);
 
+extern struct mmap_cache_entry_t *
+mmap_cache_search_custom(struct tcb *, mmap_cache_search_fn, void *);
+
 #endif /* !STRACE_MMAP_CACHE_H */
-- 
2.17.0



More information about the Strace-devel mailing list