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