Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 2 | * |
886d51a3 | 3 | * lttng-context-procname.c |
25b2f99a | 4 | * |
c26fddc2 | 5 | * LTTng procname context. |
25b2f99a | 6 | * |
886d51a3 | 7 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
25b2f99a MD |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/sched.h> | |
2df37e95 | 13 | #include <lttng/events.h> |
437d5aa5 | 14 | #include <lttng/events-internal.h> |
24591303 | 15 | #include <ringbuffer/frontend_types.h> |
241ae9a8 | 16 | #include <wrapper/vmalloc.h> |
2df37e95 MD |
17 | #include <lttng/tracer.h> |
18 | #include <lttng/endian.h> | |
25b2f99a MD |
19 | |
20 | static | |
346cb5ee | 21 | size_t procname_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) |
25b2f99a MD |
22 | { |
23 | size_t size = 0; | |
24 | ||
25 | size += sizeof(current->comm); | |
26 | return size; | |
27 | } | |
28 | ||
29 | /* | |
c26fddc2 MD |
30 | * Racy read of procname. We simply copy its whole array size. |
31 | * Races with /proc/<task>/procname write only. | |
25b2f99a MD |
32 | * Otherwise having to take a mutex for each event is cumbersome and |
33 | * could lead to crash in IRQ context and deadlock of the lockdep tracer. | |
34 | */ | |
35 | static | |
346cb5ee | 36 | void procname_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, |
e27e4381 | 37 | struct lttng_kernel_ring_buffer_ctx *ctx, |
ac847066 | 38 | struct lttng_kernel_channel_buffer *chan) |
25b2f99a | 39 | { |
77fcffef | 40 | chan->ops->event_write(ctx, current->comm, sizeof(current->comm), 1); |
25b2f99a MD |
41 | } |
42 | ||
f127e61e | 43 | static |
ea2d95e4 | 44 | void procname_get_value(void *priv, |
346cb5ee | 45 | struct lttng_kernel_probe_ctx *lttng_probe_ctx, |
ea2d95e4 | 46 | struct lttng_ctx_value *value) |
f127e61e | 47 | { |
ea2d95e4 | 48 | value->u.str = current->comm; |
f127e61e MD |
49 | } |
50 | ||
437d5aa5 MD |
51 | static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( |
52 | lttng_kernel_static_event_field("procname", | |
53 | lttng_kernel_static_type_array_text(sizeof(current->comm)), | |
07aafa15 | 54 | false, false), |
437d5aa5 | 55 | procname_get_size, |
437d5aa5 MD |
56 | procname_record, |
57 | procname_get_value, | |
58 | NULL, NULL); | |
ceabb767 | 59 | |
437d5aa5 | 60 | int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx) |
25b2f99a | 61 | { |
437d5aa5 | 62 | int ret; |
25b2f99a | 63 | |
437d5aa5 | 64 | if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name)) |
44252f0f | 65 | return -EEXIST; |
437d5aa5 | 66 | ret = lttng_kernel_context_append(ctx, ctx_field); |
263b6c88 | 67 | wrapper_vmalloc_sync_mappings(); |
437d5aa5 | 68 | return ret; |
25b2f99a | 69 | } |
c26fddc2 | 70 | EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx); |