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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>

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/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux