1 /* 2 * QEMU migration/snapshot declarations 3 * 4 * Copyright (c) 2009-2011 Red Hat, Inc. 5 * 6 * Original author: Juan Quintela <quintela@redhat.com> 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 */ 26 27 #ifndef QEMU_VMSTATE_H 28 #define QEMU_VMSTATE_H 29 30 #include "migration/qjson.h" 31 32 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); 33 typedef struct VMStateInfo VMStateInfo; 34 typedef struct VMStateDescription VMStateDescription; 35 typedef struct VMStateField VMStateField; 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 get and put 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 get/put. 43 */ 44 struct VMStateInfo { 45 const char *name; 46 int (*get)(QEMUFile *f, void *pv, size_t size, VMStateField *field); 47 int (*put)(QEMUFile *f, void *pv, size_t size, VMStateField *field, 48 QJSON *vmdesc); 49 }; 50 51 enum VMStateFlags { 52 /* Ignored */ 53 VMS_SINGLE = 0x001, 54 55 /* The struct member at opaque + VMStateField.offset is a pointer 56 * to the actual field (e.g. struct a { uint8_t *b; 57 * }). Dereference the pointer before using it as basis for 58 * further pointer arithmetic (see e.g. VMS_ARRAY). Does not 59 * affect the meaning of VMStateField.num_offset or 60 * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for 61 * those. */ 62 VMS_POINTER = 0x002, 63 64 /* The field is an array of fixed size. VMStateField.num contains 65 * the number of entries in the array. The size of each entry is 66 * given by VMStateField.size and / or opaque + 67 * VMStateField.size_offset; see VMS_VBUFFER and 68 * VMS_MULTIPLY. Each array entry will be processed individually 69 * (VMStateField.info.get()/put() if VMS_STRUCT is not set, 70 * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not 71 * be combined with VMS_VARRAY*. */ 72 VMS_ARRAY = 0x004, 73 74 /* The field is itself a struct, containing one or more 75 * fields. Recurse into VMStateField.vmsd. Most useful in 76 * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each 77 * array entry. */ 78 VMS_STRUCT = 0x008, 79 80 /* The field is an array of variable size. The int32_t at opaque + 81 * VMStateField.num_offset contains the number of entries in the 82 * array. See the VMS_ARRAY description regarding array handling 83 * in general. May not be combined with VMS_ARRAY or any other 84 * VMS_VARRAY*. */ 85 VMS_VARRAY_INT32 = 0x010, 86 87 /* Ignored */ 88 VMS_BUFFER = 0x020, 89 90 /* The field is a (fixed-size or variable-size) array of pointers 91 * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry 92 * before using it. Note: Does not imply any one of VMS_ARRAY / 93 * VMS_VARRAY*; these need to be set explicitly. */ 94 VMS_ARRAY_OF_POINTER = 0x040, 95 96 /* The field is an array of variable size. The uint16_t at opaque 97 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) 98 * contains the number of entries in the array. See the VMS_ARRAY 99 * description regarding array handling in general. May not be 100 * combined with VMS_ARRAY or any other VMS_VARRAY*. */ 101 VMS_VARRAY_UINT16 = 0x080, 102 103 /* The size of the individual entries (a single array entry if 104 * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if 105 * neither is set) is variable (i.e. not known at compile-time), 106 * but the same for all entries. Use the int32_t at opaque + 107 * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine 108 * the size of each (and every) entry. */ 109 VMS_VBUFFER = 0x100, 110 111 /* Multiply the entry size given by the int32_t at opaque + 112 * VMStateField.size_offset (see VMS_VBUFFER description) with 113 * VMStateField.size to determine the number of bytes to be 114 * allocated. Only valid in combination with VMS_VBUFFER. */ 115 VMS_MULTIPLY = 0x200, 116 117 /* The field is an array of variable size. The uint8_t at opaque + 118 * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) 119 * contains the number of entries in the array. See the VMS_ARRAY 120 * description regarding array handling in general. May not be 121 * combined with VMS_ARRAY or any other VMS_VARRAY*. */ 122 VMS_VARRAY_UINT8 = 0x400, 123 124 /* The field is an array of variable size. The uint32_t at opaque 125 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) 126 * contains the number of entries in the array. See the VMS_ARRAY 127 * description regarding array handling in general. May not be 128 * combined with VMS_ARRAY or any other VMS_VARRAY*. */ 129 VMS_VARRAY_UINT32 = 0x800, 130 131 /* Fail loading the serialised VM state if this field is missing 132 * from the input. */ 133 VMS_MUST_EXIST = 0x1000, 134 135 /* When loading serialised VM state, allocate memory for the 136 * (entire) field. Only valid in combination with 137 * VMS_POINTER. Note: Not all combinations with other flags are 138 * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't 139 * cause the individual entries to be allocated. */ 140 VMS_ALLOC = 0x2000, 141 142 /* Multiply the number of entries given by the integer at opaque + 143 * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num 144 * to determine the number of entries in the array. Only valid in 145 * combination with one of VMS_VARRAY*. */ 146 VMS_MULTIPLY_ELEMENTS = 0x4000, 147 }; 148 149 typedef enum { 150 MIG_PRI_DEFAULT = 0, 151 MIG_PRI_IOMMU, /* Must happen before PCI devices */ 152 MIG_PRI_GICV3_ITS, /* Must happen before PCI devices */ 153 MIG_PRI_GICV3, /* Must happen before the ITS */ 154 MIG_PRI_MAX, 155 } MigrationPriority; 156 157 struct VMStateField { 158 const char *name; 159 size_t offset; 160 size_t size; 161 size_t start; 162 int num; 163 size_t num_offset; 164 size_t size_offset; 165 const VMStateInfo *info; 166 enum VMStateFlags flags; 167 const VMStateDescription *vmsd; 168 int version_id; 169 bool (*field_exists)(void *opaque, int version_id); 170 }; 171 172 struct VMStateDescription { 173 const char *name; 174 int unmigratable; 175 int version_id; 176 int minimum_version_id; 177 int minimum_version_id_old; 178 MigrationPriority priority; 179 LoadStateHandler *load_state_old; 180 int (*pre_load)(void *opaque); 181 int (*post_load)(void *opaque, int version_id); 182 void (*pre_save)(void *opaque); 183 bool (*needed)(void *opaque); 184 VMStateField *fields; 185 const VMStateDescription **subsections; 186 }; 187 188 extern const VMStateDescription vmstate_dummy; 189 190 extern const VMStateInfo vmstate_info_bool; 191 192 extern const VMStateInfo vmstate_info_int8; 193 extern const VMStateInfo vmstate_info_int16; 194 extern const VMStateInfo vmstate_info_int32; 195 extern const VMStateInfo vmstate_info_int64; 196 197 extern const VMStateInfo vmstate_info_uint8_equal; 198 extern const VMStateInfo vmstate_info_uint16_equal; 199 extern const VMStateInfo vmstate_info_int32_equal; 200 extern const VMStateInfo vmstate_info_uint32_equal; 201 extern const VMStateInfo vmstate_info_uint64_equal; 202 extern const VMStateInfo vmstate_info_int32_le; 203 204 extern const VMStateInfo vmstate_info_uint8; 205 extern const VMStateInfo vmstate_info_uint16; 206 extern const VMStateInfo vmstate_info_uint32; 207 extern const VMStateInfo vmstate_info_uint64; 208 209 /** Put this in the stream when migrating a null pointer.*/ 210 #define VMS_NULLPTR_MARKER (0x30U) /* '0' */ 211 extern const VMStateInfo vmstate_info_nullptr; 212 213 extern const VMStateInfo vmstate_info_float64; 214 extern const VMStateInfo vmstate_info_cpudouble; 215 216 extern const VMStateInfo vmstate_info_timer; 217 extern const VMStateInfo vmstate_info_buffer; 218 extern const VMStateInfo vmstate_info_unused_buffer; 219 extern const VMStateInfo vmstate_info_tmp; 220 extern const VMStateInfo vmstate_info_bitmap; 221 extern const VMStateInfo vmstate_info_qtailq; 222 223 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) 224 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) 225 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) 226 227 #define vmstate_offset_value(_state, _field, _type) \ 228 (offsetof(_state, _field) + \ 229 type_check(_type, typeof_field(_state, _field))) 230 231 #define vmstate_offset_pointer(_state, _field, _type) \ 232 (offsetof(_state, _field) + \ 233 type_check_pointer(_type, typeof_field(_state, _field))) 234 235 #define vmstate_offset_array(_state, _field, _type, _num) \ 236 (offsetof(_state, _field) + \ 237 type_check_array(_type, typeof_field(_state, _field), _num)) 238 239 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \ 240 (offsetof(_state, _field) + \ 241 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2)) 242 243 #define vmstate_offset_sub_array(_state, _field, _type, _start) \ 244 vmstate_offset_value(_state, _field[_start], _type) 245 246 #define vmstate_offset_buffer(_state, _field) \ 247 vmstate_offset_array(_state, _field, uint8_t, \ 248 sizeof(typeof_field(_state, _field))) 249 250 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ 251 .name = (stringify(_field)), \ 252 .version_id = (_version), \ 253 .field_exists = (_test), \ 254 .size = sizeof(_type), \ 255 .info = &(_info), \ 256 .flags = VMS_SINGLE, \ 257 .offset = vmstate_offset_value(_state, _field, _type), \ 258 } 259 260 /* Validate state using a boolean predicate. */ 261 #define VMSTATE_VALIDATE(_name, _test) { \ 262 .name = (_name), \ 263 .field_exists = (_test), \ 264 .flags = VMS_ARRAY | VMS_MUST_EXIST, \ 265 .num = 0, /* 0 elements: no data, only run _test */ \ 266 } 267 268 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ 269 .name = (stringify(_field)), \ 270 .version_id = (_version), \ 271 .info = &(_info), \ 272 .size = sizeof(_type), \ 273 .flags = VMS_SINGLE|VMS_POINTER, \ 274 .offset = vmstate_offset_value(_state, _field, _type), \ 275 } 276 277 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \ 278 .name = (stringify(_field)), \ 279 .info = &(_info), \ 280 .field_exists = (_test), \ 281 .size = sizeof(_type), \ 282 .flags = VMS_SINGLE|VMS_POINTER, \ 283 .offset = vmstate_offset_value(_state, _field, _type), \ 284 } 285 286 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\ 287 .name = (stringify(_field)), \ 288 .version_id = (_version), \ 289 .num = (_num), \ 290 .info = &(_info), \ 291 .size = sizeof(_type), \ 292 .flags = VMS_ARRAY, \ 293 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 294 } 295 296 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \ 297 .name = (stringify(_field)), \ 298 .version_id = (_version), \ 299 .num = (_n1) * (_n2), \ 300 .info = &(_info), \ 301 .size = sizeof(_type), \ 302 .flags = VMS_ARRAY, \ 303 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \ 304 } 305 306 #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \ 307 .name = (stringify(_field)), \ 308 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 309 .num = (_multiply), \ 310 .info = &(_info), \ 311 .size = sizeof(_type), \ 312 .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \ 313 .offset = offsetof(_state, _field), \ 314 } 315 316 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ 317 .name = (stringify(_field)), \ 318 .field_exists = (_test), \ 319 .num = (_num), \ 320 .info = &(_info), \ 321 .size = sizeof(_type), \ 322 .flags = VMS_ARRAY, \ 323 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 324 } 325 326 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \ 327 .name = (stringify(_field)), \ 328 .version_id = (_version), \ 329 .num = (_num), \ 330 .info = &(_info), \ 331 .size = sizeof(_type), \ 332 .flags = VMS_ARRAY, \ 333 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 334 } 335 336 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\ 337 .name = (stringify(_field)), \ 338 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 339 .info = &(_info), \ 340 .size = sizeof(_type), \ 341 .flags = VMS_VARRAY_INT32, \ 342 .offset = offsetof(_state, _field), \ 343 } 344 345 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\ 346 .name = (stringify(_field)), \ 347 .version_id = (_version), \ 348 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 349 .info = &(_info), \ 350 .size = sizeof(_type), \ 351 .flags = VMS_VARRAY_INT32|VMS_POINTER, \ 352 .offset = vmstate_offset_pointer(_state, _field, _type), \ 353 } 354 355 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\ 356 .name = (stringify(_field)), \ 357 .version_id = (_version), \ 358 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 359 .info = &(_info), \ 360 .size = sizeof(_type), \ 361 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \ 362 .offset = vmstate_offset_pointer(_state, _field, _type), \ 363 } 364 365 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\ 366 .name = (stringify(_field)), \ 367 .version_id = (_version), \ 368 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 369 .info = &(_info), \ 370 .size = sizeof(_type), \ 371 .flags = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ 372 .offset = vmstate_offset_pointer(_state, _field, _type), \ 373 } 374 375 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\ 376 .name = (stringify(_field)), \ 377 .version_id = (_version), \ 378 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 379 .info = &(_info), \ 380 .size = sizeof(_type), \ 381 .flags = VMS_VARRAY_UINT16, \ 382 .offset = offsetof(_state, _field), \ 383 } 384 385 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ 386 .name = (stringify(_field)), \ 387 .version_id = (_version), \ 388 .field_exists = (_test), \ 389 .vmsd = &(_vmsd), \ 390 .size = sizeof(_type), \ 391 .flags = VMS_STRUCT, \ 392 .offset = vmstate_offset_value(_state, _field, _type), \ 393 } 394 395 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \ 396 .name = (stringify(_field)), \ 397 .version_id = (_version), \ 398 .vmsd = &(_vmsd), \ 399 .size = sizeof(_type *), \ 400 .flags = VMS_STRUCT|VMS_POINTER, \ 401 .offset = vmstate_offset_pointer(_state, _field, _type), \ 402 } 403 404 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \ 405 .name = (stringify(_field)), \ 406 .version_id = (_version), \ 407 .field_exists = (_test), \ 408 .vmsd = &(_vmsd), \ 409 .size = sizeof(_type *), \ 410 .flags = VMS_STRUCT|VMS_POINTER, \ 411 .offset = vmstate_offset_pointer(_state, _field, _type), \ 412 } 413 414 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\ 415 .name = (stringify(_field)), \ 416 .version_id = (_version), \ 417 .num = (_num), \ 418 .info = &(_info), \ 419 .size = sizeof(_type), \ 420 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ 421 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 422 } 423 424 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \ 425 .name = (stringify(_f)), \ 426 .version_id = (_v), \ 427 .num = (_n), \ 428 .vmsd = &(_vmsd), \ 429 .size = sizeof(_type *), \ 430 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \ 431 .offset = vmstate_offset_array(_s, _f, _type*, _n), \ 432 } 433 434 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \ 435 .name = (stringify(_field)), \ 436 .version_id = (_version), \ 437 .num = (_num), \ 438 .vmsd = &(_vmsd), \ 439 .size = sizeof(_type), \ 440 .flags = VMS_STRUCT|VMS_ARRAY, \ 441 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 442 } 443 444 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \ 445 .name = (stringify(_field)), \ 446 .num = (_num), \ 447 .field_exists = (_test), \ 448 .version_id = (_version), \ 449 .vmsd = &(_vmsd), \ 450 .size = sizeof(_type), \ 451 .flags = VMS_STRUCT|VMS_ARRAY, \ 452 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 453 } 454 455 #define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \ 456 _version, _vmsd, _type) { \ 457 .name = (stringify(_field)), \ 458 .num = (_n1) * (_n2), \ 459 .field_exists = (_test), \ 460 .version_id = (_version), \ 461 .vmsd = &(_vmsd), \ 462 .size = sizeof(_type), \ 463 .flags = VMS_STRUCT | VMS_ARRAY, \ 464 .offset = vmstate_offset_2darray(_state, _field, _type, \ 465 _n1, _n2), \ 466 } 467 468 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \ 469 .name = (stringify(_field)), \ 470 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \ 471 .version_id = (_version), \ 472 .vmsd = &(_vmsd), \ 473 .size = sizeof(_type), \ 474 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \ 475 .offset = offsetof(_state, _field), \ 476 } 477 478 /* a variable length array (i.e. _type *_field) but we know the 479 * length 480 */ 481 #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \ 482 .name = (stringify(_field)), \ 483 .num = (_num), \ 484 .version_id = (_version), \ 485 .vmsd = &(_vmsd), \ 486 .size = sizeof(_type), \ 487 .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \ 488 .offset = offsetof(_state, _field), \ 489 } 490 491 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \ 492 .name = (stringify(_field)), \ 493 .version_id = 0, \ 494 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 495 .size = sizeof(_type), \ 496 .vmsd = &(_vmsd), \ 497 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 498 .offset = vmstate_offset_pointer(_state, _field, _type), \ 499 } 500 501 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \ 502 .name = (stringify(_field)), \ 503 .version_id = 0, \ 504 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 505 .size = sizeof(_type), \ 506 .vmsd = &(_vmsd), \ 507 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 508 .offset = vmstate_offset_pointer(_state, _field, _type), \ 509 } 510 511 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \ 512 .name = (stringify(_field)), \ 513 .version_id = 0, \ 514 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 515 .size = sizeof(_type), \ 516 .vmsd = &(_vmsd), \ 517 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ 518 .offset = vmstate_offset_pointer(_state, _field, _type), \ 519 } 520 521 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 522 .name = (stringify(_field)), \ 523 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 524 .version_id = (_version), \ 525 .vmsd = &(_vmsd), \ 526 .size = sizeof(_type), \ 527 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \ 528 .offset = offsetof(_state, _field), \ 529 } 530 531 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 532 .name = (stringify(_field)), \ 533 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \ 534 .version_id = (_version), \ 535 .vmsd = &(_vmsd), \ 536 .size = sizeof(_type), \ 537 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \ 538 .offset = offsetof(_state, _field), \ 539 } 540 541 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\ 542 .name = (stringify(_field)), \ 543 .version_id = (_version), \ 544 .vmsd = &(_vmsd), \ 545 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 546 .size = sizeof(_type), \ 547 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ 548 .offset = vmstate_offset_pointer(_state, _field, _type), \ 549 } 550 551 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \ 552 .name = (stringify(_field)), \ 553 .version_id = (_version), \ 554 .field_exists = (_test), \ 555 .size = (_size - _start), \ 556 .info = &vmstate_info_buffer, \ 557 .flags = VMS_BUFFER, \ 558 .offset = vmstate_offset_buffer(_state, _field) + _start, \ 559 } 560 561 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \ 562 _field_size, _multiply) { \ 563 .name = (stringify(_field)), \ 564 .version_id = (_version), \ 565 .field_exists = (_test), \ 566 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 567 .size = (_multiply), \ 568 .info = &vmstate_info_buffer, \ 569 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ 570 .offset = offsetof(_state, _field), \ 571 } 572 573 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \ 574 .name = (stringify(_field)), \ 575 .version_id = (_version), \ 576 .field_exists = (_test), \ 577 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 578 .info = &vmstate_info_buffer, \ 579 .flags = VMS_VBUFFER|VMS_POINTER, \ 580 .offset = offsetof(_state, _field), \ 581 } 582 583 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \ 584 .name = (stringify(_field)), \ 585 .version_id = (_version), \ 586 .field_exists = (_test), \ 587 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 588 .info = &vmstate_info_buffer, \ 589 .flags = VMS_VBUFFER|VMS_POINTER, \ 590 .offset = offsetof(_state, _field), \ 591 } 592 593 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \ 594 _test, _field_size) { \ 595 .name = (stringify(_field)), \ 596 .version_id = (_version), \ 597 .field_exists = (_test), \ 598 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 599 .info = &vmstate_info_buffer, \ 600 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ 601 .offset = offsetof(_state, _field), \ 602 } 603 604 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \ 605 .name = (stringify(_field)), \ 606 .version_id = (_version), \ 607 .field_exists = (_test), \ 608 .size = (_size), \ 609 .info = &(_info), \ 610 .flags = VMS_BUFFER, \ 611 .offset = offsetof(_state, _field), \ 612 } 613 614 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \ 615 .name = (stringify(_field)), \ 616 .version_id = (_version), \ 617 .size = (_size), \ 618 .info = &vmstate_info_buffer, \ 619 .flags = VMS_BUFFER|VMS_POINTER, \ 620 .offset = offsetof(_state, _field), \ 621 } 622 623 /* Allocate a temporary of type 'tmp_type', set tmp->parent to _state 624 * and execute the vmsd on the temporary. Note that we're working with 625 * the whole of _state here, not a field within it. 626 * We compile time check that: 627 * That _tmp_type contains a 'parent' member that's a pointer to the 628 * '_state' type 629 * That the pointer is right at the start of _tmp_type. 630 */ 631 #define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \ 632 .name = "tmp", \ 633 .size = sizeof(_tmp_type) + \ 634 QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \ 635 type_check_pointer(_state, \ 636 typeof_field(_tmp_type, parent)), \ 637 .vmsd = &(_vmsd), \ 638 .info = &vmstate_info_tmp, \ 639 } 640 641 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ 642 .name = "unused", \ 643 .field_exists = (_test), \ 644 .version_id = (_version), \ 645 .size = (_size), \ 646 .info = &vmstate_info_unused_buffer, \ 647 .flags = VMS_BUFFER, \ 648 } 649 650 /* Discard size * field_num bytes, where field_num is a uint32 member */ 651 #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\ 652 .name = "unused", \ 653 .field_exists = (_test), \ 654 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 655 .version_id = (_version), \ 656 .size = (_size), \ 657 .info = &vmstate_info_unused_buffer, \ 658 .flags = VMS_VARRAY_UINT32 | VMS_BUFFER, \ 659 } 660 661 /* _field_size should be a int32_t field in the _state struct giving the 662 * size of the bitmap _field in bits. 663 */ 664 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \ 665 .name = (stringify(_field)), \ 666 .version_id = (_version), \ 667 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 668 .info = &vmstate_info_bitmap, \ 669 .flags = VMS_VBUFFER|VMS_POINTER, \ 670 .offset = offsetof(_state, _field), \ 671 } 672 673 /* For migrating a QTAILQ. 674 * Target QTAILQ needs be properly initialized. 675 * _type: type of QTAILQ element 676 * _next: name of QTAILQ entry field in QTAILQ element 677 * _vmsd: VMSD for QTAILQ element 678 * size: size of QTAILQ element 679 * start: offset of QTAILQ entry in QTAILQ element 680 */ 681 #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \ 682 { \ 683 .name = (stringify(_field)), \ 684 .version_id = (_version), \ 685 .vmsd = &(_vmsd), \ 686 .size = sizeof(_type), \ 687 .info = &vmstate_info_qtailq, \ 688 .offset = offsetof(_state, _field), \ 689 .start = offsetof(_type, _next), \ 690 } 691 692 /* _f : field name 693 _f_n : num of elements field_name 694 _n : num of elements 695 _s : struct state name 696 _v : version 697 */ 698 699 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ 700 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) 701 702 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ 703 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) 704 705 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ 706 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type) 707 708 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \ 709 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type) 710 711 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ 712 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \ 713 _vmsd, _type) 714 715 #define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \ 716 _vmsd, _type) \ 717 VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \ 718 _version, _vmsd, _type) 719 720 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \ 721 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \ 722 _size) 723 724 #define VMSTATE_BOOL_V(_f, _s, _v) \ 725 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) 726 727 #define VMSTATE_INT8_V(_f, _s, _v) \ 728 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) 729 #define VMSTATE_INT16_V(_f, _s, _v) \ 730 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) 731 #define VMSTATE_INT32_V(_f, _s, _v) \ 732 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) 733 #define VMSTATE_INT64_V(_f, _s, _v) \ 734 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) 735 736 #define VMSTATE_UINT8_V(_f, _s, _v) \ 737 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) 738 #define VMSTATE_UINT16_V(_f, _s, _v) \ 739 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) 740 #define VMSTATE_UINT32_V(_f, _s, _v) \ 741 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) 742 #define VMSTATE_UINT64_V(_f, _s, _v) \ 743 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) 744 745 #define VMSTATE_BOOL(_f, _s) \ 746 VMSTATE_BOOL_V(_f, _s, 0) 747 748 #define VMSTATE_INT8(_f, _s) \ 749 VMSTATE_INT8_V(_f, _s, 0) 750 #define VMSTATE_INT16(_f, _s) \ 751 VMSTATE_INT16_V(_f, _s, 0) 752 #define VMSTATE_INT32(_f, _s) \ 753 VMSTATE_INT32_V(_f, _s, 0) 754 #define VMSTATE_INT64(_f, _s) \ 755 VMSTATE_INT64_V(_f, _s, 0) 756 757 #define VMSTATE_UINT8(_f, _s) \ 758 VMSTATE_UINT8_V(_f, _s, 0) 759 #define VMSTATE_UINT16(_f, _s) \ 760 VMSTATE_UINT16_V(_f, _s, 0) 761 #define VMSTATE_UINT32(_f, _s) \ 762 VMSTATE_UINT32_V(_f, _s, 0) 763 #define VMSTATE_UINT64(_f, _s) \ 764 VMSTATE_UINT64_V(_f, _s, 0) 765 766 #define VMSTATE_UINT8_EQUAL(_f, _s) \ 767 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t) 768 769 #define VMSTATE_UINT16_EQUAL(_f, _s) \ 770 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t) 771 772 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \ 773 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t) 774 775 #define VMSTATE_INT32_EQUAL(_f, _s) \ 776 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) 777 778 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \ 779 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t) 780 781 #define VMSTATE_UINT32_EQUAL(_f, _s) \ 782 VMSTATE_UINT32_EQUAL_V(_f, _s, 0) 783 784 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \ 785 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) 786 787 #define VMSTATE_UINT64_EQUAL(_f, _s) \ 788 VMSTATE_UINT64_EQUAL_V(_f, _s, 0) 789 790 #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \ 791 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) 792 793 #define VMSTATE_INT8_TEST(_f, _s, _t) \ 794 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) 795 796 #define VMSTATE_INT16_TEST(_f, _s, _t) \ 797 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t) 798 799 #define VMSTATE_INT32_TEST(_f, _s, _t) \ 800 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t) 801 802 #define VMSTATE_INT64_TEST(_f, _s, _t) \ 803 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) 804 805 #define VMSTATE_UINT8_TEST(_f, _s, _t) \ 806 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) 807 808 #define VMSTATE_UINT16_TEST(_f, _s, _t) \ 809 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) 810 811 #define VMSTATE_UINT32_TEST(_f, _s, _t) \ 812 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) 813 814 #define VMSTATE_UINT64_TEST(_f, _s, _t) \ 815 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) 816 817 818 #define VMSTATE_FLOAT64_V(_f, _s, _v) \ 819 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64) 820 821 #define VMSTATE_FLOAT64(_f, _s) \ 822 VMSTATE_FLOAT64_V(_f, _s, 0) 823 824 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \ 825 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) 826 827 #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \ 828 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) 829 830 #define VMSTATE_TIMER_PTR(_f, _s) \ 831 VMSTATE_TIMER_PTR_V(_f, _s, 0) 832 833 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ 834 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *) 835 836 #define VMSTATE_TIMER_TEST(_f, _s, _test) \ 837 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer) 838 839 #define VMSTATE_TIMER_V(_f, _s, _v) \ 840 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer) 841 842 #define VMSTATE_TIMER(_f, _s) \ 843 VMSTATE_TIMER_V(_f, _s, 0) 844 845 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \ 846 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) 847 848 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \ 849 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool) 850 851 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \ 852 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0) 853 854 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \ 855 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) 856 857 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 858 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t) 859 860 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \ 861 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) 862 863 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \ 864 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0) 865 866 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 867 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t) 868 869 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \ 870 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) 871 872 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \ 873 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) 874 875 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \ 876 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t) 877 878 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \ 879 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0) 880 881 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \ 882 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) 883 884 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 885 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t) 886 887 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \ 888 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0) 889 890 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \ 891 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0) 892 893 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \ 894 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t) 895 896 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \ 897 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) 898 899 #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \ 900 VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0) 901 902 #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 903 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t) 904 905 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ 906 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) 907 908 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \ 909 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) 910 911 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \ 912 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) 913 914 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \ 915 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0) 916 917 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \ 918 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t) 919 920 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \ 921 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t) 922 923 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \ 924 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) 925 926 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \ 927 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64) 928 929 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \ 930 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0) 931 932 #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \ 933 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU) 934 935 #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \ 936 VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0) 937 938 #define VMSTATE_BUFFER_V(_f, _s, _v) \ 939 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) 940 941 #define VMSTATE_BUFFER(_f, _s) \ 942 VMSTATE_BUFFER_V(_f, _s, 0) 943 944 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \ 945 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size) 946 947 #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \ 948 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f))) 949 950 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ 951 VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) 952 953 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ 954 VMSTATE_VBUFFER(_f, _s, 0, NULL, _size) 955 956 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \ 957 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size) 958 959 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ 960 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) 961 962 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \ 963 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) 964 965 #define VMSTATE_UNUSED_V(_v, _size) \ 966 VMSTATE_UNUSED_BUFFER(NULL, _v, _size) 967 968 #define VMSTATE_UNUSED(_size) \ 969 VMSTATE_UNUSED_V(0, _size) 970 971 #define VMSTATE_UNUSED_TEST(_test, _size) \ 972 VMSTATE_UNUSED_BUFFER(_test, 0, _size) 973 974 #define VMSTATE_END_OF_LIST() \ 975 {} 976 977 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, 978 void *opaque, int version_id); 979 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, 980 void *opaque, QJSON *vmdesc); 981 982 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); 983 984 /* Returns: 0 on success, -1 on failure */ 985 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, 986 const VMStateDescription *vmsd, 987 void *base, int alias_id, 988 int required_for_version, 989 Error **errp); 990 991 /* Returns: 0 on success, -1 on failure */ 992 static inline int vmstate_register(DeviceState *dev, int instance_id, 993 const VMStateDescription *vmsd, 994 void *opaque) 995 { 996 return vmstate_register_with_alias_id(dev, instance_id, vmsd, 997 opaque, -1, 0, NULL); 998 } 999 1000 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, 1001 void *opaque); 1002 1003 struct MemoryRegion; 1004 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); 1005 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); 1006 void vmstate_register_ram_global(struct MemoryRegion *memory); 1007 1008 bool vmstate_check_only_migratable(const VMStateDescription *vmsd); 1009 1010 #endif 1011