linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] futex.2: srcfix
@ 2020-10-30 12:39 Alejandro Colomar
  2020-10-30 12:39 ` [PATCH 2/2] futex.2: Use appropriate types Alejandro Colomar
  2020-10-30 19:18 ` [PATCH 1/2] futex.2: srcfix Michael Kerrisk (man-pages)
  0 siblings, 2 replies; 6+ messages in thread
From: Alejandro Colomar @ 2020-10-30 12:39 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, linux-kernel

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man2/futex.2 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man2/futex.2 b/man2/futex.2
index f82602c11..837adbd25 100644
--- a/man2/futex.2
+++ b/man2/futex.2
@@ -25,8 +25,8 @@ futex \- fast user-space locking
 .SH SYNOPSIS
 .nf
 .PP
-.B "#include <linux/futex.h>"
-.B "#include <sys/time.h>"
+.B #include <linux/futex.h>
+.B #include <sys/time.h>
 .PP
 .BI "int futex(int *" uaddr ", int " futex_op ", int " val ,
 .BI "          const struct timespec *" timeout , \
-- 
2.28.0


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

* [PATCH 2/2] futex.2: Use appropriate types
  2020-10-30 12:39 [PATCH 1/2] futex.2: srcfix Alejandro Colomar
@ 2020-10-30 12:39 ` Alejandro Colomar
  2020-10-30 13:46   ` Alejandro Colomar
  2020-10-30 19:19   ` Michael Kerrisk (man-pages)
  2020-10-30 19:18 ` [PATCH 1/2] futex.2: srcfix Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 6+ messages in thread
From: Alejandro Colomar @ 2020-10-30 12:39 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, linux-kernel

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)
-- 
2.28.0


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

* Re: [PATCH 2/2] futex.2: Use appropriate types
  2020-10-30 12:39 ` [PATCH 2/2] futex.2: Use appropriate types Alejandro Colomar
@ 2020-10-30 13:46   ` Alejandro Colomar
  2020-10-30 19:55     ` Michael Kerrisk (man-pages)
  2020-10-30 19:19   ` Michael Kerrisk (man-pages)
  1 sibling, 1 reply; 6+ messages in thread
From: Alejandro Colomar @ 2020-10-30 13:46 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, linux-kernel

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)
> 

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

* Re: [PATCH 1/2] futex.2: srcfix
  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 19:18 ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-10-30 19:18 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, linux-kernel

On 10/30/20 1:39 PM, Alejandro Colomar wrote:
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>

Hi Alex,

I've applied this patch, but would prefer to avoid such
patches in the future. Nothing is actually broken in the 
old version, so I tend to regard such patches as unnecessary
chur,.

Thanks,

Michael

> ---
>  man2/futex.2 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man2/futex.2 b/man2/futex.2
> index f82602c11..837adbd25 100644
> --- a/man2/futex.2
> +++ b/man2/futex.2
> @@ -25,8 +25,8 @@ futex \- fast user-space locking
>  .SH SYNOPSIS
>  .nf
>  .PP
> -.B "#include <linux/futex.h>"
> -.B "#include <sys/time.h>"
> +.B #include <linux/futex.h>
> +.B #include <sys/time.h>
>  .PP
>  .BI "int futex(int *" uaddr ", int " futex_op ", int " val ,
>  .BI "          const struct timespec *" timeout , \
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

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

* Re: [PATCH 2/2] futex.2: Use appropriate types
  2020-10-30 12:39 ` [PATCH 2/2] futex.2: Use appropriate types Alejandro Colomar
  2020-10-30 13:46   ` Alejandro Colomar
@ 2020-10-30 19:19   ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-10-30 19:19 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, linux-kernel

On 10/30/20 1:39 PM, 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.

Thanks. Patch applied.

Cheers,

Michael

> 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)
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

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

* Re: [PATCH 2/2] futex.2: Use appropriate types
  2020-10-30 13:46   ` Alejandro Colomar
@ 2020-10-30 19:55     ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-10-30 19:55 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, linux-kernel

Hi Alex,

On 10/30/20 2:46 PM, Alejandro Colomar wrote:
> 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?

I'm not sure about the kernel, but I think we don't need to 
worry in the manual page.

Thanks,

Michael

> 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)
>>


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

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

end of thread, other threads:[~2020-10-30 19:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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)

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).