tools/testing/selftests/mm/pkey-helpers.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/pkey-helpers.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/pkey-helpers.h- Extension
.h- Size
- 5288 bytes
- Lines
- 220
- 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
string.hstdarg.hstdio.hstdint.hstdbool.hsignal.hassert.hstdlib.hucontext.hsys/mman.hlinux/mman.hlinux/types.hkselftest.hpkey-x86.hpkey-powerpc.hpkey-arm64.h
Detected Declarations
function sigsafe_printffunction set_pkey_bitsfunction get_pkey_bitsfunction _read_pkey_regfunction write_pkey_regfunction kernel_has_pkeysfunction is_pkeys_supported
Annotated Snippet
#ifndef _PKEYS_HELPER_H
#define _PKEYS_HELPER_H
#define _GNU_SOURCE
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <signal.h>
#include <assert.h>
#include <stdlib.h>
#include <ucontext.h>
#include <sys/mman.h>
#include <linux/mman.h>
#include <linux/types.h>
#include "kselftest.h"
/* Define some kernel-like types */
typedef __u8 u8;
typedef __u16 u16;
typedef __u32 u32;
typedef __u64 u64;
#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)
#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 0
#endif
extern int dprint_in_signal;
extern int test_nr;
extern int iteration_nr;
#ifdef __GNUC__
__printf(1, 2)
#endif
static inline void sigsafe_printf(const char *format, ...)
{
va_list ap;
if (!dprint_in_signal) {
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
} else {
int ret;
/*
* No printf() functions are signal-safe.
* They deadlock easily. Write the format
* string to get some output, even if
* incomplete.
*/
ret = write(1, format, strlen(format));
if (ret < 0)
exit(1);
}
}
#define dprintf_level(level, args...) do { \
if (level <= DEBUG_LEVEL) \
sigsafe_printf(args); \
} while (0)
#define dprintf0(args...) dprintf_level(0, args)
#define dprintf1(args...) dprintf_level(1, args)
#define dprintf2(args...) dprintf_level(2, args)
#define dprintf3(args...) dprintf_level(3, args)
#define dprintf4(args...) dprintf_level(4, args)
extern void abort_hooks(void);
#define pkey_assert(condition) do { \
if (!(condition)) { \
dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \
__FILE__, __LINE__, \
test_nr, iteration_nr); \
dprintf0("errno at assert: %d", errno); \
abort_hooks(); \
exit(__LINE__); \
} \
} while (0)
#define barrier() __asm__ __volatile__("": : :"memory")
#ifndef noinline
# define noinline __attribute__((noinline))
#endif
int sys_pkey_alloc(unsigned long flags, unsigned long init_val);
int sys_pkey_free(unsigned long pkey);
int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
unsigned long pkey);
Annotation
- Immediate include surface: `string.h`, `stdarg.h`, `stdio.h`, `stdint.h`, `stdbool.h`, `signal.h`, `assert.h`, `stdlib.h`.
- Detected declarations: `function sigsafe_printf`, `function set_pkey_bits`, `function get_pkey_bits`, `function _read_pkey_reg`, `function write_pkey_reg`, `function kernel_has_pkeys`, `function is_pkeys_supported`.
- 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.