X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=probes%2Flttng-kprobes.c;h=784002aed09662d179a01bea12a0c4f706bbcaf4;hb=b2c4e8fb4f093e99d5e464c759f3be1f3ea4a83e;hp=481807de92a2796a36a1033fec6189ca7e2a97ff;hpb=9e7e489272e646b39c51e3074de800e928bb5cec;p=lttng-modules.git diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index 481807de..784002ae 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -25,9 +25,14 @@ int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) int ret; unsigned long data = (unsigned long) p->addr; - if (!ACCESS_ONCE(chan->session->active)) + if (unlikely(!ACCESS_ONCE(chan->session->active))) return 0; - lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, sizeof(data), + if (unlikely(!ACCESS_ONCE(chan->enabled))) + return 0; + if (unlikely(!ACCESS_ONCE(event->enabled))) + return 0; + + lib_ring_buffer_ctx_init(&ctx, chan->chan, event, sizeof(data), ltt_alignof(data), -1); ret = chan->ops->event_reserve(&ctx, event->id); if (ret < 0) @@ -91,24 +96,30 @@ int lttng_kprobes_register(const char *name, { int ret; + /* Kprobes expects a NULL symbol name if unused */ + if (symbol_name[0] == '\0') + symbol_name = NULL; + ret = lttng_create_kprobe_event(name, event); if (ret) goto error; memset(&event->u.kprobe.kp, 0, sizeof(event->u.kprobe.kp)); event->u.kprobe.kp.pre_handler = lttng_kprobes_handler_pre; - event->u.kprobe.symbol_name = - kzalloc(LTTNG_SYM_NAME_LEN * sizeof(char), - GFP_KERNEL); - if (!event->u.kprobe.symbol_name) { - ret = -ENOMEM; - goto name_error; + if (symbol_name) { + event->u.kprobe.symbol_name = + kzalloc(LTTNG_SYM_NAME_LEN * sizeof(char), + GFP_KERNEL); + if (!event->u.kprobe.symbol_name) { + ret = -ENOMEM; + goto name_error; + } + memcpy(event->u.kprobe.symbol_name, symbol_name, + LTTNG_SYM_NAME_LEN * sizeof(char)); + event->u.kprobe.kp.symbol_name = + event->u.kprobe.symbol_name; } - memcpy(event->u.kprobe.symbol_name, symbol_name, - LTTNG_SYM_NAME_LEN * sizeof(char)); - event->u.kprobe.kp.symbol_name = - event->u.kprobe.symbol_name; event->u.kprobe.kp.offset = offset; - event->u.kprobe.kp.addr = (void *) addr; + event->u.kprobe.kp.addr = (void *) (unsigned long) addr; /* * Ensure the memory we just allocated don't trigger page faults.