All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] add VMSTATE_BOOL
Date: Mon, 8 Nov 2010 19:47:52 +0200	[thread overview]
Message-ID: <20101108174752.GC8498@redhat.com> (raw)
In-Reply-To: <1288623114-14439-1-git-send-email-kraxel@redhat.com>

On Mon, Nov 01, 2010 at 03:51:54PM +0100, Gerd Hoffmann wrote:
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/hw.h  |   14 ++++++++++++++
>  savevm.c |   21 +++++++++++++++++++++
>  2 files changed, 35 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/hw.h b/hw/hw.h
> index e935364..234c713 100644
> --- a/hw/hw.h
> +++ b/hw/hw.h
> @@ -333,6 +333,8 @@ struct VMStateDescription {
>      const VMStateSubsection *subsections;
>  };
>  
> +extern const VMStateInfo vmstate_info_bool;
> +
>  extern const VMStateInfo vmstate_info_int8;
>  extern const VMStateInfo vmstate_info_int16;
>  extern const VMStateInfo vmstate_info_int32;
> @@ -613,6 +615,9 @@ extern const VMStateDescription vmstate_i2c_slave;
>  #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
>      VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
>  
> +#define VMSTATE_BOOL_V(_f, _s, _v)                                    \
> +    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
> +
>  #define VMSTATE_INT8_V(_f, _s, _v)                                    \
>      VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
>  #define VMSTATE_INT16_V(_f, _s, _v)                                   \
> @@ -631,6 +636,9 @@ extern const VMStateDescription vmstate_i2c_slave;
>  #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
>      VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
>  
> +#define VMSTATE_BOOL(_f, _s)                                          \
> +    VMSTATE_BOOL_V(_f, _s, 0)
> +
>  #define VMSTATE_INT8(_f, _s)                                          \
>      VMSTATE_INT8_V(_f, _s, 0)
>  #define VMSTATE_INT16(_f, _s)                                         \
> @@ -685,6 +693,12 @@ extern const VMStateDescription vmstate_i2c_slave;
>  #define VMSTATE_PTIMER(_f, _s)                                        \
>      VMSTATE_PTIMER_V(_f, _s, 0)
>  
> +#define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
> +    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
> +
> +#define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
> +    VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
> +

Why don't we pack the bits?

>  #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
>      VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
>  
> diff --git a/savevm.c b/savevm.c
> index 10057f3..14268ea 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -675,6 +675,27 @@ uint64_t qemu_get_be64(QEMUFile *f)
>      return v;
>  }
>  
> +/* bool */
> +
> +static int get_bool(QEMUFile *f, void *pv, size_t size)
> +{
> +    bool *v = pv;
> +    *v = qemu_get_byte(f);
> +    return 0;

We must really validate that the value is 0 or 1.
If it's not, we will get undefined behaviour.

> +}
> +
> +static void put_bool(QEMUFile *f, void *pv, size_t size)
> +{
> +    bool *v = pv;
> +    qemu_put_byte(f, *v);

Is there a guarantee that bool is a single byte, BTW?

> +}
> +
> +const VMStateInfo vmstate_info_bool = {
> +    .name = "bool",
> +    .get  = get_bool,
> +    .put  = put_bool,
> +};
> +
>  /* 8 bit int */
>  
>  static int get_int8(QEMUFile *f, void *pv, size_t size)
> -- 
> 1.7.1
> 

  parent reply	other threads:[~2010-11-08 17:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-01 14:51 [Qemu-devel] [PATCH] add VMSTATE_BOOL Gerd Hoffmann
2010-11-01 15:08 ` [Qemu-devel] " malc
2010-11-08 17:47 ` Michael S. Tsirkin [this message]
2010-11-09  9:23   ` Markus Armbruster
2010-11-09  9:32     ` Paolo Bonzini
2010-11-09  9:37   ` Gerd Hoffmann
2010-11-09 11:34     ` Michael S. Tsirkin
2010-11-09 11:50       ` Gerd Hoffmann
2010-11-09 13:05         ` Michael S. Tsirkin
2010-11-09 13:28           ` Gerd Hoffmann
2010-11-09 13:37             ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101108174752.GC8498@redhat.com \
    --to=mst@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.