Skip to contentSkip to conversation

mq_notify.3: Add signal.h for SIGEV_ constants

PATCH In review Stephen Kitt 2 participants 10 messages Jan 8, 2022 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 mq_notify.3: Add signal.h for SIGEV_ constants

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

---
 man3/mq_notify.3 | 2 ++
 1 file changed, 2 insertions(+)
man3/mq_notify.3 +2 -0
index 2c35a347d..222108d61 100644
@@ -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

Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/5 newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE

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.

---
 man3/newlocale.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
man3/newlocale.3 +1 -1
index b5960c4c4..dc9406ede 100644
@@ -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);
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 2/5] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE

Quoted 3 lines · 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.

Added that text.

Thanks,

Alex

Signature · 3 lines
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#3 lore raw

PATCH 3/5 pkeys.7: Update the example to match glibc

In reply to 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.

---
 man7/pkeys.7 | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
man7/pkeys.7 +10 -9
index 73ddcdc43..7c0d37a37 100644
@@ -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");
 
Signature · 1 line
2.30.2
#4 lore raw

Re: [PATCH 3/5] pkeys.7: Update the example to match glibc

Hi Stephen,

Quoted 6 lines · 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.

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

Quoted 69 lines
---
  man7/pkeys.7 | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)
man7/pkeys.7 +10 -9
index 73ddcdc43..7c0d37a37 100644
@@ -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");
 
Signature · 3 lines
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#5 lore raw

PATCH 4/5 pkeys.7: Rely on the glibc implementations

In reply to 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).

---
 man7/pkeys.7 | 38 --------------------------------------
 1 file changed, 38 deletions(-)
man7/pkeys.7 +0 -38
index 7c0d37a37..055e57ce3 100644
@@ -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)
 
Signature · 1 line
2.30.2
#6 lore raw

PATCH 5/5 strtok.3: Fix j/str1 declaration

In reply to 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.

---
 man3/strtok.3 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
man3/strtok.3 +2 -1
index aec914094..06e9688b6 100644
@@ -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;
Signature · 1 line
2.30.2
#7 lore raw

Re: [PATCH 5/5] strtok.3: Fix j/str1 declaration

Quoted 7 lines · 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.

Patch applied.

Thanks,

Alex

Quoted 25 lines
---
  man3/strtok.3 | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
man3/strtok.3 +2 -1
index aec914094..06e9688b6 100644
@@ -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;
Signature · 3 lines
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#8 lore raw
In reply to Stephen Kitt
Quoted 3 lines · 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.

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

Regards,

Stephen

#9 lore raw
In reply to Stephen Kitt
Quoted 5 lines · 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.

Patch applied, Stephen.

Thanks,

Alex

Quoted 26 lines
---
  man3/mq_notify.3 | 2 ++
  1 file changed, 2 insertions(+)
man3/mq_notify.3 +2 -0
index 2c35a347d..222108d61 100644
@@ -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

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