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