Skip to contentSkip to conversation

xen: correct definition of uintptr_t on 32-bit platforms.

PATCH In review Ian Campbell 2 participants 7 messages Jun 4, 2013 – Jun 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: correct definition of uintptr_t on 32-bit platforms.

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms but __PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent with glibc.

Tested with:

    printk("uintptr %"PRIuPTR"\n", (uintptr_t)a_convenient_local_var);

in a conveniently built place on unstable (x86_64, arm32, arm64) and Xen 4.2 (x86_32p & x86_64).

This error will be exposed by the fixes for XSA55 and therefore will need to be backported along with those.

---
 xen/include/xen/types.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
xen/include/xen/types.h +4 -0
index 8596ded..641e1d1 100644
@@ -57,6 +57,10 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+#if BITS_PER_LONG == 64
 typedef unsigned long uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
 
 #endif /* __TYPES_H__ */
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms but __PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but argument
2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent with glibc.

Actually I would much prefer the format string prefix to be changed
- like Linux, we're assuming all over the place that pointer and longs are equivalent in size, so creating an association between pointers and ints is much more likely to cause problems than adjusting the format string prefix.

Jan

Quoted 33 lines

Tested with:

    printk("uintptr %"PRIuPTR"\n", (uintptr_t)a_convenient_local_var);

in a conveniently built place on unstable (x86_64, arm32, arm64) and Xen 4.2 (x86_32p & x86_64).

This error will be exposed by the fixes for XSA55 and therefore will need to be backported along with those.

---
 xen/include/xen/types.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
xen/include/xen/types.h +4 -0
index 8596ded..641e1d1 100644
@@ -57,6 +57,10 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+#if BITS_PER_LONG == 64
 typedef unsigned long uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
 
 #endif /* __TYPES_H__ */
Signature · 1 line
1.7.2.5
#2 lore raw
Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms but __PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but argument
2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent with glibc.

Quoted 5 lines

Actually I would much prefer the format string prefix to be changed
- like Linux, we're assuming all over the place that pointer and longs are equivalent in size, so creating an association between pointers and ints is much more likely to cause problems than adjusting the format string prefix.

Can do that if you prefer.

Would this just push the problem into the code which is compiled for both user and hypervisor space (e.g. libelf), uintptr_t would then be different in the two environments. I haven't tried it so I don't know what the practical impact is.

#3 lore raw
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms but __PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but

argument

Quoted 11 lines
Quoted 5 lines

2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent with glibc.

Actually I would much prefer the format string prefix to be changed
- like Linux, we're assuming all over the place that pointer and longs are equivalent in size, so creating an association between pointers and ints is much more likely to cause problems than adjusting the format string prefix.

Quoted 6 lines

Can do that if you prefer.

Would this just push the problem into the code which is compiled for both user and hypervisor space (e.g. libelf), uintptr_t would then be different in the two environments. I haven't tried it so I don't know what the practical impact is.

In user environment the print format should be taken from the standard C headers just as the uintptr_t definition ought to be. No risk of collision if done consistently.

Jan

#4 lore raw
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms but __PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but

argument

Quoted 11 lines
Quoted 5 lines

2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent with glibc.

Actually I would much prefer the format string prefix to be changed
- like Linux, we're assuming all over the place that pointer and longs are equivalent in size, so creating an association between pointers and ints is much more likely to cause problems than adjusting the format string prefix.

Can do that if you prefer.

Quoted 8 lines
Quoted 4 lines

Would this just push the problem into the code which is compiled for both user and hypervisor space (e.g. libelf), uintptr_t would then be different in the two environments. I haven't tried it so I don't know what the practical impact is.

In user environment the print format should be taken from the standard C headers just as the uintptr_t definition ought to be. No risk of collision if done consistently.

Yes, absolutely.

I was thinking more of "assignment from incompatible... " type errors, where fixing one case would break the other...

Ian.

#5 lore raw
Quoted 31 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms

but

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

__PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but

argument

Quoted 4 lines
Quoted 4 lines

2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent

with

Quoted 15 lines
Quoted 14 lines
Quoted 7 lines
Quoted 1 line

glibc.

Actually I would much prefer the format string prefix to be changed
- like Linux, we're assuming all over the place that pointer and longs are equivalent in size, so creating an association between pointers and ints is much more likely to cause problems than adjusting the format string prefix.

Can do that if you prefer.

Would this just push the problem into the code which is compiled for both user and hypervisor space (e.g. libelf), uintptr_t would then be different in the two environments. I haven't tried it so I don't know what the practical impact is.

Quoted 8 lines
Quoted 3 lines

In user environment the print format should be taken from the standard C headers just as the uintptr_t definition ought to be. No risk of collision if done consistently.

Yes, absolutely.

I was thinking more of "assignment from incompatible... " type errors, where fixing one case would break the other...

Ah, okay - that risk exists no matter what type we pick, as it's not just Linux our user mode stuff gets built on.

Jan

#6 lore raw
In reply to Ian Campbell
Quoted 9 lines · Ian Campbell

Currently uintptr_t is unsigned long for both 32- and 64- bit platforms but __PRIPTR_PREFIX is just "" on 32-bit leading to:

error: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Werror=format]

It was a bit of a tossup between changing __PREPTR_PREFIX and changing the definition of uintptr_t. I went with the latter since it is consistent with glibc.

Quoted 7 lines

Tested with:

    printk("uintptr %"PRIuPTR"\n", (uintptr_t)a_convenient_local_var);

in a conveniently built place on unstable (x86_64, arm32, arm64) and Xen 4.2 (x86_32p & x86_64).

This error will be exposed by the fixes for XSA55 and therefore will need to be backported along with those.

After discussing with Ian J we decided that rather than add yet more complexity / dependencies to XSA-55 it would be better for him to carry his existing workaround (#define ELF_PRIPTR, or some similar name) and to fix the issue with uintptr_t vs. PRIuPTR after XSA-55 was done.

This is 4.4 material IMHO.

Ian.

Quoted 24 lines
---
 xen/include/xen/types.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
xen/include/xen/types.h +4 -0
index 8596ded..641e1d1 100644
@@ -57,6 +57,10 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+#if BITS_PER_LONG == 64
 typedef unsigned long uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
 
 #endif /* __TYPES_H__ */