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