From 5573e16f0010af14d70d7962b91f5edc4ba29df8 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 19 Nov 2026 15:22:15 -0800 Subject: [PATCH] docs: the identity domains check run-time-offset slot accesses against the pushed length docs/API.md: the policy's identity-domain text and section 5 state SlotRemaining and ZeroAddress, the normative check in u32, what an outside load, store and atomic do, that an offset before the bind offset is outside, and what stays unchecked (constant offsets, pointers loaded from memory or made from integers). The rt README's known gaps say the same for buffer arguments, the nil buffer's length 0, and the pulled fetches. --- crates/metal2vulkan-rt/README.md | 16 ++++++++++++++-- docs/API.md | 24 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 5fbee39b2..f12308551 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -1617,8 +1617,18 @@ while the driver's exit handler waited on a lock, with every runtime thread alre - `setBytes` takes up to 64 KiB, one ring chunk (`Limit::BytesLength`). - A buffer argument bound to nothing reads the nil buffer: 64 KiB of zeros, one ring chunk the device keeps from its first such dispatch or draw, its address the argument's pushed value, as - Metal's nil buffer reads zeros. Reads past the 64 KiB and writes through a nil argument aren't + Metal's nil buffer reads zeros. Its pushed length is 0, so every checked access of it (below) + is outside. Reads past the 64 KiB and writes through a nil argument at a constant offset aren't covered. +- A buffer argument's access at a byte offset that is not a translation-time constant is checked + against the bytes from the argument's bind offset to its buffer's end, which a dispatch or draw + pushes beside the argument's address (a `set_bytes` copy's length; 0 for nil). Outside, a load + reads zero, from 16 bytes of zeros the device keeps in a ring chunk of their own, taken at the + first dispatch or draw that checks a load, which nothing is bound to and nothing writes; a store + or an atomic does nothing, and an atomic answers 0. An offset before the bind offset is outside. + This holds on every device. An access at a constant offset is not checked: a function's fixed access past a binding shorter than it reaches + past the buffer, a fault of the kind above where nothing maps there. An access through a pointer + loaded from memory or made from an integer is not checked either: no binding bounds it. - A dispatch's threadgroup memory, the kernel's own and the lengths set, each rounded up to 16 bytes, is at most the device's `maxComputeSharedMemorySize` (`Limit::ThreadgroupMemory`), where Metal's is its `maxThreadgroupMemoryLength`. A kernel's access past its threadgroup memory is @@ -2566,7 +2576,9 @@ or does not check is rebuilt from the generations' names, with young counted ful moved the image to the feedback layout, or, without the feedback loop, while the pass renders the level and layer it reads. - A vertex fetch outside its buffer returns what the device gives: the floor enables no buffer - robustness, so there is no bounds guarantee beyond the device's. + robustness, so there is no bounds guarantee beyond the device's. A post-tessellation function's + control points and a kernel's stage-in are fetched in the shader instead, checked as a buffer + argument's access is (see "Known gaps"). - A pass's visibility result buffer (`visibility_result_buffer`, Metal's `visibilityResultBuffer`) is kept by the command buffer until it retires, and its bytes stay as they were: no command of the pass reaches it, and it joins no hazard tracking. diff --git a/docs/API.md b/docs/API.md index 749cb5958..5187b878e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -111,8 +111,11 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: addresses used directly and a texture's or sampler's handle is its `gpuResourceID` ([RESOURCE-ID.md](RESOURCE-ID.md)). They need `bufferDeviceAddress` and `shaderInt64`. Under them a buffer slot is reached at its own device address (`gpuAddress` plus the bind offset), - pushed less 2^31 as `PushField::SlotGuestBase` (section 5), with no root table, no descriptor - and no containment, as Metal contains no device-address access. A slot whose argument states an + pushed less 2^31 as `PushField::SlotGuestBase` (section 5), with no root table and no + descriptor. With containment on, an access of the slot whose byte offset is not a + translation-time constant is checked against the slot's `PushField::SlotRemaining`, the bytes + from its bind offset to its buffer's end: outside, a load reads zero and a store or atomic does + nothing (section 5). An access at a constant offset is not checked. A slot whose argument states an alignment of at least 4 (`air.arg_type_align_size`) is reached from that address as it is: each access is at the pushed word plus its 32-bit byte offset plus 2^31, modulo 2^32, zero-extended, which is the address plus the offset read as signed, exact as the new runtime makes no buffer @@ -1566,6 +1569,23 @@ for dependency in &pipeline.dependencies { binder (`BindingPlan::instantiate_*`) of a device that compiles under the identity domains writes the word so. A pointer loaded from an argument buffer is the address the buffer holds, unbiased. A texture's or sampler's `SlotGuestBase` is its `gpuResourceID`, unbiased. +- Under the identity domains with containment on, a buffer slot that an access may reach at a + byte offset that is not a translation-time constant (an index the memory plan does not prove + one value, a looping `memcpy` or `memset`, a pulled fetch) also reads + `PushField::SlotRemaining`: a `u32`, the bound buffer's length less the bind offset, the length + of its `setBytes` copy, or 0 where nothing is bound. Each such access whose offset the module + does not hold as a constant is checked with the normative check, `(len >= n) && (offset <= len - + n)` in `u32`, for an `n`-byte access at its 32-bit byte offset from the bind offset, so an + offset before the bind offset, which wraps to at least 2^31, is outside, as the default domains' + descriptor range starts at the bind offset. A load outside reads each of its units at + `PushField::ZeroAddress`, a `u64` the consumer pushes: the address of 16 bytes of zeros, a + multiple of 16, that nothing writes. That is one select of each unit's address, with no select + of the value and no branch, and the load touches nothing of the slot. A store or an atomic + outside sits in the check's selection and runs nothing; an atomic's answer there is 0. Nil and a + slot shorter than one access push a length that every such access past it fails. An access at + a constant offset, and an access through a pointer loaded from memory or made from an integer, + is not checked. The binder writes `SlotRemaining` from the bound buffer and refuses + `ZeroAddress` (`Unsupported{IdentityDomains}`): the zero range is the new runtime's own memory. - The layout numbers set 0 densely, in `ResourceSlot` order. Set 1 holds the heap arrays (the resources reached through argument buffers and resource IDs); `pipeline::heap_sampler_capacity` is the most elements a set-1 sampler array has on a profile. A texture buffer reached so is an