X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=probes%2Flttng-kprobes.c;h=40fe0f68d54e41e8d032ece226ef117cbf06a416;hb=ceabb767180e064629b5a9ab4ed14449da864763;hp=38ee4513811691273de7454f0415ee56c6da44ce;hpb=e64957da15e3652322dcf6a5389beb01901de8e6;p=lttng-modules.git diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index 38ee4513..40fe0f68 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -1,43 +1,49 @@ -/* - * (C) Copyright 2009-2011 - - * Mathieu Desnoyers +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * probes/lttng-kprobes.c * * LTTng kprobes integration module. * - * Dual LGPL v2.1/GPL v2 license. + * Copyright (C) 2009-2012 Mathieu Desnoyers */ #include #include #include -#include "../ltt-events.h" -#include "../wrapper/ringbuffer/frontend_types.h" -#include "../wrapper/vmalloc.h" -#include "../ltt-tracer.h" +#include +#include +#include +#include +#include +#include static int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) { - struct ltt_event *event = - container_of(p, struct ltt_event, u.kprobe.kp); - struct ltt_channel *chan = event->chan; + struct lttng_event *event = + container_of(p, struct lttng_event, u.kprobe.kp); + struct lttng_probe_ctx lttng_probe_ctx = { + .event = event, + .interruptible = !lttng_regs_irqs_disabled(regs), + }; + struct lttng_channel *chan = event->chan; struct lib_ring_buffer_ctx ctx; int ret; unsigned long data = (unsigned long) p->addr; - if (unlikely(!ACCESS_ONCE(chan->session->active))) + if (unlikely(!READ_ONCE(chan->session->active))) return 0; - if (unlikely(!ACCESS_ONCE(chan->enabled))) + if (unlikely(!READ_ONCE(chan->enabled))) return 0; - if (unlikely(!ACCESS_ONCE(event->enabled))) + if (unlikely(!READ_ONCE(event->enabled))) return 0; - lib_ring_buffer_ctx_init(&ctx, chan->chan, event, sizeof(data), - ltt_alignof(data), -1); + lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, sizeof(data), + lttng_alignof(data), -1); ret = chan->ops->event_reserve(&ctx, event->id); if (ret < 0) return 0; - lib_ring_buffer_align_ctx(&ctx, ltt_alignof(data)); + lib_ring_buffer_align_ctx(&ctx, lttng_alignof(data)); chan->ops->event_write(&ctx, &data, sizeof(data)); chan->ops->event_commit(&ctx); return 0; @@ -47,7 +53,7 @@ int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) * Create event description */ static -int lttng_create_kprobe_event(const char *name, struct ltt_event *event) +int lttng_create_kprobe_event(const char *name, struct lttng_event *event) { struct lttng_event_field *field; struct lttng_event_desc *desc; @@ -70,12 +76,12 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event) } field->name = "ip"; field->type.atype = atype_integer; - field->type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - field->type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT; - field->type.u.basic.integer.signedness = is_signed_type(unsigned long); - field->type.u.basic.integer.reverse_byte_order = 0; - field->type.u.basic.integer.base = 16; - field->type.u.basic.integer.encoding = lttng_encode_none; + field->type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + field->type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + field->type.u.integer.signedness = lttng_is_signed_type(unsigned long); + field->type.u.integer.reverse_byte_order = 0; + field->type.u.integer.base = 16; + field->type.u.integer.encoding = lttng_encode_none; desc->owner = THIS_MODULE; event->desc = desc; @@ -92,28 +98,34 @@ int lttng_kprobes_register(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct ltt_event *event) + struct lttng_event *event) { 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_KERNEL_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_KERNEL_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. @@ -138,13 +150,13 @@ error: } EXPORT_SYMBOL_GPL(lttng_kprobes_register); -void lttng_kprobes_unregister(struct ltt_event *event) +void lttng_kprobes_unregister(struct lttng_event *event) { unregister_kprobe(&event->u.kprobe.kp); } EXPORT_SYMBOL_GPL(lttng_kprobes_unregister); -void lttng_kprobes_destroy_private(struct ltt_event *event) +void lttng_kprobes_destroy_private(struct lttng_event *event) { kfree(event->u.kprobe.symbol_name); kfree(event->desc->fields); @@ -154,5 +166,9 @@ void lttng_kprobes_destroy_private(struct ltt_event *event) EXPORT_SYMBOL_GPL(lttng_kprobes_destroy_private); MODULE_LICENSE("GPL and additional rights"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("Linux Trace Toolkit Kprobes Support"); +MODULE_AUTHOR("Mathieu Desnoyers "); +MODULE_DESCRIPTION("LTTng kprobes probes"); +MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." + __stringify(LTTNG_MODULES_MINOR_VERSION) "." + __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) + LTTNG_MODULES_EXTRAVERSION);