74 u64 * x = va_arg (*va,
u64 *);
78 *x = ((
u64) hi << 32) | (
u64) lo;
83 u32 * x = va_arg (*va,
u32 *);
89 u16 * x = va_arg (*va,
u16 *);
97 u8 * x = va_arg (*va,
u8 *);
105 f64 x = va_arg (*va,
f64);
113 f32 x = va_arg (*va,
f64);
121 f64 * x = va_arg (*va,
f64 *);
129 f32 * x = va_arg (*va,
f32 *);
137 u32 len = s ? strlen (s) : 0;
160 if (len > 0 && len != 0xFFFFFFFF)
175 u8 * s = va_arg (*va,
u8 *);
176 u32 n = va_arg (*va,
u32);
183 u8 * s = va_arg (*va,
u8 *);
184 u32 n = va_arg (*va,
u32);
190 void serialize_vec_##n_bits (serialize_main_t * m, va_list * va) \ 192 u##n_bits * s = va_arg (*va, u##n_bits *); \ 193 u32 n = va_arg (*va, u32); \ 194 u##n_bits * p = serialize_get (m, n * sizeof (s[0])); \ 198 p[0] = clib_host_to_net_u##n_bits (s[0]); \ 199 p[1] = clib_host_to_net_u##n_bits (s[1]); \ 200 p[2] = clib_host_to_net_u##n_bits (s[2]); \ 201 p[3] = clib_host_to_net_u##n_bits (s[3]); \ 209 p[0] = clib_host_to_net_u##n_bits (s[0]); \ 216 void unserialize_vec_##n_bits (serialize_main_t * m, va_list * va) \ 218 u##n_bits * s = va_arg (*va, u##n_bits *); \ 219 u32 n = va_arg (*va, u32); \ 220 u##n_bits * p = unserialize_get (m, n * sizeof (s[0])); \ 224 s[0] = clib_net_to_host_mem_u##n_bits (&p[0]); \ 225 s[1] = clib_net_to_host_mem_u##n_bits (&p[1]); \ 226 s[2] = clib_net_to_host_mem_u##n_bits (&p[2]); \ 227 s[3] = clib_net_to_host_mem_u##n_bits (&p[3]); \ 235 s[0] = clib_net_to_host_mem_u##n_bits (&p[0]); \ 248 #define SERIALIZE_VECTOR_CHUNK_SIZE 64 252 void * vec = va_arg (*va,
void *);
253 u32 elt_bytes = va_arg (*va,
u32);
284 p = v = _vec_resize (0, l, l*elt_bytes, header_bytes, align);
298 void ** vec = va_arg (*va,
void **);
299 u32 elt_bytes = va_arg (*va,
u32);
301 u32 align = va_arg (*va,
u32);
312 void ** vec = va_arg (*va,
void **);
313 u32 elt_bytes = va_arg (*va,
u32);
328 n_u32s = l *
sizeof (b[0]) /
sizeof (
u32);
332 for (i = 0; i < l; i++)
349 i = (n_u32s *
sizeof (
u32) +
sizeof (b[0]) - 1) /
sizeof (b[0]);
351 for (i = 0; i < n_u32s; i++)
360 b[i/2] |= (
u64) data << (
u64) 0;
362 b[i/2] |= (
u64) data << (
u64) 32;
375 void * pool = va_arg (*va,
void *);
376 u32 elt_bytes = va_arg (*va,
u32);
392 serialize (m, f, pool + lo*elt_bytes, hi - lo));
410 v = _vec_resize (0, l, l*elt_bytes,
sizeof (p[0]), align);
428 void ** result = va_arg (*va,
void **);
429 u32 elt_bytes = va_arg (*va,
u32);
436 void ** result = va_arg (*va,
void **);
437 u32 elt_bytes = va_arg (*va,
u32);
438 u32 align = va_arg (*va,
u32);
447 for (i = 0; i < n; i++)
459 for (i = 0; i < n; i++)
469 void * heap = va_arg (*va,
void *);
481 #define foreach_serialize_heap_header_integer \ 482 _ (head) _ (tail) _ (used_count) _ (max_len) _ (flags) _ (elt_bytes) 484 #define _(f) serialize_integer (m, h->f, sizeof (h->f)); 518 void ** result = va_arg (*va,
void **);
531 memset (&h, 0,
sizeof (h));
532 #define _(f) unserialize_integer (m, &h.f, sizeof (h.f)); 557 heap = *result = _heap_new (vl, h.
elt_bytes);
595 if (l != magic_bytes)
601 if (memcmp (magic, d, magic_bytes))
652 uword n_bytes_to_write,
655 uword cur_bi, n_left_b, n_left_o;
664 if (n_left_o > 0 && n_left_b > 0)
687 }
while (n_left_o > 0);
689 if (n_left_o > 0 || n_left_b < n_bytes_to_write)
698 return s->
buffer + cur_bi;
704 uword n_bytes_to_read,
707 uword cur_bi, cur_oi, n_left_b, n_left_o, n_left_to_read;
718 if (n_left_o >= n_bytes_to_read)
731 n_left_to_read = n_bytes_to_read;
732 while (n_left_to_read > 0)
738 if (n_left_o + n_left_b < n_bytes_to_read)
744 n_left_o += n_left_b;
745 n_left_to_read -= n_left_b;
763 && n_left_to_read == n_bytes_to_read
764 && n_left_b >= n_left_to_read)
767 return s->
buffer + cur_bi;
776 n_left_o += n_left_to_read;
782 n =
clib_min (n_left_to_read, n_left_b);
802 (m, s, n_bytes, flags));
830 memset (m, 0,
sizeof (m[0]));
851 memset (m, 0,
sizeof (m[0]));
868 memset (m, 0,
sizeof (m[0]));
880 uword n_left = n_data;
885 p[0] = d[0 * data_stride];
886 p[1] = d[1 * data_stride];
887 p[2] = d[2 * data_stride];
888 p[3] = d[3 * data_stride];
890 d += 4 * data_stride;
900 d += 1 * data_stride;
914 uword n_left = n_data;
924 d += 4 * data_stride;
934 d += 1 * data_stride;
948 uword n_left = n_data;
958 d += 4 * data_stride;
968 d += 1 * data_stride;
982 uword n_left = n_data;
987 d[0 * data_stride] = p[0];
988 d[1 * data_stride] = p[1];
989 d[2 * data_stride] = p[2];
990 d[3 * data_stride] = p[3];
992 d += 4 * data_stride;
1002 d += 1 * data_stride;
1016 uword n_left = n_data;
1026 d += 4 * data_stride;
1036 d += 1 * data_stride;
1050 uword n_left = n_data;
1060 d += 4 * data_stride;
1070 d += 1 * data_stride;
1095 _vec_len (s->
buffer) = 0;
1123 memset (m, 0,
sizeof (m[0]));
1147 mode = is_read ? O_RDONLY : O_RDWR | O_CREAT | O_TRUNC;
1148 fd = open (file, mode, 0666);
static void serialize_vector_write(serialize_main_header_t *m, serialize_stream_t *s)
sll srl srl sll sra u16x4 i
void serialize_f32(serialize_main_t *m, va_list *va)
void unserialize_check_magic(serialize_main_t *m, void *magic, u32 magic_bytes)
u32 current_overflow_index
#define serialize_error_return(m, args...)
void serialize_bitmap(serialize_main_t *m, uword *b)
void serialize_multiple_4(serialize_main_t *m, void *data, uword data_stride, uword n_data)
#define vec_serialize(m, v, f)
serialize_main_header_t header
#define vec_unserialize(m, v, f)
always_inline void serialize_likely_small_unsigned_integer(serialize_main_t *m, u64 x)
void unserialize_32(serialize_main_t *m, va_list *va)
void unserialize_multiple_2(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void serialize_f64(serialize_main_t *m, va_list *va)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static clib_error_t * serialize_open_unix_file_helper(serialize_main_t *m, char *file, uword is_read)
add_epi add_epi sub_epi sub_epi adds_epu subs_epu i16x8 y
uword clib_setjmp(clib_longjmp_t *save, uword return_value_not_taken)
static void unix_file_read(serialize_main_header_t *m, serialize_stream_t *s)
always_inline heap_elt_t * heap_next(heap_elt_t *e)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
always_inline uword heap_is_free(heap_elt_t *e)
always_inline heap_header_t * heap_header(void *v)
#define SERIALIZE_VECTOR_CHUNK_SIZE
#define foreach_serialize_heap_header_integer
void * unserialize_vector_ha(serialize_main_t *m, u32 elt_bytes, u32 header_bytes, u32 align, u32 max_length, serialize_function_t *f)
clib_error_t * serialize_open_unix_file(serialize_main_t *m, char *file)
always_inline void serialize_stream_set_end_of_stream(serialize_stream_t *s)
clib_error_t * unserialize_open_unix_file(serialize_main_t *m, char *file)
void unserialize_open_data(serialize_main_t *m, u8 *data, uword n_data_bytes)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
void unserialize_heap(serialize_main_t *m, va_list *va)
always_inline void unserialize_integer(serialize_main_t *m, void *x, u32 n_bytes)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
void unserialize_aligned_vector(serialize_main_t *m, va_list *va)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
always_inline uword heap_offset(heap_elt_t *e)
static void * serialize_read_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes_to_read, uword flags)
void serialize_16(serialize_main_t *m, va_list *va)
always_inline void serialize_error(serialize_main_header_t *m, clib_error_t *error)
#define SERIALIZE_FLAG_IS_READ
void unserialize_vec_8(serialize_main_t *m, va_list *va)
serialize_function_t serialize_vec_32
always_inline uword serialize_stream_is_end_of_stream(serialize_stream_t *s)
void serialize_open_data(serialize_main_t *m, u8 *data, uword n_data_bytes)
void serialize_pool(serialize_main_t *m, va_list *va)
void unserialize_multiple_4(serialize_main_t *m, void *data, uword data_stride, uword n_data)
#define clib_error_return_unix(e, args...)
void unserialize_8(serialize_main_t *m, va_list *va)
always_inline void * unserialize_get(serialize_main_t *m, uword n_bytes)
void serialize_8(serialize_main_t *m, va_list *va)
#define clib_error_create(args...)
always_inline word unix_error_is_fatal(word error)
static void serialize_read_write_close(serialize_main_header_t *m, serialize_stream_t *s, uword flags)
void unserialize_open_unix_file_descriptor(serialize_main_t *m, int fd)
void unserialize_cstring(serialize_main_t *m, char **s)
void * serialize_read_write_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes, uword flags)
#define uword_to_pointer(u, type)
serialize_stream_t stream
clib_error_t * serialize(serialize_main_t *m,...)
void serialize_open_vector(serialize_main_t *m, u8 *vector)
#define vec_free(V)
Free vector's memory (no header).
#define clib_memcpy(a, b, c)
serialize_data_function_t * data_function
always_inline void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
void unserialize_close(serialize_main_t *m)
static void serialize_vec_heap_elt(serialize_main_t *m, va_list *va)
uword data_function_opaque
void serialize_multiple_2(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void serialize_magic(serialize_main_t *m, void *magic, u32 magic_bytes)
void unserialize_16(serialize_main_t *m, va_list *va)
void serialize_vec_8(serialize_main_t *m, va_list *va)
void unserialize_aligned_pool(serialize_main_t *m, va_list *va)
void unserialize_multiple_1(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void serialize_open_unix_file_descriptor(serialize_main_t *m, int fd)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
void serialize_close(serialize_main_t *m)
#define pool_foreach_region(LO, HI, POOL, BODY)
clib_error_t * unserialize(serialize_main_t *m,...)
always_inline pool_header_t * pool_header(void *v)
void serialize_cstring(serialize_main_t *m, char *s)
static void unserialize_vec_heap_elt(serialize_main_t *m, va_list *va)
void serialize_32(serialize_main_t *m, va_list *va)
static void * serialize_write_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes_to_write, uword flags)
void unserialize_f64(serialize_main_t *m, va_list *va)
void unserialize_vector(serialize_main_t *m, va_list *va)
void unserialize_f32(serialize_main_t *m, va_list *va)
uword * unserialize_bitmap(serialize_main_t *m)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void( serialize_function_t)(serialize_main_t *m, va_list *va)
void serialize_heap(serialize_main_t *m, va_list *va)
void serialize_vector(serialize_main_t *m, va_list *va)
always_inline uword heap_elt_size(void *v, heap_elt_t *e)
static void serialize_open_unix_file_descriptor_helper(serialize_main_t *m, int fd, uword is_read)
static void unix_file_write(serialize_main_header_t *m, serialize_stream_t *s)
clib_error_t * va_serialize(serialize_main_t *sm, va_list *va)
void unserialize_pool(serialize_main_t *m, va_list *va)
static void * unserialize_pool_helper(serialize_main_t *m, u32 elt_bytes, u32 align, serialize_function_t *f)
#define SERIALIZE_FLAG_IS_WRITE
#define clib_mem_unaligned(pointer, type)
#define vec_foreach(var, vec)
Vector iterator.
always_inline void * serialize_get(serialize_main_t *m, uword n_bytes)
void * serialize_close_vector(serialize_main_t *m)
always_inline u64 unserialize_likely_small_unsigned_integer(serialize_main_t *m)
void unserialize_64(serialize_main_t *m, va_list *va)
void serialize_64(serialize_main_t *m, va_list *va)
void serialize_multiple_1(serialize_main_t *m, void *data, uword data_stride, uword n_data)
clib_longjmp_t error_longjmp
serialize_function_t unserialize_vec_32