Skip to contentSkip to conversation

xen/types: Alter typedef for bool_t

PATCH In review Andrew Cooper 2 participants 10 messages Aug 1, 2016 – Aug 2, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 xen/types: Alter typedef for bool_t

As xen/stdbool.h is included, the typedef should use bool rather than _Bool.

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>

---
 xen/include/xen/types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/types.h +1 -1
index 78410de..c8092d0 100644
@@ -61,7 +61,7 @@ typedef __u64 __be64;
 
 typedef unsigned long uintptr_t;
 
-typedef _Bool bool_t;
+typedef bool bool_t;
 #define test_and_set_bool(b)   xchg(&(b), true)
 #define test_and_clear_bool(b) xchg(&(b), false)
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH 2/3 xen/types: Correct the definition of uintptr_t

uintptr_t is specified as unsigned int in 32bit, not unsigned long. This is why, when copying inttypes.h from GCC, the use of PRIxPTR and similar is broken for 32bit builds.

Fix the identified breakage with ELF_PRPTRVAL

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/include/xen/libelf.h | 10 +---------
 xen/include/xen/types.h  |  4 ++++
 2 files changed, 5 insertions(+), 9 deletions(-)
xen/include/xen/libelf.h +1 -9
index 95b5370..d430c83 100644
@@ -83,15 +83,7 @@ typedef uintptr_t elf_ptrval;
 #define ELF_HANDLE_DECL(structname)          structname##_handle
   /* Provides a type declaration for a HANDLE. */
 
-#ifdef __XEN__
-# define ELF_PRPTRVAL "lx"
-  /*
-   * PRIxPTR is misdefined in xen/include/xen/inttypes.h, on 32-bit,
-   * to "x", when in fact uintptr_t is an unsigned long.
-   */
-#else
-# define ELF_PRPTRVAL PRIxPTR
-#endif
+#define ELF_PRPTRVAL PRIxPTR
   /* printf format a la PRId... for a PTRVAL */
 
 #define ELF_DEFINE_HANDLE(structname)                                   \
xen/include/xen/types.h +4 -0
index c8092d0..44ae81c 100644
@@ -59,7 +59,11 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+#if BITS_PER_LONG == 64
 typedef unsigned long uintptr_t;
+#elif BITS_PER_LONG == 32
+typedef unsigned int uintptr_t;
+#endif
 
 typedef bool bool_t;
 #define test_and_set_bool(b)   xchg(&(b), true)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 2/3] xen/types: Correct the definition of uintptr_t

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 15:14, <[email protected]> wrote:

uintptr_t is specified as unsigned int in 32bit, not unsigned long. This is why, when copying inttypes.h from GCC, the use of PRIxPTR and similar is broken for 32bit builds.

I don't think this is strictly the case, i.e. doing it this way still ties us to internal workings of the compiler (as there is room for targets to customize base types used for derived ones). Could you try whether ...

xen/include/xen/types.h typedef __u32 __be32; · line 66

Quoted 11 lines
xen/include/xen/types.h +4 -0
@@ -59,7 +59,11 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+#if BITS_PER_LONG == 64
 typedef unsigned long uintptr_t;
+#elif BITS_PER_LONG == 32
+typedef unsigned int uintptr_t;
+#endif

...

typedef unsigned int __attribute__((__mode__(__pointer__))) uintptr_t;

works both ways (32- and 64-bit)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH 2/3] xen/types: Correct the definition of uintptr_t

Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 15:14, <[email protected]> wrote:

uintptr_t is specified as unsigned int in 32bit, not unsigned long. This is why, when copying inttypes.h from GCC, the use of PRIxPTR and similar is broken for 32bit builds.

I don't think this is strictly the case, i.e. doing it this way still ties us to internal workings of the compiler (as there is room for targets to customize base types used for derived ones). Could you try whether ...

This is the entire point I am trying to make that what we are doing is currently unsafe if we are not using the header files to match the compiler in use.

Quoted 14 lines
Quoted 12 lines
xen/include/xen/types.h +4 -0
@@ -59,7 +59,11 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
+#if BITS_PER_LONG == 64
 typedef unsigned long uintptr_t;
+#elif BITS_PER_LONG == 32
+typedef unsigned int uintptr_t;
+#endif

...

Quoted 3 lines

typedef unsigned int __attribute__((__mode__(__pointer__))) uintptr_t;

works both ways (32- and 64-bit)?

It does appear to work.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH 2/3] xen/types: Correct the definition of uintptr_t

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 18:08, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 15:14, <[email protected]> wrote:

uintptr_t is specified as unsigned int in 32bit, not unsigned long. This is why, when copying inttypes.h from GCC, the use of PRIxPTR and similar is broken for 32bit builds.

Quoted 8 lines
Quoted 4 lines

I don't think this is strictly the case, i.e. doing it this way still ties us to internal workings of the compiler (as there is room for targets to customize base types used for derived ones). Could you try whether ...

This is the entire point I am trying to make that what we are doing is currently unsafe if we are not using the header files to match the compiler in use.

That's really only a problem if we don't use what the compiler provides us to make up those header clones of ours, like e.g. (as said) the mode attribute.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH v2 2/3 xen/types: Correct the definition of uintptr_t

uintptr_t is specified as unsigned int in 32bit, not unsigned long. This is why, when copying inttypes.h from GCC, the use of PRIxPTR and similar is broken for 32bit builds.

Use __attribute__((__mode__(__pointer__))) to get the compilers default pointer type, which matches the pre-existing inttypes.h

Fix the identified breakage with ELF_PRPTRVAL

Compile tested on all architectures, with a manual printk() to trigger any potential -Wformat issues.

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v2:
* Use mode rather than extra typedefs

---
 xen/include/xen/libelf.h | 10 +---------
 xen/include/xen/types.h  |  2 +-
 2 files changed, 2 insertions(+), 10 deletions(-)
xen/include/xen/libelf.h +1 -9
index 95b5370..d430c83 100644
@@ -83,15 +83,7 @@ typedef uintptr_t elf_ptrval;
 #define ELF_HANDLE_DECL(structname)          structname##_handle
   /* Provides a type declaration for a HANDLE. */
 
-#ifdef __XEN__
-# define ELF_PRPTRVAL "lx"
-  /*
-   * PRIxPTR is misdefined in xen/include/xen/inttypes.h, on 32-bit,
-   * to "x", when in fact uintptr_t is an unsigned long.
-   */
-#else
-# define ELF_PRPTRVAL PRIxPTR
-#endif
+#define ELF_PRPTRVAL PRIxPTR
   /* printf format a la PRId... for a PTRVAL */
 
 #define ELF_DEFINE_HANDLE(structname)                                   \
xen/include/xen/types.h +1 -1
index c8092d0..7bdc83b 100644
@@ -59,7 +59,7 @@ typedef __u32 __be32;
 typedef __u64 __le64;
 typedef __u64 __be64;
 
-typedef unsigned long uintptr_t;
+typedef unsigned int __attribute__((__mode__(__pointer__))) uintptr_t;
 
 typedef bool bool_t;
 #define test_and_set_bool(b)   xchg(&(b), true)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 2/3
#6 lore raw

Re: [PATCH v2 2/3] xen/types: Correct the definition of uintptr_t

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 18:34, <[email protected]> wrote:

uintptr_t is specified as unsigned int in 32bit, not unsigned long. This is why, when copying inttypes.h from GCC, the use of PRIxPTR and similar is broken for 32bit builds.

Use __attribute__((__mode__(__pointer__))) to get the compilers default pointer type, which matches the pre-existing inttypes.h

Quoted 6 lines

Fix the identified breakage with ELF_PRPTRVAL

Compile tested on all architectures, with a manual printk() to trigger any potential -Wformat issues.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

PATCH 3/3 xen/common: Sort the obj build order

In reply to Andrew Cooper

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>

---
 xen/common/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/Makefile +1 -1
index f8123c2..c2e6846 100644
@@ -1,4 +1,5 @@
 obj-y += bitmap.o
+obj-y += bsearch.o
 obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
 obj-y += cpupool.o
@@ -43,7 +44,6 @@ obj-y += schedule.o
 obj-y += shutdown.o
 obj-y += softirq.o
 obj-y += sort.o
-obj-y += bsearch.o
 obj-y += smp.o
 obj-y += spinlock.o
 obj-y += stop_machine.o
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] xen/common: Sort the obj build order

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 15:14, <[email protected]> wrote:

Just like before, in case it's not implied:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v1 1/3
#9 lore raw
In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.08.16 at 15:14, <[email protected]> wrote:

As xen/stdbool.h is included, the typedef should use bool rather than _Bool.

I think this implies it, but just in case you think it doesn't ...

Quoted 1 line

...:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel