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

Dmitry V. Levin ldv at altlinux.org
Mon Feb 26 23:27:04 UTC 2018


On Sat, Jan 27, 2018 at 05:36:44AM +0900, Masatake YAMATO wrote:
> * 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 881768dd..bae5e4a1 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -748,6 +748,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 void
>  printstrn(struct tcb *tcp, kernel_ulong_t addr, kernel_ulong_t len)
>  {
> diff --git a/mmap_cache.c b/mmap_cache.c
> index 88753071..f14d8942 100644
> --- a/mmap_cache.c
> +++ b/mmap_cache.c
> @@ -237,3 +237,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;
> +}

Why do you need this function?
It looks like an iterator rather than a search function.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180227/d37907ac/attachment.bin>


More information about the Strace-devel mailing list