*
*/
-#include "bytecode.h"
+#include "bytecode.hpp"
+#include "common/align.hpp"
-#include <errno.h>
#include <algorithm>
-
-#include "common/align.h"
+#include <errno.h>
#define INIT_ALLOC_SIZE 4
-static inline
-int get_count_order(unsigned int count)
+static inline int get_count_order(unsigned int count)
{
int order;
}
}
-static
-int32_t bytecode_reserve(struct lttng_bytecode_alloc **fb, uint32_t align, uint32_t len)
+static int32_t bytecode_reserve(struct lttng_bytecode_alloc **fb, uint32_t align, uint32_t len)
{
int32_t ret;
- uint32_t padding = lttng_offset_align((*fb)->b.len, align);
- uint32_t new_len = (*fb)->b.len + padding + len;
+ const uint32_t padding = lttng_offset_align((*fb)->b.len, align);
+ const uint32_t new_len = (*fb)->b.len + padding + len;
uint32_t new_alloc_len = sizeof(struct lttng_bytecode_alloc) + new_len;
- uint32_t old_alloc_len = (*fb)->alloc_len;
+ const uint32_t old_alloc_len = (*fb)->alloc_len;
if (new_len > LTTNG_FILTER_MAX_LEN)
return -EINVAL;
if (new_alloc_len > old_alloc_len) {
struct lttng_bytecode_alloc *newptr;
- new_alloc_len =
- std::max(1U << get_count_order(new_alloc_len), old_alloc_len << 1);
+ new_alloc_len = std::max(1U << get_count_order(new_alloc_len), old_alloc_len << 1);
newptr = (lttng_bytecode_alloc *) realloc(*fb, new_alloc_len);
if (!newptr)
return -ENOMEM;
return ret;
}
-int bytecode_push(struct lttng_bytecode_alloc **fb, const void *data,
- uint32_t align, uint32_t len)
+int bytecode_push(struct lttng_bytecode_alloc **fb, const void *data, uint32_t align, uint32_t len)
{
int32_t offset;
}
int bytecode_push_logical(struct lttng_bytecode_alloc **fb,
- struct logical_op *data,
- uint32_t align, uint32_t len,
- uint16_t *skip_offset)
+ struct logical_op *data,
+ uint32_t align,
+ uint32_t len,
+ uint16_t *skip_offset)
{
int32_t offset;
if (offset < 0)
return offset;
memcpy(&(*fb)->b.data[offset], data, len);
- *skip_offset =
- (char *) &((struct logical_op *) &(*fb)->b.data[offset])->skip_offset
- - (char *) &(*fb)->b.data[0];
+ *skip_offset = (char *) &((struct logical_op *) &(*fb)->b.data[offset])->skip_offset -
+ (char *) &(*fb)->b.data[0];
return 0;
}
return ret;
}
-int bytecode_push_get_index_u64(struct lttng_bytecode_alloc **bytecode,
- uint64_t index)
+int bytecode_push_get_index_u64(struct lttng_bytecode_alloc **bytecode, uint64_t index)
{
int ret;
struct load_op *insn;
struct get_index_u64 index_op_data;
- const uint32_t insn_len =
- sizeof(struct load_op) + sizeof(struct get_index_u64);
+ const uint32_t insn_len = sizeof(struct load_op) + sizeof(struct get_index_u64);
insn = (load_op *) calloc(insn_len, 1);
if (!insn) {
}
int bytecode_push_get_symbol(struct lttng_bytecode_alloc **bytecode,
- struct lttng_bytecode_alloc **bytecode_reloc,
- const char *symbol)
+ struct lttng_bytecode_alloc **bytecode_reloc,
+ const char *symbol)
{
int ret;
struct load_op *insn;
uint32_t reloc_offset_u32;
uint16_t reloc_offset;
uint32_t bytecode_reloc_offset_u32;
- const uint32_t insn_len =
- sizeof(struct load_op) + sizeof(struct get_symbol);
+ const uint32_t insn_len = sizeof(struct load_op) + sizeof(struct get_symbol);
insn = (load_op *) calloc(insn_len, 1);
if (!insn) {
* Get offset in the reloc portion at which the symbol name
* will end up at (GET_SYMBOL's operand points there).
*/
- bytecode_reloc_offset_u32 = bytecode_get_len(&(*bytecode_reloc)->b) +
- sizeof(reloc_offset);
+ bytecode_reloc_offset_u32 = bytecode_get_len(&(*bytecode_reloc)->b) + sizeof(reloc_offset);
symbol_offset.offset = (uint16_t) bytecode_reloc_offset_u32;
memcpy(insn->data, &symbol_offset, sizeof(symbol_offset));
}
/* Append reloc offset. */
- ret = bytecode_push(bytecode_reloc, &reloc_offset,
- 1, sizeof(reloc_offset));
+ ret = bytecode_push(bytecode_reloc, &reloc_offset, 1, sizeof(reloc_offset));
if (ret) {
goto end;
}
*
* Return allocated bytecode or NULL on error.
*/
-struct lttng_bytecode *lttng_bytecode_copy(
- const struct lttng_bytecode *orig_f)
+struct lttng_bytecode *lttng_bytecode_copy(const struct lttng_bytecode *orig_f)
{
- struct lttng_bytecode *bytecode = NULL;
-
- bytecode = (lttng_bytecode *) zmalloc(sizeof(*bytecode) + orig_f->len);
+ lttng_bytecode *bytecode = zmalloc<lttng_bytecode>(sizeof(*bytecode) + orig_f->len);
if (!bytecode) {
goto error;
}