Move headers under include/
[lttng-modules.git] / lttng-context-user-ns.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
a6cf40a4
MJ
2 *
3 * lttng-context-user-ns.c
4 *
5 * LTTng user namespace context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * 2019 Michael Jeanson <mjeanson@efficios.com>
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/sched.h>
15#include <linux/user_namespace.h>
b5304713
MD
16#include <lttng/lttng-events.h>
17#include <ringbuffer/frontend_types.h>
18#include <lttng/lttng-tracer.h>
a6cf40a4 19
9f920259 20#if defined(CONFIG_USER_NS)
a6cf40a4
MJ
21
22static
23size_t user_ns_get_size(size_t offset)
24{
25 size_t size = 0;
26
27 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int));
28 size += sizeof(unsigned int);
29 return size;
30}
31
32static
33void user_ns_record(struct lttng_ctx_field *field,
34 struct lib_ring_buffer_ctx *ctx,
35 struct lttng_channel *chan)
36{
37 unsigned int user_ns_inum = 0;
38
39 if (current_user_ns())
6388029c 40 user_ns_inum = current_user_ns()->ns.inum;
a6cf40a4
MJ
41
42 lib_ring_buffer_align_ctx(ctx, lttng_alignof(user_ns_inum));
43 chan->ops->event_write(ctx, &user_ns_inum, sizeof(user_ns_inum));
44}
45
46static
47void user_ns_get_value(struct lttng_ctx_field *field,
48 struct lttng_probe_ctx *lttng_probe_ctx,
49 union lttng_ctx_value *value)
50{
51 unsigned int user_ns_inum = 0;
52
53 if (current_user_ns())
6388029c 54 user_ns_inum = current_user_ns()->ns.inum;
a6cf40a4
MJ
55
56 value->s64 = user_ns_inum;
57}
58
59int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx)
60{
61 struct lttng_ctx_field *field;
62
63 field = lttng_append_context(ctx);
64 if (!field)
65 return -ENOMEM;
66 if (lttng_find_context(*ctx, "user_ns")) {
67 lttng_remove_context_field(ctx, field);
68 return -EEXIST;
69 }
70 field->event_field.name = "user_ns";
71 field->event_field.type.atype = atype_integer;
ceabb767
MD
72 field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT;
73 field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT;
74 field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int);
75 field->event_field.type.u.integer.reverse_byte_order = 0;
76 field->event_field.type.u.integer.base = 10;
77 field->event_field.type.u.integer.encoding = lttng_encode_none;
a6cf40a4
MJ
78 field->get_size = user_ns_get_size;
79 field->record = user_ns_record;
80 field->get_value = user_ns_get_value;
81 lttng_context_update(*ctx);
a6cf40a4
MJ
82 return 0;
83}
84EXPORT_SYMBOL_GPL(lttng_add_user_ns_to_ctx);
85
86#endif
This page took 0.028026 seconds and 4 git commands to generate.