qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-headers: Fix type cast warning for 64 bit MinGW-w64
@ 2015-09-08 19:11 Stefan Weil
  2015-09-08 19:15 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Weil @ 2015-09-08 19:11 UTC (permalink / raw)
  To: QEMU Developer; +Cc: Stefan Weil, Michael S. Tsirkin

Type casts from pointers to unsigned long don't work on 64 bit Windows
because both types have different size.

Compiler warning:

include/standard-headers/linux/virtio_ring.h:146:23:
 warning: cast from pointer to integer of different size
 [-Wpointer-to-int-cast]
  vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + ...
                       ^

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---

This is a modification of a Linux header file,
something we usually try to avoid.

I did not succeed in removing this header from compilations
for Windows (which would have been the best solution).

Nor do I expect that Linux would accept a patch which
modifies code to better support compilations for Windows.

Are there other possibilities how this could be handled?

Regards
Stefan

 include/standard-headers/linux/virtio_ring.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/standard-headers/linux/virtio_ring.h b/include/standard-headers/linux/virtio_ring.h
index 6fe276f..3d531f7 100644
--- a/include/standard-headers/linux/virtio_ring.h
+++ b/include/standard-headers/linux/virtio_ring.h
@@ -143,7 +143,7 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
 	vr->num = num;
 	vr->desc = p;
 	vr->avail = p + num*sizeof(struct vring_desc);
-	vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16)
+	vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16)
 		+ align-1) & ~(align - 1));
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-headers: Fix type cast warning for 64 bit MinGW-w64
  2015-09-08 19:11 [Qemu-devel] [PATCH] linux-headers: Fix type cast warning for 64 bit MinGW-w64 Stefan Weil
@ 2015-09-08 19:15 ` Peter Maydell
  2015-09-09  6:43   ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2015-09-08 19:15 UTC (permalink / raw)
  To: Stefan Weil; +Cc: QEMU Developer, Michael S. Tsirkin

On 8 September 2015 at 20:11, Stefan Weil <sw@weilnetz.de> wrote:
> Type casts from pointers to unsigned long don't work on 64 bit Windows
> because both types have different size.
>
> Compiler warning:
>
> include/standard-headers/linux/virtio_ring.h:146:23:
>  warning: cast from pointer to integer of different size
>  [-Wpointer-to-int-cast]
>   vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + ...
>                        ^
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> This is a modification of a Linux header file,
> something we usually try to avoid.
>
> I did not succeed in removing this header from compilations
> for Windows (which would have been the best solution).

No, this header is supposed to work everywhere (that's why
it's in standard-headers/ rather than linux-headers),
because virtio devices must work everywhere. We need to
improve the process which creates it from the kernel header
by automatedly fixing up non-portable constructs
(which is handled by scripts/update-linux-headers.sh).
Some extra seddery in cp_virtio() is probably required.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-headers: Fix type cast warning for 64 bit MinGW-w64
  2015-09-08 19:15 ` Peter Maydell
@ 2015-09-09  6:43   ` Michael S. Tsirkin
  0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2015-09-09  6:43 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Stefan Weil, thuth, QEMU Developer

On Tue, Sep 08, 2015 at 08:15:50PM +0100, Peter Maydell wrote:
> On 8 September 2015 at 20:11, Stefan Weil <sw@weilnetz.de> wrote:
> > Type casts from pointers to unsigned long don't work on 64 bit Windows
> > because both types have different size.
> >
> > Compiler warning:
> >
> > include/standard-headers/linux/virtio_ring.h:146:23:
> >  warning: cast from pointer to integer of different size
> >  [-Wpointer-to-int-cast]
> >   vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + ...
> >                        ^
> >
> > Signed-off-by: Stefan Weil <sw@weilnetz.de>
> > ---
> >
> > This is a modification of a Linux header file,
> > something we usually try to avoid.
> >
> > I did not succeed in removing this header from compilations
> > for Windows (which would have been the best solution).
> 
> No, this header is supposed to work everywhere (that's why
> it's in standard-headers/ rather than linux-headers),
> because virtio devices must work everywhere. We need to
> improve the process which creates it from the kernel header
> by automatedly fixing up non-portable constructs
> (which is handled by scripts/update-linux-headers.sh).
> Some extra seddery in cp_virtio() is probably required.
> 
> thanks
> -- PMM

commit d768f32aec8c0ebb8499ffca89cfed8f5f1a4432
Author: Thomas Huth <thuth@redhat.com>
Date:   Thu Jul 2 09:21:22 2015 +0200

    virtio: Fix typecast of pointer in vring_init()
    
    The virtio_ring.h header is used in userspace programs (ie. QEMU),
    too. Here we can not assume that sizeof(pointer) is the same as
    sizeof(long), e.g. when compiling for Windows, so the typecast in
    vring_init() should be done with (uintptr_t) instead of (unsigned long).
    
    Signed-off-by: Thomas Huth <thuth@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>


Fixed this, so it's just a question of updating from latest linux.

-- 
MST

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-09  6:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-08 19:11 [Qemu-devel] [PATCH] linux-headers: Fix type cast warning for 64 bit MinGW-w64 Stefan Weil
2015-09-08 19:15 ` Peter Maydell
2015-09-09  6:43   ` Michael S. Tsirkin

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).