2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_BUFFER_VIEW_H
9 #define LTTNG_BUFFER_VIEW_H
11 #include <common/macros.hpp>
17 struct lttng_dynamic_buffer;
19 struct lttng_buffer_view {
25 * Return a buffer view referencing a subset of the memory referenced by a raw
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.
32 * Note that a buffer view never assumes the ownership of the memory it
35 struct lttng_buffer_view lttng_buffer_view_init(const char *src, size_t offset, ptrdiff_t len);
38 * Checks if a buffer view is safe to access.
40 * After calling the buffer view creation functions, callers should verify
41 * if the resquested length (if any is explicitly provided) could be mapped
44 * @view Buffer view to validate
46 bool lttng_buffer_view_is_valid(const struct lttng_buffer_view *view);
49 * Return a buffer view referencing a subset of the memory referenced by another
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
58 * Note that a buffer view never assumes the ownership of the memory it
61 struct lttng_buffer_view
62 lttng_buffer_view_from_view(const struct lttng_buffer_view *src, size_t offset, ptrdiff_t len);
65 * Return a buffer view referencing a subset of the memory referenced by a
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
74 * Note that a buffer view never assumes the ownership of the memory it
77 struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer(
78 const struct lttng_dynamic_buffer *src, size_t offset, ptrdiff_t len);
81 * Verify that `buf` contains a string starting at `str` of length
82 * `len_with_null_terminator`.
84 * @buf The buffer view
85 * @str The start of the string
86 * @len_with_null_terminator Expected length of the string, including the
89 bool lttng_buffer_view_contains_string(const struct lttng_buffer_view *buf,
91 size_t len_with_null_terminator);
93 #endif /* LTTNG_BUFFER_VIEW_H */