| 1 | /* |
| 2 | * QEMU migration/snapshot declarations |
| 3 | * |
| 4 | * Copyright (c) 2009-2011 Red Hat, Inc. |
| 5 | * |
| 6 | * Original author: Juan Quintela <quintela@redhat.com> |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #ifndef QEMU_VMSTATE_H |
| 28 | #define QEMU_VMSTATE_H |
| 29 | |
| 30 | #include "hw/core/vmstate-if.h" |
| 31 | |
| 32 | typedef struct VMStateInfo VMStateInfo; |
| 33 | typedef struct VMStateField VMStateField; |
| 34 | typedef struct VMStateStructMember VMStateStructMember; |
| 35 | |
| 36 | /* |
| 37 | * VMStateInfo allows customized migration of objects that don't fit in |
| 38 | * any category in VMStateFlags. Additional information is always passed |
| 39 | * into load and save in terms of field and vmdesc parameters. However |
| 40 | * these two parameters should only be used in cases when customized |
| 41 | * handling is needed, such as QTAILQ. For primitive data types such as |
| 42 | * integer, field and vmdesc parameters should be ignored inside load/save. |
| 43 | * |
| 44 | * @get and @put are deprecated copies of @load and @save. For new interfaces |
| 45 | * use @load and @save. |
| 46 | */ |
| 47 | struct VMStateInfo { |
| 48 | const char *name; |
| 49 | int coroutine_mixed_fn (*get)(QEMUFile *f, void *pv, size_t size, |
| 50 | const VMStateField *field); |
| 51 | int coroutine_mixed_fn (*put)(QEMUFile *f, void *pv, size_t size, |
| 52 | const VMStateField *field, |
| 53 | JSONWriter *vmdesc); |
| 54 | bool coroutine_mixed_fn (*load)(QEMUFile *f, void *pv, size_t size, |
| 55 | const VMStateField *field, |
| 56 | Error **errp); |
| 57 | bool coroutine_mixed_fn (*save)(QEMUFile *f, void *pv, size_t size, |
| 58 | const VMStateField *field, |
| 59 | JSONWriter *vmdesc, |
| 60 | Error **errp); |
| 61 | }; |
| 62 | |
| 63 | enum VMStateFlags { |
| 64 | /* Ignored */ |
| 65 | VMS_SINGLE = 0x001, |
| 66 | |
| 67 | /* The struct member at opaque + VMStateField.offset is a pointer |
| 68 | * to the actual field (e.g. struct a { uint8_t *b; |
| 69 | * }). Dereference the pointer before using it as basis for |
| 70 | * further pointer arithmetic (see e.g. VMS_ARRAY). Does not |
| 71 | * affect the meaning of VMStateField.num_indirect or |
| 72 | * VMStateField.size_indirect; see VMS_VARRAY and VMS_VBUFFER for |
| 73 | * those. |
| 74 | */ |
| 75 | VMS_POINTER = 0x002, |
| 76 | |
| 77 | /* The field is an array of fixed size. VMStateField.num contains |
| 78 | * the number of entries in the array. The size of each entry is |
| 79 | * given by VMStateField.size and / or opaque + |
| 80 | * VMStateField.size_indirect; see VMS_VBUFFER and |
| 81 | * VMS_MULTIPLY. Each array entry will be processed individually |
| 82 | * (VMStateField.info.get()/put() if VMS_STRUCT is not set, |
| 83 | * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not |
| 84 | * be combined with VMS_VARRAY. |
| 85 | */ |
| 86 | VMS_ARRAY = 0x004, |
| 87 | |
| 88 | /* The field is itself a struct, containing one or more |
| 89 | * fields. Recurse into VMStateField.vmsd. Most useful in |
| 90 | * combination with VMS_ARRAY / VMS_VARRAY, recursing into each |
| 91 | * array entry. */ |
| 92 | VMS_STRUCT = 0x008, |
| 93 | |
| 94 | /* |
| 95 | * The field is an array of variable size. The integer at opaque + |
| 96 | * VMStateField.num_indirect contains the number of entries in the |
| 97 | * array. See the VMS_ARRAY description regarding array handling |
| 98 | * in general. May not be combined with VMS_ARRAY. |
| 99 | */ |
| 100 | VMS_VARRAY = 0x010, |
| 101 | |
| 102 | /* Ignored */ |
| 103 | VMS_BUFFER = 0x020, |
| 104 | |
| 105 | /* The field is a (fixed-size or variable-size) array of pointers |
| 106 | * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry |
| 107 | * before using it. Note: Does not imply any one of VMS_ARRAY / |
| 108 | * VMS_VARRAY; these need to be set explicitly. |
| 109 | */ |
| 110 | VMS_ARRAY_OF_POINTER = 0x040, |
| 111 | |
| 112 | /* |
| 113 | * The field contains no data. Used for special cases such as |
| 114 | * invoking a custom VMStateInfo. |
| 115 | */ |
| 116 | VMS_NO_STATE = 0x080, |
| 117 | |
| 118 | /* The size of the individual entries (a single array entry if |
| 119 | * VMS_ARRAY or VMS_VARRAY are set, or the field itself if |
| 120 | * neither is set) is variable (i.e. not known at compile-time), |
| 121 | * but the same for all entries. Use the integer at opaque + |
| 122 | * VMStateField.size_indirect (subject to VMS_MULTIPLY) to determine |
| 123 | * the size of each (and every) entry. */ |
| 124 | VMS_VBUFFER = 0x100, |
| 125 | |
| 126 | /* |
| 127 | * Multiply the entry size given by the integer at opaque + |
| 128 | * VMStateField.size_indirect (see VMS_VBUFFER description) with |
| 129 | * VMStateField.size to determine the number of bytes to be |
| 130 | * allocated. Only valid in combination with VMS_VBUFFER. */ |
| 131 | VMS_MULTIPLY = 0x200, |
| 132 | |
| 133 | /* Fail loading the serialised VM state if this field is missing |
| 134 | * from the input. */ |
| 135 | VMS_MUST_EXIST = 0x1000, |
| 136 | |
| 137 | /* When loading serialised VM state, allocate memory for the |
| 138 | * (entire) field. Only valid in combination with |
| 139 | * VMS_POINTER. Note: Not all combinations with other flags are |
| 140 | * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't |
| 141 | * cause the individual entries to be allocated. */ |
| 142 | VMS_ALLOC = 0x2000, |
| 143 | |
| 144 | /* A structure field that is like VMS_STRUCT, but uses |
| 145 | * VMStateField.struct_version_id to tell which version of the |
| 146 | * structure we are referencing to use. */ |
| 147 | VMS_VSTRUCT = 0x8000, |
| 148 | |
| 149 | /* |
| 150 | * This is a sub-flag for VMS_ARRAY_OF_POINTER. When this flag is set, |
| 151 | * VMS_ARRAY_OF_POINTER must also be set. When set, it means array |
| 152 | * elements can contain either valid or NULL pointers, vmstate core |
| 153 | * will be responsible for synchronizing the pointer status, providing |
| 154 | * proper memory allocations on the pointer when it is populated on the |
| 155 | * source QEMU. It also means the user of the field must make sure all |
| 156 | * the elements in the array are NULL pointers before loading. This |
| 157 | * should also work with VMS_ALLOC when the array itself also needs to |
| 158 | * be allocated. |
| 159 | */ |
| 160 | VMS_ARRAY_OF_POINTER_AUTO_ALLOC = 0x10000, |
| 161 | |
| 162 | /* Marker for end of list */ |
| 163 | VMS_END = 0x20000, |
| 164 | }; |
| 165 | |
| 166 | typedef enum { |
| 167 | MIG_PRI_UNINITIALIZED = 0, /* An uninitialized priority field maps to */ |
| 168 | /* MIG_PRI_DEFAULT in save_state_priority */ |
| 169 | |
| 170 | MIG_PRI_LOW, /* Must happen after default */ |
| 171 | MIG_PRI_DEFAULT, |
| 172 | MIG_PRI_IOMMU, /* Must happen before PCI devices */ |
| 173 | MIG_PRI_PCI_BUS, /* Must happen before IOMMU */ |
| 174 | MIG_PRI_VIRTIO_MEM, /* Must happen before IOMMU */ |
| 175 | MIG_PRI_APIC, /* Must happen before PCI devices */ |
| 176 | MIG_PRI_GICV3_ITS, /* Must happen before PCI devices */ |
| 177 | MIG_PRI_GICV3, /* Must happen before the ITS */ |
| 178 | MIG_PRI_MAX, |
| 179 | } MigrationPriority; |
| 180 | |
| 181 | |
| 182 | /* |
| 183 | * VMStateStructMember: Metadata about a single member of the struct |
| 184 | * being migrated by the vmstate. This is kept separate from |
| 185 | * VMStateField because a single VMStateField can reference other |
| 186 | * members of the struct aside from the main struct member that's |
| 187 | * being migrated. |
| 188 | * |
| 189 | * One situation where extra fields are referenced is the common case |
| 190 | * of a struct containing an array or buffer, the size of which is |
| 191 | * stored in another member of the same struct. |
| 192 | * |
| 193 | * Example 1: |
| 194 | * struct IDEState { |
| 195 | * ... |
| 196 | * uint8_t *io_buffer; |
| 197 | * int32_t io_buffer_total_len; |
| 198 | * ... |
| 199 | * } |
| 200 | * VMSTATE_VARRAY_INT32(io_buffer, IDEState, io_buffer_total_len, 1, |
| 201 | * vmstate_info_uint8, uint8_t) |
| 202 | * |
| 203 | * In the above, io_buffer is the main field being migrated by the |
| 204 | * VMSTATE_VARRAY while io_buffer_total_len is the meta field that |
| 205 | * provides the size of the io_buffer. In this particular case, |
| 206 | * io_buffer_total_len is never migrated. |
| 207 | * |
| 208 | * Example 2: |
| 209 | * struct SpaprMachineState { |
| 210 | * ... |
| 211 | * uint32_t fdt_size; |
| 212 | * void *fdt_blob; |
| 213 | * ... |
| 214 | * } |
| 215 | * VMSTATE_UINT32(fdt_size, SpaprMachineState), |
| 216 | * VMSTATE_VBUFFER_ALLOC_UINT32(fdt_blob, SpaprMachineState, 0, NULL, fdt_size), |
| 217 | * |
| 218 | * Here, fdt_blob is the field being migrated by VMSTATE_VBUFFER_ALLOC |
| 219 | * and fdt_size is the meta field providing the size. In this case, |
| 220 | * the extra field is also independently migrated by the |
| 221 | * VMSTATE_UINT32 above. |
| 222 | */ |
| 223 | struct VMStateStructMember { |
| 224 | /* offsetof the field inside the migrated struct */ |
| 225 | uint32_t offset; |
| 226 | /* size of field itself */ |
| 227 | uint8_t size; |
| 228 | }; |
| 229 | |
| 230 | struct VMStateField { |
| 231 | const char *name; |
| 232 | size_t offset; |
| 233 | |
| 234 | /* |
| 235 | * @size directly specifies the size of the element being |
| 236 | * migrated. |
| 237 | * |
| 238 | * @size_indirect specifies the offset inside a struct where the |
| 239 | * size of the element is stored. |
| 240 | * |
| 241 | * Only one of the above should be present (except for |
| 242 | * VMSTATE_MULTIPLY which uses .size as a multiplier). When |
| 243 | * @size_indirect is used together with VMS_VBUFFER, it means |
| 244 | * the size is dynamic calculated instead of a constant. |
| 245 | * |
| 246 | * When the field is an array of any type, these refer to the size |
| 247 | * of one element of the array. |
| 248 | * |
| 249 | * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be |
| 250 | * specified, these parameters always reflect the real size of the |
| 251 | * objects that a pointer point to. |
| 252 | * |
| 253 | * @num_indirect specifies the offset inside a struct where the |
| 254 | * number of elements of an array is stored. |
| 255 | */ |
| 256 | size_t size; |
| 257 | VMStateStructMember size_indirect; |
| 258 | VMStateStructMember num_indirect; |
| 259 | |
| 260 | size_t start; |
| 261 | int num; |
| 262 | |
| 263 | const VMStateInfo *info; |
| 264 | enum VMStateFlags flags; |
| 265 | const VMStateDescription *vmsd; |
| 266 | int version_id; |
| 267 | int struct_version_id; |
| 268 | bool (*field_exists)(void *opaque, int version_id); |
| 269 | }; |
| 270 | |
| 271 | struct VMStateDescription { |
| 272 | const char *name; |
| 273 | bool unmigratable; |
| 274 | /* |
| 275 | * This VMSD describes something that should be sent during setup phase |
| 276 | * of migration. It plays similar role as save_setup() for explicitly |
| 277 | * registered vmstate entries, so it can be seen as a way to describe |
| 278 | * save_setup() in VMSD structures. |
| 279 | * |
| 280 | * Note that for now, a SaveStateEntry cannot have a VMSD and |
| 281 | * operations (e.g., save_setup()) set at the same time. Consequently, |
| 282 | * save_setup() and a VMSD with early_setup set to true are mutually |
| 283 | * exclusive. For this reason, also early_setup VMSDs are migrated in a |
| 284 | * QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in |
| 285 | * a QEMU_VM_SECTION_START section. |
| 286 | * |
| 287 | * There are duplicate impls of the post/pre save/load hooks. |
| 288 | * New impls should preferentally use 'errp' variants of these |
| 289 | * methods and existing impls incrementally converted. |
| 290 | * The variants without 'errp' are intended to be removed |
| 291 | * once all usage is converted. |
| 292 | * |
| 293 | * For the errp variants, |
| 294 | * Returns: 0 on success, |
| 295 | * <0 on error where -value is an error number from errno.h |
| 296 | */ |
| 297 | |
| 298 | bool early_setup; |
| 299 | int version_id; |
| 300 | int minimum_version_id; |
| 301 | MigrationPriority priority; |
| 302 | int (*pre_load)(void *opaque); |
| 303 | bool (*pre_load_errp)(void *opaque, Error **errp); |
| 304 | int (*post_load)(void *opaque, int version_id); |
| 305 | bool (*post_load_errp)(void *opaque, int version_id, Error **errp); |
| 306 | int (*pre_save)(void *opaque); |
| 307 | bool (*pre_save_errp)(void *opaque, Error **errp); |
| 308 | |
| 309 | /* |
| 310 | * Unless .pre_save() fails, .post_save() is called after saving |
| 311 | * fields and subsections. It should not fail because at this |
| 312 | * point the state has potentially already been transferred. |
| 313 | */ |
| 314 | void (*post_save)(void *opaque); |
| 315 | bool (*needed)(void *opaque); |
| 316 | bool (*dev_unplug_pending)(void *opaque); |
| 317 | |
| 318 | const VMStateField *fields; |
| 319 | const VMStateDescription * const *subsections; |
| 320 | }; |
| 321 | |
| 322 | extern const VMStateInfo vmstate_info_bool; |
| 323 | |
| 324 | extern const VMStateInfo vmstate_info_int8; |
| 325 | extern const VMStateInfo vmstate_info_int16; |
| 326 | extern const VMStateInfo vmstate_info_int32; |
| 327 | extern const VMStateInfo vmstate_info_int64; |
| 328 | |
| 329 | extern const VMStateInfo vmstate_info_uint8_equal; |
| 330 | extern const VMStateInfo vmstate_info_uint16_equal; |
| 331 | extern const VMStateInfo vmstate_info_int32_equal; |
| 332 | extern const VMStateInfo vmstate_info_uint32_equal; |
| 333 | extern const VMStateInfo vmstate_info_uint64_equal; |
| 334 | extern const VMStateInfo vmstate_info_int32_le; |
| 335 | |
| 336 | extern const VMStateInfo vmstate_info_uint8; |
| 337 | extern const VMStateInfo vmstate_info_uint16; |
| 338 | extern const VMStateInfo vmstate_info_uint32; |
| 339 | extern const VMStateInfo vmstate_info_uint64; |
| 340 | extern const VMStateInfo vmstate_info_fd; |
| 341 | |
| 342 | /* |
| 343 | * Put this in the stream when migrating a pointer to reflect either a NULL |
| 344 | * or valid pointer. |
| 345 | */ |
| 346 | #define VMS_MARKER_PTR_NULL (0x30U) /* '0' */ |
| 347 | #define VMS_MARKER_PTR_VALID (0x31U) /* '1' */ |
| 348 | |
| 349 | extern const VMStateInfo vmstate_info_ptr_marker; |
| 350 | |
| 351 | extern const VMStateInfo vmstate_info_cpudouble; |
| 352 | |
| 353 | extern const VMStateInfo vmstate_info_timer; |
| 354 | extern const VMStateInfo vmstate_info_buffer; |
| 355 | extern const VMStateInfo vmstate_info_unused_buffer; |
| 356 | extern const VMStateInfo vmstate_info_tmp; |
| 357 | extern const VMStateInfo vmstate_info_bitmap; |
| 358 | extern const VMStateInfo vmstate_info_qtailq; |
| 359 | extern const VMStateInfo vmstate_info_gtree; |
| 360 | extern const VMStateInfo vmstate_info_qlist; |
| 361 | extern const VMStateInfo vmstate_info_g_byte_array; |
| 362 | |
| 363 | #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) |
| 364 | /* |
| 365 | * Check that type t2 is an array of type t1 of size n, |
| 366 | * e.g. if t1 is 'foo' and n is 32 then t2 must be 'foo[32]' |
| 367 | */ |
| 368 | #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) |
| 369 | #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) |
| 370 | /* |
| 371 | * type of element 0 of the specified (array) field of the type. |
| 372 | * Note that if the field is a pointer then this will return the |
| 373 | * pointed-to type rather than complaining. |
| 374 | */ |
| 375 | #define typeof_elt_of_field(type, field) typeof(((type *)0)->field[0]) |
| 376 | /* Check that field f in struct type t2 is an array of t1, of any size */ |
| 377 | #define type_check_varray(t1, t2, f) \ |
| 378 | (type_check(t1, typeof_elt_of_field(t2, f)) \ |
| 379 | + QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(((t2 *)0)->f))) |
| 380 | |
| 381 | #define type_check_int64(t) \ |
| 382 | (~((t)0) * sizeof(struct { \ |
| 383 | QEMU_BUILD_BUG_ON(sizeof(t) > sizeof(uint64_t)); \ |
| 384 | })) |
| 385 | |
| 386 | #define vmstate_field_offset(_state, _field) { \ |
| 387 | .offset = (offsetof(_state, _field) + \ |
| 388 | type_check_int64(typeof_field(_state, _field))), \ |
| 389 | .size = sizeof(typeof_field(_state, _field)), \ |
| 390 | } |
| 391 | |
| 392 | #define vmstate_offset_value(_state, _field, _type) \ |
| 393 | (offsetof(_state, _field) + \ |
| 394 | type_check(_type, typeof_field(_state, _field))) |
| 395 | |
| 396 | #define vmstate_offset_pointer(_state, _field, _type) \ |
| 397 | (offsetof(_state, _field) + \ |
| 398 | type_check_pointer(_type, typeof_field(_state, _field))) |
| 399 | |
| 400 | #define vmstate_offset_array(_state, _field, _type, _num) \ |
| 401 | (offsetof(_state, _field) + \ |
| 402 | type_check_array(_type, typeof_field(_state, _field), _num)) |
| 403 | |
| 404 | #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \ |
| 405 | (offsetof(_state, _field) + \ |
| 406 | type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2)) |
| 407 | |
| 408 | #define vmstate_offset_sub_array(_state, _field, _type, _start) \ |
| 409 | vmstate_offset_value(_state, _field[_start], _type) |
| 410 | |
| 411 | #define vmstate_offset_buffer(_state, _field) \ |
| 412 | vmstate_offset_array(_state, _field, uint8_t, \ |
| 413 | sizeof(typeof_field(_state, _field))) |
| 414 | |
| 415 | #define vmstate_offset_varray(_state, _field, _type) \ |
| 416 | (offsetof(_state, _field) + \ |
| 417 | type_check_varray(_type, _state, _field)) |
| 418 | |
| 419 | /* In the macros below, if there is a _version, that means the macro's |
| 420 | * field will be processed only if the version being received is >= |
| 421 | * the _version specified. In general, if you add a new field, you |
| 422 | * would increment the structure's version and put that version |
| 423 | * number into the new field so it would only be processed with the |
| 424 | * new version. |
| 425 | * |
| 426 | * In particular, for VMSTATE_STRUCT() and friends the _version does |
| 427 | * *NOT* pick the version of the sub-structure. It works just as |
| 428 | * specified above. The version of the top-level structure received |
| 429 | * is passed down to all sub-structures. This means that the |
| 430 | * sub-structures must have version that are compatible with all the |
| 431 | * structures that use them. |
| 432 | * |
| 433 | * If you want to specify the version of the sub-structure, use |
| 434 | * VMSTATE_VSTRUCT(), which allows the specific sub-structure version |
| 435 | * to be directly specified. |
| 436 | */ |
| 437 | |
| 438 | #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ |
| 439 | .name = (stringify(_field)), \ |
| 440 | .version_id = (_version), \ |
| 441 | .field_exists = (_test), \ |
| 442 | .size = sizeof(_type), \ |
| 443 | .info = &(_info), \ |
| 444 | .flags = VMS_SINGLE, \ |
| 445 | .offset = vmstate_offset_value(_state, _field, _type), \ |
| 446 | } |
| 447 | |
| 448 | #define VMSTATE_SINGLE_FULL(_field, _state, _test, _version, _info, \ |
| 449 | _type) { \ |
| 450 | .name = (stringify(_field)), \ |
| 451 | .version_id = (_version), \ |
| 452 | .field_exists = (_test), \ |
| 453 | .size = sizeof(_type), \ |
| 454 | .info = &(_info), \ |
| 455 | .flags = VMS_SINGLE, \ |
| 456 | .offset = vmstate_offset_value(_state, _field, _type), \ |
| 457 | } |
| 458 | |
| 459 | /* Validate state using a boolean predicate. */ |
| 460 | #define VMSTATE_VALIDATE(_name, _test) { \ |
| 461 | .name = (_name), \ |
| 462 | .field_exists = (_test), \ |
| 463 | .flags = VMS_MUST_EXIST | VMS_NO_STATE, \ |
| 464 | } |
| 465 | |
| 466 | #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ |
| 467 | .name = (stringify(_field)), \ |
| 468 | .version_id = (_version), \ |
| 469 | .info = &(_info), \ |
| 470 | .size = sizeof(_type), \ |
| 471 | .flags = VMS_SINGLE|VMS_POINTER, \ |
| 472 | .offset = vmstate_offset_value(_state, _field, _type), \ |
| 473 | } |
| 474 | |
| 475 | #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \ |
| 476 | .name = (stringify(_field)), \ |
| 477 | .info = &(_info), \ |
| 478 | .field_exists = (_test), \ |
| 479 | .size = sizeof(_type), \ |
| 480 | .flags = VMS_SINGLE|VMS_POINTER, \ |
| 481 | .offset = vmstate_offset_value(_state, _field, _type), \ |
| 482 | } |
| 483 | |
| 484 | #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\ |
| 485 | .name = (stringify(_field)), \ |
| 486 | .version_id = (_version), \ |
| 487 | .num = (_num), \ |
| 488 | .info = &(_info), \ |
| 489 | .size = sizeof(_type), \ |
| 490 | .flags = VMS_ARRAY, \ |
| 491 | .offset = vmstate_offset_array(_state, _field, _type, _num), \ |
| 492 | } |
| 493 | |
| 494 | #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \ |
| 495 | .name = (stringify(_field)), \ |
| 496 | .version_id = (_version), \ |
| 497 | .num = (_n1) * (_n2), \ |
| 498 | .info = &(_info), \ |
| 499 | .size = sizeof(_type), \ |
| 500 | .flags = VMS_ARRAY, \ |
| 501 | .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \ |
| 502 | } |
| 503 | |
| 504 | #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \ |
| 505 | .name = (stringify(_field)), \ |
| 506 | .version_id = (_version), \ |
| 507 | .num = (_num), \ |
| 508 | .info = &(_info), \ |
| 509 | .size = sizeof(_type), \ |
| 510 | .flags = VMS_ARRAY, \ |
| 511 | .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ |
| 512 | } |
| 513 | |
| 514 | #define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type) {\ |
| 515 | .name = (stringify(_field)), \ |
| 516 | .version_id = (_version), \ |
| 517 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 518 | .info = &(_info), \ |
| 519 | .size = sizeof(_type), \ |
| 520 | .flags = VMS_VARRAY | VMS_POINTER, \ |
| 521 | .offset = vmstate_offset_pointer(_state, _field, _type), \ |
| 522 | } |
| 523 | |
| 524 | #define VMSTATE_VARRAY_INT32 VMSTATE_VARRAY |
| 525 | #define VMSTATE_VARRAY_UINT32 VMSTATE_VARRAY |
| 526 | |
| 527 | #define VMSTATE_VARRAY_ALLOC(_field, _state, _field_num, _version, _info, \ |
| 528 | _type) { \ |
| 529 | .name = (stringify(_field)), \ |
| 530 | .version_id = (_version), \ |
| 531 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 532 | .info = &(_info), \ |
| 533 | .size = sizeof(_type), \ |
| 534 | .flags = VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ |
| 535 | .offset = vmstate_offset_pointer(_state, _field, _type), \ |
| 536 | } |
| 537 | |
| 538 | #define VMSTATE_VARRAY_INT32_ALLOC VMSTATE_VARRAY_ALLOC |
| 539 | #define VMSTATE_VARRAY_UINT32_ALLOC VMSTATE_VARRAY_ALLOC |
| 540 | #define VMSTATE_VARRAY_UINT16_ALLOC VMSTATE_VARRAY_ALLOC |
| 541 | |
| 542 | #define VMSTATE_VARRAY_UNSAFE(_field, _state, _field_num, _version, _info, \ |
| 543 | _type) { \ |
| 544 | .name = (stringify(_field)), \ |
| 545 | .version_id = (_version), \ |
| 546 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 547 | .info = &(_info), \ |
| 548 | .size = sizeof(_type), \ |
| 549 | .flags = VMS_VARRAY, \ |
| 550 | .offset = vmstate_offset_varray(_state, _field, _type), \ |
| 551 | } |
| 552 | |
| 553 | #define VMSTATE_VARRAY_UINT16_UNSAFE VMSTATE_VARRAY_UNSAFE |
| 554 | |
| 555 | #define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \ |
| 556 | .name = (stringify(_field)), \ |
| 557 | .version_id = (_version), \ |
| 558 | .struct_version_id = (_struct_version), \ |
| 559 | .field_exists = (_test), \ |
| 560 | .vmsd = &(_vmsd), \ |
| 561 | .size = sizeof(_type), \ |
| 562 | .flags = VMS_VSTRUCT, \ |
| 563 | .offset = vmstate_offset_value(_state, _field, _type), \ |
| 564 | } |
| 565 | |
| 566 | #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ |
| 567 | .name = (stringify(_field)), \ |
| 568 | .version_id = (_version), \ |
| 569 | .field_exists = (_test), \ |
| 570 | .vmsd = &(_vmsd), \ |
| 571 | .size = sizeof(_type), \ |
| 572 | .flags = VMS_STRUCT, \ |
| 573 | .offset = vmstate_offset_value(_state, _field, _type), \ |
| 574 | } |
| 575 | |
| 576 | #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \ |
| 577 | .name = (stringify(_field)), \ |
| 578 | .version_id = (_version), \ |
| 579 | .vmsd = &(_vmsd), \ |
| 580 | .size = sizeof(_type *), \ |
| 581 | .flags = VMS_STRUCT|VMS_POINTER, \ |
| 582 | .offset = vmstate_offset_pointer(_state, _field, _type), \ |
| 583 | } |
| 584 | |
| 585 | #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \ |
| 586 | .name = (stringify(_field)), \ |
| 587 | .version_id = (_version), \ |
| 588 | .field_exists = (_test), \ |
| 589 | .vmsd = &(_vmsd), \ |
| 590 | .size = sizeof(_type *), \ |
| 591 | .flags = VMS_STRUCT|VMS_POINTER, \ |
| 592 | .offset = vmstate_offset_pointer(_state, _field, _type), \ |
| 593 | } |
| 594 | |
| 595 | #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\ |
| 596 | .name = (stringify(_field)), \ |
| 597 | .version_id = (_version), \ |
| 598 | .num = (_num), \ |
| 599 | .info = &(_info), \ |
| 600 | .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ |
| 601 | .offset = vmstate_offset_array(_state, _field, _type *, _num), \ |
| 602 | } |
| 603 | |
| 604 | #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \ |
| 605 | .name = (stringify(_f)), \ |
| 606 | .version_id = (_v), \ |
| 607 | .num = (_n), \ |
| 608 | .vmsd = &(_vmsd), \ |
| 609 | .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \ |
| 610 | .offset = vmstate_offset_array(_s, _f, _type*, _n), \ |
| 611 | } |
| 612 | |
| 613 | /* |
| 614 | * For migrating a dynamically allocated uint{8,32}-indexed array of |
| 615 | * pointers to structures (with NULL entries and with auto memory |
| 616 | * allocation). |
| 617 | * |
| 618 | * _type: type of structure pointed to |
| 619 | * _vmsd: VMSD for structure _type (when VMS_STRUCT is set) |
| 620 | * _info: VMStateInfo for _type (when VMS_STRUCT is not set) |
| 621 | * start: size of (_type) pointed to (for auto memory allocation) |
| 622 | */ |
| 623 | #define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC( \ |
| 624 | _field, _state, _field_num, _version, _vmsd, _type) { \ |
| 625 | .name = (stringify(_field)), \ |
| 626 | .version_id = (_version), \ |
| 627 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 628 | .vmsd = &(_vmsd), \ |
| 629 | .size = sizeof(_type), \ |
| 630 | .flags = VMS_POINTER | VMS_VARRAY | \ |
| 631 | VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ |
| 632 | VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ |
| 633 | .offset = vmstate_offset_pointer(_state, _field, _type *), \ |
| 634 | } |
| 635 | |
| 636 | #define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT8_ALLOC \ |
| 637 | VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC |
| 638 | #define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC \ |
| 639 | VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC |
| 640 | |
| 641 | #define VMSTATE_VARRAY_OF_POINTER(_field, _state, _field_num, _version, _info, \ |
| 642 | _type) { \ |
| 643 | .name = (stringify(_field)), \ |
| 644 | .version_id = (_version), \ |
| 645 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 646 | .info = &(_info), \ |
| 647 | .flags = VMS_VARRAY | VMS_ARRAY_OF_POINTER | VMS_POINTER, \ |
| 648 | .offset = vmstate_offset_pointer(_state, _field, _type *), \ |
| 649 | } |
| 650 | |
| 651 | #define VMSTATE_VARRAY_OF_POINTER_UINT32 VMSTATE_VARRAY_OF_POINTER |
| 652 | |
| 653 | #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \ |
| 654 | .name = (stringify(_field)), \ |
| 655 | .version_id = (_version), \ |
| 656 | .num = (_num), \ |
| 657 | .vmsd = &(_vmsd), \ |
| 658 | .size = sizeof(_type), \ |
| 659 | .flags = VMS_STRUCT|VMS_ARRAY, \ |
| 660 | .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ |
| 661 | } |
| 662 | |
| 663 | #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \ |
| 664 | .name = (stringify(_field)), \ |
| 665 | .num = (_num), \ |
| 666 | .field_exists = (_test), \ |
| 667 | .version_id = (_version), \ |
| 668 | .vmsd = &(_vmsd), \ |
| 669 | .size = sizeof(_type), \ |
| 670 | .flags = VMS_STRUCT|VMS_ARRAY, \ |
| 671 | .offset = vmstate_offset_array(_state, _field, _type, _num),\ |
| 672 | } |
| 673 | |
| 674 | #define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \ |
| 675 | _version, _vmsd, _type) { \ |
| 676 | .name = (stringify(_field)), \ |
| 677 | .num = (_n1) * (_n2), \ |
| 678 | .field_exists = (_test), \ |
| 679 | .version_id = (_version), \ |
| 680 | .vmsd = &(_vmsd), \ |
| 681 | .size = sizeof(_type), \ |
| 682 | .flags = VMS_STRUCT | VMS_ARRAY, \ |
| 683 | .offset = vmstate_offset_2darray(_state, _field, _type, \ |
| 684 | _n1, _n2), \ |
| 685 | } |
| 686 | |
| 687 | #define VMSTATE_STRUCT_VARRAY(_field, _state, _field_num, _version, _vmsd, \ |
| 688 | _type) { \ |
| 689 | .name = (stringify(_field)), \ |
| 690 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 691 | .version_id = (_version), \ |
| 692 | .vmsd = &(_vmsd), \ |
| 693 | .size = sizeof(_type), \ |
| 694 | .flags = VMS_STRUCT | VMS_VARRAY, \ |
| 695 | .offset = vmstate_offset_varray(_state, _field, _type), \ |
| 696 | } |
| 697 | #define VMSTATE_STRUCT_VARRAY_UINT8 VMSTATE_STRUCT_VARRAY |
| 698 | |
| 699 | /* a variable length array (i.e. _type *_field) but we know the |
| 700 | * length |
| 701 | */ |
| 702 | #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \ |
| 703 | .name = (stringify(_field)), \ |
| 704 | .num = (_num), \ |
| 705 | .version_id = (_version), \ |
| 706 | .vmsd = &(_vmsd), \ |
| 707 | .size = sizeof(_type), \ |
| 708 | .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \ |
| 709 | .offset = offsetof(_state, _field), \ |
| 710 | } |
| 711 | |
| 712 | #define VMSTATE_STRUCT_VARRAY_POINTER(_field, _state, _field_num, _vmsd, \ |
| 713 | _type) { \ |
| 714 | .name = (stringify(_field)), \ |
| 715 | .version_id = 0, \ |
| 716 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 717 | .size = sizeof(_type), \ |
| 718 | .vmsd = &(_vmsd), \ |
| 719 | .flags = VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ |
| 720 | .offset = vmstate_offset_pointer(_state, _field, _type), \ |
| 721 | } |
| 722 | #define VMSTATE_STRUCT_VARRAY_POINTER_INT32 VMSTATE_STRUCT_VARRAY_POINTER |
| 723 | #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32 VMSTATE_STRUCT_VARRAY_POINTER |
| 724 | #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16 VMSTATE_STRUCT_VARRAY_POINTER |
| 725 | |
| 726 | #define VMSTATE_STRUCT_VARRAY(_field, _state, _field_num, _version, _vmsd, \ |
| 727 | _type) { \ |
| 728 | .name = (stringify(_field)), \ |
| 729 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 730 | .version_id = (_version), \ |
| 731 | .vmsd = &(_vmsd), \ |
| 732 | .size = sizeof(_type), \ |
| 733 | .flags = VMS_STRUCT | VMS_VARRAY, \ |
| 734 | .offset = vmstate_offset_varray(_state, _field, _type), \ |
| 735 | } |
| 736 | #define VMSTATE_STRUCT_VARRAY_INT32 VMSTATE_STRUCT_VARRAY |
| 737 | #define VMSTATE_STRUCT_VARRAY_UINT32 VMSTATE_STRUCT_VARRAY |
| 738 | |
| 739 | #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, \ |
| 740 | _vmsd, _type) { \ |
| 741 | .name = (stringify(_field)), \ |
| 742 | .version_id = (_version), \ |
| 743 | .vmsd = &(_vmsd), \ |
| 744 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 745 | .size = sizeof(_type), \ |
| 746 | .flags = VMS_STRUCT | VMS_VARRAY | VMS_ALLOC | VMS_POINTER, \ |
| 747 | .offset = vmstate_offset_pointer(_state, _field, _type), \ |
| 748 | } |
| 749 | |
| 750 | #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \ |
| 751 | .name = (stringify(_field)), \ |
| 752 | .version_id = (_version), \ |
| 753 | .field_exists = (_test), \ |
| 754 | .size = (_size - _start), \ |
| 755 | .info = &vmstate_info_buffer, \ |
| 756 | .flags = VMS_BUFFER, \ |
| 757 | .offset = vmstate_offset_buffer(_state, _field) + _start, \ |
| 758 | } |
| 759 | |
| 760 | #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \ |
| 761 | _field_size, _multiply) { \ |
| 762 | .name = (stringify(_field)), \ |
| 763 | .version_id = (_version), \ |
| 764 | .field_exists = (_test), \ |
| 765 | .size_indirect = vmstate_field_offset(_state, _field_size), \ |
| 766 | .size = (_multiply), \ |
| 767 | .info = &vmstate_info_buffer, \ |
| 768 | .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ |
| 769 | .offset = offsetof(_state, _field), \ |
| 770 | } |
| 771 | |
| 772 | #define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \ |
| 773 | .name = (stringify(_field)), \ |
| 774 | .version_id = (_version), \ |
| 775 | .field_exists = (_test), \ |
| 776 | .size_indirect = vmstate_field_offset(_state, _field_size), \ |
| 777 | .info = &vmstate_info_buffer, \ |
| 778 | .flags = VMS_VBUFFER|VMS_POINTER, \ |
| 779 | .offset = offsetof(_state, _field), \ |
| 780 | } |
| 781 | |
| 782 | #define VMSTATE_VBUFFER_UINT32 VMSTATE_VBUFFER |
| 783 | #define VMSTATE_VBUFFER_UINT64 VMSTATE_VBUFFER |
| 784 | |
| 785 | #define VMSTATE_VBUFFER_ALLOC(_field, _state, _version, \ |
| 786 | _test, _field_size) { \ |
| 787 | .name = (stringify(_field)), \ |
| 788 | .version_id = (_version), \ |
| 789 | .field_exists = (_test), \ |
| 790 | .size_indirect = vmstate_field_offset(_state, _field_size), \ |
| 791 | .info = &vmstate_info_buffer, \ |
| 792 | .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ |
| 793 | .offset = offsetof(_state, _field), \ |
| 794 | } |
| 795 | |
| 796 | #define VMSTATE_VBUFFER_ALLOC_UINT32 VMSTATE_VBUFFER_ALLOC |
| 797 | |
| 798 | #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \ |
| 799 | .name = (stringify(_field)), \ |
| 800 | .version_id = (_version), \ |
| 801 | .field_exists = (_test), \ |
| 802 | .size = (_size), \ |
| 803 | .info = &(_info), \ |
| 804 | .flags = VMS_BUFFER, \ |
| 805 | .offset = offsetof(_state, _field), \ |
| 806 | } |
| 807 | |
| 808 | #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \ |
| 809 | .name = (stringify(_field)), \ |
| 810 | .version_id = (_version), \ |
| 811 | .size = (_size), \ |
| 812 | .info = &vmstate_info_buffer, \ |
| 813 | .flags = VMS_BUFFER | VMS_POINTER, \ |
| 814 | .offset = offsetof(_state, _field), \ |
| 815 | } |
| 816 | |
| 817 | /* Allocate a temporary of type 'tmp_type', set tmp->parent to _state |
| 818 | * and execute the vmsd on the temporary. Note that we're working with |
| 819 | * the whole of _state here, not a field within it. |
| 820 | * We compile time check that: |
| 821 | * That _tmp_type contains a 'parent' member that's a pointer to the |
| 822 | * '_state' type |
| 823 | * That the pointer is right at the start of _tmp_type. |
| 824 | */ |
| 825 | #define VMSTATE_WITH_TMP_TEST(_state, _test, _tmp_type, _vmsd) { \ |
| 826 | .name = "tmp", \ |
| 827 | .field_exists = (_test), \ |
| 828 | .size = sizeof(_tmp_type) + \ |
| 829 | QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \ |
| 830 | type_check_pointer(_state, \ |
| 831 | typeof_field(_tmp_type, parent)), \ |
| 832 | .vmsd = &(_vmsd), \ |
| 833 | .info = &vmstate_info_tmp, \ |
| 834 | } |
| 835 | |
| 836 | #define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) \ |
| 837 | VMSTATE_WITH_TMP_TEST(_state, NULL, _tmp_type, _vmsd) |
| 838 | |
| 839 | #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ |
| 840 | .name = "unused", \ |
| 841 | .field_exists = (_test), \ |
| 842 | .version_id = (_version), \ |
| 843 | .size = (_size), \ |
| 844 | .info = &vmstate_info_unused_buffer, \ |
| 845 | .flags = VMS_BUFFER, \ |
| 846 | } |
| 847 | |
| 848 | /* Discard size * field_num bytes, where field_num is a uint32 member */ |
| 849 | #define VMSTATE_UNUSED_VARRAY(_state, _test, _version, _field_num, _size) {\ |
| 850 | .name = "unused", \ |
| 851 | .field_exists = (_test), \ |
| 852 | .num_indirect = vmstate_field_offset(_state, _field_num), \ |
| 853 | .version_id = (_version), \ |
| 854 | .size = (_size), \ |
| 855 | .info = &vmstate_info_unused_buffer, \ |
| 856 | .flags = VMS_VARRAY | VMS_BUFFER, \ |
| 857 | } |
| 858 | |
| 859 | #define VMSTATE_UNUSED_VARRAY_UINT32 VMSTATE_UNUSED_VARRAY |
| 860 | |
| 861 | /* _field_size should be a int32_t field in the _state struct giving the |
| 862 | * size of the bitmap _field in bits. |
| 863 | */ |
| 864 | #define VMSTATE_BITMAP_TEST(_field, _state, _test, _version, _field_size) { \ |
| 865 | .name = (stringify(_field)), \ |
| 866 | .field_exists = (_test), \ |
| 867 | .version_id = (_version), \ |
| 868 | .size_indirect = vmstate_field_offset(_state, _field_size), \ |
| 869 | .info = &vmstate_info_bitmap, \ |
| 870 | .flags = VMS_VBUFFER|VMS_POINTER, \ |
| 871 | .offset = offsetof(_state, _field), \ |
| 872 | } |
| 873 | |
| 874 | #define VMSTATE_BITMAP(_field, _state, _version, _field_size) \ |
| 875 | VMSTATE_BITMAP_TEST(_field, _state, NULL, _version, _field_size) |
| 876 | |
| 877 | /* For migrating a QTAILQ. |
| 878 | * Target QTAILQ needs be properly initialized. |
| 879 | * _type: type of QTAILQ element |
| 880 | * _next: name of QTAILQ entry field in QTAILQ element |
| 881 | * _vmsd: VMSD for QTAILQ element |
| 882 | * size: size of QTAILQ element |
| 883 | * start: offset of QTAILQ entry in QTAILQ element |
| 884 | */ |
| 885 | #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \ |
| 886 | { \ |
| 887 | .name = (stringify(_field)), \ |
| 888 | .version_id = (_version), \ |
| 889 | .vmsd = &(_vmsd), \ |
| 890 | .size = sizeof(_type), \ |
| 891 | .info = &vmstate_info_qtailq, \ |
| 892 | .offset = offsetof(_state, _field), \ |
| 893 | .start = offsetof(_type, _next), \ |
| 894 | } |
| 895 | |
| 896 | /* |
| 897 | * For migrating a GTree whose key is a pointer to _key_type and the |
| 898 | * value, a pointer to _val_type |
| 899 | * The target tree must have been properly initialized |
| 900 | * _vmsd: Start address of the 2 element array containing the data vmsd |
| 901 | * and the key vmsd, in that order |
| 902 | * _key_type: type of the key |
| 903 | * _val_type: type of the value |
| 904 | */ |
| 905 | #define VMSTATE_GTREE_V(_field, _state, _version, _vmsd, \ |
| 906 | _key_type, _val_type) \ |
| 907 | { \ |
| 908 | .name = (stringify(_field)), \ |
| 909 | .version_id = (_version), \ |
| 910 | .vmsd = (_vmsd), \ |
| 911 | .info = &vmstate_info_gtree, \ |
| 912 | .start = sizeof(_key_type), \ |
| 913 | .size = sizeof(_val_type), \ |
| 914 | .offset = offsetof(_state, _field), \ |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | * For migrating a GTree with direct key and the value a pointer |
| 919 | * to _val_type |
| 920 | * The target tree must have been properly initialized |
| 921 | * _vmsd: data vmsd |
| 922 | * _val_type: type of the value |
| 923 | */ |
| 924 | #define VMSTATE_GTREE_DIRECT_KEY_V(_field, _state, _version, _vmsd, _val_type) \ |
| 925 | { \ |
| 926 | .name = (stringify(_field)), \ |
| 927 | .version_id = (_version), \ |
| 928 | .vmsd = (_vmsd), \ |
| 929 | .info = &vmstate_info_gtree, \ |
| 930 | .start = 0, \ |
| 931 | .size = sizeof(_val_type), \ |
| 932 | .offset = offsetof(_state, _field), \ |
| 933 | } |
| 934 | |
| 935 | /* |
| 936 | * For migrating a QLIST |
| 937 | * Target QLIST needs be properly initialized. |
| 938 | * _type: type of QLIST element |
| 939 | * _next: name of QLIST_ENTRY entry field in QLIST element |
| 940 | * _vmsd: VMSD for QLIST element |
| 941 | * size: size of QLIST element |
| 942 | * start: offset of QLIST_ENTRY in QTAILQ element |
| 943 | */ |
| 944 | #define VMSTATE_QLIST_V(_field, _state, _version, _vmsd, _type, _next) \ |
| 945 | { \ |
| 946 | .name = (stringify(_field)), \ |
| 947 | .version_id = (_version), \ |
| 948 | .vmsd = &(_vmsd), \ |
| 949 | .size = sizeof(_type), \ |
| 950 | .info = &vmstate_info_qlist, \ |
| 951 | .offset = offsetof(_state, _field), \ |
| 952 | .start = offsetof(_type, _next), \ |
| 953 | } |
| 954 | |
| 955 | #define VMSTATE_GBYTEARRAY(_field, _state, _version) { \ |
| 956 | .name = (stringify(_field)), \ |
| 957 | .version_id = (_version), \ |
| 958 | .size = sizeof(GByteArray), \ |
| 959 | .info = &vmstate_info_g_byte_array, \ |
| 960 | .flags = VMS_SINGLE, \ |
| 961 | .offset = vmstate_offset_pointer(_state, _field, GByteArray), \ |
| 962 | } |
| 963 | |
| 964 | /* _f : field name |
| 965 | _f_n : num of elements field_name |
| 966 | _n : num of elements |
| 967 | _s : struct state name |
| 968 | _v : version |
| 969 | */ |
| 970 | |
| 971 | #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ |
| 972 | VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) |
| 973 | |
| 974 | #define VMSTATE_VSTRUCT(_field, _state, _vmsd, _type, _struct_version)\ |
| 975 | VMSTATE_VSTRUCT_TEST(_field, _state, NULL, 0, _vmsd, _type, _struct_version) |
| 976 | |
| 977 | #define VMSTATE_VSTRUCT_V(_field, _state, _version, _vmsd, _type, _struct_version) \ |
| 978 | VMSTATE_VSTRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type, \ |
| 979 | _struct_version) |
| 980 | |
| 981 | #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ |
| 982 | VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) |
| 983 | |
| 984 | #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ |
| 985 | VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type) |
| 986 | |
| 987 | #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \ |
| 988 | VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type) |
| 989 | |
| 990 | #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ |
| 991 | VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \ |
| 992 | _vmsd, _type) |
| 993 | |
| 994 | #define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \ |
| 995 | _vmsd, _type) \ |
| 996 | VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \ |
| 997 | _version, _vmsd, _type) |
| 998 | |
| 999 | #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \ |
| 1000 | VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \ |
| 1001 | _size) |
| 1002 | |
| 1003 | #define VMSTATE_BOOL_V(_f, _s, _v) \ |
| 1004 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) |
| 1005 | |
| 1006 | #define VMSTATE_INT8_V(_f, _s, _v) \ |
| 1007 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) |
| 1008 | #define VMSTATE_INT16_V(_f, _s, _v) \ |
| 1009 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) |
| 1010 | #define VMSTATE_INT32_V(_f, _s, _v) \ |
| 1011 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) |
| 1012 | #define VMSTATE_INT64_V(_f, _s, _v) \ |
| 1013 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) |
| 1014 | |
| 1015 | #define VMSTATE_UINT8_V(_f, _s, _v) \ |
| 1016 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) |
| 1017 | #define VMSTATE_UINT16_V(_f, _s, _v) \ |
| 1018 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) |
| 1019 | #define VMSTATE_UINT32_V(_f, _s, _v) \ |
| 1020 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) |
| 1021 | #define VMSTATE_UINT64_V(_f, _s, _v) \ |
| 1022 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) |
| 1023 | |
| 1024 | #define VMSTATE_FD_V(_f, _s, _v) \ |
| 1025 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_fd, int32_t) |
| 1026 | |
| 1027 | #ifdef CONFIG_LINUX |
| 1028 | |
| 1029 | #define VMSTATE_U8_V(_f, _s, _v) \ |
| 1030 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, __u8) |
| 1031 | #define VMSTATE_U16_V(_f, _s, _v) \ |
| 1032 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, __u16) |
| 1033 | #define VMSTATE_U32_V(_f, _s, _v) \ |
| 1034 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, __u32) |
| 1035 | #define VMSTATE_U64_V(_f, _s, _v) \ |
| 1036 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, __u64) |
| 1037 | |
| 1038 | #endif |
| 1039 | |
| 1040 | #define VMSTATE_BOOL(_f, _s) \ |
| 1041 | VMSTATE_BOOL_V(_f, _s, 0) |
| 1042 | |
| 1043 | #define VMSTATE_INT8(_f, _s) \ |
| 1044 | VMSTATE_INT8_V(_f, _s, 0) |
| 1045 | #define VMSTATE_INT16(_f, _s) \ |
| 1046 | VMSTATE_INT16_V(_f, _s, 0) |
| 1047 | #define VMSTATE_INT32(_f, _s) \ |
| 1048 | VMSTATE_INT32_V(_f, _s, 0) |
| 1049 | #define VMSTATE_INT64(_f, _s) \ |
| 1050 | VMSTATE_INT64_V(_f, _s, 0) |
| 1051 | |
| 1052 | #define VMSTATE_UINT8(_f, _s) \ |
| 1053 | VMSTATE_UINT8_V(_f, _s, 0) |
| 1054 | #define VMSTATE_UINT16(_f, _s) \ |
| 1055 | VMSTATE_UINT16_V(_f, _s, 0) |
| 1056 | #define VMSTATE_UINT32(_f, _s) \ |
| 1057 | VMSTATE_UINT32_V(_f, _s, 0) |
| 1058 | #define VMSTATE_UINT64(_f, _s) \ |
| 1059 | VMSTATE_UINT64_V(_f, _s, 0) |
| 1060 | |
| 1061 | #define VMSTATE_FD(_f, _s) \ |
| 1062 | VMSTATE_FD_V(_f, _s, 0) |
| 1063 | |
| 1064 | #ifdef CONFIG_LINUX |
| 1065 | |
| 1066 | #define VMSTATE_U16(_f, _s) \ |
| 1067 | VMSTATE_U16_V(_f, _s, 0) |
| 1068 | #define VMSTATE_U32(_f, _s) \ |
| 1069 | VMSTATE_U32_V(_f, _s, 0) |
| 1070 | #define VMSTATE_U64(_f, _s) \ |
| 1071 | VMSTATE_U64_V(_f, _s, 0) |
| 1072 | |
| 1073 | #endif |
| 1074 | |
| 1075 | #define VMSTATE_UINT8_EQUAL(_f, _s) \ |
| 1076 | VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \ |
| 1077 | vmstate_info_uint8_equal, uint8_t) |
| 1078 | |
| 1079 | #define VMSTATE_UINT16_EQUAL(_f, _s) \ |
| 1080 | VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \ |
| 1081 | vmstate_info_uint16_equal, uint16_t) |
| 1082 | |
| 1083 | #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \ |
| 1084 | VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \ |
| 1085 | vmstate_info_uint16_equal, uint16_t) |
| 1086 | |
| 1087 | #define VMSTATE_INT32_EQUAL(_f, _s) \ |
| 1088 | VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \ |
| 1089 | vmstate_info_int32_equal, int32_t) |
| 1090 | |
| 1091 | #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \ |
| 1092 | VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \ |
| 1093 | vmstate_info_uint32_equal, uint32_t) |
| 1094 | |
| 1095 | #define VMSTATE_UINT32_EQUAL(_f, _s) \ |
| 1096 | VMSTATE_UINT32_EQUAL_V(_f, _s, 0) |
| 1097 | |
| 1098 | #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \ |
| 1099 | VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \ |
| 1100 | vmstate_info_uint64_equal, uint64_t) |
| 1101 | |
| 1102 | #define VMSTATE_UINT64_EQUAL(_f, _s) \ |
| 1103 | VMSTATE_UINT64_EQUAL_V(_f, _s, 0) |
| 1104 | |
| 1105 | #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \ |
| 1106 | VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) |
| 1107 | |
| 1108 | #define VMSTATE_BOOL_TEST(_f, _s, _t) \ |
| 1109 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool) |
| 1110 | |
| 1111 | #define VMSTATE_INT64_TEST(_f, _s, _t) \ |
| 1112 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) |
| 1113 | |
| 1114 | #define VMSTATE_UINT8_TEST(_f, _s, _t) \ |
| 1115 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) |
| 1116 | |
| 1117 | #define VMSTATE_UINT16_TEST(_f, _s, _t) \ |
| 1118 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) |
| 1119 | |
| 1120 | #define VMSTATE_UINT32_TEST(_f, _s, _t) \ |
| 1121 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) |
| 1122 | |
| 1123 | #define VMSTATE_UINT64_TEST(_f, _s, _t) \ |
| 1124 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) |
| 1125 | |
| 1126 | #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \ |
| 1127 | VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) |
| 1128 | |
| 1129 | #define VMSTATE_TIMER_PTR(_f, _s) \ |
| 1130 | VMSTATE_TIMER_PTR_V(_f, _s, 0) |
| 1131 | |
| 1132 | #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ |
| 1133 | VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) |
| 1134 | |
| 1135 | #define VMSTATE_TIMER_V(_f, _s, _v) \ |
| 1136 | VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer) |
| 1137 | |
| 1138 | #define VMSTATE_TIMER(_f, _s) \ |
| 1139 | VMSTATE_TIMER_V(_f, _s, 0) |
| 1140 | |
| 1141 | #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \ |
| 1142 | VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) |
| 1143 | |
| 1144 | #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \ |
| 1145 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool) |
| 1146 | |
| 1147 | #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \ |
| 1148 | VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0) |
| 1149 | |
| 1150 | #define VMSTATE_BOOL_SUB_ARRAY(_f, _s, _start, _num) \ |
| 1151 | VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_bool, bool) |
| 1152 | |
| 1153 | #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \ |
| 1154 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) |
| 1155 | |
| 1156 | #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \ |
| 1157 | VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t) |
| 1158 | |
| 1159 | #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \ |
| 1160 | VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) |
| 1161 | |
| 1162 | #define VMSTATE_UINT16_SUB_ARRAY(_f, _s, _start, _num) \ |
| 1163 | VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint16, uint16_t) |
| 1164 | |
| 1165 | #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \ |
| 1166 | VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0) |
| 1167 | |
| 1168 | #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \ |
| 1169 | VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t) |
| 1170 | |
| 1171 | #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \ |
| 1172 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) |
| 1173 | |
| 1174 | #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \ |
| 1175 | VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) |
| 1176 | |
| 1177 | #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \ |
| 1178 | VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t) |
| 1179 | |
| 1180 | #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \ |
| 1181 | VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0) |
| 1182 | |
| 1183 | #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \ |
| 1184 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) |
| 1185 | |
| 1186 | #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \ |
| 1187 | VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t) |
| 1188 | |
| 1189 | #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \ |
| 1190 | VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0) |
| 1191 | |
| 1192 | #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \ |
| 1193 | VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t) |
| 1194 | |
| 1195 | #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \ |
| 1196 | VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0) |
| 1197 | |
| 1198 | #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \ |
| 1199 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t) |
| 1200 | |
| 1201 | #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \ |
| 1202 | VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) |
| 1203 | |
| 1204 | #define VMSTATE_UINT64_SUB_ARRAY(_f, _s, _start, _num) \ |
| 1205 | VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint64, uint64_t) |
| 1206 | |
| 1207 | #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \ |
| 1208 | VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0) |
| 1209 | |
| 1210 | #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \ |
| 1211 | VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t) |
| 1212 | |
| 1213 | #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ |
| 1214 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) |
| 1215 | |
| 1216 | #define VMSTATE_INT16_ARRAY(_f, _s, _n) \ |
| 1217 | VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) |
| 1218 | |
| 1219 | #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \ |
| 1220 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) |
| 1221 | |
| 1222 | #define VMSTATE_INT32_ARRAY(_f, _s, _n) \ |
| 1223 | VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0) |
| 1224 | |
| 1225 | #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \ |
| 1226 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t) |
| 1227 | |
| 1228 | #define VMSTATE_INT64_ARRAY(_f, _s, _n) \ |
| 1229 | VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) |
| 1230 | |
| 1231 | #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \ |
| 1232 | VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU) |
| 1233 | |
| 1234 | #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \ |
| 1235 | VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0) |
| 1236 | |
| 1237 | #define VMSTATE_BUFFER_V(_f, _s, _v) \ |
| 1238 | VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) |
| 1239 | |
| 1240 | #define VMSTATE_BUFFER(_f, _s) \ |
| 1241 | VMSTATE_BUFFER_V(_f, _s, 0) |
| 1242 | |
| 1243 | #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \ |
| 1244 | VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size) |
| 1245 | |
| 1246 | #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \ |
| 1247 | VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f))) |
| 1248 | |
| 1249 | #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ |
| 1250 | VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) |
| 1251 | |
| 1252 | #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ |
| 1253 | VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) |
| 1254 | |
| 1255 | #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \ |
| 1256 | VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) |
| 1257 | |
| 1258 | /* |
| 1259 | * These VMSTATE_UNUSED*() macros can be used to fill in the holes |
| 1260 | * when some of the vmstate fields are obsolete to be compatible with |
| 1261 | * migrations between new/old binaries. |
| 1262 | * |
| 1263 | * CAUTION: when using any of the VMSTATE_UNUSED*() macros please be |
| 1264 | * sure that the size passed in is the size that was actually *sent* |
| 1265 | * rather than the size of the *structure*. One example is the |
| 1266 | * boolean type - the size of the structure can vary depending on the |
| 1267 | * definition of boolean, however the size we actually sent is always |
| 1268 | * 1 byte (please refer to implementation of VMSTATE_BOOL_V and |
| 1269 | * vmstate_info_bool). So here we should always pass in size==1 |
| 1270 | * rather than size==sizeof(bool). |
| 1271 | */ |
| 1272 | #define VMSTATE_UNUSED_V(_v, _size) \ |
| 1273 | VMSTATE_UNUSED_BUFFER(NULL, _v, _size) |
| 1274 | |
| 1275 | #define VMSTATE_UNUSED(_size) \ |
| 1276 | VMSTATE_UNUSED_V(0, _size) |
| 1277 | |
| 1278 | #define VMSTATE_UNUSED_TEST(_test, _size) \ |
| 1279 | VMSTATE_UNUSED_BUFFER(_test, 0, _size) |
| 1280 | |
| 1281 | #define VMSTATE_END_OF_LIST() \ |
| 1282 | { \ |
| 1283 | .flags = VMS_END, \ |
| 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * vmstate_load_state() and vmstate_save_state() are |
| 1288 | * depreacated, use vmstate_load_vmsd() and vmstate_save_vmsd() |
| 1289 | * instead. |
| 1290 | */ |
| 1291 | int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, |
| 1292 | void *opaque, int version_id, Error **errp); |
| 1293 | int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, |
| 1294 | void *opaque, JSONWriter *vmdesc, Error **errp); |
| 1295 | bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd, |
| 1296 | void *opaque, int version_id, Error **errp); |
| 1297 | bool vmstate_save_vmsd(QEMUFile *f, const VMStateDescription *vmsd, |
| 1298 | void *opaque, JSONWriter *vmdesc, Error **errp); |
| 1299 | |
| 1300 | bool vmstate_section_needed(const VMStateDescription *vmsd, void *opaque); |
| 1301 | |
| 1302 | #define VMSTATE_INSTANCE_ID_ANY -1 |
| 1303 | |
| 1304 | /* Returns: 0 on success, -1 on failure */ |
| 1305 | int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, |
| 1306 | const VMStateDescription *vmsd, |
| 1307 | void *base, int alias_id, |
| 1308 | int required_for_version, |
| 1309 | Error **errp); |
| 1310 | |
| 1311 | /** |
| 1312 | * vmstate_register() - legacy function to register state |
| 1313 | * serialisation description |
| 1314 | * |
| 1315 | * New code shouldn't be using this function as QOM-ified devices have |
| 1316 | * dc->vmsd to store the serialisation description. |
| 1317 | * |
| 1318 | * Returns: 0 on success, -1 on failure |
| 1319 | */ |
| 1320 | static inline int vmstate_register(VMStateIf *obj, int instance_id, |
| 1321 | const VMStateDescription *vmsd, |
| 1322 | void *opaque) |
| 1323 | { |
| 1324 | return vmstate_register_with_alias_id(obj, instance_id, vmsd, |
| 1325 | opaque, -1, 0, NULL); |
| 1326 | } |
| 1327 | |
| 1328 | /** |
| 1329 | * vmstate_replace_hack_for_ppc() - ppc used to abuse vmstate_register |
| 1330 | * |
| 1331 | * Don't even think about using this function in new code. |
| 1332 | * |
| 1333 | * Returns: 0 on success, -1 on failure |
| 1334 | */ |
| 1335 | int vmstate_replace_hack_for_ppc(VMStateIf *obj, int instance_id, |
| 1336 | const VMStateDescription *vmsd, |
| 1337 | void *opaque); |
| 1338 | |
| 1339 | /** |
| 1340 | * vmstate_register_any() - legacy function to register state |
| 1341 | * serialisation description and let the function choose the id |
| 1342 | * |
| 1343 | * New code shouldn't be using this function as QOM-ified devices have |
| 1344 | * dc->vmsd to store the serialisation description. |
| 1345 | * |
| 1346 | * Returns: 0 on success, -1 on failure |
| 1347 | */ |
| 1348 | static inline int vmstate_register_any(VMStateIf *obj, |
| 1349 | const VMStateDescription *vmsd, |
| 1350 | void *opaque) |
| 1351 | { |
| 1352 | return vmstate_register_with_alias_id(obj, VMSTATE_INSTANCE_ID_ANY, vmsd, |
| 1353 | opaque, -1, 0, NULL); |
| 1354 | } |
| 1355 | |
| 1356 | void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, |
| 1357 | void *opaque); |
| 1358 | |
| 1359 | void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); |
| 1360 | void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); |
| 1361 | void vmstate_register_ram_global(struct MemoryRegion *memory); |
| 1362 | |
| 1363 | bool vmstate_check_only_migratable(const VMStateDescription *vmsd); |
| 1364 | |
| 1365 | #endif |