public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] uapi: Make __{u,s}64 match {u,}int64_t in userspace
@ 2022-06-21  9:09 Cyril Hrubis
  2022-06-21 10:58 ` [LTP] [PATCH v2] uapi: Make __{u, s}64 match {u, }int64_t " Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Cyril Hrubis @ 2022-06-21  9:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arch, linux-api, libc-alpha, arnd, ltp, David.Laight, zack,
	dhowells, Cyril Hrubis

From: Cyril Hrubis <chrubis@suse.cz>

This changes the __u64 and __s64 in userspace on 64bit platforms from
long long (unsigned) int to just long (unsigned) int in order to match
the uint64_t and int64_t size in userspace.

This allows us to use the kernel structure definitions in userspace.

For example we can use PRIu64 and PRId64 modifiers in printf() to print
structure membere. Morever with this there would be no need to redefine
these structures in an libc implementations as it is done now.

Consider for example the newly added statx() syscall. If we use the
header from uapi we will get warnings when attempting to print it's
members as:

	printf("%" PRIu64 "\n", stx.stx_size);

We get:

	warning: format '%lu' expects argument of type 'long unsigned int',
	         but argument 5 has type '__u64' {aka 'long long unsigned int'}

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/uapi/asm-generic/types.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

v2: Make sure we do not break C++ applications

diff --git a/include/uapi/asm-generic/types.h b/include/uapi/asm-generic/types.h
index dfaa50d99d8f..11e468a39d1e 100644
--- a/include/uapi/asm-generic/types.h
+++ b/include/uapi/asm-generic/types.h
@@ -1,9 +1,16 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _ASM_GENERIC_TYPES_H
 #define _ASM_GENERIC_TYPES_H
+
+#include <asm/bitsperlong.h>
+
 /*
- * int-ll64 is used everywhere now.
+ * int-ll64 is used everywhere in kernel now.
  */
-#include <asm-generic/int-ll64.h>
+#if !defined(__KERNEL__) && !defined(__cplusplus) && __BITSPERLONG == 64
+# include <asm-generic/int-l64.h>
+#else
+# include <asm-generic/int-ll64.h>
+#endif
 
 #endif /* _ASM_GENERIC_TYPES_H */
-- 
2.35.1


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

* Re: [LTP] [PATCH v2] uapi: Make __{u, s}64 match {u, }int64_t in userspace
  2022-06-21  9:09 [PATCH v2] uapi: Make __{u,s}64 match {u,}int64_t in userspace Cyril Hrubis
@ 2022-06-21 10:58 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2022-06-21 10:58 UTC (permalink / raw)
  To: Cyril Hrubis
  Cc: linux-kernel, linux-arch, libc-alpha, arnd, linux-api, dhowells,
	David.Laight, zack, ltp

* Cyril Hrubis:

> From: Cyril Hrubis <chrubis@suse.cz>
>
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace.
>
> This allows us to use the kernel structure definitions in userspace.
>
> For example we can use PRIu64 and PRId64 modifiers in printf() to print
> structure membere. Morever with this there would be no need to redefine
> these structures in an libc implementations as it is done now.
>
> Consider for example the newly added statx() syscall. If we use the
> header from uapi we will get warnings when attempting to print it's
> members as:
>
> 	printf("%" PRIu64 "\n", stx.stx_size);
>
> We get:
>
> 	warning: format '%lu' expects argument of type 'long unsigned int',
> 	         but argument 5 has type '__u64' {aka 'long long unsigned int'}
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

Could you add some motivation for the C++ condition to the commit
message?

Thanks,
Florian


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

end of thread, other threads:[~2022-06-21 10:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21  9:09 [PATCH v2] uapi: Make __{u,s}64 match {u,}int64_t in userspace Cyril Hrubis
2022-06-21 10:58 ` [LTP] [PATCH v2] uapi: Make __{u, s}64 match {u, }int64_t " Florian Weimer

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 read-only IMAP folder(s) and NNTP newsgroup(s).