1module Runtime.NativeTelemetrySeal
2
3import Compiler.MachineX86Native
4import Compiler.MachineX86NativeAssembly
5import Runtime.TelemetrySeal
6import Runtime.NativeWordDigest
7
8-- SEALING AN ALPHATEL RECORD AT RUN TIME (docs/observability PRD item 9).
9-- Runtime.NativeTelemetry encodes a record as "ALPHATEL", the body, then
10-- the SHA-256 of the body in 64 lowercase hex characters. A record whose
11-- body carries a clock reading can only be sealed where the reading is
12-- taken, so this routine does, in the executable, what the encoder does at
13-- build time for the rest of the body:
14--
15-- rdi the body followed by its SHA-256 padding (0x80, zeros, the bit
16-- length), whole 64-byte blocks, in writable memory
17-- rsi the number of blocks
18-- rdx the record: "ALPHATEL" already at +0; the body is copied to +8
19-- and the hex digest written after it
20-- rcx the body's length in bytes (nonzero)
21-- r8 a struct timespec (seconds, nanoseconds): its nanoseconds since
22-- the clock's epoch are written into the body at `sealMonotonicAt`
23-- first, so the digest covers them
24-- r9 a work area of `digestWorkBytes` bytes
25--
26-- It keeps the System V callee-saved registers it uses in the work area
27-- (the instruction set has no push) and returns. Every 32-bit quantity is
28-- kept zero-extended in a 64-bit register and truncated by its 32-bit
29-- store; a rotation is a shift of the doubled word. The digest is checked
30-- against the build-time encoder's by reading a record the executable
31-- wrote (scripts/ci/observability.sh: `alpha observe import alphatel`
32-- verifies every record's digest).
33def sealAssembly =
34 (telemetrySealAssemblyFor
35 (family X86NativeAssembly)
36 (family X86NativeRegister64)
37 digestX86Backend)
38
39def nativeTelemetrySealRoutine : Bytes =
40 (compiler-native-encode (family X86NativeAssembly) sealAssembly)The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.