All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants
@ 2022-01-08 15:43 Stephen Kitt
  2022-01-08 15:43 ` [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE Stephen Kitt
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Stephen Kitt @ 2022-01-08 15:43 UTC (permalink / raw)
  To: Alejandro Colomar, Michael Kerrisk; +Cc: linux-man, Stephen Kitt

The example program needs signal.h to build correctly, since the
SIGEV_ constants are defined through signal.h; also document that in
the synopsis.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 man3/mq_notify.3 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/man3/mq_notify.3 b/man3/mq_notify.3
index 2c35a347d..222108d61 100644
--- a/man3/mq_notify.3
+++ b/man3/mq_notify.3
@@ -28,6 +28,7 @@ mq_notify \- register for notification when a message is available
 .SH SYNOPSIS
 .nf
 .B #include <mqueue.h>
+.BR "#include <signal.h>           " "/* Definition of SIGEV_* constants */"
 .PP
 .BI "int mq_notify(mqd_t " mqdes ", const struct sigevent *" sevp );
 .fi
@@ -224,6 +225,7 @@ queue and then terminates the process.
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <signal.h>
 
 #define handle_error(msg) \e
     do { perror(msg); exit(EXIT_FAILURE); } while (0)

base-commit: 88d2b3fdef39603bc6a608a0d814d1800b6a4089
-- 
2.30.2


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

* [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE
  2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
@ 2022-01-08 15:43 ` Stephen Kitt
  2022-01-08 19:44   ` Alejandro Colomar (man-pages)
  2022-01-08 15:43 ` [PATCH 3/5] pkeys.7: Update the example to match glibc Stephen Kitt
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Stephen Kitt @ 2022-01-08 15:43 UTC (permalink / raw)
  To: Alejandro Colomar, Michael Kerrisk; +Cc: linux-man, Stephen Kitt

LC_GLOBAL_HANDLE has never existed; the locale object handle to use to
refer to the global locale determined by setlocale(3) is
LC_GLOBAL_LOCALE. See uselocale(3) for details.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 man3/newlocale.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/newlocale.3 b/man3/newlocale.3
index b5960c4c4..dc9406ede 100644
--- a/man3/newlocale.3
+++ b/man3/newlocale.3
@@ -360,7 +360,7 @@ main(int argc, char *argv[])
 
     /* Free the locale object. */
 
-    uselocale(LC_GLOBAL_HANDLE);    /* So \(aqloc\(aq is no longer in use */
+    uselocale(LC_GLOBAL_LOCALE);    /* So \(aqloc\(aq is no longer in use */
     freelocale(loc);
 
     exit(EXIT_SUCCESS);
-- 
2.30.2


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

* [PATCH 3/5] pkeys.7: Update the example to match glibc
  2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
  2022-01-08 15:43 ` [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE Stephen Kitt
@ 2022-01-08 15:43 ` Stephen Kitt
  2022-01-08 19:49   ` Alejandro Colomar (man-pages)
  2022-01-08 15:43 ` [PATCH 4/5] pkeys.7: Rely on the glibc implementations Stephen Kitt
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Stephen Kitt @ 2022-01-08 15:43 UTC (permalink / raw)
  To: Alejandro Colomar, Michael Kerrisk; +Cc: linux-man, Stephen Kitt

glibc 2.27 introduced support for the pkeys functions, but the glibc
versions don't match those declared in the example. Update the example
to match glibc, and avoid declaring the functions if glibc is new
enough.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 man7/pkeys.7 | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/man7/pkeys.7 b/man7/pkeys.7
index 73ddcdc43..7c0d37a37 100644
--- a/man7/pkeys.7
+++ b/man7/pkeys.7
@@ -186,6 +186,7 @@ Segmentation fault (core dumped)
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/mman.h>
 
 static inline void
@@ -200,27 +201,27 @@ wrpkru(unsigned int pkru)
 }
 
 int
-pkey_set(int pkey, unsigned long rights, unsigned long flags)
+pkey_set(int pkey, unsigned int rights)
 {
     unsigned int pkru = (rights << (2 * pkey));
-    return wrpkru(pkru);
+    wrpkru(pkru);
+    return 0;
 }
 
 int
-pkey_mprotect(void *ptr, size_t size, unsigned long orig_prot,
-              unsigned long pkey)
+pkey_mprotect(void *ptr, size_t size, int orig_prot, int pkey)
 {
     return syscall(SYS_pkey_mprotect, ptr, size, orig_prot, pkey);
 }
 
 int
-pkey_alloc(void)
+pkey_alloc(unsigned int flags, unsigned int rights)
 {
-    return syscall(SYS_pkey_alloc, 0, 0);
+    return syscall(SYS_pkey_alloc, flags, rights);
 }
 
 int
-pkey_free(unsigned long pkey)
+pkey_free(int pkey)
 {
     return syscall(SYS_pkey_free, pkey);
 }
@@ -252,7 +253,7 @@ main(void)
     /*
      * Allocate a protection key:
      */
-    pkey = pkey_alloc();
+    pkey = pkey_alloc(0, 0);
     if (pkey == \-1)
         errExit("pkey_alloc");
 
@@ -260,7 +261,7 @@ main(void)
      * Disable access to any memory with "pkey" set,
      * even though there is none right now.
      */
-    status = pkey_set(pkey, PKEY_DISABLE_ACCESS, 0);
+    status = pkey_set(pkey, PKEY_DISABLE_ACCESS);
     if (status)
         errExit("pkey_set");
 
-- 
2.30.2


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

* [PATCH 4/5] pkeys.7: Rely on the glibc implementations
  2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
  2022-01-08 15:43 ` [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE Stephen Kitt
  2022-01-08 15:43 ` [PATCH 3/5] pkeys.7: Update the example to match glibc Stephen Kitt
@ 2022-01-08 15:43 ` Stephen Kitt
  2022-01-08 15:43 ` [PATCH 5/5] strtok.3: Fix j/str1 declaration Stephen Kitt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Stephen Kitt @ 2022-01-08 15:43 UTC (permalink / raw)
  To: Alejandro Colomar, Michael Kerrisk; +Cc: linux-man, Stephen Kitt

glibc 2.27 added implementations of pkey_set(), pkey_mprotect(),
pkey_alloc(), and pkey_free(); rely on those instead of defining them
in the example. wrpkru() is only used in pkey_set() and can be removed
too (it's the internal-use-only pkey_write() in glibc).

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 man7/pkeys.7 | 38 --------------------------------------
 1 file changed, 38 deletions(-)

diff --git a/man7/pkeys.7 b/man7/pkeys.7
index 7c0d37a37..055e57ce3 100644
--- a/man7/pkeys.7
+++ b/man7/pkeys.7
@@ -184,48 +184,10 @@ Segmentation fault (core dumped)
 .EX
 #define _GNU_SOURCE
 #include <unistd.h>
-#include <sys/syscall.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/mman.h>
 
-static inline void
-wrpkru(unsigned int pkru)
-{
-    unsigned int eax = pkru;
-    unsigned int ecx = 0;
-    unsigned int edx = 0;
-
-    asm volatile(".byte 0x0f,0x01,0xef\en\et"
-                 : : "a" (eax), "c" (ecx), "d" (edx));
-}
-
-int
-pkey_set(int pkey, unsigned int rights)
-{
-    unsigned int pkru = (rights << (2 * pkey));
-    wrpkru(pkru);
-    return 0;
-}
-
-int
-pkey_mprotect(void *ptr, size_t size, int orig_prot, int pkey)
-{
-    return syscall(SYS_pkey_mprotect, ptr, size, orig_prot, pkey);
-}
-
-int
-pkey_alloc(unsigned int flags, unsigned int rights)
-{
-    return syscall(SYS_pkey_alloc, flags, rights);
-}
-
-int
-pkey_free(int pkey)
-{
-    return syscall(SYS_pkey_free, pkey);
-}
-
 #define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \e
                            } while (0)
 
-- 
2.30.2


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

* [PATCH 5/5] strtok.3: Fix j/str1 declaration
  2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
                   ` (2 preceding siblings ...)
  2022-01-08 15:43 ` [PATCH 4/5] pkeys.7: Rely on the glibc implementations Stephen Kitt
@ 2022-01-08 15:43 ` Stephen Kitt
  2022-01-08 19:51   ` Alejandro Colomar (man-pages)
  2022-01-08 16:02 ` [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
  2022-01-08 19:42 ` Alejandro Colomar (man-pages)
  5 siblings, 1 reply; 10+ messages in thread
From: Stephen Kitt @ 2022-01-08 15:43 UTC (permalink / raw)
  To: Alejandro Colomar, Michael Kerrisk; +Cc: linux-man, Stephen Kitt

    for (int j = 1, str1 = argv[1]; ...

declares two variables of type int, j and str1; the pre-existing
char * str1 isn't used. This causes compiler warnings. Declaring j
outside the loop fixes everything.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 man3/strtok.3 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/man3/strtok.3 b/man3/strtok.3
index aec914094..06e9688b6 100644
--- a/man3/strtok.3
+++ b/man3/strtok.3
@@ -255,6 +255,7 @@ main(int argc, char *argv[])
 {
     char *str1, *str2, *token, *subtoken;
     char *saveptr1, *saveptr2;
+    int j;
 
     if (argc != 4) {
         fprintf(stderr, "Usage: %s string delim subdelim\en",
@@ -262,7 +263,7 @@ main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }
 
-    for (int j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
+    for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
         token = strtok_r(str1, argv[2], &saveptr1);
         if (token == NULL)
             break;
-- 
2.30.2


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

* Re: [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants
  2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
                   ` (3 preceding siblings ...)
  2022-01-08 15:43 ` [PATCH 5/5] strtok.3: Fix j/str1 declaration Stephen Kitt
@ 2022-01-08 16:02 ` Stephen Kitt
  2022-01-08 19:42 ` Alejandro Colomar (man-pages)
  5 siblings, 0 replies; 10+ messages in thread
From: Stephen Kitt @ 2022-01-08 16:02 UTC (permalink / raw)
  To: Alejandro Colomar, Michael Kerrisk; +Cc: linux-man

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

On Sat,  8 Jan 2022 16:43:00 +0100, Stephen Kitt <steve@sk2.org> wrote:
> The example program needs signal.h to build correctly, since the
> SIGEV_ constants are defined through signal.h; also document that in
> the synopsis.

Sorry, I forgot the v2 marker for all of these...

Regards,

Stephen

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants
  2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
                   ` (4 preceding siblings ...)
  2022-01-08 16:02 ` [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
@ 2022-01-08 19:42 ` Alejandro Colomar (man-pages)
  5 siblings, 0 replies; 10+ messages in thread
From: Alejandro Colomar (man-pages) @ 2022-01-08 19:42 UTC (permalink / raw)
  To: Stephen Kitt; +Cc: linux-man, Michael Kerrisk

On 1/8/22 16:43, Stephen Kitt wrote:
> The example program needs signal.h to build correctly, since the
> SIGEV_ constants are defined through signal.h; also document that in
> the synopsis.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>

Patch applied, Stephen.

Thanks,

Alex

> ---
>   man3/mq_notify.3 | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/man3/mq_notify.3 b/man3/mq_notify.3
> index 2c35a347d..222108d61 100644
> --- a/man3/mq_notify.3
> +++ b/man3/mq_notify.3
> @@ -28,6 +28,7 @@ mq_notify \- register for notification when a message is available
>   .SH SYNOPSIS
>   .nf
>   .B #include <mqueue.h>
> +.BR "#include <signal.h>           " "/* Definition of SIGEV_* constants */"
>   .PP
>   .BI "int mq_notify(mqd_t " mqdes ", const struct sigevent *" sevp );
>   .fi
> @@ -224,6 +225,7 @@ queue and then terminates the process.
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <unistd.h>
> +#include <signal.h>
>   
>   #define handle_error(msg) \e
>       do { perror(msg); exit(EXIT_FAILURE); } while (0)
> 
> base-commit: 88d2b3fdef39603bc6a608a0d814d1800b6a4089

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

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

* Re: [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE
  2022-01-08 15:43 ` [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE Stephen Kitt
@ 2022-01-08 19:44   ` Alejandro Colomar (man-pages)
  0 siblings, 0 replies; 10+ messages in thread
From: Alejandro Colomar (man-pages) @ 2022-01-08 19:44 UTC (permalink / raw)
  To: Stephen Kitt; +Cc: linux-man, Michael Kerrisk



On 1/8/22 16:43, Stephen Kitt wrote:
> LC_GLOBAL_HANDLE has never existed; the locale object handle to use to
> refer to the global locale determined by setlocale(3) is
> LC_GLOBAL_LOCALE. See uselocale(3) for details.

Added that text.

Thanks,

Alex

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

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

* Re: [PATCH 3/5] pkeys.7: Update the example to match glibc
  2022-01-08 15:43 ` [PATCH 3/5] pkeys.7: Update the example to match glibc Stephen Kitt
@ 2022-01-08 19:49   ` Alejandro Colomar (man-pages)
  0 siblings, 0 replies; 10+ messages in thread
From: Alejandro Colomar (man-pages) @ 2022-01-08 19:49 UTC (permalink / raw)
  To: Stephen Kitt; +Cc: linux-man, Michael Kerrisk

Hi Stephen,

On 1/8/22 16:43, Stephen Kitt wrote:
> glibc 2.27 introduced support for the pkeys functions, but the glibc
> versions don't match those declared in the example. Update the example
> to match glibc, and avoid declaring the functions if glibc is new
> enough.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>

Did you accidentally drop the preprocessor stuff in the process? 
Anyway, the commit saying that it's glibc 2.27 should be enough for 
someone interested enough in reading through the git history.  So, I 
applied both 3/5 and 4/5.

Cheers,

Alex

> ---
>   man7/pkeys.7 | 19 ++++++++++---------
>   1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/man7/pkeys.7 b/man7/pkeys.7
> index 73ddcdc43..7c0d37a37 100644
> --- a/man7/pkeys.7
> +++ b/man7/pkeys.7
> @@ -186,6 +186,7 @@ Segmentation fault (core dumped)
>   #include <unistd.h>
>   #include <sys/syscall.h>
>   #include <stdio.h>
> +#include <stdlib.h>
>   #include <sys/mman.h>
>   
>   static inline void
> @@ -200,27 +201,27 @@ wrpkru(unsigned int pkru)
>   }
>   
>   int
> -pkey_set(int pkey, unsigned long rights, unsigned long flags)
> +pkey_set(int pkey, unsigned int rights)
>   {
>       unsigned int pkru = (rights << (2 * pkey));
> -    return wrpkru(pkru);
> +    wrpkru(pkru);
> +    return 0;
>   }
>   
>   int
> -pkey_mprotect(void *ptr, size_t size, unsigned long orig_prot,
> -              unsigned long pkey)
> +pkey_mprotect(void *ptr, size_t size, int orig_prot, int pkey)
>   {
>       return syscall(SYS_pkey_mprotect, ptr, size, orig_prot, pkey);
>   }
>   
>   int
> -pkey_alloc(void)
> +pkey_alloc(unsigned int flags, unsigned int rights)
>   {
> -    return syscall(SYS_pkey_alloc, 0, 0);
> +    return syscall(SYS_pkey_alloc, flags, rights);
>   }
>   
>   int
> -pkey_free(unsigned long pkey)
> +pkey_free(int pkey)
>   {
>       return syscall(SYS_pkey_free, pkey);
>   }
> @@ -252,7 +253,7 @@ main(void)
>       /*
>        * Allocate a protection key:
>        */
> -    pkey = pkey_alloc();
> +    pkey = pkey_alloc(0, 0);
>       if (pkey == \-1)
>           errExit("pkey_alloc");
>   
> @@ -260,7 +261,7 @@ main(void)
>        * Disable access to any memory with "pkey" set,
>        * even though there is none right now.
>        */
> -    status = pkey_set(pkey, PKEY_DISABLE_ACCESS, 0);
> +    status = pkey_set(pkey, PKEY_DISABLE_ACCESS);
>       if (status)
>           errExit("pkey_set");
>   

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

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

* Re: [PATCH 5/5] strtok.3: Fix j/str1 declaration
  2022-01-08 15:43 ` [PATCH 5/5] strtok.3: Fix j/str1 declaration Stephen Kitt
@ 2022-01-08 19:51   ` Alejandro Colomar (man-pages)
  0 siblings, 0 replies; 10+ messages in thread
From: Alejandro Colomar (man-pages) @ 2022-01-08 19:51 UTC (permalink / raw)
  To: Stephen Kitt; +Cc: linux-man, Michael Kerrisk



On 1/8/22 16:43, Stephen Kitt wrote:
>      for (int j = 1, str1 = argv[1]; ...
> 
> declares two variables of type int, j and str1; the pre-existing
> char * str1 isn't used. This causes compiler warnings. Declaring j
> outside the loop fixes everything.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>

Patch applied.

Thanks,

Alex

> ---
>   man3/strtok.3 | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/man3/strtok.3 b/man3/strtok.3
> index aec914094..06e9688b6 100644
> --- a/man3/strtok.3
> +++ b/man3/strtok.3
> @@ -255,6 +255,7 @@ main(int argc, char *argv[])
>   {
>       char *str1, *str2, *token, *subtoken;
>       char *saveptr1, *saveptr2;
> +    int j;
>   
>       if (argc != 4) {
>           fprintf(stderr, "Usage: %s string delim subdelim\en",
> @@ -262,7 +263,7 @@ main(int argc, char *argv[])
>           exit(EXIT_FAILURE);
>       }
>   
> -    for (int j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
> +    for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
>           token = strtok_r(str1, argv[2], &saveptr1);
>           if (token == NULL)
>               break;

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

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

end of thread, other threads:[~2022-01-08 19:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-08 15:43 [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
2022-01-08 15:43 ` [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE Stephen Kitt
2022-01-08 19:44   ` Alejandro Colomar (man-pages)
2022-01-08 15:43 ` [PATCH 3/5] pkeys.7: Update the example to match glibc Stephen Kitt
2022-01-08 19:49   ` Alejandro Colomar (man-pages)
2022-01-08 15:43 ` [PATCH 4/5] pkeys.7: Rely on the glibc implementations Stephen Kitt
2022-01-08 15:43 ` [PATCH 5/5] strtok.3: Fix j/str1 declaration Stephen Kitt
2022-01-08 19:51   ` Alejandro Colomar (man-pages)
2022-01-08 16:02 ` [PATCH 1/5] mq_notify.3: Add signal.h for SIGEV_ constants Stephen Kitt
2022-01-08 19:42 ` Alejandro Colomar (man-pages)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.