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_MAX, 153 } MigrationPriority; 154 155 struct VMStateField { 156 const char *name; 157 size_t offset; 158 size_t size; 159 size_t start; 160 int num; 161 size_t num_offset; 162 size_t size_offset; 163 const VMStateInfo *info; 164 enum VMStateFlags flags; 165 const VMStateDescription *vmsd; 166 int version_id; 167 bool (*field_exists)(void *opaque, int version_id); 168 }; 169 170 struct VMStateDescription { 171 const char *name; 172 int unmigratable; 173 int version_id; 174 int minimum_version_id; 175 int minimum_version_id_old; 176 MigrationPriority priority; 177 LoadStateHandler *load_state_old; 178 int (*pre_load)(void *opaque); 179 int (*post_load)(void *opaque, int version_id); 180 void (*pre_save)(void *opaque); 181 bool (*needed)(void *opaque); 182 VMStateField *fields; 183 const VMStateDescription **subsections; 184 }; 185 186 extern const VMStateDescription vmstate_dummy; 187 188 extern const VMStateInfo vmstate_info_bool; 189 190 extern const VMStateInfo vmstate_info_int8; 191 extern const VMStateInfo vmstate_info_int16; 192 extern const VMStateInfo vmstate_info_int32; 193 extern const VMStateInfo vmstate_info_int64; 194 195 extern const VMStateInfo vmstate_info_uint8_equal; 196 extern const VMStateInfo vmstate_info_uint16_equal; 197 extern const VMStateInfo vmstate_info_int32_equal; 198 extern const VMStateInfo vmstate_info_uint32_equal; 199 extern const VMStateInfo vmstate_info_uint64_equal; 200 extern const VMStateInfo vmstate_info_int32_le; 201 202 extern const VMStateInfo vmstate_info_uint8; 203 extern const VMStateInfo vmstate_info_uint16; 204 extern const VMStateInfo vmstate_info_uint32; 205 extern const VMStateInfo vmstate_info_uint64; 206 207 /** Put this in the stream when migrating a null pointer.*/ 208 #define VMS_NULLPTR_MARKER (0x30U) /* '0' */ 209 extern const VMStateInfo vmstate_info_nullptr; 210 211 extern const VMStateInfo vmstate_info_float64; 212 extern const VMStateInfo vmstate_info_cpudouble; 213 214 extern const VMStateInfo vmstate_info_timer; 215 extern const VMStateInfo vmstate_info_buffer; 216 extern const VMStateInfo vmstate_info_unused_buffer; 217 extern const VMStateInfo vmstate_info_tmp; 218 extern const VMStateInfo vmstate_info_bitmap; 219 extern const VMStateInfo vmstate_info_qtailq; 220 221 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) 222 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) 223 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) 224 225 #define vmstate_offset_value(_state, _field, _type) \ 226 (offsetof(_state, _field) + \ 227 type_check(_type, typeof_field(_state, _field))) 228 229 #define vmstate_offset_pointer(_state, _field, _type) \ 230 (offsetof(_state, _field) + \ 231 type_check_pointer(_type, typeof_field(_state, _field))) 232 233 #define vmstate_offset_array(_state, _field, _type, _num) \ 234 (offsetof(_state, _field) + \ 235 type_check_array(_type, typeof_field(_state, _field), _num)) 236 237 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \ 238 (offsetof(_state, _field) + \ 239 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2)) 240 241 #define vmstate_offset_sub_array(_state, _field, _type, _start) \ 242 vmstate_offset_value(_state, _field[_start], _type) 243 244 #define vmstate_offset_buffer(_state, _field) \ 245 vmstate_offset_array(_state, _field, uint8_t, \ 246 sizeof(typeof_field(_state, _field))) 247 248 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ 249 .name = (stringify(_field)), \ 250 .version_id = (_version), \ 251 .field_exists = (_test), \ 252 .size = sizeof(_type), \ 253 .info = &(_info), \ 254 .flags = VMS_SINGLE, \ 255 .offset = vmstate_offset_value(_state, _field, _type), \ 256 } 257 258 /* Validate state using a boolean predicate. */ 259 #define VMSTATE_VALIDATE(_name, _test) { \ 260 .name = (_name), \ 261 .field_exists = (_test), \ 262 .flags = VMS_ARRAY | VMS_MUST_EXIST, \ 263 .num = 0, /* 0 elements: no data, only run _test */ \ 264 } 265 266 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ 267 .name = (stringify(_field)), \ 268 .version_id = (_version), \ 269 .info = &(_info), \ 270 .size = sizeof(_type), \ 271 .flags = VMS_SINGLE|VMS_POINTER, \ 272 .offset = vmstate_offset_value(_state, _field, _type), \ 273 } 274 275 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \ 276 .name = (stringify(_field)), \ 277 .info = &(_info), \ 278 .field_exists = (_test), \ 279 .size = sizeof(_type), \ 280 .flags = VMS_SINGLE|VMS_POINTER, \ 281 .offset = vmstate_offset_value(_state, _field, _type), \ 282 } 283 284 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\ 285 .name = (stringify(_field)), \ 286 .version_id = (_version), \ 287 .num = (_num), \ 288 .info = &(_info), \ 289 .size = sizeof(_type), \ 290 .flags = VMS_ARRAY, \ 291 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 292 } 293 294 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \ 295 .name = (stringify(_field)), \ 296 .version_id = (_version), \ 297 .num = (_n1) * (_n2), \ 298 .info = &(_info), \ 299 .size = sizeof(_type), \ 300 .flags = VMS_ARRAY, \ 301 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \ 302 } 303 304 #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \ 305 .name = (stringify(_field)), \ 306 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 307 .num = (_multiply), \ 308 .info = &(_info), \ 309 .size = sizeof(_type), \ 310 .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \ 311 .offset = offsetof(_state, _field), \ 312 } 313 314 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ 315 .name = (stringify(_field)), \ 316 .field_exists = (_test), \ 317 .num = (_num), \ 318 .info = &(_info), \ 319 .size = sizeof(_type), \ 320 .flags = VMS_ARRAY, \ 321 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 322 } 323 324 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \ 325 .name = (stringify(_field)), \ 326 .version_id = (_version), \ 327 .num = (_num), \ 328 .info = &(_info), \ 329 .size = sizeof(_type), \ 330 .flags = VMS_ARRAY, \ 331 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 332 } 333 334 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\ 335 .name = (stringify(_field)), \ 336 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 337 .info = &(_info), \ 338 .size = sizeof(_type), \ 339 .flags = VMS_VARRAY_INT32, \ 340 .offset = offsetof(_state, _field), \ 341 } 342 343 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\ 344 .name = (stringify(_field)), \ 345 .version_id = (_version), \ 346 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 347 .info = &(_info), \ 348 .size = sizeof(_type), \ 349 .flags = VMS_VARRAY_INT32|VMS_POINTER, \ 350 .offset = vmstate_offset_pointer(_state, _field, _type), \ 351 } 352 353 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\ 354 .name = (stringify(_field)), \ 355 .version_id = (_version), \ 356 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 357 .info = &(_info), \ 358 .size = sizeof(_type), \ 359 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \ 360 .offset = vmstate_offset_pointer(_state, _field, _type), \ 361 } 362 363 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\ 364 .name = (stringify(_field)), \ 365 .version_id = (_version), \ 366 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 367 .info = &(_info), \ 368 .size = sizeof(_type), \ 369 .flags = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ 370 .offset = vmstate_offset_pointer(_state, _field, _type), \ 371 } 372 373 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\ 374 .name = (stringify(_field)), \ 375 .version_id = (_version), \ 376 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 377 .info = &(_info), \ 378 .size = sizeof(_type), \ 379 .flags = VMS_VARRAY_UINT16, \ 380 .offset = offsetof(_state, _field), \ 381 } 382 383 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ 384 .name = (stringify(_field)), \ 385 .version_id = (_version), \ 386 .field_exists = (_test), \ 387 .vmsd = &(_vmsd), \ 388 .size = sizeof(_type), \ 389 .flags = VMS_STRUCT, \ 390 .offset = vmstate_offset_value(_state, _field, _type), \ 391 } 392 393 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \ 394 .name = (stringify(_field)), \ 395 .version_id = (_version), \ 396 .vmsd = &(_vmsd), \ 397 .size = sizeof(_type *), \ 398 .flags = VMS_STRUCT|VMS_POINTER, \ 399 .offset = vmstate_offset_pointer(_state, _field, _type), \ 400 } 401 402 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \ 403 .name = (stringify(_field)), \ 404 .version_id = (_version), \ 405 .field_exists = (_test), \ 406 .vmsd = &(_vmsd), \ 407 .size = sizeof(_type *), \ 408 .flags = VMS_STRUCT|VMS_POINTER, \ 409 .offset = vmstate_offset_pointer(_state, _field, _type), \ 410 } 411 412 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\ 413 .name = (stringify(_field)), \ 414 .version_id = (_version), \ 415 .num = (_num), \ 416 .info = &(_info), \ 417 .size = sizeof(_type), \ 418 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ 419 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 420 } 421 422 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \ 423 .name = (stringify(_f)), \ 424 .version_id = (_v), \ 425 .num = (_n), \ 426 .vmsd = &(_vmsd), \ 427 .size = sizeof(_type *), \ 428 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \ 429 .offset = vmstate_offset_array(_s, _f, _type*, _n), \ 430 } 431 432 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \ 433 .name = (stringify(_field)), \ 434 .version_id = (_version), \ 435 .num = (_num), \ 436 .vmsd = &(_vmsd), \ 437 .size = sizeof(_type), \ 438 .flags = VMS_STRUCT|VMS_ARRAY, \ 439 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 440 } 441 442 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \ 443 .name = (stringify(_field)), \ 444 .num = (_num), \ 445 .field_exists = (_test), \ 446 .version_id = (_version), \ 447 .vmsd = &(_vmsd), \ 448 .size = sizeof(_type), \ 449 .flags = VMS_STRUCT|VMS_ARRAY, \ 450 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 451 } 452 453 #define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \ 454 _version, _vmsd, _type) { \ 455 .name = (stringify(_field)), \ 456 .num = (_n1) * (_n2), \ 457 .field_exists = (_test), \ 458 .version_id = (_version), \ 459 .vmsd = &(_vmsd), \ 460 .size = sizeof(_type), \ 461 .flags = VMS_STRUCT | VMS_ARRAY, \ 462 .offset = vmstate_offset_2darray(_state, _field, _type, \ 463 _n1, _n2), \ 464 } 465 466 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \ 467 .name = (stringify(_field)), \ 468 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \ 469 .version_id = (_version), \ 470 .vmsd = &(_vmsd), \ 471 .size = sizeof(_type), \ 472 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \ 473 .offset = offsetof(_state, _field), \ 474 } 475 476 /* a variable length array (i.e. _type *_field) but we know the 477 * length 478 */ 479 #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \ 480 .name = (stringify(_field)), \ 481 .num = (_num), \ 482 .version_id = (_version), \ 483 .vmsd = &(_vmsd), \ 484 .size = sizeof(_type), \ 485 .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \ 486 .offset = offsetof(_state, _field), \ 487 } 488 489 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \ 490 .name = (stringify(_field)), \ 491 .version_id = 0, \ 492 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 493 .size = sizeof(_type), \ 494 .vmsd = &(_vmsd), \ 495 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 496 .offset = vmstate_offset_pointer(_state, _field, _type), \ 497 } 498 499 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \ 500 .name = (stringify(_field)), \ 501 .version_id = 0, \ 502 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 503 .size = sizeof(_type), \ 504 .vmsd = &(_vmsd), \ 505 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 506 .offset = vmstate_offset_pointer(_state, _field, _type), \ 507 } 508 509 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \ 510 .name = (stringify(_field)), \ 511 .version_id = 0, \ 512 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 513 .size = sizeof(_type), \ 514 .vmsd = &(_vmsd), \ 515 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ 516 .offset = vmstate_offset_pointer(_state, _field, _type), \ 517 } 518 519 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 520 .name = (stringify(_field)), \ 521 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 522 .version_id = (_version), \ 523 .vmsd = &(_vmsd), \ 524 .size = sizeof(_type), \ 525 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \ 526 .offset = offsetof(_state, _field), \ 527 } 528 529 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 530 .name = (stringify(_field)), \ 531 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \ 532 .version_id = (_version), \ 533 .vmsd = &(_vmsd), \ 534 .size = sizeof(_type), \ 535 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \ 536 .offset = offsetof(_state, _field), \ 537 } 538 539 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\ 540 .name = (stringify(_field)), \ 541 .version_id = (_version), \ 542 .vmsd = &(_vmsd), \ 543 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 544 .size = sizeof(_type), \ 545 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ 546 .offset = vmstate_offset_pointer(_state, _field, _type), \ 547 } 548 549 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \ 550 .name = (stringify(_field)), \ 551 .version_id = (_version), \ 552 .field_exists = (_test), \ 553 .size = (_size - _start), \ 554 .info = &vmstate_info_buffer, \ 555 .flags = VMS_BUFFER, \ 556 .offset = vmstate_offset_buffer(_state, _field) + _start, \ 557 } 558 559 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \ 560 _field_size, _multiply) { \ 561 .name = (stringify(_field)), \ 562 .version_id = (_version), \ 563 .field_exists = (_test), \ 564 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 565 .size = (_multiply), \ 566 .info = &vmstate_info_buffer, \ 567 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ 568 .offset = offsetof(_state, _field), \ 569 } 570 571 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \ 572 .name = (stringify(_field)), \ 573 .version_id = (_version), \ 574 .field_exists = (_test), \ 575 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 576 .info = &vmstate_info_buffer, \ 577 .flags = VMS_VBUFFER|VMS_POINTER, \ 578 .offset = offsetof(_state, _field), \ 579 } 580 581 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \ 582 .name = (stringify(_field)), \ 583 .version_id = (_version), \ 584 .field_exists = (_test), \ 585 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 586 .info = &vmstate_info_buffer, \ 587 .flags = VMS_VBUFFER|VMS_POINTER, \ 588 .offset = offsetof(_state, _field), \ 589 } 590 591 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \ 592 _test, _field_size) { \ 593 .name = (stringify(_field)), \ 594 .version_id = (_version), \ 595 .field_exists = (_test), \ 596 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 597 .info = &vmstate_info_buffer, \ 598 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ 599 .offset = offsetof(_state, _field), \ 600 } 601 602 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \ 603 .name = (stringify(_field)), \ 604 .version_id = (_version), \ 605 .field_exists = (_test), \ 606 .size = (_size), \ 607 .info = &(_info), \ 608 .flags = VMS_BUFFER, \ 609 .offset = offsetof(_state, _field), \ 610 } 611 612 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \ 613 .name = (stringify(_field)), \ 614 .version_id = (_version), \ 615 .size = (_size), \ 616 .info = &vmstate_info_buffer, \ 617 .flags = VMS_BUFFER|VMS_POINTER, \ 618 .offset = offsetof(_state, _field), \ 619 } 620 621 /* Allocate a temporary of type 'tmp_type', set tmp->parent to _state 622 * and execute the vmsd on the temporary. Note that we're working with 623 * the whole of _state here, not a field within it. 624 * We compile time check that: 625 * That _tmp_type contains a 'parent' member that's a pointer to the 626 * '_state' type 627 * That the pointer is right at the start of _tmp_type. 628 */ 629 #define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \ 630 .name = "tmp", \ 631 .size = sizeof(_tmp_type) + \ 632 QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \ 633 type_check_pointer(_state, \ 634 typeof_field(_tmp_type, parent)), \ 635 .vmsd = &(_vmsd), \ 636 .info = &vmstate_info_tmp, \ 637 } 638 639 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ 640 .name = "unused", \ 641 .field_exists = (_test), \ 642 .version_id = (_version), \ 643 .size = (_size), \ 644 .info = &vmstate_info_unused_buffer, \ 645 .flags = VMS_BUFFER, \ 646 } 647 648 /* Discard size * field_num bytes, where field_num is a uint32 member */ 649 #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\ 650 .name = "unused", \ 651 .field_exists = (_test), \ 652 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 653 .version_id = (_version), \ 654 .size = (_size), \ 655 .info = &vmstate_info_unused_buffer, \ 656 .flags = VMS_VARRAY_UINT32 | VMS_BUFFER, \ 657 } 658 659 /* _field_size should be a int32_t field in the _state struct giving the 660 * size of the bitmap _field in bits. 661 */ 662 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \ 663 .name = (stringify(_field)), \ 664 .version_id = (_version), \ 665 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 666 .info = &vmstate_info_bitmap, \ 667 .flags = VMS_VBUFFER|VMS_POINTER, \ 668 .offset = offsetof(_state, _field), \ 669 } 670 671 /* For migrating a QTAILQ. 672 * Target QTAILQ needs be properly initialized. 673 * _type: type of QTAILQ element 674 * _next: name of QTAILQ entry field in QTAILQ element 675 * _vmsd: VMSD for QTAILQ element 676 * size: size of QTAILQ element 677 * start: offset of QTAILQ entry in QTAILQ element 678 */ 679 #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \ 680 { \ 681 .name = (stringify(_field)), \ 682 .version_id = (_version), \ 683 .vmsd = &(_vmsd), \ 684 .size = sizeof(_type), \ 685 .info = &vmstate_info_qtailq, \ 686 .offset = offsetof(_state, _field), \ 687 .start = offsetof(_type, _next), \ 688 } 689 690 /* _f : field name 691 _f_n : num of elements field_name 692 _n : num of elements 693 _s : struct state name 694 _v : version 695 */ 696 697 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ 698 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) 699 700 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ 701 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) 702 703 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ 704 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type) 705 706 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \ 707 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type) 708 709 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ 710 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \ 711 _vmsd, _type) 712 713 #define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \ 714 _vmsd, _type) \ 715 VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \ 716 _version, _vmsd, _type) 717 718 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \ 719 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \ 720 _size) 721 722 #define VMSTATE_BOOL_V(_f, _s, _v) \ 723 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) 724 725 #define VMSTATE_INT8_V(_f, _s, _v) \ 726 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) 727 #define VMSTATE_INT16_V(_f, _s, _v) \ 728 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) 729 #define VMSTATE_INT32_V(_f, _s, _v) \ 730 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) 731 #define VMSTATE_INT64_V(_f, _s, _v) \ 732 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) 733 734 #define VMSTATE_UINT8_V(_f, _s, _v) \ 735 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) 736 #define VMSTATE_UINT16_V(_f, _s, _v) \ 737 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) 738 #define VMSTATE_UINT32_V(_f, _s, _v) \ 739 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) 740 #define VMSTATE_UINT64_V(_f, _s, _v) \ 741 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) 742 743 #define VMSTATE_BOOL(_f, _s) \ 744 VMSTATE_BOOL_V(_f, _s, 0) 745 746 #define VMSTATE_INT8(_f, _s) \ 747 VMSTATE_INT8_V(_f, _s, 0) 748 #define VMSTATE_INT16(_f, _s) \ 749 VMSTATE_INT16_V(_f, _s, 0) 750 #define VMSTATE_INT32(_f, _s) \ 751 VMSTATE_INT32_V(_f, _s, 0) 752 #define VMSTATE_INT64(_f, _s) \ 753 VMSTATE_INT64_V(_f, _s, 0) 754 755 #define VMSTATE_UINT8(_f, _s) \ 756 VMSTATE_UINT8_V(_f, _s, 0) 757 #define VMSTATE_UINT16(_f, _s) \ 758 VMSTATE_UINT16_V(_f, _s, 0) 759 #define VMSTATE_UINT32(_f, _s) \ 760 VMSTATE_UINT32_V(_f, _s, 0) 761 #define VMSTATE_UINT64(_f, _s) \ 762 VMSTATE_UINT64_V(_f, _s, 0) 763 764 #define VMSTATE_UINT8_EQUAL(_f, _s) \ 765 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t) 766 767 #define VMSTATE_UINT16_EQUAL(_f, _s) \ 768 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t) 769 770 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \ 771 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t) 772 773 #define VMSTATE_INT32_EQUAL(_f, _s) \ 774 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) 775 776 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \ 777 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t) 778 779 #define VMSTATE_UINT32_EQUAL(_f, _s) \ 780 VMSTATE_UINT32_EQUAL_V(_f, _s, 0) 781 782 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \ 783 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) 784 785 #define VMSTATE_UINT64_EQUAL(_f, _s) \ 786 VMSTATE_UINT64_EQUAL_V(_f, _s, 0) 787 788 #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \ 789 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) 790 791 #define VMSTATE_INT8_TEST(_f, _s, _t) \ 792 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) 793 794 #define VMSTATE_INT16_TEST(_f, _s, _t) \ 795 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t) 796 797 #define VMSTATE_INT32_TEST(_f, _s, _t) \ 798 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t) 799 800 #define VMSTATE_INT64_TEST(_f, _s, _t) \ 801 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) 802 803 #define VMSTATE_UINT8_TEST(_f, _s, _t) \ 804 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) 805 806 #define VMSTATE_UINT16_TEST(_f, _s, _t) \ 807 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) 808 809 #define VMSTATE_UINT32_TEST(_f, _s, _t) \ 810 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) 811 812 #define VMSTATE_UINT64_TEST(_f, _s, _t) \ 813 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) 814 815 816 #define VMSTATE_FLOAT64_V(_f, _s, _v) \ 817 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64) 818 819 #define VMSTATE_FLOAT64(_f, _s) \ 820 VMSTATE_FLOAT64_V(_f, _s, 0) 821 822 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \ 823 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) 824 825 #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \ 826 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) 827 828 #define VMSTATE_TIMER_PTR(_f, _s) \ 829 VMSTATE_TIMER_PTR_V(_f, _s, 0) 830 831 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ 832 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *) 833 834 #define VMSTATE_TIMER_TEST(_f, _s, _test) \ 835 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer) 836 837 #define VMSTATE_TIMER_V(_f, _s, _v) \ 838 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer) 839 840 #define VMSTATE_TIMER(_f, _s) \ 841 VMSTATE_TIMER_V(_f, _s, 0) 842 843 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \ 844 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) 845 846 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \ 847 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool) 848 849 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \ 850 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0) 851 852 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \ 853 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) 854 855 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 856 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t) 857 858 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \ 859 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) 860 861 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \ 862 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0) 863 864 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 865 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t) 866 867 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \ 868 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) 869 870 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \ 871 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) 872 873 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \ 874 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t) 875 876 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \ 877 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0) 878 879 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \ 880 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) 881 882 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 883 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t) 884 885 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \ 886 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0) 887 888 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \ 889 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0) 890 891 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \ 892 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t) 893 894 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \ 895 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) 896 897 #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \ 898 VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0) 899 900 #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \ 901 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t) 902 903 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ 904 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) 905 906 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \ 907 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) 908 909 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \ 910 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) 911 912 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \ 913 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0) 914 915 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \ 916 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t) 917 918 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \ 919 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t) 920 921 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \ 922 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) 923 924 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \ 925 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64) 926 927 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \ 928 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0) 929 930 #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \ 931 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU) 932 933 #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \ 934 VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0) 935 936 #define VMSTATE_BUFFER_V(_f, _s, _v) \ 937 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) 938 939 #define VMSTATE_BUFFER(_f, _s) \ 940 VMSTATE_BUFFER_V(_f, _s, 0) 941 942 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \ 943 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size) 944 945 #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \ 946 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f))) 947 948 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ 949 VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) 950 951 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ 952 VMSTATE_VBUFFER(_f, _s, 0, NULL, _size) 953 954 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \ 955 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size) 956 957 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ 958 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) 959 960 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \ 961 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) 962 963 #define VMSTATE_UNUSED_V(_v, _size) \ 964 VMSTATE_UNUSED_BUFFER(NULL, _v, _size) 965 966 #define VMSTATE_UNUSED(_size) \ 967 VMSTATE_UNUSED_V(0, _size) 968 969 #define VMSTATE_UNUSED_TEST(_test, _size) \ 970 VMSTATE_UNUSED_BUFFER(_test, 0, _size) 971 972 #define VMSTATE_END_OF_LIST() \ 973 {} 974 975 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, 976 void *opaque, int version_id); 977 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, 978 void *opaque, QJSON *vmdesc); 979 980 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); 981 982 /* Returns: 0 on success, -1 on failure */ 983 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, 984 const VMStateDescription *vmsd, 985 void *base, int alias_id, 986 int required_for_version, 987 Error **errp); 988 989 /* Returns: 0 on success, -1 on failure */ 990 static inline int vmstate_register(DeviceState *dev, int instance_id, 991 const VMStateDescription *vmsd, 992 void *opaque) 993 { 994 return vmstate_register_with_alias_id(dev, instance_id, vmsd, 995 opaque, -1, 0, NULL); 996 } 997 998 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, 999 void *opaque); 1000 1001 struct MemoryRegion; 1002 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); 1003 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); 1004 void vmstate_register_ram_global(struct MemoryRegion *memory); 1005 1006 bool vmstate_check_only_migratable(const VMStateDescription *vmsd); 1007 1008 #endif 1009