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