Skip to contentSkip to conversation

linux-headers: Fix type cast warning for 64 bit MinGW-w64

PATCH In review Stefan Weil 3 participants 3 messages Sep 8, 2015 – Sep 9, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-headers: Fix type cast warning for 64 bit MinGW-w64

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] + ...

                       ^

---

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(-)
include/standard-headers/linux/virtio_ring.h +1 -1
index 6fe276f..3d531f7 100644
@@ -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));
 }
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 11 lines · Stefan Weil

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] + ...

                       ^
Quoted 8 lines

---

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

#2 lore raw
Quoted 29 lines · Peter Maydell
Quoted 11 lines · Stefan Weil

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] + ...

                       ^
Quoted 8 lines

---

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.

Quoted 2 lines

thanks
-- PMM

commit d768f32aec8c0ebb8499ffca89cfed8f5f1a4432

Author: Thomas Huth <[email protected]>
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).

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

Signature · 1 line
MST