X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fprobes%2Flttng-kprobes.c;h=7c77c566b596896a8c063318a19aaae5f12fe6ff;hb=8a57ec025ffbe56153748fd69b60118862707182;hp=ecb08fc8fd65f9f9dcb474d4e959baadca50b7d2;hpb=a67ba386d82d85c6b6ca56c249a13ab5a1f34b08;p=lttng-modules.git diff --git a/src/probes/lttng-kprobes.c b/src/probes/lttng-kprobes.c index ecb08fc8..7c77c566 100644 --- a/src/probes/lttng-kprobes.c +++ b/src/probes/lttng-kprobes.c @@ -23,54 +23,69 @@ int lttng_kprobes_event_handler_pre(struct kprobe *p, struct pt_regs *regs) { struct lttng_kernel_event_common_private *event_priv = container_of(p, struct lttng_kernel_event_common_private, u.kprobe.kp); - struct lttng_kernel_event_recorder_private *event_recorder_priv = - container_of(event_priv, struct lttng_kernel_event_recorder_private, parent); - struct lttng_kernel_event_recorder *event_recorder = - event_recorder_priv->pub; - struct lttng_probe_ctx lttng_probe_ctx = { - .event = event_recorder, + struct lttng_kernel_event_common *event = event_priv->pub; + struct lttng_kernel_probe_ctx lttng_probe_ctx = { + .event = event, .interruptible = !lttng_regs_irqs_disabled(regs), }; - struct lttng_channel *chan = event_recorder->chan; - struct lib_ring_buffer_ctx ctx; - int ret; unsigned long data = (unsigned long) p->addr; - if (unlikely(!LTTNG_READ_ONCE(chan->session->active))) - return 0; - if (unlikely(!LTTNG_READ_ONCE(chan->enabled))) - return 0; - if (unlikely(!LTTNG_READ_ONCE(event_recorder->parent.enabled))) - return 0; - - lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, sizeof(data), - lttng_alignof(data), -1); - ret = chan->ops->event_reserve(&ctx, event_recorder->priv->id); - if (ret < 0) - return 0; - lib_ring_buffer_align_ctx(&ctx, lttng_alignof(data)); - chan->ops->event_write(&ctx, &data, sizeof(data)); - chan->ops->event_commit(&ctx); - return 0; -} - -static -int lttng_kprobes_event_notifier_handler_pre(struct kprobe *p, struct pt_regs *regs) -{ - struct lttng_kernel_event_common_private *event_priv = - container_of(p, struct lttng_kernel_event_common_private, u.kprobe.kp); - struct lttng_kernel_event_notifier_private *event_notifier_priv = - container_of(event_priv, struct lttng_kernel_event_notifier_private, parent); - struct lttng_kernel_event_notifier *event_notifier = - event_notifier_priv->pub; - struct lttng_kernel_notification_ctx notif_ctx; + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + { + struct lttng_kernel_event_recorder_private *event_recorder_priv = + container_of(event_priv, struct lttng_kernel_event_recorder_private, parent); + struct lttng_kernel_event_recorder *event_recorder = + event_recorder_priv->pub; + struct lttng_channel *chan = event_recorder->chan; + + if (unlikely(!LTTNG_READ_ONCE(chan->session->active))) + return 0; + if (unlikely(!LTTNG_READ_ONCE(chan->enabled))) + return 0; + break; + } + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + break; + default: + WARN_ON_ONCE(1); + } - if (unlikely(!READ_ONCE(event_notifier->parent.enabled))) + if (unlikely(!LTTNG_READ_ONCE(event->enabled))) return 0; - notif_ctx.eval_capture = LTTNG_READ_ONCE(event_notifier->eval_capture); - event_notifier->notification_send(event_notifier, NULL, NULL, ¬if_ctx); - + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + { + struct lttng_kernel_event_recorder *event_recorder = + container_of(event, struct lttng_kernel_event_recorder, parent); + struct lttng_channel *chan = event_recorder->chan; + struct lttng_kernel_ring_buffer_ctx ctx; + int ret; + + lib_ring_buffer_ctx_init(&ctx, event_recorder, sizeof(data), + lttng_alignof(data), <tng_probe_ctx); + ret = chan->ops->event_reserve(&ctx); + if (ret < 0) + return 0; + lib_ring_buffer_align_ctx(&ctx, lttng_alignof(data)); + chan->ops->event_write(&ctx, &data, sizeof(data)); + chan->ops->event_commit(&ctx); + break; + } + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + { + struct lttng_kernel_event_notifier *event_notifier = + container_of(event, struct lttng_kernel_event_notifier, parent); + struct lttng_kernel_notification_ctx notif_ctx; + + notif_ctx.eval_capture = LTTNG_READ_ONCE(event_notifier->eval_capture); + event_notifier->notification_send(event_notifier, NULL, NULL, ¬if_ctx); + break; + } + default: + WARN_ON_ONCE(1); + } return 0; } @@ -244,7 +259,7 @@ int lttng_kprobes_register_event_notifier(const char *symbol_name, goto error; ret = _lttng_kprobes_register(symbol_name, offset, addr, - &event_notifier->priv->parent.u.kprobe, lttng_kprobes_event_notifier_handler_pre); + &event_notifier->priv->parent.u.kprobe, lttng_kprobes_event_handler_pre); if (ret) goto register_error;