1 #ifndef _BABELTRACE_CTF_TYPES_H
2 #define _BABELTRACE_CTF_TYPES_H
9 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
22 #include <babeltrace/types.h>
30 off_t offset
; /* offset of the packet in the file, in bytes */
31 size_t packet_size
; /* packet size, in bits */
32 size_t content_size
; /* content size, in bits */
36 * Always update ctf_stream_pos with ctf_move_pos and ctf_init_pos.
38 struct ctf_stream_pos
{
39 struct stream_pos parent
;
40 int fd
; /* backing file fd. -1 if unset. */
41 GArray
*packet_index
; /* contains struct packet_index */
42 int prot
; /* mmap protection */
43 int flags
; /* mmap flags */
45 /* Current position */
46 off_t mmap_offset
; /* mmap offset in the file, in bytes */
47 size_t packet_size
; /* current packet size, in bits */
48 size_t content_size
; /* current content size, in bits */
49 uint32_t *content_size_loc
; /* pointer to current content size */
50 char *base
; /* mmap base address */
51 size_t offset
; /* offset from base, in bits */
52 size_t cur_index
; /* current index in packet index */
54 int dummy
; /* dummy position, for length calculation */
58 struct ctf_stream_pos
*ctf_pos(struct stream_pos
*pos
)
60 return container_of(pos
, struct ctf_stream_pos
, parent
);
64 * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
67 * All write primitives, as well as read for dynamically sized entities, can
68 * receive a NULL ptr/dest parameter. In this case, no write is performed, but
69 * the size is returned.
72 uint64_t ctf_uint_read(struct stream_pos
*pos
,
73 const struct declaration_integer
*integer_declaration
);
74 int64_t ctf_int_read(struct stream_pos
*pos
,
75 const struct declaration_integer
*integer_declaration
);
76 void ctf_uint_write(struct stream_pos
*pos
,
77 const struct declaration_integer
*integer_declaration
,
79 void ctf_int_write(struct stream_pos
*pos
,
80 const struct declaration_integer
*integer_declaration
,
83 double ctf_double_read(struct stream_pos
*pos
,
84 const struct declaration_float
*src
);
85 void ctf_double_write(struct stream_pos
*pos
,
86 const struct declaration_float
*dest
,
88 long double ctf_ldouble_read(struct stream_pos
*pos
,
89 const struct declaration_float
*src
);
90 void ctf_ldouble_write(struct stream_pos
*pos
,
91 const struct declaration_float
*dest
,
93 void ctf_float_copy(struct stream_pos
*destp
,
94 struct stream_pos
*srcp
,
95 const struct declaration_float
*float_declaration
);
97 void ctf_string_copy(struct stream_pos
*dest
, struct stream_pos
*src
,
98 const struct declaration_string
*string_declaration
);
99 void ctf_string_read(char **dest
, struct stream_pos
*src
,
100 const struct declaration_string
*string_declaration
);
101 void ctf_string_write(struct stream_pos
*dest
, const char *src
,
102 const struct declaration_string
*string_declaration
);
103 void ctf_string_free_temp(char *string
);
105 GArray
*ctf_enum_read(struct stream_pos
*pos
,
106 const struct declaration_enum
*src
);
107 void ctf_enum_write(struct stream_pos
*pos
,
108 const struct declaration_enum
*dest
,
110 void ctf_struct_begin(struct stream_pos
*pos
,
111 const struct declaration_struct
*struct_declaration
);
112 void ctf_struct_end(struct stream_pos
*pos
,
113 const struct declaration_struct
*struct_declaration
);
114 void ctf_variant_begin(struct stream_pos
*pos
,
115 const struct declaration_variant
*variant_declaration
);
116 void ctf_variant_end(struct stream_pos
*pos
,
117 const struct declaration_variant
*variant_declaration
);
118 void ctf_array_begin(struct stream_pos
*pos
,
119 const struct declaration_array
*array_declaration
);
120 void ctf_array_end(struct stream_pos
*pos
,
121 const struct declaration_array
*array_declaration
);
122 void ctf_sequence_begin(struct stream_pos
*pos
,
123 const struct declaration_sequence
*sequence_declaration
);
124 void ctf_sequence_end(struct stream_pos
*pos
,
125 const struct declaration_sequence
*sequence_declaration
);
127 void ctf_move_pos_slow(struct ctf_stream_pos
*pos
, size_t offset
);
129 void ctf_init_pos(struct ctf_stream_pos
*pos
, int fd
);
130 void ctf_fini_pos(struct ctf_stream_pos
*pos
);
133 * move_pos - move position of a relative bit offset
135 * TODO: allow larger files by updating base too.
138 void ctf_move_pos(struct ctf_stream_pos
*pos
, size_t bit_offset
)
141 if (((pos
->prot
== PROT_READ
)
142 && (pos
->offset
+ bit_offset
>= pos
->content_size
))
143 || ((pos
->prot
== PROT_WRITE
)
144 && (pos
->offset
+ bit_offset
>= pos
->packet_size
))) {
145 ctf_move_pos_slow(pos
, bit_offset
);
149 pos
->offset
+= bit_offset
;
153 * align_pos - align position on a bit offset (> 0)
155 * TODO: allow larger files by updating base too.
158 void ctf_align_pos(struct ctf_stream_pos
*pos
, size_t bit_offset
)
160 ctf_move_pos(pos
, offset_align(pos
->offset
, bit_offset
));
164 char *ctf_get_pos_addr(struct ctf_stream_pos
*pos
)
166 /* Only makes sense to get the address after aligning on CHAR_BIT */
167 assert(!(pos
->offset
% CHAR_BIT
));
168 return pos
->base
+ (pos
->offset
/ CHAR_BIT
);
172 void ctf_dummy_pos(struct ctf_stream_pos
*pos
, struct ctf_stream_pos
*dummy
)
174 memcpy(dummy
, pos
, sizeof(struct ctf_stream_pos
));
180 * Check if current packet can hold data.
181 * Returns 0 for success, negative error otherwise.
184 int ctf_pos_packet(struct ctf_stream_pos
*dummy
)
186 if (dummy
->offset
> dummy
->packet_size
)
192 void ctf_pos_pad_packet(struct ctf_stream_pos
*pos
)
194 ctf_move_pos(pos
, pos
->packet_size
- pos
->offset
);
197 #endif /* _BABELTRACE_CTF_TYPES_H */
This page took 0.03373 seconds and 5 git commands to generate.