qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Filip Navara <filip.navara@gmail.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: aliguori@us.ibm.com, jan.kiszka@siemens.com, dlaor@redhat.com,
	qemu-devel@nongnu.org, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] Re: [PATCH 01/25] Introduce QEMU dictionary data type
Date: Thu, 30 Jul 2009 17:04:02 +0200	[thread overview]
Message-ID: <5b31733c0907300804n5ccb1c7cla77e193b90718eb6@mail.gmail.com> (raw)
In-Reply-To: <20090730115051.53495100@doriath>

On Thu, Jul 30, 2009 at 4:50 PM, Luiz Capitulino<lcapitulino@redhat.com> wrote:
> On Wed, 29 Jul 2009 19:19:38 +0300
> Avi Kivity <avi@redhat.com> wrote:
>
>> On 07/29/2009 07:11 PM, Luiz Capitulino wrote:
>> > Btw, the patches that ports command handlers have some void * to
>> > long type conversions (eg. patch 14) can someone please review
>> > them?
>> >
>> >   I'm not 100% confident about them.
>> >
>>
>> Casting long to void * may lose precision on some hosts (Windows x64).
>> Much better off casting the void * to a long * and dereferencing (and
>> deallocating later).
>
>  I was going to work on this when I remembered I have copied
> current's code behavior in this regard, and I _guess_ it may
> be correct.
>
>  The monitor accepts four argument types which have integer
> representation: '/' (the fmt one), '-' (optional), 'i' (integer)
> and 'l' (long).
>
>  The optional '-' is a bool, so it won't cause problems.
>
>  The format one '/' actually expands for three arguments: 'count',
> 'format' and 'size'. 'format' and 'size' are small integers, won't
> cause problems. Now 'count' is used to tell 'how much to print',
> this could cause problems in theory, although I think it won't
> happen in practice.
>
>  The integer type 'i' has this cast (monitor.c:2786):
>
> args[nb_args++] = (void *)(long)val;
>
>  'val' is int64_t.
>

Even if 32-bit values are used this will cause warning on MinGW64, it
is better to use intptr_t for these conversions. I have some
preliminary patches to fix this for the code that is currently in GIT,
but I won't mind if long is used for now and everything is fixed later
at once.

>  The bad news: if we use a > 32 integer here, there will be
> problems on Windows x64. The good news: as far as I could
> understand the handlers, this won't happen in practice.

It should be limited to 32-bits because of 32-bit hosts.

>  Most handlers use the 'i' type for small integers, the only
> exception are the handlers using it to represent addresses. This
> seems to be the case of do_ioport_{read,write} (which
> seems safe) and do_sum(), which is the only true problem
> (although doesn't seem serious to me).
>
>  We could define that 'i' is 32bits and put an assertion
> there, that will check if more than 32bits are being used.

...or just do (void*)(intptr_t)(int)val and watch when it breaks ;-)

>  Now the cool part. The 'l' (long) type is the one that should
> be used to store 64bits values, I think it handles it
> correctly (monitor.c:2790):
>
> #if TARGET_PHYS_ADDR_BITS > 32
>                    args[nb_args++] = (void *)(long)((val >> 32) & 0xffffffff);
> #else
>                    args[nb_args++] = (void *)0;
> #endif
>                    args[nb_args++] = (void *)(long)(val & 0xffffffff);
>
>  'val' is the same int64_t.

Again, intptr_t should be used here in long term. long is probably
fine for now before I post the Win64 patches.

>  In the dictionary patchset, this type will push the 'high' and
> 'low' values.
>
>  Considering all this explanation, I think the patchset is safe,
> in the worst case it's does the same thing as current code does.
>
>  Do you agree?

Agreed.

>  A last comment. My patches introduce explicit casting, as in:
>
> int index = (long) qemu_dict_get(qdict, "index");
>
>  Although the current code doesn't do that, it passes the
> 'arg[]' contents to handlers, I *guess* the compiler will
> do the same kind of casting will apply.
>

Best regards,
Filip Navara

  parent reply	other threads:[~2009-07-30 15:04 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-28 22:04 [Qemu-devel] [PATCH 00/25] Monitor handlers new structure phase 1 Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 01/25] Introduce QEMU dictionary data type Luiz Capitulino
2009-07-28 22:39   ` malc
2009-07-29 13:28     ` Luiz Capitulino
2009-07-29 13:38       ` malc
2009-07-29 13:38       ` Avi Kivity
2009-07-29 15:23         ` [Qemu-devel] " Paolo Bonzini
2009-07-29 15:24         ` Paolo Bonzini
2009-07-29  9:47   ` Avi Kivity
2009-07-29  9:49     ` Avi Kivity
2009-07-29 10:42       ` François Revol
2009-07-29 13:28     ` Anthony Liguori
2009-07-29 14:05       ` Avi Kivity
2009-07-29 13:46     ` Luiz Capitulino
2009-07-29 13:57       ` Avi Kivity
2009-07-29 14:22         ` Luiz Capitulino
2009-07-29 14:37           ` Avi Kivity
2009-07-29 16:11             ` Luiz Capitulino
2009-07-29 16:19               ` Avi Kivity
2009-07-30 14:50                 ` Luiz Capitulino
2009-07-30 15:03                   ` Avi Kivity
2009-07-30 15:05                     ` Luiz Capitulino
2009-07-30 15:04                   ` Filip Navara [this message]
2009-07-30 15:13                     ` Avi Kivity
2009-07-30 15:15                       ` Filip Navara
2009-07-30 15:19                       ` Paul Brook
2009-07-28 22:04 ` [Qemu-devel] [PATCH 02/25] net: Fix do_set_link() return type Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 03/25] Add wrappers to functions used by the Monitor Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 04/25] monitor: Document missing supported argument types Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 05/25] monitor: New format for handlers " Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 06/25] monitor: Setup a dictionary with handler arguments Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 07/25] monitor: Export qemu-dict.h header Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 08/25] monitor: New GET_TLONG and GET_TPHYSADDR macros Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 09/25] monitor: Port handler_0 to use the dictionary Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 10/25] monitor: Port handler_1 " Luiz Capitulino
2009-07-28 22:04 ` [Qemu-devel] [PATCH 11/25] monitor: Port handler_2 " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 12/25] monitor: Port handler_3 " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 13/25] monitor: Port handler_4 " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 14/25] monitor: Port handler_5 " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 15/25] monitor: Port handler_6 " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 16/25] monitor: Port handler_7 " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 17/25] monitor: Drop handler_8 and handler_9 handling Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 18/25] monitor: Port handler_10 to use the dictionary Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 19/25] monitor: Split monitor_handle_command() Luiz Capitulino
2009-07-29 15:31   ` [Qemu-devel] " Paolo Bonzini
2009-07-29 15:44     ` Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 20/25] monitor: Add a new index for str_allocated[] Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 21/25] monitor: Drop args[] from monitor_parse_command() Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 22/25] monitor: Drop 'nb_args' " Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 23/25] Add check support Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 24/25] Introduce dictionary test data file Luiz Capitulino
2009-07-28 22:05 ` [Qemu-devel] [PATCH 25/25] Introduce qemu-dict unit-tests Luiz Capitulino

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=5b31733c0907300804n5ccb1c7cla77e193b90718eb6@mail.gmail.com \
    --to=filip.navara@gmail.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=dlaor@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=lcapitulino@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).