From patchwork Thu Aug 20 17:42:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 31767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 7E48CB7B3E for ; Fri, 21 Aug 2009 04:16:56 +1000 (EST) Received: from localhost ([127.0.0.1]:59416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeCBw-0005k5-Fd for incoming@patchwork.ozlabs.org; Thu, 20 Aug 2009 14:16:52 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeBhY-0006Tc-4F for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeBhQ-0006Mi-Sz for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:25 -0400 Received: from [199.232.76.173] (port=39158 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeBhQ-0006MW-Ce for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50812) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MeBhP-0006zI-NX for qemu-devel@nongnu.org; Thu, 20 Aug 2009 13:45:20 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7KHjHKh022058 for ; Thu, 20 Aug 2009 13:45:17 -0400 Received: from localhost.localdomain (vpn2-8-130.ams2.redhat.com [10.36.8.130]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7KHis4c012471; Thu, 20 Aug 2009 13:45:16 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 20 Aug 2009 19:42:35 +0200 Message-Id: <07c65885c1c4bb2cd57b9f7a64b236a4deae2667.1250788880.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 17/23] Add VMState support for static sized buffers (uint_8) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds support for static sized buffer and typecheks that the buffer is right. Signed-off-by: Juan Quintela --- hw/hw.h | 18 ++++++++++++++++++ savevm.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index 911ab6f..4713967 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -284,6 +284,7 @@ enum VMStateFlags { VMS_ARRAY = 0x004, VMS_STRUCT = 0x008, VMS_VARRAY = 0x010, /* Array with size in another field */ + VMS_BUFFER = 0x020, /* static sized buffer */ }; typedef struct { @@ -320,6 +321,7 @@ extern const VMStateInfo vmstate_info_uint32; extern const VMStateInfo vmstate_info_uint64; extern const VMStateInfo vmstate_info_timer; +extern const VMStateInfo vmstate_info_buffer; #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) @@ -388,6 +390,16 @@ extern const VMStateInfo vmstate_info_timer; + type_check_array(_type,typeof_field(_state, _field),_num) \ } +#define VMSTATE_STATIC_BUFFER(_field, _state, _version) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .size = sizeof(typeof_field(_state,_field)), \ + .info = &vmstate_info_buffer, \ + .flags = VMS_BUFFER, \ + .offset = offsetof(_state, _field) \ + + type_check_array(uint8_t,typeof_field(_state, _field),sizeof(typeof_field(_state,_field))) \ +} + /* _f : field name _f_n : num of elements field_name _n : num of elements @@ -458,6 +470,12 @@ extern const VMStateInfo vmstate_info_timer; #define VMSTATE_INT32_VARRAY(_f, _s, _f_n) \ VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0) +#define VMSTATE_BUFFER_V(_f, _s, _v) \ + VMSTATE_STATIC_BUFFER(_f, _s, _v) + +#define VMSTATE_BUFFER(_f, _s) \ + VMSTATE_STATIC_BUFFER(_f, _s, 0) + #define VMSTATE_END_OF_LIST() \ {} diff --git a/savevm.c b/savevm.c index 721bbf4..1b448b9 100644 --- a/savevm.c +++ b/savevm.c @@ -819,6 +819,27 @@ const VMStateInfo vmstate_info_timer = { .put = put_timer, }; +/* uint8_t buffers */ + +static int get_buffer(QEMUFile *f, void *pv, size_t size) +{ + uint8_t *v = pv; + qemu_get_buffer(f, v, size); + return 0; +} + +static void put_buffer(QEMUFile *f, const void *pv, size_t size) +{ + uint8_t *v = (void *)pv; + qemu_put_buffer(f, v, size); +} + +const VMStateInfo vmstate_info_buffer = { + .name = "buffer", + .get = get_buffer, + .put = put_buffer, +}; + typedef struct SaveStateEntry { char idstr[256]; int instance_id;