Fix: syscall event rule: emission sites not compared in is_equal
[lttng-tools.git] / src / common / buffer-view.hpp
CommitLineData
01dc0eed 1/*
ab5be9fa 2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
01dc0eed 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
01dc0eed 5 *
01dc0eed
JG
6 */
7
8#ifndef LTTNG_BUFFER_VIEW_H
9#define LTTNG_BUFFER_VIEW_H
10
c9e313bc 11#include <common/macros.hpp>
28f23191 12
67d8e2ef 13#include <stdbool.h>
01dc0eed
JG
14#include <stddef.h>
15#include <stdint.h>
16
17struct lttng_dynamic_buffer;
18
19struct lttng_buffer_view {
20 const char *data;
21 size_t size;
22};
23
b35aac84
JG
24/**
25 * Return a buffer view referencing a subset of the memory referenced by a raw
26 * pointer.
27 *
28 * @src Source buffer to reference
29 * @offset Offset to apply to the source memory buffer
30 * @len Length of the memory contents to reference.
31 *
32 * Note that a buffer view never assumes the ownership of the memory it
33 * references.
34 */
28f23191 35struct lttng_buffer_view lttng_buffer_view_init(const char *src, size_t offset, ptrdiff_t len);
b35aac84 36
3e6e0df2
JG
37/**
38 * Checks if a buffer view is safe to access.
39 *
40 * After calling the buffer view creation functions, callers should verify
41 * if the resquested length (if any is explicitly provided) could be mapped
42 * to a new view.
b2530e4d
JG
43 *
44 * @view Buffer view to validate
3e6e0df2 45 */
3e6e0df2
JG
46bool lttng_buffer_view_is_valid(const struct lttng_buffer_view *view);
47
01dc0eed
JG
48/**
49 * Return a buffer view referencing a subset of the memory referenced by another
50 * view.
51 *
52 * @src Source view to reference
53 * @offset Offset to apply to the source memory content
54 * @len Length of the memory contents to reference. Passing -1 will
55 * cause the view to reference the whole view from the offset
56 * provided.
57 *
58 * Note that a buffer view never assumes the ownership of the memory it
59 * references.
60 */
28f23191
JG
61struct lttng_buffer_view
62lttng_buffer_view_from_view(const struct lttng_buffer_view *src, size_t offset, ptrdiff_t len);
01dc0eed
JG
63
64/**
65 * Return a buffer view referencing a subset of the memory referenced by a
66 * dynamic buffer.
67 *
68 * @src Source dynamic buffer to reference
69 * @offset Offset to apply to the source memory content
70 * @len Length of the memory contents to reference. Passing -1 will
71 * cause the view to reference the whole dynamic buffer from the
72 * offset provided.
73 *
74 * Note that a buffer view never assumes the ownership of the memory it
75 * references.
76 */
77struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
28f23191 78 const struct lttng_dynamic_buffer *src, size_t offset, ptrdiff_t len);
01dc0eed 79
67d8e2ef
SM
80/**
81 * Verify that `buf` contains a string starting at `str` of length
82 * `len_with_null_terminator`.
83 *
84 * @buf The buffer view
85 * @str The start of the string
86 * @len_with_null_terminator Expected length of the string, including the
87 * NULL terminator.
88 */
67d8e2ef 89bool lttng_buffer_view_contains_string(const struct lttng_buffer_view *buf,
28f23191
JG
90 const char *str,
91 size_t len_with_null_terminator);
67d8e2ef 92
01dc0eed 93#endif /* LTTNG_BUFFER_VIEW_H */
This page took 0.068284 seconds and 4 git commands to generate.