Commit | Line | Data |
---|---|---|
96f85541 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
96f85541 MD |
3 | * |
4 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
c0c0989a | 6 | * LTTng UST Instruction Pointer Context. |
96f85541 MD |
7 | */ |
8 | ||
3fbec7dc | 9 | #define _LGPL_SOURCE |
9af5d97a | 10 | #include <limits.h> |
b4051ad8 | 11 | #include <stddef.h> |
96f85541 MD |
12 | #include <sys/types.h> |
13 | #include <unistd.h> | |
14 | #include <lttng/ust-events.h> | |
15 | #include <lttng/ust-tracer.h> | |
0466ac28 | 16 | #include <lttng/ringbuffer-context.h> |
96f85541 | 17 | |
fc80554e MJ |
18 | #include "context-internal.h" |
19 | ||
96f85541 | 20 | static |
daacdbfc | 21 | size_t ip_get_size(struct lttng_ust_ctx_field *field, size_t offset) |
96f85541 MD |
22 | { |
23 | size_t size = 0; | |
24 | ||
25 | size += lib_ring_buffer_align(offset, lttng_alignof(void *)); | |
26 | size += sizeof(void *); | |
27 | return size; | |
28 | } | |
29 | ||
30 | static | |
daacdbfc | 31 | void ip_record(struct lttng_ust_ctx_field *field, |
96f85541 | 32 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
e7bc0ef6 | 33 | struct lttng_ust_channel_buffer *chan) |
96f85541 MD |
34 | { |
35 | void *ip; | |
36 | ||
37 | ip = ctx->ip; | |
38 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(ip)); | |
39 | chan->ops->event_write(ctx, &ip, sizeof(ip)); | |
40 | } | |
41 | ||
daacdbfc | 42 | int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx) |
96f85541 | 43 | { |
daacdbfc | 44 | struct lttng_ust_ctx_field *field; |
a084756d MD |
45 | struct lttng_ust_type_common *type; |
46 | int ret; | |
96f85541 | 47 | |
a084756d MD |
48 | type = lttng_ust_create_type_integer(sizeof(void *) * CHAR_BIT, |
49 | lttng_alignof(void *) * CHAR_BIT, | |
eae3c729 | 50 | lttng_ust_is_signed_type(void *), |
a084756d MD |
51 | BYTE_ORDER, 16); |
52 | if (!type) | |
96f85541 | 53 | return -ENOMEM; |
a084756d MD |
54 | field = lttng_append_context(ctx); |
55 | if (!field) { | |
56 | ret = -ENOMEM; | |
57 | goto error_context; | |
58 | } | |
96f85541 | 59 | if (lttng_find_context(*ctx, "ip")) { |
a084756d MD |
60 | ret = -EEXIST; |
61 | goto error_find_context; | |
96f85541 | 62 | } |
a084756d MD |
63 | field->event_field->name = strdup("ip"); |
64 | if (!field->event_field->name) { | |
65 | ret = -ENOMEM; | |
66 | goto error_name; | |
67 | } | |
68 | field->event_field->type = type; | |
96f85541 MD |
69 | field->get_size = ip_get_size; |
70 | field->record = ip_record; | |
b2cc986a | 71 | lttng_context_update(*ctx); |
96f85541 | 72 | return 0; |
a084756d MD |
73 | |
74 | error_name: | |
75 | error_find_context: | |
76 | lttng_remove_context_field(ctx, field); | |
77 | error_context: | |
78 | lttng_ust_destroy_type(type); | |
79 | return ret; | |
96f85541 | 80 | } |