From nobody Tue Apr 30 13:41:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487247233786258.05825630039385; Thu, 16 Feb 2017 04:13:53 -0800 (PST) Received: from localhost ([::1]:46018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKwX-0002BL-9n for importer@patchew.org; Thu, 16 Feb 2017 07:13:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKv0-0000Qg-7x for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceKux-0002cl-17 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60667 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ceKuw-0002Zi-Qe for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:10 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1GC3aZx131139 for ; Thu, 16 Feb 2017 07:12:09 -0500 Received: from e06smtp09.uk.ibm.com (e06smtp09.uk.ibm.com [195.75.94.105]) by mx0b-001b2d01.pphosted.com with ESMTP id 28n9b66pkv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Feb 2017 07:12:09 -0500 Received: from localhost by e06smtp09.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Feb 2017 12:12:07 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp09.uk.ibm.com (192.168.101.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Feb 2017 12:12:05 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2D50F219004D; Thu, 16 Feb 2017 12:11:07 +0000 (GMT) Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1GCC4vK15073724; Thu, 16 Feb 2017 12:12:04 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E44E952052; Thu, 16 Feb 2017 11:10:44 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id B14A052041; Thu, 16 Feb 2017 11:10:44 +0000 (GMT) From: Halil Pasic To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" Date: Thu, 16 Feb 2017 13:11:36 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> References: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021612-0036-0000-0000-0000036E454A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021612-0037-0000-0000-000015227478 Message-Id: <20170216121140.9061-2-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-16_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702160121 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 1/5] migration/vmstate: renames in (load|save)_state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The vmstate_(load|save)_state start out with an a void *opaque pointing to some struct, and manipulate one or more elements of one field within that struct. First the field within the struct is pinpointed as opaque + offset, then if this is a pointer the pointer is dereferenced to obtain a pointer to the first element of the vmstate field. Pointers to further elements if any are calculated as first_element + i * element_size (where i is the zero based index of the element in question). Currently base_addr and addr is used as a variable name for the pointer to the first element and the pointer to the current element being processed. This is suboptimal because base_addr is somewhat counter-intuitive (because obtained as base + offset) and both base_addr and addr not very descriptive (that we have a pointer should be clear from the fact that it is declared as a pointer). Let make things easier to understand by renaming base_addr to first_elem and addr to curr_elem. This has the additional benefit of harmonizing with other names within the scope (n_elems, vmstate_n_elems). Signed-off-by: Halil Pasic Reviewed-by: Dr. David Alan Gilbert --- This patch roots in the difficulties I faced when trying to figure out the code in question. In the meanwhile I'm quite fine with the current names because I have it already figured out (after a couple of months not looking on this code however, who knows). Thus my main motivation is making things easier for the next new guy, but if the old guys say not worth it I can very well accept that too. --- migration/vmstate.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index b4d8ae9..36efa80 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -116,21 +116,21 @@ int vmstate_load_state(QEMUFile *f, const VMStateDesc= ription *vmsd, field->field_exists(opaque, version_id)) || (!field->field_exists && field->version_id <=3D version_id)) { - void *base_addr =3D vmstate_base_addr(opaque, field, true); + void *first_elem =3D vmstate_base_addr(opaque, field, true); int i, n_elems =3D vmstate_n_elems(opaque, field); int size =3D vmstate_size(opaque, field); =20 for (i =3D 0; i < n_elems; i++) { - void *addr =3D base_addr + size * i; + void *curr_elem =3D first_elem + size * i; =20 if (field->flags & VMS_ARRAY_OF_POINTER) { - addr =3D *(void **)addr; + curr_elem =3D *(void **)curr_elem; } if (field->flags & VMS_STRUCT) { - ret =3D vmstate_load_state(f, field->vmsd, addr, + ret =3D vmstate_load_state(f, field->vmsd, curr_elem, field->vmsd->version_id); } else { - ret =3D field->info->get(f, addr, size, field); + ret =3D field->info->get(f, curr_elem, size, field); } if (ret >=3D 0) { ret =3D qemu_file_get_error(f); @@ -321,7 +321,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescr= iption *vmsd, while (field->name) { if (!field->field_exists || field->field_exists(opaque, vmsd->version_id)) { - void *base_addr =3D vmstate_base_addr(opaque, field, false); + void *first_elem =3D vmstate_base_addr(opaque, field, false); int i, n_elems =3D vmstate_n_elems(opaque, field); int size =3D vmstate_size(opaque, field); int64_t old_offset, written_bytes; @@ -329,18 +329,18 @@ void vmstate_save_state(QEMUFile *f, const VMStateDes= cription *vmsd, =20 trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems= ); for (i =3D 0; i < n_elems; i++) { - void *addr =3D base_addr + size * i; + void *curr_elem =3D first_elem + size * i; =20 vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems= ); old_offset =3D qemu_ftell_fast(f); - if (field->flags & VMS_ARRAY_OF_POINTER) { - addr =3D *(void **)addr; + assert(curr_elem); + curr_elem =3D *(void **)curr_elem; } if (field->flags & VMS_STRUCT) { - vmstate_save_state(f, field->vmsd, addr, vmdesc_loop); + vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_l= oop); } else { - field->info->put(f, addr, size, field, vmdesc_loop); + field->info->put(f, curr_elem, size, field, vmdesc_loo= p); } =20 written_bytes =3D qemu_ftell_fast(f) - old_offset; --=20 2.8.4 From nobody Tue Apr 30 13:41:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487247327846782.0407256089865; Thu, 16 Feb 2017 04:15:27 -0800 (PST) Received: from localhost ([::1]:46027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKy5-0003TJ-3T for importer@patchew.org; Thu, 16 Feb 2017 07:15:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKv2-0000XD-B6 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceKuz-0002iE-3T for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:16 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38509) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ceKuy-0002fN-Pq for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:13 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1GC3ZeS009698 for ; Thu, 16 Feb 2017 07:12:11 -0500 Received: from e06smtp06.uk.ibm.com (e06smtp06.uk.ibm.com [195.75.94.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 28n8jtgn2s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Feb 2017 07:12:11 -0500 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Feb 2017 12:12:08 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp06.uk.ibm.com (192.168.101.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Feb 2017 12:12:06 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7A7452190056; Thu, 16 Feb 2017 12:11:08 +0000 (GMT) Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1GCC5PT20382048; Thu, 16 Feb 2017 12:12:05 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 34D2C52047; Thu, 16 Feb 2017 11:10:46 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id EA8675203F; Thu, 16 Feb 2017 11:10:45 +0000 (GMT) From: Halil Pasic To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" Date: Thu, 16 Feb 2017 13:11:37 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> References: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021612-0024-0000-0000-000002B74813 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021612-0025-0000-0000-0000226D86E8 Message-Id: <20170216121140.9061-3-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-16_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702160121 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 2/5] migration/vmstate: split up vmstate_base_addr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently vmstate_base_addr does several things: it pinpoints the field within the struct, possibly allocates memory and possibly does the first pointer dereference. Obviously allocation is needed only for load. Let us split up the functionality in vmstate_base_addr and move the address manipulations (that is everything but the allocation logic) to load and save so it becomes more obvious what is actually going on. Like this all the address calculations (and the handling of the flags controlling these) is in one place and the sequence is more obvious. The newly introduced function vmstate_handle_alloc also fixes the allocation for the unused VMS_VBUFFER| VMS_MULTIPLY scenario and is substantially simpler than the original vmstate_base_addr. In load and save some asserts are added so it's easier to debug situations where we would end up with a null pointer dereference. Signed-off-by: Halil Pasic Reviewed-by: Dr. David Alan Gilbert --- migration/vmstate.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 36efa80..836a7a4 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -52,29 +52,15 @@ static int vmstate_size(void *opaque, VMStateField *fie= ld) return size; } =20 -static void *vmstate_base_addr(void *opaque, VMStateField *field, bool all= oc) +static void vmstate_handle_alloc(void *ptr, VMStateField *field, void *opa= que) { - void *base_addr =3D opaque + field->offset; - - if (field->flags & VMS_POINTER) { - if (alloc && (field->flags & VMS_ALLOC)) { - gsize size =3D 0; - if (field->flags & VMS_VBUFFER) { - size =3D vmstate_size(opaque, field); - } else { - int n_elems =3D vmstate_n_elems(opaque, field); - if (n_elems) { - size =3D n_elems * field->size; - } - } - if (size) { - *(void **)base_addr =3D g_malloc(size); - } + if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { + gsize size =3D vmstate_size(opaque, field); + size *=3D vmstate_n_elems(opaque, field); + if (size) { + *(void **)ptr =3D g_malloc(size); } - base_addr =3D *(void **)base_addr; } - - return base_addr; } =20 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, @@ -116,10 +102,15 @@ int vmstate_load_state(QEMUFile *f, const VMStateDesc= ription *vmsd, field->field_exists(opaque, version_id)) || (!field->field_exists && field->version_id <=3D version_id)) { - void *first_elem =3D vmstate_base_addr(opaque, field, true); + void *first_elem =3D opaque + field->offset; int i, n_elems =3D vmstate_n_elems(opaque, field); int size =3D vmstate_size(opaque, field); =20 + vmstate_handle_alloc(first_elem, field, opaque); + if (field->flags & VMS_POINTER) { + first_elem =3D *(void **)first_elem; + assert(first_elem || !n_elems); + } for (i =3D 0; i < n_elems; i++) { void *curr_elem =3D first_elem + size * i; =20 @@ -321,13 +312,17 @@ void vmstate_save_state(QEMUFile *f, const VMStateDes= cription *vmsd, while (field->name) { if (!field->field_exists || field->field_exists(opaque, vmsd->version_id)) { - void *first_elem =3D vmstate_base_addr(opaque, field, false); + void *first_elem =3D opaque + field->offset; int i, n_elems =3D vmstate_n_elems(opaque, field); int size =3D vmstate_size(opaque, field); int64_t old_offset, written_bytes; QJSON *vmdesc_loop =3D vmdesc; =20 trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems= ); + if (field->flags & VMS_POINTER) { + first_elem =3D *(void **)first_elem; + assert(first_elem || !n_elems); + } for (i =3D 0; i < n_elems; i++) { void *curr_elem =3D first_elem + size * i; =20 --=20 2.8.4 From nobody Tue Apr 30 13:41:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487247486989693.1278449947101; Thu, 16 Feb 2017 04:18:06 -0800 (PST) Received: from localhost ([::1]:46047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceL0c-0005u7-QF for importer@patchew.org; Thu, 16 Feb 2017 07:18:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKv2-0000YK-MZ for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceKuz-0002is-Dw for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:16 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56972 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ceKuz-0002hF-8F for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:13 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1GC3bT3083605 for ; Thu, 16 Feb 2017 07:12:12 -0500 Received: from e06smtp09.uk.ibm.com (e06smtp09.uk.ibm.com [195.75.94.105]) by mx0b-001b2d01.pphosted.com with ESMTP id 28n823sr8u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Feb 2017 07:12:12 -0500 Received: from localhost by e06smtp09.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Feb 2017 12:12:10 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp09.uk.ibm.com (192.168.101.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Feb 2017 12:12:07 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id B3B3A219004D; Thu, 16 Feb 2017 12:11:09 +0000 (GMT) Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1GCC7dE24117354; Thu, 16 Feb 2017 12:12:07 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7319352041; Thu, 16 Feb 2017 11:10:47 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 34E1C52047; Thu, 16 Feb 2017 11:10:47 +0000 (GMT) From: Halil Pasic To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" Date: Thu, 16 Feb 2017 13:11:38 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> References: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021612-0036-0000-0000-0000036E4555 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021612-0037-0000-0000-00001522748D Message-Id: <20170216121140.9061-4-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-16_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702160121 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 3/5] migration/vmstate: fix array of ptr with nullptrs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make VMS_ARRAY_OF_POINTER cope with null pointers. Previously the reward for trying to migrate an array with some null pointers in it was an illegal memory access, that is a swift and painless death of the process. Let's make vmstate cope with this scenario. The general approach is, when we encounter a null pointer (element), instead of following the pointer to save/load the data behind it, we save/load a placeholder. This way we can detect if we expected a null pointer at the load side but not null data was saved instead. Signed-off-by: Halil Pasic Reviewed-by: Guenther Hutzl --- We will need this to load/save some on demand created state in the (s390x) channel subsystem (see ChannelSubSys.css in hw/s390x/css.c for an example). --- include/migration/vmstate.h | 4 ++++ migration/vmstate.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 63e7b02..f2dbf84 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -253,6 +253,10 @@ extern const VMStateInfo vmstate_info_uint16; extern const VMStateInfo vmstate_info_uint32; extern const VMStateInfo vmstate_info_uint64; =20 +/** Put this in the stream when migrating a null pointer.*/ +#define VMS_NULLPTR_MARKER (0x30U) /* '0' */ +extern const VMStateInfo vmstate_info_nullptr; + extern const VMStateInfo vmstate_info_float64; extern const VMStateInfo vmstate_info_cpudouble; =20 diff --git a/migration/vmstate.c b/migration/vmstate.c index 836a7a4..cb81cef 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -117,7 +117,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescr= iption *vmsd, if (field->flags & VMS_ARRAY_OF_POINTER) { curr_elem =3D *(void **)curr_elem; } - if (field->flags & VMS_STRUCT) { + if (!curr_elem) { + /* if null pointer check placeholder and do not follow= */ + assert(field->flags & VMS_ARRAY_OF_POINTER); + vmstate_info_nullptr.get(f, curr_elem, size, NULL); + } else if (field->flags & VMS_STRUCT) { ret =3D vmstate_load_state(f, field->vmsd, curr_elem, field->vmsd->version_id); } else { @@ -332,7 +336,11 @@ void vmstate_save_state(QEMUFile *f, const VMStateDesc= ription *vmsd, assert(curr_elem); curr_elem =3D *(void **)curr_elem; } - if (field->flags & VMS_STRUCT) { + if (!curr_elem) { + /* if null pointer write placeholder and do not follow= */ + assert(field->flags & VMS_ARRAY_OF_POINTER); + vmstate_info_nullptr.put(f, curr_elem, size, NULL, NUL= L); + } else if (field->flags & VMS_STRUCT) { vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_l= oop); } else { field->info->put(f, curr_elem, size, field, vmdesc_loo= p); @@ -747,6 +755,27 @@ const VMStateInfo vmstate_info_uint64 =3D { .put =3D put_uint64, }; =20 +static int get_nullptr(QEMUFile *f, void *pv, size_t size, VMStateField *f= ield) + +{ + return qemu_get_byte(f) =3D=3D VMS_NULLPTR_MARKER ? 0 : -EINVAL; +} + +static int put_nullptr(QEMUFile *f, void *pv, size_t size, + VMStateField *field, QJSON *vmdesc) + +{ + assert(pv =3D=3D NULL); + qemu_put_byte(f, VMS_NULLPTR_MARKER); + return 0; +} + +const VMStateInfo vmstate_info_nullptr =3D { + .name =3D "uint64", + .get =3D get_nullptr, + .put =3D put_nullptr, +}; + /* 64 bit unsigned int. See that the received value is the same than the o= ne in the field */ =20 --=20 2.8.4 From nobody Tue Apr 30 13:41:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487247605937421.35652638537385; Thu, 16 Feb 2017 04:20:05 -0800 (PST) Received: from localhost ([::1]:46051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceL2a-0007C1-Bw for importer@patchew.org; Thu, 16 Feb 2017 07:20:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKv4-0000dc-MH for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceKv1-0002ny-BZ for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:18 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ceKv1-0002kv-1z for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:15 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1GC3i9l021256 for ; Thu, 16 Feb 2017 07:12:14 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 28n7cquh5m-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Feb 2017 07:12:13 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Feb 2017 12:12:10 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Feb 2017 12:12:08 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id DEFEC2190023; Thu, 16 Feb 2017 12:11:10 +0000 (GMT) Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1GCC8kx6684970; Thu, 16 Feb 2017 12:12:08 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A1FE552041; Thu, 16 Feb 2017 11:10:48 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 730215203F; Thu, 16 Feb 2017 11:10:48 +0000 (GMT) From: Halil Pasic To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" Date: Thu, 16 Feb 2017 13:11:39 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> References: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021612-0028-0000-0000-000002AC3BEF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021612-0029-0000-0000-000022666925 Message-Id: <20170216121140.9061-5-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-16_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702160121 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 4/5] tests/test-vmstate.c: test array of ptr with null X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add test for VMSTATE_ARRAY_OF_POINTER_TO_STRUCT with an array containing some null pointer. Signed-off-by: Halil Pasic Reviewed-by: Dr. David Alan Gilbert --- tests/test-vmstate.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++= +++ 1 file changed, 51 insertions(+) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index d0dd390..b68a0b3 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -487,6 +487,8 @@ const VMStateDescription vmsd_tst =3D { } }; =20 +/* test array migration */ + #define AR_SIZE 4 =20 typedef struct { @@ -542,6 +544,52 @@ static void test_arr_ptr_str_no0_load(void) } } =20 +static void test_arr_ptr_str_0_save(void) +{ + TestStructTriv ar[AR_SIZE] =3D {{.i =3D 0}, {.i =3D 1}, {.i =3D 2}, {.= i =3D 3} }; + TestArrayOfPtrToStuct sample =3D {.ar =3D {&ar[0], NULL, &ar[2], &ar[3= ]} }; + uint8_t wire_sample[] =3D { + 0x00, 0x00, 0x00, 0x00, + VMS_NULLPTR_MARKER, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, + QEMU_VM_EOF + }; + + save_vmstate(&vmsd_arps, &sample); + compare_vmstate(wire_sample, sizeof(wire_sample)); +} + +static void test_arr_ptr_str_0_load(void) +{ + TestStructTriv ar_gt[AR_SIZE] =3D {{.i =3D 0}, {.i =3D 0}, {.i =3D 2},= {.i =3D 3} }; + TestStructTriv ar[AR_SIZE] =3D {}; + TestArrayOfPtrToStuct obj =3D {.ar =3D {&ar[0], NULL, &ar[2], &ar[3]} = }; + int idx; + uint8_t wire_sample[] =3D { + 0x00, 0x00, 0x00, 0x00, + VMS_NULLPTR_MARKER, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, + QEMU_VM_EOF + }; + + save_buffer(wire_sample, sizeof(wire_sample)); + SUCCESS(load_vmstate_one(&vmsd_arps, &obj, 1, + wire_sample, sizeof(wire_sample))); + for (idx =3D 0; idx < AR_SIZE; ++idx) { + /* compare the target array ar with the ground truth array ar_gt */ + g_assert_cmpint(ar_gt[idx].i, =3D=3D, ar[idx].i); + } + for (idx =3D 0; idx < AR_SIZE; ++idx) { + if (idx =3D=3D 1) { + g_assert_cmpint((uint64_t)(obj.ar[idx]), =3D=3D, 0); + } else { + g_assert_cmpint((uint64_t)(obj.ar[idx]), !=3D, 0); + } + } +} + /* test QTAILQ migration */ typedef struct TestQtailqElement TestQtailqElement; =20 @@ -792,6 +840,9 @@ int main(int argc, char **argv) test_arr_ptr_str_no0_save); g_test_add_func("/vmstate/array/ptr/str/no0/load", test_arr_ptr_str_no0_load); + g_test_add_func("/vmstate/array/ptr/str/0/save", test_arr_ptr_str_0_sa= ve); + g_test_add_func("/vmstate/array/ptr/str/0/load", + test_arr_ptr_str_0_load); g_test_add_func("/vmstate/qtailq/save/saveq", test_save_q); g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q); g_test_add_func("/vmstate/tmp_struct", test_tmp_struct); --=20 2.8.4 From nobody Tue Apr 30 13:41:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487247723325109.10162465802716; Thu, 16 Feb 2017 04:22:03 -0800 (PST) Received: from localhost ([::1]:46061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceL4T-0008RV-Ug for importer@patchew.org; Thu, 16 Feb 2017 07:22:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceKv6-0000kb-N7 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceKv0-0002mS-OS for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:20 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40860 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ceKv0-0002kh-IS for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:12:14 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1GC3a4e030407 for ; Thu, 16 Feb 2017 07:12:14 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 28n6ua4k4s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Feb 2017 07:12:13 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Feb 2017 12:12:12 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Feb 2017 12:12:10 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 4DB5D1B08023; Thu, 16 Feb 2017 12:15:06 +0000 (GMT) Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1GCC9eP9175464; Thu, 16 Feb 2017 12:12:09 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D1D7B52049; Thu, 16 Feb 2017 11:10:49 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id A2CA85203F; Thu, 16 Feb 2017 11:10:49 +0000 (GMT) From: Halil Pasic To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" Date: Thu, 16 Feb 2017 13:11:40 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> References: <20170216121140.9061-1-pasic@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021612-0012-0000-0000-000004CF47D2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021612-0013-0000-0000-000017466C03 Message-Id: <20170216121140.9061-6-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-16_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702160121 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 5/5] tests/test-vmstate.c: test array of ptr to primitive X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's have a test for ptr arrays to some primitive type with some not-null and null ptrs intermixed. Signed-off-by: Halil Pasic Reviewed-by: Dr. David Alan Gilbert --- Mainly for the sake of completeness and also to demonstrate that it works since in the previous version I wrongly stated it does not. If guys think we do not need this, I'm happy with just dropping it. --- tests/test-vmstate.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 62 insertions(+) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index b68a0b3..82ab743 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -590,6 +590,64 @@ static void test_arr_ptr_str_0_load(void) } } =20 +typedef struct TestArrayOfPtrToInt { + int32_t *ar[AR_SIZE]; +} TestArrayOfPtrToInt; + +const VMStateDescription vmsd_arpp =3D { + .name =3D "test/arps", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_ARRAY_OF_POINTER(ar, TestArrayOfPtrToInt, + AR_SIZE, 0, vmstate_info_int32, int32_t*), + VMSTATE_END_OF_LIST() + } +}; + +static void test_arr_ptr_prim_0_save(void) +{ + int32_t ar[AR_SIZE] =3D {0 , 1, 2, 3}; + TestArrayOfPtrToInt sample =3D {.ar =3D {&ar[0], NULL, &ar[2], &ar[3]= } }; + uint8_t wire_sample[] =3D { + 0x00, 0x00, 0x00, 0x00, + VMS_NULLPTR_MARKER, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, + QEMU_VM_EOF + }; + + save_vmstate(&vmsd_arpp, &sample); + compare_vmstate(wire_sample, sizeof(wire_sample)); +} + +static void test_arr_ptr_prim_0_load(void) +{ + int32_t ar_gt[AR_SIZE] =3D {0, 1, 2, 3}; + int32_t ar[AR_SIZE] =3D {3 , 42, 1, 0}; + TestArrayOfPtrToInt obj =3D {.ar =3D {&ar[0], NULL, &ar[2], &ar[3]} }; + int idx; + uint8_t wire_sample[] =3D { + 0x00, 0x00, 0x00, 0x00, + VMS_NULLPTR_MARKER, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, + QEMU_VM_EOF + }; + + save_buffer(wire_sample, sizeof(wire_sample)); + SUCCESS(load_vmstate_one(&vmsd_arpp, &obj, 1, + wire_sample, sizeof(wire_sample))); + for (idx =3D 0; idx < AR_SIZE; ++idx) { + /* compare the target array ar with the ground truth array ar_gt */ + if (idx =3D=3D 1) { + g_assert_cmpint(42, =3D=3D, ar[idx]); + } else { + g_assert_cmpint(ar_gt[idx], =3D=3D, ar[idx]); + } + } +} + /* test QTAILQ migration */ typedef struct TestQtailqElement TestQtailqElement; =20 @@ -843,6 +901,10 @@ int main(int argc, char **argv) g_test_add_func("/vmstate/array/ptr/str/0/save", test_arr_ptr_str_0_sa= ve); g_test_add_func("/vmstate/array/ptr/str/0/load", test_arr_ptr_str_0_load); + g_test_add_func("/vmstate/array/ptr/prim/0/save", + test_arr_ptr_prim_0_save); + g_test_add_func("/vmstate/array/ptr/prim/0/load", + test_arr_ptr_prim_0_load); g_test_add_func("/vmstate/qtailq/save/saveq", test_save_q); g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q); g_test_add_func("/vmstate/tmp_struct", test_tmp_struct); --=20 2.8.4