aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / x86 / report_x86.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* report_x86.h -- the iMac kernel's network report (report_x86.c), a |
| 18 | * LAB-ONLY diagnostic: compiled and linked only into the opt-in lab image |
| 19 | * (make imac-kernel CK_X86_REPORT=1 -> IMACKERN-LAB.EFI). The default and |
| 20 | * any resident or service build carry none of it, and the Makefile fails a |
| 21 | * default image that contains it. The report is an unauthenticated UDP |
| 22 | * broadcast (header field auth=none): its run id and the UDP checksum are not |
| 23 | * cryptographic authenticity, so a received report is never a receipt, |
| 24 | * evidence or a command. It carries only console lines whose key is on a |
| 25 | * fixed allowlist (ck_x86_report_filter), never the raw console. No machine |
| 26 | * access in here, so the filter and the frame builder are also compiled and |
| 27 | * tested on the host. */ |
| 28 | #ifndef AIENOS_CK_X86_REPORT_H |
| 29 | #define AIENOS_CK_X86_REPORT_H |
| 30 | #include <stddef.h> |
| 31 | #include <stdint.h> |
| 32 | |
| 33 | #define CK_X86_REPORT_PORT 47031u /* UDP, source and destination */ |
| 34 | #define CK_X86_REPORT_CHUNK 1024u /* report bytes per datagram */ |
| 35 | #define CK_X86_REPORT_MAX 65536u /* the console's RAM copy (console_log.h), 64 parts */ |
| 36 | #define CK_X86_REPORT_NOTE_MAX 80u /* room kept for the truncation note */ |
| 37 | #define CK_X86_REPORT_LINE_MAX 240u /* longest line kept, newline excluded */ |
| 38 | |
| 39 | /* Copies into out (cap bytes) only the complete lines of log[0, len) that |
| 40 | * are on the allowlist: the line starts with one of the fixed kernel |
| 41 | * diagnostic keys followed by ':' (or is one of the fixed title lines), is at |
| 42 | * most CK_X86_REPORT_LINE_MAX bytes and holds printable ASCII only (0x20 to |
| 43 | * 0x7e). Every other line is dropped whole, as is an unterminated last line |
| 44 | * and any line that no longer fits. Kept lines are copied byte for byte, each |
| 45 | * ending in '\n'. Returns the bytes written. Pure: no device, no clock. */ |
| 46 | size_t ck_x86_report_filter(const char *log, size_t len, char *out, size_t cap); |
| 47 | /* When the console's RAM copy filled and later lines were not stored |
| 48 | * (dropped > 0), appends the line "report: console_copy_full dropped_bytes=N\n" |
| 49 | * to out[0, len) so the report never reads as complete. Call after the filter |
| 50 | * with the filter's cap reduced by CK_X86_REPORT_NOTE_MAX. Returns the new |
| 51 | * length; len unchanged when dropped is 0 or the line does not fit. Pure. */ |
| 52 | size_t ck_x86_report_seal(char *out, size_t len, size_t cap, size_t dropped); |
| 53 | /* Datagrams needed for a report of len bytes; 0 when len is 0 or too big. */ |
| 54 | unsigned ck_x86_report_parts(size_t len); |
| 55 | /* The Ethernet frame (no FCS) carrying part `part` of the report: broadcast |
| 56 | * from `mac`, IPv4 0.0.0.0 -> 255.255.255.255, UDP PORT -> PORT, TTL 1, |
| 57 | * payload "AIENOS-REPORT v=2 auth=none run=<16 hex> part=<i>/<n> |
| 58 | * bytes=<total>\n" + chunk. `report` must be ck_x86_report_filter output. |
| 59 | * Bytes written, 0 on a bad argument or a buffer too small. */ |
| 60 | size_t ck_x86_report_frame(const uint8_t mac[6], uint64_t run, const char *report, size_t len, unsigned part, |
| 61 | uint8_t *out, size_t cap); |
| 62 | #endif |