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