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