tools/testing/selftests/mm/pkey_util.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/pkey_util.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/pkey_util.c- Extension
.c- Size
- 1087 bytes
- Lines
- 42
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
sys/syscall.hunistd.hpkey-helpers.h
Detected Declarations
function sys_pkey_allocfunction sys_pkey_freefunction sys_mprotect_pkey
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#define __SANE_USERSPACE_TYPES__
#include <sys/syscall.h>
#include <unistd.h>
#include "pkey-helpers.h"
int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
{
int ret = syscall(SYS_pkey_alloc, flags, init_val);
dprintf1("%s(flags=%lx, init_val=%lx) syscall ret: %d errno: %d\n",
__func__, flags, init_val, ret, errno);
return ret;
}
int sys_pkey_free(unsigned long pkey)
{
int ret = syscall(SYS_pkey_free, pkey);
dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret);
return ret;
}
int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
unsigned long pkey)
{
int sret;
dprintf2("%s(0x%p, %zx, prot=%lx, pkey=%lx)\n", __func__,
ptr, size, orig_prot, pkey);
errno = 0;
sret = syscall(__NR_pkey_mprotect, ptr, size, orig_prot, pkey);
if (errno) {
dprintf2("SYS_mprotect_key sret: %d\n", sret);
dprintf2("SYS_mprotect_key prot: 0x%lx\n", orig_prot);
dprintf2("SYS_mprotect_key failed, errno: %d\n", errno);
if (DEBUG_LEVEL >= 2)
perror("SYS_mprotect_pkey");
}
return sret;
}
Annotation
- Immediate include surface: `sys/syscall.h`, `unistd.h`, `pkey-helpers.h`.
- Detected declarations: `function sys_pkey_alloc`, `function sys_pkey_free`, `function sys_mprotect_pkey`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.