Make API CTF-agnostic
[babeltrace.git] / include / babeltrace / ctf-writer / serialize-internal.h
index 5cf8c5bd660a787a54d7f61df37df993dff5371b..85e2fec348bd96dbdccf139b0279fd42c89d503b 100644 (file)
 #include <stdlib.h>
 #include <stdint.h>
 #include <limits.h>
-#include <sys/mman.h>
+#include <babeltrace/compat/mman-internal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/fields-internal.h>
 #include <babeltrace/align-internal.h>
+#include <babeltrace/endian-internal.h>
+#include <babeltrace/common-internal.h>
 #include <babeltrace/mmap-align-internal.h>
 #include <babeltrace/types.h>
+#include <babeltrace/ctf-writer/field-types.h>
+#include <babeltrace/ctf-writer/fields-internal.h>
+#include <babeltrace/ctf-writer/fields.h>
+#include <babeltrace/assert-internal.h>
+
+#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;
@@ -54,12 +65,12 @@ struct bt_ctf_stream_pos {
 };
 
 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);
 
@@ -81,6 +92,9 @@ int bt_ctf_stream_pos_access_ok(struct bt_ctf_stream_pos *pos, uint64_t bit_len)
                /* 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;
@@ -111,7 +125,7 @@ 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));
+       BT_ASSERT(!(pos->offset % CHAR_BIT));
        return ((char *) mmap_align_addr(pos->base_mma)) +
                pos->mmap_base_offset + (pos->offset / CHAR_BIT);
 }
This page took 0.025746 seconds and 4 git commands to generate.