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