# LCS

---

# 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` |  |
