[PATCH resend 8/8] mmap_cache: add customizable search function

Masatake YAMATO yamato at redhat.com
Fri Feb 16 19:37:15 UTC 2018


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

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

diff --git a/defs.h b/defs.h
index 0bf9a8c7..6736e02b 100644
--- a/defs.h
+++ b/defs.h
@@ -765,6 +765,9 @@ extern void mmap_cache_delete(struct tcb *tcp, const char *caller);
 extern enum mmap_cache_rebuild_result mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller);
 extern struct mmap_cache_t *mmap_cache_search(struct tcb *tcp, unsigned long ip);
 
+typedef bool (* mmap_cache_search_fn) (struct mmap_cache_t *, void *);
+extern struct mmap_cache_t *mmap_cache_search_custom(struct tcb *tcp, mmap_cache_search_fn, void *);
+
 static inline int
 printstrn(struct tcb *tcp, kernel_ulong_t addr, kernel_ulong_t len)
 {
diff --git a/mmap_cache.c b/mmap_cache.c
index 33226784..d6271095 100644
--- a/mmap_cache.c
+++ b/mmap_cache.c
@@ -239,3 +239,15 @@ mmap_cache_search(struct tcb *tcp, unsigned long ip)
 	}
 	return NULL;
 }
+
+struct mmap_cache_t *
+mmap_cache_search_custom(struct tcb *tcp, mmap_cache_search_fn search_fn, void *data)
+{
+	int i;
+
+	for (i = 0; i <= (int) tcp->mmap_cache_size; i++) {
+		if (search_fn (tcp->mmap_cache + i, data))
+			return tcp->mmap_cache + i;
+	}
+	return NULL;
+}
-- 
2.14.3





More information about the Strace-devel mailing list