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