mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
To: mtk.manpages@gmail.com
Cc: linux-man@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] futex.2: Use appropriate types
Date: Fri, 30 Oct 2020 14:46:39 +0100	[thread overview]
Message-ID: <bfffdeae-26e6-0469-f9af-f48b3b60a363@gmail.com> (raw)
In-Reply-To: <20201030123956.36169-2-colomar.6.4.3@gmail.com>

BTW, apparently the kernel doesn't use 'const' for 'utime'
('timeout' in the manual page),
but effectively, it doesn't modify it, AFAICS.

Should the kernel use 'const'?
Is there a reason for the kernel not using 'const'?
Should we do anything about it in the manual page?

Thanks,

Alex

On 2020-10-30 13:39, Alejandro Colomar wrote:
> The Linux kernel uses the following:
> 
> kernel/futex.c:3778:
> SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
> 		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
> 		u32, val3)
> 
> Since there is no glibc wrapper, use the same types the kernel uses.
> 
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>   man2/futex.2 | 27 ++++++++++++++-------------
>   1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/man2/futex.2 b/man2/futex.2
> index 837adbd25..73de71623 100644
> --- a/man2/futex.2
> +++ b/man2/futex.2
> @@ -26,12 +26,13 @@ futex \- fast user-space locking
>   .nf
>   .PP
>   .B #include <linux/futex.h>
> +.B #include <stdint.h>
>   .B #include <sys/time.h>
>   .PP
> -.BI "int futex(int *" uaddr ", int " futex_op ", int " val ,
> +.BI "long futex(uint32_t *" uaddr ", int " futex_op ", uint32_t " val ,
>   .BI "          const struct timespec *" timeout , \
>   " \fR  /* or: \fBuint32_t \fIval2\fP */"
> -.BI "          int *" uaddr2 ", int " val3 );
> +.BI "          uint32_t *" uaddr2 ", uint32_t " val3 );
>   .fi
>   .PP
>   .IR Note :
> @@ -581,8 +582,8 @@ any of the two supplied futex words:
>   .IP
>   .in +4n
>   .EX
> -int oldval = *(int *) uaddr2;
> -*(int *) uaddr2 = oldval \fIop\fP \fIoparg\fP;
> +uint32_t oldval = *(uint32_t *) uaddr2;
> +*(uint32_t *) uaddr2 = oldval \fIop\fP \fIoparg\fP;
>   futex(uaddr, FUTEX_WAKE, val, 0, 0, 0);
>   if (oldval \fIcmp\fP \fIcmparg\fP)
>       futex(uaddr2, FUTEX_WAKE, val2, 0, 0, 0);
> @@ -1765,11 +1766,11 @@ Child  (18535) 4
>   #define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \e
>                           } while (0)
>   
> -static int *futex1, *futex2, *iaddr;
> +static uint32_t *futex1, *futex2, *iaddr;
>   
>   static int
> -futex(int *uaddr, int futex_op, int val,
> -      const struct timespec *timeout, int *uaddr2, int val3)
> +futex(uint32_t *uaddr, int futex_op, uint32_t val,
> +      const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)
>   {
>       return syscall(SYS_futex, uaddr, futex_op, val,
>                      timeout, uaddr2, val3);
> @@ -1779,9 +1780,9 @@ futex(int *uaddr, int futex_op, int val,
>      become 1, and then set the value to 0. */
>   
>   static void
> -fwait(int *futexp)
> +fwait(uint32_t *futexp)
>   {
> -    int s;
> +    long s;
>   
>       /* atomic_compare_exchange_strong(ptr, oldval, newval)
>          atomically performs the equivalent of:
> @@ -1794,7 +1795,7 @@ fwait(int *futexp)
>       while (1) {
>   
>           /* Is the futex available? */
> -        const int one = 1;
> +        const uint32_t one = 1;
>           if (atomic_compare_exchange_strong(futexp, &one, 0))
>               break;      /* Yes */
>   
> @@ -1811,13 +1812,13 @@ fwait(int *futexp)
>      so that if the peer is blocked in fpost(), it can proceed. */
>   
>   static void
> -fpost(int *futexp)
> +fpost(uint32_t *futexp)
>   {
> -    int s;
> +    long s;
>   
>       /* atomic_compare_exchange_strong() was described in comments above */
>   
> -    const int zero = 0;
> +    const uint32_t zero = 0;
>       if (atomic_compare_exchange_strong(futexp, &zero, 1)) {
>           s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);
>           if (s  == \-1)
> 

  reply	other threads:[~2020-10-30 13:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 12:39 [PATCH 1/2] futex.2: srcfix Alejandro Colomar
2020-10-30 12:39 ` [PATCH 2/2] futex.2: Use appropriate types Alejandro Colomar
2020-10-30 13:46   ` Alejandro Colomar [this message]
2020-10-30 19:55     ` Michael Kerrisk (man-pages)
2020-10-30 19:19   ` Michael Kerrisk (man-pages)
2020-10-30 19:18 ` [PATCH 1/2] futex.2: srcfix Michael Kerrisk (man-pages)

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=bfffdeae-26e6-0469-f9af-f48b3b60a363@gmail.com \
    --to=colomar.6.4.3@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /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

all inboxes | Powered by JetHome®