Пример #1
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;
}
Пример #2
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);
}
Пример #3
0
int ctf_struct_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
{
    struct bt_declaration *declaration = definition->declaration;
    struct ctf_stream_pos *pos = ctf_pos(ppos);

    ctf_align_pos(pos, declaration->alignment);
    return bt_struct_rw(ppos, definition);
}
Пример #4
0
int ctf_string_read(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;
	ssize_t max_len_bits;
	char *srcaddr;

	if (!ctf_align_pos(pos, string_declaration->p.alignment))
		return -EFAULT;

	srcaddr = ctf_get_pos_addr(pos);
	if (pos->offset == EOF)
		return -EFAULT;
	/* Not counting \0. Counting in bits. */
	max_len_bits = pos->packet_size - pos->offset - CHAR_BIT;
	if (max_len_bits < 0)
		return -EFAULT;
	/* Add \0, counting in bytes. */
	len = bt_strnlen(srcaddr, (size_t) max_len_bits / CHAR_BIT) + 1;
	/* Truncated string, unexpected. Trace probably corrupted. */
	if (srcaddr[len - 1] != '\0')
		return -EFAULT;

	if (string_definition->alloc_len < len) {
		string_definition->value =
			g_realloc(string_definition->value, len);
		string_definition->alloc_len = len;
	}
	printf_debug("CTF string read %s\n", srcaddr);
	memcpy(string_definition->value, srcaddr, len);
	string_definition->len = len;
	if (!ctf_move_pos(pos, len * CHAR_BIT))
		return -EFAULT;
	return 0;
}