fix: adjust ranges for RHEL 8.2 and 8.3
[lttng-modules.git] / lttng-context-procname.c
1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
3 * lttng-context-procname.c
4 *
5 * LTTng procname context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <lttng-events.h>
14 #include <wrapper/ringbuffer/frontend_types.h>
15 #include <wrapper/vmalloc.h>
16 #include <lttng-tracer.h>
17
18 static
19 size_t procname_get_size(size_t offset)
20 {
21 size_t size = 0;
22
23 size += sizeof(current->comm);
24 return size;
25 }
26
27 /*
28 * Racy read of procname. We simply copy its whole array size.
29 * Races with /proc/<task>/procname write only.
30 * Otherwise having to take a mutex for each event is cumbersome and
31 * could lead to crash in IRQ context and deadlock of the lockdep tracer.
32 */
33 static
34 void procname_record(struct lttng_ctx_field *field,
35 struct lib_ring_buffer_ctx *ctx,
36 struct lttng_channel *chan)
37 {
38 chan->ops->event_write(ctx, current->comm, sizeof(current->comm));
39 }
40
41 static
42 void procname_get_value(struct lttng_ctx_field *field,
43 struct lttng_probe_ctx *lttng_probe_ctx,
44 union lttng_ctx_value *value)
45 {
46 value->str = current->comm;
47 }
48
49 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
50 {
51 struct lttng_ctx_field *field;
52
53 field = lttng_append_context(ctx);
54 if (!field)
55 return -ENOMEM;
56 if (lttng_find_context(*ctx, "procname")) {
57 lttng_remove_context_field(ctx, field);
58 return -EEXIST;
59 }
60 field->event_field.name = "procname";
61 field->event_field.type.atype = atype_array;
62 field->event_field.type.u.array.elem_type.atype = atype_integer;
63 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
64 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
65 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char);
66 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
67 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
68 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
69 field->event_field.type.u.array.length = sizeof(current->comm);
70
71 field->get_size = procname_get_size;
72 field->record = procname_record;
73 field->get_value = procname_get_value;
74 lttng_context_update(*ctx);
75 wrapper_vmalloc_sync_mappings();
76 return 0;
77 }
78 EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx);
This page took 0.041326 seconds and 4 git commands to generate.