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