From aa6aaa96542bf5f364a7a647528e8bd9ce33460e Mon Sep 17 00:00:00 2001 From: Vasiliy Ulyanov Date: Wed, 7 May 2014 09:33:47 +0400 Subject: [PATCH] [REFACTOR] Move events checking out from msg packing routines Now the checking is performed only when it is actually needed so the functions from the writer module can be used even if events filtering is undesirable. Change-Id: Id0e2a2077bc0bca8f2919a4683a77f0982265166 Signed-off-by: Vasiliy Ulyanov --- ks_features/ks_features.c | 11 +++++++---- sampler/swap_sampler_module.c | 3 ++- writer/swap_writer_module.c | 15 --------------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/ks_features/ks_features.c b/ks_features/ks_features.c index 04e0f12..a5fe06f 100644 --- a/ks_features/ks_features.c +++ b/ks_features/ks_features.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "ks_features.h" #include "syscall_list.h" #include "features_data.c" @@ -117,7 +118,7 @@ static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { struct kretprobe *rp = ri->rp; - if (rp) { + if (rp && check_event(current)) { struct ks_probe *ksp = container_of(rp, struct ks_probe, rp); const char *fmt = ksp->args; unsigned long addr = (unsigned long)ksp->rp.kp.addr; @@ -133,7 +134,7 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { struct kretprobe *rp = ri->rp; - if (rp) { + if (rp && check_event(current)) { unsigned long func_addr = (unsigned long)rp->kp.addr; unsigned long ret_addr = (unsigned long)ri->ret_addr; @@ -150,14 +151,16 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) /* ====================== SWITCH_CONTEXT ======================= */ static int switch_entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { - switch_entry(regs); + if (check_event(current)) + switch_entry(regs); return 0; } static int switch_ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { - switch_exit(regs); + if (check_event(current)) + switch_exit(regs); return 0; } diff --git a/sampler/swap_sampler_module.c b/sampler/swap_sampler_module.c index 4528743..9867ccf 100644 --- a/sampler/swap_sampler_module.c +++ b/sampler/swap_sampler_module.c @@ -36,6 +36,7 @@ #include #include +#include #include "swap_sampler_module.h" #include "swap_sampler_errors.h" @@ -47,7 +48,7 @@ static BLOCKING_NOTIFIER_HEAD(swap_sampler_notifier_list); static restart_ret swap_timer_restart(swap_timer *timer) { - if (current) + if (check_event(current)) sample_msg(task_pt_regs(current)); return sampler_timers_restart(timer); diff --git a/writer/swap_writer_module.c b/writer/swap_writer_module.c index cca749c..fcc2c30 100644 --- a/writer/swap_writer_module.c +++ b/writer/swap_writer_module.c @@ -707,9 +707,6 @@ int sample_msg(struct pt_regs *regs) char *buf, *payload, *buf_end; int ret; - if (!check_event(current)) - return 0; - buf = get_current_buf(); payload = pack_basic_msg_fmt(buf, MSG_SAMPLE); buf_end = pack_sample(payload, regs); @@ -876,9 +873,6 @@ int entry_event(const char *fmt, unsigned long func_addr, struct pt_regs *regs, char *buf, *payload, *args, *buf_end; int ret; - if (pt == PT_KS && !check_event(current)) - return 0; - buf = get_current_buf(); payload = pack_basic_msg_fmt(buf, MSG_FUNCTION_ENTRY); args = pack_msg_func_entry(payload, fmt, func_addr, @@ -1046,9 +1040,6 @@ int exit_event(char ret_type, struct pt_regs *regs, unsigned long func_addr, char *buf, *payload, *buf_end; int ret; - if (!check_event(current)) - return 0; - buf = get_current_buf(); payload = pack_basic_msg_fmt(buf, MSG_FUNCTION_EXIT); /* FIXME: len=1024 */ @@ -1126,9 +1117,6 @@ static int context_switch(struct pt_regs *regs, enum MSG_ID id) */ int switch_entry(struct pt_regs *regs) { - if (!check_event(current)) - return 0; - return context_switch(regs, MSG_CONTEXT_SWITCH_ENTRY); } EXPORT_SYMBOL_GPL(switch_entry); @@ -1141,9 +1129,6 @@ EXPORT_SYMBOL_GPL(switch_entry); */ int switch_exit(struct pt_regs *regs) { - if (!check_event(current)) - return 0; - return context_switch(regs, MSG_CONTEXT_SWITCH_EXIT); } EXPORT_SYMBOL_GPL(switch_exit); -- 2.7.4