static
int bt_ctf_field_structure_serialize(struct bt_ctf_field *field,
		struct ctf_stream_pos *pos)
{
	size_t i;
	int ret = 0;
	struct bt_ctf_field_structure *structure = container_of(
		field, struct bt_ctf_field_structure, parent);

	while (!ctf_pos_access_ok(pos,
		offset_align(pos->offset,
			field->type->declaration->alignment))) {
		ret = increase_packet_size(pos);
		if (ret) {
			goto end;
		}
	}

	if (!ctf_align_pos(pos, field->type->declaration->alignment)) {
		ret = -1;
		goto end;
	}

	for (i = 0; i < structure->fields->len; i++) {
		struct bt_ctf_field *field = g_ptr_array_index(
			structure->fields, i);

		ret = bt_ctf_field_serialize(field, pos);
		if (ret) {
			break;
		}
	}
end:
	return ret;
}
Exemple #2
0
int ctf_string_write(struct bt_stream_pos *ppos,
		      struct bt_definition *definition)
{
	struct definition_string *string_definition =
		container_of(definition, struct definition_string, p);
	const struct declaration_string *string_declaration =
		string_definition->declaration;
	struct ctf_stream_pos *pos = ctf_pos(ppos);
	size_t len;
	char *destaddr;

	if (!ctf_align_pos(pos, string_declaration->p.alignment))
		return -EFAULT;
	assert(string_definition->value != NULL);
	len = string_definition->len;

	if (!ctf_pos_access_ok(pos, len))
		return -EFAULT;

	if (pos->dummy)
		goto end;
	destaddr = ctf_get_pos_addr(pos);
	memcpy(destaddr, string_definition->value, len);
end:
	if (!ctf_move_pos(pos, len * CHAR_BIT))
		return -EFAULT;
	return 0;
}
Exemple #3
0
int ctf_sequence_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
	struct definition_sequence *sequence_definition =
		container_of(definition, struct definition_sequence, p);
	struct declaration_sequence *sequence_declaration =
		sequence_definition->declaration;
	struct bt_declaration *elem = sequence_declaration->elem;
	struct ctf_stream_pos *pos = ctf_pos(ppos);

	if (elem->id == CTF_TYPE_INTEGER) {
		struct declaration_integer *integer_declaration =
			container_of(elem, struct declaration_integer, p);

		if (integer_declaration->encoding == CTF_STRING_UTF8
		      || integer_declaration->encoding == CTF_STRING_ASCII) {

			if (integer_declaration->len == CHAR_BIT
			    && integer_declaration->p.alignment == CHAR_BIT) {
				uint64_t len = bt_sequence_len(sequence_definition);

				if (!ctf_align_pos(pos, integer_declaration->p.alignment))
					return -EFAULT;
				if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
					return -EFAULT;

				memcpy((char *) ctf_get_pos_addr(pos),
					sequence_definition->string->str, (size_t)len);
				if (!ctf_move_pos(pos, len * CHAR_BIT))
					return -EFAULT;
				return 0;
			}
		}
	}
	return bt_sequence_rw(ppos, definition);
}