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