API refactoring: introduce probe context
[lttng-ust.git] / src / lib / lttng-ust / lttng-context-ip.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng UST Instruction Pointer Context.
7 */
8
9 #define _LGPL_SOURCE
10 #include <limits.h>
11 #include <stddef.h>
12 #include <sys/types.h>
13 #include <unistd.h>
14 #include <lttng/ust-events.h>
15 #include <lttng/ust-tracer.h>
16 #include <lttng/ust-ringbuffer-context.h>
17
18 #include "context-internal.h"
19
20 static
21 size_t ip_get_size(void *priv __attribute__((unused)),
22 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
23 size_t offset)
24 {
25 size_t size = 0;
26
27 size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(void *));
28 size += sizeof(void *);
29 return size;
30 }
31
32 static
33 void ip_record(void *priv __attribute__((unused)),
34 struct lttng_ust_probe_ctx *probe_ctx,
35 struct lttng_ust_ring_buffer_ctx *ctx,
36 struct lttng_ust_channel_buffer *chan)
37 {
38 void *ip;
39
40 ip = probe_ctx->ip;
41 chan->ops->event_write(ctx, &ip, sizeof(ip), lttng_ust_rb_alignof(ip));
42 }
43
44 static
45 void ip_get_value(void *priv __attribute__((unused)),
46 struct lttng_ust_probe_ctx *probe_ctx,
47 struct lttng_ust_ctx_value *value)
48 {
49 value->u.u64 = (unsigned long) probe_ctx->ip;
50 }
51
52 static const struct lttng_ust_ctx_field *ctx_field = lttng_ust_static_ctx_field(
53 lttng_ust_static_event_field("ip",
54 lttng_ust_static_type_integer(sizeof(void *) * CHAR_BIT,
55 lttng_ust_rb_alignof(void *) * CHAR_BIT,
56 lttng_ust_is_signed_type(void *),
57 LTTNG_UST_BYTE_ORDER, 10),
58 false, false),
59 ip_get_size,
60 ip_record,
61 ip_get_value,
62 NULL, NULL);
63
64 int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx)
65 {
66 int ret;
67
68 if (lttng_find_context(*ctx, ctx_field->event_field->name)) {
69 ret = -EEXIST;
70 goto error_find_context;
71 }
72 ret = lttng_ust_context_append(ctx, ctx_field);
73 if (ret)
74 return ret;
75 return 0;
76
77 error_find_context:
78 return ret;
79 }
This page took 0.030209 seconds and 4 git commands to generate.