xref: /qemu/include/migration/vmstate.h (revision 081c09dc52bab0facfdd1d34fd466479af6ac531)
1701a8f76SPaolo Bonzini /*
2701a8f76SPaolo Bonzini  * QEMU migration/snapshot declarations
3701a8f76SPaolo Bonzini  *
4701a8f76SPaolo Bonzini  * Copyright (c) 2009-2011 Red Hat, Inc.
5701a8f76SPaolo Bonzini  *
6701a8f76SPaolo Bonzini  * Original author: Juan Quintela <quintela@redhat.com>
7701a8f76SPaolo Bonzini  *
8701a8f76SPaolo Bonzini  * Permission is hereby granted, free of charge, to any person obtaining a copy
9701a8f76SPaolo Bonzini  * of this software and associated documentation files (the "Software"), to deal
10701a8f76SPaolo Bonzini  * in the Software without restriction, including without limitation the rights
11701a8f76SPaolo Bonzini  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12701a8f76SPaolo Bonzini  * copies of the Software, and to permit persons to whom the Software is
13701a8f76SPaolo Bonzini  * furnished to do so, subject to the following conditions:
14701a8f76SPaolo Bonzini  *
15701a8f76SPaolo Bonzini  * The above copyright notice and this permission notice shall be included in
16701a8f76SPaolo Bonzini  * all copies or substantial portions of the Software.
17701a8f76SPaolo Bonzini  *
18701a8f76SPaolo Bonzini  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19701a8f76SPaolo Bonzini  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20701a8f76SPaolo Bonzini  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21701a8f76SPaolo Bonzini  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22701a8f76SPaolo Bonzini  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23701a8f76SPaolo Bonzini  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24701a8f76SPaolo Bonzini  * THE SOFTWARE.
25701a8f76SPaolo Bonzini  */
26175de524SMarkus Armbruster 
27701a8f76SPaolo Bonzini #ifndef QEMU_VMSTATE_H
28175de524SMarkus Armbruster #define QEMU_VMSTATE_H
29701a8f76SPaolo Bonzini 
30107b5969SMarc-André Lureau #include "hw/vmstate-if.h"
31107b5969SMarc-André Lureau 
32701a8f76SPaolo Bonzini typedef struct VMStateInfo VMStateInfo;
332c21ee76SJianjun Duan typedef struct VMStateField VMStateField;
34701a8f76SPaolo Bonzini 
352c21ee76SJianjun Duan /* VMStateInfo allows customized migration of objects that don't fit in
362c21ee76SJianjun Duan  * any category in VMStateFlags. Additional information is always passed
372c21ee76SJianjun Duan  * into get and put in terms of field and vmdesc parameters. However
382c21ee76SJianjun Duan  * these two parameters should only be used in cases when customized
392c21ee76SJianjun Duan  * handling is needed, such as QTAILQ. For primitive data types such as
402c21ee76SJianjun Duan  * integer, field and vmdesc parameters should be ignored inside get/put.
412c21ee76SJianjun Duan  */
42701a8f76SPaolo Bonzini struct VMStateInfo {
43701a8f76SPaolo Bonzini     const char *name;
448686a689SKevin Wolf     int coroutine_mixed_fn (*get)(QEMUFile *f, void *pv, size_t size,
458686a689SKevin Wolf                                   const VMStateField *field);
468686a689SKevin Wolf     int coroutine_mixed_fn (*put)(QEMUFile *f, void *pv, size_t size,
478686a689SKevin Wolf                                   const VMStateField *field,
483ddba9a9SMarkus Armbruster                                   JSONWriter *vmdesc);
49701a8f76SPaolo Bonzini };
50701a8f76SPaolo Bonzini 
51701a8f76SPaolo Bonzini enum VMStateFlags {
528da5ef57SSascha Silbe     /* Ignored */
53701a8f76SPaolo Bonzini     VMS_SINGLE           = 0x001,
548da5ef57SSascha Silbe 
558da5ef57SSascha Silbe     /* The struct member at opaque + VMStateField.offset is a pointer
568da5ef57SSascha Silbe      * to the actual field (e.g. struct a { uint8_t *b;
578da5ef57SSascha Silbe      * }). Dereference the pointer before using it as basis for
588da5ef57SSascha Silbe      * further pointer arithmetic (see e.g. VMS_ARRAY). Does not
598da5ef57SSascha Silbe      * affect the meaning of VMStateField.num_offset or
608da5ef57SSascha Silbe      * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for
618da5ef57SSascha Silbe      * those. */
62701a8f76SPaolo Bonzini     VMS_POINTER          = 0x002,
638da5ef57SSascha Silbe 
648da5ef57SSascha Silbe     /* The field is an array of fixed size. VMStateField.num contains
658da5ef57SSascha Silbe      * the number of entries in the array. The size of each entry is
668da5ef57SSascha Silbe      * given by VMStateField.size and / or opaque +
678da5ef57SSascha Silbe      * VMStateField.size_offset; see VMS_VBUFFER and
688da5ef57SSascha Silbe      * VMS_MULTIPLY. Each array entry will be processed individually
698da5ef57SSascha Silbe      * (VMStateField.info.get()/put() if VMS_STRUCT is not set,
708da5ef57SSascha Silbe      * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not
718da5ef57SSascha Silbe      * be combined with VMS_VARRAY*. */
72701a8f76SPaolo Bonzini     VMS_ARRAY            = 0x004,
738da5ef57SSascha Silbe 
748da5ef57SSascha Silbe     /* The field is itself a struct, containing one or more
758da5ef57SSascha Silbe      * fields. Recurse into VMStateField.vmsd. Most useful in
768da5ef57SSascha Silbe      * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each
778da5ef57SSascha Silbe      * array entry. */
78701a8f76SPaolo Bonzini     VMS_STRUCT           = 0x008,
798da5ef57SSascha Silbe 
808da5ef57SSascha Silbe     /* The field is an array of variable size. The int32_t at opaque +
818da5ef57SSascha Silbe      * VMStateField.num_offset contains the number of entries in the
828da5ef57SSascha Silbe      * array. See the VMS_ARRAY description regarding array handling
838da5ef57SSascha Silbe      * in general. May not be combined with VMS_ARRAY or any other
848da5ef57SSascha Silbe      * VMS_VARRAY*. */
858da5ef57SSascha Silbe     VMS_VARRAY_INT32     = 0x010,
868da5ef57SSascha Silbe 
878da5ef57SSascha Silbe     /* Ignored */
888da5ef57SSascha Silbe     VMS_BUFFER           = 0x020,
898da5ef57SSascha Silbe 
908da5ef57SSascha Silbe     /* The field is a (fixed-size or variable-size) array of pointers
918da5ef57SSascha Silbe      * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry
928da5ef57SSascha Silbe      * before using it. Note: Does not imply any one of VMS_ARRAY /
938da5ef57SSascha Silbe      * VMS_VARRAY*; these need to be set explicitly. */
94701a8f76SPaolo Bonzini     VMS_ARRAY_OF_POINTER = 0x040,
958da5ef57SSascha Silbe 
968da5ef57SSascha Silbe     /* The field is an array of variable size. The uint16_t at opaque
978da5ef57SSascha Silbe      * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
988da5ef57SSascha Silbe      * contains the number of entries in the array. See the VMS_ARRAY
998da5ef57SSascha Silbe      * description regarding array handling in general. May not be
1008da5ef57SSascha Silbe      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
1018da5ef57SSascha Silbe     VMS_VARRAY_UINT16    = 0x080,
1028da5ef57SSascha Silbe 
1038da5ef57SSascha Silbe     /* The size of the individual entries (a single array entry if
1048da5ef57SSascha Silbe      * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if
1058da5ef57SSascha Silbe      * neither is set) is variable (i.e. not known at compile-time),
1068da5ef57SSascha Silbe      * but the same for all entries. Use the int32_t at opaque +
1078da5ef57SSascha Silbe      * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine
1088da5ef57SSascha Silbe      * the size of each (and every) entry. */
1098da5ef57SSascha Silbe     VMS_VBUFFER          = 0x100,
1108da5ef57SSascha Silbe 
1118da5ef57SSascha Silbe     /* Multiply the entry size given by the int32_t at opaque +
1128da5ef57SSascha Silbe      * VMStateField.size_offset (see VMS_VBUFFER description) with
1138da5ef57SSascha Silbe      * VMStateField.size to determine the number of bytes to be
1148da5ef57SSascha Silbe      * allocated. Only valid in combination with VMS_VBUFFER. */
1158da5ef57SSascha Silbe     VMS_MULTIPLY         = 0x200,
1168da5ef57SSascha Silbe 
1178da5ef57SSascha Silbe     /* The field is an array of variable size. The uint8_t at opaque +
1188da5ef57SSascha Silbe      * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
1198da5ef57SSascha Silbe      * contains the number of entries in the array. See the VMS_ARRAY
1208da5ef57SSascha Silbe      * description regarding array handling in general. May not be
1218da5ef57SSascha Silbe      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
1228da5ef57SSascha Silbe     VMS_VARRAY_UINT8     = 0x400,
1238da5ef57SSascha Silbe 
1248da5ef57SSascha Silbe     /* The field is an array of variable size. The uint32_t at opaque
1258da5ef57SSascha Silbe      * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
1268da5ef57SSascha Silbe      * contains the number of entries in the array. See the VMS_ARRAY
1278da5ef57SSascha Silbe      * description regarding array handling in general. May not be
1288da5ef57SSascha Silbe      * combined with VMS_ARRAY or any other VMS_VARRAY*. */
1298da5ef57SSascha Silbe     VMS_VARRAY_UINT32    = 0x800,
1308da5ef57SSascha Silbe 
1318da5ef57SSascha Silbe     /* Fail loading the serialised VM state if this field is missing
1328da5ef57SSascha Silbe      * from the input. */
1338da5ef57SSascha Silbe     VMS_MUST_EXIST       = 0x1000,
1348da5ef57SSascha Silbe 
1358da5ef57SSascha Silbe     /* When loading serialised VM state, allocate memory for the
1368da5ef57SSascha Silbe      * (entire) field. Only valid in combination with
1378da5ef57SSascha Silbe      * VMS_POINTER. Note: Not all combinations with other flags are
1388da5ef57SSascha Silbe      * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't
1398da5ef57SSascha Silbe      * cause the individual entries to be allocated. */
1408da5ef57SSascha Silbe     VMS_ALLOC            = 0x2000,
1418da5ef57SSascha Silbe 
1428da5ef57SSascha Silbe     /* Multiply the number of entries given by the integer at opaque +
1438da5ef57SSascha Silbe      * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num
1448da5ef57SSascha Silbe      * to determine the number of entries in the array. Only valid in
1458da5ef57SSascha Silbe      * combination with one of VMS_VARRAY*. */
1468da5ef57SSascha Silbe     VMS_MULTIPLY_ELEMENTS = 0x4000,
1472dc6660bSCorey Minyard 
1482dc6660bSCorey Minyard     /* A structure field that is like VMS_STRUCT, but uses
1492dc6660bSCorey Minyard      * VMStateField.struct_version_id to tell which version of the
1502dc6660bSCorey Minyard      * structure we are referencing to use. */
1512dc6660bSCorey Minyard     VMS_VSTRUCT           = 0x8000,
15289c56848SDr. David Alan Gilbert 
15389c56848SDr. David Alan Gilbert     /* Marker for end of list */
15489c56848SDr. David Alan Gilbert     VMS_END = 0x10000
155701a8f76SPaolo Bonzini };
156701a8f76SPaolo Bonzini 
157f37bc036SPeter Xu typedef enum {
158*081c09dcSSteve Sistare     MIG_PRI_UNINITIALIZED = 0,  /* An uninitialized priority field maps to */
159*081c09dcSSteve Sistare                                 /* MIG_PRI_DEFAULT in save_state_priority */
160*081c09dcSSteve Sistare 
161*081c09dcSSteve Sistare     MIG_PRI_LOW,                /* Must happen after default */
162*081c09dcSSteve Sistare     MIG_PRI_DEFAULT,
1638cdcf3c1SPeter Xu     MIG_PRI_IOMMU,              /* Must happen before PCI devices */
1649d6b9db1SPeter Xu     MIG_PRI_PCI_BUS,            /* Must happen before IOMMU */
1650fd7616eSDavid Hildenbrand     MIG_PRI_VIRTIO_MEM,         /* Must happen before IOMMU */
166252a7a6aSEric Auger     MIG_PRI_GICV3_ITS,          /* Must happen before PCI devices */
167252a7a6aSEric Auger     MIG_PRI_GICV3,              /* Must happen before the ITS */
168f37bc036SPeter Xu     MIG_PRI_MAX,
169f37bc036SPeter Xu } MigrationPriority;
170f37bc036SPeter Xu 
1712c21ee76SJianjun Duan struct VMStateField {
172701a8f76SPaolo Bonzini     const char *name;
173d2164ad3SHalil Pasic     const char *err_hint;
174701a8f76SPaolo Bonzini     size_t offset;
175701a8f76SPaolo Bonzini     size_t size;
176701a8f76SPaolo Bonzini     size_t start;
177701a8f76SPaolo Bonzini     int num;
178701a8f76SPaolo Bonzini     size_t num_offset;
179701a8f76SPaolo Bonzini     size_t size_offset;
180701a8f76SPaolo Bonzini     const VMStateInfo *info;
181701a8f76SPaolo Bonzini     enum VMStateFlags flags;
182701a8f76SPaolo Bonzini     const VMStateDescription *vmsd;
183701a8f76SPaolo Bonzini     int version_id;
1842dc6660bSCorey Minyard     int struct_version_id;
185701a8f76SPaolo Bonzini     bool (*field_exists)(void *opaque, int version_id);
1862c21ee76SJianjun Duan };
187701a8f76SPaolo Bonzini 
188701a8f76SPaolo Bonzini struct VMStateDescription {
189701a8f76SPaolo Bonzini     const char *name;
19062f42625SDavid Hildenbrand     bool unmigratable;
19162f42625SDavid Hildenbrand     /*
19262f42625SDavid Hildenbrand      * This VMSD describes something that should be sent during setup phase
19362f42625SDavid Hildenbrand      * of migration. It plays similar role as save_setup() for explicitly
19462f42625SDavid Hildenbrand      * registered vmstate entries, so it can be seen as a way to describe
19562f42625SDavid Hildenbrand      * save_setup() in VMSD structures.
19662f42625SDavid Hildenbrand      *
19762f42625SDavid Hildenbrand      * Note that for now, a SaveStateEntry cannot have a VMSD and
19862f42625SDavid Hildenbrand      * operations (e.g., save_setup()) set at the same time. Consequently,
19962f42625SDavid Hildenbrand      * save_setup() and a VMSD with early_setup set to true are mutually
20062f42625SDavid Hildenbrand      * exclusive. For this reason, also early_setup VMSDs are migrated in a
20162f42625SDavid Hildenbrand      * QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in
20262f42625SDavid Hildenbrand      * a QEMU_VM_SECTION_START section.
20362f42625SDavid Hildenbrand      */
20462f42625SDavid Hildenbrand     bool early_setup;
205701a8f76SPaolo Bonzini     int version_id;
206701a8f76SPaolo Bonzini     int minimum_version_id;
207f37bc036SPeter Xu     MigrationPriority priority;
208701a8f76SPaolo Bonzini     int (*pre_load)(void *opaque);
209701a8f76SPaolo Bonzini     int (*post_load)(void *opaque, int version_id);
21044b1ff31SDr. David Alan Gilbert     int (*pre_save)(void *opaque);
2118c07559fSAaron Lindsay     int (*post_save)(void *opaque);
2125cd8cadaSJuan Quintela     bool (*needed)(void *opaque);
213c7e0acd5SJens Freimann     bool (*dev_unplug_pending)(void *opaque);
214c7e0acd5SJens Freimann 
21503fee66fSMarc-André Lureau     const VMStateField *fields;
21620270019SRichard Henderson     const VMStateDescription * const *subsections;
217701a8f76SPaolo Bonzini };
218701a8f76SPaolo Bonzini 
219701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_bool;
220701a8f76SPaolo Bonzini 
221701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_int8;
222701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_int16;
223701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_int32;
224701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_int64;
225701a8f76SPaolo Bonzini 
226701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint8_equal;
227701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint16_equal;
228701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_int32_equal;
229701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint32_equal;
230e344b8a1SDavid Gibson extern const VMStateInfo vmstate_info_uint64_equal;
231701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_int32_le;
232701a8f76SPaolo Bonzini 
233701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint8;
234701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint16;
235701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint32;
236701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_uint64;
237e3965dc3SSteve Sistare extern const VMStateInfo vmstate_info_fd;
238701a8f76SPaolo Bonzini 
23907d4e691SHalil Pasic /** Put this in the stream when migrating a null pointer.*/
24007d4e691SHalil Pasic #define VMS_NULLPTR_MARKER (0x30U) /* '0' */
24107d4e691SHalil Pasic extern const VMStateInfo vmstate_info_nullptr;
24207d4e691SHalil Pasic 
24355174749SJuan Quintela extern const VMStateInfo vmstate_info_cpudouble;
244213945e4SDavid Gibson 
245701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_timer;
246701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_buffer;
247701a8f76SPaolo Bonzini extern const VMStateInfo vmstate_info_unused_buffer;
248bcf45131SDr. David Alan Gilbert extern const VMStateInfo vmstate_info_tmp;
24908e99e29SPeter Maydell extern const VMStateInfo vmstate_info_bitmap;
25094869d5cSJianjun Duan extern const VMStateInfo vmstate_info_qtailq;
2519a85e4b8SEric Auger extern const VMStateInfo vmstate_info_gtree;
2524746dbf8SEric Auger extern const VMStateInfo vmstate_info_qlist;
253701a8f76SPaolo Bonzini 
254bd7f92e5SPeter Maydell #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
2550c413ba0SPeter Maydell /*
2560c413ba0SPeter Maydell  * Check that type t2 is an array of type t1 of size n,
2570c413ba0SPeter Maydell  * e.g. if t1 is 'foo' and n is 32 then t2 must be 'foo[32]'
2580c413ba0SPeter Maydell  */
259701a8f76SPaolo Bonzini #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
260701a8f76SPaolo Bonzini #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
2610c413ba0SPeter Maydell /*
2620c413ba0SPeter Maydell  * type of element 0 of the specified (array) field of the type.
2630c413ba0SPeter Maydell  * Note that if the field is a pointer then this will return the
2640c413ba0SPeter Maydell  * pointed-to type rather than complaining.
2650c413ba0SPeter Maydell  */
2660c413ba0SPeter Maydell #define typeof_elt_of_field(type, field) typeof(((type *)0)->field[0])
2670c413ba0SPeter Maydell /* Check that field f in struct type t2 is an array of t1, of any size */
2680c413ba0SPeter Maydell #define type_check_varray(t1, t2, f)                                 \
2690c413ba0SPeter Maydell     (type_check(t1, typeof_elt_of_field(t2, f))                      \
2700c413ba0SPeter Maydell      + QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(((t2 *)0)->f)))
271701a8f76SPaolo Bonzini 
272701a8f76SPaolo Bonzini #define vmstate_offset_value(_state, _field, _type)                  \
273701a8f76SPaolo Bonzini     (offsetof(_state, _field) +                                      \
274701a8f76SPaolo Bonzini      type_check(_type, typeof_field(_state, _field)))
275701a8f76SPaolo Bonzini 
276701a8f76SPaolo Bonzini #define vmstate_offset_pointer(_state, _field, _type)                \
277701a8f76SPaolo Bonzini     (offsetof(_state, _field) +                                      \
278701a8f76SPaolo Bonzini      type_check_pointer(_type, typeof_field(_state, _field)))
279701a8f76SPaolo Bonzini 
280701a8f76SPaolo Bonzini #define vmstate_offset_array(_state, _field, _type, _num)            \
281701a8f76SPaolo Bonzini     (offsetof(_state, _field) +                                      \
282701a8f76SPaolo Bonzini      type_check_array(_type, typeof_field(_state, _field), _num))
283701a8f76SPaolo Bonzini 
284bd7f92e5SPeter Maydell #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
285bd7f92e5SPeter Maydell     (offsetof(_state, _field) +                                      \
286bd7f92e5SPeter Maydell      type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
287bd7f92e5SPeter Maydell 
288701a8f76SPaolo Bonzini #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
289ea987c2cSPaolo Bonzini     vmstate_offset_value(_state, _field[_start], _type)
290701a8f76SPaolo Bonzini 
291701a8f76SPaolo Bonzini #define vmstate_offset_buffer(_state, _field)                        \
292701a8f76SPaolo Bonzini     vmstate_offset_array(_state, _field, uint8_t,                    \
293701a8f76SPaolo Bonzini                          sizeof(typeof_field(_state, _field)))
294701a8f76SPaolo Bonzini 
2950c413ba0SPeter Maydell #define vmstate_offset_varray(_state, _field, _type)                 \
2960c413ba0SPeter Maydell     (offsetof(_state, _field) +                                      \
2970c413ba0SPeter Maydell      type_check_varray(_type, _state, _field))
2980c413ba0SPeter Maydell 
2992dc6660bSCorey Minyard /* In the macros below, if there is a _version, that means the macro's
3002dc6660bSCorey Minyard  * field will be processed only if the version being received is >=
3012dc6660bSCorey Minyard  * the _version specified.  In general, if you add a new field, you
3022dc6660bSCorey Minyard  * would increment the structure's version and put that version
3032dc6660bSCorey Minyard  * number into the new field so it would only be processed with the
3042dc6660bSCorey Minyard  * new version.
3052dc6660bSCorey Minyard  *
3062dc6660bSCorey Minyard  * In particular, for VMSTATE_STRUCT() and friends the _version does
3072dc6660bSCorey Minyard  * *NOT* pick the version of the sub-structure.  It works just as
3082dc6660bSCorey Minyard  * specified above.  The version of the top-level structure received
3092dc6660bSCorey Minyard  * is passed down to all sub-structures.  This means that the
3102dc6660bSCorey Minyard  * sub-structures must have version that are compatible with all the
3112dc6660bSCorey Minyard  * structures that use them.
3122dc6660bSCorey Minyard  *
3132dc6660bSCorey Minyard  * If you want to specify the version of the sub-structure, use
3142dc6660bSCorey Minyard  * VMSTATE_VSTRUCT(), which allows the specific sub-structure version
3152dc6660bSCorey Minyard  * to be directly specified.
3162dc6660bSCorey Minyard  */
3172dc6660bSCorey Minyard 
318701a8f76SPaolo Bonzini #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
319701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
320701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
321701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
322701a8f76SPaolo Bonzini     .size         = sizeof(_type),                                   \
323701a8f76SPaolo Bonzini     .info         = &(_info),                                        \
324701a8f76SPaolo Bonzini     .flags        = VMS_SINGLE,                                      \
325701a8f76SPaolo Bonzini     .offset       = vmstate_offset_value(_state, _field, _type),     \
326701a8f76SPaolo Bonzini }
327701a8f76SPaolo Bonzini 
328d2164ad3SHalil Pasic #define VMSTATE_SINGLE_FULL(_field, _state, _test, _version, _info,  \
329d2164ad3SHalil Pasic                             _type, _err_hint) {                      \
330d2164ad3SHalil Pasic     .name         = (stringify(_field)),                             \
331d2164ad3SHalil Pasic     .err_hint     = (_err_hint),                                     \
332d2164ad3SHalil Pasic     .version_id   = (_version),                                      \
333d2164ad3SHalil Pasic     .field_exists = (_test),                                         \
334d2164ad3SHalil Pasic     .size         = sizeof(_type),                                   \
335d2164ad3SHalil Pasic     .info         = &(_info),                                        \
336d2164ad3SHalil Pasic     .flags        = VMS_SINGLE,                                      \
337d2164ad3SHalil Pasic     .offset       = vmstate_offset_value(_state, _field, _type),     \
338d2164ad3SHalil Pasic }
339d2164ad3SHalil Pasic 
3404082f088SMichael S. Tsirkin /* Validate state using a boolean predicate. */
3414082f088SMichael S. Tsirkin #define VMSTATE_VALIDATE(_name, _test) { \
3424082f088SMichael S. Tsirkin     .name         = (_name),                                         \
3434082f088SMichael S. Tsirkin     .field_exists = (_test),                                         \
3444082f088SMichael S. Tsirkin     .flags        = VMS_ARRAY | VMS_MUST_EXIST,                      \
3454082f088SMichael S. Tsirkin     .num          = 0, /* 0 elements: no data, only run _test */     \
3464082f088SMichael S. Tsirkin }
3474082f088SMichael S. Tsirkin 
348701a8f76SPaolo Bonzini #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
349701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
350701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
351701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
352701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
353701a8f76SPaolo Bonzini     .flags      = VMS_SINGLE|VMS_POINTER,                            \
354701a8f76SPaolo Bonzini     .offset     = vmstate_offset_value(_state, _field, _type),       \
355701a8f76SPaolo Bonzini }
356701a8f76SPaolo Bonzini 
357701a8f76SPaolo Bonzini #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) {  \
358701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
359701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
360701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
361701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
362701a8f76SPaolo Bonzini     .flags      = VMS_SINGLE|VMS_POINTER,                            \
363701a8f76SPaolo Bonzini     .offset     = vmstate_offset_value(_state, _field, _type),       \
364701a8f76SPaolo Bonzini }
365701a8f76SPaolo Bonzini 
366701a8f76SPaolo Bonzini #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
367701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
368701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
369701a8f76SPaolo Bonzini     .num        = (_num),                                            \
370701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
371701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
372701a8f76SPaolo Bonzini     .flags      = VMS_ARRAY,                                         \
373701a8f76SPaolo Bonzini     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
374701a8f76SPaolo Bonzini }
375701a8f76SPaolo Bonzini 
376bd7f92e5SPeter Maydell #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
377bd7f92e5SPeter Maydell     .name       = (stringify(_field)),                                      \
378bd7f92e5SPeter Maydell     .version_id = (_version),                                               \
379bd7f92e5SPeter Maydell     .num        = (_n1) * (_n2),                                            \
380bd7f92e5SPeter Maydell     .info       = &(_info),                                                 \
381bd7f92e5SPeter Maydell     .size       = sizeof(_type),                                            \
382bd7f92e5SPeter Maydell     .flags      = VMS_ARRAY,                                                \
383bd7f92e5SPeter Maydell     .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
384bd7f92e5SPeter Maydell }
385bd7f92e5SPeter Maydell 
386b47d3af7SJuan Quintela #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
387b47d3af7SJuan Quintela     .name       = (stringify(_field)),                               \
388b47d3af7SJuan Quintela     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
389b47d3af7SJuan Quintela     .num        = (_multiply),                                       \
390b47d3af7SJuan Quintela     .info       = &(_info),                                          \
391b47d3af7SJuan Quintela     .size       = sizeof(_type),                                     \
392b47d3af7SJuan Quintela     .flags      = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS,           \
3930c413ba0SPeter Maydell     .offset     = vmstate_offset_varray(_state, _field, _type),      \
394b47d3af7SJuan Quintela }
395b47d3af7SJuan Quintela 
396701a8f76SPaolo Bonzini #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
397701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
398701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
399701a8f76SPaolo Bonzini     .num        = (_num),                                            \
400701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
401701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
402701a8f76SPaolo Bonzini     .flags      = VMS_ARRAY,                                         \
403701a8f76SPaolo Bonzini     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
404701a8f76SPaolo Bonzini }
405701a8f76SPaolo Bonzini 
406701a8f76SPaolo Bonzini #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
407701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
408701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
409701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
410701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
411701a8f76SPaolo Bonzini     .flags      = VMS_VARRAY_INT32,                                  \
4120c413ba0SPeter Maydell     .offset     = vmstate_offset_varray(_state, _field, _type),      \
413701a8f76SPaolo Bonzini }
414701a8f76SPaolo Bonzini 
415701a8f76SPaolo Bonzini #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
416701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
417701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
418701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
419701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
420701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
421701a8f76SPaolo Bonzini     .flags      = VMS_VARRAY_INT32|VMS_POINTER,                      \
422701a8f76SPaolo Bonzini     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
423701a8f76SPaolo Bonzini }
424701a8f76SPaolo Bonzini 
425701a8f76SPaolo Bonzini #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
426701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
427701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
428701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
429701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
430701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
431701a8f76SPaolo Bonzini     .flags      = VMS_VARRAY_UINT32|VMS_POINTER,                     \
432701a8f76SPaolo Bonzini     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
433701a8f76SPaolo Bonzini }
434701a8f76SPaolo Bonzini 
435705124eaSAlexey Kardashevskiy #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
436705124eaSAlexey Kardashevskiy     .name       = (stringify(_field)),                               \
437705124eaSAlexey Kardashevskiy     .version_id = (_version),                                        \
438705124eaSAlexey Kardashevskiy     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
439705124eaSAlexey Kardashevskiy     .info       = &(_info),                                          \
440705124eaSAlexey Kardashevskiy     .size       = sizeof(_type),                                     \
441705124eaSAlexey Kardashevskiy     .flags      = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC,           \
442705124eaSAlexey Kardashevskiy     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
443705124eaSAlexey Kardashevskiy }
444705124eaSAlexey Kardashevskiy 
445ff4e6d54SYuri Benditovich #define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
446ff4e6d54SYuri Benditovich     .name       = (stringify(_field)),                               \
447ff4e6d54SYuri Benditovich     .version_id = (_version),                                        \
448ff4e6d54SYuri Benditovich     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
449ff4e6d54SYuri Benditovich     .info       = &(_info),                                          \
450ff4e6d54SYuri Benditovich     .size       = sizeof(_type),                                     \
451ff4e6d54SYuri Benditovich     .flags      = VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC,       \
452ff4e6d54SYuri Benditovich     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
453ff4e6d54SYuri Benditovich }
454ff4e6d54SYuri Benditovich 
455701a8f76SPaolo Bonzini #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
456701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
457701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
458701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
459701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
460701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
461701a8f76SPaolo Bonzini     .flags      = VMS_VARRAY_UINT16,                                 \
4620c413ba0SPeter Maydell     .offset     = vmstate_offset_varray(_state, _field, _type),      \
463701a8f76SPaolo Bonzini }
464701a8f76SPaolo Bonzini 
4652dc6660bSCorey Minyard #define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \
4662dc6660bSCorey Minyard     .name         = (stringify(_field)),                             \
4672dc6660bSCorey Minyard     .version_id   = (_version),                                      \
4682dc6660bSCorey Minyard     .struct_version_id = (_struct_version),                          \
4692dc6660bSCorey Minyard     .field_exists = (_test),                                         \
4702dc6660bSCorey Minyard     .vmsd         = &(_vmsd),                                        \
4712dc6660bSCorey Minyard     .size         = sizeof(_type),                                   \
4722dc6660bSCorey Minyard     .flags        = VMS_VSTRUCT,                                     \
4732dc6660bSCorey Minyard     .offset       = vmstate_offset_value(_state, _field, _type),     \
4742dc6660bSCorey Minyard }
4752dc6660bSCorey Minyard 
476701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
477701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
478701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
479701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
480701a8f76SPaolo Bonzini     .vmsd         = &(_vmsd),                                        \
481701a8f76SPaolo Bonzini     .size         = sizeof(_type),                                   \
482701a8f76SPaolo Bonzini     .flags        = VMS_STRUCT,                                      \
483701a8f76SPaolo Bonzini     .offset       = vmstate_offset_value(_state, _field, _type),     \
484701a8f76SPaolo Bonzini }
485701a8f76SPaolo Bonzini 
4867102400dSAlexey Kardashevskiy #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
487701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
4887102400dSAlexey Kardashevskiy     .version_id   = (_version),                                        \
4897102400dSAlexey Kardashevskiy     .vmsd         = &(_vmsd),                                        \
49020bcf73fSPeter Maydell     .size         = sizeof(_type *),                                 \
4917102400dSAlexey Kardashevskiy     .flags        = VMS_STRUCT|VMS_POINTER,                          \
49220bcf73fSPeter Maydell     .offset       = vmstate_offset_pointer(_state, _field, _type),   \
4937102400dSAlexey Kardashevskiy }
4947102400dSAlexey Kardashevskiy 
4957102400dSAlexey Kardashevskiy #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
4967102400dSAlexey Kardashevskiy     .name         = (stringify(_field)),                             \
4977102400dSAlexey Kardashevskiy     .version_id   = (_version),                                        \
498701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
499701a8f76SPaolo Bonzini     .vmsd         = &(_vmsd),                                        \
50020bcf73fSPeter Maydell     .size         = sizeof(_type *),                                 \
501701a8f76SPaolo Bonzini     .flags        = VMS_STRUCT|VMS_POINTER,                          \
50220bcf73fSPeter Maydell     .offset       = vmstate_offset_pointer(_state, _field, _type),   \
503701a8f76SPaolo Bonzini }
504701a8f76SPaolo Bonzini 
505701a8f76SPaolo Bonzini #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
506701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
507701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
508701a8f76SPaolo Bonzini     .num        = (_num),                                            \
509701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
510701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
511701a8f76SPaolo Bonzini     .flags      = VMS_ARRAY|VMS_ARRAY_OF_POINTER,                    \
512701a8f76SPaolo Bonzini     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
513701a8f76SPaolo Bonzini }
514701a8f76SPaolo Bonzini 
515a1f05e79SPeter Maydell #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
516a1f05e79SPeter Maydell     .name       = (stringify(_f)),                                   \
517a1f05e79SPeter Maydell     .version_id = (_v),                                              \
518a1f05e79SPeter Maydell     .num        = (_n),                                              \
519a1f05e79SPeter Maydell     .vmsd       = &(_vmsd),                                          \
520a1f05e79SPeter Maydell     .size       = sizeof(_type *),                                    \
521a1f05e79SPeter Maydell     .flags      = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER,         \
522a1f05e79SPeter Maydell     .offset     = vmstate_offset_array(_s, _f, _type*, _n),          \
523a1f05e79SPeter Maydell }
524a1f05e79SPeter Maydell 
525a03c3e90SPaolo Bonzini #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
526a03c3e90SPaolo Bonzini     .name       = (stringify(_field)),                                     \
527a03c3e90SPaolo Bonzini     .version_id = (_version),                                              \
528a03c3e90SPaolo Bonzini     .num        = (_num),                                                  \
529a03c3e90SPaolo Bonzini     .vmsd       = &(_vmsd),                                                \
530a03c3e90SPaolo Bonzini     .size       = sizeof(_type),                                           \
531a03c3e90SPaolo Bonzini     .flags      = VMS_STRUCT|VMS_ARRAY,                                    \
532a03c3e90SPaolo Bonzini     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
533a03c3e90SPaolo Bonzini }
534a03c3e90SPaolo Bonzini 
535701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
536701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
537701a8f76SPaolo Bonzini     .num          = (_num),                                          \
538701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
539701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
540701a8f76SPaolo Bonzini     .vmsd         = &(_vmsd),                                        \
541701a8f76SPaolo Bonzini     .size         = sizeof(_type),                                   \
542701a8f76SPaolo Bonzini     .flags        = VMS_STRUCT|VMS_ARRAY,                            \
543701a8f76SPaolo Bonzini     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
544701a8f76SPaolo Bonzini }
545701a8f76SPaolo Bonzini 
546b75c958dSStafford Horne #define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \
547b75c958dSStafford Horne                                     _version, _vmsd, _type) {        \
548b75c958dSStafford Horne     .name         = (stringify(_field)),                             \
549b75c958dSStafford Horne     .num          = (_n1) * (_n2),                                   \
550b75c958dSStafford Horne     .field_exists = (_test),                                         \
551b75c958dSStafford Horne     .version_id   = (_version),                                      \
552b75c958dSStafford Horne     .vmsd         = &(_vmsd),                                        \
553b75c958dSStafford Horne     .size         = sizeof(_type),                                   \
554b75c958dSStafford Horne     .flags        = VMS_STRUCT | VMS_ARRAY,                          \
555b75c958dSStafford Horne     .offset       = vmstate_offset_2darray(_state, _field, _type,    \
556b75c958dSStafford Horne                                            _n1, _n2),                \
557b75c958dSStafford Horne }
558b75c958dSStafford Horne 
559701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
560701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
561701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
562701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
563701a8f76SPaolo Bonzini     .vmsd       = &(_vmsd),                                          \
564701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
565701a8f76SPaolo Bonzini     .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
5660c413ba0SPeter Maydell     .offset     = vmstate_offset_varray(_state, _field, _type),      \
567701a8f76SPaolo Bonzini }
568701a8f76SPaolo Bonzini 
5693e996cc5SDr. David Alan Gilbert /* a variable length array (i.e. _type *_field) but we know the
5703e996cc5SDr. David Alan Gilbert  * length
5713e996cc5SDr. David Alan Gilbert  */
5723e996cc5SDr. David Alan Gilbert #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
5733e996cc5SDr. David Alan Gilbert     .name       = (stringify(_field)),                               \
5743e996cc5SDr. David Alan Gilbert     .num          = (_num),                                          \
5753e996cc5SDr. David Alan Gilbert     .version_id = (_version),                                        \
5763e996cc5SDr. David Alan Gilbert     .vmsd       = &(_vmsd),                                          \
5773e996cc5SDr. David Alan Gilbert     .size       = sizeof(_type),                                     \
5783e996cc5SDr. David Alan Gilbert     .flags      = VMS_STRUCT|VMS_ARRAY|VMS_POINTER,                  \
5793e996cc5SDr. David Alan Gilbert     .offset     = offsetof(_state, _field),                          \
5803e996cc5SDr. David Alan Gilbert }
5813e996cc5SDr. David Alan Gilbert 
582701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
583701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
584701a8f76SPaolo Bonzini     .version_id = 0,                                                 \
585701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
586701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
587701a8f76SPaolo Bonzini     .vmsd       = &(_vmsd),                                          \
588701a8f76SPaolo Bonzini     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
589701a8f76SPaolo Bonzini     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
590701a8f76SPaolo Bonzini }
591701a8f76SPaolo Bonzini 
5928474a9ddSDavid Gibson #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
5938474a9ddSDavid Gibson     .name       = (stringify(_field)),                               \
5948474a9ddSDavid Gibson     .version_id = 0,                                                 \
5958474a9ddSDavid Gibson     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
5968474a9ddSDavid Gibson     .size       = sizeof(_type),                                     \
5978474a9ddSDavid Gibson     .vmsd       = &(_vmsd),                                          \
5988474a9ddSDavid Gibson     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
5998474a9ddSDavid Gibson     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
6008474a9ddSDavid Gibson }
6018474a9ddSDavid Gibson 
602701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
603701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
604701a8f76SPaolo Bonzini     .version_id = 0,                                                 \
605701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
606701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
607701a8f76SPaolo Bonzini     .vmsd       = &(_vmsd),                                          \
608701a8f76SPaolo Bonzini     .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,      \
609701a8f76SPaolo Bonzini     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
610701a8f76SPaolo Bonzini }
611701a8f76SPaolo Bonzini 
612701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
613701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
614701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
615701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
616701a8f76SPaolo Bonzini     .vmsd       = &(_vmsd),                                          \
617701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
618701a8f76SPaolo Bonzini     .flags      = VMS_STRUCT|VMS_VARRAY_INT32,                       \
6190c413ba0SPeter Maydell     .offset     = vmstate_offset_varray(_state, _field, _type),      \
620701a8f76SPaolo Bonzini }
621701a8f76SPaolo Bonzini 
622701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
623701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
624701a8f76SPaolo Bonzini     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
625701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
626701a8f76SPaolo Bonzini     .vmsd       = &(_vmsd),                                          \
627701a8f76SPaolo Bonzini     .size       = sizeof(_type),                                     \
628701a8f76SPaolo Bonzini     .flags      = VMS_STRUCT|VMS_VARRAY_UINT32,                      \
6290c413ba0SPeter Maydell     .offset     = vmstate_offset_varray(_state, _field, _type),      \
630701a8f76SPaolo Bonzini }
631701a8f76SPaolo Bonzini 
632f32935eaSAlexey Kardashevskiy #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
633f32935eaSAlexey Kardashevskiy     .name       = (stringify(_field)),                               \
634f32935eaSAlexey Kardashevskiy     .version_id = (_version),                                        \
635f32935eaSAlexey Kardashevskiy     .vmsd       = &(_vmsd),                                          \
636f32935eaSAlexey Kardashevskiy     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
637f32935eaSAlexey Kardashevskiy     .size       = sizeof(_type),                                     \
638f32935eaSAlexey Kardashevskiy     .flags      = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
639f32935eaSAlexey Kardashevskiy     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
640f32935eaSAlexey Kardashevskiy }
641f32935eaSAlexey Kardashevskiy 
642701a8f76SPaolo Bonzini #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
643701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
644701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
645701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
646701a8f76SPaolo Bonzini     .size         = (_size - _start),                                \
647701a8f76SPaolo Bonzini     .info         = &vmstate_info_buffer,                            \
648701a8f76SPaolo Bonzini     .flags        = VMS_BUFFER,                                      \
649701a8f76SPaolo Bonzini     .offset       = vmstate_offset_buffer(_state, _field) + _start,  \
650701a8f76SPaolo Bonzini }
651701a8f76SPaolo Bonzini 
65259046ec2SHalil Pasic #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test,    \
65359046ec2SHalil Pasic                                  _field_size, _multiply) {           \
654701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
655701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
656701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
657701a8f76SPaolo Bonzini     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
658701a8f76SPaolo Bonzini     .size         = (_multiply),                                      \
659701a8f76SPaolo Bonzini     .info         = &vmstate_info_buffer,                            \
660377e2cb9SDavid Gibson     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY,            \
661701a8f76SPaolo Bonzini     .offset       = offsetof(_state, _field),                        \
662701a8f76SPaolo Bonzini }
663701a8f76SPaolo Bonzini 
66459046ec2SHalil Pasic #define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \
665701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
666701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
667701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
668701a8f76SPaolo Bonzini     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
669701a8f76SPaolo Bonzini     .info         = &vmstate_info_buffer,                            \
670701a8f76SPaolo Bonzini     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
671701a8f76SPaolo Bonzini     .offset       = offsetof(_state, _field),                        \
672701a8f76SPaolo Bonzini }
673701a8f76SPaolo Bonzini 
67459046ec2SHalil Pasic #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \
675701a8f76SPaolo Bonzini     .name         = (stringify(_field)),                             \
676701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
677701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
678701a8f76SPaolo Bonzini     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
679701a8f76SPaolo Bonzini     .info         = &vmstate_info_buffer,                            \
680701a8f76SPaolo Bonzini     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
681701a8f76SPaolo Bonzini     .offset       = offsetof(_state, _field),                        \
682701a8f76SPaolo Bonzini }
683701a8f76SPaolo Bonzini 
68459046ec2SHalil Pasic #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version,       \
68559046ec2SHalil Pasic                                      _test, _field_size) {           \
68694ed706dSAlexey Kardashevskiy     .name         = (stringify(_field)),                             \
68794ed706dSAlexey Kardashevskiy     .version_id   = (_version),                                      \
68894ed706dSAlexey Kardashevskiy     .field_exists = (_test),                                         \
68994ed706dSAlexey Kardashevskiy     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
69094ed706dSAlexey Kardashevskiy     .info         = &vmstate_info_buffer,                            \
69194ed706dSAlexey Kardashevskiy     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC,               \
69294ed706dSAlexey Kardashevskiy     .offset       = offsetof(_state, _field),                        \
69394ed706dSAlexey Kardashevskiy }
69494ed706dSAlexey Kardashevskiy 
6959df0b0e0SLaszlo Ersek #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
696701a8f76SPaolo Bonzini     .name       = (stringify(_field)),                               \
697701a8f76SPaolo Bonzini     .version_id = (_version),                                        \
6989df0b0e0SLaszlo Ersek     .field_exists = (_test),                                         \
699701a8f76SPaolo Bonzini     .size       = (_size),                                           \
700701a8f76SPaolo Bonzini     .info       = &(_info),                                          \
701701a8f76SPaolo Bonzini     .flags      = VMS_BUFFER,                                        \
702701a8f76SPaolo Bonzini     .offset     = offsetof(_state, _field),                          \
703701a8f76SPaolo Bonzini }
704701a8f76SPaolo Bonzini 
7058070568bSIgor Mitsyanko #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
7068070568bSIgor Mitsyanko     .name       = (stringify(_field)),                               \
7078070568bSIgor Mitsyanko     .version_id = (_version),                                        \
7088070568bSIgor Mitsyanko     .size       = (_size),                                           \
7098070568bSIgor Mitsyanko     .info       = &vmstate_info_buffer,                              \
7108070568bSIgor Mitsyanko     .flags      = VMS_BUFFER|VMS_POINTER,                            \
7118070568bSIgor Mitsyanko     .offset     = offsetof(_state, _field),                          \
7128070568bSIgor Mitsyanko }
7138070568bSIgor Mitsyanko 
714bcf45131SDr. David Alan Gilbert /* Allocate a temporary of type 'tmp_type', set tmp->parent to _state
715bcf45131SDr. David Alan Gilbert  * and execute the vmsd on the temporary.  Note that we're working with
716bcf45131SDr. David Alan Gilbert  * the whole of _state here, not a field within it.
717bcf45131SDr. David Alan Gilbert  * We compile time check that:
718bcf45131SDr. David Alan Gilbert  *    That _tmp_type contains a 'parent' member that's a pointer to the
719bcf45131SDr. David Alan Gilbert  *        '_state' type
720bcf45131SDr. David Alan Gilbert  *    That the pointer is right at the start of _tmp_type.
721bcf45131SDr. David Alan Gilbert  */
722508f7988SDavid Hildenbrand #define VMSTATE_WITH_TMP_TEST(_state, _test, _tmp_type, _vmsd) {     \
723bcf45131SDr. David Alan Gilbert     .name         = "tmp",                                           \
724508f7988SDavid Hildenbrand     .field_exists = (_test),                                         \
725bcf45131SDr. David Alan Gilbert     .size         = sizeof(_tmp_type) +                              \
726bcf45131SDr. David Alan Gilbert                     QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \
727bcf45131SDr. David Alan Gilbert                     type_check_pointer(_state,                       \
728bcf45131SDr. David Alan Gilbert                         typeof_field(_tmp_type, parent)),            \
729bcf45131SDr. David Alan Gilbert     .vmsd         = &(_vmsd),                                        \
730bcf45131SDr. David Alan Gilbert     .info         = &vmstate_info_tmp,                               \
731bcf45131SDr. David Alan Gilbert }
732bcf45131SDr. David Alan Gilbert 
733508f7988SDavid Hildenbrand #define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) \
734508f7988SDavid Hildenbrand     VMSTATE_WITH_TMP_TEST(_state, NULL, _tmp_type, _vmsd)
735508f7988SDavid Hildenbrand 
736701a8f76SPaolo Bonzini #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
737701a8f76SPaolo Bonzini     .name         = "unused",                                        \
738701a8f76SPaolo Bonzini     .field_exists = (_test),                                         \
739701a8f76SPaolo Bonzini     .version_id   = (_version),                                      \
740701a8f76SPaolo Bonzini     .size         = (_size),                                         \
741701a8f76SPaolo Bonzini     .info         = &vmstate_info_unused_buffer,                     \
742701a8f76SPaolo Bonzini     .flags        = VMS_BUFFER,                                      \
743701a8f76SPaolo Bonzini }
744701a8f76SPaolo Bonzini 
745b5b5c569SDr. David Alan Gilbert /* Discard size * field_num bytes, where field_num is a uint32 member */
746b5b5c569SDr. David Alan Gilbert #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\
747b5b5c569SDr. David Alan Gilbert     .name         = "unused",                                        \
748b5b5c569SDr. David Alan Gilbert     .field_exists = (_test),                                         \
749b5b5c569SDr. David Alan Gilbert     .num_offset   = vmstate_offset_value(_state, _field_num, uint32_t),\
750b5b5c569SDr. David Alan Gilbert     .version_id   = (_version),                                      \
751b5b5c569SDr. David Alan Gilbert     .size         = (_size),                                         \
752b5b5c569SDr. David Alan Gilbert     .info         = &vmstate_info_unused_buffer,                     \
753b5b5c569SDr. David Alan Gilbert     .flags        = VMS_VARRAY_UINT32 | VMS_BUFFER,                  \
754b5b5c569SDr. David Alan Gilbert }
755b5b5c569SDr. David Alan Gilbert 
75608e99e29SPeter Maydell /* _field_size should be a int32_t field in the _state struct giving the
75708e99e29SPeter Maydell  * size of the bitmap _field in bits.
75808e99e29SPeter Maydell  */
759508f7988SDavid Hildenbrand #define VMSTATE_BITMAP_TEST(_field, _state, _test, _version, _field_size) { \
76008e99e29SPeter Maydell     .name         = (stringify(_field)),                             \
761508f7988SDavid Hildenbrand     .field_exists = (_test),                                         \
76208e99e29SPeter Maydell     .version_id   = (_version),                                      \
76308e99e29SPeter Maydell     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
76408e99e29SPeter Maydell     .info         = &vmstate_info_bitmap,                            \
76508e99e29SPeter Maydell     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
76608e99e29SPeter Maydell     .offset       = offsetof(_state, _field),                        \
76708e99e29SPeter Maydell }
76808e99e29SPeter Maydell 
769508f7988SDavid Hildenbrand #define VMSTATE_BITMAP(_field, _state, _version, _field_size) \
770508f7988SDavid Hildenbrand     VMSTATE_BITMAP_TEST(_field, _state, NULL, _version, _field_size)
771508f7988SDavid Hildenbrand 
77294869d5cSJianjun Duan /* For migrating a QTAILQ.
77394869d5cSJianjun Duan  * Target QTAILQ needs be properly initialized.
77494869d5cSJianjun Duan  * _type: type of QTAILQ element
77594869d5cSJianjun Duan  * _next: name of QTAILQ entry field in QTAILQ element
77694869d5cSJianjun Duan  * _vmsd: VMSD for QTAILQ element
77794869d5cSJianjun Duan  * size: size of QTAILQ element
77894869d5cSJianjun Duan  * start: offset of QTAILQ entry in QTAILQ element
77994869d5cSJianjun Duan  */
78094869d5cSJianjun Duan #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next)  \
78194869d5cSJianjun Duan {                                                                        \
78294869d5cSJianjun Duan     .name         = (stringify(_field)),                                 \
78394869d5cSJianjun Duan     .version_id   = (_version),                                          \
78494869d5cSJianjun Duan     .vmsd         = &(_vmsd),                                            \
78594869d5cSJianjun Duan     .size         = sizeof(_type),                                       \
78694869d5cSJianjun Duan     .info         = &vmstate_info_qtailq,                                \
78794869d5cSJianjun Duan     .offset       = offsetof(_state, _field),                            \
78894869d5cSJianjun Duan     .start        = offsetof(_type, _next),                              \
78994869d5cSJianjun Duan }
79094869d5cSJianjun Duan 
7919a85e4b8SEric Auger /*
7929a85e4b8SEric Auger  * For migrating a GTree whose key is a pointer to _key_type and the
7939a85e4b8SEric Auger  * value, a pointer to _val_type
7949a85e4b8SEric Auger  * The target tree must have been properly initialized
7959a85e4b8SEric Auger  * _vmsd: Start address of the 2 element array containing the data vmsd
7969a85e4b8SEric Auger  *        and the key vmsd, in that order
7979a85e4b8SEric Auger  * _key_type: type of the key
7989a85e4b8SEric Auger  * _val_type: type of the value
7999a85e4b8SEric Auger  */
8009a85e4b8SEric Auger #define VMSTATE_GTREE_V(_field, _state, _version, _vmsd,                       \
8019a85e4b8SEric Auger                         _key_type, _val_type)                                  \
8029a85e4b8SEric Auger {                                                                              \
8039a85e4b8SEric Auger     .name         = (stringify(_field)),                                       \
8049a85e4b8SEric Auger     .version_id   = (_version),                                                \
8059a85e4b8SEric Auger     .vmsd         = (_vmsd),                                                   \
8069a85e4b8SEric Auger     .info         = &vmstate_info_gtree,                                       \
8079a85e4b8SEric Auger     .start        = sizeof(_key_type),                                         \
8089a85e4b8SEric Auger     .size         = sizeof(_val_type),                                         \
8099a85e4b8SEric Auger     .offset       = offsetof(_state, _field),                                  \
8109a85e4b8SEric Auger }
8119a85e4b8SEric Auger 
8129a85e4b8SEric Auger /*
8139a85e4b8SEric Auger  * For migrating a GTree with direct key and the value a pointer
8149a85e4b8SEric Auger  * to _val_type
8159a85e4b8SEric Auger  * The target tree must have been properly initialized
8169a85e4b8SEric Auger  * _vmsd: data vmsd
8179a85e4b8SEric Auger  * _val_type: type of the value
8189a85e4b8SEric Auger  */
8199a85e4b8SEric Auger #define VMSTATE_GTREE_DIRECT_KEY_V(_field, _state, _version, _vmsd, _val_type) \
8209a85e4b8SEric Auger {                                                                              \
8219a85e4b8SEric Auger     .name         = (stringify(_field)),                                       \
8229a85e4b8SEric Auger     .version_id   = (_version),                                                \
8239a85e4b8SEric Auger     .vmsd         = (_vmsd),                                                   \
8249a85e4b8SEric Auger     .info         = &vmstate_info_gtree,                                       \
8259a85e4b8SEric Auger     .start        = 0,                                                         \
8269a85e4b8SEric Auger     .size         = sizeof(_val_type),                                         \
8279a85e4b8SEric Auger     .offset       = offsetof(_state, _field),                                  \
8289a85e4b8SEric Auger }
8299a85e4b8SEric Auger 
8304746dbf8SEric Auger /*
8314746dbf8SEric Auger  * For migrating a QLIST
8324746dbf8SEric Auger  * Target QLIST needs be properly initialized.
8334746dbf8SEric Auger  * _type: type of QLIST element
8344746dbf8SEric Auger  * _next: name of QLIST_ENTRY entry field in QLIST element
8354746dbf8SEric Auger  * _vmsd: VMSD for QLIST element
8364746dbf8SEric Auger  * size: size of QLIST element
8374746dbf8SEric Auger  * start: offset of QLIST_ENTRY in QTAILQ element
8384746dbf8SEric Auger  */
8394746dbf8SEric Auger #define VMSTATE_QLIST_V(_field, _state, _version, _vmsd, _type, _next)  \
8404746dbf8SEric Auger {                                                                        \
8414746dbf8SEric Auger     .name         = (stringify(_field)),                                 \
8424746dbf8SEric Auger     .version_id   = (_version),                                          \
8434746dbf8SEric Auger     .vmsd         = &(_vmsd),                                            \
8444746dbf8SEric Auger     .size         = sizeof(_type),                                       \
8454746dbf8SEric Auger     .info         = &vmstate_info_qlist,                                 \
8464746dbf8SEric Auger     .offset       = offsetof(_state, _field),                            \
8474746dbf8SEric Auger     .start        = offsetof(_type, _next),                              \
8484746dbf8SEric Auger }
8494746dbf8SEric Auger 
850701a8f76SPaolo Bonzini /* _f : field name
851701a8f76SPaolo Bonzini    _f_n : num of elements field_name
852701a8f76SPaolo Bonzini    _n : num of elements
853701a8f76SPaolo Bonzini    _s : struct state name
854701a8f76SPaolo Bonzini    _v : version
855701a8f76SPaolo Bonzini */
856701a8f76SPaolo Bonzini 
857701a8f76SPaolo Bonzini #define VMSTATE_SINGLE(_field, _state, _version, _info, _type)        \
858701a8f76SPaolo Bonzini     VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
859701a8f76SPaolo Bonzini 
8602dc6660bSCorey Minyard #define VMSTATE_VSTRUCT(_field, _state, _vmsd, _type, _struct_version)\
8612dc6660bSCorey Minyard     VMSTATE_VSTRUCT_TEST(_field, _state, NULL, 0, _vmsd, _type, _struct_version)
8622dc6660bSCorey Minyard 
8632dc6660bSCorey Minyard #define VMSTATE_VSTRUCT_V(_field, _state, _version, _vmsd, _type, _struct_version) \
8642dc6660bSCorey Minyard     VMSTATE_VSTRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type, \
8652dc6660bSCorey Minyard                          _struct_version)
8662dc6660bSCorey Minyard 
867701a8f76SPaolo Bonzini #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)        \
868701a8f76SPaolo Bonzini     VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
869701a8f76SPaolo Bonzini 
870701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
8717102400dSAlexey Kardashevskiy     VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
8727102400dSAlexey Kardashevskiy 
8737102400dSAlexey Kardashevskiy #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type)     \
8747102400dSAlexey Kardashevskiy     VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
875701a8f76SPaolo Bonzini 
876701a8f76SPaolo Bonzini #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
877701a8f76SPaolo Bonzini     VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
878701a8f76SPaolo Bonzini             _vmsd, _type)
879701a8f76SPaolo Bonzini 
880b75c958dSStafford Horne #define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version,    \
881b75c958dSStafford Horne             _vmsd, _type)                                             \
882b75c958dSStafford Horne     VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL,       \
883b75c958dSStafford Horne             _version, _vmsd, _type)
884b75c958dSStafford Horne 
8859df0b0e0SLaszlo Ersek #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
8869df0b0e0SLaszlo Ersek     VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
8879df0b0e0SLaszlo Ersek             _size)
8889df0b0e0SLaszlo Ersek 
889701a8f76SPaolo Bonzini #define VMSTATE_BOOL_V(_f, _s, _v)                                    \
890701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
891701a8f76SPaolo Bonzini 
892701a8f76SPaolo Bonzini #define VMSTATE_INT8_V(_f, _s, _v)                                    \
893701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
894701a8f76SPaolo Bonzini #define VMSTATE_INT16_V(_f, _s, _v)                                   \
895701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
896701a8f76SPaolo Bonzini #define VMSTATE_INT32_V(_f, _s, _v)                                   \
897701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
898701a8f76SPaolo Bonzini #define VMSTATE_INT64_V(_f, _s, _v)                                   \
899701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
900701a8f76SPaolo Bonzini 
901701a8f76SPaolo Bonzini #define VMSTATE_UINT8_V(_f, _s, _v)                                   \
902701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
903701a8f76SPaolo Bonzini #define VMSTATE_UINT16_V(_f, _s, _v)                                  \
904701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
905701a8f76SPaolo Bonzini #define VMSTATE_UINT32_V(_f, _s, _v)                                  \
906701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
907701a8f76SPaolo Bonzini #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
908701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
909701a8f76SPaolo Bonzini 
910e3965dc3SSteve Sistare #define VMSTATE_FD_V(_f, _s, _v)                                  \
911e3965dc3SSteve Sistare     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_fd, int32_t)
912e3965dc3SSteve Sistare 
9136cfd7639SLiran Alon #ifdef CONFIG_LINUX
9146cfd7639SLiran Alon 
9156cfd7639SLiran Alon #define VMSTATE_U8_V(_f, _s, _v)                                   \
9166cfd7639SLiran Alon     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, __u8)
9176cfd7639SLiran Alon #define VMSTATE_U16_V(_f, _s, _v)                                  \
9186cfd7639SLiran Alon     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, __u16)
9196cfd7639SLiran Alon #define VMSTATE_U32_V(_f, _s, _v)                                  \
9206cfd7639SLiran Alon     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, __u32)
9216cfd7639SLiran Alon #define VMSTATE_U64_V(_f, _s, _v)                                  \
9226cfd7639SLiran Alon     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, __u64)
9236cfd7639SLiran Alon 
9246cfd7639SLiran Alon #endif
9256cfd7639SLiran Alon 
926701a8f76SPaolo Bonzini #define VMSTATE_BOOL(_f, _s)                                          \
927701a8f76SPaolo Bonzini     VMSTATE_BOOL_V(_f, _s, 0)
928701a8f76SPaolo Bonzini 
929701a8f76SPaolo Bonzini #define VMSTATE_INT8(_f, _s)                                          \
930701a8f76SPaolo Bonzini     VMSTATE_INT8_V(_f, _s, 0)
931701a8f76SPaolo Bonzini #define VMSTATE_INT16(_f, _s)                                         \
932701a8f76SPaolo Bonzini     VMSTATE_INT16_V(_f, _s, 0)
933701a8f76SPaolo Bonzini #define VMSTATE_INT32(_f, _s)                                         \
934701a8f76SPaolo Bonzini     VMSTATE_INT32_V(_f, _s, 0)
935701a8f76SPaolo Bonzini #define VMSTATE_INT64(_f, _s)                                         \
936701a8f76SPaolo Bonzini     VMSTATE_INT64_V(_f, _s, 0)
937701a8f76SPaolo Bonzini 
938701a8f76SPaolo Bonzini #define VMSTATE_UINT8(_f, _s)                                         \
939701a8f76SPaolo Bonzini     VMSTATE_UINT8_V(_f, _s, 0)
940701a8f76SPaolo Bonzini #define VMSTATE_UINT16(_f, _s)                                        \
941701a8f76SPaolo Bonzini     VMSTATE_UINT16_V(_f, _s, 0)
942701a8f76SPaolo Bonzini #define VMSTATE_UINT32(_f, _s)                                        \
943701a8f76SPaolo Bonzini     VMSTATE_UINT32_V(_f, _s, 0)
944701a8f76SPaolo Bonzini #define VMSTATE_UINT64(_f, _s)                                        \
945701a8f76SPaolo Bonzini     VMSTATE_UINT64_V(_f, _s, 0)
946701a8f76SPaolo Bonzini 
947e3965dc3SSteve Sistare #define VMSTATE_FD(_f, _s)                                            \
948e3965dc3SSteve Sistare     VMSTATE_FD_V(_f, _s, 0)
949e3965dc3SSteve Sistare 
9506cfd7639SLiran Alon #ifdef CONFIG_LINUX
9516cfd7639SLiran Alon 
9526cfd7639SLiran Alon #define VMSTATE_U8(_f, _s)                                         \
9536cfd7639SLiran Alon     VMSTATE_U8_V(_f, _s, 0)
9546cfd7639SLiran Alon #define VMSTATE_U16(_f, _s)                                        \
9556cfd7639SLiran Alon     VMSTATE_U16_V(_f, _s, 0)
9566cfd7639SLiran Alon #define VMSTATE_U32(_f, _s)                                        \
9576cfd7639SLiran Alon     VMSTATE_U32_V(_f, _s, 0)
9586cfd7639SLiran Alon #define VMSTATE_U64(_f, _s)                                        \
9596cfd7639SLiran Alon     VMSTATE_U64_V(_f, _s, 0)
9606cfd7639SLiran Alon 
9616cfd7639SLiran Alon #endif
9626cfd7639SLiran Alon 
963d2164ad3SHalil Pasic #define VMSTATE_UINT8_EQUAL(_f, _s, _err_hint)                        \
964d2164ad3SHalil Pasic     VMSTATE_SINGLE_FULL(_f, _s, 0, 0,                                 \
965d2164ad3SHalil Pasic                         vmstate_info_uint8_equal, uint8_t, _err_hint)
966701a8f76SPaolo Bonzini 
967d2164ad3SHalil Pasic #define VMSTATE_UINT16_EQUAL(_f, _s, _err_hint)                       \
968d2164ad3SHalil Pasic     VMSTATE_SINGLE_FULL(_f, _s, 0, 0,                                 \
969d2164ad3SHalil Pasic                         vmstate_info_uint16_equal, uint16_t, _err_hint)
970701a8f76SPaolo Bonzini 
971d2164ad3SHalil Pasic #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v, _err_hint)                 \
972d2164ad3SHalil Pasic     VMSTATE_SINGLE_FULL(_f, _s, 0,  _v,                               \
973d2164ad3SHalil Pasic                         vmstate_info_uint16_equal, uint16_t, _err_hint)
974701a8f76SPaolo Bonzini 
975d2164ad3SHalil Pasic #define VMSTATE_INT32_EQUAL(_f, _s, _err_hint)                        \
976d2164ad3SHalil Pasic     VMSTATE_SINGLE_FULL(_f, _s, 0, 0,                                 \
977d2164ad3SHalil Pasic                         vmstate_info_int32_equal, int32_t, _err_hint)
978701a8f76SPaolo Bonzini 
979d2164ad3SHalil Pasic #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v, _err_hint)                 \
980d2164ad3SHalil Pasic     VMSTATE_SINGLE_FULL(_f, _s, 0,  _v,                               \
981d2164ad3SHalil Pasic                         vmstate_info_uint32_equal, uint32_t, _err_hint)
982d58f5598SDavid Gibson 
983d2164ad3SHalil Pasic #define VMSTATE_UINT32_EQUAL(_f, _s, _err_hint)                       \
984d2164ad3SHalil Pasic     VMSTATE_UINT32_EQUAL_V(_f, _s, 0, _err_hint)
985701a8f76SPaolo Bonzini 
986d2164ad3SHalil Pasic #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v, _err_hint)                 \
987d2164ad3SHalil Pasic     VMSTATE_SINGLE_FULL(_f, _s, 0,  _v,                               \
988d2164ad3SHalil Pasic                         vmstate_info_uint64_equal, uint64_t, _err_hint)
989e344b8a1SDavid Gibson 
990d2164ad3SHalil Pasic #define VMSTATE_UINT64_EQUAL(_f, _s, _err_hint)                       \
991d2164ad3SHalil Pasic     VMSTATE_UINT64_EQUAL_V(_f, _s, 0, _err_hint)
992e344b8a1SDavid Gibson 
9933476436aSMichael S. Tsirkin #define VMSTATE_INT32_POSITIVE_LE(_f, _s)                             \
994701a8f76SPaolo Bonzini     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
995701a8f76SPaolo Bonzini 
9968e995f34SCorey Minyard #define VMSTATE_BOOL_TEST(_f, _s, _t)                               \
9978e995f34SCorey Minyard     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool)
9988e995f34SCorey Minyard 
99987774a4aSDavid Gibson #define VMSTATE_INT8_TEST(_f, _s, _t)                               \
100087774a4aSDavid Gibson     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
100187774a4aSDavid Gibson 
100287774a4aSDavid Gibson #define VMSTATE_INT16_TEST(_f, _s, _t)                               \
100387774a4aSDavid Gibson     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
100487774a4aSDavid Gibson 
100587774a4aSDavid Gibson #define VMSTATE_INT32_TEST(_f, _s, _t)                                  \
100687774a4aSDavid Gibson     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
100787774a4aSDavid Gibson 
100887774a4aSDavid Gibson #define VMSTATE_INT64_TEST(_f, _s, _t)                                  \
100987774a4aSDavid Gibson     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
101087774a4aSDavid Gibson 
1011701a8f76SPaolo Bonzini #define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
1012701a8f76SPaolo Bonzini     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
1013701a8f76SPaolo Bonzini 
1014701a8f76SPaolo Bonzini #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
1015701a8f76SPaolo Bonzini     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
1016701a8f76SPaolo Bonzini 
1017701a8f76SPaolo Bonzini #define VMSTATE_UINT32_TEST(_f, _s, _t)                                  \
1018701a8f76SPaolo Bonzini     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
1019701a8f76SPaolo Bonzini 
102087774a4aSDavid Gibson #define VMSTATE_UINT64_TEST(_f, _s, _t)                                  \
102187774a4aSDavid Gibson     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
102287774a4aSDavid Gibson 
1023e3965dc3SSteve Sistare #define VMSTATE_FD_TEST(_f, _s, _t)                                            \
1024e3965dc3SSteve Sistare     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_fd, int32_t)
1025213945e4SDavid Gibson 
1026e720677eSPaolo Bonzini #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test)                             \
1027701a8f76SPaolo Bonzini     VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
1028701a8f76SPaolo Bonzini 
1029e720677eSPaolo Bonzini #define VMSTATE_TIMER_PTR_V(_f, _s, _v)                                   \
10300281518aSPaolo Bonzini     VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
10310281518aSPaolo Bonzini 
1032e720677eSPaolo Bonzini #define VMSTATE_TIMER_PTR(_f, _s)                                         \
1033e720677eSPaolo Bonzini     VMSTATE_TIMER_PTR_V(_f, _s, 0)
1034e720677eSPaolo Bonzini 
1035e720677eSPaolo Bonzini #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n)                              \
1036e720677eSPaolo Bonzini     VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
1037e720677eSPaolo Bonzini 
1038e720677eSPaolo Bonzini #define VMSTATE_TIMER_TEST(_f, _s, _test)                             \
1039e720677eSPaolo Bonzini     VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
1040e720677eSPaolo Bonzini 
1041e720677eSPaolo Bonzini #define VMSTATE_TIMER_V(_f, _s, _v)                                   \
1042e720677eSPaolo Bonzini     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
1043e720677eSPaolo Bonzini 
1044701a8f76SPaolo Bonzini #define VMSTATE_TIMER(_f, _s)                                         \
10450281518aSPaolo Bonzini     VMSTATE_TIMER_V(_f, _s, 0)
1046701a8f76SPaolo Bonzini 
1047701a8f76SPaolo Bonzini #define VMSTATE_TIMER_ARRAY(_f, _s, _n)                              \
1048e720677eSPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
1049701a8f76SPaolo Bonzini 
1050701a8f76SPaolo Bonzini #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
1051701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
1052701a8f76SPaolo Bonzini 
1053701a8f76SPaolo Bonzini #define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
1054701a8f76SPaolo Bonzini     VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
1055701a8f76SPaolo Bonzini 
1056e0a37e26SPeter Maydell #define VMSTATE_BOOL_SUB_ARRAY(_f, _s, _start, _num)                \
1057e0a37e26SPeter Maydell     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_bool, bool)
1058e0a37e26SPeter Maydell 
1059701a8f76SPaolo Bonzini #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
1060701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
1061701a8f76SPaolo Bonzini 
1062bd7f92e5SPeter Maydell #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
1063bd7f92e5SPeter Maydell     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
1064bd7f92e5SPeter Maydell 
1065701a8f76SPaolo Bonzini #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
1066701a8f76SPaolo Bonzini     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
1067701a8f76SPaolo Bonzini 
1068b77473a0SLuc Michel #define VMSTATE_UINT16_SUB_ARRAY(_f, _s, _start, _num)                \
1069b77473a0SLuc Michel     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint16, uint16_t)
1070b77473a0SLuc Michel 
1071bd7f92e5SPeter Maydell #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
1072bd7f92e5SPeter Maydell     VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
1073bd7f92e5SPeter Maydell 
1074bd7f92e5SPeter Maydell #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
1075bd7f92e5SPeter Maydell     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
1076bd7f92e5SPeter Maydell 
1077701a8f76SPaolo Bonzini #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
1078701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
1079701a8f76SPaolo Bonzini 
1080701a8f76SPaolo Bonzini #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
1081701a8f76SPaolo Bonzini     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
1082701a8f76SPaolo Bonzini 
10832e323f03SFam Zheng #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num)                \
10842e323f03SFam Zheng     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
10852e323f03SFam Zheng 
1086bd7f92e5SPeter Maydell #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
1087bd7f92e5SPeter Maydell     VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
1088bd7f92e5SPeter Maydell 
1089701a8f76SPaolo Bonzini #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
1090701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
1091701a8f76SPaolo Bonzini 
1092a1b1d277SChristoffer Dall #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
1093a1b1d277SChristoffer Dall     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
1094a1b1d277SChristoffer Dall 
1095701a8f76SPaolo Bonzini #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
1096701a8f76SPaolo Bonzini     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
1097701a8f76SPaolo Bonzini 
1098a006f122SRichard Henderson #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)                \
1099a006f122SRichard Henderson     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
1100a006f122SRichard Henderson 
1101a1b1d277SChristoffer Dall #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2)                      \
1102a1b1d277SChristoffer Dall     VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
1103a1b1d277SChristoffer Dall 
1104701a8f76SPaolo Bonzini #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
1105701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
1106701a8f76SPaolo Bonzini 
1107701a8f76SPaolo Bonzini #define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
1108701a8f76SPaolo Bonzini     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
1109701a8f76SPaolo Bonzini 
1110a006f122SRichard Henderson #define VMSTATE_UINT64_SUB_ARRAY(_f, _s, _start, _num)                \
1111a006f122SRichard Henderson     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint64, uint64_t)
1112a006f122SRichard Henderson 
111304716bc8SPeter Maydell #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2)                      \
111404716bc8SPeter Maydell     VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0)
111504716bc8SPeter Maydell 
111604716bc8SPeter Maydell #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
111704716bc8SPeter Maydell     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t)
111804716bc8SPeter Maydell 
1119701a8f76SPaolo Bonzini #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v)                         \
1120701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
1121701a8f76SPaolo Bonzini 
1122701a8f76SPaolo Bonzini #define VMSTATE_INT16_ARRAY(_f, _s, _n)                               \
1123701a8f76SPaolo Bonzini     VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
1124701a8f76SPaolo Bonzini 
1125701a8f76SPaolo Bonzini #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
1126701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
1127701a8f76SPaolo Bonzini 
1128701a8f76SPaolo Bonzini #define VMSTATE_INT32_ARRAY(_f, _s, _n)                               \
1129701a8f76SPaolo Bonzini     VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
1130701a8f76SPaolo Bonzini 
1131701a8f76SPaolo Bonzini #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v)                         \
1132701a8f76SPaolo Bonzini     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
1133701a8f76SPaolo Bonzini 
1134701a8f76SPaolo Bonzini #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
1135701a8f76SPaolo Bonzini     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
1136701a8f76SPaolo Bonzini 
113755174749SJuan Quintela #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v)                     \
113855174749SJuan Quintela     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
113955174749SJuan Quintela 
114055174749SJuan Quintela #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n)                           \
114155174749SJuan Quintela     VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
114255174749SJuan Quintela 
1143701a8f76SPaolo Bonzini #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
1144701a8f76SPaolo Bonzini     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
1145701a8f76SPaolo Bonzini 
1146701a8f76SPaolo Bonzini #define VMSTATE_BUFFER(_f, _s)                                        \
1147701a8f76SPaolo Bonzini     VMSTATE_BUFFER_V(_f, _s, 0)
1148701a8f76SPaolo Bonzini 
1149701a8f76SPaolo Bonzini #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size)                         \
1150701a8f76SPaolo Bonzini     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
1151701a8f76SPaolo Bonzini 
1152cc966774SPaolo Bonzini #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \
1153cc966774SPaolo Bonzini     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f)))
1154cc966774SPaolo Bonzini 
1155701a8f76SPaolo Bonzini #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
1156cc966774SPaolo Bonzini     VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0)
1157701a8f76SPaolo Bonzini 
1158701a8f76SPaolo Bonzini #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)                        \
115959046ec2SHalil Pasic     VMSTATE_VBUFFER(_f, _s, 0, NULL, _size)
1160701a8f76SPaolo Bonzini 
1161701a8f76SPaolo Bonzini #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)                        \
116259046ec2SHalil Pasic     VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size)
1163701a8f76SPaolo Bonzini 
1164701a8f76SPaolo Bonzini #define VMSTATE_BUFFER_TEST(_f, _s, _test)                            \
1165701a8f76SPaolo Bonzini     VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
1166701a8f76SPaolo Bonzini 
1167701a8f76SPaolo Bonzini #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)        \
1168701a8f76SPaolo Bonzini     VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
1169701a8f76SPaolo Bonzini 
1170772c6212SPeter Xu /*
1171772c6212SPeter Xu  * These VMSTATE_UNUSED*() macros can be used to fill in the holes
1172772c6212SPeter Xu  * when some of the vmstate fields are obsolete to be compatible with
1173772c6212SPeter Xu  * migrations between new/old binaries.
1174772c6212SPeter Xu  *
1175772c6212SPeter Xu  * CAUTION: when using any of the VMSTATE_UNUSED*() macros please be
1176772c6212SPeter Xu  * sure that the size passed in is the size that was actually *sent*
1177772c6212SPeter Xu  * rather than the size of the *structure*.  One example is the
1178772c6212SPeter Xu  * boolean type - the size of the structure can vary depending on the
1179772c6212SPeter Xu  * definition of boolean, however the size we actually sent is always
1180772c6212SPeter Xu  * 1 byte (please refer to implementation of VMSTATE_BOOL_V and
1181772c6212SPeter Xu  * vmstate_info_bool).  So here we should always pass in size==1
1182772c6212SPeter Xu  * rather than size==sizeof(bool).
1183772c6212SPeter Xu  */
1184701a8f76SPaolo Bonzini #define VMSTATE_UNUSED_V(_v, _size)                                   \
1185701a8f76SPaolo Bonzini     VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
1186701a8f76SPaolo Bonzini 
1187701a8f76SPaolo Bonzini #define VMSTATE_UNUSED(_size)                                         \
1188701a8f76SPaolo Bonzini     VMSTATE_UNUSED_V(0, _size)
1189701a8f76SPaolo Bonzini 
1190701a8f76SPaolo Bonzini #define VMSTATE_UNUSED_TEST(_test, _size)                             \
1191701a8f76SPaolo Bonzini     VMSTATE_UNUSED_BUFFER(_test, 0, _size)
1192701a8f76SPaolo Bonzini 
1193701a8f76SPaolo Bonzini #define VMSTATE_END_OF_LIST()                                         \
119489c56848SDr. David Alan Gilbert     {                     \
119589c56848SDr. David Alan Gilbert         .flags = VMS_END, \
119689c56848SDr. David Alan Gilbert     }
1197701a8f76SPaolo Bonzini 
1198701a8f76SPaolo Bonzini int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
1199701a8f76SPaolo Bonzini                        void *opaque, int version_id);
1200551dbd08SDr. David Alan Gilbert int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
12013ddba9a9SMarkus Armbruster                        void *opaque, JSONWriter *vmdesc);
1202969298f9STejus GK int vmstate_save_state_with_err(QEMUFile *f, const VMStateDescription *vmsd,
1203969298f9STejus GK                        void *opaque, JSONWriter *vmdesc, Error **errp);
12042dc6660bSCorey Minyard int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
12053ddba9a9SMarkus Armbruster                          void *opaque, JSONWriter *vmdesc,
1206969298f9STejus GK                          int version_id, Error **errp);
1207d7650eabSAndreas Färber 
12084d8bdc2aSMarc-André Lureau bool vmstate_section_needed(const VMStateDescription *vmsd, void *opaque);
1209df896152SJuan Quintela 
12101df2c9a2SPeter Xu #define  VMSTATE_INSTANCE_ID_ANY  -1
12111df2c9a2SPeter Xu 
1212581f08baSDr. David Alan Gilbert /* Returns: 0 on success, -1 on failure */
121393062e23SPeter Xu int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id,
1214701a8f76SPaolo Bonzini                                    const VMStateDescription *vmsd,
1215701a8f76SPaolo Bonzini                                    void *base, int alias_id,
1216bc5c4f21SDr. David Alan Gilbert                                    int required_for_version,
1217bc5c4f21SDr. David Alan Gilbert                                    Error **errp);
1218d7650eabSAndreas Färber 
12196caf1571SAlex Bennée /**
12206caf1571SAlex Bennée  * vmstate_register() - legacy function to register state
12216caf1571SAlex Bennée  * serialisation description
12226caf1571SAlex Bennée  *
12236caf1571SAlex Bennée  * New code shouldn't be using this function as QOM-ified devices have
12246caf1571SAlex Bennée  * dc->vmsd to store the serialisation description.
12256caf1571SAlex Bennée  *
12266caf1571SAlex Bennée  * Returns: 0 on success, -1 on failure
12276caf1571SAlex Bennée  */
12283cad405bSMarc-André Lureau static inline int vmstate_register(VMStateIf *obj, int instance_id,
1229d7650eabSAndreas Färber                                    const VMStateDescription *vmsd,
1230d7650eabSAndreas Färber                                    void *opaque)
1231d7650eabSAndreas Färber {
12323cad405bSMarc-André Lureau     return vmstate_register_with_alias_id(obj, instance_id, vmsd,
1233bc5c4f21SDr. David Alan Gilbert                                           opaque, -1, 0, NULL);
1234d7650eabSAndreas Färber }
1235d7650eabSAndreas Färber 
123671daf640SJuan Quintela /**
1237485fb955SJuan Quintela  * vmstate_replace_hack_for_ppc() - ppc used to abuse vmstate_register
1238485fb955SJuan Quintela  *
1239485fb955SJuan Quintela  * Don't even think about using this function in new code.
1240485fb955SJuan Quintela  *
1241485fb955SJuan Quintela  * Returns: 0 on success, -1 on failure
1242485fb955SJuan Quintela  */
1243485fb955SJuan Quintela int vmstate_replace_hack_for_ppc(VMStateIf *obj, int instance_id,
1244485fb955SJuan Quintela                                  const VMStateDescription *vmsd,
1245485fb955SJuan Quintela                                  void *opaque);
1246485fb955SJuan Quintela 
1247485fb955SJuan Quintela /**
124871daf640SJuan Quintela  * vmstate_register_any() - legacy function to register state
124971daf640SJuan Quintela  * serialisation description and let the function choose the id
125071daf640SJuan Quintela  *
125171daf640SJuan Quintela  * New code shouldn't be using this function as QOM-ified devices have
125271daf640SJuan Quintela  * dc->vmsd to store the serialisation description.
125371daf640SJuan Quintela  *
125471daf640SJuan Quintela  * Returns: 0 on success, -1 on failure
125571daf640SJuan Quintela  */
125671daf640SJuan Quintela static inline int vmstate_register_any(VMStateIf *obj,
125771daf640SJuan Quintela                                        const VMStateDescription *vmsd,
125871daf640SJuan Quintela                                        void *opaque)
125971daf640SJuan Quintela {
126071daf640SJuan Quintela     return vmstate_register_with_alias_id(obj, VMSTATE_INSTANCE_ID_ANY, vmsd,
126171daf640SJuan Quintela                                           opaque, -1, 0, NULL);
126271daf640SJuan Quintela }
126371daf640SJuan Quintela 
12643cad405bSMarc-André Lureau void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd,
1265701a8f76SPaolo Bonzini                         void *opaque);
1266701a8f76SPaolo Bonzini 
1267701a8f76SPaolo Bonzini void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
1268701a8f76SPaolo Bonzini void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
1269701a8f76SPaolo Bonzini void vmstate_register_ram_global(struct MemoryRegion *memory);
1270701a8f76SPaolo Bonzini 
12711bfe5f05SJuan Quintela bool vmstate_check_only_migratable(const VMStateDescription *vmsd);
12721bfe5f05SJuan Quintela 
1273701a8f76SPaolo Bonzini #endif
1274