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