uprobe: Support multiple call sites for the same uprobe event
[lttng-modules.git] / lttng-context-vppid.c
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
886d51a3 3 * lttng-context-vppid.c
b64bc438
MD
4 *
5 * LTTng vPPID context.
6 *
886d51a3 7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
b64bc438
MD
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
13#include <linux/syscalls.h>
241ae9a8
MD
14#include <lttng-events.h>
15#include <wrapper/ringbuffer/frontend_types.h>
16#include <wrapper/vmalloc.h>
17#include <lttng-tracer.h>
b64bc438
MD
18
19static
20size_t vppid_get_size(size_t offset)
21{
22 size_t size = 0;
23
a90917c3 24 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
b64bc438
MD
25 size += sizeof(pid_t);
26 return size;
27}
28
29static
30void vppid_record(struct lttng_ctx_field *field,
31 struct lib_ring_buffer_ctx *ctx,
a90917c3 32 struct lttng_channel *chan)
b64bc438 33{
90f96adf 34 struct task_struct *parent;
b64bc438
MD
35 pid_t vppid;
36
90f96adf 37 /*
de544ea5
MD
38 * current nsproxy can be NULL when scheduled out of exit. pid_vnr uses
39 * the current thread nsproxy to perform the lookup.
90f96adf 40 */
1638c9b4
MD
41
42 /*
43 * TODO: when we eventually add RCU subsystem instrumentation,
44 * taking the rcu read lock here will trigger RCU tracing
45 * recursively. We should modify the kernel synchronization so
46 * it synchronizes both for RCU and RCU sched, and rely on
47 * rcu_read_lock_sched_notrace.
48 */
49
b64bc438 50 rcu_read_lock();
90f96adf 51 parent = rcu_dereference(current->real_parent);
de544ea5 52 if (!current->nsproxy)
90f96adf
MD
53 vppid = 0;
54 else
55 vppid = task_tgid_vnr(parent);
b64bc438 56 rcu_read_unlock();
a90917c3 57 lib_ring_buffer_align_ctx(ctx, lttng_alignof(vppid));
b64bc438
MD
58 chan->ops->event_write(ctx, &vppid, sizeof(vppid));
59}
60
f127e61e
MD
61static
62void vppid_get_value(struct lttng_ctx_field *field,
79150a49 63 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
64 union lttng_ctx_value *value)
65{
66 struct task_struct *parent;
67 pid_t vppid;
68
69 /*
70 * current nsproxy can be NULL when scheduled out of exit. pid_vnr uses
71 * the current thread nsproxy to perform the lookup.
72 */
73
74 /*
75 * TODO: when we eventually add RCU subsystem instrumentation,
76 * taking the rcu read lock here will trigger RCU tracing
77 * recursively. We should modify the kernel synchronization so
78 * it synchronizes both for RCU and RCU sched, and rely on
79 * rcu_read_lock_sched_notrace.
80 */
81
82 rcu_read_lock();
83 parent = rcu_dereference(current->real_parent);
84 if (!current->nsproxy)
85 vppid = 0;
86 else
87 vppid = task_tgid_vnr(parent);
88 rcu_read_unlock();
89 value->s64 = vppid;
90}
91
b64bc438
MD
92int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx)
93{
94 struct lttng_ctx_field *field;
b64bc438
MD
95
96 field = lttng_append_context(ctx);
97 if (!field)
09fec6b4 98 return -ENOMEM;
44252f0f
MD
99 if (lttng_find_context(*ctx, "vppid")) {
100 lttng_remove_context_field(ctx, field);
101 return -EEXIST;
102 }
b64bc438
MD
103 field->event_field.name = "vppid";
104 field->event_field.type.atype = atype_integer;
105 field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
a90917c3 106 field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
06254b0f 107 field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t);
b64bc438
MD
108 field->event_field.type.u.basic.integer.reverse_byte_order = 0;
109 field->event_field.type.u.basic.integer.base = 10;
110 field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
111 field->get_size = vppid_get_size;
112 field->record = vppid_record;
f127e61e 113 field->get_value = vppid_get_value;
a9dd15da 114 lttng_context_update(*ctx);
b64bc438
MD
115 wrapper_vmalloc_sync_all();
116 return 0;
117}
118EXPORT_SYMBOL_GPL(lttng_add_vppid_to_ctx);
This page took 0.039162 seconds and 4 git commands to generate.