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> | |
0b4b8811 | 16 | #include <lttng/ust-ringbuffer-context.h> |
96f85541 | 17 | |
fc80554e MJ |
18 | #include "context-internal.h" |
19 | ||
96f85541 | 20 | static |
4e48b5d2 | 21 | size_t ip_get_size(void *priv __attribute__((unused)), |
2208d8b5 | 22 | size_t offset) |
96f85541 MD |
23 | { |
24 | size_t size = 0; | |
25 | ||
b5457df5 | 26 | size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(void *)); |
96f85541 MD |
27 | size += sizeof(void *); |
28 | return size; | |
29 | } | |
30 | ||
31 | static | |
4e48b5d2 | 32 | void ip_record(void *priv __attribute__((unused)), |
b5457df5 | 33 | struct lttng_ust_ring_buffer_ctx *ctx, |
e7bc0ef6 | 34 | struct lttng_ust_channel_buffer *chan) |
96f85541 MD |
35 | { |
36 | void *ip; | |
37 | ||
38 | ip = ctx->ip; | |
8936b6c0 | 39 | chan->ops->event_write(ctx, &ip, sizeof(ip), lttng_ust_rb_alignof(ip)); |
96f85541 MD |
40 | } |
41 | ||
4e48b5d2 MD |
42 | static const struct lttng_ust_ctx_field *ctx_field = lttng_ust_static_ctx_field( |
43 | lttng_ust_static_event_field("ip", | |
44 | lttng_ust_static_type_integer(sizeof(void *) * CHAR_BIT, | |
45 | lttng_ust_rb_alignof(void *) * CHAR_BIT, | |
46 | lttng_ust_is_signed_type(void *), | |
47 | BYTE_ORDER, 10), | |
48 | false, false), | |
49 | ip_get_size, | |
50 | ip_record, | |
51 | NULL, NULL, NULL); | |
52 | ||
daacdbfc | 53 | int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx) |
96f85541 | 54 | { |
a084756d | 55 | int ret; |
96f85541 | 56 | |
4e48b5d2 | 57 | if (lttng_find_context(*ctx, ctx_field->event_field->name)) { |
a084756d MD |
58 | ret = -EEXIST; |
59 | goto error_find_context; | |
96f85541 | 60 | } |
4e48b5d2 MD |
61 | ret = lttng_ust_context_append(ctx, ctx_field); |
62 | if (ret) | |
63 | return ret; | |
96f85541 | 64 | return 0; |
a084756d | 65 | |
a084756d | 66 | error_find_context: |
a084756d | 67 | return ret; |
96f85541 | 68 | } |