1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3 * lttng-context-user-ns.c
5 * LTTng user namespace context.
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * 2019 Michael Jeanson <mjeanson@efficios.com>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/sched.h>
17 #include <linux/user_namespace.h>
18 #include <lttng/events.h>
19 #include <lttng/events-internal.h>
20 #include <ringbuffer/frontend_types.h>
21 #include <wrapper/vmalloc.h>
22 #include <lttng/tracer.h>
25 size_t user_ns_get_size(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
, size_t offset
)
29 size
+= lib_ring_buffer_align(offset
, lttng_alignof(unsigned int));
30 size
+= sizeof(unsigned int);
35 void user_ns_record(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
,
36 struct lttng_kernel_ring_buffer_ctx
*ctx
,
37 struct lttng_kernel_channel_buffer
*chan
)
39 unsigned int user_ns_inum
= 0;
41 if (current_user_ns())
42 user_ns_inum
= current_user_ns()->ns
.inum
;
44 chan
->ops
->event_write(ctx
, &user_ns_inum
, sizeof(user_ns_inum
), lttng_alignof(user_ns_inum
));
48 void user_ns_get_value(void *priv
,
49 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
50 struct lttng_ctx_value
*value
)
52 unsigned int user_ns_inum
= 0;
54 if (current_user_ns())
55 user_ns_inum
= current_user_ns()->ns
.inum
;
57 value
->u
.s64
= user_ns_inum
;
60 static const struct lttng_kernel_ctx_field
*ctx_field
= lttng_kernel_static_ctx_field(
61 lttng_kernel_static_event_field("user_ns",
62 lttng_kernel_static_type_integer_from_type(unsigned int, __BYTE_ORDER
, 10),
69 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
73 if (lttng_kernel_find_context(*ctx
, ctx_field
->event_field
->name
))
75 ret
= lttng_kernel_context_append(ctx
, ctx_field
);
76 wrapper_vmalloc_sync_mappings();
79 EXPORT_SYMBOL_GPL(lttng_add_user_ns_to_ctx
);