linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alejandro Colomar (mailing lists)" <alx.mailinglists@gmail.com>
To: Cyril Hrubis <chrubis@suse.cz>, linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, linux-api@vger.kernel.org,
	libc-alpha@sourceware.org, ltp@lists.linux.it
Subject: Re: [PATCH] uapi: Make __{u,s}64 match {u,}int64_t in userspace
Date: Mon, 22 Nov 2021 17:51:15 +0100	[thread overview]
Message-ID: <8dfbe1be-0b4d-cdda-2c71-7a098faf07da@gmail.com> (raw)
In-Reply-To: <YZvIlz7J6vOEY+Xu@yuki>

Hi Cyril,

On 11/22/21 17:43, Cyril Hrubis wrote:
> 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 members. Morever with this there would be no need to redefine
> these structures in 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'}
> 
> After this patch the types match and no warnings are generated.
This would make it even easier to ignore the existence of different 
kernel types, and let userspace use standard types.

Related recent discussion:
<https://lore.kernel.org/linux-man/20210423230609.13519-1-alx.manpages@gmail.com/>

> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

Acked-by: Alejandro Colomar <alx.manpages@gmail.com>

Thanks,
Alex

> ---
>   include/uapi/asm-generic/types.h | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/asm-generic/types.h b/include/uapi/asm-generic/types.h
> index dfaa50d99d8f..ae748a3678a4 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 __BITS_PER_LONG == 64 && !defined(__KERNEL__)

BTW, C2X adds LONG_WIDTH in <limits.h> (and in general TYPE_WIDTH) to 
get the bits of a long.

> +# include <asm-generic/int-l64.h>
> +#else
> +# include <asm-generic/int-ll64.h>
> +#endif
>   
>   #endif /* _ASM_GENERIC_TYPES_H */
> 

  reply	other threads:[~2021-11-22 16:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 16:43 [PATCH] uapi: Make __{u,s}64 match {u,}int64_t in userspace Cyril Hrubis
2021-11-22 16:51 ` Alejandro Colomar (mailing lists) [this message]
2021-11-22 20:48 ` Arnd Bergmann
2021-11-23  9:14   ` Cyril Hrubis
2021-11-23 14:18     ` Arnd Bergmann
2021-11-23 19:50     ` Florian Weimer
2021-11-24 10:17       ` Alejandro Colomar (man-pages)
2021-11-22 22:19 ` Zack Weinberg
2021-11-23  9:15   ` Cyril Hrubis
2021-12-02 15:34   ` Rich Felker
2021-12-02 23:29     ` Rich Felker
2021-12-02 23:43       ` Adhemerval Zanella
2021-12-03  0:10         ` Zack Weinberg
2021-12-03 12:32           ` Adhemerval Zanella
2021-12-03 12:54             ` Alejandro Colomar (man-pages)
2021-11-23 16:47 ` David Howells
2021-11-23 16:58   ` David Laight
2021-11-29 11:58     ` Cyril Hrubis
2021-11-29 14:34       ` Arnd Bergmann
2021-12-02 14:55         ` Zack Weinberg
2021-12-02 15:01         ` David Howells
2021-12-02 20:48           ` Zack Weinberg
2021-12-08 15:33           ` Cyril Hrubis
2022-06-17 12:13             ` Ping: " Alejandro Colomar
2022-06-17 15:04               ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8dfbe1be-0b4d-cdda-2c71-7a098faf07da@gmail.com \
    --to=alx.mailinglists@gmail.com \
    --cc=alx.manpages@gmail.com \
    --cc=chrubis@suse.cz \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).