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