From c4e4ca97bcc7741ebe4762988e16e5d4797779c1 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sat, 17 Feb 2018 04:37:13 +0900 Subject: [PATCH] mmap_cache: add function to enable mmap_cache mmap_cache was enabled indirectly via unwind feature. As now mmap_cache can be used by other part of strace, a way to enable mmap_cache directly is needed. * defs.h (mmap_cache_enable, mmap_cache_is_enabled): New function prototypes. * mmap_cache.c (use_mmap_cache): New file local variable. (mmap_cache_enable, mmap_cache_is_enabled): New functions. * syscall.c (syscall_exiting_decode): Use mmap_cache_is_enabled() instead of stack_trace_enabled. * unwind.c (unwind_init): Invoke mmap_cache_enable. Signed-off-by: Masatake YAMATO --- defs.h | 2 ++ mmap_cache.c | 11 +++++++++++ syscall.c | 4 +--- unwind.c | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/defs.h b/defs.h index 9f184c08..afcefcd8 100644 --- a/defs.h +++ b/defs.h @@ -756,6 +756,8 @@ enum mmap_cache_rebuild_result { MMAP_CACHE_REBUILD_RENEWED, }; +extern void mmap_cache_enable(void); +extern bool mmap_cache_is_enabled(void); extern void mmap_cache_invalidate(struct tcb *tcp); 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); diff --git a/mmap_cache.c b/mmap_cache.c index f26d2a78..8879c5a0 100644 --- a/mmap_cache.c +++ b/mmap_cache.c @@ -41,6 +41,17 @@ #endif static unsigned int mmap_cache_generation; +static bool use_mmap_cache; + +extern void mmap_cache_enable(void) +{ + use_mmap_cache = true; +} + +extern bool mmap_cache_is_enabled(void) +{ + return use_mmap_cache; +} /* * caching of /proc/ID/maps for each process to speed up stack tracing diff --git a/syscall.c b/syscall.c index 66d91022..c3d5f66e 100644 --- a/syscall.c +++ b/syscall.c @@ -728,12 +728,10 @@ syscall_exiting_decode(struct tcb *tcp, struct timeval *ptv) if ((Tflag || cflag) && !(filtered(tcp) || hide_log(tcp))) gettimeofday(ptv, NULL); -#ifdef USE_LIBUNWIND - if (stack_trace_enabled) { + if (mmap_cache_is_enabled()) { if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE) mmap_cache_invalidate(tcp); } -#endif if (filtered(tcp) || hide_log(tcp)) return 0; diff --git a/unwind.c b/unwind.c index 3457ec84..ea7ae353 100644 --- a/unwind.c +++ b/unwind.c @@ -74,6 +74,7 @@ unwind_init(void) if (!libunwind_as) error_msg_and_die("failed to create address space for stack tracing"); unw_set_caching_policy(libunwind_as, UNW_CACHE_GLOBAL); + mmap_cache_enable(); } void -- 2.40.0