Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
dc923e75 MJ |
2 | * |
3 | * lttng-context-vegid.c | |
4 | * | |
5 | * LTTng namespaced effective group ID 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/sched.h> | |
2df37e95 MD |
14 | #include <lttng/events.h> |
15 | #include <lttng/tracer.h> | |
24591303 | 16 | #include <ringbuffer/frontend_types.h> |
dc923e75 MJ |
17 | #include <wrapper/vmalloc.h> |
18 | #include <wrapper/user_namespace.h> | |
19 | ||
20 | static | |
21 | size_t vegid_get_size(size_t offset) | |
22 | { | |
23 | size_t size = 0; | |
24 | ||
25 | size += lib_ring_buffer_align(offset, lttng_alignof(gid_t)); | |
26 | size += sizeof(gid_t); | |
27 | return size; | |
28 | } | |
29 | ||
30 | static | |
31 | void vegid_record(struct lttng_ctx_field *field, | |
32 | struct lib_ring_buffer_ctx *ctx, | |
33 | struct lttng_channel *chan) | |
34 | { | |
35 | gid_t vegid; | |
36 | ||
37 | vegid = lttng_current_vegid(); | |
38 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(vegid)); | |
39 | chan->ops->event_write(ctx, &vegid, sizeof(vegid)); | |
40 | } | |
41 | ||
42 | static | |
43 | void vegid_get_value(struct lttng_ctx_field *field, | |
44 | struct lttng_probe_ctx *lttng_probe_ctx, | |
45 | union lttng_ctx_value *value) | |
46 | { | |
47 | value->s64 = lttng_current_vegid(); | |
48 | } | |
49 | ||
50 | int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx) | |
51 | { | |
52 | struct lttng_ctx_field *field; | |
53 | ||
54 | field = lttng_append_context(ctx); | |
55 | if (!field) | |
56 | return -ENOMEM; | |
57 | if (lttng_find_context(*ctx, "vegid")) { | |
58 | lttng_remove_context_field(ctx, field); | |
59 | return -EEXIST; | |
60 | } | |
61 | field->event_field.name = "vegid"; | |
62 | field->event_field.type.atype = atype_integer; | |
ceabb767 MD |
63 | field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; |
64 | field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; | |
65 | field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); | |
66 | field->event_field.type.u.integer.reverse_byte_order = 0; | |
67 | field->event_field.type.u.integer.base = 10; | |
68 | field->event_field.type.u.integer.encoding = lttng_encode_none; | |
dc923e75 MJ |
69 | field->get_size = vegid_get_size; |
70 | field->record = vegid_record; | |
71 | field->get_value = vegid_get_value; | |
72 | lttng_context_update(*ctx); | |
263b6c88 | 73 | wrapper_vmalloc_sync_mappings(); |
dc923e75 MJ |
74 | return 0; |
75 | } | |
76 | EXPORT_SYMBOL_GPL(lttng_add_vegid_to_ctx); |