# Native interfaces

> Peios kernel native interfaces documentation.

---

# Native kernel interfaces

_Peios Kernel / Userspace interfaces / Native interfaces / Start here_

> Syscalls, handles and device interfaces provided by the Peios kernel.

These references describe the native kernel interfaces used by applications and
system services. Generated tables give the values and layouts defined by this
kernel's UAPI headers; the accompanying articles explain validation, authority,
lifetime and error semantics.

- [KMES](</kernel/userspace/native/kmes/overview.md>): event emission and ring attachment.
- [KACS](</kernel/userspace/native/kacs/overview.md>): tokens, access checks, process and file authority.
- [LCS](</kernel/userspace/native/lcs/overview.md>): registry keys, transactions, watches and source interfaces.
- [NTFE](</kernel/userspace/native/ntfe/overview.md>): the packet engine's device, events and inspection ioctls.

For subsystem relationships, read [Kernel architecture](</kernel/introduction/architecture-and-reading-guide.md>).
For SDK wrappers and application development guidance, use
[Developing for Peios](https://learn.peios.org/peios/developing-for-peios).

---

# KMES

_Peios Kernel / Userspace interfaces / Native interfaces / KMES_

> Find the Peios kernel articles about kmes.

Use these articles to understand kmes in the Peios kernel.

- [Emission and attachment syscalls](</kernel/userspace/native/kmes/emission-and-attachment-syscalls.md>)
- [Generated ABI tables](</kernel/userspace/native/kmes/generated-abi-tables.md>)
- [ABI semantics and limits](</kernel/userspace/native/kmes/abi-semantics-and-limits.md>)

---

# Emission and attachment syscalls

_Peios Kernel / Userspace interfaces / Native interfaces / KMES_

> The three KMES syscalls — emit, batch emit and attach — with their privilege gate, rate limiting, validation and preemption behaviour.

<a id="trm-2-4"></a>

KMES exposes three syscalls in the PKM syscall range (1090–1099):
`kmes_emit` (1090) emits a single event from userspace, `kmes_attach`
(1091) attaches the caller as a consumer of one per-CPU ring buffer,
and `kmes_emit_batch` (1092) emits multiple events in one operation.
All three follow the standard Linux convention — they return −1 and
set errno on failure — and their numbers, entry struct layout, error
tables, and privilege masks are collected in [KMES ABI Reference](</kernel/userspace/native/kmes/generated-abi-tables.md#trm-2-a>).

Before KMES initialisation completes, all three syscalls fail with
`ENOMEM`. Before KACS initialisation, the emit syscalls fail closed
with `EPERM`, since privilege checks cannot be performed. <a id="cite-syscalls.pre-init-fail-closed"></a>

<a id="trm-2-4-1"></a>

## kmes_emit

Emits one event. The origin class is set to 0 (userspace)
unconditionally — the caller cannot choose it — and the event is
written to the ring buffer of the CPU the calling thread is executing
on at write time. <a id="cite-emit.origin-forced-zero"></a>

<a id="trm-2-4-1-1"></a>

### Privilege gate <a id="cite-emit.privilege-gate"></a>

The caller's effective token has to hold SeAuditPrivilege, enabled;
otherwise the syscall fails with `EPERM`. A successful gate records
SeAuditPrivilege as used on the token, as a KACS standalone privilege
gate; a failed gate records nothing. If recording the used state
itself fails, the syscall also fails with `EPERM`.

<a id="trm-2-4-1-2"></a>

### Rate limiting <a id="cite-emit.rate-limit"></a>

Callers without enabled SeTcbPrivilege are rate limited per process by
a token bucket: the refill rate and the burst capacity both equal the
configured `MaxEmitRatePerProcess` ([Self-Configuration](</kernel/internals/kmes/self-configuration.md#trm-2-6>)). The bucket is allocated
together with the process's KACS security state at fork, initialised
to full capacity, and freed when the process's security state is
released at exit. <a id="cite-emit.rate.bucket-per-process-lifecycle"></a> Refill is computed against the monotonic clock, so
wall-clock jumps do not affect it. <a id="cite-emit.rate.monotonic-refill"></a> When `MaxEmitRatePerProcess`
changes at runtime, the new rate and capacity take effect immediately
— rates are read live on every operation — and each bucket's current
token count is clamped down to the new capacity. <a id="cite-emit.rate.reconfigure-applies-immediately"></a>

A token is reserved up front and refunded if the syscall subsequently
fails, so validation failures cost nothing; the refund is clamped to
capacity, which means a refund landing just after a rate decrease can
forfeit the token. <a id="cite-emit.rate.reserve-then-refund"></a> An empty bucket fails the reserve with `EAGAIN`,
consuming nothing. <a id="cite-emit.rate.empty-eagain"></a> Callers holding enabled SeTcbPrivilege bypass the
bucket entirely, and the exemption records SeTcbPrivilege as used. <a id="cite-emit.rate.tcb-bypass"></a>

Rate state is per-process rather than per-SID: per-SID limiting would
penalise unrelated services sharing a SID (LocalService, for
instance). A process that forks to reset its limit is bounded by
`RLIMIT_NPROC`. <a id="cite-emit.rate.per-process-not-per-sid"></a>

<a id="trm-2-4-1-3"></a>

### Validation <a id="cite-emit.validation-order"></a>

Validation runs in order and stops at the first failure; the errno
reflects the first failing check.

1. The privilege gate and rate reservation, above.
2. `event_type_len` is nonzero — `EINVAL` otherwise. <a id="cite-emit.empty-type-einval"></a>
3. The declared total event size (`77 + type_len + payload_len`) is
   computed from the length fields alone, without dereferencing either
   userspace pointer, with overflow-checked arithmetic — overflow is
   `EINVAL`. <a id="cite-emit.size-computed-without-deref"></a>
4. The declared size is within `MaxEventSize` — `ENOSPC` otherwise. <a id="cite-emit.max-event-size-enospc"></a>
5. The declared size is within 50% of the ring capacity — `ENOSPC`
   otherwise. At this stage the check runs against the first live
   ring's capacity; it is repeated against the actual target CPU's
   ring inside the write phase, so a capacity swap racing the syscall
   can surface `ENOSPC` after all other validation has passed. <a id="cite-emit.half-capacity-enospc"></a>
6. The event type and payload are copied into a kernel staging buffer
   (`EFAULT` if a pointer is inaccessible, `ENOMEM` if allocation
   fails). Everything after this point — validation and the ring
   write — operates on the kernel copy, closing the TOCTOU window in
   which userspace could rewrite the payload after validation. <a id="cite-emit.staged-copy-closes-toctou"></a>
7. The event type is validated as UTF-8 — `EINVAL` otherwise. <a id="cite-emit.type-utf8-einval"></a>
8. The payload is validated as msgpack within `MaxNestingDepth`
   ([Event Model](</kernel/internals/kmes/event-model.md#trm-2-2>)) — `EINVAL` otherwise. <a id="cite-emit.payload-msgpack-einval"></a>

<a id="trm-2-4-1-4"></a>

### Preemption

Validation runs with preemption enabled — the userspace copies can
fault, and msgpack validation of a large payload takes microseconds.
Preemption is disabled only around the ring buffer write: determining
the CPU, stamping, writing, publishing `write_pos`, and checking
`need_wake`. The `cpu_id` and identity GUIDs therefore reflect the
thread's state at write time, not at syscall entry. <a id="cite-emit.stamps-at-write-time"></a> On success the
syscall returns 0 and the event is immediately visible to consumers. <a id="cite-emit.success-immediately-visible"></a>

<a id="trm-2-4-2"></a>

## kmes_emit_batch

Emits up to 256 events in one call, sharing the privilege check, the
timestamp, the identity capture, and the single `write_pos`
publication across the batch. The 256-entry cap bounds the
preemption-disabled write window to roughly 50–100 microseconds for
typical event sizes.

The caller passes an array of 32-byte entry descriptors (layout in
[KMES ABI Reference](</kernel/userspace/native/kmes/generated-abi-tables.md#trm-2-a>); the descriptor padding bytes are documented as
reserved-must-be-zero in the ABI header but are not validated), a
`count`, and an `emitted_out` pointer. <a id="cite-batch.padding-not-validated"></a>

Processing order:

1. The SeAuditPrivilege gate, as for `kmes_emit`.
2. `count` is within 1–256 — `EINVAL` otherwise. <a id="cite-batch.count-range-einval"></a>
3. `count` tokens are reserved from the rate bucket in one critical
   section, so concurrent threads cannot both pass the check —
   `EAGAIN` if unavailable, and nothing is emitted. <a id="cite-batch.tokens-reserved-atomically"></a> SeTcbPrivilege
   exempts as before.
4. Zero is stored to `*emitted_out` before any per-entry work —
   `EFAULT` if unwritable, with nothing emitted. <a id="cite-batch.emitted-out-zeroed-first"></a>
5. The descriptor array is copied from userspace (`EFAULT`/`ENOMEM`).
6. Each entry, in order, goes through the same staging pipeline as
   `kmes_emit` — declared-size arithmetic, `MaxEventSize`, 50%
   capacity, userspace copy, UTF-8, msgpack. Staging stops at the
   first failing entry. <a id="cite-batch.staging-stops-at-first-failure"></a>
7. The validated prefix is emitted in one preemption-disabled write
   phase: one timestamp, one identity capture, a sequence number per
   event, origin class 0 throughout, and a single deferred
   publication that makes the whole prefix visible atomically. <a id="cite-batch.prefix-visible-atomically"></a>
8. Unused tokens (`count` minus events emitted) are refunded — only
   events actually emitted are charged. <a id="cite-batch.unused-tokens-refunded"></a>

On full success the syscall returns 0 and writes `count` to
`*emitted_out`. If entry N fails, entries 0 through N−1 are emitted,
N is written to `*emitted_out`, and the syscall returns −1 with the
errno of the failing entry. <a id="cite-batch.partial-failure-reporting"></a> Failed entries never consume sequence
numbers, so batch validation failures leave no consumer-visible gap. <a id="cite-batch.no-gap-on-failure"></a>
The final `emitted_out` store is a second write to userspace; if it
faults, the syscall reports `EFAULT` even though the prefix was
already emitted.

Every staged entry is held in kernel memory simultaneously until the
write phase completes, so a batch's transient allocation is bounded by
`count × MaxEventSize` — up to 1 GB at the maximum settings — rather
than by a single event.

<a id="trm-2-4-3"></a>

## kmes_attach

Attaches the caller as a consumer of one per-CPU ring buffer,
returning a file descriptor. The consumer contract built on this fd —
the mapped region layout, the drain and notification protocols, and
the re-attach protocol across buffer swaps — is specified in the PSPK
event stream chapter; the TRM side of the mechanics is [Ring Buffers](</kernel/internals/kmes/ring-buffers.md#trm-2-5>).

The caller's effective token has to hold SeSecurityPrivilege, enabled
— `EPERM` otherwise — and a successful gate records SeSecurityPrivilege
as used. <a id="cite-attach.privilege-gate"></a> `cpu_id` is a logical CPU index using the same numbering as
the ring metadata and event headers.

The slot array is allocated at KMES initialisation and sized by
`nr_cpu_ids`, then filled by walking `for_each_possible_cpu`. Those two
quantities are not the same thing: the array size bounds a valid
`cpu_id`, while the ring count is however many of those slots got a
ring. They agree only when the possible-CPU mask is dense. An index at
or beyond the array size fails with `EINVAL`; so does an index inside
it whose slot holds no live ring. <a id="cite-attach.slots-sized-by-nr-cpu-ids"></a>

A consumer learns the array size by calling `kmes_attach` with
`cpu_id` set to `KMES_ATTACH_QUERY_SLOTS` (`0xFFFFFFFF`). The call
takes the same privilege gate, writes the slot count through
`capacity`, returns 0, and opens no descriptor. Enumeration then walks
0 to slots-1 and skips the indexes that answer `EINVAL`. <a id="cite-attach.query-slots"></a>

Counting up until the first `EINVAL` — which is what this interface
used to ask for — is wrong on a sparse mask: it stops at the first
hole, and every ring above it becomes permanently unreachable, filling
and overwriting with no consumer able to attach. <a id="cite-attach.enumeration-skips-holes"></a>

CPUs that were possible but offline at initialisation have rings and
are attachable; hotplug beyond the initial set is not handled ([Failure Modes](</kernel/internals/kmes/failure-modes.md#trm-2-7>)). <a id="cite-attach.offline-possible-cpus-attachable"></a>

On success the current ring capacity is written to `*capacity` — the
consumer computes its mmap size as `8192 + 2 × capacity` — and the fd
is returned. The fd is opened `O_RDWR | O_CLOEXEC` and supports
exactly two operations: `mmap()` and `close()`. <a id="cite-attach.capacity-and-fd-contract"></a> The fd is installed
before the capacity write-back; if that write faults, the fd is closed
again and the syscall returns `EFAULT`, but another thread of the
process can have observed the fd in the interim. <a id="cite-attach.writeback-fault-closes-fd"></a>

Repeated attaches to the same CPU are permitted and return a new fd
each time; all fds for one CPU share the same ring — producer
metadata, consumer metadata, and data region — so multiple direct
consumers can drain one buffer concurrently, each keeping its own
read position in its own memory. KMES stores no per-consumer state:
the fd's private data is a reference to the ring, nothing more. When
events arrive and `need_wake` is set, KMES increments that buffer's
futex counter and wakes all waiting threads. <a id="cite-attach.shared-ring-many-fds"></a>

---

# Generated ABI tables

_Peios Kernel / Userspace interfaces / Native interfaces / KMES_

> Every KMES syscall number, structure layout, ring-buffer offset and constant, generated from the uapi headers and measured by compilation.

<a id="trm-2-a"></a>

Every name, value, offset and size in this appendix is generated from
`include/uapi/pkm/kmes.h` by `tools/docs/peios-reference/generators/gen-kmes-abi.py`, with struct
layouts measured by compiling a probe against the real header.
Regenerate it whenever the ABI changes; do not edit it by hand. The
names here are the ones a program actually compiles
against. <a id="cite-abi.generated-from-source"></a>

What a compiler cannot measure -- the error vocabulary of each
syscall, the privilege each requires by name, what the configuration
keys do, and the implementation bounds that are not in the header --
is in the notes appendix, [KMES ABI Notes](</kernel/userspace/native/kmes/abi-semantics-and-limits.md#trm-2-b>), which this generator does not touch.

<a id="trm-2-a-1"></a>

## Syscall numbers <a id="cite-abi.syscall-numbers"></a>

Signatures are read from the `SYSCALL_DEFINE` sites in `security/pkm/kmes/`.
The PKM UAPI exports the uppercase constants in `<pkm/syscall.h>`. Peios
glibc 2.44-5 and later exports the standard lowercase `SYS_kmes_*`
aliases in `<sys/syscall.h>`; each alias has the same number as its PKM
constant.

| Number | PKM constant | glibc alias | Signature |
|---|---|---|---|
| 1090 | `SYS_KMES_EMIT` | `SYS_kmes_emit` | `kmes_emit(const char __user *event_type, u16 event_type_len, const void __user *payload, u32 payload_len)` |
| 1091 | `SYS_KMES_ATTACH` | `SYS_kmes_attach` | `kmes_attach(unsigned int cpu_id, u64 __user *capacity)` |
| 1092 | `SYS_KMES_EMIT_BATCH` | `SYS_kmes_emit_batch` | `kmes_emit_batch(const struct kmes_emit_entry __user *entries, u32 count, u32 __user *emitted_out)` |

<a id="trm-2-a-2"></a>

## Structure layouts

Offsets and sizes are measured, not declared.

<a id="trm-2-a-2-1"></a>

### `struct kmes_emit_entry` <a id="cite-abi.struct-kmes-emit-entry"></a>

Total size 32 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `event_type` |
| 8 | 2 | `__u16` | `event_type_len` |
| 10 | 6 | `__u8[6]` | `_pad0` |
| 16 | 8 | `__u64` | `payload` |
| 24 | 4 | `__u32` | `payload_len` |
| 28 | 4 | `__u8[4]` | `_pad1` |

<a id="trm-2-a-3"></a>

## Constants

Grouped as the header groups them.

*Event origin class — kmes_event_header.origin_class.* <a id="cite-abi.origin-class-values"></a>

| Constant | Value | Notes |
|---|---|---|
| `KMES_ORIGIN_USERSPACE` | `0` |  |
| `KMES_ORIGIN_KMES` | `1` |  |
| `KMES_ORIGIN_KACS` | `2` |  |
| `KMES_ORIGIN_LCS` | `3` |  |
| `KMES_ORIGIN_NTFE` | `4` | net/ntfe: ntfe.verdict.reported, ntfe.policy.published, ntfe.policy.rejected |

*Ring-slot discovery.* <a id="cite-abi.ring-slot-discovery"></a>

Ring slots are indexed by logical CPU id and the array is sized by the
kernel's nr_cpu_ids, so a slot inside the array holds no ring when that
CPU is not possible. Counting up from 0 until SYS_KMES_ATTACH returns
-EINVAL therefore stops at the first hole and misses every ring above
it, leaving those CPUs' events permanently unreachable.

Call SYS_KMES_ATTACH with cpu_id KMES_ATTACH_QUERY_SLOTS to learn the
slot count instead. It writes the count through the capacity argument,
returns 0, and opens no descriptor. Enumerate 0 .. count-1 and treat
-EINVAL as "this slot holds no ring", not as the end of the array.

The sentinel is outside the index space for good: nr_cpu_ids is bounded
by CONFIG_NR_CPUS, which cannot reach 2^32-1.

| Constant | Value |
|---|---|
| `KMES_ATTACH_QUERY_SLOTS` | `0xFFFFFFFF` |

*Largest entry count a single SYS_KMES_EMIT_BATCH call accepts.* <a id="cite-abi.batch-max-entries"></a>

| Constant | Value |
|---|---|
| `KMES_BATCH_MAX_ENTRIES` | `256` |

*Runtime configuration registry location and keys.* <a id="cite-abi.config-constants"></a>

Type values match the LCS REG_\* constants: REG_DWORD is 4 and REG_QWORD
is 11. They are repeated here so &lt;pkm/kmes.h&gt; remains standalone.

| Constant | Value |
|---|---|
| `KMES_CONFIG_ROOT_HIVE` | `"Machine"` |
| `KMES_CONFIG_ROOT_SYSTEM_KEY` | `"System"` |
| `KMES_CONFIG_ROOT_KMES_KEY` | `"KMES"` |
| `KMES_CONFIG_KEY_BUFFER_CAPACITY` | `"BufferCapacity"` |
| `KMES_CONFIG_KEY_MAX_EVENT_SIZE` | `"MaxEventSize"` |
| `KMES_CONFIG_KEY_MAX_NESTING_DEPTH` | `"MaxNestingDepth"` |
| `KMES_CONFIG_KEY_MAX_EMIT_RATE_PER_PROCESS` | `"MaxEmitRatePerProcess"` |
| `KMES_CONFIG_TYPE_REG_DWORD` | `4` |
| `KMES_CONFIG_TYPE_REG_QWORD` | `11` |
| `KMES_CONFIG_BUFFER_CAPACITY_TYPE` | `11` |
| `KMES_CONFIG_BUFFER_CAPACITY_DEFAULT` | `4194304` |
| `KMES_CONFIG_BUFFER_CAPACITY_MIN` | `65536` |
| `KMES_CONFIG_BUFFER_CAPACITY_MAX` | `268435456` |
| `KMES_CONFIG_MAX_EVENT_SIZE_TYPE` | `4` |
| `KMES_CONFIG_MAX_EVENT_SIZE_DEFAULT` | `65536` |
| `KMES_CONFIG_MAX_EVENT_SIZE_MIN` | `1024` |
| `KMES_CONFIG_MAX_EVENT_SIZE_MAX` | `4194304` |
| `KMES_CONFIG_MAX_NESTING_DEPTH_TYPE` | `4` |
| `KMES_CONFIG_MAX_NESTING_DEPTH_DEFAULT` | `32` |
| `KMES_CONFIG_MAX_NESTING_DEPTH_MIN` | `4` |
| `KMES_CONFIG_MAX_NESTING_DEPTH_MAX` | `256` |
| `KMES_CONFIG_MAX_EMIT_RATE_PER_PROCESS_TYPE` | `4` |
| `KMES_CONFIG_MAX_EMIT_RATE_PER_PROCESS_DEFAULT` | `10000` |
| `KMES_CONFIG_MAX_EMIT_RATE_PER_PROCESS_MIN` | `100` |
| `KMES_CONFIG_MAX_EMIT_RATE_PER_PROCESS_MAX` | `1000000` |

*Privilege requirements.* <a id="cite-abi.privilege-masks"></a>

Values mirror the corresponding KACS privilege bits while keeping this
header standalone.

| Constant | Value |
|---|---|
| `KMES_EMIT_REQUIRED_PRIVILEGE` | `0x0000000000200000` (1ULL << 21) |
| `KMES_ATTACH_REQUIRED_PRIVILEGE` | `0x0000000000000100` (1ULL << 8) |

*On-wire event header.* <a id="cite-abi.event-header-layout"></a>

Every event in a ring begins with a fixed 77-byte header, followed by
event_type_len bytes of type string and then the msgpack payload. Events
abut at event_size stride, so a header is not generally aligned; it
crosses the ABI as raw bytes, not a C struct. Its fields, in order:

```text
__u32  event_size            total event byte length (header + type + payload)
__u32  header_size           byte offset from the event start to the payload
__u64  timestamp_ns
__u64  sequence
__u16  cpu_id
__u8   origin_class          one of KMES_ORIGIN_* above
__u8   effective_token_guid[16]
__u8   true_token_guid[16]
__u8   process_guid[16]
__u16  event_type_len        length of the type string following the header
```

The three GUIDs are 16-byte Microsoft GUID binary values
(Data1/Data2/Data3 little-endian, Data4 raw), captured from KACS at
emission time; the null GUID (16 zero bytes) means identity was
unavailable (KACS not initialised, or no process context). KMES copies
them opaquely.

Read each field at its KMES_EVENT_\*_OFFSET below. header_size locates
the payload: it is KMES_EVENT_HEADER_BASE_SIZE + event_type_len. A
future revision may grow the header, so consumers must use header_size,
not the end of the type string, to find the payload.

| Constant | Value |
|---|---|
| `KMES_EVENT_SIZE_OFFSET` | `0` |
| `KMES_EVENT_HEADER_SIZE_OFFSET` | `4` |
| `KMES_EVENT_TIMESTAMP_NS_OFFSET` | `8` |
| `KMES_EVENT_SEQUENCE_OFFSET` | `16` |
| `KMES_EVENT_CPU_ID_OFFSET` | `24` |
| `KMES_EVENT_ORIGIN_CLASS_OFFSET` | `26` |
| `KMES_EVENT_EFFECTIVE_TOKEN_GUID_OFFSET` | `27` |
| `KMES_EVENT_TRUE_TOKEN_GUID_OFFSET` | `43` |
| `KMES_EVENT_PROCESS_GUID_OFFSET` | `59` |
| `KMES_EVENT_TYPE_LEN_OFFSET` | `75` |

*Byte width of each identity GUID in the event header.*

| Constant | Value |
|---|---|
| `KMES_EVENT_GUID_SIZE` | `16` |

*Byte size of the fixed event header — the offset at which the type string begins.* <a id="cite-abi.header-base-size"></a>

| Constant | Value |
|---|---|
| `KMES_EVENT_HEADER_BASE_SIZE` | `77` |

*Ring-buffer metadata layout.* <a id="cite-abi.ring-mapping-layout"></a>

An attached ring is mmap'd as:

```text
page 0          producer metadata (read-only to the consumer)
page 1          consumer metadata (read-write)
ring data       the event bytes, mapped twice back-to-back so an event
                that wraps the buffer end is still contiguous.
```

The producer metadata page begins with KMES_RING_MAGIC.

| Constant | Value |
|---|---|
| `KMES_RING_MAGIC` | `"KMESRING"` |
| `KMES_RING_VERSION` | `1` |
| `KMES_METADATA_PAGE_SIZE` | `4096` |
| `KMES_METADATA_TOTAL_SIZE` | `8192` |
| `KMES_MAPPING_PRODUCER_OFFSET` | `0` |
| `KMES_MAPPING_CONSUMER_OFFSET` | `4096` |
| `KMES_MAPPING_DATA_OFFSET` | `8192` |

*Field offsets within the producer metadata page.* <a id="cite-abi.producer-page-offsets"></a>

| Constant | Value |
|---|---|
| `KMES_PRODUCER_MAGIC_OFFSET` | `0` |
| `KMES_PRODUCER_VERSION_OFFSET` | `8` |
| `KMES_PRODUCER_CPU_ID_OFFSET` | `12` |
| `KMES_PRODUCER_CAPACITY_OFFSET` | `16` |
| `KMES_PRODUCER_DATA_OFFSET_OFFSET` | `24` |
| `KMES_PRODUCER_GENERATION_OFFSET` | `32` |
| `KMES_PRODUCER_WRITE_POS_OFFSET` | `64` |
| `KMES_PRODUCER_TAIL_POS_OFFSET` | `72` |
| `KMES_PRODUCER_FUTEX_COUNTER_OFFSET` | `128` |

*Field offset within the consumer metadata page.* <a id="cite-abi.consumer-page-offset"></a>

| Constant | Value |
|---|---|
| `KMES_CONSUMER_NEED_WAKE_OFFSET` | `0` |

<a id="trm-2-a-4"></a>

## Tracepoint diagnostic codes

From `uapi/pkm/trace.h`. These are a diagnostic contract for
ftrace, perf and eBPF consumers, letting a tool decode a `kmes:`
event's `reason`, `op` or `state` field without recompiling
against a specific kernel. No KMES syscall accepts or returns
them, and values are append-only. <a id="cite-abi.trace.diagnostic-contract"></a>

*kmes_drop reason — why the KMES ring machinery lost an event.* <a id="cite-abi.trace.drop-reasons"></a>

RING_FULL is a normal overwrite; TAIL_RESYNC is the silent corruption-
recovery path that discards ALL pending events; VALIDATE is a kernel-
emit size/type reject at the ring boundary; BATCH_STRUCT_INVALID is a
per-entry structural reject in the kernel batch path. Emitted by
kmes:kmes_drop. No event payload bytes.

| Constant | Value | Notes |
|---|---|---|
| `KMES_DROP_RING_FULL` | `0` | capacity overwrite; oldest event dropped |
| `KMES_DROP_TAIL_RESYNC` | `1` | corrupt ring header; pending events silently discarded |
| `KMES_DROP_VALIDATE` | `2` | single kernel-emit size/type reject |
| `KMES_DROP_BATCH_STRUCT_INVALID` | `3` | kernel-batch entry structurally invalid |

*kmes_swap reason — a bounded ring capacity swap lifecycle marker.* <a id="cite-abi.trace.swap-reasons"></a>

BEGIN and COMPLETE/FAILED are whole-topology (cpu field is U16_MAX);
MIGRATE_SKIP is per-CPU and carries the skipped byte count in `ret`.
Emitted by kmes:kmes_swap.

| Constant | Value | Notes |
|---|---|---|
| `KMES_SWAP_BEGIN` | `0` | capacity change accepted, rings allocating |
| `KMES_SWAP_COMPLETE` | `1` | swap committed across all CPUs |
| `KMES_SWAP_MIGRATE_SKIP` | `2` | shrink: old event too large, skipped (ret=bytes) |
| `KMES_SWAP_FAILED` | `3` | swap aborted; ret is the errno |

*kmes_rate reason — the per-process token-bucket backpressure signal.* <a id="cite-abi.trace.rate-reasons"></a>

THROTTLE is an -EAGAIN emit rejection; RECONFIGURE marks an admin rate
change clamping all buckets. Emitted by kmes:kmes_rate.

| Constant | Value | Notes |
|---|---|---|
| `KMES_RATE_THROTTLE` | `0` | emit denied -EAGAIN; tokens &lt; requested |
| `KMES_RATE_RECONFIGURE` | `1` | max emit rate reconfigured for all buckets |

*kmes_wake reason — consumer wakeup machinery.* <a id="cite-abi.trace.wake-reasons"></a>

NOTE arms a pending wake; FUTEX is the actual futex wake of blocked
consumers. Emitted by kmes:kmes_wake.

| Constant | Value | Notes |
|---|---|---|
| `KMES_WAKE_NOTE` | `0` | wake armed; futex counter incremented |
| `KMES_WAKE_FUTEX` | `1` | blocked consumers woken |

*kmes_ring_lifecycle reason — a generation-stable ring object transition.* <a id="cite-abi.trace.ring-lifecycle"></a>

`ret` is the outcome. Emitted by kmes:kmes_ring_lifecycle.

| Constant | Value | Notes |
|---|---|---|
| `KMES_RING_ALLOC` | `0` | ring backing allocated (or -ENOMEM) |
| `KMES_RING_FREE` | `1` | ring backing released |
| `KMES_RING_PRODUCER_PAGE` | `2` | producer shmem/meta page attached |
| `KMES_RING_CONSUMER_FD` | `3` | consumer anon-inode fd created |

*kmes_ingress_reject reason — why an emit request was rejected before the ring.* <a id="cite-abi.trace.ingress-reject-reasons"></a>

OVER_MAX/OVER_CAP_HALF/SIZE_OVERFLOW are declared-size rejects;
EMIT_OVERSIZE is a staged event too large at ring-write time;
BATCH_PARTIAL marks a batch that validated fewer entries than requested.
Emitted by kmes:kmes_ingress_reject.

| Constant | Value | Notes |
|---|---|---|
| `KMES_INGRESS_OVER_MAX` | `0` | event_size exceeds configured max_event_size |
| `KMES_INGRESS_OVER_CAP_HALF` | `1` | event_size exceeds ring_capacity/2 |
| `KMES_INGRESS_SIZE_OVERFLOW` | `2` | declared header/event size overflow |
| `KMES_INGRESS_EMIT_OVERSIZE` | `3` | staged event exceeds live capacity/2 at emit |
| `KMES_INGRESS_BATCH_PARTIAL` | `4` | batch staged fewer entries than requested |

*kmes_validate reason — the C-boundary result of the Rust staged-event validator.* <a id="cite-abi.trace.validate-reasons"></a>

The Rust side collapses its structural checks into one nonzero return;
only visible type/payload lengths and `ret` are recorded here. Emitted
by kmes:kmes_validate.

| Constant | Value | Notes |
|---|---|---|
| `KMES_VAL_EINVAL` | `0` | Rust msgpack/structural validation rejected |

---

# ABI semantics and limits

_Peios Kernel / Userspace interfaces / Native interfaces / KMES_

> ABI semantics and limits: behaviour and implementation of the Peios kernel.

<a id="trm-2-b"></a>

[KMES ABI Reference](</kernel/userspace/native/kmes/generated-abi-tables.md#trm-2-a>) is generated from `include/uapi/pkm/kmes.h` and holds only what a
compiler can measure. This appendix holds the rest.

The split is structural rather than editorial. `gen-kmes-abi.py`
overwrites [KMES ABI Reference](</kernel/userspace/native/kmes/generated-abi-tables.md#trm-2-a>) wholesale on every run, so anything written there is
lost the next time the ABI changes.

Layouts that form part of the consumer contract — the event header,
the producer and consumer metadata pages, and the mapped region — are
specified normatively in the PSPK event stream specification. [KMES ABI Reference](</kernel/userspace/native/kmes/generated-abi-tables.md#trm-2-a>)
gives their offsets as the header defines them; the specification
governs.

<a id="trm-2-b-1"></a>

## Syscall parameters

| Syscall | Parameter | Type | Meaning |
|---|---|---|---|
| `kmes_emit` | `event_type` | `const char *` | Event type string. |
| | `event_type_len` | `u16` | Its length in bytes. |
| | `payload` | `const void *` | MessagePack payload. |
| | `payload_len` | `u32` | Its length in bytes. |
| `kmes_emit_batch` | `entries` | `struct kmes_emit_entry *` | Array of event descriptors. |
| | `count` | `u32` | Number of entries, 1 to `KMES_BATCH_MAX_ENTRIES`. |
| | `emitted_out` | `u32 *` | Receives the number of events emitted. |
| `kmes_attach` | `cpu_id` | `unsigned int` | Ring slot index, or `KMES_ATTACH_QUERY_SLOTS` to query the slot count. |
| | `capacity` | `u64 *` | Receives the ring buffer capacity in bytes. |

`kmes_emit` and `kmes_emit_batch` return 0 on success; `kmes_attach`
returns a file descriptor. All three return -1 and set errno on
failure.

The PKM syscall range is 1090–1099; KMES uses the first three.

<a id="trm-2-b-2"></a>

## Privilege requirements <a id="cite-syscalls.privileges-by-name"></a>

`kmes.h` gives these as bit masks so it can stand alone. The names
belong to the KACS privilege catalogue, and the bit index is what the
two agree on.

| Operation | Required privilege | Bit |
|---|---|---|
| `kmes_emit`, `kmes_emit_batch` | SeAuditPrivilege | 21 |
| Rate-limit exemption on both | SeTcbPrivilege | 7 |
| `kmes_attach` | SeSecurityPrivilege | 8 |

Holding a privilege is not enough: it must be *enabled*, and KMES marks
it used before proceeding. A failure to record the used state is itself
an `EPERM`, because an unrecorded privilege use is an audit gap. <a id="cite-syscalls.privilege-enabled-and-recorded"></a>

SeTcbPrivilege is checked but not required — an emitter that holds it
enabled is exempt from the per-process rate limit, and one that does not
is throttled.

<a id="trm-2-b-3"></a>

## Implementation bounds

These are properties of the implementation rather than of the ABI, so
they are not in `kmes.h` and a program must not compile against them.
They bound what the interface will accept.

| Quantity | Value | Where |
|---|---|---|
| Maximum event size, structural | 50% of ring capacity | `security/pkm/kmes/kmes.c` |
| MessagePack validator nesting stack | 256 | `security/pkm/kmes/kmes_validate.rs` |
| Self-configuration payload buffer | 768 bytes | `security/pkm/kmes/kmes.c` |
| Self-configuration audit intents per read | 4 | `security/pkm/kmes/kmes.h` |
| Self-configuration parameter name | 64 bytes | `security/pkm/kmes/kmes.h` |

The structural 50% bound is independent of `MaxEventSize` and applies to
kernel emitters too. An event may satisfy the configured maximum and
still be refused because the ring is small.

The validator's 256-frame stack is why `MaxNestingDepth` has a maximum of
256. The two bounds are enforced independently: the configuration range
check refuses a larger value at apply time, and the validator refuses
every event outright if it is somehow handed one, rather than silently
accepting nesting it cannot track.

<a id="trm-2-b-5"></a>

## Error codes

<a id="trm-2-b-5-1"></a>

### `kmes_emit` <a id="cite-emit.errors"></a>

| Errno | Condition |
|---|---|
| `EPERM` | SeAuditPrivilege not held or not enabled, or recording its used state failed. |
| `EAGAIN` | Per-process rate limit exceeded. |
| `EINVAL` | Zero event type length, event type not valid UTF-8, declared size arithmetic overflowed, payload not valid msgpack, or nesting depth over `MaxNestingDepth`. |
| `EFAULT` | Event type or payload pointer inaccessible. |
| `ENOSPC` | Event exceeds `MaxEventSize` or 50% of ring capacity. |
| `ENOMEM` | Staging buffer allocation failed, or KMES not initialised. |

<a id="trm-2-b-5-2"></a>

### `kmes_emit_batch` <a id="cite-batch.errors"></a>

| Errno | Condition |
|---|---|
| `EPERM` | As `kmes_emit`. |
| `EAGAIN` | Fewer than `count` tokens available. |
| `EINVAL` | `count` is 0 or over `KMES_BATCH_MAX_ENTRIES`, or the failing entry hit one of `kmes_emit`'s `EINVAL` conditions. |
| `EFAULT` | `emitted_out`, the entry array, or the failing entry's type or payload pointer inaccessible. |
| `ENOSPC` | The failing entry exceeds `MaxEventSize` or 50% of ring capacity. |
| `ENOMEM` | Kernel allocation failed, or KMES not initialised. |

<a id="trm-2-b-5-3"></a>

### `kmes_attach` <a id="cite-attach.errors"></a>

| Errno | Condition |
|---|---|
| `EPERM` | SeSecurityPrivilege not held or not enabled, or recording its used state failed. |
| `EINVAL` | `cpu_id` at or beyond the ring array size, or its slot holds no live ring. |
| `EFAULT` | `capacity` pointer inaccessible. |
| `ENOMEM` | Kernel allocation failed, or KMES not initialised. |

A `KMES_ATTACH_QUERY_SLOTS` call takes the same `EPERM`, `EFAULT` and
`ENOMEM` conditions and cannot return `EINVAL`. <a id="cite-attach.query-slots-errors"></a>

The ring array is sized by `nr_cpu_ids`, not by the number of rings
allocated. On a machine with a sparse possible-CPU mask the two differ,
and a slot inside the array with no live ring returns `EINVAL` exactly
as an index beyond the array does. A consumer therefore enumerates
against the slot count from `KMES_ATTACH_QUERY_SLOTS` and skips the
`EINVAL` slots rather than stopping at the first one; see [Syscall Interface](</kernel/userspace/native/kmes/emission-and-attachment-syscalls.md#trm-2-4>).

---

# KACS

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Find the Peios kernel articles about kacs.

Use these articles to understand kacs in the Peios kernel.

- [Mount policy syscalls](</kernel/userspace/native/kacs/mount-policy-syscalls.md>)
- [Generated syscall index](</kernel/userspace/native/kacs/generated-syscall-index.md>)
- [Generated token and session ABI](</kernel/userspace/native/kacs/generated-token-and-session-abi.md>)
- [Generated access-check and descriptor ABI](</kernel/userspace/native/kacs/generated-access-check-and-descriptor-abi.md>)
- [Generated file and mount ABI](</kernel/userspace/native/kacs/generated-file-and-mount-abi.md>)
- [Generated socket and IPC ABI](</kernel/userspace/native/kacs/generated-socket-and-ipc-abi.md>)
- [Generated process and PSB ABI](</kernel/userspace/native/kacs/generated-process-and-psb-abi.md>)
- [Generated diagnostic constants](</kernel/userspace/native/kacs/generated-diagnostic-constants.md>)
- [MS-DTYP compatibility and divergences](</kernel/userspace/native/kacs/ms-dtyp-compatibility-and-divergences.md>)
- [ABI status and naming differences](</kernel/userspace/native/kacs/abi-status-and-naming-differences.md>)
- [Descriptor and ACE semantics](</kernel/userspace/native/kacs/descriptor-and-ace-semantics.md>)
- [Token query semantics](</kernel/userspace/native/kacs/token-query-semantics.md>)
- [Socket ABI compatibility](</kernel/userspace/native/kacs/socket-abi-compatibility.md>)

---

# Mount policy syscalls

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> The documented mount-policy argument fields, validation sequence and errors, retained alongside the kernel descriptor-storage contract for comparison.

<a id="trm-3-9-9"></a>

These syscall notes preserve the argument and error descriptions from the
operator guide. For the kernel contract, use [File Descriptor
Storage](/kernel/internals/kacs/file-security/descriptor-storage-and-caching.md#trm-3-9-5).

> [!WARNING]
> The privilege gate has been source-verified below, but other descriptions
> retained from the operator guide still differ. The kernel contract allows
> templates only with synthesising classes,
> caps them at 65,535 bytes, and rejects non-empty templates for deny-missing.
> The [SDK wrapper](https://learn.peios.org/peios/developing-for-peios/sdk-reference/sdk-files/mount-policy)
> documents different small-buffer handling from the raw
> syscall error table below. These differences need implementation verification;
> do not use these notes to infer a broader grant of access or a safe retry.

<a id="trm-3-9-9-1"></a>

## kacs_set_mount_policy

The write syscall:

```
result = kacs_set_mount_policy(fd, args)
```

Where `fd` is a file descriptor referring to any object on the target superblock (the kernel uses the fd to identify which superblock — the file itself does not need to be the root of the mount). `args` is a `kacs_mount_policy_args` struct:

| Field | Meaning |
|---|---|
| `policy` | The new policy class (one of `KACS_MOUNT_POLICY_DENY_MISSING`, `KACS_MOUNT_POLICY_SYNTHESIZE_EPHEMERAL`, `KACS_MOUNT_POLICY_SYNTHESIZE_PERSISTENT`). |
| `flags` | Reserved; must be zero. |
| `generation` | (Output) The new generation counter value after the change. |
| `template_sd_ptr`, `template_sd_len` | Optional mount-level SD template. Max 64 KiB. |

The kernel:

1. Validates the fd and identifies the superblock.
2. Validates the policy value. Attempts to set `KACS_MOUNT_POLICY_UNMANAGED` (which is not settable via this ABI) are rejected with `-EINVAL`.
3. Validates the template SD if provided — must parse, must be within size limits.
4. Checks the caller's privileges. Enabled `SeManageVolumePrivilege` or `SeTcbPrivilege` is required, and marking the privilege as used must succeed.
5. Atomically updates the superblock's policy class, the template SD, and increments the generation counter.
6. Writes the new generation to `args.generation`.
7. Returns 0.

The change is **atomic at the superblock level** — every future access against any inode on this superblock sees the new policy. There is no transitional state where some inodes are under the old policy and others under the new.

<a id="trm-3-9-9-1-1"></a>

### Privilege requirement

> [!IMPORTANT]
> In kernel source `8e0e22de3a59cad506bbbf8873de456e16ad272d`, both policy reads and writes use the [volume-management gate](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/capability.c#L613-L637): enabled `SeManageVolumePrivilege` or `SeTcbPrivilege`, with successful privilege-use marking. Administrator membership alone is insufficient. The [write gate](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/mount_policy.c#L369-L380) and [read gate](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/mount_policy.c#L479-L496) establish this for the pinned source, not a deployed build or a historical release boundary.

Changing a mount's policy affects the entire filesystem's access semantics.
`SeManageVolumePrivilege` can author synthesised policy and shadow existing
paths; see its [authority warning](https://learn.peios.org/kernel/internals/kacs/privileges/privilege-catalogue/#system-operations).
The [SDK wrappers](https://github.com/peios/libpeios/blob/de0018bdcaed14abb796aeccec9c8387fd30e452/src/file.rs#L451-L575) at libpeios
`de0018bdcaed14abb796aeccec9c8387fd30e452` add no TCB-only gate despite their
comments. The [`mount` command's](https://learn.peios.org/peios/using-peios/files-and-volumes/mount/)
diagnostic also retains a TCB-only hint. Do not automatically grant TCB or globally remap
`CAP_SYS_ADMIN`. A ready-to-use operator interface for changing an existing
policy is [not established here](https://learn.peios.org/peios/using-peios/files-and-volumes/mounting-storage/#verify-the-attachment-boundary).

The generated [KACS ABI trace table](/kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a)
retains the `KACS_MP_TCB_DENIED` name and TCB-only descriptions. Those labels
do not override the source-verified gate; this clarification leaves the
generated table unchanged.

<a id="trm-3-9-9-1-2"></a>

### The template SD

The optional template SD is the default SD used during synthesis when the parent's inheritance does not yield one. The kernel stores the template on the superblock; subsequent synthesis-on-missing calls use it.

The template is a complete self-relative SD — owner, primary group, DACL, optional SACL. The kernel validates the template at policy-set time:

- Must be in self-relative format.
- Must include an owner (an SD without one is malformed and rejected).
- Must fit within 65,535 bytes total; the template specifically is capped at 64 KiB.
- ACLs and ACEs must parse.

A bad template at policy-set time is rejected with `-EINVAL`; the current policy and template are unchanged.

The template can be omitted entirely (zero pointers) for mounts that don't need one. The synthesis chain then falls through to the hardcoded fallback for any file whose parent doesn't yield an SD.

<a id="trm-3-9-9-2"></a>

## kacs_get_mount_policy

The read syscall:

```
result = kacs_get_mount_policy(fd, args)
```

Same `fd` and `args` semantics, returning the current policy class, current template (if buffer provided), and current generation counter.

The kernel:

1. Validates the fd, identifies the superblock.
2. Checks the caller's privileges. Enabled `SeManageVolumePrivilege` or `SeTcbPrivilege` is required, with successful privilege-use marking.
3. Writes the policy class, generation, and template to `args` (template only if a buffer was provided).
4. Returns 0.

Like the write syscall, this uses the pinned-source [volume-management gate](#privilege-requirement). A successful policy query does not grant authority to bypass any other mount or file-access checks.

This is the kernel's read-back-the-current-policy interface. A management tool reads the policy, perhaps applies a transformation, and writes the new value back. The read-modify-write pattern is what most policy management code uses.

<a id="trm-3-9-9-2-1"></a>

### Reading the generation

Compare the value from `kacs_get_mount_policy` with your earlier read to detect
a change. Initial values are implementation-defined, and values from different
superblocks are unrelated. The counter identifies changes, not a wall-clock
change time. See the [kernel administration
contract](/kernel/internals/kacs/file-security/mount-classes-and-bootstrap-descriptors.md#trm-3-9-5-6)
for generation increments and cache invalidation.

<a id="trm-3-9-9-3"></a>

## Errors

Possible failures from `kacs_set_mount_policy`:

| Error | Cause |
|---|---|
| `-EBADF` | The fd is invalid. |
| `-EPERM` | Neither accepted privilege is enabled, or privilege-use marking failed. |
| `-EINVAL` | Setting an `unmanaged` policy via the public ABI; setting an unknown policy value; non-zero reserved flags; malformed template SD; template size exceeded. |

Possible failures from `kacs_get_mount_policy`:

| Error | Cause |
|---|---|
| `-EBADF` | The fd is invalid. |
| `-EPERM` | Neither accepted privilege is enabled, or privilege-use marking failed. |
| `-ERANGE` | A template buffer was provided but is smaller than the template. The required size is written to the output. |

In normal operation both calls succeed. Failures are typically privilege issues or malformed inputs.

---

# Generated syscall index

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated syscall index: behaviour and implementation of the Peios kernel.

<a id="trm-3-a"></a>

Every name, value, offset and size in this appendix is generated
from `include/uapi/pkm/` by `tools/docs/peios-reference/generators/gen-kacs-abi.py`, with struct
layouts measured by compiling a probe against the real headers.
Regenerate it whenever the ABI changes; do not edit it by hand.

The names here are the ones a program actually compiles against. <a id="cite-kacs-abi.generated-from-source"></a>
Everything about the ABI a compiler cannot measure -- token query
payload shapes, the specification spellings that differ from these
names, what is documented elsewhere, and the kernel configuration
-- is in the notes appendix, [KACS ABI Notes](</kernel/userspace/native/kacs/abi-status-and-naming-differences.md#trm-3-d>), which this generator does not
touch.

<a id="trm-3-a-1"></a>

## Syscall numbers <a id="cite-kacs-abi.syscall-numbers"></a>

Signatures are read from the `SYSCALL_DEFINE` sites in `security/pkm/kacs/`.
The PKM UAPI exports the uppercase constants in `<pkm/syscall.h>`. Peios
glibc 2.44-5 and later exports the standard lowercase `SYS_kacs_*`
aliases in `<sys/syscall.h>`; each alias has the same number as its PKM
constant.

| Number | PKM constant | glibc alias | Signature |
|---:|---|---|---|
| 1000 | `SYS_KACS_OPEN_SELF_TOKEN` | `SYS_kacs_open_self_token` | `kacs_open_self_token(unsigned int flags, u32 access_mask)` |
| 1001 | `SYS_KACS_OPEN_PROCESS_TOKEN` | `SYS_kacs_open_process_token` | `kacs_open_process_token(int pidfd, u32 access_mask)` |
| 1002 | `SYS_KACS_OPEN_THREAD_TOKEN` | `SYS_kacs_open_thread_token` | `kacs_open_thread_token(int pidfd, int tid, u32 access_mask)` |
| 1003 | `SYS_KACS_CREATE_TOKEN` | `SYS_kacs_create_token` | `kacs_create_token(const void __user *spec, size_t spec_len)` |
| 1004 | `SYS_KACS_CREATE_LOGON_SESSION` | `SYS_kacs_create_logon_session` | `kacs_create_logon_session(const void __user *spec, size_t spec_len)` |
| 1005 | `SYS_KACS_SET_PSB` | `SYS_kacs_set_psb` | `kacs_set_psb(int pidfd, u32 mitigations)` |
| 1006 | `SYS_KACS_DESTROY_EMPTY_LOGON_SESSION` | `SYS_kacs_destroy_empty_logon_session` | `kacs_destroy_empty_logon_session(u64 auth_id)` |
| 1012 | `SYS_KACS_REVERT` | `SYS_kacs_revert` | `kacs_revert(void)` |
| 1020 | `SYS_KACS_OPEN` | `SYS_kacs_open` | `kacs_open(int dirfd, const char __user *path, struct kacs_open_how __user *uhow, size_t howsize, u32 __user *status_out)` |
| 1021 | `SYS_KACS_GET_SD` | `SYS_kacs_get_sd` | `kacs_get_sd(int dirfd, const char __user *path, u32 security_info, void __user *buf, u32 buf_len, u32 flags)` |
| 1022 | `SYS_KACS_SET_SD` | `SYS_kacs_set_sd` | `kacs_set_sd(int dirfd, const char __user *path, u32 security_info, const void __user *sd_buf, u32 sd_len, u32 flags)` |
| 1023 | `SYS_KACS_ACCESS_CHECK` | `SYS_kacs_access_check` | `kacs_access_check(const void __user *uargs)` |
| 1024 | `SYS_KACS_ACCESS_CHECK_LIST` | `SYS_kacs_access_check_list` | `kacs_access_check_list(const void __user *uargs, struct kacs_node_result __user *results, u32 results_count)` |
| 1025 | `SYS_KACS_SET_CAAP` | `SYS_kacs_set_caap` | `kacs_set_caap(const void __user *policy_sid, u32 policy_sid_len, const void __user *spec, u32 spec_len)` |
| 1026 | `SYS_KACS_GET_MOUNT_POLICY` | `SYS_kacs_get_mount_policy` | `kacs_get_mount_policy(int fd, struct kacs_mount_policy_args __user *uargs, size_t argsize)` |
| 1027 | `SYS_KACS_SET_MOUNT_POLICY` | `SYS_kacs_set_mount_policy` | `kacs_set_mount_policy(int fd, struct kacs_mount_policy_args __user *uargs, size_t argsize)` |
| 1028 | `SYS_KACS_ACCESS_CHECK_SUBJECT` | `SYS_kacs_access_check_subject` | `kacs_access_check_subject(const void __user *request, size_t request_len, void __user *result)` |
| 1029 | `SYS_KACS_QUERY_OPEN` | `SYS_kacs_query_open` | `kacs_query_open(int fd, struct kacs_open_info __user *uinfo, size_t size)` |
| 1030 | `SYS_KACS_SET_DISPOSITION` | `SYS_kacs_set_disposition` | `kacs_set_disposition(int fd, u32 flags)` |
| 1031 | `SYS_KACS_RENAME` | `SYS_kacs_rename` | `kacs_rename(int fd, int newdirfd, const char __user *newpath, u32 flags)` |
| 1032 | `SYS_KACS_LOCK` | `SYS_kacs_lock` | `kacs_lock(int fd, const struct kacs_lock_args __user *uargs, size_t size)` |
| 1033 | `SYS_KACS_CREATE_LEASE_MANAGER` | `SYS_kacs_create_lease_manager` | `kacs_create_lease_manager(u32 flags, u32 timeout_ms)` |
| 1034 | `SYS_KACS_LEASE` | `SYS_kacs_lease` | `kacs_lease(int fd, int manager_fd, struct kacs_lease_args __user *uargs, size_t size)` |

`uapi/pkm/syscall.h` also registers the KMES and LCS numbers,
1090–1104, documented in their own chapters. <a id="cite-kacs-abi.sibling-syscall-range"></a>

<a id="trm-3-a-2"></a>

## Structure layouts

## Related explanations

- [Generated token and session ABI](</kernel/userspace/native/kacs/generated-token-and-session-abi.md>)
- [Generated access-check and descriptor ABI](</kernel/userspace/native/kacs/generated-access-check-and-descriptor-abi.md>)
- [Generated file and mount ABI](</kernel/userspace/native/kacs/generated-file-and-mount-abi.md>)
- [Generated socket and IPC ABI](</kernel/userspace/native/kacs/generated-socket-and-ipc-abi.md>)
- [Generated process and PSB ABI](</kernel/userspace/native/kacs/generated-process-and-psb-abi.md>)
- [Generated diagnostic constants](</kernel/userspace/native/kacs/generated-diagnostic-constants.md>)

---

# Generated token and session ABI

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated token and session ABI: behaviour and implementation of the Peios kernel.

<a id="trm-3-a-2-1"></a>

## `struct kacs_query_args` <a id="cite-kacs-abi.struct-kacs-query-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `token_class` |
| 4 | 4 | `__u32` | `buf_len` |
| 8 | 8 | `__u64` | `buf_ptr` |

<a id="trm-3-a-2-2"></a>

## `struct kacs_adjust_privs_args` <a id="cite-kacs-abi.struct-kacs-adjust-privs-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `count` |
| 4 | 4 | `__u32` | `_pad` |
| 8 | 8 | `__u64` | `data_ptr` |
| 16 | 8 | `__u64` | `previous_enabled` |

<a id="trm-3-a-2-3"></a>

## `struct kacs_priv_entry` <a id="cite-kacs-abi.struct-kacs-priv-entry"></a>

Total size 8 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `luid` |
| 4 | 4 | `__u32` | `attributes` |

<a id="trm-3-a-2-4"></a>

## `struct kacs_adjust_groups_args` <a id="cite-kacs-abi.struct-kacs-adjust-groups-args"></a>

Total size 144 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `count` |
| 4 | 4 | `__u32` | `_pad` |
| 8 | 8 | `__u64` | `data_ptr` |
| 16 | 128 | `__u64``[16]` | `previous_state` |

<a id="trm-3-a-2-5"></a>

## `struct kacs_duplicate_args` <a id="cite-kacs-abi.struct-kacs-duplicate-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `access_mask` |
| 4 | 4 | `__u32` | `token_type` |
| 8 | 4 | `__u32` | `impersonation_level` |
| 12 | 4 | `__s32` | `result_fd` |

<a id="trm-3-a-2-6"></a>

## `struct kacs_group_entry` <a id="cite-kacs-abi.struct-kacs-group-entry"></a>

Total size 8 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `index` |
| 4 | 4 | `__u32` | `enable` |

<a id="trm-3-a-2-7"></a>

## `struct kacs_adjust_default_args` <a id="cite-kacs-abi.struct-kacs-adjust-default-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 8 | `__u64` | `dacl_ptr` |
| 8 | 4 | `__u32` | `dacl_len` |
| 12 | 2 | `__u16` | `owner_index` |
| 14 | 2 | `__u16` | `group_index` |

<a id="trm-3-a-2-8"></a>

## `struct kacs_restrict_args` <a id="cite-kacs-abi.struct-kacs-restrict-args"></a>

Total size 40 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 8 | `__u64` | `privs_to_delete` |
| 8 | 4 | `__u32` | `num_deny_indices` |
| 12 | 4 | `__u32` | `num_restrict_sids` |
| 16 | 4 | `__u32` | `data_len` |
| 20 | 4 | `__u32` | `flags` |
| 24 | 8 | `__u64` | `data_ptr` |
| 32 | 4 | `__s32` | `result_fd` |
| 36 | 4 | `__u32` | `_pad` |

<a id="trm-3-a-2-9"></a>

## `struct kacs_link_tokens_args` <a id="cite-kacs-abi.struct-kacs-link-tokens-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__s32` | `elevated_fd` |
| 4 | 4 | `__s32` | `filtered_fd` |
| 8 | 8 | `__u64` | `logon_session_id` |

<a id="trm-3-a-2-10"></a>

## `struct kacs_get_linked_token_args` <a id="cite-kacs-abi.struct-kacs-get-linked-token-args"></a>

Total size 4 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__s32` | `result_fd` |

<a id="trm-3-a-3"></a>

## Token constants

From `uapi/pkm/token.h`.

*kacs_open_self_token (SYS_KACS_OPEN_SELF_TOKEN) flags.* <a id="cite-kacs-abi.open-self-token-flags"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_OPEN_REAL` | `0x01` (1) |

*Per-handle token rights (the low 16 bits of a token access mask).* <a id="cite-kacs-abi.token-access-rights"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_ASSIGN_PRIMARY` | `0x0001` (1) |
| `KACS_TOKEN_DUPLICATE` | `0x0002` (2) |
| `KACS_TOKEN_IMPERSONATE` | `0x0004` (4) |
| `KACS_TOKEN_QUERY` | `0x0008` (8) |
| `KACS_TOKEN_QUERY_SOURCE` | `0x0010` (16) |
| `KACS_TOKEN_ADJUST_PRIVS` | `0x0020` (32) |
| `KACS_TOKEN_ADJUST_GROUPS` | `0x0040` (64) |
| `KACS_TOKEN_ADJUST_DEFAULT` | `0x0080` (128) |
| `KACS_TOKEN_ADJUST_INTERACTIVITY_SCOPE` | `0x0100` (256) |
| `KACS_TOKEN_ALL_ACCESS` | `0x000F01FF` |

*Token ioctl interface identifier.* <a id="cite-kacs-abi.token-ioctl-magic"></a>

| Constant | Value |
|---|---|
| `KACS_IOC_MAGIC` | `0x4B` (75) |

*kacs_priv_entry.attributes bits.* <a id="cite-kacs-abi.privilege-attributes"></a>

| Constant | Value |
|---|---|
| `KACS_PRIVILEGE_ATTR_ENABLED` | `0x00000002` (2) |
| `KACS_PRIVILEGE_ATTR_REMOVED` | `0x00000004` (4) |

*kacs_adjust_privs bulk-reset flag (not a per-entry attribute).* <a id="cite-kacs-abi.privilege-reset-all-defaults"></a>

| Constant | Value |
|---|---|
| `KACS_PRIVILEGE_RESET_ALL_DEFAULTS` | `0x80000000` |

*kacs_restrict_args.flags bits.* <a id="cite-kacs-abi.restrict-flags"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_RESTRICT_WRITE_RESTRICTED` | `0x00000001` (1) |

*Token type (KACS_TOKEN_CLASS_TYPE).* <a id="cite-kacs-abi.token-types"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_TYPE_PRIMARY` | `0x01` (1) |
| `KACS_TOKEN_TYPE_IMPERSONATION` | `0x02` (2) |

*Impersonation level (KACS_TOKEN_CLASS_IMPERSONATION_LEVEL).* <a id="cite-kacs-abi.impersonation-levels"></a>

| Constant | Value |
|---|---|
| `KACS_IMLEVEL_ANONYMOUS` | `0x00` (0) |
| `KACS_IMLEVEL_IDENTIFICATION` | `0x01` (1) |
| `KACS_IMLEVEL_IMPERSONATION` | `0x02` (2) |
| `KACS_IMLEVEL_DELEGATION` | `0x03` (3) |

*Elevation type (KACS_TOKEN_CLASS_ELEVATION_TYPE).* <a id="cite-kacs-abi.elevation-types"></a>

| Constant | Value |
|---|---|
| `KACS_ELEVATION_DEFAULT` | `0x01` (1) |
| `KACS_ELEVATION_FULL` | `0x02` (2) |
| `KACS_ELEVATION_LIMITED` | `0x03` (3) |

*Mandatory-policy bits (KACS_TOKEN_CLASS_MANDATORY_POLICY).* <a id="cite-kacs-abi.mandatory-policy-bits"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_MANDATORY_POLICY_NO_WRITE_UP` | `0x00000001` (1) |
| `KACS_TOKEN_MANDATORY_POLICY_NEW_PROCESS_MIN` | `0x00000002` (2) |

Per-token audit-policy bits — the create-token spec `audit_policy` field
(KACS_TOKEN_SPEC_OFF_AUDIT_POLICY). They select which access-check
outcomes the token's object accesses generate audit events for. <a id="cite-kacs-abi.audit-policy-bits"></a>

| Constant | Value |
|---|---|
| `KACS_AUDIT_POLICY_OBJECT_ACCESS_SUCCESS` | `0x00000001` (1) |
| `KACS_AUDIT_POLICY_OBJECT_ACCESS_FAILURE` | `0x00000002` (2) |
| `KACS_AUDIT_POLICY_PRIVILEGE_USE_SUCCESS` | `0x00000004` (4) |
| `KACS_AUDIT_POLICY_PRIVILEGE_USE_FAILURE` | `0x00000008` (8) |

*Logon type (KACS_TOKEN_CLASS_LOGON_TYPE).* <a id="cite-kacs-abi.logon-types"></a>

| Constant | Value |
|---|---|
| `KACS_LOGON_TYPE_INTERACTIVE` | `2` |
| `KACS_LOGON_TYPE_NETWORK` | `3` |
| `KACS_LOGON_TYPE_BATCH` | `4` |
| `KACS_LOGON_TYPE_SERVICE` | `5` |
| `KACS_LOGON_TYPE_NETWORK_CLEARTEXT` | `8` |
| `KACS_LOGON_TYPE_NEW_CREDENTIALS` | `9` |
| `KACS_LOGON_TYPE_REMOTE_INTERACTIVE` | `10` |

*Maximum number of groups a token may carry.* <a id="cite-kacs-abi.token-max-groups"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_MAX_GROUPS` | `1024` |

*Number of 64-bit words in a group enabled-state bitmask (KACS_TOKEN_MAX_GROUPS / 64).* <a id="cite-kacs-abi.token-group-mask-words"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_GROUP_MASK_WORDS` | `16` |

*kacs_create_token (SYS_KACS_CREATE_TOKEN) spec wire format.* <a id="cite-kacs-abi.token-spec-wire-format"></a>

The (spec, len) buffer the syscall consumes is a fixed
KACS_TOKEN_SPEC_HEADER_BYTES-byte header followed by variable-length
sections at header-specified byte offsets. An offset/length (or
offset/count) pair that is both zero means the section is absent.
Sections may appear in any order; every offset+length is validated to
fall within the buffer. The header is not a C struct (it carries packed
mixed-width fields and crosses the syscall boundary as raw bytes); read
each field at its KACS_TOKEN_SPEC_OFF_* offset. Its fields, in order:
__u32 version must be KACS_TOKEN_SPEC_VERSION __u8 token_type
KACS_TOKEN_TYPE_ __u8 impersonation_level KACS_IMLEVEL_ __u8
_reserved0[2] must be 0 __u32 integrity_rid integrity-level RID __u32
mandatory_policy KACS_TOKEN_MANDATORY_POLICY_* bits __u64 privs_present
privilege bitmask (KACS_SE_*_PRIVILEGE) __u64 privs_enabled initially
enabled privileges (subset) __u32 _reserved1 must be 0 (elevation set
only by LINK_TOKENS) __u32 projected_uid Linux UID for credential
projection __u32 projected_gid Linux GID for credential projection __u32
audit_policy per-token audit flags __u64 expiration expiry timestamp (0
= none) __u64 logon_session_id logon session ID (auth_id) __u32
owner_sid_index 0 = user SID, 1..N = caller group __u32
primary_group_index 0 = user SID, 1..N = caller group __u8
source_name[8] token source name __u64 source_id token source LUID __u32
user_sid_offset byte offset to the user SID __u32 groups_offset byte
offset to the groups array __u32 groups_count number of group entries
__u32 default_dacl_offset byte offset to the default DACL (0 = none)
__u32 default_dacl_len default DACL byte length (0 = none) __u32
user_claims_offset byte offset to user claims (0 = none) __u32
user_claims_len user claims byte length (0 = none) __u32
device_claims_offset byte offset to device claims (0 = none) __u32
device_claims_len device claims byte length (0 = none) __u32
device_groups_offset byte offset to device groups (0 = none) __u32
device_groups_count number of device-group entries (0 = none) __u32
restricted_sids_offset byte offset to restricted SIDs (0 = none) __u32
restricted_sids_count number of restricted-SID entries (0 = none) __u32
confinement_sid_offset byte offset to confinement SID (0 = none) __u32
confinement_sid_len confinement SID byte length (0 = none) __u32
confinement_caps_offset byte offset to confinement caps (0 = none) __u32
confinement_caps_count number of confinement-cap entries (0 = none) __u8
confinement_exempt 1 = exempt from confinement __u8 write_restricted 1 =
write-restricted mode __u8 user_deny_only 1 = user SID matches deny ACEs
only __u8 isolation_boundary 1 = enable namespace filtering __u32
supp_gids_offset byte offset to supplementary GIDs (0 = none) __u32
supp_gids_count number of supplementary-GID entries (0 = none) __u32
restricted_device_groups_offset byte offset (0 = none) __u32
restricted_device_groups_count entry count (0 = none) __u64 origin
originating logon-session LUID (0 = none) __u32 interactivity_scope
interactive session number __u32 lcs_credentials_offset byte offset to
the LCS extension (0 = none) A group/device-group/restricted-
SID/confinement-cap/restricted-device-group entry is [__u32
sid_len][__u8 sid[sid_len]][__u32 attributes]. A supplementary-GIDs
section is supp_gids_count little-endian __u32 GIDs. All multi-byte
header and section scalars are little-endian.

| Constant | Value |
|---|---|
| `KACS_TOKEN_SPEC_VERSION` | `2` |
| `KACS_TOKEN_SPEC_HEADER_BYTES` | `192` |
| `KACS_TOKEN_SPEC_MIN_BYTES` | `192` |
| `KACS_TOKEN_SPEC_MAX_BYTES` | `65536` |

*Byte offsets of the fixed token-spec header fields.* <a id="cite-kacs-abi.token-spec-offsets"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_SPEC_OFF_VERSION` | `0` |
| `KACS_TOKEN_SPEC_OFF_TOKEN_TYPE` | `4` |
| `KACS_TOKEN_SPEC_OFF_IMPERSONATION_LEVEL` | `5` |
| `KACS_TOKEN_SPEC_OFF_RESERVED0` | `6` |
| `KACS_TOKEN_SPEC_OFF_INTEGRITY_RID` | `8` |
| `KACS_TOKEN_SPEC_OFF_MANDATORY_POLICY` | `12` |
| `KACS_TOKEN_SPEC_OFF_PRIVS_PRESENT` | `16` |
| `KACS_TOKEN_SPEC_OFF_PRIVS_ENABLED` | `24` |
| `KACS_TOKEN_SPEC_OFF_RESERVED1` | `32` |
| `KACS_TOKEN_SPEC_OFF_PROJECTED_UID` | `36` |
| `KACS_TOKEN_SPEC_OFF_PROJECTED_GID` | `40` |
| `KACS_TOKEN_SPEC_OFF_AUDIT_POLICY` | `44` |
| `KACS_TOKEN_SPEC_OFF_EXPIRATION` | `48` |
| `KACS_TOKEN_SPEC_OFF_LOGON_SESSION_ID` | `56` |
| `KACS_TOKEN_SPEC_OFF_OWNER_SID_INDEX` | `64` |
| `KACS_TOKEN_SPEC_OFF_PRIMARY_GROUP_INDEX` | `68` |
| `KACS_TOKEN_SPEC_OFF_SOURCE_NAME` | `72` |
| `KACS_TOKEN_SPEC_OFF_SOURCE_ID` | `80` |
| `KACS_TOKEN_SPEC_OFF_USER_SID_OFFSET` | `88` |
| `KACS_TOKEN_SPEC_OFF_GROUPS_OFFSET` | `92` |
| `KACS_TOKEN_SPEC_OFF_GROUPS_COUNT` | `96` |
| `KACS_TOKEN_SPEC_OFF_DEFAULT_DACL_OFFSET` | `100` |
| `KACS_TOKEN_SPEC_OFF_DEFAULT_DACL_LEN` | `104` |
| `KACS_TOKEN_SPEC_OFF_USER_CLAIMS_OFFSET` | `108` |
| `KACS_TOKEN_SPEC_OFF_USER_CLAIMS_LEN` | `112` |
| `KACS_TOKEN_SPEC_OFF_DEVICE_CLAIMS_OFFSET` | `116` |
| `KACS_TOKEN_SPEC_OFF_DEVICE_CLAIMS_LEN` | `120` |
| `KACS_TOKEN_SPEC_OFF_DEVICE_GROUPS_OFFSET` | `124` |
| `KACS_TOKEN_SPEC_OFF_DEVICE_GROUPS_COUNT` | `128` |
| `KACS_TOKEN_SPEC_OFF_RESTRICTED_SIDS_OFFSET` | `132` |
| `KACS_TOKEN_SPEC_OFF_RESTRICTED_SIDS_COUNT` | `136` |
| `KACS_TOKEN_SPEC_OFF_CONFINEMENT_SID_OFFSET` | `140` |
| `KACS_TOKEN_SPEC_OFF_CONFINEMENT_SID_LEN` | `144` |
| `KACS_TOKEN_SPEC_OFF_CONFINEMENT_CAPS_OFFSET` | `148` |
| `KACS_TOKEN_SPEC_OFF_CONFINEMENT_CAPS_COUNT` | `152` |
| `KACS_TOKEN_SPEC_OFF_CONFINEMENT_EXEMPT` | `156` |
| `KACS_TOKEN_SPEC_OFF_WRITE_RESTRICTED` | `157` |
| `KACS_TOKEN_SPEC_OFF_USER_DENY_ONLY` | `158` |
| `KACS_TOKEN_SPEC_OFF_ISOLATION_BOUNDARY` | `159` |
| `KACS_TOKEN_SPEC_OFF_SUPP_GIDS_OFFSET` | `160` |
| `KACS_TOKEN_SPEC_OFF_SUPP_GIDS_COUNT` | `164` |
| `KACS_TOKEN_SPEC_OFF_RESTRICTED_DEVICE_GROUPS_OFFSET` | `168` |
| `KACS_TOKEN_SPEC_OFF_RESTRICTED_DEVICE_GROUPS_COUNT` | `172` |
| `KACS_TOKEN_SPEC_OFF_ORIGIN` | `176` |
| `KACS_TOKEN_SPEC_OFF_INTERACTIVITY_SCOPE` | `184` |
| `KACS_TOKEN_SPEC_OFF_LCS_CREDENTIALS_OFFSET` | `188` |

*Byte length of the fixed token-source-name field.* <a id="cite-kacs-abi.token-source-name-bytes"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_SPEC_SOURCE_NAME_BYTES` | `8` |

Optional LCS registry-credentials extension, located at the token-spec
header's lcs_credentials_offset. The section is a fixed
KACS_TOKEN_LCS_EXT_HEADER_BYTES-byte header bounded by the next active
variable-section offset or the end of the spec; it is consumed exactly
(trailing bytes are malformed). Header fields, in order: __u32 version
must be KACS_TOKEN_LCS_EXT_VERSION __u32 _reserved must be 0 __u32
scope_count private hive scope GUIDs (<= max) __u32 private_layer_count
private layer names (<= max) Payload: scope_count raw 16-byte GUIDs,
then private_layer_count little-endian __u32 name byte lengths, then the
concatenated UTF-8 layer names. Scope GUIDs must be non-nil and unique;
layer names must be 1.. KACS_TOKEN_LCS_MAX_LAYER_NAME_BYTES bytes, must
not contain '\\', '/', or NUL, and must be unique under case-insensitive
matching. <a id="cite-kacs-abi.token-lcs-extension"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_LCS_EXT_VERSION` | `1` |
| `KACS_TOKEN_LCS_EXT_HEADER_BYTES` | `16` |
| `KACS_TOKEN_LCS_SCOPE_GUID_BYTES` | `16` |
| `KACS_TOKEN_LCS_MAX_SCOPE_GUIDS` | `256` |
| `KACS_TOKEN_LCS_MAX_PRIVATE_LAYERS` | `256` |
| `KACS_TOKEN_LCS_MAX_LAYER_NAME_BYTES` | `255` |

*Byte offsets of the fixed LCS-extension header fields.* <a id="cite-kacs-abi.token-lcs-extension-offsets"></a>

| Constant | Value |
|---|---|
| `KACS_TOKEN_LCS_EXT_OFF_VERSION` | `0` |
| `KACS_TOKEN_LCS_EXT_OFF_RESERVED` | `4` |
| `KACS_TOKEN_LCS_EXT_OFF_SCOPE_COUNT` | `8` |
| `KACS_TOKEN_LCS_EXT_OFF_PRIVATE_LAYER_COUNT` | `12` |

*kacs_create_logon_session (SYS_KACS_CREATE_LOGON_SESSION) spec wire format.* <a id="cite-kacs-abi.logon-session-spec-wire-format"></a>

The (spec, len) buffer the syscall consumes is, in order: __u8
logon_type one of KACS_LOGON_TYPE_* above __le16 auth_pkg_len byte
length of the auth-package name __u8 auth_pkg[auth_pkg_len] auth-package
name (valid UTF-8) __le32 user_sid_len byte length of the user SID __u8
user_sid[user_sid_len] binary SID of the authenticated user The buffer
is consumed exactly: 7 + auth_pkg_len + user_sid_len must equal len. The
kernel assigns the session ID and derives the logon SID from it.

| Constant | Value |
|---|---|
| `KACS_LOGON_SESSION_SPEC_MIN_BYTES` | `15` |
| `KACS_LOGON_SESSION_SPEC_MAX_BYTES` | `4096` |

*Byte offsets of the fixed-position session-spec fields.* <a id="cite-kacs-abi.logon-session-spec-offsets"></a>

| Constant | Value |
|---|---|
| `KACS_LOGON_SESSION_SPEC_OFF_LOGON_TYPE` | `0` |
| `KACS_LOGON_SESSION_SPEC_OFF_AUTH_PKG_LEN` | `1` |
| `KACS_LOGON_SESSION_SPEC_OFF_AUTH_PKG` | `3` |

*Token-handle ioctls.* <a id="cite-kacs-abi.token-ioctls"></a>

| Constant | Value |
|---|---|
| `KACS_IOC_QUERY` | `0xC0104B00` |
| `KACS_IOC_ADJUST_PRIVS` | `0x40184B01` |
| `KACS_IOC_DUPLICATE` | `0xC0104B02` |
| `KACS_IOC_INSTALL` | `0x00004B03` |
| `KACS_IOC_RESTRICT` | `0xC0284B04` |
| `KACS_IOC_LINK_TOKENS` | `0x40104B05` |
| `KACS_IOC_GET_LINKED_TOKEN` | `0xC0044B06` |
| `KACS_IOC_ADJUST_GROUPS` | `0x40904B07` |
| `KACS_IOC_IMPERSONATE` | `0x00004B08` |
| `KACS_IOC_ADJUST_DEFAULT` | `0x40104B09` |
| `KACS_IOC_ADJUST_INTERACTIVITY_SCOPE` | `0x40044B0A` |

*Token information classes (kacs_query_args.token_class).* <a id="cite-kacs-abi.token-information-classes"></a>

GUID returns 16 immutable raw bytes in the same order as KMES headers.

| Constant | Value |
|---|---|
| `KACS_TOKEN_CLASS_USER` | `0x01` (1) |
| `KACS_TOKEN_CLASS_GROUPS` | `0x02` (2) |
| `KACS_TOKEN_CLASS_PRIVILEGES` | `0x03` (3) |
| `KACS_TOKEN_CLASS_TYPE` | `0x04` (4) |
| `KACS_TOKEN_CLASS_INTEGRITY_LEVEL` | `0x05` (5) |
| `KACS_TOKEN_CLASS_OWNER` | `0x06` (6) |
| `KACS_TOKEN_CLASS_PRIMARY_GROUP` | `0x07` (7) |
| `KACS_TOKEN_CLASS_INTERACTIVITY_SCOPE` | `0x08` (8) |
| `KACS_TOKEN_CLASS_RESTRICTED_SIDS` | `0x09` (9) |
| `KACS_TOKEN_CLASS_SOURCE` | `0x0A` (10) |
| `KACS_TOKEN_CLASS_STATISTICS` | `0x0B` (11) |
| `KACS_TOKEN_CLASS_ORIGIN` | `0x0C` (12) |
| `KACS_TOKEN_CLASS_ELEVATION_TYPE` | `0x0D` (13) |
| `KACS_TOKEN_CLASS_DEVICE_GROUPS` | `0x0E` (14) |
| `KACS_TOKEN_CLASS_APPCONTAINER_SID` | `0x0F` (15) |
| `KACS_TOKEN_CLASS_CAPABILITIES` | `0x10` (16) |
| `KACS_TOKEN_CLASS_MANDATORY_POLICY` | `0x11` (17) |
| `KACS_TOKEN_CLASS_LOGON_TYPE` | `0x12` (18) |
| `KACS_TOKEN_CLASS_LOGON_SID` | `0x13` (19) |
| `KACS_TOKEN_CLASS_DEFAULT_DACL` | `0x14` (20) |
| `KACS_TOKEN_CLASS_IMPERSONATION_LEVEL` | `0x15` (21) |
| `KACS_TOKEN_CLASS_USER_CLAIMS` | `0x16` (22) |
| `KACS_TOKEN_CLASS_DEVICE_CLAIMS` | `0x17` (23) |
| `KACS_TOKEN_CLASS_PROJECTED_SUPPLEMENTARY_GIDS` | `0x18` (24) |
| `KACS_TOKEN_CLASS_GUID` | `0x19` (25) |

Privileges, as single-bit masks within a token's 64-bit privilege word
(present / enabled / enabled-by-default / used are each one such word).
Named for the Windows privilege identifiers (SeTcbPrivilege, …). <a id="cite-kacs-abi.privilege-bits"></a>

| Constant | Value |
|---|---|
| `KACS_SE_CREATE_TOKEN_PRIVILEGE` | `4` |
| `KACS_SE_ASSIGN_PRIMARY_TOKEN_PRIVILEGE` | `8` |
| `KACS_SE_LOCK_MEMORY_PRIVILEGE` | `16` |
| `KACS_SE_INCREASE_QUOTA_PRIVILEGE` | `32` |
| `KACS_SE_TCB_PRIVILEGE` | `128` |
| `KACS_SE_SECURITY_PRIVILEGE` | `256` |
| `KACS_SE_TAKE_OWNERSHIP_PRIVILEGE` | `512` |
| `KACS_SE_LOAD_DRIVER_PRIVILEGE` | `1024` |
| `KACS_SE_SYSTEM_PROFILE_PRIVILEGE` | `2048` |
| `KACS_SE_SYSTEMTIME_PRIVILEGE` | `4096` |
| `KACS_SE_PROFILE_SINGLE_PROCESS_PRIVILEGE` | `8192` |
| `KACS_SE_INCREASE_BASE_PRIORITY_PRIVILEGE` | `16384` |
| `KACS_SE_BACKUP_PRIVILEGE` | `131072` |
| `KACS_SE_RESTORE_PRIVILEGE` | `262144` |
| `KACS_SE_SHUTDOWN_PRIVILEGE` | `524288` |
| `KACS_SE_DEBUG_PRIVILEGE` | `0x100000` (1048576) |
| `KACS_SE_AUDIT_PRIVILEGE` | `0x200000` (2097152) |
| `KACS_SE_CHANGE_NOTIFY_PRIVILEGE` | `0x800000` (8388608) |
| `KACS_SE_REMOTE_SHUTDOWN_PRIVILEGE` | `0x1000000` (16777216) |
| `KACS_SE_MANAGE_VOLUME_PRIVILEGE` | `0x10000000` (268435456) |
| `KACS_SE_IMPERSONATE_PRIVILEGE` | `0x20000000` (536870912) |
| `KACS_SE_RELABEL_PRIVILEGE` | `0x100000000` (4294967296) |
| `KACS_SE_CREATE_SYMBOLIC_LINK_PRIVILEGE` | `0x800000000` (34359738368) |
| `KACS_SE_LOCK_PARENTAGE_PRIVILEGE` | `0x2000000000000000` (2305843009213693952) |

---

# Generated access-check and descriptor ABI

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated access-check and descriptor ABI: behaviour and implementation of the Peios kernel.

<a id="trm-3-a-2-11"></a>

## `struct kacs_subject_request` <a id="cite-kacs-abi.struct-kacs-subject-request"></a>

Total size 152 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `version` |
| 4 | 4 | `__u32` | `total_bytes` |
| 8 | 4 | `__u32` | `flags` |
| 12 | 4 | `__u32` | `known_groups` |
| 16 | 4 | `__u32` | `desired_access` |
| 20 | 4 | `__u32` | `mapping_read` |
| 24 | 4 | `__u32` | `mapping_write` |
| 28 | 4 | `__u32` | `mapping_execute` |
| 32 | 4 | `__u32` | `mapping_all` |
| 36 | 4 | `__u32` | `object_index` |
| 40 | 4 | `__u32` | `complete_claims` |
| 44 | 4 | `__u32` | `reserved` |
| 48 | 104 | `__u32``[26]` | `sections` |

<a id="trm-3-a-2-12"></a>

## `struct kacs_subject_result` <a id="cite-kacs-abi.struct-kacs-subject-result"></a>

Total size 12 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `decision` |
| 4 | 4 | `__u32` | `granted` |
| 8 | 4 | `__u32` | `missing` |

<a id="trm-3-a-2-13"></a>

## `struct kacs_access_check_args` <a id="cite-kacs-abi.struct-kacs-access-check-args"></a>

Total size 136 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `caller_size` |
| 4 | 4 | `__s32` | `token_fd` |
| 8 | 8 | `__u64` | `sd_ptr` |
| 16 | 4 | `__u32` | `sd_len` |
| 20 | 4 | `__u32` | `desired_access` |
| 24 | 4 | `__u32` | `mapping_read` |
| 28 | 4 | `__u32` | `mapping_write` |
| 32 | 4 | `__u32` | `mapping_execute` |
| 36 | 4 | `__u32` | `mapping_all` |
| 40 | 8 | `__u64` | `self_sid_ptr` |
| 48 | 4 | `__u32` | `self_sid_len` |
| 52 | 4 | `__u32` | `privilege_intent` |
| 56 | 8 | `__u64` | `object_tree_ptr` |
| 64 | 4 | `__u32` | `object_tree_count` |
| 68 | 4 | `__u32` | `_pad0` |
| 72 | 8 | `__u64` | `local_claims_ptr` |
| 80 | 4 | `__u32` | `local_claims_len` |
| 84 | 4 | `__u32` | `_pad1` |
| 88 | 8 | `__u64` | `granted_out_ptr` |
| 96 | 4 | `__u32` | `pip_type` |
| 100 | 4 | `__u32` | `pip_trust` |
| 104 | 8 | `__u64` | `audit_context_ptr` |
| 112 | 4 | `__u32` | `audit_context_len` |
| 116 | 4 | `__u32` | `_pad2` |
| 120 | 8 | `__u64` | `continuous_audit_out_ptr` |
| 128 | 8 | `__u64` | `staging_mismatch_out_ptr` |

<a id="trm-3-a-2-14"></a>

## `struct kacs_object_type_entry` <a id="cite-kacs-abi.struct-kacs-object-type-entry"></a>

Total size 20 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 2 | `__u16` | `level` |
| 2 | 2 | `__u16` | `_reserved` |
| 4 | 16 | `__u8``[16]` | `guid` |

<a id="trm-3-a-2-15"></a>

## `struct kacs_node_result` <a id="cite-kacs-abi.struct-kacs-node-result"></a>

Total size 8 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `granted` |
| 4 | 4 | `__s32` | `status` |

<a id="trm-3-a-2-23"></a>

## `struct kacs_generic_mapping` <a id="cite-kacs-abi.struct-kacs-generic-mapping"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `read` |
| 4 | 4 | `__u32` | `write` |
| 8 | 4 | `__u32` | `execute` |
| 12 | 4 | `__u32` | `all` |

<a id="trm-3-a-7"></a>

## AccessCheck constants

From `uapi/pkm/access.h`.

*Full size of kacs_access_check_args the current kernel copies.* <a id="cite-kacs-abi.access-check-args-size"></a>

| Constant | Value |
|---|---|
| `KACS_ACCESS_CHECK_ARGS_SIZE` | `136` |

*Minimum caller_size the kernel accepts (the v1 / v0.20 layout).* <a id="cite-kacs-abi.access-check-args-v1-size"></a>

| Constant | Value |
|---|---|
| `KACS_ACCESS_CHECK_ARGS_V1_SIZE` | `40` |

*Byte size of one kacs_object_type_entry in the object-type tree array.* <a id="cite-kacs-abi.object-type-entry-size"></a>

| Constant | Value |
|---|---|
| `KACS_OBJECT_TYPE_ENTRY_SIZE` | `20` |

*Largest object-audit-context buffer the kernel accepts.* <a id="cite-kacs-abi.max-audit-context-len"></a>

| Constant | Value |
|---|---|
| `KACS_ACCESS_CHECK_MAX_AUDIT_CONTEXT_LEN` | `4096` |

*Largest @Local claims blob the kernel accepts (local_claims_ptr).* <a id="cite-kacs-abi.max-local-claims-len"></a>

| Constant | Value |
|---|---|
| `KACS_ACCESS_CHECK_MAX_LOCAL_CLAIMS_LEN` | `65536` |

*Largest object-type tree entry count the kernel accepts.* <a id="cite-kacs-abi.max-object-type-count"></a>

| Constant | Value |
|---|---|
| `KACS_ACCESS_CHECK_MAX_OBJECT_TYPE_COUNT` | `1024` |

*Supplied-subject query, syscall 1028.*

No token is created or adopted. One LE buffer contains this 152-byte
header followed by packed sections in table order. Each pair is {offset,
byte_length}; empty sections use {0,0}. Sections: SD, user SID, groups,
device groups, user/device/local claims, user/device/local known-absent
names, SELF SID, object tree, audit context. Groups use repeated {u32
sid_len, SID bytes, u32 attributes}; claims use repeated {u32 entry_len,
typed claim entry}; absent names use {u32 len, UTF8}. Known bits 0/1
distinguish known-empty user/device groups from unknown. Coverage bits
0/1/2 mark complete user/device/local claim sets; otherwise omitted
claim names remain unknown unless listed explicitly as absent. Unknown
flags/bits, nonzero reserved fields, gaps/overlap/trailing bytes,
invalid or excessive collections fail the entire request. No truncation.
Typed claims are at most 64 KiB per namespace, 1024 values per
attribute; the sum of entry_bytes * max(value_count, 1), including SD
resource claims, is at most 1 MiB, bounding repeated-offset decoding
before allocation. Absent names are 1..255 UTF8 bytes; each collection
has at most 1024 items.

| Constant | Value |
|---|---|
| `KACS_SUBJECT_VERSION` | `1` |
| `KACS_SUBJECT_HEADER_BYTES` | `152` |
| `KACS_SUBJECT_MAX_BYTES` | `0x100000` (1048576) |
| `KACS_SUBJECT_MAX_ITEMS` | `1024` |
| `KACS_SUBJECT_NO_AUDIT` | `1` |

Claim value types — the discriminant of one attribute in the @Local
claims array (local_claims_ptr). <a id="cite-kacs-abi.claim-value-types"></a>

| Constant | Value |
|---|---|
| `KACS_CLAIM_TYPE_INT64` | `0x0001` (1) |
| `KACS_CLAIM_TYPE_UINT64` | `0x0002` (2) |
| `KACS_CLAIM_TYPE_STRING` | `0x0003` (3) |
| `KACS_CLAIM_TYPE_SID` | `0x0005` (5) |
| `KACS_CLAIM_TYPE_BOOLEAN` | `0x0006` (6) |
| `KACS_CLAIM_TYPE_OCTET` | `0x0010` (16) |

*Claim attribute flags.* <a id="cite-kacs-abi.claim-attribute-flags"></a>

| Constant | Value |
|---|---|
| `KACS_CLAIM_ATTR_CASE_SENSITIVE` | `0x0002` (2) |
| `KACS_CLAIM_ATTR_USE_FOR_DENY_ONLY` | `0x0004` (4) |
| `KACS_CLAIM_ATTR_DISABLED` | `0x0010` (16) |

Central Access Policy (CAAP) spec wire format — the (spec, spec_len)
buffer kacs_set_caap (SYS_KACS_SET_CAAP) consumes. A non-empty spec
replaces the policy identified by the call's policy SID; a NULL/zero
spec removes it. The buffer is a fixed prefix followed by rule_count
per-rule sections, and is consumed exactly (trailing bytes are
rejected). It is not a C struct (the rule sections are variable-length);
read it as raw bytes: __u8 version must be KACS_CAAP_SPEC_VERSION __le32
rule_count number of rules that follow (<= max) rule_count * { __le32
applies_to_len [__u8 applies_to[applies_to_len]] conditional-expression
bytecode; 0 = always __le32 effective_dacl_len [__u8
effective_dacl[...]] binary ACL; length MUST be nonzero __le32
effective_sacl_len [__u8 effective_sacl[...]] (0 = none) __le32
staged_dacl_len [__u8 staged_dacl[...]] (0 = none) __le32
staged_sacl_len [__u8 staged_sacl[...]] (0 = none) } Every length-
prefixed field uses a little-endian __u32 length and is bounded by
KACS_CAAP_MAX_FIELD_BYTES; ACL payloads additionally parse under the
security-descriptor size limit (KACS_CAAP_MAX_ACL_BYTES). ACLs use the
binary ACL format from <pkm/sd.h>; applies_to is conditional-ACE
bytecode. <a id="cite-kacs-abi.caap-spec-wire-format"></a>

| Constant | Value |
|---|---|
| `KACS_CAAP_SPEC_VERSION` | `0x01` (1) |
| `KACS_CAAP_MAX_SPEC_BYTES` | `262144` |
| `KACS_CAAP_MAX_RULE_COUNT` | `256` |
| `KACS_CAAP_MAX_FIELD_BYTES` | `65536` |
| `KACS_CAAP_MAX_ACL_BYTES` | `65535` |

*Byte offsets of the fixed CAAP-spec prefix fields.* <a id="cite-kacs-abi.caap-spec-offsets"></a>

| Constant | Value |
|---|---|
| `KACS_CAAP_SPEC_OFF_VERSION` | `0` |
| `KACS_CAAP_SPEC_OFF_RULE_COUNT` | `1` |

*Byte length of the fixed CAAP-spec prefix (version + rule_count).* <a id="cite-kacs-abi.caap-spec-prefix-bytes"></a>

| Constant | Value |
|---|---|
| `KACS_CAAP_SPEC_PREFIX_BYTES` | `5` |

<a id="trm-3-a-11"></a>

## Security descriptor constants

From `uapi/pkm/sd.h`.

*Byte length of the self-relative security-descriptor header.* <a id="cite-kacs-abi.sd-header-bytes"></a>

| Constant | Value |
|---|---|
| `KACS_SD_HEADER_BYTES` | `20` |

SECURITY_INFORMATION selector bits — which components of a security
descriptor a kacs_get_sd / kacs_set_sd call reads or writes. <a id="cite-kacs-abi.security-information-bits"></a>

| Constant | Value |
|---|---|
| `KACS_SECINFO_OWNER` | `0x00000001` (1) |
| `KACS_SECINFO_GROUP` | `0x00000002` (2) |
| `KACS_SECINFO_DACL` | `0x00000004` (4) |
| `KACS_SECINFO_SACL` | `0x00000008` (8) |
| `KACS_SECINFO_LABEL` | `0x00000010` (16) |

*SECURITY_DESCRIPTOR_CONTROL bits — the SD header `control` field.* <a id="cite-kacs-abi.sd-control-bits"></a>

| Constant | Value |
|---|---|
| `KACS_SD_OWNER_DEFAULTED` | `0x0001` (1) |
| `KACS_SD_GROUP_DEFAULTED` | `0x0002` (2) |
| `KACS_SD_DACL_PRESENT` | `0x0004` (4) |
| `KACS_SD_DACL_DEFAULTED` | `0x0008` (8) |
| `KACS_SD_SACL_PRESENT` | `0x0010` (16) |
| `KACS_SD_SACL_DEFAULTED` | `0x0020` (32) |
| `KACS_SD_DACL_TRUSTED` | `0x0040` (64) |
| `KACS_SD_SERVER_SECURITY` | `0x0080` (128) |
| `KACS_SD_DACL_AUTO_INHERIT_REQ` | `0x0100` (256) |
| `KACS_SD_SACL_AUTO_INHERIT_REQ` | `0x0200` (512) |
| `KACS_SD_DACL_AUTO_INHERITED` | `0x0400` (1024) |
| `KACS_SD_SACL_AUTO_INHERITED` | `0x0800` (2048) |
| `KACS_SD_DACL_PROTECTED` | `0x1000` (4096) |
| `KACS_SD_SACL_PROTECTED` | `0x2000` (8192) |
| `KACS_SD_RM_CONTROL_VALID` | `0x4000` (16384) |
| `KACS_SD_SELF_RELATIVE` | `0x8000` (32768) |

*Access-mask bits — standard rights (bits 16-24) and generic rights (bits 28-31).* <a id="cite-kacs-abi.standard-and-generic-rights"></a>

The low 16 bits of a mask are object-class specific; see <pkm/file.h>
and <pkm/token.h> for those.

| Constant | Value |
|---|---|
| `KACS_ACCESS_DELETE` | `0x00010000` (65536) |
| `KACS_ACCESS_READ_CONTROL` | `0x00020000` |
| `KACS_ACCESS_WRITE_DAC` | `0x00040000` |
| `KACS_ACCESS_WRITE_OWNER` | `0x00080000` |
| `KACS_ACCESS_SYNCHRONIZE` | `0x00100000` |
| `KACS_ACCESS_ACCESS_SYSTEM_SECURITY` | `0x01000000` |
| `KACS_ACCESS_MAXIMUM_ALLOWED` | `0x02000000` |
| `KACS_ACCESS_GENERIC_ALL` | `0x10000000` |
| `KACS_ACCESS_GENERIC_EXECUTE` | `0x20000000` |
| `KACS_ACCESS_GENERIC_WRITE` | `0x40000000` |
| `KACS_ACCESS_GENERIC_READ` | `0x80000000` |

*ACE types — the `ace_type` byte of an ACE header (MS-DTYP 2.4.4.1).* <a id="cite-kacs-abi.ace-types"></a>

| Constant | Value |
|---|---|
| `KACS_ACE_TYPE_ACCESS_ALLOWED` | `0x00` (0) |
| `KACS_ACE_TYPE_ACCESS_DENIED` | `0x01` (1) |
| `KACS_ACE_TYPE_SYSTEM_AUDIT` | `0x02` (2) |
| `KACS_ACE_TYPE_SYSTEM_ALARM` | `0x03` (3) |
| `KACS_ACE_TYPE_ACCESS_ALLOWED_COMPOUND` | `0x04` (4) |
| `KACS_ACE_TYPE_ACCESS_ALLOWED_OBJECT` | `0x05` (5) |
| `KACS_ACE_TYPE_ACCESS_DENIED_OBJECT` | `0x06` (6) |
| `KACS_ACE_TYPE_SYSTEM_AUDIT_OBJECT` | `0x07` (7) |
| `KACS_ACE_TYPE_SYSTEM_ALARM_OBJECT` | `0x08` (8) |
| `KACS_ACE_TYPE_ACCESS_ALLOWED_CALLBACK` | `0x09` (9) |
| `KACS_ACE_TYPE_ACCESS_DENIED_CALLBACK` | `0x0A` (10) |
| `KACS_ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT` | `0x0B` (11) |
| `KACS_ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT` | `0x0C` (12) |
| `KACS_ACE_TYPE_SYSTEM_AUDIT_CALLBACK` | `0x0D` (13) |
| `KACS_ACE_TYPE_SYSTEM_ALARM_CALLBACK` | `0x0E` (14) |
| `KACS_ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT` | `0x0F` (15) |
| `KACS_ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT` | `0x10` (16) |
| `KACS_ACE_TYPE_SYSTEM_MANDATORY_LABEL` | `0x11` (17) |
| `KACS_ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE` | `0x12` (18) |
| `KACS_ACE_TYPE_SYSTEM_SCOPED_POLICY_ID` | `0x13` (19) |
| `KACS_ACE_TYPE_SYSTEM_PROCESS_TRUST_LABEL` | `0x14` (20) |
| `KACS_ACE_TYPE_SYSTEM_ACCESS_FILTER` | `0x15` (21) |

*ACE header `ace_flags` byte — inheritance and audit control.* <a id="cite-kacs-abi.ace-flags"></a>

| Constant | Value |
|---|---|
| `KACS_ACE_FLAG_OBJECT_INHERIT` | `0x01` (1) |
| `KACS_ACE_FLAG_CONTAINER_INHERIT` | `0x02` (2) |
| `KACS_ACE_FLAG_NO_PROPAGATE_INHERIT` | `0x04` (4) |
| `KACS_ACE_FLAG_INHERIT_ONLY` | `0x08` (8) |
| `KACS_ACE_FLAG_INHERITED` | `0x10` (16) |
| `KACS_ACE_FLAG_SUCCESSFUL_ACCESS` | `0x40` (64) |
| `KACS_ACE_FLAG_FAILED_ACCESS` | `0x80` (128) |

Mandatory-label policy bits — the __le32 access mask of a
KACS_ACE_TYPE_SYSTEM_MANDATORY_LABEL ACE. They control which DACL-
granted rights a caller whose integrity level does not dominate the
object's label (the "up" direction) is denied. Each bit suppresses the
rights mapped from the corresponding generic class; unknown bits MUST be
ignored. <a id="cite-kacs-abi.mandatory-label-policy-bits"></a>

| Constant | Value |
|---|---|
| `KACS_SYSTEM_MANDATORY_LABEL_NO_READ_UP` | `0x00000001` (1) |
| `KACS_SYSTEM_MANDATORY_LABEL_NO_WRITE_UP` | `0x00000002` (2) |
| `KACS_SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP` | `0x00000004` (4) |

Object-ACE body `Flags` field — the __le32 at object-ACE body offset 8,
distinct from the 1-byte `ace_flags` header field above. Indicates which
optional GUIDs the object-ACE body carries. <a id="cite-kacs-abi.object-ace-flags"></a>

| Constant | Value |
|---|---|
| `KACS_ACE_OBJECT_TYPE_PRESENT` | `0x00000001` (1) |
| `KACS_ACE_INHERITED_OBJECT_TYPE_PRESENT` | `0x00000002` (2) |

<a id="trm-3-a-12"></a>

## SID constants

From `uapi/pkm/sid.h`.

*Largest sub_authority_count a valid SID may declare.* <a id="cite-kacs-abi.sid-max-sub-authorities"></a>

| Constant | Value |
|---|---|
| `KACS_SID_MAX_SUB_AUTHORITIES` | `15` |

*Encoded byte length of a SID with the given sub-authority count.* <a id="cite-kacs-abi.sid-byte-len"></a>

| Constant | Value |
|---|---|
| `KACS_SID_BYTE_LEN(count)` | `(8 + 4 * (count))` |

*SID_AND_ATTRIBUTES "Attributes" bits (MS-DTYP 2.4.4).* <a id="cite-kacs-abi.sid-attribute-bits"></a>

These describe how a group or restricted SID participates in an access
check. MS-DTYP names them for groups; they apply to any
SID_AND_ATTRIBUTES entry.

| Constant | Value |
|---|---|
| `KACS_SID_GROUP_MANDATORY` | `0x00000001` (1) |
| `KACS_SID_GROUP_ENABLED_BY_DEFAULT` | `0x00000002` (2) |
| `KACS_SID_GROUP_ENABLED` | `0x00000004` (4) |
| `KACS_SID_GROUP_OWNER` | `0x00000008` (8) |
| `KACS_SID_GROUP_USE_FOR_DENY_ONLY` | `0x00000010` (16) |
| `KACS_SID_GROUP_INTEGRITY` | `0x00000020` (32) |
| `KACS_SID_GROUP_INTEGRITY_ENABLED` | `0x00000040` (64) |
| `KACS_SID_GROUP_RESOURCE` | `0x20000000` |
| `KACS_SID_GROUP_LOGON_ID` | `0xC0000000` |

---

# Generated file and mount ABI

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated file and mount ABI: behaviour and implementation of the Peios kernel.

<a id="trm-3-a-2-16"></a>

## `struct kacs_open_how` <a id="cite-kacs-abi.struct-kacs-open-how"></a>

Total size 56 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `desired_access` |
| 4 | 4 | `__u32` | `create_disposition` |
| 8 | 4 | `__u32` | `create_options` |
| 12 | 4 | `__u32` | `flags` |
| 16 | 8 | `__u64` | `sd_ptr` |
| 24 | 4 | `__u32` | `sd_len` |
| 28 | 4 | `__u32` | `share_access` |
| 32 | 16 | `__u8``[16]` | `lease_key` |
| 48 | 4 | `__s32` | `lease_fd` |
| 52 | 4 | `__u32` | `__pad2` |

<a id="trm-3-a-2-17"></a>

## `struct kacs_open_info` <a id="cite-kacs-abi.struct-kacs-open-info"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `granted_access` |
| 4 | 4 | `__u32` | `share_access` |
| 8 | 4 | `__u32` | `flags` |
| 12 | 4 | `__u32` | `__pad` |

<a id="trm-3-a-2-18"></a>

## `struct kacs_lock_args` <a id="cite-kacs-abi.struct-kacs-lock-args"></a>

Total size 32 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 8 | `__u64` | `offset` |
| 8 | 8 | `__u64` | `length` |
| 16 | 4 | `__u32` | `op` |
| 20 | 4 | `__u32` | `flags` |
| 24 | 8 | `__u64` | `cookie` |

<a id="trm-3-a-2-19"></a>

## `struct kacs_lease_args` <a id="cite-kacs-abi.struct-kacs-lease-args"></a>

Total size 32 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 16 | `__u8``[16]` | `lease_key` |
| 16 | 4 | `__u32` | `state` |
| 20 | 4 | `__u32` | `flags` |
| 24 | 8 | `__u64` | `__pad` |

<a id="trm-3-a-2-20"></a>

## `struct kacs_lease_break` <a id="cite-kacs-abi.struct-kacs-lease-break"></a>

Total size 48 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 16 | `__u8``[16]` | `lease_key` |
| 16 | 8 | `__u64` | `dev` |
| 24 | 8 | `__u64` | `ino` |
| 32 | 4 | `__u32` | `current_state` |
| 36 | 4 | `__u32` | `new_state` |
| 40 | 4 | `__u32` | `reason` |
| 44 | 4 | `__u32` | `epoch` |

<a id="trm-3-a-2-21"></a>

## `struct kacs_mount_policy_args` <a id="cite-kacs-abi.struct-kacs-mount-policy-args"></a>

Total size 32 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `policy` |
| 4 | 4 | `__u32` | `flags` |
| 8 | 4 | `__u32` | `generation` |
| 12 | 4 | `__u32` | `__pad0` |
| 16 | 8 | `__u64` | `template_sd_ptr` |
| 24 | 4 | `__u32` | `template_sd_len` |
| 28 | 4 | `__u32` | `__pad1` |

<a id="trm-3-a-2-22"></a>

## `struct kacs_sattr` <a id="cite-kacs-abi.struct-kacs-sattr"></a>

Total size 32 bytes.

| Offset | Size | Type | Field |
|---:|---:|---|---|
| 0 | 4 | `__u32` | `version` |
| 4 | 4 | `__u32` | `valid` |
| 8 | 4 | `__u32` | `attributes` |
| 12 | 4 | `__u32` | `flags` |
| 16 | 8 | `__s64` | `created_at_sec` |
| 24 | 4 | `__u32` | `created_at_nsec` |
| 28 | 4 | `__u32` | `__pad` |

<a id="trm-3-a-6"></a>

## mntns.h

From `uapi/pkm/mntns.h`.

*KACS access rights for mount namespaces.* <a id="cite-kacs-abi.mntns-access-rights"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_MNTNS_MOUNT` | `0x00000001` (1) | change the mount table |
| `KACS_MNTNS_ENTER` | `0x00000002` (2) | join the namespace with setns(2) |
| `KACS_MNTNS_ALL_ACCESS` | `917507` |  |

<a id="trm-3-a-8"></a>

## File and open constants

From `uapi/pkm/file.h`.

*The value of the special-attributes extended attribute, as read and as written.* <a id="cite-kacs-abi.sattr-xattr-name"></a>

valid names the fields a write changes; a read sets every bit. Other
fields a write does not name are ignored, and __pad must be zero.

| Constant | Value |
|---|---|
| `KACS_SATTR_XATTR_NAME` | `109012802569580` |

*Minimum caller-supplied size accepted for each argument block.* <a id="cite-kacs-abi.arg-block-min-sizes"></a>

| Constant | Value |
|---|---|
| `KACS_OPEN_HOW_MIN_SIZE` | `16` |
| `KACS_MOUNT_POLICY_ARGS_MIN_SIZE` | `16` |
| `KACS_OPEN_INFO_MIN_SIZE` | `4` |
| `KACS_LOCK_ARGS_MIN_SIZE` | `24` |
| `KACS_LEASE_ARGS_MIN_SIZE` | `24` |

*Sizes of each published version of kacs_open_how.* <a id="cite-kacs-abi.open-how-sizes"></a>

| Constant | Value |
|---|---|
| `KACS_OPEN_HOW_SIZE_VER0` | `32` |
| `KACS_OPEN_HOW_SIZE_VER1` | `56` |

*Create dispositions (kacs_open_how.create_disposition).* <a id="cite-kacs-abi.create-dispositions"></a>

| Constant | Value |
|---|---|
| `KACS_DISPOSITION_SUPERSEDE` | `0` |
| `KACS_DISPOSITION_OPEN` | `1` |
| `KACS_DISPOSITION_CREATE` | `2` |
| `KACS_DISPOSITION_OPEN_IF` | `3` |
| `KACS_DISPOSITION_OVERWRITE` | `4` |
| `KACS_DISPOSITION_OVERWRITE_IF` | `5` |

*Create options (kacs_open_how.create_options).* <a id="cite-kacs-abi.create-options"></a>

| Constant | Value |
|---|---|
| `KACS_CREATE_OPT_DIRECTORY` | `0x0001` (1) |
| `KACS_CREATE_OPT_DELETE_ON_CLOSE` | `0x0002` (2) |

*kacs_open_how.flags bits.* <a id="cite-kacs-abi.open-how-flags"></a>

| Constant | Value |
|---|---|
| `KACS_BACKUP_INTENT` | `0x00000001` (1) |
| `KACS_RESTORE_INTENT` | `0x00000002` (2) |
| `KACS_OPEN_SHARE_ACCESS` | `0x00000004` (4) |
| `KACS_OPEN_LEASE_KEY` | `0x00000008` (8) |
| `KACS_OPEN_PIN_ANCESTORS` | `0x00000010` (16) |

*Share access (kacs_open_how.share_access, kacs_open_info.share_access).* <a id="cite-kacs-abi.share-access"></a>

| Constant | Value |
|---|---|
| `KACS_FILE_SHARE_READ` | `0x00000001` (1) |
| `KACS_FILE_SHARE_WRITE` | `0x00000002` (2) |
| `KACS_FILE_SHARE_DELETE` | `0x00000004` (4) |

*kacs_open_info.flags bits.* <a id="cite-kacs-abi.open-info-flags"></a>

| Constant | Value |
|---|---|
| `KACS_OPEN_INFO_MANAGED` | `0x00000001` (1) |
| `KACS_OPEN_INFO_DELETE_PENDING` | `0x00000002` (2) |
| `KACS_OPEN_INFO_DELETE_ON_CLOSE` | `0x00000004` (4) |
| `KACS_OPEN_INFO_ANCESTORS_PINNED` | `0x00000008` (8) |

*kacs_set_disposition flags, as FILE_DISPOSITION_INFORMATION_EX.* <a id="cite-kacs-abi.disposition-flags"></a>

| Constant | Value |
|---|---|
| `KACS_DISPOSITION_DELETE` | `0x00000001` (1) |
| `KACS_DISPOSITION_POSIX_SEMANTICS` | `0x00000002` (2) |
| `KACS_DISPOSITION_ON_CLOSE` | `0x00000008` (8) |
| `KACS_DISPOSITION_IGNORE_READONLY` | `0x00000010` (16) |

*kacs_rename flags, as FILE_RENAME_INFORMATION_EX.* <a id="cite-kacs-abi.rename-flags"></a>

| Constant | Value |
|---|---|
| `KACS_RENAME_REPLACE_IF_EXISTS` | `0x00000001` (1) |
| `KACS_RENAME_POSIX_SEMANTICS` | `0x00000002` (2) |
| `KACS_RENAME_IGNORE_READONLY` | `0x00000040` (64) |

*kacs_lock_args.op values.* <a id="cite-kacs-abi.lock-ops"></a>

| Constant | Value |
|---|---|
| `KACS_LOCK_SHARED` | `1` |
| `KACS_LOCK_EXCLUSIVE` | `2` |
| `KACS_LOCK_UNLOCK` | `3` |
| `KACS_LOCK_CANCEL` | `4` |

*kacs_lock_args.flags bits.* <a id="cite-kacs-abi.lock-flags"></a>

| Constant | Value |
|---|---|
| `KACS_LOCK_FAIL_IMMEDIATELY` | `0x00000001` (1) |

*Lease states: the NT caching bits.* <a id="cite-kacs-abi.lease-states"></a>

| Constant | Value |
|---|---|
| `KACS_LEASE_READ` | `0x00000001` (1) |
| `KACS_LEASE_HANDLE` | `0x00000002` (2) |
| `KACS_LEASE_WRITE` | `0x00000004` (4) |

*kacs_lease_args.flags bits.* <a id="cite-kacs-abi.lease-flags"></a>

| Constant | Value |
|---|---|
| `KACS_LEASE_ACKNOWLEDGE` | `0x00000001` (1) |

*kacs_lease_break.reason values: the operation that broke the lease.* <a id="cite-kacs-abi.lease-break-reasons"></a>

| Constant | Value |
|---|---|
| `KACS_LEASE_BREAK_OPEN` | `1` |
| `KACS_LEASE_BREAK_SHARING` | `2` |
| `KACS_LEASE_BREAK_WRITE` | `3` |
| `KACS_LEASE_BREAK_SIZE` | `4` |
| `KACS_LEASE_BREAK_LOCK` | `5` |
| `KACS_LEASE_BREAK_NAMESPACE` | `6` |
| `KACS_LEASE_BREAK_DELETE` | `7` |
| `KACS_LEASE_BREAK_SECURITY` | `8` |
| `KACS_LEASE_BREAK_ATTRIBUTES` | `9` |
| `KACS_LEASE_BREAK_CHILD` | `10` |
| `KACS_LEASE_BREAK_TIMEOUT` | `11` |

*kacs_create_lease_manager flags.* <a id="cite-kacs-abi.lease-manager-flags"></a>

| Constant | Value |
|---|---|
| `KACS_LEASE_MANAGER_CLOEXEC` | `0x00000001` (1) |
| `KACS_LEASE_MANAGER_NONBLOCK` | `0x00000002` (2) |

*Break timeout applied when kacs_create_lease_manager is given zero.* <a id="cite-kacs-abi.lease-default-timeout"></a>

| Constant | Value |
|---|---|
| `KACS_LEASE_DEFAULT_BREAK_TIMEOUT_MS` | `35000` |

*kacs_sattr.version.* <a id="cite-kacs-abi.sattr-version"></a>

| Constant | Value |
|---|---|
| `KACS_SATTR_VERSION` | `1` |

*kacs_sattr.valid bits.* <a id="cite-kacs-abi.sattr-valid-bits"></a>

| Constant | Value |
|---|---|
| `KACS_SATTR_VALID_ATTRIBUTES` | `0x00000001` (1) |
| `KACS_SATTR_VALID_CREATED_AT` | `0x00000002` (2) |

*kacs_sattr.attributes bits.* <a id="cite-kacs-abi.sattr-attribute-bits"></a>

| Constant | Value |
|---|---|
| `KACS_SATTR_READONLY` | `0x00000001` (1) |

*kacs_sattr.flags bits.* <a id="cite-kacs-abi.sattr-flags"></a>

On a read, CREATED_AT_SET says Created At was set explicitly rather than
taken from the birth time. On a write naming
KACS_SATTR_VALID_CREATED_AT, CREATED_AT_CLEAR unsets it.

| Constant | Value |
|---|---|
| `KACS_SATTR_CREATED_AT_SET` | `0x00000001` (1) |
| `KACS_SATTR_CREATED_AT_CLEAR` | `0x00000002` (2) |

*File and directory object-specific access rights (the low 16 bits of a file access mask).* <a id="cite-kacs-abi.file-access-rights"></a>

The directory aliases name the same bit as the file right it acts as for
a directory object.

| Constant | Value |
|---|---|
| `KACS_FILE_READ_DATA` | `0x00000001` (1) |
| `KACS_FILE_WRITE_DATA` | `0x00000002` (2) |
| `KACS_FILE_APPEND_DATA` | `0x00000004` (4) |
| `KACS_FILE_READ_EA` | `0x00000008` (8) |
| `KACS_FILE_WRITE_EA` | `0x00000010` (16) |
| `KACS_FILE_EXECUTE` | `0x00000020` (32) |
| `KACS_FILE_DELETE_CHILD` | `0x00000040` (64) |
| `KACS_FILE_READ_ATTRIBUTES` | `0x00000080` (128) |
| `KACS_FILE_WRITE_ATTRIBUTES` | `0x00000100` (256) |
| `KACS_FILE_LIST_DIRECTORY` | `1` |
| `KACS_FILE_TRAVERSE` | `32` |
| `KACS_FILE_ADD_FILE` | `2` |
| `KACS_FILE_ADD_SUBDIRECTORY` | `4` |

*Mount-policy values (kacs_mount_policy_args.policy).* <a id="cite-kacs-abi.mount-policy-values"></a>

| Constant | Value |
|---|---|
| `KACS_MOUNT_POLICY_UNMANAGED` | `1` |
| `KACS_MOUNT_POLICY_DENY_MISSING` | `2` |
| `KACS_MOUNT_POLICY_SYNTHESIZE_EPHEMERAL` | `3` |
| `KACS_MOUNT_POLICY_SYNTHESIZE_PERSISTENT` | `4` |

*Status word kacs_open writes back, describing what happened to the file.* <a id="cite-kacs-abi.open-status-values"></a>

| Constant | Value |
|---|---|
| `KACS_STATUS_OPENED` | `1` |
| `KACS_STATUS_CREATED` | `2` |
| `KACS_STATUS_OVERWRITTEN` | `3` |
| `KACS_STATUS_SUPERSEDED` | `4` |

Status word kacs_open writes back when it fails, naming the NT condition
behind the errno where one errno covers several. <a id="cite-kacs-abi.open-failure-status-values"></a>

| Constant | Value |
|---|---|
| `KACS_STATUS_SHARING_VIOLATION` | `0x10` (16) |
| `KACS_STATUS_DELETE_PENDING` | `0x11` (17) |
| `KACS_STATUS_CANNOT_DELETE` | `0x12` (18) |

---

# Generated socket and IPC ABI

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated socket and IPC ABI: behaviour and implementation of the Peios kernel.

<a id="trm-3-a-4"></a>

## socket.h

From `uapi/pkm/socket.h`.

*KACS socket options — peer identity on local sockets.* <a id="cite-kacs-abi.sol-kacs"></a>

KACS captures a connecting client's identity onto the accepted end of an
AF_UNIX SOCK_STREAM / SOCK_SEQPACKET connection at connect(). This
header is the setsockopt(2)/getsockopt(2) surface through which that
identity is bounded and read back. Every option lives under one option
level, SOL_KACS, which the kernel dispatches ahead of the protocol's own
setsockopt/getsockopt (net/socket.c), so the options behave identically
on every socket family that supports them. SOL_KACS is 4096: far above
the upstream SOL_* range, which grows by one per new protocol, so it
cannot collide with a future Linux level. Errors: -ENOPROTOOPT for an
option this level does not define (or a get-only option passed to
setsockopt); -EOPNOTSUPP on a socket family KACS does not carry identity
on (and, for the register, on a socket type that has none); -EINVAL for
a short optlen or an out-of-range value; -EFAULT for an
unreadable/unwritable optval.

| Constant | Value |
|---|---|
| `SOL_KACS` | `4096` |

*getsockopt only.* <a id="cite-kacs-abi.so-peer-token"></a>

optval: int — a new token fd, carrying fixed TOKEN_QUERY |
TOKEN_IMPERSONATE | TOKEN_DUPLICATE access and opened O_CLOEXEC, for
this end's conveyed-identity register: the peer identity associated with
the data this end has consumed so far. The register is initialised at
connect() — on the accepted end with the client's identity, on the
connecting end with the listener's identity as captured at listen() (at
KACS_IMLEVEL_IDENTIFICATION unless the listener set its own level) — and
advanced by each KACS_SCM_TOKEN the reader's position passes (a token
still queued but unread is not yet visible). Every call returns a fresh
fd to an immutable snapshot; two calls may name different tokens, but no
token ever changes. -ENOTCONN if the socket is not connected; -ENODATA
if nothing has been conveyed yet.

| Constant | Value |
|---|---|
| `KACS_SO_PEER_TOKEN` | `1` |

*getsockopt / setsockopt.* <a id="cite-kacs-abi.so-impersonation-level"></a>

optval: __u32 KACS_IMLEVEL_* — the maximum impersonation level at which
identity leaving this end may be captured: at connect(), and at each
send that conveys identity. The default is KACS_IMLEVEL_IMPERSONATION.
May be changed at any time; a change bounds captures from then on and
never rewrites one already made.

| Constant | Value |
|---|---|
| `KACS_SO_IMPERSONATION_LEVEL` | `2` |

*getsockopt / setsockopt.* <a id="cite-kacs-abi.so-pass-token"></a>

optval: int (0/1) — sender-side automation: while set, every send from
this end carries the sender's effective identity as a KACS_SCM_TOKEN,
derived at this end's impersonation level. Costs nothing at the trust
level: the sender can always attest to what it is. Default 0.

| Constant | Value |
|---|---|
| `KACS_SO_PASS_TOKEN` | `3` |

*setsockopt only.* <a id="cite-kacs-abi.so-restamp"></a>

optval: int, ignored. Self-gated: a process can always attest to what it
is. On a listening AF_UNIX socket: replaces the identity the listener
conveys to connecting clients — captured when listen() was called — with
the caller's current effective identity, at the listener's level. For a
process that receives a listener it did not create (from a descriptor
store after a restart, or from a broker), so that clients see the
process actually accepting. -EINVAL if the socket is not listening. On
an AF_INET / AF_INET6 socket, in any state: replaces the identity that
governs the socket's traffic for network policy — stamped at creation,
bind, listen, connect and accept — with the caller's current effective
identity, so a socket handed to another program (socket activation,
descriptor passing) is governed as that program's. The identity is read
by the network policy engine at the first judgment of each flow and
fixed for that flow's life.

| Constant | Value |
|---|---|
| `KACS_SO_RESTAMP` | `4` |

*Ancillary message type, at cmsg_level SOL_KACS.* <a id="cite-kacs-abi.scm-token"></a>

Data: one int. Received: a token fd (TOKEN_QUERY | TOKEN_IMPERSONATE |
TOKEN_DUPLICATE, O_CLOEXEC) for the identity the kernel attests sent the
accompanying data. Delivered when the receive buffer has room for it and
the conveyed identity differs from the reader's register; a receiver
that reads no ancillary data still has the register
(KACS_SO_PEER_TOKEN). Sent: a token fd the sender wishes to attach to
the data. The kernel gates the send as if the sender were impersonating
that token: the two-gate model runs with the sender as installer, and an
attach that would lower the token's level fails with -EPERM rather than
downgrading. A primary token is derived to an impersonation token at
this end's level. The fd must carry TOKEN_IMPERSONATE (-EACCES
otherwise); at most one per message (-EINVAL). Attaching is exactly
equivalent to impersonating the token for the duration of the send.

| Constant | Value |
|---|---|
| `KACS_SCM_TOKEN` | `1` |

<a id="trm-3-a-5"></a>

## ipc.h

From `uapi/pkm/ipc.h`.

KACS access rights for System V IPC objects — message queues, shared
memory segments and semaphore arrays. Every SysV object carries a
security descriptor, created from the creator's token at *get time and
enforced through the LSM IPC hooks; the nine-bit ipc_perm mode is never
consulted (CAP_IPC_OWNER is in KACS's always-allow set). The key
namespace is claim-on-create: the descriptor protects the object,
nothing protects the name. Object-specific rights (low 16 bits); the
standard rights (DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER —
<pkm/access.h>) apply as on every KACS object. <a id="cite-kacs-abi.ipc-access-rights"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_IPC_READ` | `0x00000001` (1) | msgrcv, shmat read-only, semop without alter, GETVAL/GETALL |
| `KACS_IPC_WRITE` | `0x00000002` (2) | msgsnd, shmat read-write, semop with alter, SETVAL/SETALL |
| `KACS_IPC_QUERY_INFORMATION` | `0x00000004` (4) | IPC_STAT and the *_STAT variants |
| `KACS_IPC_SET_INFORMATION` | `0x00000008` (8) | SHM_LOCK / SHM_UNLOCK |
| `KACS_IPC_ALL_ACCESS` | `983055` |  |

ipcctl gates: IPC_RMID needs DELETE; IPC_SET needs WRITE_DAC and
WRITE_OWNER (one command carries mode, uid and gid); the mode, uid and
gid it writes are informational (ipcs, IPC_STAT) and never decide
access. Addressing a SysV object's descriptor with kacs_get_sd /
kacs_set_sd: pass one of these in `flags`, the object id in `dirfd`, and
a NULL path. The object is looked up in the caller's IPC namespace. <a id="cite-kacs-abi.sysv-sd-selectors"></a>

| Constant | Value |
|---|---|
| `KACS_SD_AT_SYSV_SHM` | `0x01000000` |
| `KACS_SD_AT_SYSV_MSG` | `0x02000000` |
| `KACS_SD_AT_SYSV_SEM` | `0x04000000` |
| `KACS_SD_AT_SYSV_MASK` | `117440512` |

---

# Generated process and PSB ABI

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated process and PSB ABI: behaviour and implementation of the Peios kernel.

<a id="trm-3-a-9"></a>

## Process access rights

From `uapi/pkm/process.h`.

*KACS process object-specific access rights (the low 16 bits of a process access mask).* <a id="cite-kacs-abi.process-access-rights"></a>

Named for the Windows process rights; an access check folds the generic
bits (<pkm/sd.h>) into these via the process generic mapping.

| Constant | Value |
|---|---|
| `KACS_PROCESS_TERMINATE` | `0x00000001` (1) |
| `KACS_PROCESS_SIGNAL` | `0x00000002` (2) |
| `KACS_PROCESS_VM_READ` | `0x00000010` (16) |
| `KACS_PROCESS_VM_WRITE` | `0x00000020` (32) |
| `KACS_PROCESS_DUP_HANDLE` | `0x00000040` (64) |
| `KACS_PROCESS_SET_INFORMATION` | `0x00000200` (512) |
| `KACS_PROCESS_QUERY_INFORMATION` | `0x00000400` (1024) |
| `KACS_PROCESS_SUSPEND_RESUME` | `0x00000800` (2048) |
| `KACS_PROCESS_QUERY_LIMITED` | `0x00001000` (4096) |

<a id="trm-3-a-10"></a>

## Process mitigation bits

From `uapi/pkm/psb.h`.

*Process Security Block (PSB) process-mitigation bits.* <a id="cite-kacs-abi.mitigation-bits"></a>

The `mitigations` argument of kacs_set_psb (SYS_KACS_SET_PSB) is a
bitmask of these flags. Setting a bit is activation-backed: KACS either
places the target process in the protected state (or verifies it already
satisfies the invariant) before committing, and rejects later operations
that would disable the protection. Each mitigation is enforced at its
own enforcement point and persists across exec. See Kernel TRM section
3.3 (Process Security Block). Only the bits in KACS_MIT_ALL are valid;
any other bit set in the request is rejected. KACS_MIT_CFI is a legacy
alias: requesting it sets both KACS_MIT_CFIF and KACS_MIT_CFIB, and the
alias bit itself is not retained.

| Constant | Value | Notes |
|---|---|---|
| `KACS_MIT_WXP` | `0x001` (1) | Write-XOR-Execute protection |
| `KACS_MIT_TLP` | `0x002` (2) | Trusted Library Paths |
| `KACS_MIT_LSV` | `0x004` (4) | Library Signature Verification |
| `KACS_MIT_CFI` | `0x008` (8) | legacy alias: CFIF \| CFIB |
| `KACS_MIT_UI_ACCESS` | `0x010` (16) | UI interaction (reserved) |
| `KACS_MIT_NO_CHILD` | `0x020` (32) | cannot fork (one-way) |
| `KACS_MIT_CFIF` | `0x040` (64) | forward-edge CFI (Intel IBT) |
| `KACS_MIT_CFIB` | `0x080` (128) | backward-edge CFI (shadow stack) |
| `KACS_MIT_PIE` | `0x100` (256) | reject non-PIE binaries at exec |
| `KACS_MIT_SML` | `0x200` (512) | speculation mitigation lock |

*All valid mitigation bits OR'd together — the accepted-request mask.* <a id="cite-kacs-abi.mitigation-all-mask"></a>

| Constant | Value |
|---|---|
| `KACS_MIT_ALL` | `0x3FF` (1023) |

---

# Generated diagnostic constants

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Generated diagnostic constants: behaviour and implementation of the Peios kernel.

<a id="trm-3-a-13"></a>

## Tracepoint diagnostic codes

From `uapi/pkm/trace.h`.

*kacs_access_decision reason — why a KACS access hook took the return path it did.* <a id="cite-kacs-abi.trace.access-decision-reasons"></a>

Emitted by the kacs:kacs_file_access / _file_open / _native_open
_inode_file_access / _inode_permission events. Verdict (allow vs deny)
is a separate signal, read from the `ret` field (0 == allow).

| Constant | Value | Notes |
|---|---|---|
| `KACS_TR_DECISION` | `0` | resolved allow/deny |
| `KACS_TR_BAD_ARGS` | `1` | NULL/zero argument guard |
| `KACS_TR_NO_ISEC` | `2` | inode has no i_security blob |
| `KACS_TR_UNMANAGED` | `3` | superblock mount policy UNMANAGED |
| `KACS_TR_PIP_CONTEXT` | `4` | current PIP context unavailable |
| `KACS_TR_NO_TOKEN` | `5` | no effective subject token |
| `KACS_TR_NO_DENTRY_ALIAS` | `6` | inode has no dentry alias yet |
| `KACS_TR_DELETE_ON_CLOSE_PENDING` | `7` | open of a delete-on-close file |
| `KACS_TR_NATIVE_STAMP` | `8` | native-open granted-access stamp |
| `KACS_TR_NATIVE_ARM` | `9` | native-open delete-on-close arm |
| `KACS_TR_STAMP` | `10` | legacy-open granted-access stamp |
| `KACS_TR_LAZY_DENTRY_RELOOKUP` | `11` | native create lazy re-lookup |
| `KACS_TR_NEGATIVE_AFTER_CREATE` | `12` | negative dentry after create |
| `KACS_TR_CHANGE_NOTIFY_PRIV` | `13` | traverse via CHANGE_NOTIFY priv |
| `KACS_TR_CHANGE_NOTIFY_PRIV_EXHAUSTED` | `14` | CHANGE_NOTIFY priv use exhausted |
| `KACS_TR_NT_SHARE` | `15` | NT share registration refused the open |
| `KACS_TR_NT_SHARE_OVERRIDE` | `16` | backup/restore intent set a share denial aside |

*kacs_sd_cache reason — the inode security-descriptor cache outcome.* <a id="cite-kacs-abi.trace.sd-cache-reasons"></a>

The lookup miss codes disambiguate the three cache-absent paths that
were previously an indistinguishable NULL return (no cache / stale
generation missing-but-synthesis-required); the corrupt codes name why a
stored SD was rejected. Emitted by kacs:kacs_sd_cache_lookup / _corrupt.

| Constant | Value | Notes |
|---|---|---|
| `KACS_SDC_HIT` | `0` | current, valid cache present |
| `KACS_SDC_MISS_NONE` | `1` | no cache attached |
| `KACS_SDC_MISS_STALE_GEN` | `2` | cache present but stale generation |
| `KACS_SDC_MISS_NEEDS_SYNTH` | `3` | missing SD requires synthesis |
| `KACS_SDC_CORRUPT_EMPTY_OR_OVERSIZE` | `4` | stored SD zero-length or oversize |
| `KACS_SDC_CORRUPT_VALIDATE_FAIL` | `5` | stored SD failed validation |

kacs_process_access reason — the outcome of a cross-process access
decision (signal, ptrace, scheduler/attribute, prlimit). The reason
distinguishes the paths that all surface as -EACCES: an SD denial, a
PIP-based denial, a denial rescued (or not) by SeDebugPrivilege, and a
PIP-dominance failure. Emitted by kacs:kacs_process_access. <a id="cite-kacs-abi.trace.process-access-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_PA_ALLOW` | `0` | access granted |
| `KACS_PA_BAD_ARGS` | `1` | NULL subject/target guard |
| `KACS_PA_NO_TARGET` | `2` | target has no process state/SD |
| `KACS_PA_NO_SD` | `3` | target process SD unavailable |
| `KACS_PA_SD_ERROR` | `4` | SD check failed (non-EACCES) |
| `KACS_PA_PIP_DENIED` | `5` | denied by process-integrity policy |
| `KACS_PA_DEBUG_RESCUE` | `6` | SD denial rescued by SeDebugPrivilege |
| `KACS_PA_DEBUG_DENIED` | `7` | denied; no usable SeDebugPrivilege |
| `KACS_PA_PIP_DOMINANCE` | `8` | caller PIP does not dominate target |

*kacs_exec reason — an exec/bprm credential or PIP transition.* <a id="cite-kacs-abi.trace.exec-reasons"></a>

Distinguishes the uid/gid-change gate outcomes, the exec primary-token
derivation paths and their failures, the exec file integrity-label
lookup failures, and the two commit-time transitions. Verdict is the
`ret` field. Emitted by kacs:kacs_exec.

| Constant | Value | Notes |
|---|---|---|
| `KACS_EXEC_CREDS_ALLOW` | `0` | exec cred transition allowed |
| `KACS_EXEC_BAD_ARGS` | `1` | NULL cred/token guard |
| `KACS_EXEC_ID_CHANGE_NO_TOKEN` | `2` | uid/gid change, no subject token |
| `KACS_EXEC_ID_CHANGE_PRIV_UNSUPPORTED` | `3` | id change + ASSIGN_PRIMARY_TOKEN priv |
| `KACS_EXEC_TOKEN_NPM_DERIVED` | `4` | exec token derived via new-process-min |
| `KACS_EXEC_TOKEN_CLONE` | `5` | exec token via primary clone fallback |
| `KACS_EXEC_NPM_NO_FILE` | `6` | new-process-min needs file, none supplied |
| `KACS_EXEC_NPM_DERIVE_FAIL` | `7` | new_process_min_exec derivation failed |
| `KACS_EXEC_TOKEN_INSTALL_FAIL` | `8` | install token ref on new cred failed |
| `KACS_EXEC_TOKEN_CLONE_FAIL` | `9` | primary token clone returned NULL |
| `KACS_EXEC_INTEGRITY_NO_ISEC` | `10` | exec file inode has no i_security |
| `KACS_EXEC_INTEGRITY_NO_CACHE` | `11` | exec file SD cache absent |
| `KACS_EXEC_INTEGRITY_INVALID_SD` | `12` | exec file cached SD invalid/empty |
| `KACS_EXEC_IMPERSONATION_REVERT_FAIL` | `13` | bprm impersonation revert failed |
| `KACS_EXEC_PIP_COMMITTED` | `14` | pending exec PIP committed at commit |
| `KACS_EXEC_UMH_NOT_TCB` | `15` | usermodehelper exec below PeiosTcb trust |
| `KACS_EXEC_SIGNATURE_UNVERIFIABLE` | `16` | exec refused: signature could not be verified |
| `KACS_EXEC_PIP_CAPPED_UNSAFE` | `17` | exec PIP label capped at the current one: traced or no_new_privs |

kacs_signing reason — code-signature verification outcomes and the
distinct reject reasons of the signing-material probe. Only source enum,
verified flag, PIP tier codes, file length, reason, and ret are recorded
— never key, signature, xattr, or file bytes. Emitted by
kacs:kacs_signing_verify _crypto / _probe. <a id="cite-kacs-abi.trace.signing-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_SIG_UNSIGNED` | `0` | material source NONE (unsigned) |
| `KACS_SIG_BAD_KEY_TABLE` | `1` | key table malformed / bad args |
| `KACS_SIG_NO_KEY_MATCH` | `2` | no key verified the signature |
| `KACS_SIG_VERIFIED` | `3` | a key verified; trust assigned |
| `KACS_SIG_CRYPTO_UNAVAILABLE` | `4` | mldsa65 tfm allocation failed |
| `KACS_SIG_CRYPTO_MISMATCH` | `5` | set-pubkey/verify returned nonzero |
| `KACS_SIG_PROBE_FOUND` | `6` | valid signature material committed |
| `KACS_SIG_ELF_MAGIC_READ` | `7` | failed reading ELF magic |
| `KACS_SIG_ELF_SHORT_EHDR` | `8` | file too short for Elf64_Ehdr |
| `KACS_SIG_ELF_EHDR_READ` | `9` | failed reading ELF header |
| `KACS_SIG_ELF_BAD_IDENT` | `10` | unsupported e_ident class/data/version |
| `KACS_SIG_ELF_BAD_SHTABLE` | `11` | bad shentsize/shstrndx |
| `KACS_SIG_ELF_SHDRS_RANGE` | `12` | section-header table offset/len out of range |
| `KACS_SIG_ELF_SHSTR_READ` | `13` | failed reading shstrtab section header |
| `KACS_SIG_ELF_STRTAB_RANGE` | `14` | shstrtab offset/len out of range |
| `KACS_SIG_ELF_SHDR_READ` | `15` | failed reading a section header |
| `KACS_SIG_ELF_NAME_READ` | `16` | failed reading a section name |
| `KACS_SIG_ELF_BAD_SIG_SECTION` | `17` | sig section wrong type/size/range |
| `KACS_SIG_ELF_BAD_BLOB` | `18` | sig blob read failed or invalid |
| `KACS_SIG_ELF_HASH_FAIL` | `19` | hashing failed for ELF sig |
| `KACS_SIG_XATTR_BAD_BLOB` | `20` | xattr sig blob invalid |
| `KACS_SIG_XATTR_HASH_FAIL` | `21` | hashing failed for xattr sig |
| `KACS_SIG_SIZE_CHANGED` | `22` | file size changed during probe (TOCTOU) |

kacs_firmware reason — why a kernel-initiated firmware read was allowed
or refused (kacs/firmware.c, PEI-493). Firmware is code that runs on a
device with DMA into host memory, so it is held to the PeiosTcb tier:
the same bar as a usermodehelper exec. `ret` is the verdict handed to
the loader; under log mode it is 0 whatever the reason. Emitted by
kacs:kacs_firmware_load. No path, key, or signature bytes are recorded. <a id="cite-kacs-abi.trace.firmware-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_FW_ALLOWED` | `0` | verified at PeiosTcb |
| `KACS_FW_UNSIGNED` | `1` | no signature material on the file |
| `KACS_FW_NO_KEY_MATCH` | `2` | signed, but no built-in key verified it |
| `KACS_FW_BELOW_TCB` | `3` | verified, but the key's tier is below PeiosTcb |
| `KACS_FW_UNVERIFIABLE` | `4` | verification could not run (crypto unavailable) |
| `KACS_FW_PROBE_FAILED` | `5` | reading the signature material failed |

*kacs_socket reason — the outcome of an AF_UNIX socket SD / impersonation hook.* <a id="cite-kacs-abi.trace.socket-reasons"></a>

Distinguishes the guard, not-applicable, and verdict paths that
otherwise collapse into an indistinguishable -EACCES. Verdict is the
`ret` field. No address, pathname, or SD bytes are recorded.

| Constant | Value | Notes |
|---|---|---|
| `KACS_SOCK_BAD_ARGS` | `0` | NULL/guard argument rejected |
| `KACS_SOCK_NOT_UNIX` | `1` | not AF_UNIX / unsupported type |
| `KACS_SOCK_NO_SECURITY` | `2` | sock has no sk_security blob |
| `KACS_SOCK_NO_TOKEN` | `3` | no effective subject/client token |
| `KACS_SOCK_BAD_LEVEL` | `4` | invalid impersonation level |
| `KACS_SOCK_WRONG_STATE` | `5` | socket state forbids the op |
| `KACS_SOCK_NO_PEER_TOKEN` | `6` | no captured peer token present |
| `KACS_SOCK_PIP_CONTEXT` | `7` | caller PIP context unavailable |
| `KACS_SOCK_SD_DECISION` | `8` | socket-SD check produced verdict |
| `KACS_SOCK_NO_SD` | `9` | no socket SD; allowed without check |
| `KACS_SOCK_HAVE_SD` | `10` | socket SD present; check performed |
| `KACS_SOCK_ALREADY_BOUND` | `11` | socket SD already installed |
| `KACS_SOCK_BIND` | `12` | abstract-socket SD bind result |
| `KACS_SOCK_CONNECT` | `13` | unix_stream_connect result |
| `KACS_SOCK_LEVEL_SET` | `14` | impersonation level updated |
| `KACS_SOCK_OPEN_TOKEN` | `15` | open peer-token fd result |

*16 was KACS_SOCK_IMPERSONATE (kacs_impersonate_peer); retired, not reused.* <a id="cite-kacs-abi.trace.socket-reason-16-retired"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_SOCK_ATTACH` | `17` | identity attached to a send |
| `KACS_SOCK_GATE` | `18` | explicit KACS_SCM_TOKEN send-gate verdict |
| `KACS_SOCK_REGISTER` | `19` | conveyed-identity register advanced |
| `KACS_SOCK_DELIVER` | `20` | KACS_SCM_TOKEN delivered to a receiver |
| `KACS_SOCK_LISTEN` | `21` | listener identity captured at listen() |
| `KACS_SOCK_RESTAMP` | `22` | listener identity replaced by KACS_SO_RESTAMP |
| `KACS_SOCK_PORT_BIND` | `23` | inet bind: port reservation SD verdict |
| `KACS_SOCK_PORT_TABLE` | `24` | port reservation table load result |
| `KACS_SOCK_OWNER` | `25` | governing identity stamped on an inet socket |

*kacs_ipc reason — a System V IPC object SD decision (ipc.c).* <a id="cite-kacs-abi.trace.ipc-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_IPC_ALLOC` | `0` | default SD stamped at *get creation |
| `KACS_IPC_PERMISSION` | `1` | ipc_permission: read/write access to the object |
| `KACS_IPC_CTL` | `2` | *ctl command gate (RMID/SET/STAT/...) |
| `KACS_IPC_SD_QUERY` | `3` | kacs_get_sd on the object |
| `KACS_IPC_SD_SET` | `4` | kacs_set_sd on the object |
| `KACS_IPC_NO_SD` | `5` | object carries no SD; fail closed |

*kacs_namespace stage — which sub-decision of a namespace-mutation hook a record describes.* <a id="cite-kacs-abi.trace.namespace-stages"></a>

Single-decision ops report PRIMARY; multi-stage ops (link, rename,
delete fallback) tag each distinct verdict. Verdict is the `ret` field.
Never records a pathname. Emitted by the kacs:kacs_inode_* events.

| Constant | Value | Notes |
|---|---|---|
| `KACS_NS_PRIMARY` | `0` | the op's principal decision |
| `KACS_NS_PARENT_FALLBACK` | `1` | delete: parent DELETE_CHILD fallback |
| `KACS_NS_SOURCE` | `2` | link/rename source-side decision |
| `KACS_NS_DEST` | `3` | link/rename destination-parent add |
| `KACS_NS_DELETE_EXISTING` | `4` | rename: delete pre-existing dest |

kacs_psb reason — which process-security-baseline path an event marks:
mitigation activation (apply) or a W^X / LSV / PIE / prctl-lock
enforcement denial. The ok-vs-deny verdict is read from `ret`. Emitted
by kacs:kacs_psb_*. <a id="cite-kacs-abi.trace.psb-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_PSB_APPLY_OK` | `0` | mitigations applied; result_bits set |
| `KACS_PSB_APPLY_NORMALIZE` | `1` | requested mask bad or unsupported (EINVAL/ENODEV) |
| `KACS_PSB_APPLY_MM_ACQUIRE` | `2` | could not acquire target mm (EACCES) |
| `KACS_PSB_APPLY_CFIF` | `3` | forward-CFI (IBT) activation failed |
| `KACS_PSB_APPLY_SML` | `4` | speculative-mitigation-lock activation failed |
| `KACS_PSB_APPLY_CFIB` | `5` | backward-CFI (shadow stack) activation failed |
| `KACS_PSB_WXP_MMAP` | `6` | W^X blocked a W+X mmap |
| `KACS_PSB_WXP_MPROTECT` | `7` | W^X blocked an mprotect transition |
| `KACS_PSB_WXP_EXISTING_VMA` | `8` | W^X activation blocked by an existing W+X vma |
| `KACS_PSB_LSV_PROBE` | `9` | LSV signing probe of the image failed |
| `KACS_PSB_LSV_VERIFY` | `10` | LSV signature not verified/trusted |
| `KACS_PSB_LSV_PIP_DOMINANCE` | `11` | LSV image PIP does not dominate process PIP |
| `KACS_PSB_PIE_ET_EXEC` | `12` | PIE blocked a non-PIE ET_EXEC image |
| `KACS_PSB_PRCTL_SML` | `13` | prctl blocked by SML lock |
| `KACS_PSB_PRCTL_CFIB` | `14` | prctl blocked by shadow-stack (CFIB) lock |
| `KACS_PSB_PRCTL_PIP` | `15` | prctl set-dumpable blocked by process PIP |

*kacs_token_ioctl cmd — which token-fd ioctl verb a record describes.* <a id="cite-kacs-abi.trace.token-ioctl-cmds"></a>

The verdict (allow vs deny) is read from the `ret` field (0 == allow);
the access-mask-gate rejections surface as ret == -EACCES. `token` is an
opaque numeric id (never token bytes). Emitted by kacs:kacs_token_ioctl.

| Constant | Value | Notes |
|---|---|---|
| `KACS_TOK_QUERY` | `0` | KACS_IOC_QUERY |
| `KACS_TOK_ADJUST_PRIVS` | `1` | KACS_IOC_ADJUST_PRIVS |
| `KACS_TOK_ADJUST_GROUPS` | `2` | KACS_IOC_ADJUST_GROUPS |
| `KACS_TOK_DUPLICATE` | `3` | KACS_IOC_DUPLICATE |
| `KACS_TOK_INSTALL` | `4` | KACS_IOC_INSTALL |
| `KACS_TOK_RESTRICT` | `5` | KACS_IOC_RESTRICT |
| `KACS_TOK_LINK` | `6` | KACS_IOC_LINK_TOKENS |
| `KACS_TOK_GET_LINKED` | `7` | KACS_IOC_GET_LINKED_TOKEN |
| `KACS_TOK_IMPERSONATE` | `8` | KACS_IOC_IMPERSONATE |
| `KACS_TOK_ADJUST_DEFAULT` | `9` | KACS_IOC_ADJUST_DEFAULT |
| `KACS_TOK_ADJUST_INTERACTIVITY_SCOPE` | `10` | KACS_IOC_ADJUST_INTERACTIVITY_SCOPE |
| `KACS_TOK_UNKNOWN` | `11` | unrecognised ioctl verb (-ENOTTY) |

*kacs_token_ref reason — a token-fd reference lifecycle transition.* <a id="cite-kacs-abi.trace.token-ref-reasons"></a>

TO_FD is a token installed into a fresh anon-inode handle; RELEASE is
the handle teardown that drops the token ref; BIND clones a token onto
an existing file; OPEN is the checked/fixed-access open path that clones
the target token. `token` is an opaque numeric id, never token bytes.
Emitted by kacs:kacs_token_ref.

| Constant | Value | Notes |
|---|---|---|
| `KACS_TREF_TO_FD` | `0` | token installed into a new fd (ret == fd) |
| `KACS_TREF_RELEASE` | `1` | token-fd released; ref dropped |
| `KACS_TREF_BIND` | `2` | token cloned + bound onto an existing file |
| `KACS_TREF_OPEN` | `3` | token cloned for a token-open path |

*kacs_logon_session reason — a session/token creation-surface outcome.* <a id="cite-kacs-abi.trace.logon-session-reasons"></a>

The *_DENIED codes name the privilege-gate rejections (the value); the
plain op codes mark the successful op. Verdict is also in `ret`. No
token/spec bytes are recorded. Emitted by kacs:kacs_logon_session.

| Constant | Value | Notes |
|---|---|---|
| `KACS_SES_CREATE` | `0` | create_logon_session published a session |
| `KACS_SES_CREATE_PRIV_DENIED` | `1` | create_logon_session: TCB privilege gate denied |
| `KACS_SES_DESTROY` | `2` | destroy_empty_logon_session outcome |
| `KACS_SES_DESTROY_PRIV_DENIED` | `3` | destroy: TCB privilege gate denied |
| `KACS_SES_CREATE_TOKEN` | `4` | create_token issued a token fd |
| `KACS_SES_CREATE_TOKEN_PRIV_DENIED` | `5` | create_token: CREATE_TOKEN privilege denied |

kacs_cred reason — a credential-security lifecycle transition: LSM cred
prepare/transfer/alloc/free, explicit token-ref install, the clone-time
primary-token lifecycle (CLONE_THREAD share vs fork deep-copy), and the
project-linux-cred rejection paths. old_token/new_token are opaque token
pointer ids (0 when absent); clone_flags is set only on the clone paths.
Verdict/outcome is the `ret` field. Emitted by kacs:kacs_cred. <a id="cite-kacs-abi.trace.cred-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_CRED_PREPARE` | `0` | cred_prepare token clone |
| `KACS_CRED_TRANSFER` | `1` | cred_transfer token clone |
| `KACS_CRED_ALLOC_BLANK` | `2` | cred_alloc_blank cleared sec |
| `KACS_CRED_FREE` | `3` | cred_free released token/state |
| `KACS_CRED_INSTALL_TOKEN_REF` | `4` | install token ref on a cred |
| `KACS_CRED_CLONE_THREAD_SHARE` | `5` | CLONE_THREAD shares parent primary cred |
| `KACS_CRED_CLONE_FORK_COPY` | `6` | fork deep-copies parent primary token |
| `KACS_CRED_PROJECT_UID0_BLOCKED` | `7` | uid0 projection not allowed by token |
| `KACS_CRED_PROJECT_GROUPS_ALLOC_FAIL` | `8` | groups_alloc failed (ENOMEM) |
| `KACS_CRED_PROJECT_E2BIG` | `9` | supplementary gid count > NGROUPS_MAX |

kacs_setid reason — the KACS gate on a Linux setid projection
(task_fix_setuid / _setgid / _setgroups). Each op has two distinct
denials that otherwise collapse: NO_TOKEN (-EACCES, no effective subject
token) and PRIV_GATE (-EOPNOTSUPP, holder of ASSIGN_PRIMARY_TOKEN
privilege). `flags` is the LSM_SETID_* mask (0 for setgroups). Emitted
by kacs:kacs_setid. <a id="cite-kacs-abi.trace.setid-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_SETID_SETUID_NO_TOKEN` | `0` | setuid gate: no subject token |
| `KACS_SETID_SETUID_PRIV_GATE` | `1` | setuid gate: ASSIGN_PRIMARY priv |
| `KACS_SETID_SETGID_NO_TOKEN` | `2` | setgid gate: no subject token |
| `KACS_SETID_SETGID_PRIV_GATE` | `3` | setgid gate: ASSIGN_PRIMARY priv |
| `KACS_SETID_SETGROUPS_NO_TOKEN` | `4` | setgroups gate: no subject token |
| `KACS_SETID_SETGROUPS_PRIV_GATE` | `5` | setgroups gate: ASSIGN_PRIMARY priv |

*kacs_task reason — a task-security lifecycle transition.* <a id="cite-kacs-abi.trace.task-reasons"></a>

task_alloc reports a NO_CHILD-mitigation clone block, a process-state
inherit ENOMEM, or success; task_free marks teardown. `process_state` is
an opaque process-state pointer id (0 when absent); `clone_flags` is set
on the alloc paths. Outcome is `ret`. Emitted by kacs:kacs_task.

| Constant | Value | Notes |
|---|---|---|
| `KACS_TASK_ALLOC_NO_CHILD_BLOCKED` | `0` | clone blocked by NO_CHILD mitigation |
| `KACS_TASK_ALLOC_INHERIT_ENOMEM` | `1` | process-state inherit failed (ENOMEM) |
| `KACS_TASK_ALLOC` | `2` | task_alloc completed |
| `KACS_TASK_FREE` | `3` | task_free teardown |

*kacs_primary_install reason — a primary-token / impersonation credential transition.* <a id="cite-kacs-abi.trace.primary-install-reasons"></a>

Distinguishes the install commit, the user-SID-change process-SD
reallocation and its ENOMEM, the commit_creds apply, the impersonation
override/revert, and the sibling-thread taskwork requeue/failure.
old_primary and new_primary are opaque token identity ids (never token
bytes). Verdict is the `ret` field. Emitted by
kacs:kacs_primary_install.

| Constant | Value | Notes |
|---|---|---|
| `KACS_PRIM_INSTALL_OK` | `0` | primary token install committed |
| `KACS_PRIM_SD_REALLOC` | `1` | user-SID changed; process SD reallocated |
| `KACS_PRIM_SD_ALLOC_FAIL` | `2` | process SD realloc failed (ENOMEM) |
| `KACS_PRIM_APPLY_COMMIT` | `3` | new real creds committed (commit_creds) |
| `KACS_PRIM_IMPERSONATE_INSTALL` | `4` | impersonation token installed (override_creds) |
| `KACS_PRIM_IMPERSONATE_REVERT` | `5` | impersonation reverted (revert_creds) |
| `KACS_PRIM_SIBLING_REQUEUE` | `6` | queued sibling install re-queued on ENOMEM |
| `KACS_PRIM_SIBLING_FAILED` | `7` | queued sibling install failed after apply |

kacs_process_token_open reason — the outcome of opening a process/thread
primary or effective token (kacs_open_process_token / _thread_token and
the proc inspection files). Distinguishes the bad access-mask reject,
the no-target-token path, the process access-check denial, the self vs
cross inspection verdicts, and the successful open.
subject_token/target_token are opaque token identity ids (0 when unknown
at the emit site); access_mask is the requested mask. Verdict is `ret`
(>=0 fd == allow). Emitted by kacs:kacs_process_token_open. <a id="cite-kacs-abi.trace.process-token-open-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_PTO_OPEN_OK` | `0` | token fd opened |
| `KACS_PTO_BAD_ARGS` | `1` | NULL subject/state/task guard |
| `KACS_PTO_NO_TARGET` | `2` | target has no token |
| `KACS_PTO_BAD_ACCESS` | `3` | invalid access mask rejected |
| `KACS_PTO_ACCESS_DENIED` | `4` | process access check denied |
| `KACS_PTO_SELF` | `5` | self-target inspection allowed |
| `KACS_PTO_CROSS` | `6` | cross-process inspection authorized |

*kacs_process_state reason — a process-state / process-SD lifecycle or PIP transition.* <a id="cite-kacs-abi.trace.process-state-reasons"></a>

Covers process-state alloc/free, the CLONE_THREAD share vs fork
inheritance split, the no-child clone block, the pending-exec-PIP
stage/commit and dumpable hardening, and the process-SD
alloc/wrap/replace primitives. process_state is an opaque state-object
id (0 when none in scope, e.g. the process-SD primitives);
pip_type/pip_trust carry the PIP tier. `ret` is the outcome (0 == ok).
No token or SD bytes. Emitted by kacs:kacs_process_state.

| Constant | Value | Notes |
|---|---|---|
| `KACS_PST_ALLOC` | `0` | process state allocated |
| `KACS_PST_ALLOC_FAIL` | `1` | process state alloc failed (ENOMEM) |
| `KACS_PST_FREE` | `2` | process state freed (refcount hit 0) |
| `KACS_PST_INHERIT_SHARE` | `3` | CLONE_THREAD: parent state shared |
| `KACS_PST_INHERIT_FORK` | `4` | fork: new state allocated from parent |
| `KACS_PST_EXEC_PIP_STAGE` | `5` | pending exec PIP staged |
| `KACS_PST_EXEC_PIP_COMMIT` | `6` | pending exec PIP committed to state |
| `KACS_PST_DUMPABLE` | `7` | exec dumpable hardened by PIP |
| `KACS_PST_CLONE_BLOCKED_NOCHILD` | `8` | clone blocked by NO_CHILD mitigation |
| `KACS_PST_SD_ALLOC` | `9` | default process SD allocated |
| `KACS_PST_SD_ALLOC_FAIL` | `10` | process/socket SD alloc failed |
| `KACS_PST_SD_WRAP_FAIL` | `11` | process SD wrapper alloc failed (ENOMEM) |
| `KACS_PST_SD_REPLACE` | `12` | process SD replaced on state |
| `KACS_PST_SOCKET_SD_ALLOC` | `13` | default socket SD allocated |

*kacs_mount_policy reason — the outcome of a mount-policy set (TCB-gated) or get.* <a id="cite-kacs-abi.trace.mount-policy-reasons"></a>

SET_OK marks a committed policy change (generation bumped); the guard
codes name the pre-commit rejects that otherwise collapse into a bare
-EINVAL/-EOPNOTSUPP/-EPERM. GET_OK/GET_NO_SECURITY are the snapshot
paths. Verdict is also in `ret`. Emitted by kacs:kacs_mount_policy_set /
_get.

| Constant | Value | Notes |
|---|---|---|
| `KACS_MP_SET_OK` | `0` | policy committed; generation bumped |
| `KACS_MP_BAD_ARGS` | `1` | NULL subject/sb/args guard (EINVAL) |
| `KACS_MP_NO_SECURITY` | `2` | superblock has no s_security (EOPNOTSUPP) |
| `KACS_MP_UNMANAGED` | `3` | magic-derived UNMANAGED; not settable (EOPNOTSUPP) |
| `KACS_MP_VALIDATE` | `4` | mount-policy args validation failed (EINVAL) |
| `KACS_MP_TEMPLATE_INVALID` | `5` | template SD bytes failed validation (EINVAL) |
| `KACS_MP_TCB_DENIED` | `6` | SeTcbPrivilege gate denied (EPERM) |
| `KACS_MP_GET_OK` | `7` | policy snapshot returned |
| `KACS_MP_GET_NO_SECURITY` | `8` | get: no s_security; magic-derived policy returned |
| `KACS_MP_FIXED_POLICY` | `9` | filesystem fixes its policy class (EOPNOTSUPP) |

kacs_sd_syscall target_kind — which SD-bearing object a query/set record
describes, resolved by the get_sd/set_sd syscall target-kind
fallthrough. ACCESS_CHECK tags the AccessCheck ingress events
(kacs_access_check*), whose other scalar fields are 0 at the ingress
boundary. <a id="cite-kacs-abi.trace.sd-syscall-target-kinds"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_SDS_KIND_TOKEN` | `0` | token-fd target |
| `KACS_SDS_KIND_FILE` | `1` | file/inode target |
| `KACS_SDS_KIND_PROCESS` | `2` | pidfd process target |
| `KACS_SDS_KIND_PATH` | `3` | path-resolved file target |
| `KACS_SDS_KIND_ACCESS_CHECK` | `4` | AccessCheck ingress (not an SD get/set) |

*kacs_sd_syscall reason — the outcome of an SD query/set core.* <a id="cite-kacs-abi.trace.sd-syscall-reasons"></a>

QUERY_OK/SET_OK are the success paths; the remaining codes name the
guard / denial paths that otherwise surface as an indistinguishable
-EINVAL/-EACCES/-EOPNOTSUPP. Verdict is also in `ret`. Emitted by
kacs:kacs_sd_query / _set.

| Constant | Value | Notes |
|---|---|---|
| `KACS_SDS_QUERY_OK` | `0` | SD subset extracted and returned |
| `KACS_SDS_SET_OK` | `1` | SD merged/replaced |
| `KACS_SDS_BAD_ARGS` | `2` | NULL/zero argument guard (EINVAL) |
| `KACS_SDS_UNMANAGED` | `3` | superblock UNMANAGED (EOPNOTSUPP) |
| `KACS_SDS_ACCESS_DENIED` | `4` | SD access check denied (EACCES) |
| `KACS_SDS_NO_SD` | `5` | target has no usable SD (EACCES) |
| `KACS_SDS_RESTORE_BYPASS` | `6` | set via SeRestorePrivilege bypass |
| `KACS_SDS_QUERY_FAIL` | `7` | subset extraction failed after auth |

kacs_access_check reason — the AccessCheck kernel-ingress outcome, above
the closed Slice 15 ABI bridge. OK is a completed ingress; the remaining
codes name the ingress-time rejects (token-eval-context gate, token
resolution, and caap-cache lock acquisition). Verdict is also in `ret`.
Emitted by kacs:kacs_access_check / _list. <a id="cite-kacs-abi.trace.access-check-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_ACK_OK` | `0` | ingress dispatched to the ABI bridge |
| `KACS_ACK_EVAL_CONTEXT` | `1` | token-eval-context gate denied (EACCES) |
| `KACS_ACK_TOKEN_RESOLVE` | `2` | token/args resolution failed |
| `KACS_ACK_CAAP_LOCK_FAIL` | `3` | caap-cache lock acquisition failed |

*kacs_file_snapshot op — which snapshot-grant file operation an event marks.* <a id="cite-kacs-abi.trace.file-snapshot-ops"></a>

The allow-vs-deny verdict is read from `ret`; `reason` names why a deny
path was taken. Emitted by kacs:kacs_file_snapshot (file_access.c).

| Constant | Value | Notes |
|---|---|---|
| `KACS_FSOP_ACCESS` | `0` | generic snapshot-grant access check |
| `KACS_FSOP_PERMISSION` | `1` | file_permission hook |
| `KACS_FSOP_IOCTL` | `2` | file ioctl snapshot |
| `KACS_FSOP_LOCK` | `3` | file lock snapshot |
| `KACS_FSOP_FCNTL` | `4` | file fcntl snapshot |
| `KACS_FSOP_TRUNCATE` | `5` | file truncate snapshot |
| `KACS_FSOP_FALLOCATE` | `6` | file fallocate snapshot |
| `KACS_FSOP_MMAP` | `7` | file mmap snapshot |
| `KACS_FSOP_MPROTECT` | `8` | file mprotect snapshot |
| `KACS_FSOP_WRITE_INTENT` | `9` | write-intent snapshot |
| `KACS_FSOP_SYSFS_WRITE_GATE` | `10` | unmanaged sysfs write gate |

*kacs_file_snapshot reason — why a snapshot-grant op took its return path.* <a id="cite-kacs-abi.trace.file-snapshot-reasons"></a>

DECISION is the resolved allow/deny (verdict in `ret`); the remaining
codes name the distinct deny causes. Emitted by kacs:kacs_file_snapshot.

| Constant | Value | Notes |
|---|---|---|
| `KACS_FSR_DECISION` | `0` | resolved allow/deny (grant compare) |
| `KACS_FSR_SIGNED_EXEC` | `1` | signed-exec content mutation denied |
| `KACS_FSR_GRANT_DENY` | `2` | granted access lacked required right |
| `KACS_FSR_APPEND_DENY` | `3` | append/write intent lacked write grant |
| `KACS_FSR_UNMANAGED_SYSFS` | `4` | unmanaged fd: sysfs write gate applied |
| `KACS_FSR_AUDIT_EMIT_FAIL` | `5` | kacs.audit.handle.used emit failed |

*kacs_metadata reason — the file-metadata (getattr/setattr/xattr/getsecurity) decision path.* <a id="cite-kacs-abi.trace.metadata-reasons"></a>

DECISION/CONSUME_HIT/BEGIN_BUSY mark the begin/consume decision
lifecycle; the remaining codes name the distinct deny reasons of the
xattr setattr hooks. `op_class` carries the internal
PKM_KACS_METADATA_OP_* value; `matched` is the consume match flag.
Emitted by kacs:kacs_metadata (file_metadata.c).

| Constant | Value | Notes |
|---|---|---|
| `KACS_META_DECISION` | `0` | generic metadata decision |
| `KACS_META_CONSUME_HIT` | `1` | consumed a pre-staged decision |
| `KACS_META_BEGIN_BUSY` | `2` | begin failed: a decision already active |
| `KACS_META_CANONICAL_SD` | `3` | canonical SD xattr access denied |
| `KACS_META_CAPS_XATTR` | `4` | capability xattr mutation denied (EPERM) |
| `KACS_META_ACL` | `5` | POSIX ACL xattr denied |
| `KACS_META_SIGNED_EXEC` | `6` | signed-exec xattr/size mutation denied |
| `KACS_META_BAD_ARGS` | `7` | NULL name / dentry guard |
| `KACS_META_INTERNAL_SD` | `8` | internal SD read/write re-entry allowed |
| `KACS_META_GETSECURITY` | `9` | inode_getsecurity outcome |

kacs_native_open_ext reason — a widening decision inside the native
(kacs_open) create/open machinery. The PREPARE_* codes name the arg-
validation reject buckets of pkm_kacs_prepare_native_open; RESOLVE /
BUILD_CREATED_SD DELETE_ON_CLOSE_ARM name the later stage outcomes
(verdict in `ret`). Emitted by kacs:kacs_native_open_ext
(native_open.c). <a id="cite-kacs-abi.trace.native-open-ext-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_NOX_PREPARE_OK` | `0` | prepare accepted the request |
| `KACS_NOX_PREPARE_BAD_FLAGS` | `1` | flags/create_options/__pad rejected |
| `KACS_NOX_PREPARE_BAD_SD_ARGS` | `2` | sd_ptr/sd_len/disposition-sd combo bad |
| `KACS_NOX_PREPARE_BAD_DISPOSITION` | `3` | create_disposition out of range |
| `KACS_NOX_PREPARE_BAD_ACCESS` | `4` | desired-access mask invalid/empty |
| `KACS_NOX_PREPARE_UNSUPPORTED` | `5` | valid but unsupported combination |
| `KACS_NOX_RESOLVE` | `6` | resolve-existing-path outcome |
| `KACS_NOX_BUILD_CREATED_SD` | `7` | build-created-file-SD outcome |
| `KACS_NOX_DELETE_ON_CLOSE_ARM` | `8` | delete-on-close arm outcome |

*kacs_object reason — which object-lifecycle verdict a record marks.* <a id="cite-kacs-abi.trace.object-reasons"></a>

Only the high-value transitions are traced (pure inode/file/sb
alloc/free are not). `ret` is the outcome (0 == ok). Emitted by
kacs:kacs_object.

| Constant | Value | Notes |
|---|---|---|
| `KACS_OBJ_DELETE_ON_CLOSE_UNLINK` | `0` | file_release delete-on-close unlink attempt |
| `KACS_OBJ_SIGNED_EXEC_PIN` | `1` | inode pinned as signed-exec (immutable) |
| `KACS_OBJ_SIGNED_EXEC_MUTATION_BLOCKED` | `2` | content mutation of a signed-exec-pinned inode denied |

*kacs_securityfs reason — which securityfs endpoint path a record marks.* <a id="cite-kacs-abi.trace.securityfs-reasons"></a>

The sessions_read codes disambiguate the deny rungs that otherwise
collapse into an errno; open_self / init report the endpoint outcome.
Verdict is `ret`. Emitted by kacs:kacs_securityfs.

| Constant | Value | Notes |
|---|---|---|
| `KACS_SFS_LOGON_SESSIONS_NO_TOKEN` | `0` | sessions read: no effective subject token |
| `KACS_SFS_LOGON_SESSIONS_PIP_CONTEXT` | `1` | sessions read: caller PIP context unavailable |
| `KACS_SFS_LOGON_SESSIONS_ACCESS_CHECK` | `2` | sessions read: rust access check denied |
| `KACS_SFS_OPEN_SELF` | `3` | open of kacs/self self-token file outcome |
| `KACS_SFS_INIT` | `4` | securityfs kacs/ endpoint init outcome |

*kacs_caap reason — which CAAP policy-cache path a record marks.* <a id="cite-kacs-abi.trace.caap-reasons"></a>

SET carries the post-set cache_len (an insert grows it; an evict/replace
may shrink it); INIT/DESTROY are cache lifecycle; TCB_GATE is the
SeTcbPrivilege gate deny. Emitted by kacs:kacs_caap. No SID or spec
bytes — lengths only.

| Constant | Value | Notes |
|---|---|---|
| `KACS_CAAP_TCB_GATE` | `0` | SeTcbPrivilege gate denied the caller |
| `KACS_CAAP_SET` | `1` | cache set (insert/evict); cache_len is post-set count |
| `KACS_CAAP_INIT` | `2` | CAAP cache created |
| `KACS_CAAP_DESTROY` | `3` | CAAP cache destroyed |

kacs_capability reason — the capability->privilege gate verdicts and the
capability LSM-hook outcomes. ALLOW_GRANT is an auto-granted allow-cap;
HARD_DENY is the SETPCAP/SETFCAP/MAC_OVERRIDE hard block;
PRIV_NOT_ENABLED USE_MARK_FAIL are the mapped-privilege gate failures;
CAPSET / PRCTL_GUARD CAPABLE / CAPGET report the corresponding hook
outcome. Emitted by kacs:kacs_capability. Verdict is `ret`. <a id="cite-kacs-abi.trace.capability-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_CAP_ALLOW_GRANT` | `0` | allow-cap auto-granted (no privilege needed) |
| `KACS_CAP_HARD_DENY` | `1` | SETPCAP/SETFCAP/MAC_OVERRIDE hard-denied |
| `KACS_CAP_PRIV_NOT_ENABLED` | `2` | mapped privilege not enabled on token |
| `KACS_CAP_USE_MARK_FAIL` | `3` | privilege use-mark failed |
| `KACS_CAP_CAPSET` | `4` | capset core outcome |
| `KACS_CAP_PRCTL_GUARD` | `5` | prctl capability-guard outcome |
| `KACS_CAP_CAPABLE` | `6` | capable() hook guard-deny outcome |
| `KACS_CAP_CAPGET` | `7` | capget for-task outcome |

kacs_privilege reason — the require_enabled_privilege gate rungs plus
two standalone privilege-path markers. NULL_OR_ZERO is a null-
token/zero-mask guard; NOT_ENABLED / USE_MARK_FAIL are the gate
failures; CHANGE_NOTIFY marks the open_by_handle_at
SeChangeNotifyPrivilege check outcome; RCU_ENOMEM_ FALLBACK marks the
deferred-free ENOMEM synchronize_rcu fallback. Emitted by
kacs:kacs_privilege. Verdict is `ret`. <a id="cite-kacs-abi.trace.privilege-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `KACS_PRIV_NULL_OR_ZERO` | `0` | null token or zero privilege mask |
| `KACS_PRIV_NOT_ENABLED` | `1` | privilege not enabled on token |
| `KACS_PRIV_USE_MARK_FAIL` | `2` | privilege use-mark failed |
| `KACS_PRIV_CHANGE_NOTIFY` | `3` | open_by_handle_at CHANGE_NOTIFY gate outcome |
| `KACS_PRIV_RCU_ENOMEM_FALLBACK` | `4` | deferred-free kmalloc failed; sync-rcu fallback |

*kacs_tlp reason — the trusted-launch-path decisions.* <a id="cite-kacs-abi.trace.tlp-reasons"></a>

CHECK_PATH marks a no-prefix-match executable-transition deny (path_len
+ prefix_count only, NEVER path or prefix bytes); REPLACE marks a
prefix-table replacement. Emitted by kacs:kacs_tlp. Verdict is `ret`.

| Constant | Value | Notes |
|---|---|---|
| `KACS_TLP_CHECK_PATH` | `0` | executable transition denied: no prefix match |
| `KACS_TLP_REPLACE` | `1` | TLP prefix table replaced |

*kacs_mntns reason — mount-namespace object lifecycle and the mount gate.*

SD_ALLOC / SD_ALLOC_FAIL mark a namespace minted with (or without) its
creator descriptor; the gate reasons say which rung admitted or refused
a mount-table change: PRIVILEGE is SeManageVolume / SeTcb, NO_SD is a
namespace with no descriptor (the initial one), OP_NOT_ADMITTED is an
operation the descriptor can never grant, SD_DECISION is the access
check against the namespace descriptor, PIP_CONTEXT a failure to read
the caller's PIP state. Emitted by kacs:kacs_mntns. Verdict is `ret`.

| Constant | Value | Notes |
|---|---|---|
| `KACS_MNTNS_SD_ALLOC` | `0` | namespace minted with a creator descriptor |
| `KACS_MNTNS_SD_ALLOC_FAIL` | `1` | descriptor could not be built |
| `KACS_MNTNS_GATE_PRIVILEGE` | `2` | admitted by SeManageVolume / SeTcb |
| `KACS_MNTNS_GATE_NO_SD` | `3` | namespace has no descriptor; refused |
| `KACS_MNTNS_GATE_OP_NOT_ADMITTED` | `4` | op needs the privilege whatever the SD says |
| `KACS_MNTNS_GATE_SD_DECISION` | `5` | access check against the namespace SD |
| `KACS_MNTNS_GATE_PIP_CONTEXT` | `6` | caller PIP context unavailable |
| `KACS_MNTNS_GATE_FS_NOT_ADMITTED` | `7` | filesystem type not on the unprivileged allowlist |
| `KACS_MNTNS_SB_STAMP` | `8` | unprivileged tmpfs stamped synth-ephemeral, creator template |
| `KACS_MNTNS_SB_STAMP_FAIL` | `9` | creator template could not be built |

---

# MS-DTYP compatibility and divergences

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Where KACS departs from MS-DTYP despite using its binary formats, and which features are handled elsewhere rather than here.

<a id="trm-3-b"></a>

KACS uses the binary formats MS-DTYP specifies, so a descriptor
authored by a Windows domain controller and replicated through Samba
is evaluated without translation. <a id="cite-dtyp.binary-formats-untranslated"></a> PCDS specifies those formats
normatively.

Evaluator behaviour is a separate question. Given the same token,
descriptor and desired mask, KACS generally reaches the same decision
MS-DTYP describes — which is what makes policy authored in an AD
environment behave predictably here — but it departs deliberately in
the following places.

| Area | Departure | Why |
|---|---|---|
| Conditional ACE `@Local.` | Resolved from an AccessCheck parameter rather than a token field | The context is per-call and varies between checks. <a id="cite-dtyp.local-from-accesscheck-parameter"></a> |
| Virtual groups in expressions | `Member_of({S-1-3-4})` returns true for the owner | Keeps the SID matcher and the expression evaluator semantically consistent. <a id="cite-dtyp.member-of-owner-virtual-group"></a> |
| INT64/UINT64 promotion | Relational operators promote between the two | Without promotion, `UINT64` claims cannot be used in conditions at all. <a id="cite-dtyp.int64-uint64-promotion"></a> |
| `Member_of` filtering | Filtered by ACE polarity, so deny-only groups do not satisfy allow-ACE conditions | Consistent with deny-only group semantics everywhere else. <a id="cite-dtyp.member-of-ace-polarity"></a> |
| `Exists` scope | Extended to all four attribute namespaces | No reason to restrict existence tests to Local and Resource. <a id="cite-dtyp.exists-all-namespaces"></a> |
| ACE mask mapping | ACE masks are mapped through GenericMapping at evaluation time | Required for `GENERIC_ALL` in central access policy recovery ACEs ([Central Access and Auditing Policy](</kernel/internals/kacs/access-check/central-access-and-auditing-policy.md#trm-3-8-8>)). <a id="cite-dtyp.ace-mask-generic-mapping"></a> |
| `MAXIMUM_ALLOWED` | First-writer-wins for targeted *and* maximum-allowed requests | Eliminates disagreement between "what can I do?" and "can I do this?" on a non-canonically ordered DACL. <a id="cite-dtyp.maximum-allowed-first-writer-wins"></a> |
| Zero desired mask | Succeeds rather than returning access denied | "Asked for nothing, got nothing" is a valid answer. <a id="cite-dtyp.zero-desired-mask-succeeds"></a> |
| Alarm ACEs | Repurposed for continuous per-operation auditing, recorded as `kacs.audit.handle.used` ([Auditing in AccessCheck](</kernel/internals/kacs/access-check/auditing-in-accesscheck.md#trm-3-8-9>)) | Reserved but never implemented in the reference model. <a id="cite-dtyp.alarm-ace-continuous-audit"></a> |
| Multiple scoped policy ACEs | Several permitted per SACL | AND semantics make composition safe. <a id="cite-dtyp.multiple-scoped-policy-aces"></a> |
| Mandatory policy mutability | `mandatory_policy` is immutable on the token ([Token Structure](</kernel/internals/kacs/tokens/token-structure.md#trm-3-2-2>)) | A mutable policy reduces MIC to advisory. <a id="cite-dtyp.mandatory-policy-immutable"></a> |
| Impersonation integrity ceiling | Enforced unconditionally; `SeImpersonatePrivilege` does not bypass it ([Impersonation Gates](</kernel/internals/kacs/impersonation/levels-and-admission.md#trm-3-5-2>)) | MIC is a real boundary precisely because the mandatory policy is immutable. <a id="cite-dtyp.impersonation-ceiling-unconditional"></a> |
| Impersonation origin check | Dropped | Eliminates hidden impersonation paths. <a id="cite-dtyp.impersonation-origin-check-dropped"></a> |
| Impersonation level on primaries | Meaningful and queryable: a ratchet every token carries, bounding everything derived from it ([Impersonation Levels](</kernel/internals/kacs/impersonation/levels-and-admission.md#trm-3-5-1>)). Windows rejects `TokenImpersonationLevel` on a primary. | Delegation here is a flag authd enforces rather than a property of the credential cache, so the flag itself has to be unforgeable across duplication. <a id="cite-dtyp.impersonation-level-on-primaries"></a> |
| PIP determination | Kernel-only, from the binary signature, with no parent input ([PSB Fields](</kernel/internals/kacs/process-security/psb-fields.md#trm-3-3-2>)) | One input, one answer, no ambiguity. <a id="cite-dtyp.pip-kernel-only-determination"></a> |
| Object type list validation | Duplicate GUIDs and level gaps rejected ([Object ACEs and Property-Level Access](</kernel/internals/kacs/access-check/object-aces-and-property-level-access.md#trm-3-8-5>)) | Prevents node lookup returning the wrong node and propagation becoming undefined. <a id="cite-dtyp.object-type-list-validation"></a> |
| Object type list depth | No limit on levels; the tree is bounded only by the node count the access-check interface accepts. MS-DTYP limits a list to four levels. | A depth limit would reject lists the validation rules already make well-defined, and nothing in propagation depends on depth. <a id="cite-dtyp.object-type-list-no-level-limit"></a> |

<a id="trm-3-b-1"></a>

## Features handled elsewhere

Several capabilities relevant to a complete security posture are not
KACS's, and are named here so their absence is not mistaken for a gap.
Kerberos and NTLM authentication, S4U, and credential storage and
protection belong to authd, as do Resource-Based Constrained
Delegation and Authentication Policies and Silos through the KDC.
Active Directory replication is Samba's. Group Policy distribution
goes through the registry and roles. Network share permissions belong
to the Samba SMB layer. An Encrypting File System is a future service.

---

# ABI status and naming differences

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> ABI status and naming differences: behaviour and implementation of the Peios kernel.

<a id="trm-3-d"></a>

[KACS ABI Reference](</kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a>) is generated from `include/uapi/pkm/` and holds only what a compiler
can measure. This appendix holds the rest: the two ACE types that have
a constant and no behaviour, the payload shapes behind the token query
classes, the specification spellings a reader may arrive holding, what
is deliberately documented elsewhere, and the kernel configuration
KACS is built by.

The split is structural rather than editorial. `gen-kacs-abi.py`
overwrites [KACS ABI Reference](</kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a>) wholesale on every run, so anything written there is
lost the next time the ABI changes — which is exactly what happened to
two sections of this one before they were moved here.

<a id="trm-3-d-4"></a>

## Names that differ from the specifications

This manual uses the names `include/uapi/pkm/` declares, and the generated
tables of [KACS ABI Reference](</kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a>) are authoritative for them. A reader may instead arrive
holding the name PCDS uses, which is MS-DTYP's — a legitimate spelling,
not an obsolete one, and the one a third party implementing PCDS will
have. This table maps those onto the headers.

| PCDS / MS-DTYP | uapi name |
|---|---|
| `ACCESS_ALLOWED_ACE_TYPE`, `SYSTEM_AUDIT_ACE_TYPE`, ... | `KACS_ACE_TYPE_ACCESS_ALLOWED`, `KACS_ACE_TYPE_SYSTEM_AUDIT`, ... (the qualifier moves to the front) |
| `KACS_REAL_TOKEN` | `KACS_TOKEN_OPEN_REAL` |
| `KACS_LEVEL_*` | `KACS_IMLEVEL_*` |
| `KACS_FILE_SUPERSEDE`, `_OPEN`, ... | `KACS_DISPOSITION_*` |
| `OWNER_SECURITY_INFORMATION`, ... | `KACS_SECINFO_*` |
| `SE_PRIVILEGE_ENABLED` / `_REMOVED` | `KACS_PRIVILEGE_ATTR_ENABLED` / `_REMOVED` |
| `KACS_PRIV_RESET_ALL_DEFAULTS` | `KACS_PRIVILEGE_RESET_ALL_DEFAULTS` |
| `KACS_RESTRICT_WRITE_RESTRICTED` | `KACS_TOKEN_RESTRICT_WRITE_RESTRICTED` |
| `SE_GROUP_*` | `KACS_SID_GROUP_*` |
| `TOKEN_CLASS_*` | `KACS_TOKEN_CLASS_*` |

The PIP tiers have no public names at all. The Protected type (512)
and the `PeiosTcb` trust level (8192) exist only as kernel-private
constants, and nothing in `include/uapi/pkm/` defines None, Protected or
Isolated. <a id="cite-abi-notes.pip-tiers-kernel-private"></a> A program reasoning about tiers compares the numbers
([Process Integrity Protection](</kernel/internals/kacs/executable-trust/process-integrity-protection.md#trm-3-7>)).

<a id="trm-3-d-6"></a>

## Open-interface documentation discrepancies

The comparison below records historical documentation differences. The
[pinned source findings](#pinned-source-findings) resolve specific creator-SD,
create-option and no-follow questions; they do **not** reconcile every group
below. No runtime behavior or historical release boundary was tested or
established. The generated ABI supplies layouts and constants; it does not
settle these behavioral questions.

Source labels and line numbers refer to the `learn` snapshot
`4b119864d7f51c569ae1ac1932e4430f06731cf2`:

- **O:** the former Security Fundamentals [Opening files source](https://github.com/peios/learn/blob/4b119864d7f51c569ae1ac1932e4430f06731cf2/peios.product/1--security-fundamentals.antho/200--access-control.shelf/500--file-access.topic/300--opening-files.md), retained in that revision's history.
- **N:** [KACS-Native Open](/kernel/internals/kacs/file-security/kacs-native-open.md#trm-3-9-2), TRM [KACS-Native Open](</kernel/internals/kacs/file-security/kacs-native-open.md#trm-3-9-2>).
- **L:** [Legacy Open Compatibility](/kernel/internals/kacs/file-security/legacy-open-compatibility.md#trm-3-9-3), TRM [Legacy Open Compatibility](</kernel/internals/kacs/file-security/legacy-open-compatibility.md#trm-3-9-3>).
- **D:** [Opening a file](https://learn.peios.org/peios/developing-for-peios/sdk-reference/sdk-files/opening-a-file), SDK reference.
- **G:** [Securing files](https://learn.peios.org/peios/developing-for-peios/sdk-access-control/securing-files), SDK guide.

The links reach the current references; the line numbers identify the
comparison snapshot above.

The PEI-1720 change has since replaced the native-open contract that
groups 1, 5 and 7 compare against. `MAXIMUM_ALLOWED` may be named
alone, and no data right is required. Delete-on-close follows NT,
deleting at the last close of any open. `kacs_open_how` carries a share
mode. The current behaviour is in [KACS-Native Open](</kernel/internals/kacs/file-security/kacs-native-open.md#trm-3-9-2>) and [Sharing and Deletion](</kernel/internals/kacs/file-security/sharing-and-deletion.md#trm-3-9-10>); those groups
record the historical differences only.

1. **Maximum allowed.** O:116–127 says `MAXIMUM_ALLOWED` returns the
   maximum mask without checking the other requested bits, which it calls
   hints; N:14–19 says the concrete data/execute bits must be granted.
   Both require a concrete bit and reject `MAXIMUM_ALLOWED` alone. The
   general [DACL walk](/kernel/internals/kacs/access-check/the-dacl-walk.md#trm-3-8-2-5)
   describes a separate AccessCheck layer and cannot settle open validity
   by analogy.

2. **Legacy masks.** O:135–145 maps `O_RDONLY` to
   `FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA | READ_CONTROL | SYNCHRONIZE`,
   `O_WRONLY` to
   `FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | READ_CONTROL | SYNCHRONIZE`,
   and `O_RDWR` to their union. O:154–158 makes only `FILE_READ_DATA` core
   for read-only opens and allows `FILE_READ_ATTRIBUTES` to be dropped.
   L:16–37 instead makes `FILE_READ_ATTRIBUTES` core with read data, write
   data, or both according to the flag; L:39–49 lists broader compat rights.
   O:138 says `O_APPEND` adds `FILE_APPEND_DATA`; L:30–33 replaces core
   `FILE_WRITE_DATA` with it, then re-adds write data for `O_TRUNC`.
   L:44–45 also requests write data as optional compat access on append
   opens. These are different mappings, not interchangeable summaries.

3. **Creator descriptors.** O:96–97 groups open-existing branches under
   `EINVAL` and lists `SUPERSEDE` only for an absent target. N:133–144
   distinguishes `FILE_OPEN` (`EOPNOTSUPP`) from existing
   `FILE_OPEN_IF`, `FILE_OVERWRITE` and `FILE_OVERWRITE_IF` (`EINVAL`);
   N:82–89 also permits a caller-supplied SD on replacement by
   `FILE_SUPERSEDE`. D:36–46 and G:19–36 show `OPEN_IF` with a non-null
   creator SD and imply that the existing-file branch succeeds, despite
   O and N rejecting it. The SDK examples have now been changed to create-only.
   The pinned source findings below settle these existing-object rejections;
   this pass does not settle the separate `SUPERSEDE` comparison.

4. **Replacement and status.** O:71 says `SUPERSEDE` removes the inode
   and recommends it for atomic-replace patterns. N:82–89 replaces the
   pathname while preserving old hardlinks and already-open references.
   O:112 claims nonconditional dispositions predict the status; N:176–179
   says an absent-target `FILE_SUPERSEDE` reports `CREATED`, with
   `SUPERSEDED` only for actual replacement. No atomicity guarantee follows
   from this comparison.

5. **Delete-on-close.** O:80 describes deletion on the last fd referencing
   the file. N:112–129 instead specifies final close of one file-description
   lineage, preserved by `dup`, `fork` and `SCM_RIGHTS`; later opens fail
   closed, and only regular files are supported. Generic inode
   last-reference semantics and this no-share lineage boundary differ.

6. **Unverified raw details.** O:88 claims native `AT_EMPTY_PATH` opens
   an empty path against the directory referenced by `dirfd`; N:66–69
   discusses that flag for get/set-security, not native open. O:140–143
   maps `O_CREAT` to `OPEN_IF` with parent `FILE_ADD_FILE`,
   `O_CREAT | O_EXCL` to `CREATE`, and `O_NOFOLLOW` to
   `AT_SYMLINK_NOFOLLOW`. Their exact legacy translation and parent-right
   timing are not established by N/L/D. O:170 attributes legacy creation
   to umask-based defaults plus parent inheritable ACEs; [Inheritance](https://learn.peios.org/specifications/pcds/security-descriptor/inheritance/)
   describes parent, creator and token SD sources without establishing
   that umask contribution. O:183,185 also lists path-component
   `ENOTDIR` and invalid-disposition `EINVAL`. These remain earlier,
   unverified claims; omission from another reference does not prove
   rejection or support. O:180 distinguishes a failed open access check
   from an unreachable path component; [directory traversal](/kernel/internals/kacs/file-security/use-time-semantics.md#trm-3-9-4-3)
   is a separate authorization check.

7. **SDK destination caveats.** D:3 mentions share mode; D:28 describes
   no-follow, write-through and the rest of the `NtCreateFile` option set.
   N:111–120 instead lists two supported create-option bits, reserves all
   others, and says the ABI has no share-mode field. D:26 calls the native
   result a “granted subset,” while N:6–19 distinguishes strict requests
   from maximum-allowed requests. The SDK reference is a programming
   entry point, not evidence that every difference has been reconciled. The
   current SDK page no longer advertises share mode or unsupported create
   options; the pinned source below verifies the accepted option bits and
   their SDK field mapping. The granted-subset wording versus strict/maximum
   semantics remains part of the unresolved comparison.

<a id="trm-3-d-6-1"></a>

### Pinned source findings

A bounded source check used kernel
`8e0e22de3a59cad506bbbf8873de456e16ad272d` and libpeios 0.5.8
`de0018bdcaed14abb796aeccec9c8387fd30e452`. These are implementation findings
for those commits, not proof about a deployed kernel or the release where a
behavior began. Referenced KUnit tests are definitions; they were not executed.

- **Creator SDs (part of group 3).** [Argument validation](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/native_open.c#L192-L202)
  rejects `OPEN` plus creator SD with `EOPNOTSUPP` and `OVERWRITE` plus creator
  SD with `EINVAL`. [Existing-path handling](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/native_open.c#L1443-L1451)
  rejects `OPEN_IF` and `OVERWRITE_IF` plus creator SD with `EINVAL` when the
  object exists. The [OPEN_IF test](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/kunit_file.c#L6020-L6053)
  records that expectation. [SDK marshalling](https://github.com/peios/libpeios/blob/de0018bdcaed14abb796aeccec9c8387fd30e452/src/file.rs#L131-L196)
  forwards the disposition and SD, rather than stripping the SD on an existing
  path. Use create-only with an explicit SD or open-existing with `NULL` SD;
  an `EEXIST` retry is a separate operation, not an atomic transaction.
- **Create options (part of group 7).** The [accepted-bit mask](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/native_open.c#L165-L170)
  contains only `DIRECTORY` and `DELETE_ON_CLOSE`; unsupported bits return
  `EINVAL`. The same SDK marshalling copies `options` to `create_options` and
  `flags` to `flags`, so `AT_SYMLINK_NOFOLLOW` belongs in the latter.
- **No-follow is operation-specific.** [Native open](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/native_open.c#L1334-L1349)
  rejects a terminal symlink with `ELOOP`. The by-path SD query instead selects
  the link itself through its [lookup flags](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/sd_access.c#L312-L327)
  and [path resolver](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/sd_access.c#L506-L536), as recorded by a
  [link-query test](https://github.com/peios/pkm/blob/8e0e22de3a59cad506bbbf8873de456e16ad272d/kacs/kunit_file.c#L7586-L7625).
  The [SDK query path](https://github.com/peios/libpeios/blob/de0018bdcaed14abb796aeccec9c8387fd30e452/src/file.rs#L220-L312) forwards the flags; its
  buffer-size adaptation does not impose a terminal-link rejection. This
  query finding does not verify a successful link-SD write or remove the
  set-security component and storage checks.

Groups 1, 2, 4, 5 and 6 remain unresolved by this check, as do the other
behavioral claims in groups 3 and 7. Do not treat the TRM, SDK or generated
ABI as a blanket resolution of those differences.

<a id="trm-3-d-7"></a>

## What is not here

Required rights, error codes and validation rules are properties of
the implementation rather than of the headers, so they are documented
with the operations themselves: token rights and the per-ioctl
requirements in [Token Access Rights](</kernel/internals/kacs/tokens/token-access-rights.md#trm-3-2-8>), the file rights in [The Handle Model](</kernel/internals/kacs/file-security/the-handle-model.md#trm-3-9-1>), the process rights
in [Process Security Descriptors](</kernel/internals/kacs/process-security/process-security-descriptors.md#trm-3-3-3>), and the privileges in [Privilege Catalogue](</kernel/internals/kacs/privileges/privilege-catalogue.md#trm-3-4-2>).

Two neighbouring ABIs are generated or documented separately.
`include/uapi/pkm/trace.h` is a versioned, append-only ABI of tracepoint
reason, operation and state codes intended for tooling.
`include/uapi/pkm/kmes.h` and `include/uapi/pkm/lcs.h` belong to their own chapters.

---

# Descriptor and ACE semantics

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Descriptor and ACE semantics: behaviour and implementation of the Peios kernel.

<a id="trm-3-d-1"></a>

## ACE types with no evaluator behaviour <a id="cite-abi-notes.opaque-ace-types"></a>

Two of the ACE type constants in [KACS ABI Reference](</kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a>) have a constant and nothing
behind it. The ACE parser in `kacs-core` dispatches on 0x00–0x03,
0x05–0x14 and classifies every other value as opaque, so an ACE of type
0x04 or 0x15 is skipped during evaluation and written back
byte-for-byte on serialisation. The constants exist so that a decoder
can put a name to the byte. libpeios' SDDL codec does, printing 0x15 as
`SYSTEM_ACCESS_FILTER`; the `sd` utility does not, and renders both as
`OTHER(0x04)` and `OTHER(0x15)`. [PCDS ACE types](https://learn.peios.org/specifications/pcds/security-descriptor/ace-types) records the same state
normatively.

---

# Token query semantics

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Token query semantics: behaviour and implementation of the Peios kernel.

<a id="trm-3-d-2"></a>

## Querying a token handle

The ioctl is straightforward in shape:

```
ioctl(token_fd, KACS_IOC_QUERY, &args)
```

Where `args` is a `kacs_query_args` struct:

| Field | Meaning |
|---|---|
| `token_class` | The numeric class identifying what to return (1–24 in v0.20). |
| `buf_len` | Input: the size of the output buffer in bytes. Output: the actual number of bytes the query needed. |
| `buf_ptr` | Userspace pointer to the output buffer. |

The kernel:

1. Validates the class against the catalog. Unknown classes return `-EINVAL`.
2. Checks that the fd grants `TOKEN_QUERY`. If not, returns `-EACCES`.
3. Computes the size the response needs.
4. If `buf_ptr` is zero or `buf_len` is zero — this is a **size query** — writes the required size to `buf_len` and returns 0.
5. If `buf_ptr` is non-zero but `buf_len` is smaller than required, returns `-ERANGE` with the required size still written to `buf_len`.
6. Otherwise writes the response to the buffer and returns 0.

The "two-call pattern" — size query then fetch — is the standard way to handle variable-length output:

1. Call once with `buf_ptr = NULL` (or `buf_len = 0`). The kernel writes the required size into `buf_len` and returns 0.
2. Allocate a buffer of the indicated size.
3. Call again with `buf_ptr` set to the buffer and `buf_len` set to its size. The kernel writes the response.

For classes with a fixed-size response, a single call with a buffer of the known size works in one go. The two-call pattern is needed only for classes whose response size depends on the token's contents (the groups class, the restricted-SIDs class, the default-DACL class, the claims classes).

The ioctl is idempotent — multiple queries for the same class produce the same result as long as the token has not been modified. Tokens carry a `modified_id` counter that increments on adjustment; if a query is part of a pipeline that depends on consistency across multiple queries, the `modified_id` can be queried first to detect mid-pipeline changes.

<a id="trm-3-d-3"></a>

## Token query payloads <a id="cite-abi-notes.token-query-payloads"></a>

The class numbers come from the header and are tabulated in [KACS ABI Reference](</kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a>);
these are the payloads each one returns. Sizes are in bytes; a variable-length payload uses
the shapes below. An invalid class returns `EINVAL`. <a id="cite-abi-notes.token-query-invalid-class"></a>

Two repeating shapes appear throughout. A **SID array** is
`[count:u32le]` followed by `count` entries of
`[sid_len:u32le][sid_bytes][attributes:u32le]`, and reports a count of
zero when the array is empty rather than an empty payload. <a id="cite-abi-notes.sid-array-shape"></a> A **claims
array** is `[count:u32le]` followed by `count` entries of
`[entry_len:u32le][entry_bytes]`. <a id="cite-abi-notes.claims-array-shape"></a> A bare SID is the SID bytes alone,
and an absent optional SID or ACL is zero bytes. <a id="cite-abi-notes.absent-optional-is-zero-bytes"></a>

| Class | Payload |
|---|---|
| `USER` | Bare SID. |
| `GROUPS` | SID array. |
| `PRIVILEGES` | 32 bytes: present, enabled, enabled-by-default and used, four `u64` in that order. |
| `TYPE` | `u32`, 4 bytes. |
| `INTEGRITY_LEVEL` | The mandatory-label SID `S-1-16-<level>`, 12 bytes. |
| `OWNER` | Bare SID, resolved through the owner index: 0 is the user SID, N is `groups[N-1]`. <a id="cite-abi-notes.owner-index-resolution"></a> |
| `PRIMARY_GROUP` | Bare SID, resolved the same way. |
| `INTERACTIVITY_SCOPE` | `u32`, 4 bytes. |
| `RESTRICTED_SIDS` | SID array; count 0 on an unrestricted token. |
| `SOURCE` | 16 bytes: an 8-byte name followed by a `u64` LUID. |
| `STATISTICS` | 40 bytes: token id, LogonSession id, modified id, token type, a reserved zero, and expiration. |
| `ORIGIN` | `u64`, 8 bytes. |
| `ELEVATION_TYPE` | `u32`, 4 bytes. |
| `DEVICE_GROUPS` | SID array. |
| `APPCONTAINER_SID` | Bare SID; empty when the token is unconfined. |
| `CAPABILITIES` | SID array. |
| `MANDATORY_POLICY` | `u32`, 4 bytes. |
| `LOGON_TYPE` | `u32`, 4 bytes, read from the LogonSession. |
| `LOGON_SID` | Bare SID, derived from the LogonSession id. |
| `DEFAULT_DACL` | Binary ACL; empty when none is set. |
| `IMPERSONATION_LEVEL` | `u32`, 4 bytes. |
| `USER_CLAIMS` | Claims array. |
| `DEVICE_CLAIMS` | Claims array. |
| `PROJECTED_SUPPLEMENTARY_GIDS` | `[count:u32le]` followed by `count` `u32` GIDs. |
| `GUID` | 16 raw bytes: the immutable token instance GUID, in the same byte order as KMES headers. |

`KACS_TOKEN_CLASS_GUID` (`0x19`) uses the standard query contract: a size probe reports 16, a non-probe buffer smaller than 16 returns `ERANGE` without a partial payload, and every query requires `TOKEN_QUERY`. `TOKEN_QUERY_SOURCE` alone does not grant it. <a id="cite-token.query.guid-size-and-right"></a>

Adjusting a token preserves its GUID; duplicating or restricting it creates a distinct token with a new GUID. Reopening the same token returns the same GUID. The `STATISTICS` payload remains 40 bytes and its token id is a LUID, not this GUID. <a id="cite-token.query.guid-immutable-instance"></a>

Querying the effective token returns the bytes stamped as KMES `effective_token_guid`; querying the real primary token returns `true_token_guid`. Impersonation changes which token the effective open selects, not either token's identity. <a id="cite-token.query.guid-matches-kmes"></a>

Several token fields have no query class at all: `created_at`,
`audit_policy`, `write_restricted`, `user_deny_only`,
`isolation_boundary`, `confinement_exempt`, the projected UID and GID
— only the supplementary GIDs are reportable —
`restricted_device_groups`, and the LCS registry credentials. <a id="cite-abi-notes.fields-without-query-class"></a>

---

# Socket ABI compatibility

_Peios Kernel / Userspace interfaces / Native interfaces / KACS_

> Socket ABI compatibility: behaviour and implementation of the Peios kernel.

<a id="trm-3-d-5"></a>

## Socket options and retired syscall numbers

Peer identity on AF_UNIX sockets is read and bounded through socket
options rather than syscalls. `include/uapi/pkm/socket.h` defines the option
level `SOL_KACS` (4096), its options `KACS_SO_PEER_TOKEN`,
`KACS_SO_IMPERSONATION_LEVEL`, `KACS_SO_PASS_TOKEN` and
`KACS_SO_RESTAMP`, and the ancillary message type `KACS_SCM_TOKEN`,
which travels at
`cmsg_level SOL_KACS` ([KACS ABI Reference](</kernel/userspace/native/kacs/generated-syscall-index.md#trm-3-a>)). <a id="cite-abi-notes.scm-token-cmsg-level"></a> The kernel dispatches the option level
in `net/socket.c` ahead of the protocol's own handlers (patch
`net/socket.c`), so the options reach KACS on
every socket family and KACS decides which it supports. <a id="cite-abi-notes.sol-kacs-dispatch-all-families"></a> The ancillary
message is carried per skb on AF_UNIX: `net/core/scm.c`
gives `struct scm_cookie` a counted token reference and parses
`SOL_KACS` control messages; `net/unix/af_unix.c` carries
the reference on `struct unix_skb_parms`, stops a stream read at an
identity boundary, and advances the register at the point of
consumption. Everything KACS-specific behind those hooks lives in
`security/pkm/kacs/socket.c`. The semantics and error codes are in [Impersonation Lifecycle](</kernel/internals/kacs/impersonation/state-transitions.md#trm-3-5-3>).

System V IPC objects carry descriptors of their own ([Objects and Their Descriptors](</kernel/internals/kacs/system-v-ipc/objects-and-their-descriptors.md#trm-3-11-1>)); their
rights are `include/uapi/pkm/ipc.h`, and the same header defines the
`KACS_SD_AT_SYSV_*` flags that let `kacs_get_sd` and `kacs_set_sd`
address such an object by kind and id (`dirfd` carries the id, the
path is NULL). <a id="cite-abi-notes.sysv-sd-at-addressing"></a> The lookup is `ipc_lsm_with_object`, exported from
`ipc/util.c` by `ipc/util-lsm-with-object.patch`; the hooks themselves
are the LSM's own IPC hooks and need no patch.

Three syscall numbers are retired and left as permanent holes:
1010 (`kacs_open_peer_token`), 1011 (`kacs_impersonate_peer`) and
1013 (`kacs_set_impersonation_level`). A binary built against them
gets `ENOSYS`. <a id="cite-abi-notes.retired-syscalls-enosys"></a> The first became `getsockopt(SOL_KACS,
KACS_SO_PEER_TOKEN)`, the third `setsockopt(SOL_KACS,
KACS_SO_IMPERSONATION_LEVEL)`, and the second was a fusion of the
first with `KACS_IOC_IMPERSONATE` that now lives in libpeios as
`peios_token_impersonate_peer`.

---

# LCS

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Find the Peios kernel articles about lcs.

Use these articles to understand lcs in the Peios kernel.

- [File descriptors and buffer conventions](</kernel/userspace/native/lcs/file-descriptors-and-buffer-conventions.md>)
- [Open, create and transaction syscalls](</kernel/userspace/native/lcs/open-create-and-transaction-syscalls.md>)
- [Key ioctls](</kernel/userspace/native/lcs/key-ioctls.md>)
- [Transaction ioctls](</kernel/userspace/native/lcs/transaction-ioctls.md>)
- [Errors](</kernel/userspace/native/lcs/errors.md>)
- [Generated syscall and common ABI](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md>)
- [Generated key and security ABI](</kernel/userspace/native/lcs/generated-key-and-security-abi.md>)
- [Generated watch ABI](</kernel/userspace/native/lcs/generated-watch-abi.md>)
- [Generated transaction and backup ABI](</kernel/userspace/native/lcs/generated-transaction-and-backup-abi.md>)
- [Generated source and diagnostic ABI](</kernel/userspace/native/lcs/generated-source-and-diagnostic-abi.md>)

---

# File descriptors and buffer conventions

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> The hybrid syscall and ioctl interface — key fds, open-time checking, transaction fds, and the conventions for strings and output buffers.

<a id="trm-5-5-1"></a>

LCS uses a hybrid syscall/ioctl interface, the same shape KACS uses
within PKM.

**Syscalls** create file descriptors: opening a key, creating a key,
beginning a transaction. There are three, numbered 1100 to 1102 in the
PKM range. <a id="cite-fd.three-syscalls-numbered-1100-to-1102"></a>

**Ioctls** operate on a descriptor that already exists —
eighteen of them, all under type byte `'R'`. <a id="cite-fd.eighteen-ioctls-under-type-r"></a>

**`close()`** releases
both kinds of fd through the ordinary fd lifecycle. <a id="cite-fd.close-releases-both-kinds"></a>

<a id="trm-5-5-1-1"></a>

## Key fds

A key fd is an anonymous inode created with `O_CLOEXEC`, holding: <a id="cite-fd.key-fd-is-an-anonymous-inode-with-cloexec"></a>

| Field | Description |
|---|---|
| Source and key GUID | The identity of the opened key. |
| Granted access mask | Computed once by AccessCheck at open. Immutable. |
| Resolved path | After symlink resolution and `CurrentUser\` rewriting. |
| Ancestor chain | The GUID at each path component from the hive root down. Captured during the open walk, used for subtree watch dispatch ([Dispatch](</kernel/internals/lcs/watches/dispatch.md#trm-5-6-3>)). |
| Watch state | Armed or not, filter, subtree flag, pending event queue. |

Key fds behave like any other fd: `close()`, close-on-exec,
`poll`/`epoll`, and passing over Unix sockets with `SCM_RIGHTS`. <a id="cite-fd.key-fds-are-ordinary-fds"></a> That
last one is what makes them capabilities ([The Access Flow](</kernel/internals/lcs/security/the-access-flow.md#trm-5-4-1>)).

<a id="trm-5-5-1-2"></a>

## Open-time checking

A caller names a desired access mask, and AccessCheck evaluates it
against the key's Security Descriptor. All of it is granted or the open
fails with `EACCES`. `MAXIMUM_ALLOWED` is the only way to ask for
whatever is available.

The granted mask lives on the fd, and every subsequent ioctl is a
bitmask test against it — not a fresh AccessCheck, and not a fresh read
of the descriptor.

Opening relative to a parent fd skips both path parsing and
AccessCheck for the parent portion. The caller already proved its
access when it obtained the parent fd, and this is the ordinary way to
walk a subtree.

<a id="trm-5-5-1-3"></a>

## Transaction fds

A transaction fd is an anonymous inode holding a transaction id and,
once bound, its source and hive. <a id="cite-fd.txn-fd-holds-id-source-and-hive"></a> Transaction lifetime is fd lifetime:
closing without committing aborts ([Scope and Lifetime](</kernel/internals/lcs/transactions/scope-and-lifetime.md#trm-5-7-1>)).

<a id="trm-5-5-1-4"></a>

## Reserved fields

Every syscall and ioctl argument structure uses natural C layout with
fixed-width fields and explicit padding. Nothing is packed. <a id="cite-fd.structs-use-natural-c-layout"></a>

Fields named `_pad`, and anything else described as reserved, are ABI
extension points. **A caller must set them to zero**, and a non-zero
reserved or padding field fails the operation with `EINVAL` — before
source dispatch, before transaction enlistment, before sequence
allocation, and before any output is copied. <a id="cite-fd.non-zero-reserved-field-is-einval"></a>

In the other direction, LCS zeroes every reserved and padding byte of
an output structure or a watch event before copying it to userspace. <a id="cite-fd.output-padding-is-zeroed"></a>

Flags fields carry only the bits defined for them. An unknown or
reserved flag bit is `EINVAL` unless a specific field says otherwise. <a id="cite-fd.unknown-flag-bit-is-einval"></a>

The point of all this is that a future version can give a reserved
field meaning without an older kernel having silently accepted a value
it did not understand.

<a id="trm-5-5-1-5"></a>

## Strings

Strings in ioctl structures are **length-delimited, not
null-terminated**. Each is a `(len, ptr)` pair where `len` is a byte
count and `ptr` is a `u64` userspace address. LCS reads exactly `len`
bytes. <a id="cite-fd.string-is-a-len-ptr-pair"></a> A terminator is neither required nor expected, and one included
in the length is a null byte and therefore invalid.

Syscall paths are the exception: they arrive as null-terminated C
strings and have the terminator stripped before validation ([Names and Case](</kernel/internals/lcs/data-model/names-and-case.md#trm-5-2-8>)).

<a id="trm-5-5-1-6"></a>

## Variable-size output buffers

Six ioctls return variable-size data — `REG_IOC_QUERY_VALUE`,
`QUERY_VALUES_BATCH`, `ENUM_VALUES`, `ENUM_SUBKEYS`, `QUERY_KEY_INFO`
and `GET_SECURITY` — and all six use one convention. <a id="cite-fd.six-ioctls-return-variable-size-data"></a>

For each output buffer described by `(length, pointer)`:

- **length 0 is a size probe**, whether the pointer is null or not. The
  pointer is not dereferenced. <a id="cite-fd.zero-length-is-a-size-probe"></a>
- **length greater than 0** requires a non-null pointer writable for
  that many bytes, or the ioctl returns `EFAULT`. <a id="cite-fd.non-zero-length-needs-a-writable-pointer"></a>

If any output buffer is too small the ioctl returns `ERANGE` and writes
**every required size it can determine**, not just the first one that
failed — so a caller with two undersized buffers learns both sizes from
one call. <a id="cite-fd.erange-writes-every-determinable-size"></a>

On `ERANGE`, output buffers are **not partially filled**; their
contents are unspecified. <a id="cite-fd.erange-leaves-buffers-unfilled"></a>

Output scalar metadata is meaningful only on
success, unless an ioctl explicitly documents a field as carrying a
required size or count on `ERANGE`. <a id="cite-fd.output-scalars-meaningful-only-on-success"></a>

Input pointer faults return `EFAULT`, validated before source dispatch
wherever that is possible. <a id="cite-fd.input-pointer-fault-is-efault"></a>

<a id="trm-5-b"></a>

[LCS ABI Reference](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md#trm-5-a>) is generated from `include/uapi/pkm/lcs.h` and holds only what a
compiler can measure. This appendix holds the rest.

The split is structural rather than editorial. `gen-lcs-abi.py`
overwrites [LCS ABI Reference](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md#trm-5-a>) wholesale on every run, so anything written there is
lost the next time the ABI changes.

<a id="trm-5-b-1"></a>

## What is not here

The header carries names, numbers and layouts. Everything else about the
interface is a property of the implementation rather than of the ABI, and
is documented with the operation it belongs to: the required access right
for each ioctl and the two-pass output buffer convention in [The Fd Model](</kernel/userspace/native/lcs/file-descriptors-and-buffer-conventions.md#trm-5-5-1>), the
error vocabulary in [The Error Model](</kernel/userspace/native/lcs/errors.md#trm-5-5-5>), the RSI payload shapes in the Registry Source
Interface specification, and the backup stream's record payloads in the
Registry Backup Format specification.

`REG_BACKUP_MAGIC` in [LCS ABI Reference](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md#trm-5-a>) is the eight-byte header magic; <a id="cite-lcs-abi-notes.backup-magic-is-eight-byte-header"></a> the record
type codes are the framing, not the payloads.

---

# Open, create and transaction syscalls

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Opening keys and beginning read or write transactions, with their arguments and failure conditions.

<a id="trm-5-5-2"></a>

<a id="trm-5-5-2-1"></a>

## `reg_open_key` (1100)

```c
int reg_open_key(int parent_fd, const char __user *path,
                 u32 desired_access, u32 flags);
```

Opens an existing key. Fails if it does not exist after layer
resolution.

| Parameter | Description |
|---|---|
| `parent_fd` | An open key fd to resolve relative to, or -1 for an absolute path. No AccessCheck is performed on the parent. <a id="cite-reg-syscall.open-key.parent-fd-or-minus-one"></a> |
| `path` | A null-terminated registry path — absolute with a hive prefix when `parent_fd` is -1, relative to the parent key otherwise. <a id="cite-reg-syscall.open-key.path-is-absolute-or-parent-relative"></a> |
| `desired_access` | Requested rights, raw generic bits, `MAXIMUM_ALLOWED`, or a combination ([Access Rights](</kernel/internals/lcs/security/access-rights.md#trm-5-4-2>)). Zero and unknown bits are `EINVAL`. |
| `flags` | `REG_OPEN_LINK` (`0x01`) opens a symlink key rather than following it. Every other bit is reserved and must be zero. <a id="cite-reg-syscall.open-key.flags-only-reg-open-link"></a> |

The open proceeds as follows. <a id="cite-reg-syscall.open-key.step-order"></a>

1. Parse and canonicalise the path: normalise separators, reject empty
   components and a trailing separator, check the total length and each
   component length.
2. Rewrite a leading `CurrentUser\` to `Users\<caller SID>\` — only for
   an absolute path, and only the first component ([Hives and Routing](</kernel/internals/lcs/data-model/hives-and-routing.md#trm-5-2-1>)).
3. Route. For an absolute path, look the hive name up, private hives
   before global ones. For a relative one, use the parent key's source
   and resolve from the parent's GUID.
4. Walk the path component by component through `RSI_LOOKUP`, resolving
   each through the layer stack and following symlinks — except a final
   component when `REG_OPEN_LINK` is set. Collect the ancestor chain as
   you go. <a id="cite-reg-syscall.open-key.walks-each-component-through-rsi-lookup"></a>
5. Run AccessCheck against the final key's descriptor.
6. Publish an fd holding the key GUID, the granted mask, the resolved
   path and the ancestor chain. <a id="cite-reg-syscall.open-key.fd-holds-guid-mask-path-and-chain"></a>

If the path traversed a symlink, the fd stores the *resolved* path and
ancestor chain. It refers to the target object.

| Errno | Condition |
|---|---|
| `ENOENT` | The key does not exist after layer resolution. <a id="cite-reg-syscall.open-key.enoent-key-missing"></a> |
| `EACCES` | AccessCheck did not grant everything requested. |
| `EINVAL` | Malformed path; zero or unknown `desired_access` bits; a symlink whose effective default value is not `REG_LINK`; maximum depth exceeded. |
| `ELOOP` | Symlink depth limit exceeded. |
| `ENAMETOOLONG` | A component or the total path is too long. <a id="cite-reg-syscall.open-key.enametoolong"></a> |
| `ETIMEDOUT` | The source did not answer within `RequestTimeoutMs`. |
| `EIO` | The source failed or is unavailable. |
| `ENOMEM` | Kernel allocation failure. |

<a id="trm-5-5-2-2"></a>

## `reg_create_key` (1101)

```c
int reg_create_key(const struct reg_create_key_args __user *args);
```

Opens the key if it exists after layer resolution, creates it with an
inherited descriptor if not, and reports which happened. <a id="cite-reg-syscall.create-key.opens-or-creates"></a>

| Field | Description |
|---|---|
| `parent_fd` | As `reg_open_key`. |
| `path_ptr` | Pointer to a null-terminated path. |
| `desired_access` | As `reg_open_key`. |
| `flags` | `REG_OPTION_VOLATILE` (`0x01`), `REG_OPTION_CREATE_LINK` (`0x02`). Other bits reserved. <a id="cite-reg-syscall.create-key.flags"></a> |
| `layer_ptr` | Pointer to a null-terminated layer name for creation, or null for the base layer. Names the layer whose entry is created; what "exists" means depends on it (below). <a id="cite-reg-syscall.create-key.null-layer-means-base"></a> |
| `txn_fd` | A transaction fd, or -1. A non-negative value makes creation a mutating operation that binds or reuses that transaction. <a id="cite-reg-syscall.create-key.txn-fd-makes-creation-transactional"></a> |
| `disposition_ptr` | Receives `REG_CREATED_NEW` (1) or `REG_OPENED_EXISTING` (2). May be null. <a id="cite-reg-syscall.create-key.disposition-values"></a> |
| `_pad0`, `_pad1` | Reserved; must be zero. |

**If the key exists**, this behaves as `reg_open_key` and the
disposition is `REG_OPENED_EXISTING`. <a id="cite-reg-syscall.create-key.existing-key-is-opened"></a>
What "exists" means depends on the layer named. For the base layer (a
null `layer_ptr`) it is the path resolving through any enabled layer.
For a named layer it is that layer holding an entry at the path:
presence is per layer ([Path Entries](</kernel/internals/lcs/data-model/path-entries.md#trm-5-2-5>)), so another layer's key at the same path
does not count, and the create makes the named layer's own entry, with
its own GUID and `REG_CREATED_NEW` — which is how hide-and-replace is
authored. <a id="cite-reg-syscall.create-key.named-layer-creates-its-own-entry"></a>

The named-layer presence check is read-only and compares layer names without
case sensitivity. If that layer already names a key, LCS opens the effective
key using normal layer resolution and checks the requested rights on that
key. It does not require `KEY_CREATE_SUB_KEY` on the parent, perform layer
write authorization, or send `CREATE_ENTRY`/`CREATE_KEY` for an existing key.
An unbound transaction remains unbound by this open; a bound transaction
uses its own view, including entries it has created but not yet committed.
The checks below still apply when the named layer has no key entry there.

**If it does not:**

1. Resolve the parent, which must exist. Check that the parent's depth
   plus one is within `MaxKeyDepth`. <a id="cite-reg-syscall.create-key.parent-must-exist-and-depth-checked"></a>
2. AccessCheck the parent for `KEY_CREATE_SUB_KEY`.
3. Perform layer write authorization against the target layer's
   metadata key ([Writing Into a Layer](</kernel/internals/lcs/layers/writing-into-a-layer.md#trm-5-3-4>)).
4. Mint a fresh UUIDv4 GUID.
5. Compute the new key's descriptor from the parent's, through KACS.
6. Create the path entry with a new sequence number, then the key
   record ([Path Entries](</kernel/internals/lcs/data-model/path-entries.md#trm-5-2-5>)).
7. AccessCheck the *new* key's inherited descriptor against
   `desired_access` — an inherited descriptor may not grant everything
   the creator asked for. <a id="cite-reg-syscall.create-key.inherited-descriptor-rechecked"></a>
8. Publish the fd with the granted mask and disposition
   `REG_CREATED_NEW`. <a id="cite-reg-syscall.create-key.new-key-reports-created-new"></a>

Intermediate path components are not auto-created. Only the final one
is. <a id="cite-reg-syscall.create-key.no-intermediate-creation"></a>

**Races.** If two callers race, one creates and the other observes the
key as existing. `RSI_ALREADY_EXISTS` on the path entry is retried as
an open, reporting `REG_OPENED_EXISTING`, and `EEXIST` never reaches
userspace from this syscall. `RSI_ALREADY_EXISTS` on the *key record*,
for a GUID LCS has just minted, is not a race — the source and the
kernel disagree about what exists — and fails closed with `EIO`
([Keys](</kernel/internals/lcs/data-model/keys.md#trm-5-2-3>)).

| Errno | Condition, in addition to `reg_open_key`'s |
|---|---|
| `ENOENT` | The parent does not exist, or the named layer is not in the layer table. <a id="cite-reg-syscall.create-key.enoent-parent-missing"></a> |
| `EACCES` | The parent denied `KEY_CREATE_SUB_KEY`, the inherited descriptor denied the requested access, or layer write authorization failed. |
| `EPERM` | `REG_OPTION_CREATE_LINK` without `KEY_CREATE_LINK` on the parent, or without `SeTcbPrivilege` or Administrators. |
| `ENOSPC` | The per-value layer cap was exceeded. |
| `EINVAL` | A non-volatile key under a volatile parent; a non-zero reserved field. |

<a id="trm-5-5-2-3"></a>

## `reg_begin_transaction` (1102)

```c
int reg_begin_transaction(void);
```

Allocates a transaction id, publishes a transaction fd in state
`REG_TXN_ACTIVE_UNBOUND`, and starts the lifetime timer. It contacts no
source and chooses none ([Scope and Lifetime](</kernel/internals/lcs/transactions/scope-and-lifetime.md#trm-5-7-1>)). It can fail only with `ENOMEM`,
`EOVERFLOW` on transaction id exhaustion, or `EINVAL`. <a id="cite-reg-syscall.begin-transaction.failure-set"></a>

## `reg_begin_read_transaction` (1103)

```c
int reg_begin_read_transaction(void);
```

Creates a read-only transaction with the same fd lifetime and status model.
The first read binds one source/hive, pins its persistent and volatile stores,
and freezes layer selection. Later reads, enumeration and transacted opens use
that view. Mutations fail `EROFS`; another hive fails `EXDEV`.

Capture overlapping Registry publication fails `EAGAIN`. Start a fresh
transaction and repeat the complete read. It never falls back to live reads.
The lifetime starts at begin and uses `TransactionTimeoutMs`. The source's
`MaxReadOnlyTransactionsPerSource` quota applies once bound. Closing releases
the snapshot; a bound snapshot may also be ended with `REG_IOC_COMMIT`.

The caller's ordered private-layer and hive-scope attachments must remain the
same throughout the read transaction. A changed attachment view fails `EACCES`;
it cannot silently select different data from the same snapshot. This does not
freeze the caller's identity or permissions for new opens.

## `reg_open_key_transacted` (1104)

```c
int reg_open_key_transacted(int parent_fd, const char __user *path,
                           u32 desired_access, u32 flags, int txn_fd);
```

Uses the same path and access arguments as `reg_open_key`, with a transaction
fd. In a read-only transaction, names and symlinks resolve through the frozen
view. AccessCheck uses the current descriptor of the resolved GUID and the
calling thread's effective token. A deleted GUID fails `ENOENT`, even if its
old path remains in the snapshot. A replacement at the same path has a distinct
GUID and cannot substitute its permissions. Existing key fds retain their
ordinary granted-access semantics.

---

# Key ioctls

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> The sixteen ioctls acting on a key fd — reading, writing, security, watches, durability and bulk — each gated on the fd's granted mask.

`REG_IOC_QUERY_KEY_INFO_TRANSACTED` and `REG_IOC_GET_SECURITY_TRANSACTED`
accept `reg_read_transacted_args`: `args_ptr` points to the corresponding
ordinary argument structure, `txn_fd` names the transaction, and `_pad` is
zero. They retain the ordinary access checks and buffer contracts, with data
read from the transaction. Key-info hive generation is fixed at read snapshot
capture. Existing non-transacted commands retain their live-read behaviour.

<a id="trm-5-5-3"></a>

Sixteen ioctls act on a key fd. <a id="cite-ioctl.sixteen-act-on-a-key-fd"></a> Each checks the fd's granted mask
first and returns `EACCES` without contacting the source if the
required right is absent ([Access Rights](</kernel/internals/lcs/security/access-rights.md#trm-5-4-2>)). Numbers, directions and argument
layouts are in [LCS ABI Reference](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md#trm-5-a>).

Every mutating ioctl accepts an optional transaction fd. <a id="cite-ioctl.mutating-ioctls-accept-a-transaction-fd"></a> So do the four
read ioctls — a read inside a bound transaction sees the transaction's
own uncommitted writes. A transaction bound to a different hive is
`EXDEV`; a committed, aborted or closed one is `EINVAL`; a timed-out
one is `ETIMEDOUT`; one whose source went Down is `EIO`. An unbound
transaction fd does not bind on a read, which is simply performed
non-transactionally.

Every mutating ioctl that names a layer performs layer write
authorization first ([Writing Into a Layer](</kernel/internals/lcs/layers/writing-into-a-layer.md#trm-5-3-4>)).

<a id="trm-5-5-3-1"></a>

## Common errors

| Errno | Condition |
|---|---|
| `EACCES` | The granted mask lacks the required right, or layer write authorization failed. |
| `EFAULT` | An input pointer is invalid, or a non-zero-length output buffer pointer is null or unwritable. |
| `EIO` | The source is unavailable, failed, or the transaction's source went Down. |
| `ETIMEDOUT` | The source did not answer within `RequestTimeoutMs`, or the transaction had timed out. |
| `ENOMEM` | Kernel allocation failure. <a id="cite-ioctl.enomem-on-allocation-failure"></a> |
| `EXDEV` | The transaction is bound to a different hive. |
| `ENOENT` | The named layer is not in the layer table. |
| `EINVAL` | A non-zero reserved or padding field. |
| `ENOTTY` | An ioctl number this fd type does not implement. <a id="cite-ioctl.enotty-for-an-unimplemented-number"></a> |

<a id="trm-5-5-3-2"></a>

## Reading

**`REG_IOC_QUERY_VALUE`** returns the effective value at a name:
its type, data, the sequence number of the winning entry, and the
**canonical name of the winning layer** — which is the layer table's
spelling, not whatever string the source stored. <a id="cite-ioctl.query-value.result-fields"></a> A base-layer entry
therefore reports `base`.

A winning tombstone or blanket, or no
entries at all, is `ENOENT`. <a id="cite-ioctl.query-value.masked-is-enoent"></a>

**`REG_IOC_QUERY_VALUES_BATCH`** returns every effective value on the
key in one call: name, type and data for each, with tombstoned and
blanket-masked values omitted. <a id="cite-ioctl.query-values-batch.returns-every-effective-value"></a> This is the call to use when you want
them all ([Resolution](</kernel/internals/lcs/layers/resolution.md#trm-5-3-6>)).

**`REG_IOC_ENUM_VALUES`** and **`REG_IOC_ENUM_SUBKEYS`** return the
entry at an index, and `ENOENT` past the end. <a id="cite-ioctl.enum.index-and-enoent-past-the-end"></a>

Both re-resolve the full
set on every call, and enumeration order is undefined — see [Resolution](</kernel/internals/lcs/layers/resolution.md#trm-5-3-6>) for
why the batch call usually wins. <a id="cite-ioctl.enum.re-resolves-and-order-is-undefined"></a>

`ENUM_SUBKEYS` performs no per-child access check. It returns every
visible child with its last write time, subkey count and value count. <a id="cite-ioctl.enum-subkeys.child-fields"></a>
The caller learns names and must open each child separately to read
anything ([Access Rights](</kernel/internals/lcs/security/access-rights.md#trm-5-4-2>)).

**`REG_IOC_QUERY_KEY_INFO`** returns the key's name, last write time,
subkey and value counts, the maximum subkey name length, maximum value
name length and maximum value data size, the descriptor size, the
volatile and symlink flags, and the hive generation number. <a id="cite-ioctl.query-key-info.result-fields"></a> It requires
`READ_CONTROL`.

For a non-root key, the name is the stored key record's informational name,
with its original spelling, rather than the spelling used to open the fd.
The required buffer length is that stored name's UTF-8 byte length, including
when the opening spelling folds to it but has a different byte length.
The source name must fold to the leaf the fd resolved; an unrelated name
is malformed key metadata, audited and refused with `EIO`, including on
a buffer-length probe. Hive roots have no child name and instead report
the preserved hive name from source registration, with its own byte length.
<a id="cite-ioctl.query-key-info.stored-name"></a>

It is declared `_IOWR`, which is what it does: it reads the caller's
output-buffer fields out of the argument structure before writing it
back. <a id="cite-ioctl.query-key-info.is-iowr"></a>

It was declared `_IOR`, and because the direction bits are part of
the encoded ioctl number and the kernel dispatches on the whole encoded
value, correcting that was an ABI break rather than a relabelling. A
binary built against the old constant gets `ENOTTY` from a kernel
carrying the new one. <a id="cite-ioctl.query-key-info.old-constant-gets-enotty"></a>

<a id="trm-5-5-3-2-1"></a>

### The hive generation number

A monotonic per-hive change epoch owned by the kernel. It is not a
sequence number and must not be read as one: sources neither report it
nor persist it ([The Sequence Counter](</kernel/internals/lcs/layers/the-sequence-counter.md#trm-5-3-7>)).

It is incremented once per committed mutation, or once per committed
transaction per affected hive, however many operations that transaction
contained. <a id="cite-ioctl.hive-generation.one-increment-per-commit"></a>

Its baseline is initialised from the source's reported
maximum sequence at registration so that observed values are monotonic
relative to persisted entries; saturating at `U64_MAX` is `EOVERFLOW`. <a id="cite-ioctl.hive-generation.saturation-is-eoverflow"></a>

It is exposed on every key because it is cheap and because a watcher
that receives `OVERFLOW` can compare the generation it last saw with
the current one and skip the recovery re-read entirely if nothing has
committed ([Queues and Overflow](</kernel/internals/lcs/watches/queues-and-overflow.md#trm-5-6-4>)).

Layer operations produce a single generation increment covering the
metadata key deletion, `RSI_DELETE_LAYER`, the recomputation and the
resulting watch effects. There is no generation at which the metadata
key is gone but the layer's entries are still resolving. <a id="cite-ioctl.hive-generation.layer-operation-is-one-increment"></a>

An operation
affecting several hives increments each independently. <a id="cite-ioctl.hive-generation.per-hive-independent"></a>

<a id="trm-5-5-3-3"></a>

## Writing

**`REG_IOC_SET_VALUE`** writes a value entry in a layer. LCS allocates
a sequence number and tells the source to store
`(key GUID, value name, layer) → (type, data, sequence)`, then updates
the key's last write time. <a id="cite-ioctl.set-value.stores-the-layer-tuple"></a>

Writing type `REG_TOMBSTONE` is the explicit tombstone operation and
requires zero-length data ([Values](</kernel/internals/lcs/data-model/values.md#trm-5-2-6>)).

A non-zero `expected_sequence` makes the write **conditional**. It is
passed to the source, which atomically verifies that the layer's own
current entry carries that sequence number before writing, and answers
`RSI_CAS_FAILED` if not — which LCS returns as `EAGAIN`. LCS reads the key's entries before every write, for watch dispatch,
but there is no kernel-side query-then-write for the condition: the
check is the source's, and it is atomic there or nowhere. <a id="cite-ioctl.set-value.expected-sequence-is-a-cas"></a>

The condition is evaluated against the **layer's own entry**, not
against the effective value. <a id="cite-ioctl.set-value.cas-tests-the-layers-own-entry"></a> A higher-precedence layer overriding a
value is not a lost update; it is the layer system working.

Additional errors:

- `EINVAL` for an unknown type or a tombstone with data.
- `EAGAIN` for a failed conditional write.
- `ENOSPC` for the layer cap or oversized data. <a id="cite-ioctl.set-value.enospc-layer-cap-or-oversized-data"></a>
- `ENAMETOOLONG` for the value name. <a id="cite-ioctl.set-value.enametoolong-value-name"></a>
- `EPERM` for a `Precedence` above 0 without `SeTcbPrivilege` ([Writing Into a Layer](</kernel/internals/lcs/layers/writing-into-a-layer.md#trm-5-3-4>)).

**`REG_IOC_DELETE_VALUE`** removes one layer's entry at a value name —
whether that entry was a value or a tombstone. <a id="cite-ioctl.delete-value.removes-one-layers-entry"></a> Removing a layer's
opinion lets lower-precedence layers surface.

The operation is meant to be idempotent, and it is idempotent as far as
a caller sees, provided the source answers `RSI_OK` for an entry that
was not there. LCS does not mask a source's `RSI_NOT_FOUND`; that
propagates as `ENOENT`. Idempotency is a source obligation, not a
kernel behaviour. <a id="cite-ioctl.delete-value.source-not-found-is-enoent"></a>

**`REG_IOC_BLANKET_TOMBSTONE`** sets or removes a blanket tombstone for
a layer on this key ([Tombstones](</kernel/internals/lcs/data-model/tombstones.md#trm-5-2-7>)). A new sequence number is assigned for
dispatch ordering, and watch events are generated for every value whose
effective state changed.

**`REG_IOC_DELETE_KEY`** removes this key's path entry from a layer. <a id="cite-ioctl.delete-key.removes-the-path-entry"></a>

The parent GUID comes from the fd's ancestor chain and the child name
from the last component of its resolved path. <a id="cite-ioctl.delete-key.parent-and-name-from-the-fd"></a> `ENOTEMPTY` if the key
has visible children; `EINVAL` on a hive root ([Deletion and Orphans](</kernel/internals/lcs/data-model/deletion-and-orphans.md#trm-5-2-9>)).

**`REG_IOC_HIDE_KEY`** creates a HIDDEN path entry at the same place
instead, masking lower-precedence entries. <a id="cite-ioctl.hide-key.creates-a-hidden-entry"></a> The caller must hold an open
fd to the key, which is how it proved access to it. <a id="cite-ioctl.hide-key.requires-an-open-fd"></a> `EINVAL` on a hive
root.

<a id="trm-5-5-3-4"></a>

## Security

**`REG_IOC_GET_SECURITY`** and **`REG_IOC_SET_SECURITY`** read and
merge Security Descriptor components, selected by a `security_info`
bitmask. [Inheritance and Hive Roots](</kernel/internals/lcs/security/inheritance-and-hive-roots.md#trm-5-4-3>) covers the rights, the merge, and the validation.

<a id="trm-5-5-3-5"></a>

## Watches, durability, bulk

**`REG_IOC_NOTIFY`** arms, re-arms or disarms a watch ([The Watch Model](</kernel/internals/lcs/watches/the-watch-model.md#trm-5-6-1>)).

**`REG_IOC_FLUSH`** tells the source to persist pending writes for this
key's hive, and returns when persistence is confirmed. <a id="cite-ioctl.flush.persists-and-waits-for-confirmation"></a> The hive name
comes from the first component of the fd's resolved path. <a id="cite-ioctl.flush.hive-from-the-fd-path"></a> It requires
`KEY_SET_VALUE` ([Access Rights](</kernel/internals/lcs/security/access-rights.md#trm-5-4-2>)).

**`REG_IOC_BACKUP`** and **`REG_IOC_RESTORE`** export and replace a
subtree. They are privilege-gated with no per-key access check, and
they are covered in [The Stream](</kernel/internals/lcs/backup-and-restore/the-stream.md#trm-5-9-1>).

---

# Transaction ioctls

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> The two ioctls acting on a transaction fd — commit and status — and why the key fd error table does not apply.

<a id="trm-5-5-4"></a>

Two ioctls act on a transaction fd. Everything else on that fd is
`ENOTTY` — there are no savepoint or nesting operations to have. <a id="cite-txn-ioctl.only-two-others-are-enotty"></a>

The common key fd error table does not apply here.

<a id="trm-5-5-4-1"></a>

## `REG_IOC_COMMIT`

Commits every operation in the transaction. [Commit and Failure](</kernel/internals/lcs/transactions/commit-and-failure.md#trm-5-7-3>) covers what happens
in each case; in summary:

| Errno | Condition |
|---|---|
| — | Success. The object becomes `COMMITTED`, poll waiters are woken, watch events are delivered, and further use of the fd returns `EINVAL`. |
| `EINVAL` | Already committed, or never bound to a source. <a id="cite-txn-ioctl.commit.einval-when-committed-or-unbound"></a> |
| `EBUSY` | The source could not take the write lock. The transaction stays `ACTIVE_BOUND`; retry. |
| `EIO` | The source failed to commit. The transaction stays `ACTIVE_BOUND`. |
| `ETIMEDOUT` | The transaction timed out before the commit completed. |

`EBUSY` and `EIO` both leave the transaction usable: the mutation log
is retained, no events are emitted, and poll waiters are not woken as
though it had become terminal. The caller retries or closes the fd to
abort.

<a id="trm-5-5-4-2"></a>

## `REG_IOC_TXN_STATUS`

Reports the transaction's state and a terminal errno into a
`reg_txn_status_args`. It reads nothing from the caller, consistent
with its `_IOR` direction, and can fail only with `EFAULT` on an
unwritable output pointer. <a id="cite-txn-ioctl.status.efault-is-the-only-failure"></a>

| State | `terminal_errno` |
|---|---|
| `REG_TXN_ACTIVE_UNBOUND` | 0 |
| `REG_TXN_ACTIVE_BOUND` | 0 |
| `REG_TXN_COMMITTED` | 0 |
| `REG_TXN_ABORTED` | `EINVAL` |
| `REG_TXN_TIMED_OUT` | `ETIMEDOUT` |
| `REG_TXN_SOURCE_DOWN` | `EIO` |

For the three failed terminal states, `terminal_errno` is the errno a
further operation on the fd would return. For `COMMITTED` it is not:
the transaction reports 0, but using the fd again returns `EINVAL`.

This ioctl is what makes a poll wakeup useful. A terminal transition
reports `POLLERR | POLLHUP`, which says only that *something*
terminal happened; the status call says what.

---

# Errors

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> How LCS reports failure, and the two errnos worth reading closely because they mean less than they appear to.

<a id="trm-5-5-5"></a>

Syscalls and ioctls follow the ordinary Linux convention: -1 and
`errno`. <a id="cite-errno.minus-one-and-errno"></a>

The errno is the whole interface — source-specific error
detail is never surfaced to a caller. <a id="cite-errno.no-source-detail-surfaced"></a>

| Errno | What it means here |
|---|---|
| `ENOENT` | A key or value does not exist after layer resolution; an enumeration index is past the end; a named layer is not in the layer table; a namespace operation on an orphaned key. |
| `EACCES` | AccessCheck denied a right, the fd's granted mask lacks it, or layer write authorization failed. |
| `EINVAL` | An invalid path or argument; a non-zero reserved or padding field; a zero or unknown-bit `desired_access`; an operation on a committed, aborted or closed transaction; a symlink target that is not `REG_LINK`; maximum key depth exceeded; delete or hide on a hive root. |
| `EFAULT` | An invalid userspace pointer. A zero-length output probe ignores its pointer; a non-zero length with a null or unwritable pointer does not. |
| `ENAMETOOLONG` | A key or value name exceeds `MaxPathComponentLength`, or a path exceeds `MaxTotalPathLength`. |
| `ELOOP` | The symlink resolution depth limit was exceeded. |
| `ETIMEDOUT` | The source did not answer within `RequestTimeoutMs`, or a timed-out transaction fd was used. |
| `EIO` | The source failed, is unavailable, returned malformed data, or a transaction's bound source went Down. |
| `ENOMEM` | Kernel allocation failure. |
| `ENOSPC` | A layer cap was exceeded, or value data exceeds `MaxValueSize`. |
| `ENOTEMPTY` | A key with visible children cannot be deleted. |
| `EXDEV` | An operation targeted a different hive from the one its transaction is bound to. |
| `EPERM` | A privilege the caller does not hold: symlink creation, creating or raising a layer above precedence 0, backup, restore. |
| `EAGAIN` | A conditional write failed — the layer entry's sequence did not match. Re-read and retry. |
| `EBUSY` | A commit could not take the source's write lock, or `MaxBoundTransactionsPerSource` or `MaxReadOnlyTransactionsPerSource` was exceeded. |
| `ERANGE` | An output buffer is too small. Every determinable required size is written; buffers are not partially filled. Retry with larger ones. |
| `EEXIST` | A path entry or key already exists at the source. |
| `ENOTSUP` | The source does not support the transaction mode being requested. |
| `EBADF` | An fd argument is not valid or not open in the required mode — a backup output fd that is not writable, a restore input fd that is not readable. |
| `EOVERFLOW` | A counter cannot advance: a source reported a persisted sequence number too large to allocate past, a hive generation saturated, restore sequence remapping would overflow, or transaction ids are exhausted. |
| `ESTALE` | A source re-registration tried to resume a Down slot with a mismatched hive identity. |

<a id="trm-5-5-5-1"></a>

## Two errnos worth reading closely

**`ETIMEDOUT` means "may or may not have happened."** If the deadline
expired before an in-flight RSI slot was reserved, no request was sent
at all. <a id="cite-errno.etimedout-before-dispatch-means-nothing-was-sent"></a> If it expired after dispatch, the source may still apply the
operation and answer later, and LCS will apply the kernel-side effects
when it does ([Failure and Late Responses](</kernel/internals/lcs/sources/failure-and-late-responses.md#trm-5-8-5>)). A caller that needs certainty checks state
before retrying. The same applies to a transaction commit.

**`EEXIST` is rarer than it looks.** It never comes out of
`reg_create_key`, which retries a losing race as an open ([Syscalls](</kernel/userspace/native/lcs/open-create-and-transaction-syscalls.md#trm-5-5-2>)). From
`REG_IOC_RESTORE` it arrives only by propagation: the source answers
`RSI_ALREADY_EXISTS` while the stream is being replayed. There is no
kernel-side pre-check that a non-root GUID in a backup already exists
outside the subtree being replaced, so a collision is detected during
the restore rather than before it — inside the restore transaction,
which then rolls back ([Restore](</kernel/internals/lcs/backup-and-restore/restore.md#trm-5-9-3>)). Its other source is source
registration, where a hive identity collides with an **Active** slot;
a collision with a Down slot yields `EINVAL` or `ESTALE` instead
([Registration and Slots](</kernel/internals/lcs/sources/registration-and-slots.md#trm-5-8-2>)).

---

# Generated syscall and common ABI

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Generated syscall and common ABI: behaviour and implementation of the Peios kernel.

<a id="trm-5-a"></a>

Every name, value, offset and size in this appendix is generated from
`include/uapi/pkm/lcs.h` by `tools/docs/peios-reference/generators/gen-lcs-abi.py`, with ioctl
encodings and struct layouts measured by compiling a probe against the
real header. Regenerate it whenever the ABI changes; do not edit it by
hand. The names here are the ones a program actually compiles against. <a id="cite-lcs-abi.generated-from-source"></a>

What a compiler cannot measure -- which properties belong with their
operations rather than here, and the kernel configuration -- is in the
notes appendix, [LCS ABI Notes](</kernel/userspace/native/lcs/file-descriptors-and-buffer-conventions.md#trm-5-b>), which this generator does not touch.

<a id="trm-5-a-1"></a>

## Syscall numbers <a id="cite-lcs-abi.syscall-numbers"></a>

Signatures are read from the `SYSCALL_DEFINE` sites in `security/pkm/lcs/`.
The PKM UAPI exports the uppercase constants in `<pkm/syscall.h>`. Peios
glibc 2.44-5 and later exports the standard lowercase `SYS_reg_*`
aliases in `<sys/syscall.h>`; each alias has the same number as its PKM
constant.

| Number | PKM constant | glibc alias | Signature |
|---|---|---|---|
| 1100 | `SYS_REG_OPEN_KEY` | `SYS_reg_open_key` | `reg_open_key(int parent_fd, const char __user *path, u32 desired_access, u32 flags)` |
| 1101 | `SYS_REG_CREATE_KEY` | `SYS_reg_create_key` | `reg_create_key(const struct reg_create_key_args __user *args)` |
| 1102 | `SYS_REG_BEGIN_TRANSACTION` | `SYS_reg_begin_transaction` | `reg_begin_transaction(void)` |
| 1103 | `SYS_REG_BEGIN_READ_TRANSACTION` | `SYS_reg_begin_read_transaction` | `reg_begin_read_transaction(void)` |
| 1104 | `SYS_REG_OPEN_KEY_TRANSACTED` | `SYS_reg_open_key_transacted` | `reg_open_key_transacted(int parent_fd, const char __user *path, u32 desired_access, u32 flags, int txn_fd)` |

<a id="trm-5-a-2"></a>

## Ioctls <a id="cite-lcs-abi.ioctl-numbers"></a>

The type byte is `'R'`. Ioctl number namespaces are per fd type, so
`REG_SRC_REGISTER` (number 0 on the source device) and
`REG_IOC_QUERY_VALUE` (number 0 on a key fd) do not collide: the
kernel dispatches on the fd's `file_operations`, not globally. The
encoded value is what `_IOC` produces from the direction, type byte,
number and argument size.

*Source device fd.*

| Ioctl | Number | Direction | Argument | Arg size | Encoded |
|---|---|---|---|---|---|
| `REG_SRC_REGISTER` | 0 | _IOW | `struct reg_src_register_args` | 24 | `0x40185200` |
| `REG_SRC_NEGOTIATE` | 1 | _IOWR | `struct reg_src_negotiate_args` | 16 | `0xC0105201` |
| `REG_SRC_REQUEST_CONTEXT` | 2 | _IOWR | `struct reg_src_request_context_args` | 40 | `0xC0285202` |
| `REG_SRC_RENEW` | 3 | _IOWR | `struct reg_src_renew_args` | 32 | `0xC0205203` |

*Key fd.*

| Ioctl | Number | Direction | Argument | Arg size | Encoded |
|---|---|---|---|---|---|
| `REG_IOC_QUERY_VALUE` | 0 | _IOWR | `struct reg_query_value_args` | 64 | `0xC0405200` |
| `REG_IOC_SET_VALUE` | 1 | _IOW | `struct reg_set_value_args` | 64 | `0x40405201` |
| `REG_IOC_DELETE_VALUE` | 2 | _IOW | `struct reg_delete_value_args` | 40 | `0x40285202` |
| `REG_IOC_BLANKET_TOMBSTONE` | 3 | _IOW | `struct reg_blanket_tombstone_args` | 24 | `0x40185203` |
| `REG_IOC_QUERY_VALUES_BATCH` | 4 | _IOWR | `struct reg_query_values_batch_args` | 24 | `0xC0185204` |
| `REG_IOC_ENUM_VALUES` | 5 | _IOWR | `struct reg_enum_value_args` | 40 | `0xC0285205` |
| `REG_IOC_ENUM_SUBKEYS` | 6 | _IOWR | `struct reg_enum_subkey_args` | 40 | `0xC0285206` |
| `REG_IOC_QUERY_KEY_INFO` | 7 | _IOWR | `struct reg_query_key_info_args` | 64 | `0xC0405207` |
| `REG_IOC_DELETE_KEY` | 8 | _IOW | `struct reg_delete_key_args` | 24 | `0x40185208` |
| `REG_IOC_HIDE_KEY` | 9 | _IOW | `struct reg_hide_key_args` | 24 | `0x40185209` |
| `REG_IOC_GET_SECURITY` | 10 | _IOWR | `struct reg_get_security_args` | 16 | `0xC010520A` |
| `REG_IOC_SET_SECURITY` | 11 | _IOW | `struct reg_set_security_args` | 24 | `0x4018520B` |
| `REG_IOC_NOTIFY` | 12 | _IOW | `struct reg_notify_args` | 8 | `0x4008520C` |
| `REG_IOC_FLUSH` | 13 | _IO | none | 0 | `0x0000520D` |
| `REG_IOC_BACKUP` | 14 | _IOW | `struct reg_backup_args` | 4 | `0x4004520E` |
| `REG_IOC_RESTORE` | 15 | _IOW | `struct reg_restore_args` | 4 | `0x4004520F` |
| `REG_IOC_QUERY_KEY_INFO_TRANSACTED` | 18 | _IOWR | `struct reg_read_transacted_args` | 16 | `0xC0105212` |
| `REG_IOC_GET_SECURITY_TRANSACTED` | 19 | _IOWR | `struct reg_read_transacted_args` | 16 | `0xC0105213` |

*Transaction fd.*

| Ioctl | Number | Direction | Argument | Arg size | Encoded |
|---|---|---|---|---|---|
| `REG_IOC_COMMIT` | 16 | _IO | none | 0 | `0x00005210` |
| `REG_IOC_TXN_STATUS` | 17 | _IOR | `struct reg_txn_status_args` | 8 | `0x80085211` |

<a id="trm-5-a-3"></a>

## Structure layouts

Offsets and sizes are measured, not declared. The header also defines
a `_SIZE` constant for each of these structures; the two agree by
construction, and a mismatch fails the build in `uapi/smoke_test.c`.

<a id="trm-5-a-4"></a>

## Constants

Grouped as the header groups them.

*Optional RSI lifetime extension, negotiated before REG_SRC_REGISTER. All timestamps use CLOCK_MONOTONIC nanoseconds. Zero lifetime means an operation-owned transaction with no independent lifetime limit. The session is unique to this open source fd, including across restarts.*

| Constant | Value |
|---|---|
| `REG_SRC_LIFETIME_VERSION` | `1` |

*Syscall and ioctl argument sizes (Kernel TRM section 5.A, LCS ABI).* <a id="cite-lcs-abi.argument-sizes"></a>

| Constant | Value |
|---|---|
| `REG_CREATE_KEY_ARGS_SIZE` | `48` |
| `REG_QUERY_VALUE_ARGS_SIZE` | `64` |
| `REG_SET_VALUE_ARGS_SIZE` | `64` |
| `REG_DELETE_VALUE_ARGS_SIZE` | `40` |
| `REG_BLANKET_TOMBSTONE_ARGS_SIZE` | `24` |
| `REG_QUERY_VALUES_BATCH_ARGS_SIZE` | `24` |
| `REG_ENUM_VALUE_ARGS_SIZE` | `40` |
| `REG_ENUM_SUBKEY_ARGS_SIZE` | `40` |
| `REG_QUERY_KEY_INFO_ARGS_SIZE` | `64` |
| `REG_READ_TRANSACTED_ARGS_SIZE` | `16` |
| `REG_DELETE_KEY_ARGS_SIZE` | `24` |
| `REG_HIDE_KEY_ARGS_SIZE` | `24` |
| `REG_GET_SECURITY_ARGS_SIZE` | `16` |
| `REG_SET_SECURITY_ARGS_SIZE` | `24` |
| `REG_NOTIFY_ARGS_SIZE` | `8` |
| `REG_BACKUP_ARGS_SIZE` | `4` |
| `REG_RESTORE_ARGS_SIZE` | `4` |
| `REG_TXN_STATUS_ARGS_SIZE` | `8` |
| `REG_SRC_NEGOTIATE_ARGS_SIZE` | `16` |
| `REG_SRC_REQUEST_CONTEXT_ARGS_SIZE` | `40` |
| `REG_SRC_RENEW_ARGS_SIZE` | `32` |
| `REG_SRC_REGISTER_ARGS_SIZE` | `24` |
| `REG_SRC_HIVE_ENTRY_SIZE` | `56` |

*Transaction state codes.* <a id="cite-lcs-abi.txn-state-codes"></a>

| Constant | Value |
|---|---|
| `REG_TXN_ACTIVE_UNBOUND` | `0` |
| `REG_TXN_ACTIVE_BOUND` | `1` |
| `REG_TXN_COMMITTED` | `2` |
| `REG_TXN_ABORTED` | `3` |
| `REG_TXN_TIMED_OUT` | `4` |
| `REG_TXN_SOURCE_DOWN` | `5` |

*Syscall flags and dispositions.* <a id="cite-lcs-abi.syscall-flags-and-dispositions"></a>

| Constant | Value |
|---|---|
| `REG_OPEN_LINK` | `0x01` |
| `REG_OPTION_VOLATILE` | `0x01` |
| `REG_OPTION_CREATE_LINK` | `0x02` |
| `REG_CREATED_NEW` | `1` |
| `REG_OPENED_EXISTING` | `2` |

*Registry key access rights.* <a id="cite-lcs-abi.key-access-rights"></a>

| Constant | Value |
|---|---|
| `KEY_QUERY_VALUE` | `0x00000001` |
| `KEY_SET_VALUE` | `0x00000002` |
| `KEY_CREATE_SUB_KEY` | `0x00000004` |
| `KEY_ENUMERATE_SUB_KEYS` | `0x00000008` |
| `KEY_NOTIFY` | `0x00000010` |
| `KEY_CREATE_LINK` | `0x00000020` |
| `DELETE` | `0x00010000` |
| `READ_CONTROL` | `0x00020000` |
| `WRITE_DAC` | `0x00040000` |
| `WRITE_OWNER` | `0x00080000` |
| `ACCESS_SYSTEM_SECURITY` | `0x01000000` |
| `MAXIMUM_ALLOWED` | `0x02000000` |
| `GENERIC_ALL` | `0x10000000` |
| `GENERIC_EXECUTE` | `0x20000000` |
| `GENERIC_WRITE` | `0x40000000` |
| `GENERIC_READ` | `0x80000000` |
| `KEY_READ` | `0x00020019` |
| `KEY_WRITE` | `0x00020006` |
| `KEY_ALL_ACCESS` | `0x000F003F` |
| `REG_VALID_DESIRED_ACCESS_MASK` | `0xF30F003F` |
| `REG_VALID_MAPPED_ACCESS_MASK` | `0x010F003F` |
| `REG_VALID_ACE_ACCESS_MASK` | `0xF10F003F` |

*Security information flags for REG_IOC_GET_SECURITY / SET_SECURITY.* <a id="cite-lcs-abi.security-information-flags"></a>

| Constant | Value |
|---|---|
| `OWNER_SECURITY_INFORMATION` | `0x00000001` |
| `GROUP_SECURITY_INFORMATION` | `0x00000002` |
| `DACL_SECURITY_INFORMATION` | `0x00000004` |
| `SACL_SECURITY_INFORMATION` | `0x00000008` |
| `LABEL_SECURITY_INFORMATION` | `0x00000010` |
| `REG_VALID_SECURITY_INFORMATION` | `0x0000001F` |

*Registry value types.* <a id="cite-lcs-abi.value-types"></a>

| Constant | Value |
|---|---|
| `REG_NONE` | `0` |
| `REG_SZ` | `1` |
| `REG_EXPAND_SZ` | `2` |
| `REG_BINARY` | `3` |
| `REG_DWORD` | `4` |
| `REG_DWORD_BIG_ENDIAN` | `5` |
| `REG_LINK` | `6` |
| `REG_MULTI_SZ` | `7` |
| `REG_RESOURCE_LIST` | `8` |
| `REG_FULL_RESOURCE_DESCRIPTOR` | `9` |
| `REG_RESOURCE_REQUIREMENTS_LIST` | `10` |
| `REG_QWORD` | `11` |
| `REG_TOMBSTONE` | `0xFFFF` |

*Watch event types and filters.* <a id="cite-lcs-abi.watch-event-types-and-filters"></a>

| Constant | Value |
|---|---|
| `REG_WATCH_VALUE_SET` | `1` |
| `REG_WATCH_VALUE_DELETED` | `2` |
| `REG_WATCH_SUBKEY_CREATED` | `3` |
| `REG_WATCH_SUBKEY_DELETED` | `4` |
| `REG_WATCH_SD_CHANGED` | `5` |
| `REG_WATCH_KEY_DELETED` | `6` |
| `REG_WATCH_OVERFLOW` | `7` |

*Watch event raw byte layout.* <a id="cite-lcs-abi.watch-record-layout"></a>

| Constant | Value |
|---|---|
| `REG_WATCH_EVENT_TOTAL_LEN_OFFSET` | `0` |
| `REG_WATCH_EVENT_TYPE_OFFSET` | `4` |
| `REG_WATCH_EVENT_NAME_LEN_OFFSET` | `6` |
| `REG_WATCH_EVENT_NAME_OFFSET` | `8` |
| `REG_WATCH_EVENT_MIN_SIZE` | `8` |
| `REG_WATCH_SUBTREE_PATH_DEPTH_REL_OFFSET` | `0` |
| `REG_WATCH_SUBTREE_PATH_DEPTH_SIZE` | `2` |
| `REG_WATCH_SUBTREE_PATH_COMPONENTS_REL_OFFSET` | `2` |
| `REG_WATCH_PATH_COMPONENT_LEN_SIZE` | `2` |
| `REG_NOTIFY_VALUE` | `0x01` |
| `REG_NOTIFY_SUBKEY` | `0x02` |
| `REG_NOTIFY_SD` | `0x04` |
| `REG_NOTIFY_ALL` | `0x07` |

*RSI common wire layout.* <a id="cite-lcs-abi.rsi-wire-layout"></a>

| Constant | Value |
|---|---|
| `RSI_REQUEST_TOTAL_LEN_OFFSET` | `0` |
| `RSI_REQUEST_ID_OFFSET` | `4` |
| `RSI_REQUEST_OP_CODE_OFFSET` | `12` |
| `RSI_REQUEST_TXN_ID_OFFSET` | `14` |
| `RSI_REQUEST_HEADER_SIZE` | `22` |
| `RSI_RESPONSE_TOTAL_LEN_OFFSET` | `0` |
| `RSI_RESPONSE_ID_OFFSET` | `4` |
| `RSI_RESPONSE_OP_CODE_OFFSET` | `12` |
| `RSI_RESPONSE_HEADER_SIZE` | `14` |
| `RSI_RESPONSE_STATUS_OFFSET` | `14` |
| `RSI_STATUS_SIZE` | `4` |
| `RSI_MIN_RESPONSE_SIZE` | `18` |
| `RSI_LENGTH_PREFIX_SIZE` | `4` |
| `RSI_GUID_SIZE` | `16` |
| `RSI_RESPONSE_BIT` | `0x8000` |

*RSI op codes and response op codes.* <a id="cite-lcs-abi.rsi-op-codes"></a>

| Constant | Value |
|---|---|
| `RSI_LOOKUP` | `0x0001` |
| `RSI_CREATE_ENTRY` | `0x0002` |
| `RSI_HIDE_ENTRY` | `0x0003` |
| `RSI_DELETE_ENTRY` | `0x0004` |
| `RSI_ENUM_CHILDREN` | `0x0005` |
| `RSI_CREATE_KEY` | `0x0010` |
| `RSI_READ_KEY` | `0x0011` |
| `RSI_WRITE_KEY` | `0x0012` |
| `RSI_DROP_KEY` | `0x0013` |
| `RSI_QUERY_VALUES` | `0x0020` |
| `RSI_SET_VALUE` | `0x0021` |
| `RSI_DELETE_VALUE_ENTRY` | `0x0022` |
| `RSI_SET_BLANKET_TOMBSTONE` | `0x0023` |
| `RSI_BEGIN_TRANSACTION` | `0x0030` |
| `RSI_COMMIT_TRANSACTION` | `0x0031` |
| `RSI_ABORT_TRANSACTION` | `0x0032` |
| `RSI_FLUSH` | `0x0040` |
| `RSI_DELETE_LAYER` | `0x0050` |
| `RSI_LOOKUP_RESPONSE` | `0x8001` |
| `RSI_CREATE_ENTRY_RESPONSE` | `0x8002` |
| `RSI_HIDE_ENTRY_RESPONSE` | `0x8003` |
| `RSI_DELETE_ENTRY_RESPONSE` | `0x8004` |
| `RSI_ENUM_CHILDREN_RESPONSE` | `0x8005` |
| `RSI_CREATE_KEY_RESPONSE` | `0x8010` |
| `RSI_READ_KEY_RESPONSE` | `0x8011` |
| `RSI_WRITE_KEY_RESPONSE` | `0x8012` |
| `RSI_DROP_KEY_RESPONSE` | `0x8013` |
| `RSI_QUERY_VALUES_RESPONSE` | `0x8020` |
| `RSI_SET_VALUE_RESPONSE` | `0x8021` |
| `RSI_DELETE_VALUE_ENTRY_RESPONSE` | `0x8022` |
| `RSI_SET_BLANKET_TOMBSTONE_RESPONSE` | `0x8023` |
| `RSI_BEGIN_TRANSACTION_RESPONSE` | `0x8030` |
| `RSI_COMMIT_TRANSACTION_RESPONSE` | `0x8031` |
| `RSI_ABORT_TRANSACTION_RESPONSE` | `0x8032` |
| `RSI_FLUSH_RESPONSE` | `0x8040` |
| `RSI_DELETE_LAYER_RESPONSE` | `0x8050` |

*RSI status codes.* <a id="cite-lcs-abi.rsi-status-codes"></a>

| Constant | Value |
|---|---|
| `RSI_OK` | `0` |
| `RSI_NOT_FOUND` | `1` |
| `RSI_ALREADY_EXISTS` | `2` |
| `RSI_STORAGE_ERROR` | `3` |
| `RSI_NOT_EMPTY` | `4` |
| `RSI_TOO_LARGE` | `5` |
| `RSI_TXN_BUSY` | `6` |
| `RSI_INVALID` | `7` |
| `RSI_CAS_FAILED` | `8` |
| `RSI_TXN_NOT_SUPPORTED` | `9` |

*RSI path target types.* <a id="cite-lcs-abi.rsi-path-target-types"></a>

| Constant | Value |
|---|---|
| `RSI_PATH_TARGET_GUID` | `0` |
| `RSI_PATH_TARGET_HIDDEN` | `1` |

*RSI_WRITE_KEY field mask bits.* <a id="cite-lcs-abi.rsi-write-key-field-mask"></a>

| Constant | Value |
|---|---|
| `RSI_WRITE_KEY_FIELD_SD` | `0x01` |
| `RSI_WRITE_KEY_FIELD_LAST_WRITE_TIME` | `0x02` |
| `RSI_WRITE_KEY_FIELD_KNOWN_MASK` | `0x00000003` |

*RSI transaction modes and source-registration flags.* <a id="cite-lcs-abi.rsi-txn-modes-and-registration-flags"></a>

| Constant | Value |
|---|---|
| `RSI_TXN_READ_WRITE` | `0` |
| `RSI_TXN_READ_ONLY` | `1` |
| `RSI_HIVE_PRIVATE` | `0x01` |

*Backup record types and magic.* <a id="cite-lcs-abi.backup-record-types"></a>

| Constant | Value |
|---|---|
| `REG_BACKUP_HEADER` | `0x01` |
| `REG_BACKUP_LAYER` | `0x02` |
| `REG_BACKUP_KEY` | `0x03` |
| `REG_BACKUP_PATH_ENTRY` | `0x04` |
| `REG_BACKUP_VALUE` | `0x05` |
| `REG_BACKUP_BLANKET_TOMBSTONE` | `0x06` |
| `REG_BACKUP_TRAILER` | `0xFF` |
| `REG_BACKUP_MAGIC` | `"PEIOSREG"` |

## Related explanations

- [Generated key and security ABI](</kernel/userspace/native/lcs/generated-key-and-security-abi.md>)
- [Generated watch ABI](</kernel/userspace/native/lcs/generated-watch-abi.md>)
- [Generated transaction and backup ABI](</kernel/userspace/native/lcs/generated-transaction-and-backup-abi.md>)
- [Generated source and diagnostic ABI](</kernel/userspace/native/lcs/generated-source-and-diagnostic-abi.md>)

---

# Generated key and security ABI

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Generated key and security ABI: behaviour and implementation of the Peios kernel.

<a id="trm-5-a-3-1"></a>

## `struct reg_create_key_args` <a id="cite-lcs-abi.struct-reg-create-key-args"></a>

Total size 48 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__s32` | `parent_fd` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `path_ptr` |
| 16 | 4 | `__u32` | `desired_access` |
| 20 | 4 | `__u32` | `flags` |
| 24 | 8 | `__u64` | `layer_ptr` |
| 32 | 4 | `__s32` | `txn_fd` |
| 36 | 4 | `__u32` | `_pad1` |
| 40 | 8 | `__u64` | `disposition_ptr` |

<a id="trm-5-a-3-2"></a>

## `struct reg_query_value_args` <a id="cite-lcs-abi.struct-reg-query-value-args"></a>

Total size 64 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `name_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 4 | `__u32` | `type` |
| 20 | 4 | `__u32` | `data_len` |
| 24 | 4 | `__s32` | `txn_fd` |
| 28 | 4 | `__u32` | `layer_buf_len` |
| 32 | 8 | `__u64` | `data_ptr` |
| 40 | 8 | `__u64` | `sequence` |
| 48 | 4 | `__u32` | `layer_len` |
| 52 | 4 | `__u32` | `_pad1` |
| 56 | 8 | `__u64` | `layer_ptr` |

<a id="trm-5-a-3-3"></a>

## `struct reg_set_value_args` <a id="cite-lcs-abi.struct-reg-set-value-args"></a>

Total size 64 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `name_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 4 | `__u32` | `type` |
| 20 | 4 | `__u32` | `data_len` |
| 24 | 8 | `__u64` | `data_ptr` |
| 32 | 4 | `__u32` | `layer_len` |
| 36 | 4 | `__u32` | `_pad1` |
| 40 | 8 | `__u64` | `layer_ptr` |
| 48 | 4 | `__s32` | `txn_fd` |
| 52 | 4 | `__u32` | `_pad2` |
| 56 | 8 | `__u64` | `expected_seq` |

<a id="trm-5-a-3-4"></a>

## `struct reg_delete_value_args` <a id="cite-lcs-abi.struct-reg-delete-value-args"></a>

Total size 40 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `name_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 4 | `__u32` | `layer_len` |
| 20 | 4 | `__u32` | `_pad1` |
| 24 | 8 | `__u64` | `layer_ptr` |
| 32 | 4 | `__s32` | `txn_fd` |
| 36 | 4 | `__u32` | `_pad2` |

<a id="trm-5-a-3-5"></a>

## `struct reg_blanket_tombstone_args` <a id="cite-lcs-abi.struct-reg-blanket-tombstone-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `layer_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `layer_ptr` |
| 16 | 1 | `__u8` | `set` |
| 17 | 3 | `__u8``[3]` | `_pad1` |
| 20 | 4 | `__s32` | `txn_fd` |

<a id="trm-5-a-3-6"></a>

## `struct reg_query_values_batch_args` <a id="cite-lcs-abi.struct-reg-query-values-batch-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `buf_len` |
| 4 | 4 | `__u32` | `count` |
| 8 | 8 | `__u64` | `buf_ptr` |
| 16 | 4 | `__s32` | `txn_fd` |
| 20 | 4 | `__u32` | `_pad` |

<a id="trm-5-a-3-7"></a>

## `struct reg_enum_value_args` <a id="cite-lcs-abi.struct-reg-enum-value-args"></a>

Total size 40 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `index` |
| 4 | 4 | `__u32` | `name_len` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 4 | `__u32` | `type` |
| 20 | 4 | `__u32` | `data_len` |
| 24 | 8 | `__u64` | `data_ptr` |
| 32 | 4 | `__s32` | `txn_fd` |
| 36 | 4 | `__u32` | `_pad` |

<a id="trm-5-a-3-8"></a>

## `struct reg_enum_subkey_args` <a id="cite-lcs-abi.struct-reg-enum-subkey-args"></a>

Total size 40 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `index` |
| 4 | 4 | `__u32` | `name_len` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 8 | `__u64` | `last_write_time` |
| 24 | 4 | `__u32` | `subkey_count` |
| 28 | 4 | `__u32` | `value_count` |
| 32 | 4 | `__s32` | `txn_fd` |
| 36 | 4 | `__u32` | `_pad` |

<a id="trm-5-a-3-9"></a>

## `struct reg_query_key_info_args` <a id="cite-lcs-abi.struct-reg-query-key-info-args"></a>

Total size 64 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `name_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 8 | `__u64` | `last_write_time` |
| 24 | 4 | `__u32` | `subkey_count` |
| 28 | 4 | `__u32` | `value_count` |
| 32 | 4 | `__u32` | `max_subkey_name_len` |
| 36 | 4 | `__u32` | `max_value_name_len` |
| 40 | 4 | `__u32` | `max_value_data_size` |
| 44 | 4 | `__u32` | `sd_size` |
| 48 | 1 | `__u8` | `volatile_key` |
| 49 | 1 | `__u8` | `symlink` |
| 50 | 6 | `__u8``[6]` | `_pad1` |
| 56 | 8 | `__u64` | `hive_generation` |

<a id="trm-5-a-3-10"></a>

## `struct reg_delete_key_args` <a id="cite-lcs-abi.struct-reg-delete-key-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `layer_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `layer_ptr` |
| 16 | 4 | `__s32` | `txn_fd` |
| 20 | 4 | `__u32` | `_pad1` |

<a id="trm-5-a-3-11"></a>

## `struct reg_hide_key_args` <a id="cite-lcs-abi.struct-reg-hide-key-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `layer_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `layer_ptr` |
| 16 | 4 | `__s32` | `txn_fd` |
| 20 | 4 | `__u32` | `_pad1` |

<a id="trm-5-a-3-12"></a>

## `struct reg_get_security_args` <a id="cite-lcs-abi.struct-reg-get-security-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `security_info` |
| 4 | 4 | `__u32` | `sd_len` |
| 8 | 8 | `__u64` | `sd_ptr` |

<a id="trm-5-a-3-13"></a>

## `struct reg_set_security_args` <a id="cite-lcs-abi.struct-reg-set-security-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `security_info` |
| 4 | 4 | `__u32` | `sd_len` |
| 8 | 8 | `__u64` | `sd_ptr` |
| 16 | 4 | `__s32` | `txn_fd` |
| 20 | 4 | `__u32` | `_pad` |

<a id="trm-5-a-3-23"></a>

## `struct reg_read_transacted_args` <a id="cite-lcs-abi.struct-reg-read-transacted-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `args_ptr` |
| 8 | 4 | `__s32` | `txn_fd` |
| 12 | 4 | `__u32` | `_pad` |

---

# Generated watch ABI

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Generated watch ABI: behaviour and implementation of the Peios kernel.

<a id="trm-5-a-3-14"></a>

## `struct reg_notify_args` <a id="cite-lcs-abi.struct-reg-notify-args"></a>

Total size 8 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `filter` |
| 4 | 1 | `__u8` | `subtree` |
| 5 | 3 | `__u8``[3]` | `_pad` |

---

# Generated transaction and backup ABI

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Generated transaction and backup ABI: behaviour and implementation of the Peios kernel.

<a id="trm-5-a-3-15"></a>

## `struct reg_backup_args` <a id="cite-lcs-abi.struct-reg-backup-args"></a>

Total size 4 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__s32` | `output_fd` |

<a id="trm-5-a-3-16"></a>

## `struct reg_restore_args` <a id="cite-lcs-abi.struct-reg-restore-args"></a>

Total size 4 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__s32` | `input_fd` |

<a id="trm-5-a-3-17"></a>

## `struct reg_txn_status_args` <a id="cite-lcs-abi.struct-reg-txn-status-args"></a>

Total size 8 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `state` |
| 4 | 4 | `__s32` | `terminal_errno` |

---

# Generated source and diagnostic ABI

_Peios Kernel / Userspace interfaces / Native interfaces / LCS_

> Generated source and diagnostic ABI: behaviour and implementation of the Peios kernel.

<a id="trm-5-a-3-18"></a>

## `struct reg_src_register_args` <a id="cite-lcs-abi.struct-reg-src-register-args"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `hive_count` |
| 4 | 4 | `__u32` | `_pad` |
| 8 | 8 | `__u64` | `max_sequence` |
| 16 | 8 | `__u64` | `hives_ptr` |

<a id="trm-5-a-3-19"></a>

## `struct reg_src_negotiate_args` <a id="cite-lcs-abi.struct-reg-src-negotiate-args"></a>

Total size 16 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `version` |
| 4 | 4 | `__u32` | `flags` |
| 8 | 8 | `__u64` | `session` |

<a id="trm-5-a-3-20"></a>

## `struct reg_src_request_context_args` <a id="cite-lcs-abi.struct-reg-src-request-context-args"></a>

Total size 40 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `session` |
| 8 | 8 | `__u64` | `request_id` |
| 16 | 8 | `__u64` | `request_deadline_ns` |
| 24 | 8 | `__u64` | `lifetime_deadline_ns` |
| 32 | 8 | `__u64` | `lease_deadline_ns` |

<a id="trm-5-a-3-21"></a>

## `struct reg_src_renew_args` <a id="cite-lcs-abi.struct-reg-src-renew-args"></a>

Total size 32 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `session` |
| 8 | 8 | `__u64` | `transaction_id` |
| 16 | 8 | `__u64` | `lifetime_deadline_ns` |
| 24 | 8 | `__u64` | `lease_deadline_ns` |

<a id="trm-5-a-3-22"></a>

## `struct reg_src_hive_entry` <a id="cite-lcs-abi.struct-reg-src-hive-entry"></a>

Total size 56 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `name_len` |
| 4 | 4 | `__u32` | `_pad0` |
| 8 | 8 | `__u64` | `name_ptr` |
| 16 | 16 | `__u8``[16]` | `root_guid` |
| 32 | 4 | `__u32` | `flags` |
| 36 | 4 | `__u32` | `_pad1` |
| 40 | 16 | `__u8``[16]` | `scope_guid` |

<a id="trm-5-a-5"></a>

## Tracepoint diagnostic codes

From `uapi/pkm/trace.h`. These are a diagnostic contract for
ftrace, perf and eBPF consumers, letting a tool decode an `lcs:`
event's `reason`, `op` or `state` field without recompiling
against a specific kernel. No LCS syscall accepts or returns
them, and values are append-only.

lcs_rsi_request op — which of the 18 RSI dispatch verbs a source-side
request admission record describes. Emitted by lcs:lcs_rsi_request on
successful queue admission and on the admission error rungs; the rung is
read from `ret` (0 == enqueued, -EAGAIN == in-flight at limit /
backpressure, -EIO == source gone / fd closing, -EOVERFLOW == request-id
space exhausted, other == build reject). The same op enum tags the
round-trip begin marker (lcs_rsi_roundtrip). Never records a pathname,
key name, GUID, or frame bytes — only this op code, ids, counts and ret. <a id="cite-lcs-abi.trace.rsi-request-ops"></a>

| Constant | Value | Notes |
|---|---|---|
| `LCS_OP_LOOKUP` | `0` | RSI_LOOKUP |
| `LCS_OP_READ_KEY` | `1` | RSI_READ_KEY |
| `LCS_OP_ENUM_CHILDREN` | `2` | RSI_ENUM_CHILDREN |
| `LCS_OP_QUERY_VALUES` | `3` | RSI_QUERY_VALUES |
| `LCS_OP_SET_VALUE` | `4` | RSI_SET_VALUE |
| `LCS_OP_DELETE_VALUE` | `5` | RSI_DELETE_VALUE_ENTRY |
| `LCS_OP_BLANKET_TOMBSTONE` | `6` | RSI_SET_BLANKET_TOMBSTONE |
| `LCS_OP_DROP_KEY` | `7` | RSI_DROP_KEY |
| `LCS_OP_CREATE_ENTRY` | `8` | RSI_CREATE_ENTRY |
| `LCS_OP_HIDE_ENTRY` | `9` | RSI_HIDE_ENTRY |
| `LCS_OP_DELETE_ENTRY` | `10` | RSI_DELETE_ENTRY |
| `LCS_OP_CREATE_KEY` | `11` | RSI_CREATE_KEY |
| `LCS_OP_WRITE_KEY` | `12` | RSI_WRITE_KEY |
| `LCS_OP_TXN_BEGIN` | `13` | RSI_BEGIN_TRANSACTION |
| `LCS_OP_TXN_COMMIT` | `14` | RSI_COMMIT_TRANSACTION |
| `LCS_OP_TXN_ABORT` | `15` | RSI_ABORT_TRANSACTION |
| `LCS_OP_FLUSH` | `16` | RSI_FLUSH |
| `LCS_OP_DELETE_LAYER` | `17` | RSI_DELETE_LAYER |

lcs_rsi_response reason — the outcome of accepting/validating a source's
RSI response frame, and the late-response effects that silently mark a
source DOWN. ACCEPTED is the clean path; DESYNC / OP_MISMATCH /
UNKNOWN_STATUS are the accept-time rejects that all surface as
-EINVAL/-EIO; MALFORMED_PAYLOAD is a per-op body validation reject; the
LATE_* codes mark a response whose deferred effect
(commit/mutation/begin bookkeeping) failed and took the source DOWN.
Verdict/outcome is also in `ret`. Never records name/GUID/frame bytes. <a id="cite-lcs-abi.trace.rsi-response-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `LCS_RESP_ACCEPTED` | `0` | response matched an in-flight request |
| `LCS_RESP_DESYNC` | `1` | no matching delivered/unaccepted record |
| `LCS_RESP_OP_MISMATCH` | `2` | response op != request op \| RESPONSE_BIT |
| `LCS_RESP_UNKNOWN_STATUS` | `3` | rsi_status not a known status code |
| `LCS_RESP_MALFORMED_PAYLOAD` | `4` | per-op response body failed validation |
| `LCS_RESP_LATE_COMMIT_FAIL` | `5` | commit late-effect failed; source DOWN |
| `LCS_RESP_LATE_MUTATION_FAIL` | `6` | mutation late-effect failed; source DOWN |
| `LCS_RESP_LATE_BEGIN_FAIL` | `7` | begin-txn late-effect failed; source DOWN |

*lcs_source_fd reason — which source-fd lifecycle transition a record marks.* <a id="cite-lcs-abi.trace.source-fd-reasons"></a>

OPEN is a fresh /dev/pkm_registry fd; the remaining codes are the entry
points that drive a source to the DOWN/closing state. `source_down_id`
is the source id that transitioned DOWN (0 if the call was a no-op). The
semantic *cause* of a late-effect-driven DOWN is carried by
lcs_rsi_response (LCS_RESP_LATE_*); here EXPLICIT/MARK_BY_ID are the
mechanical transitions. No pathname/SD bytes.

| Constant | Value | Notes |
|---|---|---|
| `LCS_SRC_OPEN` | `0` | new source fd issued (post-TCB check) |
| `LCS_SRC_RELEASE` | `1` | fd .release() teardown |
| `LCS_SRC_MALFORMED` | `2` | malformed protocol frame -> mark down |
| `LCS_SRC_EXPLICIT` | `3` | explicit mark-down of this fd |
| `LCS_SRC_MARK_BY_ID` | `4` | mark-down requested by source id |

lcs_in_flight reason — an in-flight RSI request table transition (kept
lean; insert on admission, delivered when handed to the source's read(),
release on response completion or teardown). `in_flight_count` is the
post-transition depth. Emitted by lcs:lcs_in_flight. <a id="cite-lcs-abi.trace.in-flight-reasons"></a>

| Constant | Value | Notes |
|---|---|---|
| `LCS_IF_INSERT` | `0` | request inserted into in-flight table |
| `LCS_IF_DELIVERED` | `1` | request delivered to source read() |
| `LCS_IF_RELEASE` | `2` | request released from in-flight table |

*lcs_route op — which resolution the lcs:lcs_route event describes.* <a id="cite-lcs-abi.trace.route-ops"></a>

| Constant | Value | Notes |
|---|---|---|
| `LCS_ROUTE_HIVE_NAME` | `0` | hive-name -> source/root resolution |
| `LCS_ROUTE_ABSOLUTE_PATH` | `1` | absolute-path -> source/root resolution |
| `LCS_ROUTE_SYMLINK_TARGET` | `2` | symlink-target -> source/root resolution |

*lcs_registration decision — the source registration path.* <a id="cite-lcs-abi.trace.registration-decisions"></a>

NEW/RESUME_DOWN are publish verdicts; COPY is the input-copy stage;
REPLAY_FAIL/OVERFLOW_FAIL are resume post-publish -EIO paths that mark
the resumed source down. Emitted by lcs:lcs_source_register /
_registration_publish / _registration_copy.

| Constant | Value | Notes |
|---|---|---|
| `LCS_REG_NEW` | `0` | new source slot admitted |
| `LCS_REG_RESUME_DOWN` | `1` | down source slot resumed |
| `LCS_REG_COPY` | `2` | registration input copied from user |
| `LCS_REG_REPLAY_FAIL` | `3` | resume pending-delete replay failed (EIO) |
| `LCS_REG_OVERFLOW_FAIL` | `4` | resume overflow dispatch failed (EIO) |

*lcs_bootstrap stage — the phase of a bootstrap / self-config refresh.* <a id="cite-lcs-abi.trace.bootstrap-stages"></a>

Emitted by lcs:lcs_bootstrap_refresh / _self_config_refresh /
_self_config_publish.

| Constant | Value | Notes |
|---|---|---|
| `LCS_BOOT_REGISTRY` | `0` | registry root discover phase |
| `LCS_BOOT_KMES` | `1` | kmes config root discover phase |
| `LCS_BOOT_LAYERS` | `2` | layer metadata root discover phase |
| `LCS_BOOT_SELF_WATCH` | `3` | self-watch arm phase |
| `LCS_BOOT_COMPLETE` | `4` | bootstrap refresh completed |
| `LCS_BOOT_SELF_CONFIG_REFRESH` | `5` | self-config refresh-from-key outcome |
| `LCS_BOOT_SELF_CONFIG_PARAM_INVALID` | `6` | self-config publish rejected a parameter |

lcs_runtime_limits field_id — which runtime-limit field a validate
reject names, or LCS_LIM_ALL for a successful whole-struct publish.
Emitted by lcs:lcs_limits_validate (-EINVAL, `value` offending) and
lcs:lcs_limits_publish. <a id="cite-lcs-abi.trace.runtime-limit-fields"></a>

| Constant | Value | Notes |
|---|---|---|
| `LCS_LIM_REQUEST_TIMEOUT_MS` | `0` |  |
| `LCS_LIM_TRANSACTION_TIMEOUT_MS` | `1` |  |
| `LCS_LIM_NOTIFICATION_QUEUE_SIZE` | `2` |  |
| `LCS_LIM_SYMLINK_DEPTH_LIMIT` | `3` |  |
| `LCS_LIM_MAX_VALUE_SIZE` | `4` |  |
| `LCS_LIM_MAX_KEY_DEPTH` | `5` |  |
| `LCS_LIM_MAX_PATH_COMPONENT_LENGTH` | `6` |  |
| `LCS_LIM_MAX_TOTAL_PATH_LENGTH` | `7` |  |
| `LCS_LIM_MAX_LAYERS_PER_VALUE` | `8` |  |
| `LCS_LIM_MAX_BOUND_TRANSACTIONS_PER_SOURCE` | `9` |  |
| `LCS_LIM_MAX_READ_ONLY_TRANSACTIONS_PER_SOURCE` | `10` |  |
| `LCS_LIM_MAX_TOTAL_LAYERS` | `11` |  |
| `LCS_LIM_MAX_REGISTERED_SOURCES` | `12` |  |
| `LCS_LIM_MAX_HIVES_PER_SOURCE` | `13` |  |
| `LCS_LIM_MAX_CONCURRENT_RSI_REQUESTS` | `14` |  |
| `LCS_LIM_MAX_SCOPE_GUIDS_PER_TOKEN` | `15` |  |
| `LCS_LIM_MAX_PRIVATE_LAYERS_PER_TOKEN` | `16` |  |
| `LCS_LIM_MAX_SUBTREE_WATCH_DEPTH` | `17` |  |
| `LCS_LIM_MAX_TRANSACTION_WATCH_EVENT_BURST` | `18` |  |
| `LCS_LIM_ALL` | `19` | whole-struct publish (success) |

*lcs_audit event_type_id — which LCS audit event a record describes.* <a id="cite-lcs-abi.trace.audit-event-types"></a>

Emitted by lcs:lcs_audit_emit and lcs:lcs_audit_emit_failed.
`result_errno` carries the op-specific numeric. No SD or raw GUID bytes;
key GUID is a u64 hash.

| Constant | Value | Notes |
|---|---|---|
| `LCS_AUDIT_KEY_OPEN` | `0` | key-open SACL audit |
| `LCS_AUDIT_BACKUP_START` | `1` |  |
| `LCS_AUDIT_BACKUP_COMPLETE` | `2` |  |
| `LCS_AUDIT_RESTORE_START` | `3` |  |
| `LCS_AUDIT_RESTORE_COMPLETE` | `4` |  |
| `LCS_AUDIT_VALIDATION_FAILURE` | `5` | source validation-failure audit |
| `LCS_AUDIT_SELF_CONFIG_INVALID` | `6` | self-config-invalid audit |

*lcs_txn state — the transaction-fd state machine state carried in old_state new_state.* <a id="cite-lcs-abi.trace.txn-states"></a>

Emitted by lcs:lcs_txn_begin / _first_bind / _bind_mutation _commit /
_abort / _timeout / _source_down.

| Constant | Value | Notes |
|---|---|---|
| `LCS_TXN_ST_ACTIVE_UNBOUND` | `0` | allocated, not yet source-bound |
| `LCS_TXN_ST_ACTIVE_BOUND` | `1` | bound to a source + root guid |
| `LCS_TXN_ST_COMMITTED` | `2` | commit round-trip succeeded |
| `LCS_TXN_ST_ABORTED` | `3` | aborted (close / layer writer abort) |
| `LCS_TXN_ST_TIMED_OUT` | `4` | deadline timer or commit timeout |
| `LCS_TXN_ST_SOURCE_DOWN` | `5` | bound source marked down |

*lcs_key_fd cmd — the key-fd ioctl verb (also stamped on lcs_key_mutation).* <a id="cite-lcs-abi.trace.key-fd-cmds"></a>

LCS_KCMD_NONE is used by publish/release/read. Never records key/name/SD
bytes. Emitted by lcs:lcs_key_ioctl / _mutation.

| Constant | Value | Notes |
|---|---|---|
| `LCS_KCMD_NONE` | `0` | no ioctl verb (publish/release/read) |
| `LCS_KCMD_SET_VALUE` | `1` |  |
| `LCS_KCMD_DELETE_VALUE` | `2` |  |
| `LCS_KCMD_BLANKET_TOMBSTONE` | `3` |  |
| `LCS_KCMD_DELETE_KEY` | `4` |  |
| `LCS_KCMD_HIDE_KEY` | `5` |  |
| `LCS_KCMD_QUERY_VALUE` | `6` |  |
| `LCS_KCMD_QUERY_VALUES_BATCH` | `7` |  |
| `LCS_KCMD_ENUM_VALUES` | `8` |  |
| `LCS_KCMD_ENUM_SUBKEYS` | `9` |  |
| `LCS_KCMD_QUERY_KEY_INFO` | `10` |  |
| `LCS_KCMD_GET_SECURITY` | `11` |  |
| `LCS_KCMD_SET_SECURITY` | `12` |  |
| `LCS_KCMD_FLUSH` | `13` |  |
| `LCS_KCMD_BACKUP` | `14` |  |
| `LCS_KCMD_RESTORE` | `15` |  |
| `LCS_KCMD_NOTIFY` | `16` |  |

---

# NTFE

_Peios Kernel / Userspace interfaces / Native interfaces / NTFE_

> Find the Peios kernel articles about ntfe.

Use these articles to understand ntfe in the Peios kernel.

- [Event records and status semantics](</kernel/userspace/native/ntfe/event-records-and-status-semantics.md>)
- [Generated device ABI](</kernel/userspace/native/ntfe/generated-device-abi.md>)
- [Device operations and errors](</kernel/userspace/native/ntfe/device-operations-and-errors.md>)

---

# Event records and status semantics

_Peios Kernel / Userspace interfaces / Native interfaces / NTFE_

> Event records and status semantics: behaviour and implementation of the Peios kernel.

<a id="trm-6-7-1"></a>

## One event

An event is the decision and enough of the snapshot to find the packet
it was about: sequence number, `CLOCK_REALTIME` nanoseconds, the seat
and layer, the verdict and — when it was a reject — its kind, flags
(`BACKSTOP`, `FAIL_CLOSED`, `REJECT_DEGRADED`, `REJUDGED` for a Flow
evaluation that replaced a stale sentence, `IDENTITY_UNRESOLVED` for
one whose endpoint could not be attributed), <a id="cite-ntfe-stream.event-flags"></a> direction, address family,
protocol, flow state, interface index, ports, ethertype, both addresses,
the stack-view length, the effect counts the evaluation yielded packed
eight bits each (tags, counts, reports, prompts, saturating), <a id="cite-ntfe-stream.event-effect-counts-packed-saturating"></a> and the
attributing rule's path — the winning rule, or `backstop`, or
`fail-closed` — in a 96-byte field (`PEIOS_NTFE_EV_ATTR_LEN`), so a
longer path is cut to 95 bytes, at a byte rather than a character
boundary, and NUL-terminated. <a id="cite-ntfe-stream.event-attributed-path-truncated-96"></a> A `Flow` event also carries both
endpoints' identities as the judgment read them ([The identity facts](</kernel/internals/ntfe/the-identity-facts.md#trm-6-9>)): the kind, the
process GUID, pid and comm, the user SID and the service SID — binary
SIDs, so the viewer, not the kernel, turns them into names. <a id="cite-ntfe-stream.flow-event-carries-endpoint-identities"></a>

The path is relative to the layer key: `no-inbound/ssh`, not
`Machine\System\Network\Rules\Packet\no-inbound\ssh`. <a id="cite-ntfe-stream.path-relative-to-layer-key"></a>

<a id="trm-6-7-3"></a>

## Status

`PEIOS_NTFE_IOC_STATUS` fills `struct peios_ntfe_status`: the ABI version
(check it before trusting the rest — the ABI is experimental and
versioned, currently 5), <a id="cite-ntfe-stream.status-abi-version-5"></a> the generation, whether any layer is enforcing,
the ring's confessed drops, and the engine counters. <a id="cite-ntfe-stream.status-ioctl-contents"></a> The counters are
plain 64-bit atomics rather than per-CPU — legibility over throughput
while the engine is young, to be revisited with a compiled evaluator. <a id="cite-ntfe-stream.counters-plain-64bit-atomics"></a>

| Group | Counters |
|---|---|
| Seats | `seen_ingress`, `seen_egress`, `seen_local_in`, `seen_local_out`, `deferred` (ingress traversals left for the IP seat), `fallback_judged` (ingress traversals the Packet layer judged there) <a id="cite-ntfe-stream.counters-seats"></a> |
| Evaluation | `judged`, `permissive`, `parse_errors`, `fail_closed` <a id="cite-ntfe-stream.counters-evaluation"></a> |
| Verdicts | `verdict_pass`, `verdict_drop`, `verdict_reject`, `reject_degraded` <a id="cite-ntfe-stream.counters-verdicts"></a> |
| Effects yielded | `fx_tags`, `fx_counts`, `fx_reports`, `fx_prompts` <a id="cite-ntfe-stream.counters-effects-yielded"></a> |
| Ingestion | `last_ingest_error`, `last_ingest_t_ns`, `reporting_level`, `changes_noted` and `changes_walked` ([Ingestion and generations](</kernel/internals/ntfe/policy-ingestion-and-validation.md#trm-6-5>), in force), `contexts` (interfaces in the network context table) <a id="cite-ntfe-stream.counters-ingestion"></a> |
| The stores | `tag_writes`, `tag_untracked`, `tag_refused`, `count_writes`, `count_key_absent`, `count_refused`, `reports_emitted`, `counter_cells` <a id="cite-ntfe-stream.counters-stores"></a> |
| The Flow layer | `flow_judged` (evaluations, sentences written), `flow_cached` (packets answered by a current sentence), `flow_rejudged` (stale by generation), `flow_expired` (stale by time edge), `flow_uncached` (flows with no extension to hold a sentence, evaluated per packet) <a id="cite-ntfe-stream.counters-flow-layer"></a> |
| Refusals | `refusals_emitted` (answers built and sent), `refusals_bypassed` (own refusals waved through a seat), `teardowns_emitted` (far-end resets for refused established TCP flows) <a id="cite-ntfe-stream.counters-refusals"></a> |
| The identity facts | `identity_unresolved` (endpoints that could not be attributed at resolution: a socket with no KACS state, an inet socket nobody stamped, a loopback sender the inbound seat could not see) <a id="cite-ntfe-stream.counters-identity"></a> |

Two invariants a reader can check: `judged` equals the number of
evaluations against a live forest at any layer (Flow evaluations
included, so `judged − flow_judged` is the per-packet count), <a id="cite-ntfe-stream.judged-counts-live-forest-evaluations"></a> and
`permissive` counts layer evaluations that found no forest — at
generation 0, every one. <a id="cite-ntfe-stream.permissive-counts-forestless-evaluations"></a>

`PEIOS_NTFE_IOC_COUNTERS` is the counter dump described in [The stores](</kernel/internals/ntfe/the-stores.md#trm-6-6>): the
caller supplies a buffer of `struct peios_ntfe_counter_rec`, the kernel
fills as many as fit and reports both how many it wrote and how many
cells exist, so a short buffer is visible. <a id="cite-ntfe-stream.counters-ioctl-short-buffer-visible"></a> `PEIOS_NTFE_IOC_FLOWS` is the
flows dump described in [The Flow layer](</kernel/internals/ntfe/the-flow-layer.md#trm-6-8>), with the same short-buffer contract over
`struct peios_ntfe_flow_rec`. <a id="cite-ntfe-stream.flows-ioctl-short-buffer-visible"></a>

<a id="trm-6-7-4"></a>

## Confessions, collected

Everything NTFE declines to do is counted somewhere in the status, and
the viewer shows every one of them. <a id="cite-ntfe-stream.every-refusal-counted"></a> A reader should never have to infer
a refusal from a missing effect:

- a `REJECT` it could not send → `reject_degraded`, and the event's flag; <a id="cite-ntfe-stream.confess-reject-degraded"></a>
- an evaluation it could not finish → `fail_closed`, and an event; <a id="cite-ntfe-stream.confess-fail-closed"></a>
- a frame it could not describe → `parse_errors`; <a id="cite-ntfe-stream.confess-parse-errors"></a>
- a tag it could not write → `tag_untracked` or `tag_refused`; <a id="cite-ntfe-stream.confess-tag-not-written"></a>
- a count it could not land → `count_key_absent` or `count_refused`; <a id="cite-ntfe-stream.confess-count-not-landed"></a>
- a sentence it could not keep → `flow_uncached`; <a id="cite-ntfe-stream.confess-flow-uncached"></a>
- an endpoint it could not attribute → `identity_unresolved`, and the
  event's flag; <a id="cite-ntfe-stream.confess-identity-unresolved"></a>
- a packet it did not judge because a sentence answered → `flow_cached`; <a id="cite-ntfe-stream.confess-flow-cached"></a>
- a refusal it did not judge because it was its own → `refusals_bypassed`; <a id="cite-ntfe-stream.confess-refusals-bypassed"></a>
- a generation it could not accept → `last_ingest_error`, and the log; <a id="cite-ntfe-stream.confess-ingest-error"></a>
- an event it could not keep → `events_dropped`. <a id="cite-ntfe-stream.confess-events-dropped"></a>

<a id="trm-6-b-3"></a>

## Event fields

- `attributed` is the winning rule's path relative to its layer key,
  UTF-8, NUL-terminated, truncated to `PEIOS_NTFE_EV_ATTR_LEN` − 1 bytes
  (95), which may split a multi-byte character. <a id="cite-ntfe-abi-notes.event-attributed-relative-nul-truncated"></a>
  Two reserved values: `backstop` (nothing yielded) and `fail-closed`
  (evaluation failed). <a id="cite-ntfe-abi-notes.event-attributed-reserved-values"></a>
- `effects` packs the effect counts the evaluation *yielded* — `tags |
  counts << 8 | reports << 16 | prompts << 24`, each saturating at 255. <a id="cite-ntfe-abi-notes.event-effects-packing-saturating"></a>
  What the stores then *applied* is in the status confessions, not in
  the event. <a id="cite-ntfe-abi-notes.event-effects-yielded-not-applied"></a>
- `reject_kind` is meaningful only when `verdict` is
  `PEIOS_NTFE_EV_VERDICT_REJECT`; <a id="cite-ntfe-abi-notes.event-reject-kind-only-on-reject"></a> a degraded reject (`flags &
  PEIOS_NTFE_EV_F_REJECT_DEGRADED`) still carries the kind the rule
  chose. <a id="cite-ntfe-abi-notes.event-degraded-reject-keeps-kind"></a>
- `PEIOS_NTFE_EV_F_REJUDGED` marks a `Flow`-layer evaluation that
  replaced a stale sentence (policy change or time edge). <a id="cite-ntfe-abi-notes.event-rejudged-flag"></a> A packet
  answered by a current sentence produces no event at all. <a id="cite-ntfe-abi-notes.cached-sentence-packet-no-event"></a>
- `layer` 2 is `Flow`; `seat` 4 is `LOCAL_OUT`. <a id="cite-ntfe-abi-notes.layer-2-flow-seat-4-local-out"></a> A `Flow` event's
  `direction` is the endpoint judged: the originator's side for a normal
  flow, each seat's own for a loopback flow's two judgments. <a id="cite-ntfe-abi-notes.flow-event-direction-is-endpoint-judged"></a>
- Addresses: the first 4 bytes when `addr_family` is 4, all 16 when 6,
  undefined when 0. <a id="cite-ntfe-abi-notes.event-address-bytes-by-family"></a> Ports are 0 when the fact was absent — check
  `protocol`. <a id="cite-ntfe-abi-notes.event-ports-zero-when-absent"></a>
- `flow_state` 0 means the fact was absent (the ingress seat), not that
  the flow was untracked; untracked is 5. <a id="cite-ntfe-abi-notes.event-flow-state-0-absent-5-untracked"></a>
- The identity fields (ABI 4) are set on `Flow` events only and zero
  elsewhere. <a id="cite-ntfe-abi-notes.event-identity-fields-flow-only"></a> `local_kind` / `remote_kind` are `PEIOS_NTFE_EV_LOCAL_*`:
  `ABSENT` (0) for a non-Flow event, and for `remote` whenever the
  other end is not local; <a id="cite-ntfe-abi-notes.event-kind-absent-cases"></a> `remote` is filled only on a loopback flow. <a id="cite-ntfe-abi-notes.event-remote-loopback-only"></a>
  For a `PROGRAM` end, `*_guid`, `*_pid` and `*_comm` are the process
  facts at the socket's stamp, `*_user` the token's user SID and
  `*_service` its per-service SID, both binary and self-sized (byte 1
  is the sub-authority count; all zero = absent — a user program has no
  service SID). <a id="cite-ntfe-abi-notes.event-program-end-fields"></a> `*_unresolved` says the end could not be attributed and
  was reported as the kernel's or as absent. <a id="cite-ntfe-abi-notes.event-unresolved-flag"></a>

<a id="trm-6-b-4"></a>

## Counter records

- `name` is the stream name (a rule's `COUNT(Name)`), NUL-terminated;
  `hash` is its FNV-1a identity as the kernel keys tables. <a id="cite-ntfe-abi-notes.counter-rec-name-and-hash"></a>
- `keyspec` says which of `src_addr`, `dst_addr`, `ifindex` are
  meaningful for this cell's key; the others are zero. <a id="cite-ntfe-abi-notes.counter-rec-keyspec-unkeyed-zero"></a> `family` is 4, 6,
  or 0 when no address fact is keyed. <a id="cite-ntfe-abi-notes.counter-rec-family"></a>
- `window_secs[i]` / `window_value[i]` for `i < n_windows` are the
  table's windows and this cell's current value in each; <a id="cite-ntfe-abi-notes.counter-rec-window-values"></a> `total` is
  cumulative since the cell was created (or migrated — see [The stores](</kernel/internals/ntfe/the-stores.md#trm-6-6>)); <a id="cite-ntfe-abi-notes.counter-rec-total-cumulative"></a>
  `last_secs` is `CLOCK_REALTIME` seconds of the last write, for
  staleness. <a id="cite-ntfe-abi-notes.counter-rec-last-secs"></a>
- The dump lists every table's cells consecutively; group by `(name,
  keyspec)` to reconstruct tables. <a id="cite-ntfe-abi-notes.counter-dump-tables-consecutive"></a>

<a id="trm-6-b-5"></a>

## Flow records

- `id` is conntrack's own id for the entry (`nf_ct_get_id()`), stable
  for the flow's life and the key to use across dumps. <a id="cite-ntfe-abi-notes.flow-rec-id-stable"></a>
- `src_addr`/`dst_addr`, the ports and the ICMP fields are the
  *original-direction* tuple — the originator first. <a id="cite-ntfe-abi-notes.flow-rec-original-direction-tuple"></a> For ICMP, `src_port`
  carries the echo id and `icmp_type`/`icmp_code` the type and code;
  `dst_port` is 0. <a id="cite-ntfe-abi-notes.flow-rec-icmp-fields"></a>
- `direction`, `ifindex` and `loopback` are meaningful only when `judged`
  is 1: they were recorded at the Flow layer's first judgment. <a id="cite-ntfe-abi-notes.flow-rec-judged-gates-first-judgment-fields"></a> A flow
  with `judged == 0` has had no Flow judgment recorded: every packet of
  it that reached the flow dispatch ([The Flow layer](</kernel/internals/ntfe/the-flow-layer.md#trm-6-8>)) found no Flow forest (a
  permissive generation) or failed closed, or none did — or it has no
  extension at all, and so nowhere to record one (`flow_uncached`; its
  sentences and identities read empty too). <a id="cite-ntfe-abi-notes.flow-rec-unjudged-began-permissive"></a>
- The sentences are parallel arrays indexed by slot (UAPI records hold
  scalars only): slot 0 is the flow's sentence; slot 1 is only ever
  filled for a loopback flow (its inbound endpoint). <a id="cite-ntfe-abi-notes.flow-rec-sentence-slots"></a> A slot with
  `sentence_generation == 0` is empty. <a id="cite-ntfe-abi-notes.flow-rec-generation-0-empty"></a> `sentence_expires_at` 0 means
  never. <a id="cite-ntfe-abi-notes.flow-rec-expires-0-never"></a> `sentence_rule_hash` is FNV-1a-64 (offset
  `0xcbf29ce484222325`, prime `0x100000001b3`) of the whole attributing
  path relative to the layer key, however long — not of the event's
  truncated `attributed`. `backstop` hashes like any other path; <a id="cite-ntfe-abi-notes.flow-rec-rule-hash-fnv1a-64"></a>
  `fail-closed` is never a sentence's, since a failed evaluation is
  not cached. <a id="cite-ntfe-abi-notes.flow-rec-fail-closed-never-cached"></a>
- `packets`/`bytes` are conntrack's accounting, original then reply; <a id="cite-ntfe-abi-notes.flow-rec-accounting-original-then-reply"></a>
  NTFE turns conntrack accounting on at init
  (`net.netfilter.nf_conntrack_acct`). <a id="cite-ntfe-abi-notes.init-enables-conntrack-acct"></a>
- `timeout_secs` is the entry's remaining lifetime as conntrack sees it; <a id="cite-ntfe-abi-notes.flow-rec-timeout-remaining"></a>
  `start_secs` is `CLOCK_REALTIME` seconds when conntrack created it. <a id="cite-ntfe-abi-notes.flow-rec-start-secs"></a>
- `tag_hash`/`tag_value` hold up to `PEIOS_NTFE_FLOW_MAX_TAGS` (8)
  present tags by name hash and value; <a id="cite-ntfe-abi-notes.flow-rec-up-to-8-tags"></a> `n_tags` is the flow's *total*,
  so a value above 8 means some are not listed. <a id="cite-ntfe-abi-notes.flow-rec-n-tags-is-total"></a>
- The identities (ABI 4) are per sentence slot, recorded at the flow's
  first judgment and fixed: `owner_kind[slot]` is `PEIOS_NTFE_EV_LOCAL_*`
  (`ABSENT` = not resolved; `ABSENT` with `owner_unresolved[slot]` set
  = judged but unattributed, such as a loopback sender the outbound seat
  never recorded); <a id="cite-ntfe-abi-notes.flow-rec-owner-kind-per-slot"></a> the per-slot arrays are flattened at a
  fixed stride — `owner_guid` 16 bytes per slot, `owner_comm` 16,
  `owner_user` 68, `owner_service` 32 — so slot 1's user SID starts at
  byte 68. <a id="cite-ntfe-abi-notes.flow-rec-owner-array-strides"></a> Slot 1 is filled only for a loopback flow. <a id="cite-ntfe-abi-notes.flow-rec-owner-slot-1-loopback-only"></a>

<a id="trm-6-b-6"></a>

## Listener records

- One record per socket prepared to receive: TCP in `LISTEN`, and UDP /
  UDP-Lite bound to a port (`connected` when it also has a peer and so
  receives from one address only). <a id="cite-ntfe-abi-notes.listener-rec-one-per-receiving-socket"></a> `addr` all zero is the wildcard; <a id="cite-ntfe-abi-notes.listener-rec-zero-addr-wildcard"></a>
  `ifindex` is `SO_BINDTODEVICE`, 0 for any; <a id="cite-ntfe-abi-notes.listener-rec-ifindex-bindtodevice"></a> `reuseport` marks a member
  of a `SO_REUSEPORT` group, of which each member is listed. <a id="cite-ntfe-abi-notes.listener-rec-reuseport-each-member-listed"></a> `v6only`
  says an `AF_INET6` socket refuses v4-mapped traffic — a v6 socket
  without it answers on both families. <a id="cite-ntfe-abi-notes.listener-rec-v6only"></a>
- The owner fields are those of the flow record's slot, for the socket's
  current stamp: `owner_kind` is `PROGRAM` or `KERNEL` (a socket nobody
  stamped reads `KERNEL` with `owner_unresolved` set). <a id="cite-ntfe-abi-notes.listener-rec-owner-current-stamp"></a>
- The walk is the root namespace's tables only, copied out between hash
  buckets: a best-effort list of a set that changes under it. <a id="cite-ntfe-abi-notes.listener-dump-root-ns-best-effort"></a>

---

# Generated device ABI

_Peios Kernel / Userspace interfaces / Native interfaces / NTFE_

> Every NTFE ioctl number, event and status structure layout, counter record layout and constant, generated from the uapi header and measured by compilation.

<a id="trm-6-a"></a>

Every name, value, offset and size in this appendix is generated from
`include/uapi/pkm/ntfe.h` by `tools/docs/peios-reference/generators/gen-ntfe-abi.py`, with struct
layouts measured by compiling a probe against the real header.
Regenerate it whenever the ABI changes; do not edit it by hand. The
names here are the ones a program actually compiles
against. <a id="cite-abi.ntfe-generated-from-source"></a>

What a compiler cannot measure -- the device's read and poll
semantics, what each ioctl expects, the error vocabulary, and the
bounds that are not in the header -- is in the notes appendix, [NTFE ABI Notes](</kernel/userspace/native/ntfe/device-operations-and-errors.md#trm-6-b>),
which this generator does not touch.

<a id="trm-6-a-1"></a>

## Ioctl requests <a id="cite-abi.ioctl-numbers"></a>

Request numbers on `/dev/peios-ntfe`, packed as `<linux/ioctl.h>`
packs them (direction, argument size, type `'N'`, number).

| Constant | Value | Definition |
|---|---|---|
| `PEIOS_NTFE_IOC_STATUS` | `0x81704E01` | `_IOR(PEIOS_NTFE_IOC_TYPE, PEIOS_NTFE_IOC_STATUS_NR, struct peios_ntfe_status)` |
| `PEIOS_NTFE_IOC_COUNTERS` | `0xC0184E02` | `_IOWR(PEIOS_NTFE_IOC_TYPE, PEIOS_NTFE_IOC_COUNTERS_NR, struct peios_ntfe_counters_query)` |
| `PEIOS_NTFE_IOC_FLOWS` | `0xC0184E03` | `_IOWR(PEIOS_NTFE_IOC_TYPE, PEIOS_NTFE_IOC_FLOWS_NR, struct peios_ntfe_flows_query)` |
| `PEIOS_NTFE_IOC_LISTENERS` | `0xC0184E04` | `_IOWR(PEIOS_NTFE_IOC_TYPE, PEIOS_NTFE_IOC_LISTENERS_NR, struct peios_ntfe_listeners_query)` |

<a id="trm-6-a-2"></a>

## Structure layouts

Offsets and sizes are measured, not declared.

<a id="trm-6-a-2-1"></a>

### `struct peios_ntfe_event` <a id="cite-abi.struct-peios-ntfe-event"></a>

Total size 456 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `seq` |
| 8 | 8 | `__u64` | `t_ns` |
| 16 | 1 | `__u8` | `seat` |
| 17 | 1 | `__u8` | `layer` |
| 18 | 1 | `__u8` | `verdict` |
| 19 | 1 | `__u8` | `flags` |
| 20 | 1 | `__u8` | `direction` |
| 21 | 1 | `__u8` | `addr_family` |
| 22 | 1 | `__u8` | `protocol` |
| 23 | 1 | `__u8` | `flow_state` |
| 24 | 4 | `__u32` | `ifindex` |
| 28 | 2 | `__u16` | `src_port` |
| 30 | 2 | `__u16` | `dst_port` |
| 32 | 2 | `__u16` | `ether_type` |
| 34 | 1 | `__u8` | `reject_kind` |
| 35 | 1 | `__u8` | `_pad0` |
| 36 | 16 | `__u8[16]` | `src_addr` |
| 52 | 16 | `__u8[16]` | `dst_addr` |
| 68 | 4 | `__u32` | `length` |
| 72 | 4 | `__u32` | `effects` |
| 76 | 96 | `__u8[PEIOS_NTFE_EV_ATTR_LEN]` | `attributed` |
| 172 | 4 | `__u32` | `_pad1` |
| 176 | 1 | `__u8` | `local_kind` |
| 177 | 1 | `__u8` | `remote_kind` |
| 178 | 1 | `__u8` | `local_unresolved` |
| 179 | 1 | `__u8` | `remote_unresolved` |
| 180 | 4 | `__s32` | `local_pid` |
| 184 | 4 | `__s32` | `remote_pid` |
| 188 | 16 | `__u8[PEIOS_NTFE_GUID_LEN]` | `local_guid` |
| 204 | 16 | `__u8[PEIOS_NTFE_GUID_LEN]` | `remote_guid` |
| 220 | 16 | `__u8[PEIOS_NTFE_COMM_LEN]` | `local_comm` |
| 236 | 16 | `__u8[PEIOS_NTFE_COMM_LEN]` | `remote_comm` |
| 252 | 68 | `__u8[PEIOS_NTFE_SID_LEN]` | `local_user` |
| 320 | 68 | `__u8[PEIOS_NTFE_SID_LEN]` | `remote_user` |
| 388 | 32 | `__u8[PEIOS_NTFE_SERVICE_SID_LEN]` | `local_service` |
| 420 | 32 | `__u8[PEIOS_NTFE_SERVICE_SID_LEN]` | `remote_service` |
| 452 | 4 | `__u32` | `_pad2` |

<a id="trm-6-a-2-2"></a>

### `struct peios_ntfe_status` <a id="cite-abi.struct-peios-ntfe-status"></a>

Total size 368 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `abi` |
| 8 | 8 | `__u64` | `generation` |
| 16 | 8 | `__u64` | `enforcing` |
| 24 | 8 | `__u64` | `events_dropped` |
| 32 | 8 | `__u64` | `seen_ingress` |
| 40 | 8 | `__u64` | `seen_egress` |
| 48 | 8 | `__u64` | `seen_local_in` |
| 56 | 8 | `__u64` | `deferred` |
| 64 | 8 | `__u64` | `fallback_judged` |
| 72 | 8 | `__u64` | `parse_errors` |
| 80 | 8 | `__u64` | `judged` |
| 88 | 8 | `__u64` | `permissive` |
| 96 | 8 | `__u64` | `fail_closed` |
| 104 | 8 | `__u64` | `verdict_pass` |
| 112 | 8 | `__u64` | `verdict_drop` |
| 120 | 8 | `__u64` | `verdict_reject` |
| 128 | 8 | `__u64` | `reject_degraded` |
| 136 | 8 | `__u64` | `fx_tags` |
| 144 | 8 | `__u64` | `fx_counts` |
| 152 | 8 | `__u64` | `fx_reports` |
| 160 | 8 | `__u64` | `fx_prompts` |
| 168 | 8 | `__u64` | `last_ingest_error` |
| 176 | 8 | `__u64` | `last_ingest_t_ns` |
| 184 | 8 | `__u64` | `tag_writes` |
| 192 | 8 | `__u64` | `tag_untracked` |
| 200 | 8 | `__u64` | `tag_refused` |
| 208 | 8 | `__u64` | `count_writes` |
| 216 | 8 | `__u64` | `count_key_absent` |
| 224 | 8 | `__u64` | `count_refused` |
| 232 | 8 | `__u64` | `reports_emitted` |
| 240 | 8 | `__u64` | `counter_cells` |
| 248 | 8 | `__u64` | `reporting_level` |
| 256 | 8 | `__u64` | `seen_local_out` |
| 264 | 8 | `__u64` | `flow_judged` |
| 272 | 8 | `__u64` | `flow_cached` |
| 280 | 8 | `__u64` | `flow_rejudged` |
| 288 | 8 | `__u64` | `flow_expired` |
| 296 | 8 | `__u64` | `flow_uncached` |
| 304 | 8 | `__u64` | `refusals_emitted` |
| 312 | 8 | `__u64` | `refusals_bypassed` |
| 320 | 8 | `__u64` | `teardowns_emitted` |
| 328 | 8 | `__u64` | `identity_unresolved` |
| 336 | 8 | `__u64` | `changes_noted` |
| 344 | 8 | `__u64` | `changes_walked` |
| 352 | 8 | `__u64` | `contexts` |
| 360 | 8 | `__u64[1]` | `_reserved` |

<a id="trm-6-a-2-3"></a>

### `struct peios_ntfe_counter_rec` <a id="cite-abi.struct-peios-ntfe-counter-rec"></a>

Total size 232 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 64 | `__u8[PEIOS_NTFE_COUNTER_NAME_LEN]` | `name` |
| 64 | 8 | `__u64` | `hash` |
| 72 | 1 | `__u8` | `keyspec` |
| 73 | 1 | `__u8` | `family` |
| 74 | 2 | `__u8[2]` | `_pad0` |
| 76 | 4 | `__s32` | `ifindex` |
| 80 | 16 | `__u8[16]` | `src_addr` |
| 96 | 16 | `__u8[16]` | `dst_addr` |
| 112 | 8 | `__u64` | `total` |
| 120 | 8 | `__u64` | `last_secs` |
| 128 | 4 | `__u32` | `n_windows` |
| 132 | 4 | `__u32` | `_pad1` |
| 136 | 32 | `__u32[PEIOS_NTFE_COUNTER_MAX_WINDOWS]` | `window_secs` |
| 168 | 64 | `__u64[PEIOS_NTFE_COUNTER_MAX_WINDOWS]` | `window_value` |

<a id="trm-6-a-2-4"></a>

### `struct peios_ntfe_counters_query` <a id="cite-abi.struct-peios-ntfe-counters-query"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `buf` |
| 8 | 4 | `__u32` | `buf_len` |
| 12 | 4 | `__u32` | `count` |
| 16 | 4 | `__u32` | `total` |
| 20 | 4 | `__u32` | `_pad0` |

<a id="trm-6-a-2-5"></a>

### `struct peios_ntfe_flow_rec` <a id="cite-abi.struct-peios-ntfe-flow-rec"></a>

Total size 568 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 4 | `__u32` | `id` |
| 4 | 1 | `__u8` | `family` |
| 5 | 1 | `__u8` | `protocol` |
| 6 | 1 | `__u8` | `direction` |
| 7 | 1 | `__u8` | `loopback` |
| 8 | 1 | `__u8` | `seen_reply` |
| 9 | 1 | `__u8` | `assured` |
| 10 | 1 | `__u8` | `related` |
| 11 | 1 | `__u8` | `judged` |
| 12 | 4 | `__s32` | `ifindex` |
| 16 | 4 | `__u32` | `timeout_secs` |
| 20 | 16 | `__u8[16]` | `src_addr` |
| 36 | 16 | `__u8[16]` | `dst_addr` |
| 52 | 2 | `__u16` | `src_port` |
| 54 | 2 | `__u16` | `dst_port` |
| 56 | 1 | `__u8` | `icmp_type` |
| 57 | 1 | `__u8` | `icmp_code` |
| 58 | 1 | `__u8` | `n_tags` |
| 59 | 5 | `__u8[5]` | `_pad0` |
| 64 | 8 | `__u64` | `start_secs` |
| 72 | 16 | `__u64[2]` | `packets` |
| 88 | 16 | `__u64[2]` | `bytes` |
| 104 | 16 | `__u64[PEIOS_NTFE_FLOW_SENTENCES]` | `sentence_generation` |
| 120 | 16 | `__s64[PEIOS_NTFE_FLOW_SENTENCES]` | `sentence_expires_at` |
| 136 | 16 | `__u64[PEIOS_NTFE_FLOW_SENTENCES]` | `sentence_rule_hash` |
| 152 | 2 | `__u8[PEIOS_NTFE_FLOW_SENTENCES]` | `sentence_verdict` |
| 154 | 2 | `__u8[PEIOS_NTFE_FLOW_SENTENCES]` | `sentence_reject_kind` |
| 156 | 4 | `__u8[4]` | `_pad1` |
| 160 | 64 | `__u64[PEIOS_NTFE_FLOW_MAX_TAGS]` | `tag_hash` |
| 224 | 64 | `__u64[PEIOS_NTFE_FLOW_MAX_TAGS]` | `tag_value` |
| 288 | 2 | `__u8[PEIOS_NTFE_FLOW_SENTENCES]` | `owner_kind` |
| 290 | 2 | `__u8[PEIOS_NTFE_FLOW_SENTENCES]` | `owner_unresolved` |
| 292 | 4 | `__u8[4]` | `_pad2` |
| 296 | 8 | `__s32[PEIOS_NTFE_FLOW_SENTENCES]` | `owner_pid` |
| 304 | 32 | `__u8[32]` | `owner_guid` |
| 336 | 32 | `__u8[32]` | `owner_comm` |
| 368 | 136 | `__u8[136]` | `owner_user` |
| 504 | 64 | `__u8[64]` | `owner_service` |

<a id="trm-6-a-2-6"></a>

### `struct peios_ntfe_flows_query` <a id="cite-abi.struct-peios-ntfe-flows-query"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `buf` |
| 8 | 4 | `__u32` | `buf_len` |
| 12 | 4 | `__u32` | `count` |
| 16 | 4 | `__u32` | `total` |
| 20 | 4 | `__u32` | `_pad0` |

<a id="trm-6-a-2-7"></a>

### `struct peios_ntfe_listener_rec` <a id="cite-abi.struct-peios-ntfe-listener-rec"></a>

Total size 168 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 1 | `__u8` | `family` |
| 1 | 1 | `__u8` | `protocol` |
| 2 | 1 | `__u8` | `reuseport` |
| 3 | 1 | `__u8` | `connected` |
| 4 | 1 | `__u8` | `v6only` |
| 5 | 1 | `__u8` | `owner_kind` |
| 6 | 1 | `__u8` | `owner_unresolved` |
| 7 | 1 | `__u8` | `_pad0` |
| 8 | 2 | `__u16` | `port` |
| 10 | 2 | `__u16` | `_pad1` |
| 12 | 4 | `__s32` | `ifindex` |
| 16 | 16 | `__u8[16]` | `addr` |
| 32 | 4 | `__s32` | `owner_pid` |
| 36 | 16 | `__u8[PEIOS_NTFE_GUID_LEN]` | `owner_guid` |
| 52 | 16 | `__u8[PEIOS_NTFE_COMM_LEN]` | `owner_comm` |
| 68 | 68 | `__u8[PEIOS_NTFE_SID_LEN]` | `owner_user` |
| 136 | 32 | `__u8[PEIOS_NTFE_SERVICE_SID_LEN]` | `owner_service` |

<a id="trm-6-a-2-8"></a>

### `struct peios_ntfe_listeners_query` <a id="cite-abi.struct-peios-ntfe-listeners-query"></a>

Total size 24 bytes.

| Offset | Size | Type | Field |
|---|---|---|---|
| 0 | 8 | `__u64` | `buf` |
| 8 | 4 | `__u32` | `buf_len` |
| 12 | 4 | `__u32` | `count` |
| 16 | 4 | `__u32` | `total` |
| 20 | 4 | `__u32` | `_pad0` |

<a id="trm-6-a-3"></a>

## Constants

Grouped as the header groups them.

*NTFE — the Network Traffic Filtering Engine: the verdict event stream and engine status.*

The engine (net/ntfe) judges every traversal at its standing seats and
appends one event per evaluation to a bounded ring. /dev/peios-ntfe
(mode 0600; any number of openers, one reader of the stream at a time)
drains it: read() returns whole events only — never a partial record —
and blocks when the ring is empty unless O_NONBLOCK; poll() raises
POLLIN when events are waiting. A slow reader loses the OLDEST events,
and the loss is confessed in peios_ntfe_status.events_dropped (the
honesty rule: drops are counted, never silent).

Events are emitted for real evaluations (a published forest judged the
traversal) and for fail-closed drops; permissive traversals (a layer
with no forest — all of them at generation 0) emit nothing, because
there is no decision to attribute. Status tells that story instead:
generation 0 means "not enforcing", loudly.

This ABI is EXPERIMENTAL while NTFE grows: no stability promise until
the design ships (PEI-598). Check `abi` before trusting the rest.

| Constant | Value |
|---|---|
| `PEIOS_NTFE_ABI_VERSION` | `5` |

*Which standing seat judged the traversal.* <a id="cite-abi.seat-values"></a>

| Constant | Value |
|---|---|
| `PEIOS_NTFE_EV_SEAT_INGRESS` | `1` |
| `PEIOS_NTFE_EV_SEAT_EGRESS` | `2` |
| `PEIOS_NTFE_EV_SEAT_LOCAL_IN` | `3` |
| `PEIOS_NTFE_EV_SEAT_LOCAL_OUT` | `4` |

*Which rules layer.* <a id="cite-abi.layer-values"></a>

| Constant | Value |
|---|---|
| `PEIOS_NTFE_EV_LAYER_PACKET` | `0` |
| `PEIOS_NTFE_EV_LAYER_RAWPACKET` | `1` |
| `PEIOS_NTFE_EV_LAYER_FLOW` | `2` |

*The verdict, in strictness order.* <a id="cite-abi.verdict-values"></a>

| Constant | Value |
|---|---|
| `PEIOS_NTFE_EV_VERDICT_PASS` | `0` |
| `PEIOS_NTFE_EV_VERDICT_REJECT` | `1` |
| `PEIOS_NTFE_EV_VERDICT_DROP` | `2` |

*The story a REJECT told (meaningful iff verdict == REJECT).* <a id="cite-abi.reject-kinds"></a>

| Constant | Value | Notes |
|---|---|---|
| `PEIOS_NTFE_EV_REJECT_REFUSED` | `0` | RST / port-unreachable |
| `PEIOS_NTFE_EV_REJECT_PROHIBITED` | `1` | admin-prohibited |

*Traversal direction.* <a id="cite-abi.direction-values"></a>

| Constant | Value |
|---|---|
| `PEIOS_NTFE_EV_DIR_IN` | `0` |
| `PEIOS_NTFE_EV_DIR_OUT` | `1` |

*Flow state as the snapshot carried it (0 = the fact was absent).* <a id="cite-abi.flow-state-values"></a>

| Constant | Value |
|---|---|
| `PEIOS_NTFE_EV_FLOW_ABSENT` | `0` |
| `PEIOS_NTFE_EV_FLOW_NEW` | `1` |
| `PEIOS_NTFE_EV_FLOW_ESTABLISHED` | `2` |
| `PEIOS_NTFE_EV_FLOW_RELATED` | `3` |
| `PEIOS_NTFE_EV_FLOW_INVALID` | `4` |
| `PEIOS_NTFE_EV_FLOW_UNTRACKED` | `5` |

*Event flags.* <a id="cite-abi.event-flags"></a>

| Constant | Value | Notes |
|---|---|---|
| `PEIOS_NTFE_EV_F_BACKSTOP` | `0x01` | nothing yielded; DROP |
| `PEIOS_NTFE_EV_F_FAIL_CLOSED` | `0x02` | evaluation failed; DROP |
| `PEIOS_NTFE_EV_F_REJECT_DEGRADED` | `0x04` | REJECT emitted as DROP |
| `PEIOS_NTFE_EV_F_REJUDGED` | `0x08` | Flow: a stale sentence re-judged |
| `PEIOS_NTFE_EV_F_IDENTITY_UNRESOLVED` | `0x10` | Flow: an endpoint could not be attributed |

*What stood at an endpoint: the Flow layer's Local / Remote facts (ABI 4).*

| Constant | Value | Notes |
|---|---|---|
| `PEIOS_NTFE_EV_LOCAL_ABSENT` | `0` | not a Flow event / not local |
| `PEIOS_NTFE_EV_LOCAL_PROGRAM` | `1` | a process's socket |
| `PEIOS_NTFE_EV_LOCAL_KERNEL` | `2` | the stack itself |
| `PEIOS_NTFE_EV_LOCAL_SHARED` | `3` | inbound multicast / broadcast |
| `PEIOS_NTFE_EV_LOCAL_NONE` | `4` | nothing receives it |
| `PEIOS_NTFE_EV_ATTR_LEN` | `96` |  |

A SID's binary form: revision, sub-authority count, a 48-bit authority,
up to 15 sub-authorities. Self-sized by its count byte; all zero =
absent.

| Constant | Value |
|---|---|
| `PEIOS_NTFE_SID_LEN` | `68` |

*A per-service SID (S-1-5-80 + five sub-authorities) is exactly this.*

| Constant | Value |
|---|---|
| `PEIOS_NTFE_SERVICE_SID_LEN` | `32` |
| `PEIOS_NTFE_COMM_LEN` | `16` |
| `PEIOS_NTFE_GUID_LEN` | `16` |

One counter cell, as the counters dump reports it: the stream and key-
spec of its table, the key it holds (only the facts the key-spec names
are meaningful; the rest are zero), the cumulative total, and the value
of every window the table answers.

| Constant | Value |
|---|---|
| `PEIOS_NTFE_COUNTER_NAME_LEN` | `64` |
| `PEIOS_NTFE_COUNTER_MAX_WINDOWS` | `8` |

*Key-spec bits.* <a id="cite-abi.keyspec-bits"></a>

| Constant | Value |
|---|---|
| `PEIOS_NTFE_KEY_SRC_ADDR` | `0x01` |
| `PEIOS_NTFE_KEY_DST_ADDR` | `0x02` |
| `PEIOS_NTFE_KEY_INTERFACE` | `0x04` |

One live flow, as the flows dump reports it (ABI 3): conntrack's view of
the flow (original-direction tuple, state, remaining lifetime,
accounting), NTFE's extension (start time, the interface and direction
at first judgment, the sentences, the tags). Tags are reported by hash;
the policy names them.

| Constant | Value |
|---|---|
| `PEIOS_NTFE_FLOW_MAX_TAGS` | `8` |
| `PEIOS_NTFE_FLOW_SENTENCES` | `2` |

The listeners dump: fills `buf` with as many records as fit; `count` is
how many were written, `total` how many sockets the walk saw.

| Constant | Value |
|---|---|
| `PEIOS_NTFE_IOC_TYPE` | `0x0000004E` |
| `PEIOS_NTFE_IOC_STATUS_NR` | `0x00000001` |
| `PEIOS_NTFE_IOC_COUNTERS_NR` | `0x00000002` |
| `PEIOS_NTFE_IOC_FLOWS_NR` | `0x00000003` |
| `PEIOS_NTFE_IOC_LISTENERS_NR` | `0x00000004` |

---

# Device operations and errors

_Peios Kernel / Userspace interfaces / Native interfaces / NTFE_

> Device operations and errors: behaviour and implementation of the Peios kernel.

<a id="trm-6-b"></a>

[NTFE ABI Reference](</kernel/userspace/native/ntfe/generated-device-abi.md#trm-6-a>) is generated from `include/uapi/pkm/ntfe.h` and holds only what a
compiler can measure. This appendix holds the rest.

<a id="trm-6-b-1"></a>

## Stability

The ABI is **experimental** while NTFE grows (PEI-598): no stability
promise until the design ships. `peios_ntfe_status.abi` carries
`PEIOS_NTFE_ABI_VERSION`; <a id="cite-ntfe-abi-notes.status-abi-carries-version"></a> a consumer checks it before trusting any other
field or record layout. <a id="cite-ntfe-abi-notes.consumer-checks-abi-first"></a> Version 2 (the machinery slice) added the
event's `reject_kind`, the store confessions and `counter_cells` and
`reporting_level` in the status, and the counters ioctl. Version 3 (the
Flow layer) added the `LOCAL_OUT` seat and `Flow` layer ids, the
`REJUDGED` event flag, the Flow and refusal counters in the status, and
the flows ioctl. Version 4 (the identity facts) added the endpoints'
identities to the event and the flow record, the `IDENTITY_UNRESOLVED`
event flag and the `identity_unresolved` counter (in a reserved slot,
so the status kept its size). Version 5 renamed the device and every
symbol from `pnp` to `ntfe`, let more than one file hold the device open,
and added `changes_noted`, `changes_walked` and `contexts` to the status:
the first took one of the two reserved words version 4 left, the other
two are new, so the status grew by two words and keeps one reserved. <a id="cite-ntfe-abi-notes.abi-v5-changes"></a> pnpd and the kernel ship together on the
experimental edition, so the check is a guard, not a negotiation.

<a id="trm-6-b-2"></a>

## `/dev/peios-ntfe`

A misc device, created mode 0600 and owned by uid 0. Those Unix fields
do not grant native access: KACS checks an `open()` using the opener's
token and the node's security descriptor
([File Descriptor Storage](</kernel/internals/kacs/file-security/descriptor-storage-and-caching.md#trm-3-9-5>)). On devtmpfs that descriptor is inherited from the seeded
root's, which grants `GENERIC_ALL` to SYSTEM alone, so the device is
SYSTEM's unless trusted userspace sets another. <a id="cite-ntfe-abi-notes.device-misc-0600-root-only"></a>

| Operation | Semantics | Errors |
|---|---|---|
| `open()` | Any number of openers. | — <a id="cite-ntfe-abi-notes.open-any-number-of-openers"></a> |
| `read(buf, len)` | Returns whole `struct peios_ntfe_event` records only — never a partial one — up to 64 per call, oldest first, consuming them. Blocks on an empty ring unless `O_NONBLOCK`. | `EINVAL` — `len` smaller than one record; `EBUSY` — another open file is the stream's reader; `EAGAIN` — empty and non-blocking; `EINTR`; `ENOMEM`; `EFAULT` — the records it took are lost (below) <a id="cite-ntfe-abi-notes.read-whole-records-oldest-first"></a> <a id="cite-ntfe-abi-notes.read-einval-len-below-one-record"></a> <a id="cite-ntfe-abi-notes.read-ebusy-other-file-is-reader"></a> <a id="cite-ntfe-abi-notes.read-eagain-empty-nonblocking"></a> <a id="cite-ntfe-abi-notes.read-eintr"></a> <a id="cite-ntfe-abi-notes.read-enomem"></a> <a id="cite-ntfe-abi-notes.read-efault"></a> |
| `poll()` | `POLLIN \| POLLRDNORM` when at least one event waits. | — <a id="cite-ntfe-abi-notes.poll-readable-when-event-waits"></a> |
| `ioctl(PEIOS_NTFE_IOC_STATUS, struct peios_ntfe_status *)` | Fills the status snapshot. Cumulative counters since boot. | `EFAULT` <a id="cite-ntfe-abi-notes.status-ioctl-fills-snapshot"></a> |
| `ioctl(PEIOS_NTFE_IOC_COUNTERS, struct peios_ntfe_counters_query *)` | `buf`/`buf_len` describe a user buffer of `struct peios_ntfe_counter_rec`; on return `count` is how many were written and `total` how many cells exist. A short buffer is not an error — the two numbers disagree. Best-effort snapshot: cells may change between records. | `EFAULT`; `ENOMEM` <a id="cite-ntfe-abi-notes.counters-ioctl-count-and-total"></a> <a id="cite-ntfe-abi-notes.counters-ioctl-efault"></a> <a id="cite-ntfe-abi-notes.counters-ioctl-enomem"></a> |
| `ioctl(PEIOS_NTFE_IOC_FLOWS, struct peios_ntfe_flows_query *)` | Same contract over `struct peios_ntfe_flow_rec`: `count` written, `total` live flows the walk saw. Records are copied out between hash buckets, so the dump is a best-effort picture of a table that changes under it. | `EFAULT`; `ENOMEM` <a id="cite-ntfe-abi-notes.flows-ioctl-count-and-total"></a> <a id="cite-ntfe-abi-notes.flows-ioctl-efault"></a> <a id="cite-ntfe-abi-notes.flows-ioctl-enomem"></a> |
| `ioctl(PEIOS_NTFE_IOC_LISTENERS, struct peios_ntfe_listeners_query *)` | Same contract over `struct peios_ntfe_listener_rec`: every TCP socket in the listening state and every bound UDP / UDP-Lite socket of the root network namespace, with the identity KACS stamped on it ([The identity facts](</kernel/internals/ntfe/the-identity-facts.md#trm-6-9>)). `total` is how many the walk saw. A hash bucket holding more sockets than one copy-out batch is walked again from where the batch filled, so with room for every record `count` equals `total`. | `EFAULT`; `ENOMEM` <a id="cite-ntfe-abi-notes.listeners-ioctl-count-and-total"></a> <a id="cite-ntfe-abi-notes.listeners-ioctl-efault"></a> <a id="cite-ntfe-abi-notes.listeners-ioctl-enomem"></a> |
| other ioctls | — | `ENOTTY` <a id="cite-ntfe-abi-notes.unknown-ioctl-enotty"></a> |

Sequence numbers are monotonic per boot. <a id="cite-ntfe-abi-notes.sequence-monotonic-per-boot"></a> A gap between consecutive
records read is the number of events the ring overwrote while the
reader was away, plus any a faulting `read()` consumed; <a id="cite-ntfe-abi-notes.sequence-gap-equals-overwritten"></a> `events_dropped` in the status is the running
total of the overwrites. <a id="cite-ntfe-abi-notes.events-dropped-running-total"></a> A `read()` that fails with `EFAULT` has
already taken its records off the ring: they are lost, and counted
nowhere but in that gap. <a id="cite-ntfe-abi-notes.read-efault-consumes-records"></a>

<a id="trm-6-b-7"></a>

## Bounds not in the header

| Bound | Value |
|---|---|
| Event ring | 4096 records, overwrite-oldest <a id="cite-ntfe-abi-notes.bound-event-ring-4096"></a> |
| Records per `read()` | 64 <a id="cite-ntfe-abi-notes.bound-read-64-records"></a> |
| Counter cells per table | 4096 (`PEIOS_NTFE_COUNTER_MAX_KEYS`, kernel-internal) <a id="cite-ntfe-abi-notes.bound-counter-cells-per-table-4096"></a> |
| Distinct tags per flow | 64 (`PEIOS_NTFE_TAG_MAX_PER_FLOW`, kernel-internal) <a id="cite-ntfe-abi-notes.bound-tags-per-flow-64"></a> |
| Rule depth / rules per layer | 12 (roots are depth 0: 13 levels) / 4096 (ingestion) <a id="cite-ntfe-abi-notes.bound-rule-depth-12-rules-4096"></a> |
| Longest counter window | 86 400 s <a id="cite-ntfe-abi-notes.bound-counter-window-86400s"></a> |
| Sentences per flow | 2 (slot 1 only for loopback flows) <a id="cite-ntfe-abi-notes.bound-sentences-per-flow-2"></a> |
| Flow records batched per copy-out | 32 (kernel-internal) <a id="cite-ntfe-abi-notes.bound-flow-batch-32"></a> |
| Listener records batched per copy-out | 32 (kernel-internal) <a id="cite-ntfe-abi-notes.bound-listener-batch-32"></a> |
