2 * QEMU migration/snapshot declarations
4 * Copyright (c) 2009-2011 Red Hat, Inc.
6 * Original author: Juan Quintela <quintela@redhat.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
27 #ifndef QEMU_VMSTATE_H
28 #define QEMU_VMSTATE_H
30 #include "migration/qjson.h"
32 typedef struct VMStateInfo VMStateInfo
;
33 typedef struct VMStateDescription VMStateDescription
;
34 typedef struct VMStateField VMStateField
;
36 /* VMStateInfo allows customized migration of objects that don't fit in
37 * any category in VMStateFlags. Additional information is always passed
38 * into get and put in terms of field and vmdesc parameters. However
39 * these two parameters should only be used in cases when customized
40 * handling is needed, such as QTAILQ. For primitive data types such as
41 * integer, field and vmdesc parameters should be ignored inside get/put.
45 int (*get
)(QEMUFile
*f
, void *pv
, size_t size
, VMStateField
*field
);
46 int (*put
)(QEMUFile
*f
, void *pv
, size_t size
, VMStateField
*field
,
54 /* The struct member at opaque + VMStateField.offset is a pointer
55 * to the actual field (e.g. struct a { uint8_t *b;
56 * }). Dereference the pointer before using it as basis for
57 * further pointer arithmetic (see e.g. VMS_ARRAY). Does not
58 * affect the meaning of VMStateField.num_offset or
59 * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for
63 /* The field is an array of fixed size. VMStateField.num contains
64 * the number of entries in the array. The size of each entry is
65 * given by VMStateField.size and / or opaque +
66 * VMStateField.size_offset; see VMS_VBUFFER and
67 * VMS_MULTIPLY. Each array entry will be processed individually
68 * (VMStateField.info.get()/put() if VMS_STRUCT is not set,
69 * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not
70 * be combined with VMS_VARRAY*. */
73 /* The field is itself a struct, containing one or more
74 * fields. Recurse into VMStateField.vmsd. Most useful in
75 * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each
79 /* The field is an array of variable size. The int32_t at opaque +
80 * VMStateField.num_offset contains the number of entries in the
81 * array. See the VMS_ARRAY description regarding array handling
82 * in general. May not be combined with VMS_ARRAY or any other
84 VMS_VARRAY_INT32
= 0x010,
89 /* The field is a (fixed-size or variable-size) array of pointers
90 * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry
91 * before using it. Note: Does not imply any one of VMS_ARRAY /
92 * VMS_VARRAY*; these need to be set explicitly. */
93 VMS_ARRAY_OF_POINTER
= 0x040,
95 /* The field is an array of variable size. The uint16_t at opaque
96 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
97 * contains the number of entries in the array. See the VMS_ARRAY
98 * description regarding array handling in general. May not be
99 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
100 VMS_VARRAY_UINT16
= 0x080,
102 /* The size of the individual entries (a single array entry if
103 * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if
104 * neither is set) is variable (i.e. not known at compile-time),
105 * but the same for all entries. Use the int32_t at opaque +
106 * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine
107 * the size of each (and every) entry. */
110 /* Multiply the entry size given by the int32_t at opaque +
111 * VMStateField.size_offset (see VMS_VBUFFER description) with
112 * VMStateField.size to determine the number of bytes to be
113 * allocated. Only valid in combination with VMS_VBUFFER. */
114 VMS_MULTIPLY
= 0x200,
116 /* The field is an array of variable size. The uint8_t at opaque +
117 * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
118 * contains the number of entries in the array. See the VMS_ARRAY
119 * description regarding array handling in general. May not be
120 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
121 VMS_VARRAY_UINT8
= 0x400,
123 /* The field is an array of variable size. The uint32_t at opaque
124 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
125 * contains the number of entries in the array. See the VMS_ARRAY
126 * description regarding array handling in general. May not be
127 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
128 VMS_VARRAY_UINT32
= 0x800,
130 /* Fail loading the serialised VM state if this field is missing
132 VMS_MUST_EXIST
= 0x1000,
134 /* When loading serialised VM state, allocate memory for the
135 * (entire) field. Only valid in combination with
136 * VMS_POINTER. Note: Not all combinations with other flags are
137 * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't
138 * cause the individual entries to be allocated. */
141 /* Multiply the number of entries given by the integer at opaque +
142 * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num
143 * to determine the number of entries in the array. Only valid in
144 * combination with one of VMS_VARRAY*. */
145 VMS_MULTIPLY_ELEMENTS
= 0x4000,
150 MIG_PRI_IOMMU
, /* Must happen before PCI devices */
151 MIG_PRI_GICV3_ITS
, /* Must happen before PCI devices */
152 MIG_PRI_GICV3
, /* Must happen before the ITS */
156 struct VMStateField
{
164 const VMStateInfo
*info
;
165 enum VMStateFlags flags
;
166 const VMStateDescription
*vmsd
;
168 bool (*field_exists
)(void *opaque
, int version_id
);
171 struct VMStateDescription
{
175 int minimum_version_id
;
176 int minimum_version_id_old
;
177 MigrationPriority priority
;
178 LoadStateHandler
*load_state_old
;
179 int (*pre_load
)(void *opaque
);
180 int (*post_load
)(void *opaque
, int version_id
);
181 void (*pre_save
)(void *opaque
);
182 bool (*needed
)(void *opaque
);
183 VMStateField
*fields
;
184 const VMStateDescription
**subsections
;
187 extern const VMStateDescription vmstate_dummy
;
189 extern const VMStateInfo vmstate_info_bool
;
191 extern const VMStateInfo vmstate_info_int8
;
192 extern const VMStateInfo vmstate_info_int16
;
193 extern const VMStateInfo vmstate_info_int32
;
194 extern const VMStateInfo vmstate_info_int64
;
196 extern const VMStateInfo vmstate_info_uint8_equal
;
197 extern const VMStateInfo vmstate_info_uint16_equal
;
198 extern const VMStateInfo vmstate_info_int32_equal
;
199 extern const VMStateInfo vmstate_info_uint32_equal
;
200 extern const VMStateInfo vmstate_info_uint64_equal
;
201 extern const VMStateInfo vmstate_info_int32_le
;
203 extern const VMStateInfo vmstate_info_uint8
;
204 extern const VMStateInfo vmstate_info_uint16
;
205 extern const VMStateInfo vmstate_info_uint32
;
206 extern const VMStateInfo vmstate_info_uint64
;
208 /** Put this in the stream when migrating a null pointer.*/
209 #define VMS_NULLPTR_MARKER (0x30U) /* '0' */
210 extern const VMStateInfo vmstate_info_nullptr
;
212 extern const VMStateInfo vmstate_info_float64
;
213 extern const VMStateInfo vmstate_info_cpudouble
;
215 extern const VMStateInfo vmstate_info_timer
;
216 extern const VMStateInfo vmstate_info_buffer
;
217 extern const VMStateInfo vmstate_info_unused_buffer
;
218 extern const VMStateInfo vmstate_info_tmp
;
219 extern const VMStateInfo vmstate_info_bitmap
;
220 extern const VMStateInfo vmstate_info_qtailq
;
222 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
223 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
224 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
226 #define vmstate_offset_value(_state, _field, _type) \
227 (offsetof(_state, _field) + \
228 type_check(_type, typeof_field(_state, _field)))
230 #define vmstate_offset_pointer(_state, _field, _type) \
231 (offsetof(_state, _field) + \
232 type_check_pointer(_type, typeof_field(_state, _field)))
234 #define vmstate_offset_array(_state, _field, _type, _num) \
235 (offsetof(_state, _field) + \
236 type_check_array(_type, typeof_field(_state, _field), _num))
238 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \
239 (offsetof(_state, _field) + \
240 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
242 #define vmstate_offset_sub_array(_state, _field, _type, _start) \
243 vmstate_offset_value(_state, _field[_start], _type)
245 #define vmstate_offset_buffer(_state, _field) \
246 vmstate_offset_array(_state, _field, uint8_t, \
247 sizeof(typeof_field(_state, _field)))
249 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
250 .name = (stringify(_field)), \
251 .version_id = (_version), \
252 .field_exists = (_test), \
253 .size = sizeof(_type), \
255 .flags = VMS_SINGLE, \
256 .offset = vmstate_offset_value(_state, _field, _type), \
259 /* Validate state using a boolean predicate. */
260 #define VMSTATE_VALIDATE(_name, _test) { \
262 .field_exists = (_test), \
263 .flags = VMS_ARRAY | VMS_MUST_EXIST, \
264 .num = 0, /* 0 elements: no data, only run _test */ \
267 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
268 .name = (stringify(_field)), \
269 .version_id = (_version), \
271 .size = sizeof(_type), \
272 .flags = VMS_SINGLE|VMS_POINTER, \
273 .offset = vmstate_offset_value(_state, _field, _type), \
276 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
277 .name = (stringify(_field)), \
279 .field_exists = (_test), \
280 .size = sizeof(_type), \
281 .flags = VMS_SINGLE|VMS_POINTER, \
282 .offset = vmstate_offset_value(_state, _field, _type), \
285 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
286 .name = (stringify(_field)), \
287 .version_id = (_version), \
290 .size = sizeof(_type), \
291 .flags = VMS_ARRAY, \
292 .offset = vmstate_offset_array(_state, _field, _type, _num), \
295 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
296 .name = (stringify(_field)), \
297 .version_id = (_version), \
298 .num = (_n1) * (_n2), \
300 .size = sizeof(_type), \
301 .flags = VMS_ARRAY, \
302 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \
305 #define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
306 .name = (stringify(_field)), \
307 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
308 .num = (_multiply), \
310 .size = sizeof(_type), \
311 .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \
312 .offset = offsetof(_state, _field), \
315 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
316 .name = (stringify(_field)), \
317 .field_exists = (_test), \
320 .size = sizeof(_type), \
321 .flags = VMS_ARRAY, \
322 .offset = vmstate_offset_array(_state, _field, _type, _num),\
325 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
326 .name = (stringify(_field)), \
327 .version_id = (_version), \
330 .size = sizeof(_type), \
331 .flags = VMS_ARRAY, \
332 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
335 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
336 .name = (stringify(_field)), \
337 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
339 .size = sizeof(_type), \
340 .flags = VMS_VARRAY_INT32, \
341 .offset = offsetof(_state, _field), \
344 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
345 .name = (stringify(_field)), \
346 .version_id = (_version), \
347 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
349 .size = sizeof(_type), \
350 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
351 .offset = vmstate_offset_pointer(_state, _field, _type), \
354 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
355 .name = (stringify(_field)), \
356 .version_id = (_version), \
357 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
359 .size = sizeof(_type), \
360 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
361 .offset = vmstate_offset_pointer(_state, _field, _type), \
364 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
365 .name = (stringify(_field)), \
366 .version_id = (_version), \
367 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
369 .size = sizeof(_type), \
370 .flags = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \
371 .offset = vmstate_offset_pointer(_state, _field, _type), \
374 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
375 .name = (stringify(_field)), \
376 .version_id = (_version), \
377 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
379 .size = sizeof(_type), \
380 .flags = VMS_VARRAY_UINT16, \
381 .offset = offsetof(_state, _field), \
384 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
385 .name = (stringify(_field)), \
386 .version_id = (_version), \
387 .field_exists = (_test), \
389 .size = sizeof(_type), \
390 .flags = VMS_STRUCT, \
391 .offset = vmstate_offset_value(_state, _field, _type), \
394 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
395 .name = (stringify(_field)), \
396 .version_id = (_version), \
398 .size = sizeof(_type *), \
399 .flags = VMS_STRUCT|VMS_POINTER, \
400 .offset = vmstate_offset_pointer(_state, _field, _type), \
403 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
404 .name = (stringify(_field)), \
405 .version_id = (_version), \
406 .field_exists = (_test), \
408 .size = sizeof(_type *), \
409 .flags = VMS_STRUCT|VMS_POINTER, \
410 .offset = vmstate_offset_pointer(_state, _field, _type), \
413 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
414 .name = (stringify(_field)), \
415 .version_id = (_version), \
418 .size = sizeof(_type), \
419 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
420 .offset = vmstate_offset_array(_state, _field, _type, _num), \
423 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
424 .name = (stringify(_f)), \
425 .version_id = (_v), \
428 .size = sizeof(_type *), \
429 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \
430 .offset = vmstate_offset_array(_s, _f, _type*, _n), \
433 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
434 .name = (stringify(_field)), \
435 .version_id = (_version), \
438 .size = sizeof(_type), \
439 .flags = VMS_STRUCT|VMS_ARRAY, \
440 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
443 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
444 .name = (stringify(_field)), \
446 .field_exists = (_test), \
447 .version_id = (_version), \
449 .size = sizeof(_type), \
450 .flags = VMS_STRUCT|VMS_ARRAY, \
451 .offset = vmstate_offset_array(_state, _field, _type, _num),\
454 #define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \
455 _version, _vmsd, _type) { \
456 .name = (stringify(_field)), \
457 .num = (_n1) * (_n2), \
458 .field_exists = (_test), \
459 .version_id = (_version), \
461 .size = sizeof(_type), \
462 .flags = VMS_STRUCT | VMS_ARRAY, \
463 .offset = vmstate_offset_2darray(_state, _field, _type, \
467 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
468 .name = (stringify(_field)), \
469 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
470 .version_id = (_version), \
472 .size = sizeof(_type), \
473 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
474 .offset = offsetof(_state, _field), \
477 /* a variable length array (i.e. _type *_field) but we know the
480 #define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
481 .name = (stringify(_field)), \
483 .version_id = (_version), \
485 .size = sizeof(_type), \
486 .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \
487 .offset = offsetof(_state, _field), \
490 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
491 .name = (stringify(_field)), \
493 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
494 .size = sizeof(_type), \
496 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
497 .offset = vmstate_offset_pointer(_state, _field, _type), \
500 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
501 .name = (stringify(_field)), \
503 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
504 .size = sizeof(_type), \
506 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
507 .offset = vmstate_offset_pointer(_state, _field, _type), \
510 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
511 .name = (stringify(_field)), \
513 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
514 .size = sizeof(_type), \
516 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
517 .offset = vmstate_offset_pointer(_state, _field, _type), \
520 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
521 .name = (stringify(_field)), \
522 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
523 .version_id = (_version), \
525 .size = sizeof(_type), \
526 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
527 .offset = offsetof(_state, _field), \
530 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
531 .name = (stringify(_field)), \
532 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
533 .version_id = (_version), \
535 .size = sizeof(_type), \
536 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
537 .offset = offsetof(_state, _field), \
540 #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
541 .name = (stringify(_field)), \
542 .version_id = (_version), \
544 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
545 .size = sizeof(_type), \
546 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
547 .offset = vmstate_offset_pointer(_state, _field, _type), \
550 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
551 .name = (stringify(_field)), \
552 .version_id = (_version), \
553 .field_exists = (_test), \
554 .size = (_size - _start), \
555 .info = &vmstate_info_buffer, \
556 .flags = VMS_BUFFER, \
557 .offset = vmstate_offset_buffer(_state, _field) + _start, \
560 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \
561 _field_size, _multiply) { \
562 .name = (stringify(_field)), \
563 .version_id = (_version), \
564 .field_exists = (_test), \
565 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
566 .size = (_multiply), \
567 .info = &vmstate_info_buffer, \
568 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \
569 .offset = offsetof(_state, _field), \
572 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \
573 .name = (stringify(_field)), \
574 .version_id = (_version), \
575 .field_exists = (_test), \
576 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
577 .info = &vmstate_info_buffer, \
578 .flags = VMS_VBUFFER|VMS_POINTER, \
579 .offset = offsetof(_state, _field), \
582 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \
583 .name = (stringify(_field)), \
584 .version_id = (_version), \
585 .field_exists = (_test), \
586 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
587 .info = &vmstate_info_buffer, \
588 .flags = VMS_VBUFFER|VMS_POINTER, \
589 .offset = offsetof(_state, _field), \
592 #define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \
593 _test, _field_size) { \
594 .name = (stringify(_field)), \
595 .version_id = (_version), \
596 .field_exists = (_test), \
597 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
598 .info = &vmstate_info_buffer, \
599 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \
600 .offset = offsetof(_state, _field), \
603 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
604 .name = (stringify(_field)), \
605 .version_id = (_version), \
606 .field_exists = (_test), \
609 .flags = VMS_BUFFER, \
610 .offset = offsetof(_state, _field), \
613 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
614 .name = (stringify(_field)), \
615 .version_id = (_version), \
617 .info = &vmstate_info_buffer, \
618 .flags = VMS_BUFFER|VMS_POINTER, \
619 .offset = offsetof(_state, _field), \
622 /* Allocate a temporary of type 'tmp_type', set tmp->parent to _state
623 * and execute the vmsd on the temporary. Note that we're working with
624 * the whole of _state here, not a field within it.
625 * We compile time check that:
626 * That _tmp_type contains a 'parent' member that's a pointer to the
628 * That the pointer is right at the start of _tmp_type.
630 #define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \
632 .size = sizeof(_tmp_type) + \
633 QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \
634 type_check_pointer(_state, \
635 typeof_field(_tmp_type, parent)), \
637 .info = &vmstate_info_tmp, \
640 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
642 .field_exists = (_test), \
643 .version_id = (_version), \
645 .info = &vmstate_info_unused_buffer, \
646 .flags = VMS_BUFFER, \
649 /* Discard size * field_num bytes, where field_num is a uint32 member */
650 #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\
652 .field_exists = (_test), \
653 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
654 .version_id = (_version), \
656 .info = &vmstate_info_unused_buffer, \
657 .flags = VMS_VARRAY_UINT32 | VMS_BUFFER, \
660 /* _field_size should be a int32_t field in the _state struct giving the
661 * size of the bitmap _field in bits.
663 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
664 .name = (stringify(_field)), \
665 .version_id = (_version), \
666 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
667 .info = &vmstate_info_bitmap, \
668 .flags = VMS_VBUFFER|VMS_POINTER, \
669 .offset = offsetof(_state, _field), \
672 /* For migrating a QTAILQ.
673 * Target QTAILQ needs be properly initialized.
674 * _type: type of QTAILQ element
675 * _next: name of QTAILQ entry field in QTAILQ element
676 * _vmsd: VMSD for QTAILQ element
677 * size: size of QTAILQ element
678 * start: offset of QTAILQ entry in QTAILQ element
680 #define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \
682 .name = (stringify(_field)), \
683 .version_id = (_version), \
685 .size = sizeof(_type), \
686 .info = &vmstate_info_qtailq, \
687 .offset = offsetof(_state, _field), \
688 .start = offsetof(_type, _next), \
692 _f_n : num of elements field_name
694 _s : struct state name
698 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
699 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
701 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
702 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
704 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
705 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
707 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \
708 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
710 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
711 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
714 #define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \
716 VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \
717 _version, _vmsd, _type)
719 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
720 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
723 #define VMSTATE_BOOL_V(_f, _s, _v) \
724 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
726 #define VMSTATE_INT8_V(_f, _s, _v) \
727 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
728 #define VMSTATE_INT16_V(_f, _s, _v) \
729 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
730 #define VMSTATE_INT32_V(_f, _s, _v) \
731 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
732 #define VMSTATE_INT64_V(_f, _s, _v) \
733 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
735 #define VMSTATE_UINT8_V(_f, _s, _v) \
736 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
737 #define VMSTATE_UINT16_V(_f, _s, _v) \
738 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
739 #define VMSTATE_UINT32_V(_f, _s, _v) \
740 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
741 #define VMSTATE_UINT64_V(_f, _s, _v) \
742 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
744 #define VMSTATE_BOOL(_f, _s) \
745 VMSTATE_BOOL_V(_f, _s, 0)
747 #define VMSTATE_INT8(_f, _s) \
748 VMSTATE_INT8_V(_f, _s, 0)
749 #define VMSTATE_INT16(_f, _s) \
750 VMSTATE_INT16_V(_f, _s, 0)
751 #define VMSTATE_INT32(_f, _s) \
752 VMSTATE_INT32_V(_f, _s, 0)
753 #define VMSTATE_INT64(_f, _s) \
754 VMSTATE_INT64_V(_f, _s, 0)
756 #define VMSTATE_UINT8(_f, _s) \
757 VMSTATE_UINT8_V(_f, _s, 0)
758 #define VMSTATE_UINT16(_f, _s) \
759 VMSTATE_UINT16_V(_f, _s, 0)
760 #define VMSTATE_UINT32(_f, _s) \
761 VMSTATE_UINT32_V(_f, _s, 0)
762 #define VMSTATE_UINT64(_f, _s) \
763 VMSTATE_UINT64_V(_f, _s, 0)
765 #define VMSTATE_UINT8_EQUAL(_f, _s) \
766 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
768 #define VMSTATE_UINT16_EQUAL(_f, _s) \
769 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
771 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
772 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
774 #define VMSTATE_INT32_EQUAL(_f, _s) \
775 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
777 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \
778 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t)
780 #define VMSTATE_UINT32_EQUAL(_f, _s) \
781 VMSTATE_UINT32_EQUAL_V(_f, _s, 0)
783 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \
784 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
786 #define VMSTATE_UINT64_EQUAL(_f, _s) \
787 VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
789 #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \
790 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
792 #define VMSTATE_INT8_TEST(_f, _s, _t) \
793 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
795 #define VMSTATE_INT16_TEST(_f, _s, _t) \
796 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
798 #define VMSTATE_INT32_TEST(_f, _s, _t) \
799 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
801 #define VMSTATE_INT64_TEST(_f, _s, _t) \
802 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
804 #define VMSTATE_UINT8_TEST(_f, _s, _t) \
805 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
807 #define VMSTATE_UINT16_TEST(_f, _s, _t) \
808 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
810 #define VMSTATE_UINT32_TEST(_f, _s, _t) \
811 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
813 #define VMSTATE_UINT64_TEST(_f, _s, _t) \
814 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
817 #define VMSTATE_FLOAT64_V(_f, _s, _v) \
818 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
820 #define VMSTATE_FLOAT64(_f, _s) \
821 VMSTATE_FLOAT64_V(_f, _s, 0)
823 #define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \
824 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
826 #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \
827 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
829 #define VMSTATE_TIMER_PTR(_f, _s) \
830 VMSTATE_TIMER_PTR_V(_f, _s, 0)
832 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \
833 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
835 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
836 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
838 #define VMSTATE_TIMER_V(_f, _s, _v) \
839 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
841 #define VMSTATE_TIMER(_f, _s) \
842 VMSTATE_TIMER_V(_f, _s, 0)
844 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
845 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
847 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
848 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
850 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
851 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
853 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
854 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
856 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \
857 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
859 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
860 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
862 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \
863 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
865 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \
866 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
868 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
869 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
871 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
872 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
874 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \
875 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
877 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \
878 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
880 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
881 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
883 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \
884 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
886 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
887 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
889 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \
890 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
892 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
893 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
895 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
896 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
898 #define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \
899 VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0)
901 #define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \
902 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t)
904 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
905 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
907 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \
908 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
910 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
911 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
913 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
914 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
916 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
917 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
919 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
920 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
922 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \
923 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
925 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \
926 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
928 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
929 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
931 #define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \
932 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
934 #define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \
935 VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
937 #define VMSTATE_BUFFER_V(_f, _s, _v) \
938 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
940 #define VMSTATE_BUFFER(_f, _s) \
941 VMSTATE_BUFFER_V(_f, _s, 0)
943 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
944 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
946 #define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \
947 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f)))
949 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
950 VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0)
952 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
953 VMSTATE_VBUFFER(_f, _s, 0, NULL, _size)
955 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
956 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size)
958 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
959 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
961 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
962 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
964 #define VMSTATE_UNUSED_V(_v, _size) \
965 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
967 #define VMSTATE_UNUSED(_size) \
968 VMSTATE_UNUSED_V(0, _size)
970 #define VMSTATE_UNUSED_TEST(_test, _size) \
971 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
973 #define VMSTATE_END_OF_LIST() \
976 int vmstate_load_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
977 void *opaque
, int version_id
);
978 void vmstate_save_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
979 void *opaque
, QJSON
*vmdesc
);
981 bool vmstate_save_needed(const VMStateDescription
*vmsd
, void *opaque
);
983 /* Returns: 0 on success, -1 on failure */
984 int vmstate_register_with_alias_id(DeviceState
*dev
, int instance_id
,
985 const VMStateDescription
*vmsd
,
986 void *base
, int alias_id
,
987 int required_for_version
,
990 /* Returns: 0 on success, -1 on failure */
991 static inline int vmstate_register(DeviceState
*dev
, int instance_id
,
992 const VMStateDescription
*vmsd
,
995 return vmstate_register_with_alias_id(dev
, instance_id
, vmsd
,
996 opaque
, -1, 0, NULL
);
999 void vmstate_unregister(DeviceState
*dev
, const VMStateDescription
*vmsd
,
1002 struct MemoryRegion
;
1003 void vmstate_register_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
1004 void vmstate_unregister_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
1005 void vmstate_register_ram_global(struct MemoryRegion
*memory
);
1007 bool vmstate_check_only_migratable(const VMStateDescription
*vmsd
);