API refactoring: introduce probe context
[lttng-ust.git] / src / lib / lttng-ust / lttng-context-ip.c
CommitLineData
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 20static
4e48b5d2 21size_t ip_get_size(void *priv __attribute__((unused)),
b2e37d27 22 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
2208d8b5 23 size_t offset)
96f85541
MD
24{
25 size_t size = 0;
26
b5457df5 27 size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(void *));
96f85541
MD
28 size += sizeof(void *);
29 return size;
30}
31
32static
4e48b5d2 33void ip_record(void *priv __attribute__((unused)),
b2e37d27
MD
34 struct lttng_ust_probe_ctx *probe_ctx,
35 struct lttng_ust_ring_buffer_ctx *ctx,
36 struct lttng_ust_channel_buffer *chan)
96f85541
MD
37{
38 void *ip;
39
b2e37d27 40 ip = probe_ctx->ip;
8936b6c0 41 chan->ops->event_write(ctx, &ip, sizeof(ip), lttng_ust_rb_alignof(ip));
96f85541
MD
42}
43
b2e37d27
MD
44static
45void 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
4e48b5d2
MD
52static 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 *),
baa8acf3 57 LTTNG_UST_BYTE_ORDER, 10),
4e48b5d2
MD
58 false, false),
59 ip_get_size,
60 ip_record,
b2e37d27
MD
61 ip_get_value,
62 NULL, NULL);
4e48b5d2 63
daacdbfc 64int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx)
96f85541 65{
a084756d 66 int ret;
96f85541 67
4e48b5d2 68 if (lttng_find_context(*ctx, ctx_field->event_field->name)) {
a084756d
MD
69 ret = -EEXIST;
70 goto error_find_context;
96f85541 71 }
4e48b5d2
MD
72 ret = lttng_ust_context_append(ctx, ctx_field);
73 if (ret)
74 return ret;
96f85541 75 return 0;
a084756d 76
a084756d 77error_find_context:
a084756d 78 return ret;
96f85541 79}
This page took 0.03359 seconds and 4 git commands to generate.