libxtc
0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_pkey.h
1
/*-
2
* Copyright (c) 2026, The XTC Project
3
* Use of this source code is governed by the ISC License.
4
*
5
* src/inc/xtc_pkey.h
6
* Optional memory-protection-key (PKU) tier for in-process memory
7
* isolation (isolation tier c). On Linux/x86 with PKU, a region
8
* can be tagged with a protection key and a thread can then disable
9
* its own access/write to that key's pages in O(1) (no syscall on
10
* the toggle, via the PKRU register), giving coarse, domain-based
11
* in-process isolation -- a guest can be denied access to host
12
* pages without a separate address space.
13
*
14
* This is a hardening tier, NOT a portable guarantee: keys are
15
* scarce (16 on x86), it is Linux/x86-only (ARMv8.5 POE is newer
16
* and not wired here), and there is no macOS/Windows equivalent.
17
* Every call returns XTC_E_NOSYS where PKU is unavailable; probe
18
* with xtc_pkey_supported() first. For real, portable isolation
19
* use process-per-task (xtc_osproc).
20
*/
21
22
#ifndef XTC_PKEY_H
23
#define XTC_PKEY_H
24
25
#include <stddef.h>
26
27
#include "xtc.h"
28
29
/*
30
* PUBLIC: int xtc_pkey_supported __P((void));
31
* PUBLIC: int xtc_pkey_alloc __P((int *));
32
* PUBLIC: int xtc_pkey_protect __P((void *, size_t, int));
33
* PUBLIC: int xtc_pkey_set_access __P((int, int, int));
34
* PUBLIC: int xtc_pkey_free __P((int));
35
*/
36
37
/* 1 if protection keys are usable on this host right now, else 0. */
38
int
xtc_pkey_supported(
void
);
39
40
/* Allocate a protection key (initially full access). XTC_OK + *out,
41
* or XTC_E_NOSYS / XTC_E_INVAL. */
42
int
xtc_pkey_alloc(
int
*out_key);
43
44
/* Tag [addr,addr+len) (page-aligned) with key, keeping read+write
45
* protection bits. Access is then gated by the key's per-thread
46
* rights (xtc_pkey_set_access). */
47
int
xtc_pkey_protect(
void
*addr,
size_t
len,
int
key);
48
49
/* Set the CALLING thread's rights for key: allow_read/allow_write
50
* (0 disables). Disabling read implies disabling write. */
51
int
xtc_pkey_set_access(
int
key,
int
allow_read,
int
allow_write);
52
53
/* Release a key. */
54
int
xtc_pkey_free(
int
key);
55
56
#endif
/* XTC_PKEY_H */
src
inc
xtc_pkey.h
Generated by
1.9.8