X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fctf-writer%2Fserialize-internal.h;h=85e2fec348bd96dbdccf139b0279fd42c89d503b;hb=e1e02a22957d83adc526c016d5d3b978b8e6d26d;hp=15ced8debe823b0f048b2cf93ff3284eb3e0a098;hpb=3d9990ac8bcbb870300869ed217b80151b52bf4e;p=babeltrace.git diff --git a/include/babeltrace/ctf-writer/serialize-internal.h b/include/babeltrace/ctf-writer/serialize-internal.h index 15ced8de..85e2fec3 100644 --- a/include/babeltrace/ctf-writer/serialize-internal.h +++ b/include/babeltrace/ctf-writer/serialize-internal.h @@ -26,17 +26,30 @@ * http://www.efficios.com/ctf */ +#include #include #include -#include +#include #include #include #include -#include -#include -#include #include +#include +#include #include +#include +#include +#include +#include +#include + +#define PACKET_LEN_INCREMENT (bt_common_get_page_size() * 8 * CHAR_BIT) + +#if (BYTE_ORDER == BIG_ENDIAN) +# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN +#else +# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN +#endif struct bt_ctf_stream_pos { int fd; @@ -47,18 +60,17 @@ struct bt_ctf_stream_pos { off_t mmap_offset; /* mmap offset in the file, in bytes */ off_t mmap_base_offset; /* offset of start of packet in mmap, in bytes */ uint64_t packet_size; /* current packet size, in bits */ - uint64_t content_size; /* current content size, in bits */ int64_t offset; /* offset from base, in bits. EOF for end of file. */ struct mmap_align *base_mma;/* mmap base address */ }; BT_HIDDEN -int bt_ctf_field_integer_write(struct bt_ctf_field_integer *field, +int bt_ctf_field_integer_write(struct bt_ctf_field_common *field, struct bt_ctf_stream_pos *pos, enum bt_ctf_byte_order native_byte_order); BT_HIDDEN -int bt_ctf_field_floating_point_write(struct bt_ctf_field_floating_point *field, +int bt_ctf_field_floating_point_write(struct bt_ctf_field_common *field, struct bt_ctf_stream_pos *pos, enum bt_ctf_byte_order native_byte_order); @@ -69,16 +81,20 @@ int bt_ctf_stream_pos_access_ok(struct bt_ctf_stream_pos *pos, uint64_t bit_len) if (unlikely(pos->offset == EOF)) return 0; + if (pos->prot == PROT_READ) { /* * Reads may only reach up to the "content_size", * regardless of the packet_size. */ - max_len = pos->content_size; + max_len = pos->offset; } else { /* Writes may take place up to the end of the packet. */ max_len = pos->packet_size; } + if (unlikely(pos->offset < 0 || bit_len > INT64_MAX - pos->offset)) { + return 0; + } if (unlikely(pos->offset + bit_len > max_len)) return 0; return 1; @@ -109,8 +125,8 @@ static inline char *bt_ctf_stream_pos_get_addr(struct bt_ctf_stream_pos *pos) { /* Only makes sense to get the address after aligning on CHAR_BIT */ - assert(!(pos->offset % CHAR_BIT)); - return mmap_align_addr(pos->base_mma) + + BT_ASSERT(!(pos->offset % CHAR_BIT)); + return ((char *) mmap_align_addr(pos->base_mma)) + pos->mmap_base_offset + (pos->offset / CHAR_BIT); } @@ -130,7 +146,7 @@ int bt_ctf_stream_pos_init(struct bt_ctf_stream_pos *pos, pos->flags = MAP_SHARED; break; default: - assert(false); + abort(); } return 0;