xref: /qemu/include/migration/vmstate.h (revision ba4dba54)
1 /*
2  * QEMU migration/snapshot declarations
3  *
4  * Copyright (c) 2009-2011 Red Hat, Inc.
5  *
6  * Original author: Juan Quintela <quintela@redhat.com>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 #ifndef QEMU_VMSTATE_H
27 #define QEMU_VMSTATE_H 1
28 
29 #ifndef CONFIG_USER_ONLY
30 #include <migration/qemu-file.h>
31 #endif
32 #include "migration/qjson.h"
33 
34 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
35 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
36 
37 typedef struct SaveVMHandlers {
38     /* This runs inside the iothread lock.  */
39     void (*set_params)(const MigrationParams *params, void * opaque);
40     SaveStateHandler *save_state;
41 
42     void (*cleanup)(void *opaque);
43     int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque);
44     int (*save_live_complete_precopy)(QEMUFile *f, void *opaque);
45 
46     /* This runs both outside and inside the iothread lock.  */
47     bool (*is_active)(void *opaque);
48 
49     /* This runs outside the iothread lock in the migration case, and
50      * within the lock in the savevm case.  The callback had better only
51      * use data that is local to the migration thread or protected
52      * by other locks.
53      */
54     int (*save_live_iterate)(QEMUFile *f, void *opaque);
55 
56     /* This runs outside the iothread lock!  */
57     int (*save_live_setup)(QEMUFile *f, void *opaque);
58     void (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size,
59                               uint64_t *non_postcopiable_pending,
60                               uint64_t *postcopiable_pending);
61     LoadStateHandler *load_state;
62 } SaveVMHandlers;
63 
64 int register_savevm(DeviceState *dev,
65                     const char *idstr,
66                     int instance_id,
67                     int version_id,
68                     SaveStateHandler *save_state,
69                     LoadStateHandler *load_state,
70                     void *opaque);
71 
72 int register_savevm_live(DeviceState *dev,
73                          const char *idstr,
74                          int instance_id,
75                          int version_id,
76                          SaveVMHandlers *ops,
77                          void *opaque);
78 
79 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
80 
81 typedef struct VMStateInfo VMStateInfo;
82 typedef struct VMStateDescription VMStateDescription;
83 
84 struct VMStateInfo {
85     const char *name;
86     int (*get)(QEMUFile *f, void *pv, size_t size);
87     void (*put)(QEMUFile *f, void *pv, size_t size);
88 };
89 
90 enum VMStateFlags {
91     /* Ignored */
92     VMS_SINGLE           = 0x001,
93 
94     /* The struct member at opaque + VMStateField.offset is a pointer
95      * to the actual field (e.g. struct a { uint8_t *b;
96      * }). Dereference the pointer before using it as basis for
97      * further pointer arithmetic (see e.g. VMS_ARRAY). Does not
98      * affect the meaning of VMStateField.num_offset or
99      * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for
100      * those. */
101     VMS_POINTER          = 0x002,
102 
103     /* The field is an array of fixed size. VMStateField.num contains
104      * the number of entries in the array. The size of each entry is
105      * given by VMStateField.size and / or opaque +
106      * VMStateField.size_offset; see VMS_VBUFFER and
107      * VMS_MULTIPLY. Each array entry will be processed individually
108      * (VMStateField.info.get()/put() if VMS_STRUCT is not set,
109      * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not
110      * be combined with VMS_VARRAY*. */
111     VMS_ARRAY            = 0x004,
112 
113     /* The field is itself a struct, containing one or more
114      * fields. Recurse into VMStateField.vmsd. Most useful in
115      * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each
116      * array entry. */
117     VMS_STRUCT           = 0x008,
118 
119     /* The field is an array of variable size. The int32_t at opaque +
120      * VMStateField.num_offset contains the number of entries in the
121      * array. See the VMS_ARRAY description regarding array handling
122      * in general. May not be combined with VMS_ARRAY or any other
123      * VMS_VARRAY*. */
124     VMS_VARRAY_INT32     = 0x010,
125 
126     /* Ignored */
127     VMS_BUFFER           = 0x020,
128 
129     /* The field is a (fixed-size or variable-size) array of pointers
130      * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry
131      * before using it. Note: Does not imply any one of VMS_ARRAY /
132      * VMS_VARRAY*; these need to be set explicitly. */
133     VMS_ARRAY_OF_POINTER = 0x040,
134 
135     /* The field is an array of variable size. The uint16_t at opaque
136      * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
137      * contains the number of entries in the array. See the VMS_ARRAY
138      * description regarding array handling in general. May not be
139      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
140     VMS_VARRAY_UINT16    = 0x080,
141 
142     /* The size of the individual entries (a single array entry if
143      * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if
144      * neither is set) is variable (i.e. not known at compile-time),
145      * but the same for all entries. Use the int32_t at opaque +
146      * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine
147      * the size of each (and every) entry. */
148     VMS_VBUFFER          = 0x100,
149 
150     /* Multiply the entry size given by the int32_t at opaque +
151      * VMStateField.size_offset (see VMS_VBUFFER description) with
152      * VMStateField.size to determine the number of bytes to be
153      * allocated. Only valid in combination with VMS_VBUFFER. */
154     VMS_MULTIPLY         = 0x200,
155 
156     /* The field is an array of variable size. The uint8_t at opaque +
157      * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
158      * contains the number of entries in the array. See the VMS_ARRAY
159      * description regarding array handling in general. May not be
160      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
161     VMS_VARRAY_UINT8     = 0x400,
162 
163     /* The field is an array of variable size. The uint32_t at opaque
164      * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
165      * contains the number of entries in the array. See the VMS_ARRAY
166      * description regarding array handling in general. May not be
167      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
168     VMS_VARRAY_UINT32    = 0x800,
169 
170     /* Fail loading the serialised VM state if this field is missing
171      * from the input. */
172     VMS_MUST_EXIST       = 0x1000,
173 
174     /* When loading serialised VM state, allocate memory for the
175      * (entire) field. Only valid in combination with
176      * VMS_POINTER. Note: Not all combinations with other flags are
177      * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't
178      * cause the individual entries to be allocated. */
179     VMS_ALLOC            = 0x2000,
180 
181     /* Multiply the number of entries given by the integer at opaque +
182      * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num
183      * to determine the number of entries in the array. Only valid in
184      * combination with one of VMS_VARRAY*. */
185     VMS_MULTIPLY_ELEMENTS = 0x4000,
186 };
187 
188 typedef struct {
189     const char *name;
190     size_t offset;
191     size_t size;
192     size_t start;
193     int num;
194     size_t num_offset;
195     size_t size_offset;
196     const VMStateInfo *info;
197     enum VMStateFlags flags;
198     const VMStateDescription *vmsd;
199     int version_id;
200     bool (*field_exists)(void *opaque, int version_id);
201 } VMStateField;
202 
203 struct VMStateDescription {
204     const char *name;
205     int unmigratable;
206     int version_id;
207     int minimum_version_id;
208     int minimum_version_id_old;
209     LoadStateHandler *load_state_old;
210     int (*pre_load)(void *opaque);
211     int (*post_load)(void *opaque, int version_id);
212     void (*pre_save)(void *opaque);
213     bool (*needed)(void *opaque);
214     VMStateField *fields;
215     const VMStateDescription **subsections;
216 };
217 
218 extern const VMStateDescription vmstate_dummy;
219 
220 extern const VMStateInfo vmstate_info_bool;
221 
222 extern const VMStateInfo vmstate_info_int8;
223 extern const VMStateInfo vmstate_info_int16;
224 extern const VMStateInfo vmstate_info_int32;
225 extern const VMStateInfo vmstate_info_int64;
226 
227 extern const VMStateInfo vmstate_info_uint8_equal;
228 extern const VMStateInfo vmstate_info_uint16_equal;
229 extern const VMStateInfo vmstate_info_int32_equal;
230 extern const VMStateInfo vmstate_info_uint32_equal;
231 extern const VMStateInfo vmstate_info_uint64_equal;
232 extern const VMStateInfo vmstate_info_int32_le;
233 
234 extern const VMStateInfo vmstate_info_uint8;
235 extern const VMStateInfo vmstate_info_uint16;
236 extern const VMStateInfo vmstate_info_uint32;
237 extern const VMStateInfo vmstate_info_uint64;
238 
239 extern const VMStateInfo vmstate_info_float64;
240 extern const VMStateInfo vmstate_info_cpudouble;
241 
242 extern const VMStateInfo vmstate_info_timer;
243 extern const VMStateInfo vmstate_info_buffer;
244 extern const VMStateInfo vmstate_info_unused_buffer;
245 extern const VMStateInfo vmstate_info_bitmap;
246 
247 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
248 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
249 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
250 
251 #define vmstate_offset_value(_state, _field, _type)                  \
252     (offsetof(_state, _field) +                                      \
253      type_check(_type, typeof_field(_state, _field)))
254 
255 #define vmstate_offset_pointer(_state, _field, _type)                \
256     (offsetof(_state, _field) +                                      \
257      type_check_pointer(_type, typeof_field(_state, _field)))
258 
259 #define vmstate_offset_array(_state, _field, _type, _num)            \
260     (offsetof(_state, _field) +                                      \
261      type_check_array(_type, typeof_field(_state, _field), _num))
262 
263 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
264     (offsetof(_state, _field) +                                      \
265      type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
266 
267 #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
268     vmstate_offset_value(_state, _field[_start], _type)
269 
270 #define vmstate_offset_buffer(_state, _field)                        \
271     vmstate_offset_array(_state, _field, uint8_t,                    \
272                          sizeof(typeof_field(_state, _field)))
273 
274 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
275     .name         = (stringify(_field)),                             \
276     .version_id   = (_version),                                      \
277     .field_exists = (_test),                                         \
278     .size         = sizeof(_type),                                   \
279     .info         = &(_info),                                        \
280     .flags        = VMS_SINGLE,                                      \
281     .offset       = vmstate_offset_value(_state, _field, _type),     \
282 }
283 
284 /* Validate state using a boolean predicate. */
285 #define VMSTATE_VALIDATE(_name, _test) { \
286     .name         = (_name),                                         \
287     .field_exists = (_test),                                         \
288     .flags        = VMS_ARRAY | VMS_MUST_EXIST,                      \
289     .num          = 0, /* 0 elements: no data, only run _test */     \
290 }
291 
292 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
293     .name       = (stringify(_field)),                               \
294     .version_id = (_version),                                        \
295     .info       = &(_info),                                          \
296     .size       = sizeof(_type),                                     \
297     .flags      = VMS_SINGLE|VMS_POINTER,                            \
298     .offset     = vmstate_offset_value(_state, _field, _type),       \
299 }
300 
301 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) {  \
302     .name       = (stringify(_field)),                               \
303     .info       = &(_info),                                          \
304     .field_exists = (_test),                                         \
305     .size       = sizeof(_type),                                     \
306     .flags      = VMS_SINGLE|VMS_POINTER,                            \
307     .offset     = vmstate_offset_value(_state, _field, _type),       \
308 }
309 
310 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
311     .name       = (stringify(_field)),                               \
312     .version_id = (_version),                                        \
313     .num        = (_num),                                            \
314     .info       = &(_info),                                          \
315     .size       = sizeof(_type),                                     \
316     .flags      = VMS_ARRAY,                                         \
317     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
318 }
319 
320 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
321     .name       = (stringify(_field)),                                      \
322     .version_id = (_version),                                               \
323     .num        = (_n1) * (_n2),                                            \
324     .info       = &(_info),                                                 \
325     .size       = sizeof(_type),                                            \
326     .flags      = VMS_ARRAY,                                                \
327     .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
328 }
329 
330 #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
331     .name       = (stringify(_field)),                               \
332     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
333     .num        = (_multiply),                                       \
334     .info       = &(_info),                                          \
335     .size       = sizeof(_type),                                     \
336     .flags      = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS,           \
337     .offset     = offsetof(_state, _field),                          \
338 }
339 
340 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
341     .name         = (stringify(_field)),                              \
342     .field_exists = (_test),                                          \
343     .num          = (_num),                                           \
344     .info         = &(_info),                                         \
345     .size         = sizeof(_type),                                    \
346     .flags        = VMS_ARRAY,                                        \
347     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
348 }
349 
350 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
351     .name       = (stringify(_field)),                               \
352     .version_id = (_version),                                        \
353     .num        = (_num),                                            \
354     .info       = &(_info),                                          \
355     .size       = sizeof(_type),                                     \
356     .flags      = VMS_ARRAY,                                         \
357     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
358 }
359 
360 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
361     .name       = (stringify(_field)),                               \
362     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
363     .info       = &(_info),                                          \
364     .size       = sizeof(_type),                                     \
365     .flags      = VMS_VARRAY_INT32,                                  \
366     .offset     = offsetof(_state, _field),                          \
367 }
368 
369 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
370     .name       = (stringify(_field)),                               \
371     .version_id = (_version),                                        \
372     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
373     .info       = &(_info),                                          \
374     .size       = sizeof(_type),                                     \
375     .flags      = VMS_VARRAY_INT32|VMS_POINTER,                      \
376     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
377 }
378 
379 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
380     .name       = (stringify(_field)),                               \
381     .version_id = (_version),                                        \
382     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
383     .info       = &(_info),                                          \
384     .size       = sizeof(_type),                                     \
385     .flags      = VMS_VARRAY_UINT32|VMS_POINTER,                     \
386     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
387 }
388 
389 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
390     .name       = (stringify(_field)),                               \
391     .version_id = (_version),                                        \
392     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
393     .info       = &(_info),                                          \
394     .size       = sizeof(_type),                                     \
395     .flags      = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC,           \
396     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
397 }
398 
399 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
400     .name       = (stringify(_field)),                               \
401     .version_id = (_version),                                        \
402     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
403     .info       = &(_info),                                          \
404     .size       = sizeof(_type),                                     \
405     .flags      = VMS_VARRAY_UINT16,                                 \
406     .offset     = offsetof(_state, _field),                          \
407 }
408 
409 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
410     .name         = (stringify(_field)),                             \
411     .version_id   = (_version),                                      \
412     .field_exists = (_test),                                         \
413     .vmsd         = &(_vmsd),                                        \
414     .size         = sizeof(_type),                                   \
415     .flags        = VMS_STRUCT,                                      \
416     .offset       = vmstate_offset_value(_state, _field, _type),     \
417 }
418 
419 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
420     .name         = (stringify(_field)),                             \
421     .version_id   = (_version),                                        \
422     .vmsd         = &(_vmsd),                                        \
423     .size         = sizeof(_type *),                                 \
424     .flags        = VMS_STRUCT|VMS_POINTER,                          \
425     .offset       = vmstate_offset_pointer(_state, _field, _type),   \
426 }
427 
428 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
429     .name         = (stringify(_field)),                             \
430     .version_id   = (_version),                                        \
431     .field_exists = (_test),                                         \
432     .vmsd         = &(_vmsd),                                        \
433     .size         = sizeof(_type *),                                 \
434     .flags        = VMS_STRUCT|VMS_POINTER,                          \
435     .offset       = vmstate_offset_pointer(_state, _field, _type),   \
436 }
437 
438 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
439     .name       = (stringify(_field)),                               \
440     .version_id = (_version),                                        \
441     .num        = (_num),                                            \
442     .info       = &(_info),                                          \
443     .size       = sizeof(_type),                                     \
444     .flags      = VMS_ARRAY|VMS_ARRAY_OF_POINTER,                    \
445     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
446 }
447 
448 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
449     .name       = (stringify(_f)),                                   \
450     .version_id = (_v),                                              \
451     .num        = (_n),                                              \
452     .vmsd       = &(_vmsd),                                          \
453     .size       = sizeof(_type *),                                    \
454     .flags      = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER,         \
455     .offset     = vmstate_offset_array(_s, _f, _type*, _n),          \
456 }
457 
458 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
459     .name       = (stringify(_field)),                                     \
460     .version_id = (_version),                                              \
461     .num        = (_num),                                                  \
462     .vmsd       = &(_vmsd),                                                \
463     .size       = sizeof(_type),                                           \
464     .flags      = VMS_STRUCT|VMS_ARRAY,                                    \
465     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
466 }
467 
468 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
469     .name         = (stringify(_field)),                             \
470     .num          = (_num),                                          \
471     .field_exists = (_test),                                         \
472     .version_id   = (_version),                                      \
473     .vmsd         = &(_vmsd),                                        \
474     .size         = sizeof(_type),                                   \
475     .flags        = VMS_STRUCT|VMS_ARRAY,                            \
476     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
477 }
478 
479 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
480     .name       = (stringify(_field)),                               \
481     .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
482     .version_id = (_version),                                        \
483     .vmsd       = &(_vmsd),                                          \
484     .size       = sizeof(_type),                                     \
485     .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
486     .offset     = offsetof(_state, _field),                          \
487 }
488 
489 /* a variable length array (i.e. _type *_field) but we know the
490  * length
491  */
492 #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
493     .name       = (stringify(_field)),                               \
494     .num          = (_num),                                          \
495     .version_id = (_version),                                        \
496     .vmsd       = &(_vmsd),                                          \
497     .size       = sizeof(_type),                                     \
498     .flags      = VMS_STRUCT|VMS_ARRAY|VMS_POINTER,                  \
499     .offset     = offsetof(_state, _field),                          \
500 }
501 
502 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
503     .name       = (stringify(_field)),                               \
504     .version_id = 0,                                                 \
505     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
506     .size       = sizeof(_type),                                     \
507     .vmsd       = &(_vmsd),                                          \
508     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
509     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
510 }
511 
512 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
513     .name       = (stringify(_field)),                               \
514     .version_id = 0,                                                 \
515     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
516     .size       = sizeof(_type),                                     \
517     .vmsd       = &(_vmsd),                                          \
518     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
519     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
520 }
521 
522 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
523     .name       = (stringify(_field)),                               \
524     .version_id = 0,                                                 \
525     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
526     .size       = sizeof(_type),                                     \
527     .vmsd       = &(_vmsd),                                          \
528     .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,      \
529     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
530 }
531 
532 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
533     .name       = (stringify(_field)),                               \
534     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
535     .version_id = (_version),                                        \
536     .vmsd       = &(_vmsd),                                          \
537     .size       = sizeof(_type),                                     \
538     .flags      = VMS_STRUCT|VMS_VARRAY_INT32,                       \
539     .offset     = offsetof(_state, _field),                          \
540 }
541 
542 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
543     .name       = (stringify(_field)),                               \
544     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
545     .version_id = (_version),                                        \
546     .vmsd       = &(_vmsd),                                          \
547     .size       = sizeof(_type),                                     \
548     .flags      = VMS_STRUCT|VMS_VARRAY_UINT32,                      \
549     .offset     = offsetof(_state, _field),                          \
550 }
551 
552 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
553     .name       = (stringify(_field)),                               \
554     .version_id = (_version),                                        \
555     .vmsd       = &(_vmsd),                                          \
556     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
557     .size       = sizeof(_type),                                     \
558     .flags      = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
559     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
560 }
561 
562 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
563     .name         = (stringify(_field)),                             \
564     .version_id   = (_version),                                      \
565     .field_exists = (_test),                                         \
566     .size         = (_size - _start),                                \
567     .info         = &vmstate_info_buffer,                            \
568     .flags        = VMS_BUFFER,                                      \
569     .offset       = vmstate_offset_buffer(_state, _field) + _start,  \
570 }
571 
572 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
573     .name         = (stringify(_field)),                             \
574     .version_id   = (_version),                                      \
575     .field_exists = (_test),                                         \
576     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
577     .size         = (_multiply),                                      \
578     .info         = &vmstate_info_buffer,                            \
579     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY,            \
580     .offset       = offsetof(_state, _field),                        \
581     .start        = (_start),                                        \
582 }
583 
584 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
585     .name         = (stringify(_field)),                             \
586     .version_id   = (_version),                                      \
587     .field_exists = (_test),                                         \
588     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
589     .info         = &vmstate_info_buffer,                            \
590     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
591     .offset       = offsetof(_state, _field),                        \
592     .start        = (_start),                                        \
593 }
594 
595 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
596     .name         = (stringify(_field)),                             \
597     .version_id   = (_version),                                      \
598     .field_exists = (_test),                                         \
599     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
600     .info         = &vmstate_info_buffer,                            \
601     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
602     .offset       = offsetof(_state, _field),                        \
603     .start        = (_start),                                        \
604 }
605 
606 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, _test, _start, _field_size) { \
607     .name         = (stringify(_field)),                             \
608     .version_id   = (_version),                                      \
609     .field_exists = (_test),                                         \
610     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
611     .info         = &vmstate_info_buffer,                            \
612     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC,               \
613     .offset       = offsetof(_state, _field),                        \
614     .start        = (_start),                                        \
615 }
616 
617 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
618     .name       = (stringify(_field)),                               \
619     .version_id = (_version),                                        \
620     .field_exists = (_test),                                         \
621     .size       = (_size),                                           \
622     .info       = &(_info),                                          \
623     .flags      = VMS_BUFFER,                                        \
624     .offset     = offsetof(_state, _field),                          \
625 }
626 
627 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
628     .name       = (stringify(_field)),                               \
629     .version_id = (_version),                                        \
630     .size       = (_size),                                           \
631     .info       = &vmstate_info_buffer,                              \
632     .flags      = VMS_BUFFER|VMS_POINTER,                            \
633     .offset     = offsetof(_state, _field),                          \
634 }
635 
636 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
637     .name         = "unused",                                        \
638     .field_exists = (_test),                                         \
639     .version_id   = (_version),                                      \
640     .size         = (_size),                                         \
641     .info         = &vmstate_info_unused_buffer,                     \
642     .flags        = VMS_BUFFER,                                      \
643 }
644 
645 /* _field_size should be a int32_t field in the _state struct giving the
646  * size of the bitmap _field in bits.
647  */
648 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) {      \
649     .name         = (stringify(_field)),                             \
650     .version_id   = (_version),                                      \
651     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
652     .info         = &vmstate_info_bitmap,                            \
653     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
654     .offset       = offsetof(_state, _field),                        \
655 }
656 
657 /* _f : field name
658    _f_n : num of elements field_name
659    _n : num of elements
660    _s : struct state name
661    _v : version
662 */
663 
664 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type)        \
665     VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
666 
667 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)        \
668     VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
669 
670 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
671     VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
672 
673 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type)     \
674     VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
675 
676 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
677     VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
678             _vmsd, _type)
679 
680 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
681     VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
682             _size)
683 
684 #define VMSTATE_BOOL_V(_f, _s, _v)                                    \
685     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
686 
687 #define VMSTATE_INT8_V(_f, _s, _v)                                    \
688     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
689 #define VMSTATE_INT16_V(_f, _s, _v)                                   \
690     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
691 #define VMSTATE_INT32_V(_f, _s, _v)                                   \
692     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
693 #define VMSTATE_INT64_V(_f, _s, _v)                                   \
694     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
695 
696 #define VMSTATE_UINT8_V(_f, _s, _v)                                   \
697     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
698 #define VMSTATE_UINT16_V(_f, _s, _v)                                  \
699     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
700 #define VMSTATE_UINT32_V(_f, _s, _v)                                  \
701     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
702 #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
703     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
704 
705 #define VMSTATE_BOOL(_f, _s)                                          \
706     VMSTATE_BOOL_V(_f, _s, 0)
707 
708 #define VMSTATE_INT8(_f, _s)                                          \
709     VMSTATE_INT8_V(_f, _s, 0)
710 #define VMSTATE_INT16(_f, _s)                                         \
711     VMSTATE_INT16_V(_f, _s, 0)
712 #define VMSTATE_INT32(_f, _s)                                         \
713     VMSTATE_INT32_V(_f, _s, 0)
714 #define VMSTATE_INT64(_f, _s)                                         \
715     VMSTATE_INT64_V(_f, _s, 0)
716 
717 #define VMSTATE_UINT8(_f, _s)                                         \
718     VMSTATE_UINT8_V(_f, _s, 0)
719 #define VMSTATE_UINT16(_f, _s)                                        \
720     VMSTATE_UINT16_V(_f, _s, 0)
721 #define VMSTATE_UINT32(_f, _s)                                        \
722     VMSTATE_UINT32_V(_f, _s, 0)
723 #define VMSTATE_UINT64(_f, _s)                                        \
724     VMSTATE_UINT64_V(_f, _s, 0)
725 
726 #define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
727     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
728 
729 #define VMSTATE_UINT16_EQUAL(_f, _s)                                  \
730     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
731 
732 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v)                            \
733     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
734 
735 #define VMSTATE_INT32_EQUAL(_f, _s)                                   \
736     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
737 
738 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v)                            \
739     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t)
740 
741 #define VMSTATE_UINT32_EQUAL(_f, _s)                                  \
742     VMSTATE_UINT32_EQUAL_V(_f, _s, 0)
743 
744 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v)                            \
745     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
746 
747 #define VMSTATE_UINT64_EQUAL(_f, _s)                                  \
748     VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
749 
750 #define VMSTATE_INT32_POSITIVE_LE(_f, _s)                             \
751     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
752 
753 #define VMSTATE_INT8_TEST(_f, _s, _t)                               \
754     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
755 
756 #define VMSTATE_INT16_TEST(_f, _s, _t)                               \
757     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
758 
759 #define VMSTATE_INT32_TEST(_f, _s, _t)                                  \
760     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
761 
762 #define VMSTATE_INT64_TEST(_f, _s, _t)                                  \
763     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
764 
765 #define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
766     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
767 
768 #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
769     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
770 
771 #define VMSTATE_UINT32_TEST(_f, _s, _t)                                  \
772     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
773 
774 #define VMSTATE_UINT64_TEST(_f, _s, _t)                                  \
775     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
776 
777 
778 #define VMSTATE_FLOAT64_V(_f, _s, _v)                                 \
779     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
780 
781 #define VMSTATE_FLOAT64(_f, _s)                                       \
782     VMSTATE_FLOAT64_V(_f, _s, 0)
783 
784 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test)                             \
785     VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
786 
787 #define VMSTATE_TIMER_PTR_V(_f, _s, _v)                                   \
788     VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
789 
790 #define VMSTATE_TIMER_PTR(_f, _s)                                         \
791     VMSTATE_TIMER_PTR_V(_f, _s, 0)
792 
793 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n)                              \
794     VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
795 
796 #define VMSTATE_TIMER_TEST(_f, _s, _test)                             \
797     VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
798 
799 #define VMSTATE_TIMER_V(_f, _s, _v)                                   \
800     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
801 
802 #define VMSTATE_TIMER(_f, _s)                                         \
803     VMSTATE_TIMER_V(_f, _s, 0)
804 
805 #define VMSTATE_TIMER_ARRAY(_f, _s, _n)                              \
806     VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
807 
808 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
809     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
810 
811 #define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
812     VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
813 
814 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
815     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
816 
817 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
818     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
819 
820 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
821     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
822 
823 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
824     VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
825 
826 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
827     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
828 
829 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
830     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
831 
832 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
833     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
834 
835 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num)                \
836     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
837 
838 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
839     VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
840 
841 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
842     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
843 
844 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
845     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
846 
847 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
848     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
849 
850 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2)                      \
851     VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
852 
853 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
854     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
855 
856 #define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
857     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
858 
859 #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2)                      \
860     VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0)
861 
862 #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
863     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t)
864 
865 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v)                         \
866     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
867 
868 #define VMSTATE_INT16_ARRAY(_f, _s, _n)                               \
869     VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
870 
871 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
872     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
873 
874 #define VMSTATE_INT32_ARRAY(_f, _s, _n)                               \
875     VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
876 
877 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)                \
878     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
879 
880 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v)                         \
881     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
882 
883 #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
884     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
885 
886 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v)                       \
887     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
888 
889 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n)                             \
890     VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
891 
892 #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v)                     \
893     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
894 
895 #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n)                           \
896     VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
897 
898 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
899     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
900 
901 #define VMSTATE_BUFFER(_f, _s)                                        \
902     VMSTATE_BUFFER_V(_f, _s, 0)
903 
904 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size)                         \
905     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
906 
907 #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \
908     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f)))
909 
910 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
911     VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0)
912 
913 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)                        \
914     VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
915 
916 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)                        \
917     VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
918 
919 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)                    \
920     VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
921 
922 #define VMSTATE_BUFFER_TEST(_f, _s, _test)                            \
923     VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
924 
925 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)        \
926     VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
927 
928 #define VMSTATE_UNUSED_V(_v, _size)                                   \
929     VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
930 
931 #define VMSTATE_UNUSED(_size)                                         \
932     VMSTATE_UNUSED_V(0, _size)
933 
934 #define VMSTATE_UNUSED_TEST(_test, _size)                             \
935     VMSTATE_UNUSED_BUFFER(_test, 0, _size)
936 
937 #define VMSTATE_END_OF_LIST()                                         \
938     {}
939 
940 #define SELF_ANNOUNCE_ROUNDS 5
941 
942 void loadvm_free_handlers(MigrationIncomingState *mis);
943 
944 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
945                        void *opaque, int version_id);
946 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
947                         void *opaque, QJSON *vmdesc);
948 
949 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
950 
951 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
952                                    const VMStateDescription *vmsd,
953                                    void *base, int alias_id,
954                                    int required_for_version);
955 
956 static inline int vmstate_register(DeviceState *dev, int instance_id,
957                                    const VMStateDescription *vmsd,
958                                    void *opaque)
959 {
960     return vmstate_register_with_alias_id(dev, instance_id, vmsd,
961                                           opaque, -1, 0);
962 }
963 
964 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
965                         void *opaque);
966 
967 struct MemoryRegion;
968 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
969 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
970 void vmstate_register_ram_global(struct MemoryRegion *memory);
971 
972 static inline
973 int64_t self_announce_delay(int round)
974 {
975     assert(round < SELF_ANNOUNCE_ROUNDS && round > 0);
976     /* delay 50ms, 150ms, 250ms, ... */
977     return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100;
978 }
979 
980 void dump_vmstate_json_to_file(FILE *out_fp);
981 
982 #endif
983