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