From: Stephen Kitt <steve@sk2.org>
To: Alejandro Colomar <alx.manpages@gmail.com>,
Michael Kerrisk <mtk.manpages@gmail.com>
Cc: linux-man@vger.kernel.org, Stephen Kitt <steve@sk2.org>
Subject: [PATCH 3/5] pkeys.7: Update the example to match glibc
Date: Sat, 8 Jan 2022 16:43:02 +0100 [thread overview]
Message-ID: <20220108154304.1030478-3-steve@sk2.org> (raw)
In-Reply-To: <20220108154304.1030478-1-steve@sk2.org>
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
next prev parent reply other threads:[~2022-01-08 15:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Stephen Kitt [this message]
2022-01-08 19:49 ` [PATCH 3/5] pkeys.7: Update the example to match glibc 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)
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=20220108154304.1030478-3-steve@sk2.org \
--to=steve@sk2.org \
--cc=alx.manpages@gmail.com \
--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