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 #ifndef QEMU_VMSTATE_H 27 #define QEMU_VMSTATE_H 1 28 29 #include <migration/qemu-file.h> 30 31 typedef void SaveStateHandler(QEMUFile *f, void *opaque); 32 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); 33 34 typedef struct SaveVMHandlers { 35 /* This runs inside the iothread lock. */ 36 void (*set_params)(const MigrationParams *params, void * opaque); 37 SaveStateHandler *save_state; 38 39 void (*cancel)(void *opaque); 40 int (*save_live_complete)(QEMUFile *f, void *opaque); 41 42 /* This runs both outside and inside the iothread lock. */ 43 bool (*is_active)(void *opaque); 44 45 /* This runs outside the iothread lock in the migration case, and 46 * within the lock in the savevm case. The callback had better only 47 * use data that is local to the migration thread or protected 48 * by other locks. 49 */ 50 int (*save_live_iterate)(QEMUFile *f, void *opaque); 51 52 /* This runs outside the iothread lock! */ 53 int (*save_live_setup)(QEMUFile *f, void *opaque); 54 uint64_t (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size); 55 56 LoadStateHandler *load_state; 57 } SaveVMHandlers; 58 59 int register_savevm(DeviceState *dev, 60 const char *idstr, 61 int instance_id, 62 int version_id, 63 SaveStateHandler *save_state, 64 LoadStateHandler *load_state, 65 void *opaque); 66 67 int register_savevm_live(DeviceState *dev, 68 const char *idstr, 69 int instance_id, 70 int version_id, 71 SaveVMHandlers *ops, 72 void *opaque); 73 74 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque); 75 void register_device_unmigratable(DeviceState *dev, const char *idstr, 76 void *opaque); 77 78 79 typedef struct VMStateInfo VMStateInfo; 80 typedef struct VMStateDescription VMStateDescription; 81 82 struct VMStateInfo { 83 const char *name; 84 int (*get)(QEMUFile *f, void *pv, size_t size); 85 void (*put)(QEMUFile *f, void *pv, size_t size); 86 }; 87 88 enum VMStateFlags { 89 VMS_SINGLE = 0x001, 90 VMS_POINTER = 0x002, 91 VMS_ARRAY = 0x004, 92 VMS_STRUCT = 0x008, 93 VMS_VARRAY_INT32 = 0x010, /* Array with size in int32_t field*/ 94 VMS_BUFFER = 0x020, /* static sized buffer */ 95 VMS_ARRAY_OF_POINTER = 0x040, 96 VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */ 97 VMS_VBUFFER = 0x100, /* Buffer with size in int32_t field */ 98 VMS_MULTIPLY = 0x200, /* multiply "size" field by field_size */ 99 VMS_VARRAY_UINT8 = 0x400, /* Array with size in uint8_t field*/ 100 VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/ 101 }; 102 103 typedef struct { 104 const char *name; 105 size_t offset; 106 size_t size; 107 size_t start; 108 int num; 109 size_t num_offset; 110 size_t size_offset; 111 const VMStateInfo *info; 112 enum VMStateFlags flags; 113 const VMStateDescription *vmsd; 114 int version_id; 115 bool (*field_exists)(void *opaque, int version_id); 116 } VMStateField; 117 118 typedef struct VMStateSubsection { 119 const VMStateDescription *vmsd; 120 bool (*needed)(void *opaque); 121 } VMStateSubsection; 122 123 struct VMStateDescription { 124 const char *name; 125 int unmigratable; 126 int version_id; 127 int minimum_version_id; 128 int minimum_version_id_old; 129 LoadStateHandler *load_state_old; 130 int (*pre_load)(void *opaque); 131 int (*post_load)(void *opaque, int version_id); 132 void (*pre_save)(void *opaque); 133 VMStateField *fields; 134 const VMStateSubsection *subsections; 135 }; 136 137 #ifdef CONFIG_USER_ONLY 138 extern const VMStateDescription vmstate_dummy; 139 #endif 140 141 extern const VMStateInfo vmstate_info_bool; 142 143 extern const VMStateInfo vmstate_info_int8; 144 extern const VMStateInfo vmstate_info_int16; 145 extern const VMStateInfo vmstate_info_int32; 146 extern const VMStateInfo vmstate_info_int64; 147 148 extern const VMStateInfo vmstate_info_uint8_equal; 149 extern const VMStateInfo vmstate_info_uint16_equal; 150 extern const VMStateInfo vmstate_info_int32_equal; 151 extern const VMStateInfo vmstate_info_uint32_equal; 152 extern const VMStateInfo vmstate_info_int32_le; 153 154 extern const VMStateInfo vmstate_info_uint8; 155 extern const VMStateInfo vmstate_info_uint16; 156 extern const VMStateInfo vmstate_info_uint32; 157 extern const VMStateInfo vmstate_info_uint64; 158 159 extern const VMStateInfo vmstate_info_timer; 160 extern const VMStateInfo vmstate_info_buffer; 161 extern const VMStateInfo vmstate_info_unused_buffer; 162 extern const VMStateInfo vmstate_info_bitmap; 163 164 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) 165 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) 166 167 #define vmstate_offset_value(_state, _field, _type) \ 168 (offsetof(_state, _field) + \ 169 type_check(_type, typeof_field(_state, _field))) 170 171 #define vmstate_offset_pointer(_state, _field, _type) \ 172 (offsetof(_state, _field) + \ 173 type_check_pointer(_type, typeof_field(_state, _field))) 174 175 #define vmstate_offset_array(_state, _field, _type, _num) \ 176 (offsetof(_state, _field) + \ 177 type_check_array(_type, typeof_field(_state, _field), _num)) 178 179 #define vmstate_offset_sub_array(_state, _field, _type, _start) \ 180 (offsetof(_state, _field[_start])) 181 182 #define vmstate_offset_buffer(_state, _field) \ 183 vmstate_offset_array(_state, _field, uint8_t, \ 184 sizeof(typeof_field(_state, _field))) 185 186 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ 187 .name = (stringify(_field)), \ 188 .version_id = (_version), \ 189 .field_exists = (_test), \ 190 .size = sizeof(_type), \ 191 .info = &(_info), \ 192 .flags = VMS_SINGLE, \ 193 .offset = vmstate_offset_value(_state, _field, _type), \ 194 } 195 196 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ 197 .name = (stringify(_field)), \ 198 .version_id = (_version), \ 199 .info = &(_info), \ 200 .size = sizeof(_type), \ 201 .flags = VMS_SINGLE|VMS_POINTER, \ 202 .offset = vmstate_offset_value(_state, _field, _type), \ 203 } 204 205 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \ 206 .name = (stringify(_field)), \ 207 .info = &(_info), \ 208 .field_exists = (_test), \ 209 .size = sizeof(_type), \ 210 .flags = VMS_SINGLE|VMS_POINTER, \ 211 .offset = vmstate_offset_value(_state, _field, _type), \ 212 } 213 214 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\ 215 .name = (stringify(_field)), \ 216 .version_id = (_version), \ 217 .num = (_num), \ 218 .info = &(_info), \ 219 .size = sizeof(_type), \ 220 .flags = VMS_ARRAY, \ 221 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 222 } 223 224 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ 225 .name = (stringify(_field)), \ 226 .field_exists = (_test), \ 227 .num = (_num), \ 228 .info = &(_info), \ 229 .size = sizeof(_type), \ 230 .flags = VMS_ARRAY, \ 231 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 232 } 233 234 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \ 235 .name = (stringify(_field)), \ 236 .version_id = (_version), \ 237 .num = (_num), \ 238 .info = &(_info), \ 239 .size = sizeof(_type), \ 240 .flags = VMS_ARRAY, \ 241 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ 242 } 243 244 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\ 245 .name = (stringify(_field)), \ 246 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 247 .info = &(_info), \ 248 .size = sizeof(_type), \ 249 .flags = VMS_VARRAY_INT32, \ 250 .offset = offsetof(_state, _field), \ 251 } 252 253 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\ 254 .name = (stringify(_field)), \ 255 .version_id = (_version), \ 256 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 257 .info = &(_info), \ 258 .size = sizeof(_type), \ 259 .flags = VMS_VARRAY_INT32|VMS_POINTER, \ 260 .offset = vmstate_offset_pointer(_state, _field, _type), \ 261 } 262 263 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\ 264 .name = (stringify(_field)), \ 265 .version_id = (_version), \ 266 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ 267 .info = &(_info), \ 268 .size = sizeof(_type), \ 269 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \ 270 .offset = vmstate_offset_pointer(_state, _field, _type), \ 271 } 272 273 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\ 274 .name = (stringify(_field)), \ 275 .version_id = (_version), \ 276 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 277 .info = &(_info), \ 278 .size = sizeof(_type), \ 279 .flags = VMS_VARRAY_UINT16, \ 280 .offset = offsetof(_state, _field), \ 281 } 282 283 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ 284 .name = (stringify(_field)), \ 285 .version_id = (_version), \ 286 .field_exists = (_test), \ 287 .vmsd = &(_vmsd), \ 288 .size = sizeof(_type), \ 289 .flags = VMS_STRUCT, \ 290 .offset = vmstate_offset_value(_state, _field, _type), \ 291 } 292 293 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \ 294 .name = (stringify(_field)), \ 295 .field_exists = (_test), \ 296 .vmsd = &(_vmsd), \ 297 .size = sizeof(_type), \ 298 .flags = VMS_STRUCT|VMS_POINTER, \ 299 .offset = vmstate_offset_value(_state, _field, _type), \ 300 } 301 302 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\ 303 .name = (stringify(_field)), \ 304 .version_id = (_version), \ 305 .num = (_num), \ 306 .info = &(_info), \ 307 .size = sizeof(_type), \ 308 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ 309 .offset = vmstate_offset_array(_state, _field, _type, _num), \ 310 } 311 312 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \ 313 .name = (stringify(_field)), \ 314 .num = (_num), \ 315 .field_exists = (_test), \ 316 .version_id = (_version), \ 317 .vmsd = &(_vmsd), \ 318 .size = sizeof(_type), \ 319 .flags = VMS_STRUCT|VMS_ARRAY, \ 320 .offset = vmstate_offset_array(_state, _field, _type, _num),\ 321 } 322 323 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \ 324 .name = (stringify(_field)), \ 325 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \ 326 .version_id = (_version), \ 327 .vmsd = &(_vmsd), \ 328 .size = sizeof(_type), \ 329 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \ 330 .offset = offsetof(_state, _field), \ 331 } 332 333 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \ 334 .name = (stringify(_field)), \ 335 .version_id = 0, \ 336 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 337 .size = sizeof(_type), \ 338 .vmsd = &(_vmsd), \ 339 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ 340 .offset = vmstate_offset_pointer(_state, _field, _type), \ 341 } 342 343 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \ 344 .name = (stringify(_field)), \ 345 .version_id = 0, \ 346 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ 347 .size = sizeof(_type), \ 348 .vmsd = &(_vmsd), \ 349 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ 350 .offset = vmstate_offset_pointer(_state, _field, _type), \ 351 } 352 353 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 354 .name = (stringify(_field)), \ 355 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ 356 .version_id = (_version), \ 357 .vmsd = &(_vmsd), \ 358 .size = sizeof(_type), \ 359 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \ 360 .offset = offsetof(_state, _field), \ 361 } 362 363 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \ 364 .name = (stringify(_field)), \ 365 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \ 366 .version_id = (_version), \ 367 .vmsd = &(_vmsd), \ 368 .size = sizeof(_type), \ 369 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \ 370 .offset = offsetof(_state, _field), \ 371 } 372 373 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \ 374 .name = (stringify(_field)), \ 375 .version_id = (_version), \ 376 .field_exists = (_test), \ 377 .size = (_size - _start), \ 378 .info = &vmstate_info_buffer, \ 379 .flags = VMS_BUFFER, \ 380 .offset = vmstate_offset_buffer(_state, _field) + _start, \ 381 } 382 383 #define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \ 384 .name = (stringify(_field)), \ 385 .version_id = (_version), \ 386 .field_exists = (_test), \ 387 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 388 .size = (_multiply), \ 389 .info = &vmstate_info_buffer, \ 390 .flags = VMS_VBUFFER|VMS_MULTIPLY, \ 391 .offset = offsetof(_state, _field), \ 392 .start = (_start), \ 393 } 394 395 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \ 396 .name = (stringify(_field)), \ 397 .version_id = (_version), \ 398 .field_exists = (_test), \ 399 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 400 .info = &vmstate_info_buffer, \ 401 .flags = VMS_VBUFFER|VMS_POINTER, \ 402 .offset = offsetof(_state, _field), \ 403 .start = (_start), \ 404 } 405 406 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \ 407 .name = (stringify(_field)), \ 408 .version_id = (_version), \ 409 .field_exists = (_test), \ 410 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ 411 .info = &vmstate_info_buffer, \ 412 .flags = VMS_VBUFFER|VMS_POINTER, \ 413 .offset = offsetof(_state, _field), \ 414 .start = (_start), \ 415 } 416 417 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \ 418 .name = (stringify(_field)), \ 419 .version_id = (_version), \ 420 .size = (_size), \ 421 .info = &(_info), \ 422 .flags = VMS_BUFFER, \ 423 .offset = offsetof(_state, _field), \ 424 } 425 426 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ 427 .name = "unused", \ 428 .field_exists = (_test), \ 429 .version_id = (_version), \ 430 .size = (_size), \ 431 .info = &vmstate_info_unused_buffer, \ 432 .flags = VMS_BUFFER, \ 433 } 434 435 /* _field_size should be a int32_t field in the _state struct giving the 436 * size of the bitmap _field in bits. 437 */ 438 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \ 439 .name = (stringify(_field)), \ 440 .version_id = (_version), \ 441 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ 442 .info = &vmstate_info_bitmap, \ 443 .flags = VMS_VBUFFER|VMS_POINTER, \ 444 .offset = offsetof(_state, _field), \ 445 } 446 447 /* _f : field name 448 _f_n : num of elements field_name 449 _n : num of elements 450 _s : struct state name 451 _v : version 452 */ 453 454 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ 455 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) 456 457 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ 458 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) 459 460 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ 461 VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type) 462 463 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ 464 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \ 465 _vmsd, _type) 466 467 #define VMSTATE_BOOL_V(_f, _s, _v) \ 468 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) 469 470 #define VMSTATE_INT8_V(_f, _s, _v) \ 471 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) 472 #define VMSTATE_INT16_V(_f, _s, _v) \ 473 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) 474 #define VMSTATE_INT32_V(_f, _s, _v) \ 475 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) 476 #define VMSTATE_INT64_V(_f, _s, _v) \ 477 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) 478 479 #define VMSTATE_UINT8_V(_f, _s, _v) \ 480 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) 481 #define VMSTATE_UINT16_V(_f, _s, _v) \ 482 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) 483 #define VMSTATE_UINT32_V(_f, _s, _v) \ 484 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) 485 #define VMSTATE_UINT64_V(_f, _s, _v) \ 486 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) 487 488 #define VMSTATE_BOOL(_f, _s) \ 489 VMSTATE_BOOL_V(_f, _s, 0) 490 491 #define VMSTATE_INT8(_f, _s) \ 492 VMSTATE_INT8_V(_f, _s, 0) 493 #define VMSTATE_INT16(_f, _s) \ 494 VMSTATE_INT16_V(_f, _s, 0) 495 #define VMSTATE_INT32(_f, _s) \ 496 VMSTATE_INT32_V(_f, _s, 0) 497 #define VMSTATE_INT64(_f, _s) \ 498 VMSTATE_INT64_V(_f, _s, 0) 499 500 #define VMSTATE_UINT8(_f, _s) \ 501 VMSTATE_UINT8_V(_f, _s, 0) 502 #define VMSTATE_UINT16(_f, _s) \ 503 VMSTATE_UINT16_V(_f, _s, 0) 504 #define VMSTATE_UINT32(_f, _s) \ 505 VMSTATE_UINT32_V(_f, _s, 0) 506 #define VMSTATE_UINT64(_f, _s) \ 507 VMSTATE_UINT64_V(_f, _s, 0) 508 509 #define VMSTATE_UINT8_EQUAL(_f, _s) \ 510 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t) 511 512 #define VMSTATE_UINT16_EQUAL(_f, _s) \ 513 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t) 514 515 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \ 516 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t) 517 518 #define VMSTATE_INT32_EQUAL(_f, _s) \ 519 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) 520 521 #define VMSTATE_UINT32_EQUAL(_f, _s) \ 522 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t) 523 524 #define VMSTATE_INT32_LE(_f, _s) \ 525 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) 526 527 #define VMSTATE_UINT8_TEST(_f, _s, _t) \ 528 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) 529 530 #define VMSTATE_UINT16_TEST(_f, _s, _t) \ 531 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) 532 533 #define VMSTATE_UINT32_TEST(_f, _s, _t) \ 534 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) 535 536 #define VMSTATE_TIMER_TEST(_f, _s, _test) \ 537 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) 538 539 #define VMSTATE_TIMER_V(_f, _s, _v) \ 540 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) 541 542 #define VMSTATE_TIMER(_f, _s) \ 543 VMSTATE_TIMER_V(_f, _s, 0) 544 545 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \ 546 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *) 547 548 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \ 549 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool) 550 551 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \ 552 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0) 553 554 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \ 555 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) 556 557 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \ 558 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) 559 560 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \ 561 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) 562 563 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \ 564 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) 565 566 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \ 567 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) 568 569 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \ 570 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0) 571 572 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \ 573 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t) 574 575 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \ 576 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) 577 578 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ 579 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) 580 581 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \ 582 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) 583 584 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \ 585 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) 586 587 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \ 588 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0) 589 590 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \ 591 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t) 592 593 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \ 594 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0) 595 596 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \ 597 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t) 598 599 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \ 600 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) 601 602 #define VMSTATE_BUFFER_V(_f, _s, _v) \ 603 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) 604 605 #define VMSTATE_BUFFER(_f, _s) \ 606 VMSTATE_BUFFER_V(_f, _s, 0) 607 608 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \ 609 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size) 610 611 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ 612 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f))) 613 614 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ 615 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size) 616 617 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \ 618 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size) 619 620 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \ 621 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size) 622 623 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ 624 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) 625 626 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \ 627 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) 628 629 #define VMSTATE_UNUSED_V(_v, _size) \ 630 VMSTATE_UNUSED_BUFFER(NULL, _v, _size) 631 632 #define VMSTATE_UNUSED(_size) \ 633 VMSTATE_UNUSED_V(0, _size) 634 635 #define VMSTATE_UNUSED_TEST(_test, _size) \ 636 VMSTATE_UNUSED_BUFFER(_test, 0, _size) 637 638 #define VMSTATE_END_OF_LIST() \ 639 {} 640 641 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, 642 void *opaque, int version_id); 643 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, 644 void *opaque); 645 646 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, 647 const VMStateDescription *vmsd, 648 void *base, int alias_id, 649 int required_for_version); 650 651 static inline int vmstate_register(DeviceState *dev, int instance_id, 652 const VMStateDescription *vmsd, 653 void *opaque) 654 { 655 return vmstate_register_with_alias_id(dev, instance_id, vmsd, 656 opaque, -1, 0); 657 } 658 659 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, 660 void *opaque); 661 662 struct MemoryRegion; 663 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); 664 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); 665 void vmstate_register_ram_global(struct MemoryRegion *memory); 666 667 #endif 668