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 |
b4051ad8 | 10 | #include <stddef.h> |
96f85541 MD |
11 | #include <sys/types.h> |
12 | #include <unistd.h> | |
13 | #include <lttng/ust-events.h> | |
14 | #include <lttng/ust-tracer.h> | |
15 | #include <lttng/ringbuffer-config.h> | |
16 | ||
fc80554e MJ |
17 | #include "context-internal.h" |
18 | ||
96f85541 | 19 | static |
daacdbfc | 20 | size_t ip_get_size(struct lttng_ust_ctx_field *field, size_t offset) |
96f85541 MD |
21 | { |
22 | size_t size = 0; | |
23 | ||
24 | size += lib_ring_buffer_align(offset, lttng_alignof(void *)); | |
25 | size += sizeof(void *); | |
26 | return size; | |
27 | } | |
28 | ||
29 | static | |
daacdbfc | 30 | void ip_record(struct lttng_ust_ctx_field *field, |
96f85541 MD |
31 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
32 | struct lttng_channel *chan) | |
33 | { | |
34 | void *ip; | |
35 | ||
36 | ip = ctx->ip; | |
37 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(ip)); | |
38 | chan->ops->event_write(ctx, &ip, sizeof(ip)); | |
39 | } | |
40 | ||
daacdbfc | 41 | int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx) |
96f85541 | 42 | { |
daacdbfc | 43 | struct lttng_ust_ctx_field *field; |
a084756d MD |
44 | struct lttng_ust_type_common *type; |
45 | int ret; | |
96f85541 | 46 | |
a084756d MD |
47 | type = lttng_ust_create_type_integer(sizeof(void *) * CHAR_BIT, |
48 | lttng_alignof(void *) * CHAR_BIT, | |
49 | lttng_is_signed_type(void *), | |
50 | BYTE_ORDER, 16); | |
51 | if (!type) | |
96f85541 | 52 | return -ENOMEM; |
a084756d MD |
53 | field = lttng_append_context(ctx); |
54 | if (!field) { | |
55 | ret = -ENOMEM; | |
56 | goto error_context; | |
57 | } | |
96f85541 | 58 | if (lttng_find_context(*ctx, "ip")) { |
a084756d MD |
59 | ret = -EEXIST; |
60 | goto error_find_context; | |
96f85541 | 61 | } |
a084756d MD |
62 | field->event_field->name = strdup("ip"); |
63 | if (!field->event_field->name) { | |
64 | ret = -ENOMEM; | |
65 | goto error_name; | |
66 | } | |
67 | field->event_field->type = type; | |
96f85541 MD |
68 | field->get_size = ip_get_size; |
69 | field->record = ip_record; | |
b2cc986a | 70 | lttng_context_update(*ctx); |
96f85541 | 71 | return 0; |
a084756d MD |
72 | |
73 | error_name: | |
74 | error_find_context: | |
75 | lttng_remove_context_field(ctx, field); | |
76 | error_context: | |
77 | lttng_ust_destroy_type(type); | |
78 | return ret; | |
96f85541 | 79 | } |