vmstate.h: Type check VMSTATE_STRUCT_VARRAY macros
commit0c413ba0d87c1c0444b5aaec050ba86f33409474
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 26 Jul 2019 14:40:28 +0000 (26 15:40 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 26 Jul 2019 15:17:56 +0000 (26 16:17 +0100)
treebb70eb013b09d26978f24405971ed242a7c7d5fc
parent372e458ebc41c980d4fa23e3234a5222813cd405
vmstate.h: Type check VMSTATE_STRUCT_VARRAY macros

The VMSTATE_STRUCT_VARRAY_UINT32 macro is intended to handle
migrating a field which is an array of structs, but where instead of
migrating the entire array we only migrate a variable number of
elements of it.

The VMSTATE_STRUCT_VARRAY_POINTER_UINT32 macro is intended to handle
migrating a field which is of pointer type, and points to a
dynamically allocated array of structs of variable size.

We weren't actually checking that the field passed to
VMSTATE_STRUCT_VARRAY_UINT32 really is an array, with the result that
accidentally using it where the _POINTER_ macro was intended would
compile but silently corrupt memory on migration.

Add type-checking that enforces that the field passed in is
really of the right array type. This applies to all the VMSTATE
macros which use flags including VMS_VARRAY_* but not VMS_POINTER.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Tested-by: Damien Hedde <damien.hedde@greensocs.com>
Message-id: 20190725163710.11703-3-peter.maydell@linaro.org
include/migration/vmstate.h